简体   繁体   中英

How can I determine max memory usage of a process in Linux?

I have a program that's running in two different modes. I want to compare the two modes with regard to runtime and memory requirements. Determining runtime is easy with using time . In fact, in this case it's really easy because the program reports both the CPU time and the wallclock time at the end of the test. However, determining memory usage is a bit harder.

How can I get details of the memory usage of the process throughout its lifetime? I want to know both the maximum usage and the average. In fact, ideally I'd like some graph of memory usage throughout the life of the run.

time has a verbose mode which gives you the maximum and average resident set size.

(The resident set size is the portion of a process's memory that is held in RAM).

$ /usr/bin/time -v command_that_needs_to_measured |& grep resident
    Maximum resident set size (kbytes): 6596
    Average resident set size (kbytes): 0

Remember to use the binary /usr/bin/time , which has a -v option. You can view its documentation by running man time . If you fail to specify its path, bash's built-in time will run instead, which doesn't have a -v option. You can view its documentation in the bash man page or by running help time .

Valgrind's massif tool can give you a chart of memory usage over time. See http://valgrind.org/docs/manual/ms-manual.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM