Massif: a heap profiler
1
#include <stdlib.h>
2
3
void g(void)
4
{
5
malloc(4000);
6
}
7
8
void f(void)
9
{
10
malloc(2000);
11
g();
12
}
13
14
int main(void)
15
{
16
int i;
17
int* a[10];
18
19
for (i = 0; i < 10; i++) {
20
a[i] = malloc(1000);
21
}
22
23
f();
24
25
g();
26
27
for (i = 0; i < 10; i++) {
28
free(a[i]);
29
}
30
31
return 0;
32
}
9.2.2. Running Massif
To gather heap profiling information about the program
prog
, type:
valgrind --tool=massif prog
The program will execute (slowly). Upon completion, no summary statistics are printed to Valgrind’s commentary;
all of Massif’s profiling data is written to a file. By default, this file is called
massif.out.<pid>
, where
<pid>
is the process ID, although this filename can be changed with the
--massif-out-file
option.
9.2.3. Running ms_print
To see the information gathered by Massif in an easy-to-read form, use ms_print.
If the output file’s name is
massif.out.12345
, type:
137