内存使用情况命令,语法类似于time命令


18

什么命令显示程序的内存使用情况,我正在寻找一个易于使用且语法与该time命令相似的命令。我正在尝试查找用C编写的md5哈希程序的内存使用情况,并且需要7秒钟来哈希“ hello world”。

我正在使用安装了busybox的android操作系统。

Answers:


24

具有讽刺意味的是,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

+1,很高兴知道这一点。但是请注意,这是GNU特定的功能。Android是否包括GNU time(1)
沃伦·杨

内置Shell?这里的no bashzshmanpage 都没有提到这一点。您将其与混淆times吗?
沃伦·杨

@WarrenYoung,for SH in zsh bash dash; do $SH -c 'echo $0; type time'; done — zsh时间是一个保留字— bash时间是一个shell关键字—破折号时间是/ usr / bin / time
poige 2013年

@WarrenYoung,不,Android默认情况下没有它,但是由于/usr/bin/time它很大程度上建立在系统调用wait3wait4(我不记得确切)的基础之上,因此它也可以很容易地付诸实践。
poige

顺便说一下,macOS时间以字节为单位显示最大内存使用量,以千字节为单位显示Linux。
user31389 '19

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

我没有,valgrind但似乎有一个适用于android的端口,我将尝试安装它。
kyle k

1
@kylek:如果您正在Android上进行任何本机CPU软件开发,则无论如何都希望拥有它。
沃伦·杨
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.