Skip to content

Commit f6fe1e4

Browse files
John Garryacmel
authored andcommitted
perf metricgroup: Split up metricgroup__print()
To aid supporting system event metric groups, break up the function metricgroup__print() into a part which iterates metrics and a part which actually "prints" the metric. No functional change intended. Signed-off-by: John Garry <john.garry@huawei.com> Acked-by: Kajol Jain <kjain@linux.ibm.com> Cc: Alexander Shishkin <alexander.shishkin@linux.intel.com> Cc: Andi Kleen <ak@linux.intel.com> Cc: Ian Rogers <irogers@google.com> Cc: Jiri Olsa <jolsa@redhat.com> Cc: Joakim Zhang <qiangqing.zhang@nxp.com> Cc: Kan Liang <kan.liang@linux.intel.com> Cc: Kim Phillips <kim.phillips@amd.com> Cc: Leo Yan <leo.yan@linaro.org> Cc: Mark Rutland <mark.rutland@arm.com> Cc: Mathieu Poirier <mathieu.poirier@linaro.org> Cc: Namhyung Kim <namhyung@kernel.org> Cc: Peter Zijlstra <peterz@infradead.org> Cc: Shaokun Zhang <zhangshaokun@hisilicon.com> Cc: Will Deacon <will@kernel.org> Cc: linux-arm-kernel@lists.infradead.org Cc: linuxarm@huawei.com Link: http://lore.kernel.org/lkml/1607080216-36968-8-git-send-email-john.garry@huawei.com Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
1 parent c2337d6 commit f6fe1e4

File tree

1 file changed

+70
-54
lines changed

1 file changed

+70
-54
lines changed

tools/perf/util/metricgroup.c

Lines changed: 70 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,72 @@ static void metricgroup__print_strlist(struct strlist *metrics, bool raw)
493493
putchar('\n');
494494
}
495495

496+
static int metricgroup__print_pmu_event(struct pmu_event *pe,
497+
bool metricgroups, char *filter,
498+
bool raw, bool details,
499+
struct rblist *groups,
500+
struct strlist *metriclist)
501+
{
502+
const char *g;
503+
char *omg, *mg;
504+
505+
g = pe->metric_group;
506+
if (!g && pe->metric_name) {
507+
if (pe->name)
508+
return 0;
509+
g = "No_group";
510+
}
511+
512+
if (!g)
513+
return 0;
514+
515+
mg = strdup(g);
516+
517+
if (!mg)
518+
return -ENOMEM;
519+
omg = mg;
520+
while ((g = strsep(&mg, ";")) != NULL) {
521+
struct mep *me;
522+
char *s;
523+
524+
g = skip_spaces(g);
525+
if (*g == 0)
526+
g = "No_group";
527+
if (filter && !strstr(g, filter))
528+
continue;
529+
if (raw)
530+
s = (char *)pe->metric_name;
531+
else {
532+
if (asprintf(&s, "%s\n%*s%s]",
533+
pe->metric_name, 8, "[", pe->desc) < 0)
534+
return -1;
535+
if (details) {
536+
if (asprintf(&s, "%s\n%*s%s]",
537+
s, 8, "[", pe->metric_expr) < 0)
538+
return -1;
539+
}
540+
}
541+
542+
if (!s)
543+
continue;
544+
545+
if (!metricgroups) {
546+
strlist__add(metriclist, s);
547+
} else {
548+
me = mep_lookup(groups, g);
549+
if (!me)
550+
continue;
551+
strlist__add(me->metrics, s);
552+
}
553+
554+
if (!raw)
555+
free(s);
556+
}
557+
free(omg);
558+
559+
return 0;
560+
}
561+
496562
void metricgroup__print(bool metrics, bool metricgroups, char *filter,
497563
bool raw, bool details)
498564
{
@@ -517,66 +583,16 @@ void metricgroup__print(bool metrics, bool metricgroups, char *filter,
517583
groups.node_cmp = mep_cmp;
518584
groups.node_delete = mep_delete;
519585
for (i = 0; ; i++) {
520-
const char *g;
521586
pe = &map->table[i];
522587

523588
if (!pe->name && !pe->metric_group && !pe->metric_name)
524589
break;
525590
if (!pe->metric_expr)
526591
continue;
527-
g = pe->metric_group;
528-
if (!g && pe->metric_name) {
529-
if (pe->name)
530-
continue;
531-
g = "No_group";
532-
}
533-
if (g) {
534-
char *omg;
535-
char *mg = strdup(g);
536-
537-
if (!mg)
538-
return;
539-
omg = mg;
540-
while ((g = strsep(&mg, ";")) != NULL) {
541-
struct mep *me;
542-
char *s;
543-
544-
g = skip_spaces(g);
545-
if (*g == 0)
546-
g = "No_group";
547-
if (filter && !strstr(g, filter))
548-
continue;
549-
if (raw)
550-
s = (char *)pe->metric_name;
551-
else {
552-
if (asprintf(&s, "%s\n%*s%s]",
553-
pe->metric_name, 8, "[", pe->desc) < 0)
554-
return;
555-
556-
if (details) {
557-
if (asprintf(&s, "%s\n%*s%s]",
558-
s, 8, "[", pe->metric_expr) < 0)
559-
return;
560-
}
561-
}
562-
563-
if (!s)
564-
continue;
565-
566-
if (!metricgroups) {
567-
strlist__add(metriclist, s);
568-
} else {
569-
me = mep_lookup(&groups, g);
570-
if (!me)
571-
continue;
572-
strlist__add(me->metrics, s);
573-
}
574-
575-
if (!raw)
576-
free(s);
577-
}
578-
free(omg);
579-
}
592+
if (metricgroup__print_pmu_event(pe, metricgroups, filter,
593+
raw, details, &groups,
594+
metriclist) < 0)
595+
return;
580596
}
581597

582598
if (!filter || !rblist__empty(&groups)) {

0 commit comments

Comments
 (0)