Skip to content

Commit ce39194

Browse files
olsajiriacmel
authored andcommitted
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: Jiri Olsa <[email protected]> Reviewed-by: Kajol Jain <[email protected]> Acked-by: Ian Rogers <[email protected]> Cc: Alexander Shishkin <[email protected]> Cc: Andi Kleen <[email protected]> Cc: John Garry <[email protected]> Cc: Michael Petlan <[email protected]> Cc: Namhyung Kim <[email protected]> Cc: Paul Clarke <[email protected]> Cc: Peter Zijlstra <[email protected]> Cc: Stephane Eranian <[email protected]> Link: http://lore.kernel.org/lkml/[email protected] Signed-off-by: Arnaldo Carvalho de Melo <[email protected]>
1 parent 3fd29fa commit ce39194

File tree

1 file changed

+40
-37
lines changed

1 file changed

+40
-37
lines changed

tools/perf/util/metricgroup.c

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -614,6 +614,17 @@ static int __metricgroup__add_metric(struct list_head *group_list,
614614
return 0;
615615
}
616616

617+
#define map_for_each_event(__pe, __idx, __map) \
618+
for (__idx = 0, __pe = &__map->table[__idx]; \
619+
__pe->name || __pe->metric_group || __pe->metric_name; \
620+
__pe = &__map->table[++__idx])
621+
622+
#define map_for_each_metric(__pe, __idx, __map, __metric) \
623+
map_for_each_event(__pe, __idx, __map) \
624+
if (__pe->metric_expr && \
625+
(match_metric(__pe->metric_group, __metric) || \
626+
match_metric(__pe->metric_name, __metric)))
627+
617628
static int metricgroup__add_metric(const char *metric, bool metric_no_group,
618629
struct strbuf *events,
619630
struct list_head *group_list,
@@ -624,49 +635,41 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
624635
int i, ret;
625636
bool has_match = false;
626637

627-
for (i = 0; ; i++) {
628-
pe = &map->table[i];
629-
630-
if (!pe->name && !pe->metric_group && !pe->metric_name) {
631-
/* End of pmu events. */
632-
if (!has_match)
633-
return -EINVAL;
634-
break;
635-
}
636-
if (!pe->metric_expr)
637-
continue;
638-
if (match_metric(pe->metric_group, metric) ||
639-
match_metric(pe->metric_name, metric)) {
640-
has_match = true;
641-
pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
642-
643-
if (!strstr(pe->metric_expr, "?")) {
644-
ret = __metricgroup__add_metric(group_list,
645-
pe,
646-
metric_no_group,
647-
1);
648-
if (ret)
649-
return ret;
650-
} else {
651-
int j, count;
638+
map_for_each_metric(pe, i, map, metric) {
639+
pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
640+
has_match = true;
641+
642+
if (!strstr(pe->metric_expr, "?")) {
643+
ret = __metricgroup__add_metric(group_list,
644+
pe,
645+
metric_no_group,
646+
1);
647+
if (ret)
648+
return ret;
649+
} else {
650+
int j, count;
652651

653-
count = arch_get_runtimeparam();
652+
count = arch_get_runtimeparam();
654653

655-
/* This loop is added to create multiple
656-
* events depend on count value and add
657-
* those events to group_list.
658-
*/
654+
/* This loop is added to create multiple
655+
* events depend on count value and add
656+
* those events to group_list.
657+
*/
659658

660-
for (j = 0; j < count; j++) {
661-
ret = __metricgroup__add_metric(
662-
group_list, pe,
663-
metric_no_group, j);
664-
if (ret)
665-
return ret;
666-
}
659+
for (j = 0; j < count; j++) {
660+
ret = __metricgroup__add_metric(
661+
group_list, pe,
662+
metric_no_group, j);
663+
if (ret)
664+
return ret;
667665
}
668666
}
669667
}
668+
669+
/* End of pmu events. */
670+
if (!has_match)
671+
return -EINVAL;
672+
670673
list_for_each_entry(eg, group_list, nd) {
671674
if (events->len > 0)
672675
strbuf_addf(events, ",");

0 commit comments

Comments
 (0)