Answers:
具有讽刺意味的是,time
可能有一个答案,但是这次它不应该是内置的,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
bash
和zsh
manpage 都没有提到这一点。您将其与混淆times
吗?
for SH in zsh bash dash; do $SH -c 'echo $0; type time'; done
— zsh时间是一个保留字— bash时间是一个shell关键字—破折号时间是/ usr / bin / time
/usr/bin/time
它很大程度上建立在系统调用wait3
或wait4
(我不记得确切)的基础之上,因此它也可以很容易地付诸实践。
您可以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
valgrind
但似乎有一个适用于android的端口,我将尝试安装它。
time(1)
?