やりたいこと
ピークメモリ使用量、つまりプロセスが実行中に一番メモリを使っていた時点での使用量を調べたい。
現在起動中のプロセスを調べる方法(/procを利用)
grep 'Peak' /proc/$PID/status
コマンドを実行。
例:
$ grep 'Peak' /proc/409/status
VmPeak: 216940 kB
プロセス起動前に指定する方法(timeコマンドを利用)
/usr/bin/time -v
を使ってMaximum resident set size
のところを見れば良い。
/usr/bin/time
は
- CentOSなら
yum install time
- Arch Linuxなら
pacman -S time
でインストールできる。
例えばdu -h
のメモリ使用量を調べたい場合は次のようにする。
$ /usr/bin/time -v du -h > /dev/null
Command being timed: "du -h"
User time (seconds): 0.02
System time (seconds): 0.08
Percent of CPU this job got: 98%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:00.12
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): 2236
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 130
Voluntary context switches: 1
Involuntary context switches: 37
Swaps: 0
File system inputs: 0
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
Maximum resident set size (kbytes): 2236
なのでピークメモリ使用量は約2MiBだったと分かる。
See Also