简体   繁体   中英

Memory usage using /usr/bin/time for a giving program

I Would like to know how can I gather the memory usage of one program/command (eg. gcc ...) using time command. Many properties are reported in the documentation of 'time' command. I don't know which one I should use:

Memory

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

Memory usage does not means much (it is an ambiguous term), since a process can, at runtime, ask more virtual memory with mmap(2) (often called by malloc ....) and release that memory using munmap (but free often don't call munmap but simply marks freed memory as reusable for future malloc )

So the memory usage is dynamic ; you might read proc(5) and query the instantaneous state of your process of pid 1234 thru /proc/1234/maps , /proc/1234/status , /proc/1234/statm etc etc etc... See also getrusage(2)

You might be interested by different measures: average or max RSS , size of address space, working set , etc... YMMV; if you tell (or document) some measure somewhere you probably should explain what and how you did measure that (eg. say something like: "1234Kbytes of average total memory, measured with time %K " ...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM