aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndi Kleen <ak@linux.intel.com>2016-02-29 17:36:21 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2016-03-03 09:10:36 -0500
commit92a61f6412d3a09d6462252a522fa79c9290f405 (patch)
tree1bfcdc6dc01c03abb1a65f7af31b1955cb27ff90
parent95c365617aa37878592f2f1c6c64e1abb19f0d4a (diff)
perf stat: Implement CSV metrics output
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 $ 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 branches Two 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 v8: Remove extra run, ena fields v9: Avoid extra new line for unsupported counters Signed-off-by: Andi Kleen <ak@linux.intel.com> Acked-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Link: http://lkml.kernel.org/r/1456785386-19481-3-git-send-email-andi@firstfloor.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-stat.c73
-rw-r--r--tools/perf/util/stat-shadow.c2
2 files changed, 70 insertions, 5 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 24f222dd2a8a..2ffb8221917a 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -739,6 +739,7 @@ struct outstate {
739 FILE *fh; 739 FILE *fh;
740 bool newline; 740 bool newline;
741 const char *prefix; 741 const char *prefix;
742 int nfields;
742}; 743};
743 744
744#define METRIC_LEN 35 745#define METRIC_LEN 35
@@ -789,6 +790,43 @@ static void print_metric_std(void *ctx, const char *color, const char *fmt,
789 fprintf(out, " %-*s", METRIC_LEN - n - 1, unit); 790 fprintf(out, " %-*s", METRIC_LEN - n - 1, unit);
790} 791}
791 792
793static void new_line_csv(void *ctx)
794{
795 struct outstate *os = ctx;
796 int i;
797
798 fputc('\n', os->fh);
799 if (os->prefix)
800 fprintf(os->fh, "%s%s", os->prefix, csv_sep);
801 for (i = 0; i < os->nfields; i++)
802 fputs(csv_sep, os->fh);
803}
804
805static void print_metric_csv(void *ctx,
806 const char *color __maybe_unused,
807 const char *fmt, const char *unit, double val)
808{
809 struct outstate *os = ctx;
810 FILE *out = os->fh;
811 char buf[64], *vals, *ends;
812
813 if (unit == NULL || fmt == NULL) {
814 fprintf(out, "%s%s%s%s", csv_sep, csv_sep, csv_sep, csv_sep);
815 return;
816 }
817 snprintf(buf, sizeof(buf), fmt, val);
818 vals = buf;
819 while (isspace(*vals))
820 vals++;
821 ends = vals;
822 while (isdigit(*ends) || *ends == '.')
823 ends++;
824 *ends = 0;
825 while (isspace(*unit))
826 unit++;
827 fprintf(out, "%s%s%s%s", csv_sep, vals, csv_sep, unit);
828}
829
792static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg) 830static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
793{ 831{
794 FILE *output = stat_config.output; 832 FILE *output = stat_config.output;
@@ -860,6 +898,22 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,
860 898
861 nl = new_line_std; 899 nl = new_line_std;
862 900
901 if (csv_output) {
902 static int aggr_fields[] = {
903 [AGGR_GLOBAL] = 0,
904 [AGGR_THREAD] = 1,
905 [AGGR_NONE] = 1,
906 [AGGR_SOCKET] = 2,
907 [AGGR_CORE] = 2,
908 };
909
910 pm = print_metric_csv;
911 nl = new_line_csv;
912 os.nfields = 3;
913 os.nfields += aggr_fields[stat_config.aggr_mode];
914 if (counter->cgrp)
915 os.nfields++;
916 }
863 if (run == 0 || ena == 0 || counter->counts->scaled == -1) { 917 if (run == 0 || ena == 0 || counter->counts->scaled == -1) {
864 aggr_printout(counter, id, nr); 918 aggr_printout(counter, id, nr);
865 919
@@ -880,7 +934,12 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,
880 fprintf(stat_config.output, "%s%s", 934 fprintf(stat_config.output, "%s%s",
881 csv_sep, counter->cgrp->name); 935 csv_sep, counter->cgrp->name);
882 936
937 if (!csv_output)
938 pm(&os, NULL, NULL, "", 0);
939 print_noise(counter, noise);
883 print_running(run, ena); 940 print_running(run, ena);
941 if (csv_output)
942 pm(&os, NULL, NULL, "", 0);
884 return; 943 return;
885 } 944 }
886 945
@@ -893,14 +952,20 @@ static void printout(int id, int nr, struct perf_evsel *counter, double uval,
893 out.new_line = nl; 952 out.new_line = nl;
894 out.ctx = &os; 953 out.ctx = &os;
895 954
896 if (!csv_output) 955 if (csv_output) {
897 perf_stat__print_shadow_stats(counter, uval, 956 print_noise(counter, noise);
957 print_running(run, ena);
958 }
959
960 perf_stat__print_shadow_stats(counter, uval,
898 stat_config.aggr_mode == AGGR_GLOBAL ? 0 : 961 stat_config.aggr_mode == AGGR_GLOBAL ? 0 :
899 cpu_map__id_to_cpu(id), 962 cpu_map__id_to_cpu(id),
900 &out); 963 &out);
901 964
902 print_noise(counter, noise); 965 if (!csv_output) {
903 print_running(run, ena); 966 print_noise(counter, noise);
967 print_running(run, ena);
968 }
904} 969}
905 970
906static void print_aggr(char *prefix) 971static void print_aggr(char *prefix)
diff --git a/tools/perf/util/stat-shadow.c b/tools/perf/util/stat-shadow.c
index 4d8f18581b9b..367e220e93d5 100644
--- a/tools/perf/util/stat-shadow.c
+++ b/tools/perf/util/stat-shadow.c
@@ -310,8 +310,8 @@ void perf_stat__print_shadow_stats(struct perf_evsel *evsel,
310 total = avg_stats(&runtime_stalled_cycles_front_stats[ctx][cpu]); 310 total = avg_stats(&runtime_stalled_cycles_front_stats[ctx][cpu]);
311 total = max(total, avg_stats(&runtime_stalled_cycles_back_stats[ctx][cpu])); 311 total = max(total, avg_stats(&runtime_stalled_cycles_back_stats[ctx][cpu]));
312 312
313 out->new_line(ctxp);
314 if (total && avg) { 313 if (total && avg) {
314 out->new_line(ctxp);
315 ratio = total / avg; 315 ratio = total / avg;
316 print_metric(ctxp, NULL, "%7.2f ", 316 print_metric(ctxp, NULL, "%7.2f ",
317 "stalled cycles per insn", 317 "stalled cycles per insn",