어떤 명령이 프로그램의 메모리 사용량을 표시합니까? 사용하기 쉽고 명령과 구문이 유사한 명령을 찾고 time있습니다. C로 작성되었으며 “hello world”를 해시하는 데 7 초가 걸리는 md5 해싱 프로그램의 메모리 사용량을 찾으려고합니다.
busybox가 설치된 Android 운영 체제를 사용하고 있습니다.
답변
아이러니하게도 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
VSS가 아닌 MAX RSS를 계산하므로 유용 할 것입니다.
UPD. : 맥 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
답변
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