Commit ce391940 authored by Jiri Olsa's avatar Jiri Olsa Committed by Arnaldo Carvalho de Melo
Browse files

perf metric: Add macros for iterating map events



Adding following macros to iterate events and metric:

  map_for_each_event(__pe, __idx, __map)
    - iterates over all pmu_events_map events

  map_for_each_metric(__pe, __idx, __map, __metric)
    - iterates over all metrics that match __metric argument

and use it in metricgroup__add_metric function. Macros will be be used
from other places in following changes.

Signed-off-by: default avatarJiri Olsa <jolsa@kernel.org>
Reviewed-by: default avatarKajol Jain <kjain@linux.ibm.com>
Acked-by: default avatarIan Rogers <irogers@google.com>
Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com>
Cc: Andi Kleen <ak@linux.intel.com>
Cc: John Garry <john.garry@huawei.com>
Cc: Michael Petlan <mpetlan@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Cc: Paul Clarke <pc@us.ibm.com>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lore.kernel.org/lkml/20200719181320.785305-6-jolsa@kernel.org


Signed-off-by: default avatarArnaldo Carvalho de Melo <acme@redhat.com>
parent 3fd29fa6
Loading
Loading
Loading
Loading
+40 −37
Original line number Diff line number Diff line
@@ -614,6 +614,17 @@ static int __metricgroup__add_metric(struct list_head *group_list,
	return 0;
}

#define map_for_each_event(__pe, __idx, __map)				\
	for (__idx = 0, __pe = &__map->table[__idx];			\
	     __pe->name || __pe->metric_group || __pe->metric_name;	\
	     __pe = &__map->table[++__idx])

#define map_for_each_metric(__pe, __idx, __map, __metric)		\
	map_for_each_event(__pe, __idx, __map)				\
		if (__pe->metric_expr &&				\
		    (match_metric(__pe->metric_group, __metric) ||	\
		     match_metric(__pe->metric_name, __metric)))

static int metricgroup__add_metric(const char *metric, bool metric_no_group,
				   struct strbuf *events,
				   struct list_head *group_list,
@@ -624,21 +635,9 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
	int i, ret;
	bool has_match = false;

	for (i = 0; ; i++) {
		pe = &map->table[i];

		if (!pe->name && !pe->metric_group && !pe->metric_name) {
			/* End of pmu events. */
			if (!has_match)
				return -EINVAL;
			break;
		}
		if (!pe->metric_expr)
			continue;
		if (match_metric(pe->metric_group, metric) ||
		    match_metric(pe->metric_name, metric)) {
			has_match = true;
	map_for_each_metric(pe, i, map, metric) {
		pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
		has_match = true;

		if (!strstr(pe->metric_expr, "?")) {
			ret = __metricgroup__add_metric(group_list,
@@ -666,7 +665,11 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
			}
		}
	}
	}

	/* End of pmu events. */
	if (!has_match)
		return -EINVAL;

	list_for_each_entry(eg, group_list, nd) {
		if (events->len > 0)
			strbuf_addf(events, ",");