/usr/bin/time -v: Measure Peak Memory (Max RSS)
/usr/bin/time -v runs a command and prints detailed resource use, including Maximum resident set size (peak memory).
The shell has a time keyword, but only the standalone /usr/bin/time reports peak memory. It is the simplest way to catch a memory regression in a build or test step.
What it does
GNU time (the /usr/bin/time binary, not the shell builtin) runs a command and reports elapsed wall time, user and system CPU time, and Maximum resident set size in kilobytes, plus page faults and context switches with -v.
Common usage
/usr/bin/time -v ./my-build.sh
# custom format: just peak RSS in KB and elapsed seconds
/usr/bin/time -f '%M KB %e s' ./my-build.sh
# write the stats to a file
/usr/bin/time -v -o time.log ./my-build.shOptions
| Flag | What it does |
|---|---|
| -v | Verbose: print all fields including Maximum resident set size |
| -f <fmt> | Custom format string, e.g. %M (max RSS KB), %e (elapsed s), %P (CPU %) |
| -o <file> | Write the report to a file instead of stderr |
| -a | Append to the -o file rather than overwrite |
In CI
Grep the "Maximum resident set size" line and fail the job if it exceeds a budget. Note the value is in kilobytes on Linux. This catches memory regressions that wall-clock time alone would miss.
Common errors in CI
"-v: command not found" or the shell printing only real/user/sys means you hit the shell builtin, not the binary; call the full path /usr/bin/time. On minimal images the binary is absent entirely ("/usr/bin/time: No such file"); install the "time" package (apt-get install time). On macOS the flags differ (BSD time uses -l), so scripts written for GNU time do not port directly.