views:

689

answers:

3

Hello,

I've been trying to use the time command /usr/bin/time to measure the peak memory consumption of a program on a linux system. Independently of what executable I experiment with, I get the correct answer for what regards running time, but memory usage figures are always 0.

the typical output from time is something like:

8.68user 0.04system 0:08.73elapsed 99%CPU (0avgtext+0avgdata 0maxresident)k 0inputs+16outputs (0major+20366minor)pagefaults 0swaps

the zeroes which I am not understanding are:

0avgtext+0avgdata 0maxresident

I have googled around, and I gather that GNU time is actually not able to compute those memory usage data which are referred to in its man page. Am I correct? What is an alternative command I could use to the same effect? (without having to exercise valgrind)

Thanks

+2  A: 

Peak memory usage is not implemented in Linux as far as I know so time does not report it. Most people use the number of minor pagefaults (1 == 4Kb block) as indication for the amount of memory used.

See for example here how Linus Torvalds uses it to look for git performance.

The only way I would know to measure it otherwise would be by using 'ulimit' and using binary search to find the least amount of memory it needs :)

Rutger Nijlunsing
+1  A: 

Its true that time does not universally support all the extended features.

There are alternatives to valgrind such as mempatrol and electric fence, which do not have the same overhead (but have less fancy features). Valgrind is actually ridiculously overpowered for this, and you pay for that in runtime.

You could also look at using systemtap scripts to achieve similar results.

top is also very useful.

Alex Brown
A: 

Here's a way to get peak memory utilization that I use (I find it more strait forward): http://badassdev.com/articles/2010/6/29/space-compliment-to-the-time-utility.html

bad