mirror of
https://mirrors.bfsu.edu.cn/git/linux.git
synced 2024-12-15 23:14:31 +08:00
e5c6109f48
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>
91 lines
2.9 KiB
C
91 lines
2.9 KiB
C
// SPDX-License-Identifier: GPL-2.0-only
|
|
#ifndef METRICGROUP_H
|
|
#define METRICGROUP_H 1
|
|
|
|
#include <linux/list.h>
|
|
#include <linux/rbtree.h>
|
|
#include <stdbool.h>
|
|
#include "pmu-events/pmu-events.h"
|
|
|
|
struct evlist;
|
|
struct evsel;
|
|
struct option;
|
|
struct print_callbacks;
|
|
struct rblist;
|
|
struct cgroup;
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
struct metric_event {
|
|
struct rb_node nd;
|
|
struct evsel *evsel;
|
|
struct list_head head; /* list of metric_expr */
|
|
};
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
struct metric_ref {
|
|
const char *metric_name;
|
|
const char *metric_expr;
|
|
};
|
|
|
|
/**
|
|
* One in a list of metric_expr associated with an evsel. The data is used to
|
|
* generate a metric value during stat output.
|
|
*/
|
|
struct metric_expr {
|
|
struct list_head nd;
|
|
/** The expression to parse, for example, "instructions/cycles". */
|
|
const char *metric_expr;
|
|
/** The name of the meric such as "IPC". */
|
|
const char *metric_name;
|
|
/**
|
|
* 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.
|
|
*/
|
|
const char *metric_unit;
|
|
/** Null terminated array of events used by the metric. */
|
|
struct evsel **metric_events;
|
|
/** Null terminated array of referenced metrics. */
|
|
struct metric_ref *metric_refs;
|
|
/** A value substituted for '?' during parsing. */
|
|
int runtime;
|
|
};
|
|
|
|
struct metric_event *metricgroup__lookup(struct rblist *metric_events,
|
|
struct evsel *evsel,
|
|
bool create);
|
|
int metricgroup__parse_groups(struct evlist *perf_evlist,
|
|
const char *str,
|
|
bool metric_no_group,
|
|
bool metric_no_merge,
|
|
const char *user_requested_cpu_list,
|
|
bool system_wide,
|
|
struct rblist *metric_events);
|
|
int metricgroup__parse_groups_test(struct evlist *evlist,
|
|
const struct pmu_events_table *table,
|
|
const char *str,
|
|
bool metric_no_group,
|
|
bool metric_no_merge,
|
|
struct rblist *metric_events);
|
|
|
|
void metricgroup__print(const struct print_callbacks *print_cb, void *print_state);
|
|
bool metricgroup__has_metric(const char *metric);
|
|
int arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused);
|
|
void metricgroup__rblist_exit(struct rblist *metric_events);
|
|
|
|
int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
|
|
struct rblist *new_metric_events,
|
|
struct rblist *old_metric_events);
|
|
#endif
|