这是跟踪进程的峰值内存使用情况的两种方法。
糖浆
我没有使用过此工具,但听起来像您要找的东西。这就是所谓的糖浆。
描述
Syrupy是一个Python脚本,它定期捕获一个或多个正在运行的进程的内存和CPU负载的快照,以便动态建立它们对系统资源使用情况的配置文件。
例
$ syrupy.py myprog
PID DATE TIME ELAPSED CPU MEM RSS VSIZE
14634 2008-10-10 20:45:25 00:00 0.0 0.0 2996 6680
14634 2008-10-10 20:45:26 00:01 105 0.2 7804 12592
14634 2008-10-10 20:45:27 00:02 103 0.2 8996 13776
14634 2008-10-10 20:45:28 00:03 103 0.2 10468 15348
14634 2008-10-10 20:45:29 00:04 103 0.3 11412 16396
14634 2008-10-10 20:45:30 00:05 104 0.3 12492 17444
/usr/bin/time -v
是的,具有讽刺意味的是,GNU time命令可以为您提供进程的峰值内存使用率。它将报告峰值内存,如下所示:Maximum resident set size (kbytes)
。
例
$ /usr/bin/time -v ~/projects/prime_numbers/eratosthenes_prime_sieve.pl 10 1000000
...
Command being timed: "/home/saml/projects/prime_numbers/eratosthenes_prime_sieve.pl 10 1000000"
User time (seconds): 1.12
System time (seconds): 0.05
Percent of CPU this job got: 54%
Elapsed (wall clock) time (h:mm:ss or m:ss): 0:02.19
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): 79304
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 0
Minor (reclaiming a frame) page faults: 20014
Voluntary context switches: 83
Involuntary context switches: 274
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
参考文献