Trying to find the memory high water mark for a given process

I wanted to find out the most memory a process used while running. ps_mem.py is great for showing the total size (resident + shared) for processes but it’s only an instantaneous snapshot. After some searching, I found out that a tool I’d known about forever already has (mostly) the feature I wanted: /usr/bin/time.

$ /usr/bin/time -v uptime
20:18:17 up 23:19, 5 users, load average: 1.76, 2.30, 2.30
Command being timed: "uptime"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 18%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.04
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): 3032
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 1
Minor (reclaiming a frame) page faults: 136
Voluntary context switches: 5
Involuntary context switches: 0
Swaps: 0
File system inputs: 88
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0

Not to be confused with the Bash builtin command, /usr/bin/time -v will show numerous stats about a process that just finished running, including a line that looks like this: Maximum resident set size (kbytes): 63992. While it may not show the resident + shared size like ps_mem.py, it’s still very valuable information when trying to figure out if you’re approaching a certain memory limit.