perf stat: Show percore counts in per CPU output
PATCH 1/1 perf stat: Show percore counts in per CPU output
We have supported the event modifier "percore" which sums up the event counts for all hardware threads in a core and show the counts per core.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A -- sleep 1
Performance counter stats for 'system wide':
S0-D0-C0 395,072 cpu/event=cpu-cycles,percore/ S0-D0-C1 851,248 cpu/event=cpu-cycles,percore/ S0-D0-C2 954,226 cpu/event=cpu-cycles,percore/ S0-D0-C3 1,233,659 cpu/event=cpu-cycles,percore/
This patch provides a new option "--percore-show-thread". It is used with event modifier "percore" together to sum up the event counts for all hardware threads in a core but show the counts per hardware thread.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -- sleep 1
Performance counter stats for 'system wide':
CPU0 2,453,061 cpu/event=cpu-cycles,percore/ CPU1 1,823,921 cpu/event=cpu-cycles,percore/ CPU2 1,383,166 cpu/event=cpu-cycles,percore/ CPU3 1,102,652 cpu/event=cpu-cycles,percore/ CPU4 2,453,061 cpu/event=cpu-cycles,percore/ CPU5 1,823,921 cpu/event=cpu-cycles,percore/ CPU6 1,383,166 cpu/event=cpu-cycles,percore/ CPU7 1,102,652 cpu/event=cpu-cycles,percore/
We can see counts are duplicated in some CPU pairs (CPU0/CPU4, CPU1/CPU5, CPU2/CPU6, CPU3/CPU7).
This new option may be useful for some script processing.
--- tools/perf/Documentation/perf-stat.txt | 7 ++++ tools/perf/builtin-stat.c | 4 ++ tools/perf/util/stat-display.c | 57 ++++++++++++++++++++++---- tools/perf/util/stat.h | 1 + 4 files changed, 60 insertions(+), 9 deletions(-)
tools/perf/Documentation/perf-stat.txt +7 -0
@@ -334,6 +334,13 @@ Configure all used events to run in kernel space. --all-user:: Configure all used events to run in user space. +--percore-show-thread:: +The event modifier "percore" has supported to sum up the event counts +for all hardware threads in a core and show the counts per core. + +This option with event modifier "percore" enabled also sums up the event +counts for all hardware threads in a core but show the counts per thread. + EXAMPLES --------
tools/perf/builtin-stat.c +4 -0
@@ -929,6 +929,10 @@ static struct option stat_options[] = {OPT_BOOLEAN_FLAG (0 ,"all-user" , &stat_config.all_user,"Configure all used events to run in user space." ,PARSE_OPT_EXCLUSIVE ), +OPT_BOOLEAN (0 ,"percore-show-thread" , &stat_config.percore_show_thread, +"Use with 'percore' event qualifier to show the event " +"counts of one hardware thread by sum up total hardware " +"threads of same physical core" ), OPT_END() };
tools/perf/util/stat-display.c +48 -9
99 lines not on this page · raw message
tools/perf/util/stat.h +1 -0
@@ -109,6 +109,7 @@ struct perf_stat_config {bool walltime_run_table;bool all_kernel;bool all_user; +bool percore_show_thread;FILE *output;unsigned int interval;unsigned int timeout;
Signature · 1 line
2.17.1
Quoted 26 lines · Jin Yao
We have supported the event modifier "percore" which sums up the event counts for all hardware threads in a core and show the counts per core.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A -- sleep 1Performance counter stats for 'system wide':
S0-D0-C0 395,072 cpu/event=cpu-cycles,percore/ S0-D0-C1 851,248 cpu/event=cpu-cycles,percore/ S0-D0-C2 954,226 cpu/event=cpu-cycles,percore/ S0-D0-C3 1,233,659 cpu/event=cpu-cycles,percore/This patch provides a new option "--percore-show-thread". It is used with event modifier "percore" together to sum up the event counts for all hardware threads in a core but show the counts per hardware thread.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -- sleep 1Performance counter stats for 'system wide':
Quoted 8 lines
CPU0 2,453,061 cpu/event=cpu-cycles,percore/ CPU1 1,823,921 cpu/event=cpu-cycles,percore/ CPU2 1,383,166 cpu/event=cpu-cycles,percore/ CPU3 1,102,652 cpu/event=cpu-cycles,percore/ CPU4 2,453,061 cpu/event=cpu-cycles,percore/ CPU5 1,823,921 cpu/event=cpu-cycles,percore/ CPU6 1,383,166 cpu/event=cpu-cycles,percore/ CPU7 1,102,652 cpu/event=cpu-cycles,percore/
I don't understand how is this different from -A output:
# ./perf stat -e cpu/event=cpu-cycles/ -A ^C Performance counter stats for 'system wide':
CPU0 56,847,497 cpu/event=cpu-cycles/ CPU1 75,274,384 cpu/event=cpu-cycles/ CPU2 63,866,342 cpu/event=cpu-cycles/ CPU3 89,559,693 cpu/event=cpu-cycles/ CPU4 74,761,132 cpu/event=cpu-cycles/ CPU5 76,320,191 cpu/event=cpu-cycles/ CPU6 55,100,175 cpu/event=cpu-cycles/ CPU7 48,472,895 cpu/event=cpu-cycles/
1.074800857 seconds time elapsed
also the interval output is mangled:
# ./perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -I 1000
# time CPU counts unit events
1.000177375 1.000177375 CPU0 138,483,540 cpu/event=cpu-cycles,percore/
1.000177375 1.000177375 CPU1 143,159,477 cpu/event=cpu-cycles,percore/
1.000177375 1.000177375 CPU2 177,554,642 cpu/event=cpu-cycles,percore/
1.000177375 1.000177375 CPU3 150,974,512 cpu/event=cpu-cycles,percore/
1.000177375 1.000177375 CPU4 138,483,540 cpu/event=cpu-cycles,percore/
1.000177375 1.000177375 CPU5 143,159,477 cpu/event=cpu-cycles,percore/
1.000177375 1.000177375 CPU6 177,554,642 cpu/event=cpu-cycles,percore/ jirka
Quoted 51 lines · Jiri Olsa
Quoted 26 lines · Jin Yao
We have supported the event modifier "percore" which sums up the event counts for all hardware threads in a core and show the counts per core.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A -- sleep 1Performance counter stats for 'system wide':
S0-D0-C0 395,072 cpu/event=cpu-cycles,percore/ S0-D0-C1 851,248 cpu/event=cpu-cycles,percore/ S0-D0-C2 954,226 cpu/event=cpu-cycles,percore/ S0-D0-C3 1,233,659 cpu/event=cpu-cycles,percore/This patch provides a new option "--percore-show-thread". It is used with event modifier "percore" together to sum up the event counts for all hardware threads in a core but show the counts per hardware thread.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -- sleep 1Performance counter stats for 'system wide':
Quoted 8 lines
CPU0 2,453,061 cpu/event=cpu-cycles,percore/ CPU1 1,823,921 cpu/event=cpu-cycles,percore/ CPU2 1,383,166 cpu/event=cpu-cycles,percore/ CPU3 1,102,652 cpu/event=cpu-cycles,percore/ CPU4 2,453,061 cpu/event=cpu-cycles,percore/ CPU5 1,823,921 cpu/event=cpu-cycles,percore/ CPU6 1,383,166 cpu/event=cpu-cycles,percore/ CPU7 1,102,652 cpu/event=cpu-cycles,percore/I don't understand how is this different from -A output:
# ./perf stat -e cpu/event=cpu-cycles/ -A ^C Performance counter stats for 'system wide':CPU0 56,847,497 cpu/event=cpu-cycles/ CPU1 75,274,384 cpu/event=cpu-cycles/ CPU2 63,866,342 cpu/event=cpu-cycles/ CPU3 89,559,693 cpu/event=cpu-cycles/ CPU4 74,761,132 cpu/event=cpu-cycles/ CPU5 76,320,191 cpu/event=cpu-cycles/ CPU6 55,100,175 cpu/event=cpu-cycles/ CPU7 48,472,895 cpu/event=cpu-cycles/
Quoted 2 lines
1.074800857 seconds time elapsed
The results are different.
With --percore-show-thread, CPU0 and CPU4 have the same counts (CPU0 and CPU4 are siblings, e.g. 2,453,061 in my example). The value is sum of CPU0 + CPU4.
Without --percore-show-thread, CPU0 and CPU4 have their own counts.
Quoted 12 lines
also the interval output is mangled:
# ./perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -I 1000 # time CPU counts unit events 1.000177375 1.000177375 CPU0 138,483,540 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU1 143,159,477 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU2 177,554,642 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU3 150,974,512 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU4 138,483,540 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU5 143,159,477 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU6 177,554,642 cpu/event=cpu-cycles,percore/
Quoted 2 lines
jirka
Sorry, why the interval output is mangled? It's expected that CPU0 and CPU4 have the same counts.
Thanks
Jin Yao
Quoted 54 lines · Yao
Quoted 51 lines · Jiri Olsa
Quoted 26 lines · Jin Yao
We have supported the event modifier "percore" which sums up the event counts for all hardware threads in a core and show the counts per core.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A -- sleep 1Performance counter stats for 'system wide':
S0-D0-C0 395,072 cpu/event=cpu-cycles,percore/ S0-D0-C1 851,248 cpu/event=cpu-cycles,percore/ S0-D0-C2 954,226 cpu/event=cpu-cycles,percore/ S0-D0-C3 1,233,659 cpu/event=cpu-cycles,percore/This patch provides a new option "--percore-show-thread". It is used with event modifier "percore" together to sum up the event counts for all hardware threads in a core but show the counts per hardware thread.
For example,
# perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -- sleep 1Performance counter stats for 'system wide':
Quoted 8 lines
CPU0 2,453,061 cpu/event=cpu-cycles,percore/ CPU1 1,823,921 cpu/event=cpu-cycles,percore/ CPU2 1,383,166 cpu/event=cpu-cycles,percore/ CPU3 1,102,652 cpu/event=cpu-cycles,percore/ CPU4 2,453,061 cpu/event=cpu-cycles,percore/ CPU5 1,823,921 cpu/event=cpu-cycles,percore/ CPU6 1,383,166 cpu/event=cpu-cycles,percore/ CPU7 1,102,652 cpu/event=cpu-cycles,percore/I don't understand how is this different from -A output:
# ./perf stat -e cpu/event=cpu-cycles/ -A ^C Performance counter stats for 'system wide':CPU0 56,847,497 cpu/event=cpu-cycles/ CPU1 75,274,384 cpu/event=cpu-cycles/ CPU2 63,866,342 cpu/event=cpu-cycles/ CPU3 89,559,693 cpu/event=cpu-cycles/ CPU4 74,761,132 cpu/event=cpu-cycles/ CPU5 76,320,191 cpu/event=cpu-cycles/ CPU6 55,100,175 cpu/event=cpu-cycles/ CPU7 48,472,895 cpu/event=cpu-cycles/
Quoted 8 lines
Quoted 2 lines
1.074800857 seconds time elapsedThe results are different.
With --percore-show-thread, CPU0 and CPU4 have the same counts (CPU0 and CPU4 are siblings, e.g. 2,453,061 in my example). The value is sum of CPU0 + CPU4.
so it shows percore stats but displays all the cpus? what is this good for? to see which cpus are in core? if that's the case then I think we could somehow display the cpu numbers for core in --per-core output, like:
S0-D0-C0(0,4) 395,072 cpu/event=cpu-cycles,percore/ S0-D0-C1(1,5) 851,248 cpu/event=cpu-cycles,percore/ S0-D0-C2(2,6) 954,226 cpu/event=cpu-cycles,percore/ S0-D0-C3(3,7) 1,233,659 cpu/event=cpu-cycles,percore/
Quoted 15 lines
Without --percore-show-thread, CPU0 and CPU4 have their own counts.
Quoted 12 lines
also the interval output is mangled:
# ./perf stat -e cpu/event=cpu-cycles,percore/ -a -A --percore-show-thread -I 1000 # time CPU counts unit events 1.000177375 1.000177375 CPU0 138,483,540 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU1 143,159,477 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU2 177,554,642 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU3 150,974,512 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU4 138,483,540 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU5 143,159,477 cpu/event=cpu-cycles,percore/ 1.000177375 1.000177375 CPU6 177,554,642 cpu/event=cpu-cycles,percore/
Quoted 5 lines
Quoted 2 lines
jirka
Sorry, why the interval output is mangled? It's expected that CPU0 and CPU4 have the same counts.
there are 2 timestamp columns and the header line does not align with the data
jirka
Quoted 5 lines
Quoted 3 lines
With --percore-show-thread, CPU0 and CPU4 have the same counts (CPU0 and CPU4 are siblings, e.g. 2,453,061 in my example). The value is sum of CPU0 + CPU4.
so it shows percore stats but displays all the cpus? what is this good for?
This is essentially a replacement for the any bit (which is gone in Icelake). Per core counts are useful for some formulas, e.g. CoreIPC
The original percore version was inconvenient to post process. This variant matches the output of the any bit.
-Andi
Quoted 11 lines · Andi Kleen
Quoted 5 lines
Quoted 3 lines
With --percore-show-thread, CPU0 and CPU4 have the same counts (CPU0 and CPU4 are siblings, e.g. 2,453,061 in my example). The value is sum of CPU0 + CPU4.
so it shows percore stats but displays all the cpus? what is this good for?
This is essentially a replacement for the any bit (which is gone in Icelake). Per core counts are useful for some formulas, e.g. CoreIPC
The original percore version was inconvenient to post process. This variant matches the output of the any bit.
I see, please put this to the changelog/doc
thanks,
jirka
Quoted 10 lines · Jiri Olsa
Quoted 9 lines · Andi Kleen
Quoted 5 lines
Quoted 3 lines
With --percore-show-thread, CPU0 and CPU4 have the same counts (CPU0 and CPU4 are siblings, e.g. 2,453,061 in my example). The value is sum of CPU0 + CPU4.
so it shows percore stats but displays all the cpus? what is this good for?
This is essentially a replacement for the any bit (which is gone in Icelake). Per core counts are useful for some formulas, e.g. CoreIPC
Quoted 8 lines
Quoted 2 lines
The original percore version was inconvenient to post process. This variant matches the output of the any bit.
I see, please put this to the changelog/doc
thanks,
jirka
Thanks Jiri, thanks Andi!
I will put the explanation in v2.
Thanks
Jin Yao