Skip to content

Commit a29c164

Browse files
olsajiriacmel
authored andcommitted
perf metric: Add add_metric function
Decouple metric adding logging into add_metric function, so it can 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 ce39194 commit a29c164

File tree

1 file changed

+36
-26
lines changed

1 file changed

+36
-26
lines changed

tools/perf/util/metricgroup.c

Lines changed: 36 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -625,6 +625,39 @@ static int __metricgroup__add_metric(struct list_head *group_list,
625625
(match_metric(__pe->metric_group, __metric) || \
626626
match_metric(__pe->metric_name, __metric)))
627627

628+
static int add_metric(struct list_head *group_list,
629+
struct pmu_event *pe,
630+
bool metric_no_group)
631+
{
632+
int ret = 0;
633+
634+
pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
635+
636+
if (!strstr(pe->metric_expr, "?")) {
637+
ret = __metricgroup__add_metric(group_list,
638+
pe,
639+
metric_no_group,
640+
1);
641+
} else {
642+
int j, count;
643+
644+
count = arch_get_runtimeparam();
645+
646+
/* This loop is added to create multiple
647+
* events depend on count value and add
648+
* those events to group_list.
649+
*/
650+
651+
for (j = 0; j < count && !ret; j++) {
652+
ret = __metricgroup__add_metric(
653+
group_list, pe,
654+
metric_no_group, j);
655+
}
656+
}
657+
658+
return ret;
659+
}
660+
628661
static int metricgroup__add_metric(const char *metric, bool metric_no_group,
629662
struct strbuf *events,
630663
struct list_head *group_list,
@@ -636,34 +669,11 @@ static int metricgroup__add_metric(const char *metric, bool metric_no_group,
636669
bool has_match = false;
637670

638671
map_for_each_metric(pe, i, map, metric) {
639-
pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
640672
has_match = true;
641673

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;
651-
652-
count = arch_get_runtimeparam();
653-
654-
/* This loop is added to create multiple
655-
* events depend on count value and add
656-
* those events to group_list.
657-
*/
658-
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;
665-
}
666-
}
674+
ret = add_metric(group_list, pe, metric_no_group);
675+
if (ret)
676+
return ret;
667677
}
668678

669679
/* End of pmu events. */

0 commit comments

Comments
 (0)