[英]Memory usage using /usr/bin/time for a giving program
我想知道如何使用time命令收集一个程序/命令(例如gcc ...)的内存使用情况。 “ time”命令的文档中报告了许多属性。 我不知道应该使用哪一个:
记忆
%M Maximum resident set size of the process during its lifetime,
in Kbytes.
%t (Not in tcsh(1).) Average resident set size of the process,
in Kbytes.
%K Average total (data+stack+text) memory use of the process, in
Kbytes.
%D Average size of the process's unshared data area, in Kbytes.
%p (Not in tcsh(1).) Average size of the process's unshared
stack space, in Kbytes.
%X Average size of the process's shared text space, in Kbytes.
%Z (Not in tcsh(1).) System's page size, in bytes. This is a
per-system constant, but varies between systems.
%F Number of major page faults that occurred while the process
was running. These are faults where the page has to be read
in from disk.
%R Number of minor, or recoverable, page faults. These are
faults for pages that are not valid but which have not yet
been claimed by other virtual pages. Thus the data in the
page is still valid but the system tables must be updated.
%W Number of times the process was swapped out of main memory.
%c Number of times the process was context-switched involuntarily
(because the time slice expired).
%w Number of waits: times that the program was context-switched
voluntarily, for instance while waiting for an I/O operation
to complete.
内存使用并不意味着太多(这是一个模糊的术语),因为进程可以在运行时使用mmap(2)请求更多的虚拟内存 (通常由malloc
....调用)并使用munmap
释放该内存(但free
通常不调用munmap
而只是将释放的内存标记为可用于将来的malloc
)
因此内存使用是动态的 ; 您可以阅读proc(5)并通过/proc/1234/maps
, /proc/1234/status
, /proc/1234/statm
等查询pid 1234进程的瞬时状态...另请参见getrusage(2 )
您可能会通过不同的方法感兴趣:平均或最大RSS ,地址空间的大小, 工作集等。 如果您在某处告诉(或记录)某个度量,则可能应该解释该度量的方式和方式(例如,说:“平均总内存1234KB,以time %K
度量...”)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.