测量多线程程序的CPU使用率

时间:2015-08-12 16:41:27

标签: linux multithreading performance c++11 gcc

在GCC错误报告(Bug 51617)中,海报将他的异步(C ++ 11)程序执行时的输出看作是这样的:

$(document).ready(function() {
  $('#reservationId').closest('form').on('ajax:error', function(xhr, status, error) {
    $("#cancel_error_text").html("Sorry, we can't cancel your booking at the moment, please try calling the restaurant:");
  });
});

海报可以用什么来提供(或类似的)输出?

注意:检查我的人员/tmp/tst 81.54s user 0.23s system 628% cpu 13.001 total 的条目并没有暗示为此目的有用。

1 个答案:

答案 0 :(得分:3)

我的(Ubuntu)Linux系统上的time(1)手册页说:

   -f FORMAT, --format FORMAT
          Use  FORMAT  as  the  format  string that controls the output of
          time.  See the below more information.

FORMATTING THE OUTPUT
   The format string FORMAT controls the contents of the time output.  The
   format  string can be set using the `-f' or `--format', `-v' or `--ver‐
   bose', or `-p' or `--portability' options.  If they are not given,  but
   the  TIME  environment variable is set, its value is used as the format
   string.  Otherwise, a built-in default format  is  used.   The  default
   format is:
     %Uuser %Ssystem %Eelapsed %PCPU (%Xtext+%Ddata %Mmax)k
     %Iinputs+%Ooutputs (%Fmajor+%Rminor)pagefaults %Wswaps

   The resource specifiers, which are a superset of  those  recognized  by
   the tcsh(1) builtin `time' command, are:
          %      A literal `%'.
          C      Name  and  command  line  arguments  of the command being
                 timed.
          D      Average size of the  process's  unshared  data  area,  in
                 Kilobytes.
          E      Elapsed  real  (wall  clock) time used by the process, in
                 [hours:]minutes:seconds.
          F      Number of major, or I/O-requiring, page faults  that  oc‐
                 curred  while  the process was running.  These are faults
                 where the page has actually migrated out of primary memo‐
                 ry.
          I      Number of file system inputs by the process.
          K      Average   total   (data+stack+text)  memory  use  of  the
                 process, in Kilobytes.
          M      Maximum resident set size of the process during its life‐
                 time, in Kilobytes.
          O      Number of file system outputs by the process.
          P      Percentage  of  the  CPU that this job got.  This is just
                 user + system times divided by the total running time. It
                 also prints a percentage sign.
          R      Number  of minor, or recoverable, page faults.  These are
                 pages that are not valid (so they fault) 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.
          S      Total  number of CPU-seconds used by the system on behalf
                 of the process (in kernel mode), in seconds.
          U      Total number of CPU-seconds that the process used direct‐
                 ly (in user mode), in seconds.
          W      Number of times the process was swapped out of main memo‐
                 ry.
          X      Average amount of shared text in the  process,  in  Kilo‐
                 bytes.
          Z      System's  page size, in bytes.  This is a per-system con‐
                 stant, but varies between systems.
          c      Number of times the process was context-switched involun‐
                 tarily (because the time slice expired).
          e      Elapsed  real  (wall  clock) time used by the process, in
                 seconds.
          k      Number of signals delivered to the process.
          p      Average unshared stack size of the process, in Kilobytes.
          r      Number of socket messages received by the process.
          s      Number of socket messages sent by the process.
          t      Average resident set size of the process, in Kilobytes.
          w      Number of times that  the  program  was  context-switched
                 voluntarily, for instance while waiting for an I/O opera‐
                 tion to complete.
          x      Exit status of the command.

因此,您可以将格式为%P的CPU百分比。

请注意,这是针对/usr/bin/time二进制文件的 - 内置time内置版通常不同(且功能较差)