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