Hello list,
I have written a program and would like to trace its memory usage as it runs
and output the data to a file for easy logging/comparison/graphing.
getrusage(2) looks as though it would be appropriate for this. Unfortunately I
seem to be misunderstanding how it should be used, since I would not expect the
program below to output five 0's, yet it does on 4.8-release (i386) and a
slightly out of date 4.8-current (amd64).
Could somebody give me a hint as to where my misunderstanding lies or how else
I might track the memory usage of my program?
Many thanks,
Patsy
#include <stdio.h>
#include <sys/time.h>
#include <sys/resource.h>
int main()
{
struct rusage val;
int retval;
long buf[10000];
retval = getrusage(RUSAGE_SELF, &val);
printf("retval = %d\n", retval);
printf("mem = %ld\n", val.ru_maxrss);
printf("mem = %ld\n", val.ru_ixrss);
printf("mem = %ld\n", val.ru_idrss);
printf("mem = %ld\n", val.ru_isrss);
return 0;
}