Problem with GNU time command to measure memory usage

I am trying to use the time / usr / bin / time command to measure the peak memory consumption of a program on a linux system. Regardless of which executable I am experimenting with, I get the correct answer as regards runtime, but the memory usage figures are always 0.

a typical time result is something like:

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

zeros that I don't understand:

0avgtext + 0avgdata 0maxresident

I googled around, and I believe that GNU time is actually not able to calculate the memory usage data that is mentioned on its man page. I'm right? What is an alternative command that I could use with the same effect? (without having to execute valgrind)

+4
source share
2 answers

The use of peak memory in Linux is not implemented, as far as I know, so time does not report it. Most people use the number of secondary files (1 == 4Kb block) as an indicator of the amount of memory used.

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

The only way I could know to measure it, otherwise - using "ulimit" and using binary search to find the smallest amount of memory that it needs :)

+4
source

It is true that time does not universally support all advanced functions.

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

You can also look at systemtap scripts to achieve similar results.

top is also very helpful.

+2
source

Source: https://habr.com/ru/post/1286252/


All Articles