【问题标题】:Memory usage using /usr/bin/time for a giving program给程序使用 /usr/bin/time 的内存使用情况
【发布时间】:2015-10-15 03:44:00
【问题描述】:

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

【问题讨论】:

    标签: linux performance memory time


    【解决方案1】:

    内存使用意义不大(这是一个模棱两可的术语),因为进程可以在运行时询问更多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 的平均总内存,使用 time %K 测量”...)

    【讨论】:

    • %K 进程的平均总(数据+堆栈+文本)内存使用量,以千字节为单位。不使用“时间”吗?
    • 是的,但这只是一个平均值,您可能对此并不满意。
    • 是的,我只想进行估计。在上面列出的命令选项列表中。 %k 是提供内存使用估计的最接近的一个吗..
    • 我的意思是内存使用是不明确的。您可以自行决定要测量什么。
    猜你喜欢
    • 2013-10-29
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    • 2011-03-09
    • 2023-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多