On 29 Dec 2010 at 14:25, patsy wrote:

> 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;
> }
> 

Got my attention -- discovered a missing declaration in 
/usr/include/sys/resource.h
on my SVR4 system -- added it from Solaris, compiled your program, an on SVR4
I get:

# ./rusage
retval = 0
mem = 0
mem = 0
mem = 0
mem = 0

Anyway, I appreciate discovering the omission for the structure declaration in 
the
header file (not obsd however)

Michael

Reply via email to