3

I have one bench marking application in which I am evaluating a C++ framework.

I am looking for the time and memory consumption. On linux, to get the memory occupied by the current program, I am using getrusage function. It works perfectly on my machine.

Problems arise when I cross compile this application into an arm architecture and run my code on my embedded device (also running linux), the memory function returns 0. Application runs just fine on the embedded device, its just that the memory function is returning me 0.

Any idea what could be the possible solution to this?

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Nadeem
  • 75
  • 2
  • 11
  • 2
    According to [the man page](http://linux.die.net/man/2/getrusage), a return value of 0 indicates success. Or did you mean something else? Please post a minimal, complete program that demonstrates the problem you are having, along with your expected and actual aoutput. – Robᵩ Jul 22 '11 at 15:26

1 Answers1

4

Linux versions prior to 2.6.31.14 do not support the ru_maxrss field of struct rusage. Linux versions starting with 2.6.32 do. I suppose that you are running an earlier version in your embedded system than you are on your desktop.

Robᵩ
  • 163,533
  • 20
  • 239
  • 308
  • Great. You are absolutely right here, just checked my versions. – Nadeem Jul 22 '11 at 15:56
  • So, what are my options now??? can you suggest any alternate for a linux kernel <= 2.6.31.14 – Nadeem Jul 22 '11 at 15:57
  • 1
    You'll have to confirm the usefulness of this on your own, but I'd start `/proc/self/stat`, `/proc/self/statm`, and `/proc/self/status`. See [their man page](http://www.kernel.org/doc/man-pages/online/pages/man5/proc.5.html) for details. – Robᵩ Jul 22 '11 at 16:14
  • Let me go on with them and come again if i find any problems Cheers! – Nadeem Jul 22 '11 at 16:19
  • Hi Rob, I am looking at the /proc/self/status (which is more human readable as compared to /proc/self/stat and /proc/self/statm) and found VmPeak (Peak Virtual Memory) and VmSize (Virtual Memory Size) as the only memory related information there. However, they are not truly matching the size that i get from getrusage function. I am running code on the same machine and checking out memory usage with getrusage and /proc/pid/status. Do you know why there is this difference???? – Nadeem Aug 03 '11 at 13:32
  • @Nadeem - Sorry, I don't. You could try reading the kernel source: http://lxr.linux.no/linux+v2.6.15/kernel/sys.c#L1679 and http://lxr.linux.no/linux+v2.6.15/fs/proc/task_mmu.c#L36. Make sure you read the source for the version of Linux you are running. These are for 2.6.15. – Robᵩ Aug 03 '11 at 15:09