WRITELOOP

USING TIME COMMAND TO TRACK PEAK MEMORY CONSUMPTION

2020 August 4

When you want to profile the maximum/average physical memory a command/process took during its execution, it happens you can use the linux time command for that - but you will have to use its’ full path so the syntax works with -v. After finishing the execution, this command outputs e.g. this information:

$ /usr/bin/time -v sudo htop
Command being timed: "sudo htop"
User time (seconds): 0.10
System time (seconds): 0.23
Percent of CPU this job got: 5%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:05.77
Average shared text size (kbytes): 0
Average unshared data size (kbytes): 0
Average stack size (kbytes): 0
Average total size (kbytes): 0
Maximum resident set size (kbytes): 7312
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 2
Minor (reclaiming a frame) page faults: 1290
Voluntary context switches: 36
Involuntary context switches: 22
Swaps: 0
File system inputs: 376
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0

On these statistics, the memory related metrics are named resident set size (kbytes). As you can see in this example, the maximum memory used by the htop process was 7312 kb. You can also see other interesting execution metrics there.