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.
Use ps Command to Find Top Processes by Memory and CPU Usage ps is a Linux command-line utility with many options that helps you to display output in different formats. You can use the ps command with –sort argument to sort the output by memory and CPU usage.
In the Activity Monitor utility, you can see the name of each process running ("Process Name" column) and how much memory each process is using ("Real Mem" column).
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
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With