From c7551a2e33c60189147f84b17934cb5f1784d0dd Mon Sep 17 00:00:00 2001 From: Ian Rogers Date: Sun, 19 Feb 2023 01:28:32 -0800 Subject: [PATCH] perf list: Support for printing metric thresholds Add to json output by default. For regular output, only enable with the --detail flag. Signed-off-by: Ian Rogers Cc: Adrian Hunter Cc: Alexander Shishkin Cc: Alexandre Torgue Cc: Andrii Nakryiko Cc: Athira Rajeev Cc: Caleb Biggers Cc: Eduard Zingerman Cc: Florian Fischer Cc: Ingo Molnar Cc: James Clark Cc: Jing Zhang Cc: Jiri Olsa Cc: John Garry Cc: Kajol Jain Cc: Kan Liang Cc: Leo Yan Cc: Mark Rutland Cc: Maxime Coquelin Cc: Namhyung Kim Cc: Perry Taylor Cc: Peter Zijlstra Cc: Ravi Bangoria Cc: Sandipan Das Cc: Sean Christopherson Cc: Stephane Eranian Cc: Suzuki Poulouse Cc: Xing Zhengjun Cc: linux-arm-kernel@lists.infradead.org Cc: linux-stm32@st-md-mailman.stormreply.com Link: https://lore.kernel.org/r/20230219092848.639226-36-irogers@google.com Signed-off-by: Arnaldo Carvalho de Melo --- tools/perf/builtin-list.c | 13 ++++++++++++- tools/perf/util/metricgroup.c | 3 +++ tools/perf/util/print-events.h | 1 + 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/tools/perf/builtin-list.c b/tools/perf/builtin-list.c index 791f513ae5b4..76e1d31a68ee 100644 --- a/tools/perf/builtin-list.c +++ b/tools/perf/builtin-list.c @@ -168,6 +168,7 @@ static void default_print_metric(void *ps, const char *desc, const char *long_desc, const char *expr, + const char *threshold, const char *unit __maybe_unused) { struct print_state *print_state = ps; @@ -227,6 +228,11 @@ static void default_print_metric(void *ps, wordwrap(expr, 8, pager_get_columns(), 0); printf("]\n"); } + if (threshold && print_state->detailed) { + printf("%*s", 8, "["); + wordwrap(threshold, 8, pager_get_columns(), 0); + printf("]\n"); + } } struct json_print_state { @@ -367,7 +373,7 @@ static void json_print_event(void *ps, const char *pmu_name, const char *topic, static void json_print_metric(void *ps __maybe_unused, const char *group, const char *name, const char *desc, const char *long_desc, const char *expr, - const char *unit) + const char *threshold, const char *unit) { struct json_print_state *print_state = ps; bool need_sep = false; @@ -388,6 +394,11 @@ static void json_print_metric(void *ps __maybe_unused, const char *group, fix_escape_printf(&buf, "%s\t\"MetricExpr\": \"%S\"", need_sep ? ",\n" : "", expr); need_sep = true; } + if (threshold) { + fix_escape_printf(&buf, "%s\t\"MetricThreshold\": \"%S\"", need_sep ? ",\n" : "", + threshold); + need_sep = true; + } if (unit) { fix_escape_printf(&buf, "%s\t\"ScaleUnit\": \"%S\"", need_sep ? ",\n" : "", unit); need_sep = true; diff --git a/tools/perf/util/metricgroup.c b/tools/perf/util/metricgroup.c index 868fc9c35606..b1d56a73223d 100644 --- a/tools/perf/util/metricgroup.c +++ b/tools/perf/util/metricgroup.c @@ -368,6 +368,7 @@ struct mep { const char *metric_desc; const char *metric_long_desc; const char *metric_expr; + const char *metric_threshold; const char *metric_unit; }; @@ -447,6 +448,7 @@ static int metricgroup__add_to_mep_groups(const struct pmu_metric *pm, me->metric_desc = pm->desc; me->metric_long_desc = pm->long_desc; me->metric_expr = pm->metric_expr; + me->metric_threshold = pm->metric_threshold; me->metric_unit = pm->unit; } } @@ -522,6 +524,7 @@ void metricgroup__print(const struct print_callbacks *print_cb, void *print_stat me->metric_desc, me->metric_long_desc, me->metric_expr, + me->metric_threshold, me->metric_unit); next = rb_next(node); rblist__remove_node(&groups, node); diff --git a/tools/perf/util/print-events.h b/tools/perf/util/print-events.h index 716dcf4b4859..e75a3d7e3fe3 100644 --- a/tools/perf/util/print-events.h +++ b/tools/perf/util/print-events.h @@ -23,6 +23,7 @@ struct print_callbacks { const char *desc, const char *long_desc, const char *expr, + const char *threshold, const char *unit); };