xref: /linux/tools/perf/util/metricgroup.h (revision 6c8c1406)
1 // SPDX-License-Identifier: GPL-2.0-only
2 #ifndef METRICGROUP_H
3 #define METRICGROUP_H 1
4 
5 #include <linux/list.h>
6 #include <linux/rbtree.h>
7 #include <stdbool.h>
8 #include "pmu-events/pmu-events.h"
9 
10 struct evlist;
11 struct evsel;
12 struct option;
13 struct rblist;
14 struct cgroup;
15 
16 /**
17  * A node in a rblist keyed by the evsel. The global rblist of metric events
18  * generally exists in perf_stat_config. The evsel is looked up in the rblist
19  * yielding a list of metric_expr.
20  */
21 struct metric_event {
22 	struct rb_node nd;
23 	struct evsel *evsel;
24 	struct list_head head; /* list of metric_expr */
25 };
26 
27 /**
28  * A metric referenced by a metric_expr. When parsing a metric expression IDs
29  * will be looked up, matching either a value (from metric_events) or a
30  * metric_ref. A metric_ref will then be parsed recursively. The metric_refs and
31  * metric_events need to be known before parsing so that their values may be
32  * placed in the parse context for lookup.
33  */
34 struct metric_ref {
35 	const char *metric_name;
36 	const char *metric_expr;
37 };
38 
39 /**
40  * One in a list of metric_expr associated with an evsel. The data is used to
41  * generate a metric value during stat output.
42  */
43 struct metric_expr {
44 	struct list_head nd;
45 	/** The expression to parse, for example, "instructions/cycles". */
46 	const char *metric_expr;
47 	/** The name of the meric such as "IPC". */
48 	const char *metric_name;
49 	/**
50 	 * The "ScaleUnit" that scales and adds a unit to the metric during
51 	 * output. For example, "6.4e-05MiB" means to scale the resulting metric
52 	 * by 6.4e-05 (typically converting a unit like cache lines to something
53 	 * more human intelligible) and then add "MiB" afterward when displayed.
54 	 */
55 	const char *metric_unit;
56 	/** Null terminated array of events used by the metric. */
57 	struct evsel **metric_events;
58 	/** Null terminated array of referenced metrics. */
59 	struct metric_ref *metric_refs;
60 	/** A value substituted for '?' during parsing. */
61 	int runtime;
62 };
63 
64 struct metric_event *metricgroup__lookup(struct rblist *metric_events,
65 					 struct evsel *evsel,
66 					 bool create);
67 int metricgroup__parse_groups(struct evlist *perf_evlist,
68 			      const char *str,
69 			      bool metric_no_group,
70 			      bool metric_no_merge,
71 			      const char *user_requested_cpu_list,
72 			      bool system_wide,
73 			      struct rblist *metric_events);
74 int metricgroup__parse_groups_test(struct evlist *evlist,
75 				   const struct pmu_events_table *table,
76 				   const char *str,
77 				   bool metric_no_group,
78 				   bool metric_no_merge,
79 				   struct rblist *metric_events);
80 
81 void metricgroup__print(bool metrics, bool groups, char *filter,
82 			bool raw, bool details, const char *pmu_name);
83 bool metricgroup__has_metric(const char *metric);
84 int arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused);
85 void metricgroup__rblist_exit(struct rblist *metric_events);
86 
87 int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
88 				    struct rblist *new_metric_events,
89 				    struct rblist *old_metric_events);
90 #endif
91