Skip to content
Latchkey

/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

Terminal
/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.sh

Options

FlagWhat it does
-vVerbose: 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
-aAppend 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.

Related guides

Run this faster and cheaper on Latchkey managed runners. Start free →