perf list: Support for printing metric thresholds
authorIan Rogers <irogers@google.com>
Sun, 19 Feb 2023 09:28:32 +0000 (01:28 -0800)
committerArnaldo Carvalho de Melo <acme@redhat.com>
Sun, 19 Feb 2023 11:06:49 +0000 (08:06 -0300)
Add to json output by default. For regular output, only enable with
the --detail flag.

Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Alexandre Torgue <alexandre.torgue@foss.st.com>
Cc: Andrii Nakryiko <andrii@kernel.org>
Cc: Athira Rajeev <atrajeev@linux.vnet.ibm.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Eduard Zingerman <eddyz87@gmail.com>
Cc: Florian Fischer <florian.fischer@muhq.space>
Cc: Ingo Molnar <mingo@redhat.com>
Cc: James Clark <james.clark@arm.com>
Cc: Jing Zhang <renyu.zj@linux.alibaba.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: John Garry <john.g.garry@oracle.com>
Cc: Kajol Jain <kjain@linux.ibm.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Leo Yan <leo.yan@linaro.org>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Maxime Coquelin <mcoquelin.stm32@gmail.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Perry Taylor <perry.taylor@intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@amd.com>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Sean Christopherson <seanjc@google.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Suzuki Poulouse <suzuki.poulose@arm.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
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 <acme@redhat.com>
tools/perf/builtin-list.c
tools/perf/util/metricgroup.c
tools/perf/util/print-events.h

index 791f513..76e1d31 100644 (file)
@@ -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;
index 868fc9c..b1d56a7 100644 (file)
@@ -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);
index 716dcf4..e75a3d7 100644 (file)
@@ -23,6 +23,7 @@ struct print_callbacks {
                        const char *desc,
                        const char *long_desc,
                        const char *expr,
+                       const char *threshold,
                        const char *unit);
 };