manuelgr
manuelgr

Reputation: 518

Linux perf tools - How to simultaniously profiling multiple processes? How to extract Percentage of CPU cycles?

I am trying to profile a set of processes on my CPU. In order to be very precise I want to use the perf stat command to see how many CPU cycles my processes used. This is different from top, where I only see the percentage of the CPU used in a snapshot.

Unfortunately I didn't find a way to profile multiple processes at the same time. Is this possible?

And as a second question: Is it possible to not only see the CPU cycles used, but also the total amount of CPU cycles (or the percentage) used in the same time interval?

Upvotes: 6

Views: 4352

Answers (1)

osgx
osgx

Reputation: 94465

You can try running perf stat -p PID1,PID2,PID3 for every pid you want (get them with pidof, pgrep, etc...) http://man7.org/linux/man-pages/man1/perf-stat.1.html

 -p, --pid=<pid>
    stat events on existing process id (comma separated list)

There is also useful -I msecs option to enable periodic printing and --per-thread to separate threads.

Also try system-wide perf stat -a with -A or some --per-* options: http://man7.org/linux/man-pages/man1/perf-stat.1.html

   -a, --all-cpus
       system-wide collection from all CPUs (default if no target is
       specified)
   -A, --no-aggr
       Do not aggregate counts across all monitored CPUs.

   --per-socket
       Aggregate counts per processor socket for system-wide mode
       measurements. This is a useful mode to detect imbalance between
       sockets. To enable this mode, use --per-socket in addition to -a.
       (system-wide). The output includes the socket number and the
       number of online processors on that socket. This is useful to
       gauge the amount of aggregation.

   --per-core
       Aggregate counts per physical processor for system-wide mode
       measurements. This is a useful mode to detect imbalance between
       physical cores. To enable this mode, use --per-core in addition
       to -a. (system-wide). The output includes the core number and the
       number of online logical processors on that physical processor.

   --per-thread
       Aggregate counts per monitored threads, when monitoring threads
       (-t option) or processes (-p option).

Upvotes: 8

Related Questions