On Wed, Dec 29, 2010 at 6:25 AM, patsy <[email protected]> wrote: > 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? ... > 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);
Support for those four members of struct rusage, as well as the ru_nswap member, is not implemented in OpenBSD. You can get the RSS value reported by ps (and top, etc) by using kvm_getproc2(), presumably with the KERN_PROC_PID op to request just the process you care about; the RSS value is is in the p_vm_rssize member. Philip Guenther

