![内存使用命令,语法与时间命令类似](https://linux22.com/image/49841/%E5%86%85%E5%AD%98%E4%BD%BF%E7%94%A8%E5%91%BD%E4%BB%A4%EF%BC%8C%E8%AF%AD%E6%B3%95%E4%B8%8E%E6%97%B6%E9%97%B4%E5%91%BD%E4%BB%A4%E7%B1%BB%E4%BC%BC.png)
什么命令显示程序的内存使用情况,我正在寻找一个易于使用且与该time
命令具有相似语法的命令。我正在尝试查找用 C 编写的 md5 哈希程序的内存使用情况,该程序需要 7 秒来哈希“hello world”。
我使用的是安装了 busybox 的 android 操作系统。
答案1
讽刺的是,time
可能会给你一个答案,但这次它不应该是 shell 内置的time
,而是独立的:
$ /usr/bin/time -v uname
Linux
Command being timed: "uname"
User time (seconds): 0.00
System time (seconds): 0.00
Percent of CPU this job got: 2%
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): 896
Average resident set size (kbytes): 0
Major (requiring I/O) page faults: 1
Minor (reclaiming a frame) page faults: 304
Voluntary context switches: 3
Involuntary context switches: 3
Swaps: 0
File system inputs: 56
File system outputs: 0
Socket messages sent: 0
Socket messages received: 0
Signals delivered: 0
Page size (bytes): 4096
Exit status: 0
不过它计算的是 MAX RSS,而不是 VSS,所以它对您是否有用很大程度上取决于您的任务。
UPD。:Mac OS X’“认为”略有不同,但仍然是time
:
/usr/bin/time -l /Applications/Opera.app/Contents/MacOS/Opera
244.63 real 54.34 user 26.44 sys
284827648 maximum resident set size
0 average shared memory size
0 average unshared data size
0 average unshared stack size
711407 page reclaims
1272 page faults
0 swaps
155 block input operations
251 block output operations
98542 messages sent
68330 messages received
16 signals received
699 voluntary context switches
468999 involuntary context switches
答案2
您可以使用valgrind
为了这:
$ valgrind myprogram arg1 arg2
它的输出将有很多不相关的东西,但它的堆摘要可以满足您的要求:
==91383== HEAP SUMMARY:
==91383== in use at exit: 157,643 bytes in 364 blocks
==91383== total heap usage: 2,999 allocs, 2,635 frees, 306,450 bytes allocated