Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #ifndef METRICGROUP_H
0003 #define METRICGROUP_H 1
0004 
0005 #include <linux/list.h>
0006 #include <linux/rbtree.h>
0007 #include <stdbool.h>
0008 #include "pmu-events/pmu-events.h"
0009 
0010 struct evlist;
0011 struct evsel;
0012 struct option;
0013 struct rblist;
0014 struct cgroup;
0015 
0016 /**
0017  * A node in a rblist keyed by the evsel. The global rblist of metric events
0018  * generally exists in perf_stat_config. The evsel is looked up in the rblist
0019  * yielding a list of metric_expr.
0020  */
0021 struct metric_event {
0022     struct rb_node nd;
0023     struct evsel *evsel;
0024     struct list_head head; /* list of metric_expr */
0025 };
0026 
0027 /**
0028  * A metric referenced by a metric_expr. When parsing a metric expression IDs
0029  * will be looked up, matching either a value (from metric_events) or a
0030  * metric_ref. A metric_ref will then be parsed recursively. The metric_refs and
0031  * metric_events need to be known before parsing so that their values may be
0032  * placed in the parse context for lookup.
0033  */
0034 struct metric_ref {
0035     const char *metric_name;
0036     const char *metric_expr;
0037 };
0038 
0039 /**
0040  * One in a list of metric_expr associated with an evsel. The data is used to
0041  * generate a metric value during stat output.
0042  */
0043 struct metric_expr {
0044     struct list_head nd;
0045     /** The expression to parse, for example, "instructions/cycles". */
0046     const char *metric_expr;
0047     /** The name of the meric such as "IPC". */
0048     const char *metric_name;
0049     /**
0050      * The "ScaleUnit" that scales and adds a unit to the metric during
0051      * output. For example, "6.4e-05MiB" means to scale the resulting metric
0052      * by 6.4e-05 (typically converting a unit like cache lines to something
0053      * more human intelligible) and then add "MiB" afterward when displayed.
0054      */
0055     const char *metric_unit;
0056     /** Null terminated array of events used by the metric. */
0057     struct evsel **metric_events;
0058     /** Null terminated array of referenced metrics. */
0059     struct metric_ref *metric_refs;
0060     /** A value substituted for '?' during parsing. */
0061     int runtime;
0062 };
0063 
0064 struct metric_event *metricgroup__lookup(struct rblist *metric_events,
0065                      struct evsel *evsel,
0066                      bool create);
0067 int metricgroup__parse_groups(const struct option *opt,
0068                   const char *str,
0069                   bool metric_no_group,
0070                   bool metric_no_merge,
0071                   struct rblist *metric_events);
0072 int metricgroup__parse_groups_test(struct evlist *evlist,
0073                    const struct pmu_events_table *table,
0074                    const char *str,
0075                    bool metric_no_group,
0076                    bool metric_no_merge,
0077                    struct rblist *metric_events);
0078 
0079 void metricgroup__print(bool metrics, bool groups, char *filter,
0080             bool raw, bool details, const char *pmu_name);
0081 bool metricgroup__has_metric(const char *metric);
0082 int arch_get_runtimeparam(const struct pmu_event *pe __maybe_unused);
0083 void metricgroup__rblist_exit(struct rblist *metric_events);
0084 
0085 int metricgroup__copy_metric_events(struct evlist *evlist, struct cgroup *cgrp,
0086                     struct rblist *new_metric_events,
0087                     struct rblist *old_metric_events);
0088 #endif