2019-08-21 21:54:14 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2017-09-01 03:40:31 +08:00
|
|
|
#ifndef METRICGROUP_H
|
|
|
|
#define METRICGROUP_H 1
|
|
|
|
|
2019-08-21 21:54:14 +08:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/rbtree.h>
|
|
|
|
#include <stdbool.h>
|
2020-09-07 14:41:32 +08:00
|
|
|
#include "pmu-events/pmu-events.h"
|
2019-08-21 21:54:14 +08:00
|
|
|
|
2020-09-24 20:44:53 +08:00
|
|
|
struct evlist;
|
2019-08-21 21:54:14 +08:00
|
|
|
struct evsel;
|
|
|
|
struct option;
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
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: 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: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-15 05:07:22 +08:00
|
|
|
struct print_callbacks;
|
2019-08-21 21:54:14 +08:00
|
|
|
struct rblist;
|
2020-09-24 20:44:53 +08:00
|
|
|
struct cgroup;
|
2017-09-01 03:40:31 +08:00
|
|
|
|
2021-10-16 01:21:21 +08:00
|
|
|
/**
|
|
|
|
* A node in a rblist keyed by the evsel. The global rblist of metric events
|
|
|
|
* generally exists in perf_stat_config. The evsel is looked up in the rblist
|
|
|
|
* yielding a list of metric_expr.
|
|
|
|
*/
|
2017-09-01 03:40:31 +08:00
|
|
|
struct metric_event {
|
|
|
|
struct rb_node nd;
|
2019-07-21 19:23:51 +08:00
|
|
|
struct evsel *evsel;
|
2023-06-16 11:14:16 +08:00
|
|
|
bool is_default; /* the metric evsel from the Default metricgroup */
|
2017-09-01 03:40:31 +08:00
|
|
|
struct list_head head; /* list of metric_expr */
|
|
|
|
};
|
|
|
|
|
2021-10-16 01:21:21 +08:00
|
|
|
/**
|
|
|
|
* A metric referenced by a metric_expr. When parsing a metric expression IDs
|
|
|
|
* will be looked up, matching either a value (from metric_events) or a
|
|
|
|
* metric_ref. A metric_ref will then be parsed recursively. The metric_refs and
|
|
|
|
* metric_events need to be known before parsing so that their values may be
|
|
|
|
* placed in the parse context for lookup.
|
|
|
|
*/
|
2020-07-20 02:13:10 +08:00
|
|
|
struct metric_ref {
|
|
|
|
const char *metric_name;
|
|
|
|
const char *metric_expr;
|
|
|
|
};
|
|
|
|
|
2021-10-16 01:21:21 +08:00
|
|
|
/**
|
|
|
|
* One in a list of metric_expr associated with an evsel. The data is used to
|
|
|
|
* generate a metric value during stat output.
|
|
|
|
*/
|
2017-09-01 03:40:31 +08:00
|
|
|
struct metric_expr {
|
|
|
|
struct list_head nd;
|
2021-10-16 01:21:21 +08:00
|
|
|
/** The expression to parse, for example, "instructions/cycles". */
|
2017-09-01 03:40:31 +08:00
|
|
|
const char *metric_expr;
|
2021-10-16 01:21:21 +08:00
|
|
|
/** The name of the meric such as "IPC". */
|
2017-09-01 03:40:31 +08:00
|
|
|
const char *metric_name;
|
2023-02-19 17:28:33 +08:00
|
|
|
const char *metric_threshold;
|
2021-10-16 01:21:21 +08:00
|
|
|
/**
|
|
|
|
* The "ScaleUnit" that scales and adds a unit to the metric during
|
|
|
|
* output. For example, "6.4e-05MiB" means to scale the resulting metric
|
|
|
|
* by 6.4e-05 (typically converting a unit like cache lines to something
|
|
|
|
* more human intelligible) and then add "MiB" afterward when displayed.
|
|
|
|
*/
|
perf metricgroup: Scale the metric result
Some metrics define the scale unit, such as
{
"BriefDescription": "Intel Optane DC persistent memory read latency (ns). Derived from unc_m_pmm_rpq_occupancy.all",
"Counter": "0,1,2,3",
"EventCode": "0xE0",
"EventName": "UNC_M_PMM_READ_LATENCY",
"MetricExpr": "UNC_M_PMM_RPQ_OCCUPANCY.ALL / UNC_M_PMM_RPQ_INSERTS / UNC_M_CLOCKTICKS",
"MetricName": "UNC_M_PMM_READ_LATENCY",
"PerPkg": "1",
"ScaleUnit": "6000000000ns",
"UMask": "0x1",
"Unit": "iMC"
},
For above example, the ratio should be,
ratio = (UNC_M_PMM_RPQ_OCCUPANCY.ALL / UNC_M_PMM_RPQ_INSERTS / UNC_M_CLOCKTICKS) * 6000000000
But in current code, the ratio is not scaled ( * 6000000000)
With this patch, the ratio is scaled and the unit (ns) is printed.
For example,
# 219.4 ns UNC_M_PMM_READ_LATENCY
Signed-off-by: Jin Yao <yao.jin@linux.intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Link: http://lore.kernel.org/lkml/20190828055932.8269-4-yao.jin@linux.intel.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2019-08-28 13:59:31 +08:00
|
|
|
const char *metric_unit;
|
2023-06-16 11:14:16 +08:00
|
|
|
/** Displayed metricgroup name of the Default metricgroup */
|
|
|
|
const char *default_metricgroup_name;
|
2021-10-16 01:21:21 +08:00
|
|
|
/** Null terminated array of events used by the metric. */
|
2019-07-21 19:23:51 +08:00
|
|
|
struct evsel **metric_events;
|
2021-10-16 01:21:21 +08:00
|
|
|
/** Null terminated array of referenced metrics. */
|
2020-07-20 02:13:10 +08:00
|
|
|
struct metric_ref *metric_refs;
|
2021-10-16 01:21:21 +08:00
|
|
|
/** A value substituted for '?' during parsing. */
|
perf metricgroups: Enhance JSON/metric infrastructure to handle "?"
Patch enhances current metric infrastructure to handle "?" in the metric
expression. The "?" can be use for parameters whose value not known
while creating metric events and which can be replace later at runtime
to the proper value. It also add flexibility to create multiple events
out of single metric event added in JSON file.
Patch adds function 'arch_get_runtimeparam' which is a arch specific
function, returns the count of metric events need to be created. By
default it return 1.
This infrastructure needed for hv_24x7 socket/chip level events.
"hv_24x7" chip level events needs specific chip-id to which the data is
requested. Function 'arch_get_runtimeparam' implemented in header.c
which extract number of sockets from sysfs file "sockets" under
"/sys/devices/hv_24x7/interface/".
With this patch basically we are trying to create as many metric events
as define by runtime_param.
For that one loop is added in function 'metricgroup__add_metric', which
create multiple events at run time depend on return value of
'arch_get_runtimeparam' and merge that event in 'group_list'.
To achieve that we are actually passing this parameter value as part of
`expr__find_other` function and changing "?" present in metric
expression with this value.
As in our JSON file, there gonna be single metric event, and out of
which we are creating multiple events.
To understand which data count belongs to which parameter value,
we also printing param value in generic_metric function.
For example,
command:# ./perf stat -M PowerBUS_Frequency -C 0 -I 1000
1.000101867 9,356,933 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
1.000101867 9,366,134 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1
2.000314878 9,365,868 hv_24x7/pm_pb_cyc,chip=0/ # 2.3 GHz PowerBUS_Frequency_0
2.000314878 9,366,092 hv_24x7/pm_pb_cyc,chip=1/ # 2.3 GHz PowerBUS_Frequency_1
So, here _0 and _1 after PowerBUS_Frequency specify parameter value.
Signed-off-by: Kajol Jain <kjain@linux.ibm.com>
Acked-by: Jiri Olsa <jolsa@redhat.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: Anju T Sudhakar <anju@linux.vnet.ibm.com>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Jin Yao <yao.jin@linux.intel.com>
Cc: Joe Mario <jmario@redhat.com>
Cc: Kan Liang <kan.liang@linux.intel.com>
Cc: Madhavan Srinivasan <maddy@linux.vnet.ibm.com>
Cc: Mamatha Inamdar <mamatha4@linux.vnet.ibm.com>
Cc: Mark Rutland <mark.rutland@arm.com>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Mackerras <paulus@ozlabs.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Ravi Bangoria <ravi.bangoria@linux.ibm.com>
Cc: Sukadev Bhattiprolu <sukadev@linux.vnet.ibm.com>
Cc: Thomas Gleixner <tglx@linutronix.de>
Cc: linuxppc-dev@lists.ozlabs.org
Link: http://lore.kernel.org/lkml/20200401203340.31402-5-kjain@linux.ibm.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2020-04-02 04:33:37 +08:00
|
|
|
int runtime;
|
2017-09-01 03:40:31 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct metric_event *metricgroup__lookup(struct rblist *metric_events,
|
2019-07-21 19:23:51 +08:00
|
|
|
struct evsel *evsel,
|
2017-09-01 03:40:31 +08:00
|
|
|
bool create);
|
2022-09-01 01:49:24 +08:00
|
|
|
int metricgroup__parse_groups(struct evlist *perf_evlist,
|
2023-05-03 06:38:46 +08:00
|
|
|
const char *pmu,
|
2020-05-21 02:20:10 +08:00
|
|
|
const char *str,
|
|
|
|
bool metric_no_group,
|
|
|
|
bool metric_no_merge,
|
2023-02-19 17:28:35 +08:00
|
|
|
bool metric_no_threshold,
|
2022-09-01 01:49:25 +08:00
|
|
|
const char *user_requested_cpu_list,
|
|
|
|
bool system_wide,
|
2020-05-21 02:20:10 +08:00
|
|
|
struct rblist *metric_events);
|
2020-06-03 05:47:36 +08:00
|
|
|
int metricgroup__parse_groups_test(struct evlist *evlist,
|
2023-01-27 07:36:39 +08:00
|
|
|
const struct pmu_metrics_table *table,
|
2020-06-03 05:47:36 +08:00
|
|
|
const char *str,
|
|
|
|
struct rblist *metric_events);
|
|
|
|
|
perf list: Reorganize to use callbacks to allow honouring command line options
Rather than controlling the list output with passed flags, add
callbacks that are called when an event or metric are
encountered. State is passed to the callback so that command line
options can be respected, alternatively the callbacks can be changed.
Fix a few bugs:
- wordwrap to columns metric descriptions and expressions;
- remove unnecessary whitespace after PMU event names;
- the metric filter is a glob but matched using strstr which will
always fail, switch to using a proper globmatch,
- the detail flag gives details for extra kernel PMU events like
branch-instructions.
In metricgroup.c switch from struct mep being a rbtree of metricgroups
containing a list of metrics, to the tree directly containing all the
metrics. In general the alias for a name is passed to the print
routine rather than being contained in the name with OR.
Committer notes:
Check the asprint() return to address this on fedora 36:
util/print-events.c: In function ‘print_sdt_events’:
util/print-events.c:183:33: error: ignoring return value of ‘asprintf’ declared with attribute ‘warn_unused_result’ [-Werror=unused-result]
183 | asprintf(&evt_name, "%s@%s(%.12s)", sdt_name->s, path, bid);
| ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
$ gcc --version | head -1
gcc (GCC) 12.2.1 20220819 (Red Hat 12.2.1-2)
$
Fix ps.pmu_glob setting when dealing with *:* events, it was being left
with a freed pointer that then at the end of cmd_list() would be double
freed.
Check if pmu_name is NULL in default_print_event() before calling
strglobmatch(pmu_name, ...) to avoid a segfault.
Signed-off-by: Ian Rogers <irogers@google.com>
Cc: Adrian Hunter <adrian.hunter@intel.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Caleb Biggers <caleb.biggers@intel.com>
Cc: Jiri Olsa <jolsa@kernel.org>
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: 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: Rob Herring <robh@kernel.org>
Cc: Sandipan Das <sandipan.das@amd.com>
Cc: Stephane Eranian <eranian@google.com>
Cc: Weilin Wang <weilin.wang@intel.com>
Cc: Xin Gao <gaoxin@cdjrlc.com>
Cc: Xing Zhengjun <zhengjun.xing@linux.intel.com>
Link: http://lore.kernel.org/lkml/20221114210723.2749751-10-irogers@google.com
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
2022-11-15 05:07:22 +08:00
|
|
|
void metricgroup__print(const struct print_callbacks *print_cb, void *print_state);
|
2023-05-03 06:38:45 +08:00
|
|
|
bool metricgroup__has_metric(const char *pmu, const char *metric);
|
2023-02-19 17:28:37 +08:00
|
|
|
unsigned int metricgroups__topdown_max_level(void);
|
2023-01-27 07:36:34 +08:00
|
|
|
int arch_get_runtimeparam(const struct pmu_metric *pm);
|
2020-06-03 05:47:38 +08:00
|
|
|
void metricgroup__rblist_exit(struct rblist *metric_events);
|
2020-09-24 20:44:53 +08:00
|
|
|
|
|
|
|
int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
|
|
|
|
struct rblist *new_metric_events,
|
|
|
|
struct rblist *old_metric_events);
|
2017-09-01 03:40:31 +08:00
|
|
|
#endif
|