linux - 给定程序使用/usr/bin/time 的内存使用情况

标签 linux performance memory time

我想知道如何使用 time 命令收集一个程序/命令(例如 gcc ...)的内存使用情况。 “时间”命令的文档中报告了许多属性。我不知道应该使用哪一个:

内存

   %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.

最佳答案

内存使用没有多大意义(这是一个模棱两可的术语),因为进程可以在运行时询问更多virtual memorymmap(2) (通常由 malloc.... 调用)并使用 munmap 释放内存(但 free 通常不调用 munmap 但只是将释放的内存标记为可重用以供将来使用 malloc)

所以内存使用是动态;你可能会读到 proc(5)并通过 /proc/1234/maps/proc/1234/status/proc/1234/statm< 查询 pid 1234 进程的瞬时状态 等等等等......另见getrusage(2)

您可能对不同的度量感兴趣:平均值或最大值 RSS ,地址空间的大小,working set等... YMMV;如果你在某处告诉(或记录)一些措施,你可能应该解释你做了什么以及如何测量(例如,说这样的话:“1234Kbytes of average total memory, measured with time %K”.. .)

关于linux - 给定程序使用/usr/bin/time 的内存使用情况,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31611026/

相关文章:

c++ - linux下编译c++程序

c++ - Julia 表演建议

javascript - 通过单击事件向 div 添加背景图像。

c++ - 通过 C++ DLL 将 Arduino 字符串转换为 Excel BSTR 的随机字符

php - 为什么 PHP 中的转换和比较比 is_* 更快?

python 内存问题

linux - 从文本列表复制文件

linux - ctags:加载共享库时出错:libgpm.so.1:无法打开共享对象文件:没有这样的文件或目录

linux - 是否可以在raspbian上安装linux程序?

Ruby-on-rails 4 性能低下