使用/ usr / bin / time的内存使用情况

时间:2015-07-24 12:51:55

标签: linux performance memory time

我想知道如何使用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.

1 个答案:

答案 0 :(得分:1)

内存使用并不多(这是一个不明确的术语),因为一个进程可以在运行时通过virtual memory询问更多mmap(2)(通常由{ {1}} ....)并使用malloc释放该内存(但munmap通常不会调用free,而只是将释放的内存标记为可重用的munmap

所以内存使用情况动态 ;您可以阅读proc(5)并通过malloc/proc/1234/maps/proc/1234/status等等查询pid 1234流程的即时状态等...另请参阅getrusage(2)

您可能会对不同的衡量标准感兴趣:平均或最大RSS,地址空间大小,working set等... YMMV;如果你在某个地方告诉(或记录)一些措施,你可能应该解释一下你做了什么以及如何衡量(例如:“1234Kbytes of average total memory,用/proc/1234/statm测量”......)

相关问题