perf, tools: Refactor and support interval and CSV metrics
Rebased tree and fixed Jiri's last feedback.
[v5: Fix mainly bisect problems. No regressions introduced by one patch and fixed again later. Some minor fixes in addition]
[v6: Fix running/noise printing patch.]
[v7: Reorder and merge two patches to avoid a bisect hole where unsupported was printed as 0]
[v8: Minor fixes for review feedback. See changelog in patches.] [v9: Fix newline bug. Add support for -A for --metric-only]
[v10: Remove extra "noise" printing (Jiri)
Fix fields in documentation (Jiri)]
[v11: Fix manpage again. Avoid extra metric output in CSV mode.] [v12: Move CSV metrics fields to after running/enabled/variance.
Fix regression with not counted counters.
Minor fixes.]
Currently perf stat does not support printing computed metrics for interval (-I xxx) or CSV (-x,) mode. For example IPC or TSX metrics over time are quite useful to know.
This patch implements them. The main obstacle was that the
metrics printing was all open coded all over the metrics computation code. The second patch refactors the metrics printing to work through call backs that can be more easily changed. This also cleans up the metrics printing significantly. The indentation is now handled through printf, no more need to manually count spaces.
Then based on that it implements metrics printing for CSV and interval mode, and finally a --metric-only mode.
Example output:
% perf stat -I1000 -a sleep 1
# time counts unit events metric multiplex
1.001301370 12020.049593 task-clock (msec) (100.00%)
1.001301370 3,952 context-switches # 0.329 K/sec (100.00%)
1.001301370 69 cpu-migrations # 0.006 K/sec (100.00%)
1.001301370 76 page-faults # 0.006 K/sec
1.001301370 386,582,789 cycles # 0.032 GHz (100.00%)
1.001301370 716,441,544 stalled-cycles-frontend # 185.33% frontend cycles idle (100.00%)
1.001301370 <not supported> stalled-cycles-backend
1.001301370 101,751,678 instructions # 0.26 insn per cycle
1.001301370 # 7.04 stalled cycles per insn (100.00%)
1.001301370 20,914,692 branches # 1.740 M/sec (100.00%)
1.001301370 1,943,630 branch-misses # 9.29% of all branches CSV mode:
% perf stat -x, -I1000 -a sleep 1
1.000982778,12006.549977,,task-clock,12006547787,100.00,,,,
1.000982778,12822,,context-switches,12007100604,100.00,0.001,M/sec
1.000982778,175,,cpu-migrations,12007180306,100.00,0.015,K/sec
1.000982778,3404,,page-faults,12007185482,100.00,0.284,K/sec
1.000982778,1930307489,,cycles,12007018233,100.00,0.161,GHz
1.000982778,6971803638,,stalled-cycles-frontend,12006902870,100.00,361.18,frontend cycles idle
1.000982778,<not supported>,,stalled-cycles-backend,0,100.00,,,,
1.000982778,464493941,,instructions,12006873327,100.00,0.24,insn per cycle
1.000982778,,,,,,15.01,stalled cycles per insn
1.000982778,86548409,,branches,12006758420,100.00,7.208,M/sec
1.000982778,4933638,,branch-misses,12006648104,100.00,5.70,of all branchesNow includes metrics
Metric only mode:
Concicse information if you only care about computed metrics, not raw values
% perf stat --metric-only -a -I 1000
1.001750901 frontend cycles idle backend cycles idle insn per cycle stalled cycles per insn branch-misses of all branches
1.001750901 188.78% 0.53 3.56 4.19%
2.002625926 233.68% 0.86 2.30 2.84%
3.003296456 236.16% 1.18 1.58 2.87%
4.004095913 129.87% 0.24 7.82 2.08%
5.004964861 116.26% 0.17 11.35 1.43%
6.005802242 148.16% 0.19 10.05 1.54%
7.006485273 151.76% 0.18 11.25 1.88% Metric only mode in CSV (flat format, easy to plot and analyze in statistical tools like JMP, R, pandas, gnuplot):
% perf stat -x, --metric-only -a -I 1000
1.001381652,frontend cycles idle,backend cycles idle,insn per cycle,stalled cycles per insn,branch-misses of all branches,
1.001381652,173.32,,0.83,2.09,1.73,
2.002073343,199.47,,1.07,1.60,2.14,
3.002875524,109.52,,0.22,7.83,1.63,
4.003970059,132.10,,0.17,10.85,1.51,
5.004818754,181.60,,0.22,8.87,2.22,Available ingit://git.kernel.org/pub/scm/linux/kernel/git/ak/linux-misc-2.6 perf/stat-metrics-16
PATCH 1/6 perf, tools, stat: Handled scaled == -1 case for counters
From: Andi Kleen <[email protected]>
Arnaldo pointed out that the earlier
"Move noise/running printing into printout"
change changed behavior for not counted counters. This patch fixes it again.
--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
@@ -860,7 +860,7 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval, nl = new_line_std; -if (run ==0 || ena ==0 ) { +if (run ==0 || ena ==0 || counter->counts->scaled ==-1 ) {aggr_printout (counter, id, nr); fprintf(stat_config.output, "%*s%s",
Signature · 1 line
2.5.0
tip-bot for Andi Kleen
merge bot[tip:perf/core] perf stat: Handled scaled == -1 case for counters
perf stat: Handled scaled == -1 case for counters
Commit-ID: b002f3bbd321993c1a6d56b86544065420156ab9 Gitweb: http://git.kernel.org/tip/b002f3bbd321993c1a6d56b86544065420156ab9 Author: Andi Kleen <[email protected]> AuthorDate: Wed, 17 Feb 2016 14:44:00 -0800 Committer: Arnaldo Carvalho de Melo <[email protected]> CommitDate: Fri, 19 Feb 2016 19:12:45 -0300
perf stat: Handled scaled == -1 case for counters
Arnaldo pointed out that the earlier cb110f471025 ("perf stat: Move noise/running printing into printout") change changed behavior for not counted counters. This patch fixes it again.
--- tools/perf/builtin-stat.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
tools/perf/builtin-stat.c +1 -1
@@ -860,7 +860,7 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval, nl = new_line_std; -if (run ==0 || ena ==0 ) { +if (run ==0 || ena ==0 || counter->counts->scaled ==-1 ) {aggr_printout (counter, id, nr); fprintf(stat_config.output, "%*s%s",
PATCH 2/6 perf, tools, stat: Implement CSV metrics output
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Now support CSV output for metrics. With the new output callbacks this is relatively straight forward by creating new callbacks.
This allows to easily plot metrics from CSV files.
The new line callback needs to know the number of fields to skip them correctly
Example output before:
% perf stat -x, true
0.200687,,task-clock,200687,100.00
0,,context-switches,200687,100.00
0,,cpu-migrations,200687,100.00
40,,page-faults,200687,100.00
730871,,cycles,203601,100.00
551056,,stalled-cycles-frontend,203601,100.00
<not supported>,,stalled-cycles-backend,0,100.00
385523,,instructions,203601,100.00
78028,,branches,203601,100.00
3946,,branch-misses,203601,100.00
After:
% perf stat -x, true .502457,,task-clock,502457,100.00,0.485,CPUs utilized 0,,context-switches,502457,100.00,0.000,K/sec 0,,cpu-migrations,502457,100.00,0.000,K/sec 45,,page-faults,502457,100.00,0.090,M/sec 644692,,cycles,509102,100.00,1.283,GHz 423470,,stalled-cycles-frontend,509102,100.00,65.69,frontend cycles idle <not supported>,,stalled-cycles-backend,0,100.00,,,, 492701,,instructions,509102,100.00,0.76,insn per cycle ,,,,,0.86,stalled cycles per insn 97767,,branches,509102,100.00,194.578,M/sec 4788,,branch-misses,509102,100.00,4.90,of all branches
or easier readable
perf stat -x, -o x.csv true
[ak@tassilo hle]$ column -s, -t x.csv
0.490635 task-clock 490635 100.00 0.489 CPUs utilized
0 context-switches 490635 100.00 0.000 K/sec
0 cpu-migrations 490635 100.00 0.000 K/sec
45 page-faults 490635 100.00 0.092 M/sec
629080 cycles 497698 100.00 1.282 GHz
409498 stalled-cycles-frontend 497698 100.00 65.09 frontend cycles idle
<not supported> stalled-cycles-backend 0 100.00
491424 instructions 497698 100.00 0.78 insn per cycle
0.83 stalled cycles per insn
97278 branches 497698 100.00 198.270 M/sec
4569 branch-misses 497698 100.00 4.70 of all branchesTwo new fields are added: metric value and metric name.
v2: Split out function argument changes
v3: Reenable metrics for real.
v4: Fix wrong hunk from refactoring.
v5: Remove extra "noise" printing (Jiri), but add it to the not counted case. Print empty metrics for not counted.
v6: Avoid outputting metric on empty format.
v7: Print metric at the end
--- tools/perf/builtin-stat.c | 76 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-)
tools/perf/builtin-stat.c +72 -4
@@ -739,6 +739,8 @@ struct outstate {FILE *fh;bool newline;const char *prefix; +int nfields; +u64 run, ena; };#define METRIC_LEN 35
@@ -789,6 +791,43 @@ static void print_metric_std(void *ctx, const char *color, const char *fmt,fprintf (out," %-*s" ,METRIC_LEN - n -1 , unit); } +static void new_line_csv (void *ctx) +{ +struct outstate *os = ctx; +int i; + +fputc ('\n' , os->fh); +if (os->prefix) +fprintf (os->fh,"%s%s" , os->prefix, csv_sep); +for (i =0 ; i < os->nfields; i++) +fputs (csv_sep, os->fh); +} + +static void print_metric_csv (void *ctx, +const char *color__maybe_unused , +const char *fmt,const char *unit,double val) +{ +struct outstate *os = ctx; +FILE *out = os->fh; +char buf[64 ], *vals, *ends; + +if (unit ==NULL || fmt ==NULL ) { +fprintf (out,"%s%s%s%s" , csv_sep, csv_sep, csv_sep, csv_sep); +return ; + } +snprintf (buf,sizeof (buf), fmt, val); + vals = buf; +while (isspace (*vals)) + vals++; + ends = vals; +while (isdigit (*ends) || *ends =='.' ) + ends++; + *ends =0 ; +while (isspace (*unit)) + unit++; +fprintf (out,"%s%s%s%s" , csv_sep, vals, csv_sep, unit); +} +static void nsec_printout (int id,int nr,struct perf_evsel *evsel,double avg) {FILE *output = stat_config.output;
@@ -860,6 +899,24 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval, nl = new_line_std; +if (csv_output) { +static int aggr_fields[] = { + [AGGR_GLOBAL ] =0 , + [AGGR_THREAD ] =1 , + [AGGR_NONE ] =1 , + [AGGR_SOCKET ] =2 , + [AGGR_CORE ] =2 , + }; + + pm = print_metric_csv; + nl = new_line_csv; + os.nfields =3 ; + os.nfields += aggr_fields[stat_config.aggr_mode]; +if (counter->cgrp) + os.nfields++; + os.run = run; + os.ena = ena; + }if (run ==0 || ena ==0 || counter->counts->scaled ==-1 ) {aggr_printout (counter, id, nr);
@@ -880,7 +937,12 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,fprintf (stat_config.output,"%s%s" , csv_sep, counter->cgrp->name); +if (!csv_output) +pm (&os,NULL ,NULL ,"" ,0 ); +print_noise (counter, noise);print_running (run, ena); +if (csv_output) +pm (&os,NULL ,NULL ,"" ,0 );return ; }
@@ -893,14 +955,20 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval, out.new_line = nl; out.ctx = &os; -if (!csv_output) -perf_stat__print_shadow_stats (counter, uval, +if (csv_output) { +print_noise (counter, noise); +print_running (run, ena); + } + +perf_stat__print_shadow_stats (counter, uval, stat_config.aggr_mode ==AGGR_GLOBAL ?0 :cpu_map__id_to_cpu (id), &out); -print_noise (counter, noise); -print_running (run, ena); +if (!csv_output) { +print_noise (counter, noise); +print_running (run, ena); + } }static void print_aggr (char *prefix)
Signature · 1 line
2.5.0
Arnaldo Carvalho de Melo
maintainerRe: [PATCH 2/6] perf, tools, stat: Implement CSV metrics output
Em Wed, Feb 17, 2016 at 02:44:01PM -0800, Andi Kleen escreveu:
Quoted 26 lines
From: Andi Kleen <[email protected]>
Now support CSV output for metrics. With the new output callbacks this is relatively straight forward by creating new callbacks.
This allows to easily plot metrics from CSV files.
The new line callback needs to know the number of fields to skip them correctly
Example output before:
% perf stat -x, true
0.200687,,task-clock,200687,100.00
0,,context-switches,200687,100.00
0,,cpu-migrations,200687,100.00
40,,page-faults,200687,100.00
730871,,cycles,203601,100.00
551056,,stalled-cycles-frontend,203601,100.00
<not supported>,,stalled-cycles-backend,0,100.00
385523,,instructions,203601,100.00
78028,,branches,203601,100.00
3946,,branch-misses,203601,100.00After:
Quoted 12 lines
% perf stat -x, true .502457,,task-clock,502457,100.00,0.485,CPUs utilized 0,,context-switches,502457,100.00,0.000,K/sec 0,,cpu-migrations,502457,100.00,0.000,K/sec 45,,page-faults,502457,100.00,0.090,M/sec 644692,,cycles,509102,100.00,1.283,GHz 423470,,stalled-cycles-frontend,509102,100.00,65.69,frontend cycles idle <not supported>,,stalled-cycles-backend,0,100.00,,,, 492701,,instructions,509102,100.00,0.76,insn per cycle ,,,,,0.86,stalled cycles per insn 97767,,branches,509102,100.00,194.578,M/sec 4788,,branch-misses,509102,100.00,4.90,of all branches
Testing here I noticed this new line with just commas:
[root@jouet ~]# perf stat -x, usleep 1 0.268163,,task-clock,268163,100.00,0.484,CPUs utilized 1,,context-switches,268163,100.00,0.004,M/sec 0,,cpu-migrations,268163,100.00,0.000,K/sec 52,,page-faults,268163,100.00,0.194,M/sec 815922,,cycles,270746,100.00,3.043,GHz
<not supported>,,stalled-cycles-frontend,0,100.00,,,, <not supported>,,stalled-cycles-backend,0,100.00,,,, 680198,,instructions,270746,100.00,0.83,insn per cycle ,,,,,,,, 136401,,branches,270746,100.00,508.650,M/sec 6995,,branch-misses,270746,100.00,5.13,of all branches [root@jouet ~]#
Where before it wasn't there:
cat /tmp/before
0.282628,,task-clock,282628,100.00
1,,context-switches,282628,100.00
0,,cpu-migrations,282628,100.00
52,,page-faults,282628,100.00
861213,,cycles,285354,100.00
<not supported>,,stalled-cycles-frontend,0,100.00
<not supported>,,stalled-cycles-backend,0,100.00
686082,,instructions,285354,100.00
137846,,branches,285354,100.00
7142,,branch-misses,285354,100.00
Re: [PATCH 2/6] perf, tools, stat: Implement CSV metrics output
Quoted 13 lines
Where before it wasn't there:
cat
/tmp/before
0.282628,,task-clock,282628,100.00
1,,context-switches,282628,100.00
0,,cpu-migrations,282628,100.00
52,,page-faults,282628,100.00
861213,,cycles,285354,100.00
<not supported>,,stalled-cycles-frontend,0,100.00
<not supported>,,stalled-cycles-backend,0,100.00
686082,,instructions,285354,100.00
137846,,branches,285354,100.00
7142,,branch-misses,285354,100.00
This is intentional. See the standard perf output:
521,232 instructions # 0.63 insns per cycle
# 1.13 stalled cycles per insnSo this line has multiple metrics. In CSV this is expressed as a mostly empty line.
-Andi
Re: [PATCH 2/6] perf, tools, stat: Implement CSV metrics output
Quoted 14 lines · Andi Kleen
Quoted 13 lines
Where before it wasn't there:
cat
/tmp/before
0.282628,,task-clock,282628,100.00
1,,context-switches,282628,100.00
0,,cpu-migrations,282628,100.00
52,,page-faults,282628,100.00
861213,,cycles,285354,100.00
<not supported>,,stalled-cycles-frontend,0,100.00
<not supported>,,stalled-cycles-backend,0,100.00
686082,,instructions,285354,100.00
137846,,branches,285354,100.00
7142,,branch-misses,285354,100.00
Quoted 7 lines
This is intentional. See the standard perf output:
521,232 instructions # 0.63 insns per cycle # 1.13 stalled cycles per insnSo this line has multiple metrics. In CSV this is expressed as a mostly empty line.
it's intentional if you have data from stalled cycles counter on cpu where this one is non supported you get blank line:
0.186177,,task-clock,186177,100.00,0.448,CPUs utilized 0,,context-switches,186177,100.00,0.000,K/sec 0,,cpu-migrations,186177,100.00,0.000,K/sec 43,,page-faults,186177,100.00,0.231,M/sec 567286,,cycles,187628,100.00,3.047,GHz
<not supported>,,stalled-cycles-frontend,0,100.00,,,, <not supported>,,stalled-cycles-backend,0,100.00,,,, 456664,,instructions,187628,100.00,0.80,insn per cycle ,,,,,,,, 89069,,branches,187628,100.00,478.410,M/sec 3360,,branch-misses,187628,100.00,3.77,of all branches
which I think is wrong and we should not print
jirka
Re: [PATCH 2/6] perf, tools, stat: Implement CSV metrics output
Quoted 18 lines · Jiri Olsa
Quoted 17 lines · Andi Kleen
Quoted 13 lines
Where before it wasn't there:
cat
/tmp/before
0.282628,,task-clock,282628,100.00
1,,context-switches,282628,100.00
0,,cpu-migrations,282628,100.00
52,,page-faults,282628,100.00
861213,,cycles,285354,100.00
<not supported>,,stalled-cycles-frontend,0,100.00
<not supported>,,stalled-cycles-backend,0,100.00
686082,,instructions,285354,100.00
137846,,branches,285354,100.00
7142,,branch-misses,285354,100.00This is intentional. See the standard perf output:
Quoted 7 lines
Quoted 4 lines
521,232 instructions # 0.63 insns per cycle # 1.13 stalled cycles per insnSo this line has multiple metrics. In CSV this is expressed as a mostly empty line.
it's intentional if you have data from stalled cycles counter on cpu where this one is non supported you get blank line:
I fixed this now by probing for the stalled cycles counters in advance. That avoids a couple of other issues too, like the empty columns in --metric-only, and even makes the output of standard perf stat shorter.
-Andi
Re: [PATCH 2/6] perf, tools, stat: Implement CSV metrics output
In reply to Andi KleenOn Wed, Feb 17, 2016 at 02:44:01PM -0800, Andi Kleen wrote:
SNIP
Quoted 9 lines
--- tools/perf/builtin-stat.c | 76 ++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 72 insertions(+), 4 deletions(-)tools/perf/builtin-stat.c +0
-0
tools/perf/builtin-stat.c struct outstate { · line 743
Quoted 5 lines
tools/perf/builtin-stat.c +2
-0@@ -739,6 +739,8 @@ struct outstate {FILE *fh;bool newline;const char *prefix; +int nfields; +u64 run, ena;
what are outstate's ena and run being used for?
thanks,
jirka
PATCH 3/6 perf, tools, stat: Support metrics in --per-core/socket mode
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Enable metrics printing in --per-core / --per-socket mode. We need to save the shadow metrics in a unique place. Always use the first CPU in the aggregation. Then use the same CPU to retrieve the shadow value later.
Example output:
% perf stat --per-core -a ./BC1s
Performance counter stats for 'system wide':
S0-C0 2 2966.020381 task-clock (msec) # 2.004 CPUs utilized (100.00%) S0-C0 2 49 context-switches # 0.017 K/sec (100.00%) S0-C0 2 4 cpu-migrations # 0.001 K/sec (100.00%) S0-C0 2 467 page-faults # 0.157 K/sec S0-C0 2 4,599,061,773 cycles # 1.551 GHz (100.00%) S0-C0 2 9,755,886,883 instructions # 2.12 insn per cycle (100.00%) S0-C0 2 1,906,272,125 branches # 642.704 M/sec (100.00%) S0-C0 2 81,180,867 branch-misses # 4.26% of all branches S0-C1 2 2965.995373 task-clock (msec) # 2.003 CPUs utilized (100.00%) S0-C1 2 62 context-switches # 0.021 K/sec (100.00%) S0-C1 2 8 cpu-migrations # 0.003 K/sec (100.00%) S0-C1 2 281 page-faults # 0.095 K/sec S0-C1 2 6,347,290 cycles # 0.002 GHz (100.00%) S0-C1 2 4,654,156 instructions # 0.73 insn per cycle (100.00%) S0-C1 2 947,121 branches # 0.319 M/sec (100.00%) S0-C1 2 37,322 branch-misses # 3.94% of all branches
1.480409747 seconds time elapsed
v2: Rebase to older patches
--- tools/perf/builtin-stat.c | 58 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 51 insertions(+), 7 deletions(-)
tools/perf/builtin-stat.c +51 -7
@@ -741,6 +741,8 @@ struct outstate {const char *prefix;int nfields;u64 run, ena; +int id, nr; +struct perf_evsel *evsel; };#define METRIC_LEN 35
@@ -756,12 +758,9 @@ static void do_new_line_std(struct outstate *os) {fputc ('\n' , os->fh);fputs (os->prefix, os->fh); +aggr_printout (os->evsel, os->id, os->nr);if (stat_config.aggr_mode ==AGGR_NONE )fprintf (os->fh," " ); -if (stat_config.aggr_mode ==AGGR_CORE ) -fprintf (os->fh," " ); -if (stat_config.aggr_mode ==AGGR_SOCKET ) -fprintf (os->fh," " );fprintf (os->fh," " ); }
@@ -799,6 +798,7 @@ static void new_line_csv(void *ctx)fputc ('\n' , os->fh);if (os->prefix)fprintf (os->fh,"%s%s" , os->prefix, csv_sep); +aggr_printout (os->evsel, os->id, os->nr);for (i =0 ; i < os->nfields; i++)fputs (csv_sep, os->fh); }
@@ -856,6 +856,22 @@ static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)fprintf (output,"%s%s" , csv_sep, evsel->cgrp->name); } +static int first_shadow_cpu (struct perf_evsel *evsel,int id) +{ +int i; + +if (aggr_get_id ==NULL ) +return 0 ; + +for (i =0 ; i <perf_evsel__nr_cpus (evsel); i++) { +int cpu2 =perf_evsel__cpus (evsel)->map[i]; + +if (aggr_get_id (evsel_list->cpus, cpu2) == id) +return cpu2; + } +return 0 ; +} +static void abs_printout (int id,int nr,struct perf_evsel *evsel,double avg) {FILE *output = stat_config.output;
@@ -892,7 +908,10 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,struct perf_stat_output_ctx out;struct outstate os = { .fh = stat_config.output, - .prefix = prefix ? prefix :"" + .prefix = prefix ? prefix :"" , + .id = id, + .nr = nr, + .evsel = counter, };print_metric_t pm = print_metric_std;void (*nl)(void *);
@@ -962,15 +981,38 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,perf_stat__print_shadow_stats (counter, uval, stat_config.aggr_mode ==AGGR_GLOBAL ?0 : -cpu_map__id_to_cpu (id), +first_shadow_cpu (counter, id), &out); -if (!csv_output) {print_noise (counter, noise);print_running (run, ena); } } +static void aggr_update_shadow (void ) +{ +int cpu, cpu2, s2, id, s; +u64 val; +struct perf_evsel *counter; + +for (s =0 ; s < aggr_map->nr; s++) { + id = aggr_map->map[s]; +evlist__for_each (evsel_list, counter) { + val =0 ; +for (cpu =0 ; cpu <perf_evsel__nr_cpus (counter); cpu++) { + cpu2 =perf_evsel__cpus (counter)->map[cpu]; + s2 =aggr_get_id (evsel_list->cpus, cpu2); +if (s2 != id) +continue ; + val +=perf_counts (counter->counts, cpu,0 )->val; + } + val = val * counter->scale; +perf_stat__update_shadow_stats (counter, &val, +first_shadow_cpu (counter, id)); + } + } +} +static void print_aggr (char *prefix) {FILE *output = stat_config.output;
@@ -982,6 +1024,8 @@ static void print_aggr(char *prefix)if (!(aggr_map || aggr_get_id))return ; +aggr_update_shadow (); +for (s =0 ; s < aggr_map->nr; s++) { id = aggr_map->map[s];evlist__for_each (evsel_list, counter) {
Signature · 1 line
2.5.0
Re: [PATCH 3/6] perf, tools, stat: Support metrics in --per-core/socket mode
On Wed, Feb 17, 2016 at 02:44:02PM -0800, Andi Kleen wrote:
SNIP
Quoted 16 lines
tools/perf/builtin-stat.c +4
-2perf_stat__print_shadow_stats (counter, uval, stat_config.aggr_mode ==AGGR_GLOBAL ?0 : -cpu_map__id_to_cpu (id), +first_shadow_cpu (counter, id), &out); -if (!csv_output) {print_noise (counter, noise);print_running (run, ena); } } +static void aggr_update_shadow (void ) +{ +int cpu, cpu2, s2, id, s;
tools/perf/builtin-stat.c static void printout(int id, int nr, struct perf_evsel *counter, double uval, · line 1004
Quoted 10 lines
tools/perf/builtin-stat.c +10
-0+u64 val; +struct perf_evsel *counter; + +for (s =0 ; s < aggr_map->nr; s++) { + id = aggr_map->map[s]; +evlist__for_each (evsel_list, counter) { + val =0 ; +for (cpu =0 ; cpu <perf_evsel__nr_cpus (counter); cpu++) { + cpu2 =perf_evsel__cpus (counter)->map[cpu]; + s2 =aggr_get_id (evsel_list->cpus, cpu2);
I think you need to pass cpu's 'idx' into aggr_get_id, because it will do evsel_list->cpus[cpu2] for you
jirka
Re: [PATCH 3/6] perf, tools, stat: Support metrics in --per-core/socket mode
In reply to Andi KleenOn Wed, Feb 17, 2016 at 02:44:02PM -0800, Andi Kleen wrote:
SNIP
Quoted 30 lines
tools/perf/builtin-stat.c +24
-0+static void aggr_update_shadow (void ) +{ +int cpu, cpu2, s2, id, s; +u64 val; +struct perf_evsel *counter; + +for (s =0 ; s < aggr_map->nr; s++) { + id = aggr_map->map[s]; +evlist__for_each (evsel_list, counter) { + val =0 ; +for (cpu =0 ; cpu <perf_evsel__nr_cpus (counter); cpu++) { + cpu2 =perf_evsel__cpus (counter)->map[cpu]; + s2 =aggr_get_id (evsel_list->cpus, cpu2); +if (s2 != id) +continue ; + val +=perf_counts (counter->counts, cpu,0 )->val; + } + val = val * counter->scale; +perf_stat__update_shadow_stats (counter, &val, +first_shadow_cpu (counter, id)); + } + } +} +static void print_aggr (char *prefix) {FILE *output = stat_config.output;
tools/perf/builtin-stat.c static void print_aggr(char *prefix) · line 1027
Quoted 4 lines
tools/perf/builtin-stat.c +1
-0@@ -982,6 +1024,8 @@ static void print_aggr(char *prefix)if (!(aggr_map || aggr_get_id))return ; +aggr_update_shadow ();
this should be called from perf_stat_process_counter, not from display function
also please document somewhere (best around shadow stats variables) what cpus (array members) are used for given AGGR_*
thanks,
jirka
Re: [PATCH 3/6] perf, tools, stat: Support metrics in --per-core/socket mode
Quoted 8 lines
Quoted 8 lines
tools/perf/builtin-stat.c +1
-0+static void print_aggr (char *prefix) {FILE *output = stat_config.output;@@ -982,6 +1024,8 @@ static void print_aggr(char *prefix)if (!(aggr_map || aggr_get_id))return ;
Quoted 4 lines
tools/perf/builtin-stat.c static void print_aggr(char *prefix) · line 1027
Quoted 1 line
tools/perf/builtin-stat.c +1
-0+aggr_update_shadow ();this should be called from
perf_stat_process_counter, not from display function
I tried it, but the function needs a lot of stuff (aggr_map, evsel_list) that only exists in builtin-stat. Passing all that around is quite complicated and intrusive.
I left it alone for now.
-Andi
Re: [PATCH 3/6] perf, tools, stat: Support metrics in --per-core/socket mode
In reply to Andi KleenOn Wed, Feb 17, 2016 at 02:44:02PM -0800, Andi Kleen wrote:
SNIP
Quoted 13 lines
tools/perf/builtin-stat.c +4
-1@@ -892,7 +908,10 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,struct perf_stat_output_ctx out;struct outstate os = { .fh = stat_config.output, - .prefix = prefix ? prefix :"" + .prefix = prefix ? prefix :"" , + .id = id, + .nr = nr, + .evsel = counter, };print_metric_t pm = print_metric_std;void (*nl)(void *);
tools/perf/builtin-stat.c static void printout(int id, int nr, struct perf_evsel *counter, double uval, · line 984
Quoted 5 lines
tools/perf/builtin-stat.c +1
-1@@ -962,15 +981,38 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval, perf_stat__print_shadow_stats(counter, uval, stat_config.aggr_mode == AGGR_GLOBAL ? 0 : - cpu_map__id_to_cpu(id), + first_shadow_cpu(counter, id),
hum, IIUC you need to handle AGGR_NONE in here as well?
thanks,
jirka
Re: [PATCH 3/6] perf, tools, stat: Support metrics in --per-core/socket mode
Quoted 18 lines · Jiri Olsa
On Wed, Feb 17, 2016 at 02:44:02PM -0800, Andi Kleen wrote:
SNIP
Quoted 14 lines
tools/perf/builtin-stat.c +4
-1@@ -892,7 +908,10 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,struct perf_stat_output_ctx out;struct outstate os = { .fh = stat_config.output, - .prefix = prefix ? prefix :"" + .prefix = prefix ? prefix :"" , + .id = id, + .nr = nr, + .evsel = counter, };print_metric_t pm = print_metric_std;void (*nl)(void *);@@ -962,15 +981,38 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,
Quoted 6 lines
tools/perf/builtin-stat.c static void printout(int id, int nr, struct perf_evsel *counter, double uval, · line 984
Quoted 4 lines
tools/perf/builtin-stat.c +1
-1perf_stat__print_shadow_stats(counter, uval, stat_config.aggr_mode == AGGR_GLOBAL ? 0 : - cpu_map__id_to_cpu(id), + first_shadow_cpu(counter, id),hum, IIUC you need to handle
AGGR_NONEin here as well?
AFAIK it works. aggr_get_id in first_shadow_cpu and cpu_map__id_to_cpu handle this case, right?
-Andi
Re: [PATCH 3/6] perf, tools, stat: Support metrics in --per-core/socket mode
Quoted 26 lines · Andi Kleen
Quoted 18 lines · Jiri Olsa
On Wed, Feb 17, 2016 at 02:44:02PM -0800, Andi Kleen wrote:
SNIP
Quoted 14 lines
tools/perf/builtin-stat.c +4
-1@@ -892,7 +908,10 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,struct perf_stat_output_ctx out;struct outstate os = { .fh = stat_config.output, - .prefix = prefix ? prefix :"" + .prefix = prefix ? prefix :"" , + .id = id, + .nr = nr, + .evsel = counter, };print_metric_t pm = print_metric_std;void (*nl)(void *);@@ -962,15 +981,38 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,Quoted 6 lines
tools/perf/builtin-stat.c static void printout(int id, int nr, struct perf_evsel *counter, double uval, · line 984
Quoted 4 lines
tools/perf/builtin-stat.c +1
-1perf_stat__print_shadow_stats(counter, uval, stat_config.aggr_mode == AGGR_GLOBAL ? 0 : - cpu_map__id_to_cpu(id), + first_shadow_cpu(counter, id),hum, IIUC you need to handle
AGGR_NONEin here as well?
Quoted 2 lines
AFAIK it works.
aggr_get_idinfirst_shadow_cpuandcpu_map__id_to_cpuhandle this case, right?
it does not look like.. however it'll be more clear once there's the doc/comment about used cpus for aggr modes I asked for in here:
http://marc.info/?l=linux-kernel&m=145607533503803&w=2
thanks,
jirka
PATCH 4/6 perf, tools, stat: Document CSV format in manpage
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
With all the recently added fields in the perf stat CSV output we should finally document them in the man page. Do this here.
v2: Fix fields in documentation (Jiri)
v3: fix order of fields again (Jiri)
v4: Change order again.
--- tools/perf/Documentation/perf-stat.txt | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
tools/perf/Documentation/perf-stat.txt +21 -0
@@ -211,6 +211,27 @@ $ perf stat -- make -j Wall-clock time elapsed: 719.554352 msecs +CSV FORMAT +---------- + +With -x, perf stat is able to output a not-quite-CSV format output +Commas in the output are not put into "". To make it easy to parse +it is recommended to use a different character like -x \; + +The fields are in this order: + + - optional usec time stamp in fractions of second (with -I xxx) + - counter value + - unit of the counter value or empty + - event name + - run time of counter + - percentage of measurement time the counter was running + - optional variance if multiple values are collected with -r + - optional metric value + - optional unit of metric + +Additional metrics may be printed with all earlier fields being empty. + SEE ALSO -------- linkperf:perf-top[1], linkperf:perf-list[1]
Signature · 1 line
2.5.0
PATCH 5/6 perf, tools, stat: Implement --metric-only mode
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Add a new mode to only print metrics. Sometimes we don't care about the raw values, just want the computed metrics. This allows more compact printing, so with -I each sample is only a single line. This also allows easier plotting and processing with other tools.
The main target is with using --topdown, but it also works with -T and standard perf stat. A few metrics are not supported.
To avoiding having to hardcode all the metrics in the code it uses a two pass approach: first compute dummy metrics and only print the headers in the print_metric callback. Then use the callback to print the actual values.
There are some additional changes
in the stat printout code to handle all metrics being on a single line.
One issue is that the column code doesn't know in advance what events are not supported by the CPU, and it would be hard to find out as this could change based on dynamic conditions. That causes empty columns in some cases.
The output can be fairly wide, often you may need more than 80 columns.
Example:
% perf stat -a -I 1000 --metric-only
1.000604977 frontend cycles idle backend cycles idle insn per cycle stalled cycles per insn branch-misses of all branches
1.000604977 0.76 2.35%
2.000924680 0.72 2.34%
3.001139592 0.76 2.57%
4.001358452 0.73 2.44%v2: Lots of updates.
v3: Use slightly narrower columns
--- tools/perf/Documentation/perf-stat.txt | 4 + tools/perf/builtin-stat.c | 207 +++++++++++++++++++++++++++++++-- 2 files changed, 201 insertions(+), 10 deletions(-)
tools/perf/Documentation/perf-stat.txt +4 -0
@@ -139,6 +139,10 @@ Print count deltas every N milliseconds (minimum: 10ms) The overhead percentage could be high in some cases, for instance with small, sub 100ms intervals. Use with caution. example: 'perf stat -I 1000 -e cycles -a sleep 5' +--metric-only:: +Only print computed metrics. Print them in a single line. +Don't show any raw values. Not supported with -A or --per-thread. + --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,
tools/perf/builtin-stat.c +197 -10
320 lines not on this page · raw message
Signature · 1 line
2.5.0
PATCH 6/6 perf, tools, stat: Add --metric-only support for -A
In reply to Andi KleenFrom: Andi Kleen <[email protected]>
Add metric only support for -A too. This requires a new print function that prints the metrics in the right order.
v2: Fix manpage
--- tools/perf/Documentation/perf-stat.txt | 2 +- tools/perf/builtin-stat.c | 48 ++++++++++++++++++++++++++++------ 2 files changed, 41 insertions(+), 9 deletions(-)
tools/perf/Documentation/perf-stat.txt +1 -1
@@ -141,7 +141,7 @@ The overhead percentage could be high in some cases, for instance with small, su --metric-only:: Only print computed metrics. Print them in a single line. -Don't show any raw values. Not supported with -A or --per-thread. +Don't show any raw values. Not supported with --per-thread. --per-socket:: Aggregate counts per processor socket for system-wide mode measurements. This
tools/perf/builtin-stat.c +40 -8
69 lines not on this page · raw message
Signature · 1 line
2.5.0