aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJiri Olsa <jolsa@kernel.org>2018-06-06 18:15:08 -0400
committerArnaldo Carvalho de Melo <acme@redhat.com>2018-06-07 14:59:13 -0400
commitf515572734fb323aa0efe9ea2c546cd7fee327f7 (patch)
treeae92d8a4579d32f5fd91bc3bfd8eccddbab2b067
parentb37d33edbf41b532ddd156707c037c6f4784e40b (diff)
perf stat: Fix metric column header display alignment
Make the metric only display aligned. Before: # perf stat --topdown -I 1000 # time core cpus retiring bad speculation frontend bound backend bound 1.000394323 S0-C0 2 37.4% 12.0% 31.4% 19.2% 1.000394323 S0-C1 2 25.1% 9.2% 43.8% 21.9% 2.001521204 S0-C0 2 36.4% 11.4% 32.4% 19.8% 2.001521204 S0-C1 2 26.2% 9.4% 43.1% 21.3% 3.001930208 S0-C0 2 35.1% 10.7% 33.6% 20.6% 3.001930208 S0-C1 2 28.9% 10.0% 40.0% 21.1% After: # perf stat --topdown -I 1000 # time core cpus retiring bad speculation frontend bound backend bound 1.000303722 S0-C0 2 34.2% 7.6% 34.2% 24.0% 1.000303722 S0-C1 2 33.1% 6.4% 36.9% 23.6% 2.001281055 S0-C0 2 34.6% 6.7% 36.8% 21.8% 2.001281055 S0-C1 2 32.8% 7.1% 38.1% 22.0% 3.001546080 S0-C0 2 39.3% 5.5% 32.7% 22.5% 3.001546080 S0-C1 2 37.8% 6.0% 33.1% 23.1% Signed-off-by: Jiri Olsa <jolsa@kernel.org> Tested-by: Arnaldo Carvalho de Melo <acme@redhat.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <andi@firstfloor.org> Cc: David Ahern <dsahern@gmail.com> Cc: Frederic Weisbecker <frederic@kernel.org> Cc: Milian Wolff <milian.wolff@kdab.com> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Stephane Eranian <eranian@google.com> Link: http://lkml.kernel.org/r/20180606221513.11302-6-jolsa@kernel.org Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
-rw-r--r--tools/perf/builtin-stat.c17
1 files changed, 9 insertions, 8 deletions
diff --git a/tools/perf/builtin-stat.c b/tools/perf/builtin-stat.c
index 9e7b6f108956..8f3fdc052728 100644
--- a/tools/perf/builtin-stat.c
+++ b/tools/perf/builtin-stat.c
@@ -1001,19 +1001,20 @@ static void print_metric_only(void *ctx, const char *color, const char *fmt,
1001{ 1001{
1002 struct outstate *os = ctx; 1002 struct outstate *os = ctx;
1003 FILE *out = os->fh; 1003 FILE *out = os->fh;
1004 int n; 1004 char buf[1024], str[1024];
1005 char buf[1024];
1006 unsigned mlen = METRIC_ONLY_LEN; 1005 unsigned mlen = METRIC_ONLY_LEN;
1007 1006
1008 if (!valid_only_metric(unit)) 1007 if (!valid_only_metric(unit))
1009 return; 1008 return;
1010 unit = fixunit(buf, os->evsel, unit); 1009 unit = fixunit(buf, os->evsel, unit);
1011 n = color_fprintf(out, color ?: "", fmt, val);
1012 if (n > METRIC_ONLY_LEN)
1013 n = METRIC_ONLY_LEN;
1014 if (mlen < strlen(unit)) 1010 if (mlen < strlen(unit))
1015 mlen = strlen(unit) + 1; 1011 mlen = strlen(unit) + 1;
1016 fprintf(out, "%*s", mlen - n, ""); 1012
1013 if (color)
1014 mlen += strlen(color) + sizeof(PERF_COLOR_RESET) - 1;
1015
1016 color_snprintf(str, sizeof(str), color ?: "", fmt, val);
1017 fprintf(out, "%*s ", mlen, str);
1017} 1018}
1018 1019
1019static void print_metric_only_csv(void *ctx, const char *color __maybe_unused, 1020static void print_metric_only_csv(void *ctx, const char *color __maybe_unused,
@@ -1053,7 +1054,7 @@ static void print_metric_header(void *ctx, const char *color __maybe_unused,
1053 if (csv_output) 1054 if (csv_output)
1054 fprintf(os->fh, "%s%s", unit, csv_sep); 1055 fprintf(os->fh, "%s%s", unit, csv_sep);
1055 else 1056 else
1056 fprintf(os->fh, "%-*s ", METRIC_ONLY_LEN, unit); 1057 fprintf(os->fh, "%*s ", METRIC_ONLY_LEN, unit);
1057} 1058}
1058 1059
1059static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg) 1060static void nsec_printout(int id, int nr, struct perf_evsel *evsel, double avg)
@@ -1721,7 +1722,7 @@ static void print_interval(char *prefix, struct timespec *ts)
1721 fprintf(output, " counts %*s events\n", unit_width, "unit"); 1722 fprintf(output, " counts %*s events\n", unit_width, "unit");
1722 break; 1723 break;
1723 case AGGR_NONE: 1724 case AGGR_NONE:
1724 fprintf(output, "# time CPU"); 1725 fprintf(output, "# time CPU ");
1725 if (!metric_only) 1726 if (!metric_only)
1726 fprintf(output, " counts %*s events\n", unit_width, "unit"); 1727 fprintf(output, " counts %*s events\n", unit_width, "unit");
1727 break; 1728 break;