blob: 7ad81c8177eae1f8faab42839f62fc28980f3ac7 [file] [log] [blame]
Thomas Gleixner2025cf92019-05-29 07:18:02 -07001// SPDX-License-Identifier: GPL-2.0-only
Andi Kleenb18f3e32017-08-31 12:40:31 -07002/*
3 * Copyright (c) 2017, Intel Corporation.
Andi Kleenb18f3e32017-08-31 12:40:31 -07004 */
5
6/* Manage metrics and groups of metrics from JSON files */
7
8#include "metricgroup.h"
Arnaldo Carvalho de Melob4209022019-08-29 15:56:40 -03009#include "debug.h"
Andi Kleenb18f3e32017-08-31 12:40:31 -070010#include "evlist.h"
Arnaldo Carvalho de Melo0b8026e2019-08-21 10:54:14 -030011#include "evsel.h"
Andi Kleenb18f3e32017-08-31 12:40:31 -070012#include "strbuf.h"
13#include "pmu.h"
14#include "expr.h"
15#include "rblist.h"
Andi Kleenb18f3e32017-08-31 12:40:31 -070016#include <string.h>
Andi Kleenb18f3e32017-08-31 12:40:31 -070017#include <errno.h>
18#include "pmu-events/pmu-events.h"
Andi Kleenb18f3e32017-08-31 12:40:31 -070019#include "strlist.h"
20#include <assert.h>
Arnaldo Carvalho de Melobd9860b2019-06-25 21:13:51 -030021#include <linux/ctype.h>
Arnaldo Carvalho de Melob4209022019-08-29 15:56:40 -030022#include <linux/string.h>
Arnaldo Carvalho de Melod8f9da22019-07-04 12:06:20 -030023#include <linux/zalloc.h>
Arnaldo Carvalho de Melo0b8026e2019-08-21 10:54:14 -030024#include <subcmd/parse-options.h>
Kan Liangab483d82020-02-24 13:59:23 -080025#include <api/fs/fs.h>
26#include "util.h"
Andi Kleenb18f3e32017-08-31 12:40:31 -070027
28struct metric_event *metricgroup__lookup(struct rblist *metric_events,
Jiri Olsa32dcd022019-07-21 13:23:51 +020029 struct evsel *evsel,
Andi Kleenb18f3e32017-08-31 12:40:31 -070030 bool create)
31{
32 struct rb_node *nd;
33 struct metric_event me = {
34 .evsel = evsel
35 };
Andi Kleen4bd1bef2017-11-17 13:43:00 -080036
37 if (!metric_events)
38 return NULL;
39
Andi Kleenb18f3e32017-08-31 12:40:31 -070040 nd = rblist__find(metric_events, &me);
41 if (nd)
42 return container_of(nd, struct metric_event, nd);
43 if (create) {
44 rblist__add_node(metric_events, &me);
45 nd = rblist__find(metric_events, &me);
46 if (nd)
47 return container_of(nd, struct metric_event, nd);
48 }
49 return NULL;
50}
51
52static int metric_event_cmp(struct rb_node *rb_node, const void *entry)
53{
54 struct metric_event *a = container_of(rb_node,
55 struct metric_event,
56 nd);
57 const struct metric_event *b = entry;
58
59 if (a->evsel == b->evsel)
60 return 0;
61 if ((char *)a->evsel < (char *)b->evsel)
62 return -1;
63 return +1;
64}
65
66static struct rb_node *metric_event_new(struct rblist *rblist __maybe_unused,
67 const void *entry)
68{
69 struct metric_event *me = malloc(sizeof(struct metric_event));
70
71 if (!me)
72 return NULL;
73 memcpy(me, entry, sizeof(struct metric_event));
74 me->evsel = ((struct metric_event *)entry)->evsel;
75 INIT_LIST_HEAD(&me->head);
76 return &me->nd;
77}
78
79static void metricgroup__rblist_init(struct rblist *metric_events)
80{
81 rblist__init(metric_events);
82 metric_events->node_cmp = metric_event_cmp;
83 metric_events->node_new = metric_event_new;
84}
85
86struct egroup {
87 struct list_head nd;
88 int idnum;
89 const char **ids;
90 const char *metric_name;
91 const char *metric_expr;
Jin Yao287f2642019-08-28 13:59:31 +080092 const char *metric_unit;
Andi Kleenb18f3e32017-08-31 12:40:31 -070093};
94
Jiri Olsa63503db2019-07-21 13:23:52 +020095static struct evsel *find_evsel_group(struct evlist *perf_evlist,
Jiri Olsa32dcd022019-07-21 13:23:51 +020096 const char **ids,
97 int idnum,
Kajol Jain58fc90f2020-02-21 15:41:21 +053098 struct evsel **metric_events,
99 bool *evlist_used)
Andi Kleenb18f3e32017-08-31 12:40:31 -0700100{
Jin Yaof01642e2019-08-28 13:59:32 +0800101 struct evsel *ev;
Kajol Jain58fc90f2020-02-21 15:41:21 +0530102 int i = 0, j = 0;
Jin Yaof01642e2019-08-28 13:59:32 +0800103 bool leader_found;
Andi Kleenb18f3e32017-08-31 12:40:31 -0700104
105 evlist__for_each_entry (perf_evlist, ev) {
Kajol Jain58fc90f2020-02-21 15:41:21 +0530106 if (evlist_used[j++])
107 continue;
Jin Yaof01642e2019-08-28 13:59:32 +0800108 if (!strcmp(ev->name, ids[i])) {
109 if (!metric_events[i])
110 metric_events[i] = ev;
Kajol Jaineb573e72019-11-20 14:10:59 +0530111 i++;
112 if (i == idnum)
113 break;
Andi Kleenb18f3e32017-08-31 12:40:31 -0700114 } else {
Kajol Jain58fc90f2020-02-21 15:41:21 +0530115 /* Discard the whole match and start again */
116 i = 0;
117 memset(metric_events, 0,
118 sizeof(struct evsel *) * idnum);
Jin Yaof01642e2019-08-28 13:59:32 +0800119
Kajol Jain58fc90f2020-02-21 15:41:21 +0530120 if (!strcmp(ev->name, ids[i])) {
121 if (!metric_events[i])
122 metric_events[i] = ev;
123 i++;
124 if (i == idnum)
125 break;
Andi Kleen2f87f332019-06-24 12:37:10 -0700126 }
Andi Kleenb18f3e32017-08-31 12:40:31 -0700127 }
128 }
Jin Yaof01642e2019-08-28 13:59:32 +0800129
Kajol Jaineb573e72019-11-20 14:10:59 +0530130 if (i != idnum) {
Jin Yaof01642e2019-08-28 13:59:32 +0800131 /* Not whole match */
132 return NULL;
133 }
134
135 metric_events[idnum] = NULL;
136
137 for (i = 0; i < idnum; i++) {
138 leader_found = false;
139 evlist__for_each_entry(perf_evlist, ev) {
140 if (!leader_found && (ev == metric_events[i]))
141 leader_found = true;
142
143 if (leader_found &&
144 !strcmp(ev->name, metric_events[i]->name)) {
145 ev->metric_leader = metric_events[i];
146 }
Kajol Jain58fc90f2020-02-21 15:41:21 +0530147 j++;
Jin Yaof01642e2019-08-28 13:59:32 +0800148 }
Kajol Jain58fc90f2020-02-21 15:41:21 +0530149 ev = metric_events[i];
150 evlist_used[ev->idx] = true;
Jin Yaof01642e2019-08-28 13:59:32 +0800151 }
152
153 return metric_events[0];
Andi Kleenb18f3e32017-08-31 12:40:31 -0700154}
155
156static int metricgroup__setup_events(struct list_head *groups,
Jiri Olsa63503db2019-07-21 13:23:52 +0200157 struct evlist *perf_evlist,
Andi Kleenb18f3e32017-08-31 12:40:31 -0700158 struct rblist *metric_events_list)
159{
160 struct metric_event *me;
161 struct metric_expr *expr;
162 int i = 0;
163 int ret = 0;
164 struct egroup *eg;
Jiri Olsa32dcd022019-07-21 13:23:51 +0200165 struct evsel *evsel;
Kajol Jain58fc90f2020-02-21 15:41:21 +0530166 bool *evlist_used;
167
168 evlist_used = calloc(perf_evlist->core.nr_entries, sizeof(bool));
169 if (!evlist_used) {
170 ret = -ENOMEM;
171 return ret;
172 }
Andi Kleenb18f3e32017-08-31 12:40:31 -0700173
174 list_for_each_entry (eg, groups, nd) {
Jiri Olsa32dcd022019-07-21 13:23:51 +0200175 struct evsel **metric_events;
Andi Kleenb18f3e32017-08-31 12:40:31 -0700176
177 metric_events = calloc(sizeof(void *), eg->idnum + 1);
178 if (!metric_events) {
179 ret = -ENOMEM;
180 break;
181 }
Andi Kleen2f87f332019-06-24 12:37:10 -0700182 evsel = find_evsel_group(perf_evlist, eg->ids, eg->idnum,
Kajol Jain58fc90f2020-02-21 15:41:21 +0530183 metric_events, evlist_used);
Andi Kleenb18f3e32017-08-31 12:40:31 -0700184 if (!evsel) {
185 pr_debug("Cannot resolve %s: %s\n",
186 eg->metric_name, eg->metric_expr);
187 continue;
188 }
189 for (i = 0; i < eg->idnum; i++)
190 metric_events[i]->collect_stat = true;
191 me = metricgroup__lookup(metric_events_list, evsel, true);
192 if (!me) {
193 ret = -ENOMEM;
194 break;
195 }
196 expr = malloc(sizeof(struct metric_expr));
197 if (!expr) {
198 ret = -ENOMEM;
199 break;
200 }
201 expr->metric_expr = eg->metric_expr;
202 expr->metric_name = eg->metric_name;
Jin Yao287f2642019-08-28 13:59:31 +0800203 expr->metric_unit = eg->metric_unit;
Andi Kleenb18f3e32017-08-31 12:40:31 -0700204 expr->metric_events = metric_events;
205 list_add(&expr->nd, &me->head);
206 }
Kajol Jain58fc90f2020-02-21 15:41:21 +0530207
208 free(evlist_used);
209
Andi Kleenb18f3e32017-08-31 12:40:31 -0700210 return ret;
211}
212
213static bool match_metric(const char *n, const char *list)
214{
215 int len;
216 char *m;
217
218 if (!list)
219 return false;
220 if (!strcmp(list, "all"))
221 return true;
222 if (!n)
223 return !strcasecmp(list, "No_group");
224 len = strlen(list);
225 m = strcasestr(n, list);
226 if (!m)
227 return false;
228 if ((m == n || m[-1] == ';' || m[-1] == ' ') &&
229 (m[len] == 0 || m[len] == ';'))
230 return true;
231 return false;
232}
233
Andi Kleen71b0acc2017-08-31 12:40:32 -0700234struct mep {
235 struct rb_node nd;
236 const char *name;
237 struct strlist *metrics;
238};
239
240static int mep_cmp(struct rb_node *rb_node, const void *entry)
241{
242 struct mep *a = container_of(rb_node, struct mep, nd);
243 struct mep *b = (struct mep *)entry;
244
245 return strcmp(a->name, b->name);
246}
247
248static struct rb_node *mep_new(struct rblist *rl __maybe_unused,
249 const void *entry)
250{
251 struct mep *me = malloc(sizeof(struct mep));
252
253 if (!me)
254 return NULL;
255 memcpy(me, entry, sizeof(struct mep));
256 me->name = strdup(me->name);
257 if (!me->name)
258 goto out_me;
259 me->metrics = strlist__new(NULL, NULL);
260 if (!me->metrics)
261 goto out_name;
262 return &me->nd;
263out_name:
Arnaldo Carvalho de Melod8f9da22019-07-04 12:06:20 -0300264 zfree(&me->name);
Andi Kleen71b0acc2017-08-31 12:40:32 -0700265out_me:
266 free(me);
267 return NULL;
268}
269
270static struct mep *mep_lookup(struct rblist *groups, const char *name)
271{
272 struct rb_node *nd;
273 struct mep me = {
274 .name = name
275 };
276 nd = rblist__find(groups, &me);
277 if (nd)
278 return container_of(nd, struct mep, nd);
279 rblist__add_node(groups, &me);
280 nd = rblist__find(groups, &me);
281 if (nd)
282 return container_of(nd, struct mep, nd);
283 return NULL;
284}
285
286static void mep_delete(struct rblist *rl __maybe_unused,
287 struct rb_node *nd)
288{
289 struct mep *me = container_of(nd, struct mep, nd);
290
291 strlist__delete(me->metrics);
Arnaldo Carvalho de Melod8f9da22019-07-04 12:06:20 -0300292 zfree(&me->name);
Andi Kleen71b0acc2017-08-31 12:40:32 -0700293 free(me);
294}
295
296static void metricgroup__print_strlist(struct strlist *metrics, bool raw)
297{
298 struct str_node *sn;
299 int n = 0;
300
301 strlist__for_each_entry (sn, metrics) {
302 if (raw)
303 printf("%s%s", n > 0 ? " " : "", sn->s);
304 else
305 printf(" %s\n", sn->s);
306 n++;
307 }
308 if (raw)
309 putchar('\n');
310}
311
312void metricgroup__print(bool metrics, bool metricgroups, char *filter,
Jiri Olsa33bbc572019-02-13 13:32:41 +0100313 bool raw, bool details)
Andi Kleen71b0acc2017-08-31 12:40:32 -0700314{
Ganapatrao Kulkarni54e32dc2017-10-17 00:02:18 +0530315 struct pmu_events_map *map = perf_pmu__find_map(NULL);
Andi Kleen71b0acc2017-08-31 12:40:32 -0700316 struct pmu_event *pe;
317 int i;
318 struct rblist groups;
319 struct rb_node *node, *next;
320 struct strlist *metriclist = NULL;
321
322 if (!map)
323 return;
324
325 if (!metricgroups) {
326 metriclist = strlist__new(NULL, NULL);
327 if (!metriclist)
328 return;
329 }
330
331 rblist__init(&groups);
332 groups.node_new = mep_new;
333 groups.node_cmp = mep_cmp;
334 groups.node_delete = mep_delete;
335 for (i = 0; ; i++) {
336 const char *g;
337 pe = &map->table[i];
338
339 if (!pe->name && !pe->metric_group && !pe->metric_name)
340 break;
341 if (!pe->metric_expr)
342 continue;
343 g = pe->metric_group;
344 if (!g && pe->metric_name) {
345 if (pe->name)
346 continue;
347 g = "No_group";
348 }
349 if (g) {
350 char *omg;
351 char *mg = strdup(g);
352
353 if (!mg)
354 return;
355 omg = mg;
356 while ((g = strsep(&mg, ";")) != NULL) {
357 struct mep *me;
358 char *s;
359
Arnaldo Carvalho de Melo80e90732019-06-26 11:21:47 -0300360 g = skip_spaces(g);
Andi Kleen71b0acc2017-08-31 12:40:32 -0700361 if (*g == 0)
362 g = "No_group";
Andi Kleen71b0acc2017-08-31 12:40:32 -0700363 if (filter && !strstr(g, filter))
364 continue;
365 if (raw)
366 s = (char *)pe->metric_name;
367 else {
Michael Petlan95f04322018-07-30 17:35:04 -0400368 if (asprintf(&s, "%s\n%*s%s]",
369 pe->metric_name, 8, "[", pe->desc) < 0)
Andi Kleen71b0acc2017-08-31 12:40:32 -0700370 return;
Jiri Olsa33bbc572019-02-13 13:32:41 +0100371
372 if (details) {
373 if (asprintf(&s, "%s\n%*s%s]",
374 s, 8, "[", pe->metric_expr) < 0)
375 return;
376 }
Andi Kleen71b0acc2017-08-31 12:40:32 -0700377 }
378
379 if (!s)
380 continue;
381
382 if (!metricgroups) {
383 strlist__add(metriclist, s);
384 } else {
385 me = mep_lookup(&groups, g);
386 if (!me)
387 continue;
388 strlist__add(me->metrics, s);
389 }
390 }
391 free(omg);
392 }
393 }
394
395 if (metricgroups && !raw)
396 printf("\nMetric Groups:\n\n");
397 else if (metrics && !raw)
398 printf("\nMetrics:\n\n");
399
Davidlohr Buesoca227022018-12-06 11:18:16 -0800400 for (node = rb_first_cached(&groups.entries); node; node = next) {
Andi Kleen71b0acc2017-08-31 12:40:32 -0700401 struct mep *me = container_of(node, struct mep, nd);
402
403 if (metricgroups)
Andi Kleen9c344d12019-06-28 15:07:36 -0700404 printf("%s%s%s", me->name, metrics && !raw ? ":" : "", raw ? " " : "\n");
Andi Kleen71b0acc2017-08-31 12:40:32 -0700405 if (metrics)
406 metricgroup__print_strlist(me->metrics, raw);
407 next = rb_next(node);
408 rblist__remove_node(&groups, node);
409 }
410 if (!metricgroups)
411 metricgroup__print_strlist(metriclist, raw);
412 strlist__delete(metriclist);
413}
414
Kan Liangf7426342020-02-24 13:59:21 -0800415static void metricgroup__add_metric_weak_group(struct strbuf *events,
416 const char **ids,
417 int idnum)
418{
419 bool no_group = false;
420 int i;
421
422 for (i = 0; i < idnum; i++) {
423 pr_debug("found event %s\n", ids[i]);
424 /*
425 * Duration time maps to a software event and can make
426 * groups not count. Always use it outside a
427 * group.
428 */
429 if (!strcmp(ids[i], "duration_time")) {
430 if (i > 0)
431 strbuf_addf(events, "}:W,");
432 strbuf_addf(events, "duration_time");
433 no_group = true;
434 continue;
435 }
436 strbuf_addf(events, "%s%s",
437 i == 0 || no_group ? "{" : ",",
438 ids[i]);
439 no_group = false;
440 }
441 if (!no_group)
442 strbuf_addf(events, "}:W");
443}
444
Kan Liangab483d82020-02-24 13:59:23 -0800445static void metricgroup__add_metric_non_group(struct strbuf *events,
446 const char **ids,
447 int idnum)
448{
449 int i;
450
451 for (i = 0; i < idnum; i++)
452 strbuf_addf(events, ",%s", ids[i]);
453}
454
455static void metricgroup___watchdog_constraint_hint(const char *name, bool foot)
456{
457 static bool violate_nmi_constraint;
458
459 if (!foot) {
460 pr_warning("Splitting metric group %s into standalone metrics.\n", name);
461 violate_nmi_constraint = true;
462 return;
463 }
464
465 if (!violate_nmi_constraint)
466 return;
467
468 pr_warning("Try disabling the NMI watchdog to comply NO_NMI_WATCHDOG metric constraint:\n"
469 " echo 0 > /proc/sys/kernel/nmi_watchdog\n"
470 " perf stat ...\n"
471 " echo 1 > /proc/sys/kernel/nmi_watchdog\n");
472}
473
474static bool metricgroup__has_constraint(struct pmu_event *pe)
475{
476 if (!pe->metric_constraint)
477 return false;
478
479 if (!strcmp(pe->metric_constraint, "NO_NMI_WATCHDOG") &&
480 sysctl__nmi_watchdog_enabled()) {
481 metricgroup___watchdog_constraint_hint(pe->metric_name, false);
482 return true;
483 }
484
485 return false;
486}
487
Kajol Jain47352ab2020-04-02 02:03:36 +0530488static int __metricgroup__add_metric(struct strbuf *events,
489 struct list_head *group_list, struct pmu_event *pe)
490{
491
492 const char **ids;
493 int idnum;
494 struct egroup *eg;
495
496 if (expr__find_other(pe->metric_expr, NULL, &ids, &idnum) < 0)
497 return -EINVAL;
498
499 if (events->len > 0)
500 strbuf_addf(events, ",");
501
502 if (metricgroup__has_constraint(pe))
503 metricgroup__add_metric_non_group(events, ids, idnum);
504 else
505 metricgroup__add_metric_weak_group(events, ids, idnum);
506
507 eg = malloc(sizeof(*eg));
508 if (!eg)
509 return -ENOMEM;
510
511 eg->ids = ids;
512 eg->idnum = idnum;
513 eg->metric_name = pe->metric_name;
514 eg->metric_expr = pe->metric_expr;
515 eg->metric_unit = pe->unit;
516 list_add_tail(&eg->nd, group_list);
517
518 return 0;
519}
520
Andi Kleenb18f3e32017-08-31 12:40:31 -0700521static int metricgroup__add_metric(const char *metric, struct strbuf *events,
522 struct list_head *group_list)
523{
Ganapatrao Kulkarni54e32dc2017-10-17 00:02:18 +0530524 struct pmu_events_map *map = perf_pmu__find_map(NULL);
Andi Kleenb18f3e32017-08-31 12:40:31 -0700525 struct pmu_event *pe;
Kan Liangf7426342020-02-24 13:59:21 -0800526 int i, ret = -EINVAL;
Andi Kleenb18f3e32017-08-31 12:40:31 -0700527
Andi Kleenb18f3e32017-08-31 12:40:31 -0700528 if (!map)
529 return 0;
530
531 for (i = 0; ; i++) {
532 pe = &map->table[i];
533
534 if (!pe->name && !pe->metric_group && !pe->metric_name)
535 break;
536 if (!pe->metric_expr)
537 continue;
538 if (match_metric(pe->metric_group, metric) ||
539 match_metric(pe->metric_name, metric)) {
Andi Kleenb18f3e32017-08-31 12:40:31 -0700540
541 pr_debug("metric expr %s for %s\n", pe->metric_expr, pe->metric_name);
542
Kajol Jain47352ab2020-04-02 02:03:36 +0530543 ret = __metricgroup__add_metric(events, group_list, pe);
544 if (ret == -ENOMEM)
Andi Kleenb18f3e32017-08-31 12:40:31 -0700545 break;
Andi Kleenb18f3e32017-08-31 12:40:31 -0700546 }
547 }
548 return ret;
549}
550
551static int metricgroup__add_metric_list(const char *list, struct strbuf *events,
552 struct list_head *group_list)
553{
554 char *llist, *nlist, *p;
555 int ret = -EINVAL;
556
557 nlist = strdup(list);
558 if (!nlist)
559 return -ENOMEM;
560 llist = nlist;
Andi Kleen411bc312017-09-14 13:57:35 -0700561
562 strbuf_init(events, 100);
563 strbuf_addf(events, "%s", "");
564
Andi Kleenb18f3e32017-08-31 12:40:31 -0700565 while ((p = strsep(&llist, ",")) != NULL) {
566 ret = metricgroup__add_metric(p, events, group_list);
567 if (ret == -EINVAL) {
568 fprintf(stderr, "Cannot find metric or group `%s'\n",
569 p);
570 break;
571 }
572 }
573 free(nlist);
Kan Liangab483d82020-02-24 13:59:23 -0800574
575 if (!ret)
576 metricgroup___watchdog_constraint_hint(NULL, true);
577
Andi Kleenb18f3e32017-08-31 12:40:31 -0700578 return ret;
579}
580
581static void metricgroup__free_egroups(struct list_head *group_list)
582{
583 struct egroup *eg, *egtmp;
584 int i;
585
586 list_for_each_entry_safe (eg, egtmp, group_list, nd) {
587 for (i = 0; i < eg->idnum; i++)
Arnaldo Carvalho de Melod8f9da22019-07-04 12:06:20 -0300588 zfree(&eg->ids[i]);
589 zfree(&eg->ids);
Arnaldo Carvalho de Meloacc7bfb2019-07-04 12:20:21 -0300590 list_del_init(&eg->nd);
Andi Kleenb18f3e32017-08-31 12:40:31 -0700591 free(eg);
592 }
593}
594
595int metricgroup__parse_groups(const struct option *opt,
596 const char *str,
597 struct rblist *metric_events)
598{
599 struct parse_events_error parse_error;
Jiri Olsa63503db2019-07-21 13:23:52 +0200600 struct evlist *perf_evlist = *(struct evlist **)opt->value;
Andi Kleenb18f3e32017-08-31 12:40:31 -0700601 struct strbuf extra_events;
602 LIST_HEAD(group_list);
603 int ret;
604
605 if (metric_events->nr_entries == 0)
606 metricgroup__rblist_init(metric_events);
607 ret = metricgroup__add_metric_list(str, &extra_events, &group_list);
608 if (ret)
609 return ret;
610 pr_debug("adding %s\n", extra_events.buf);
Ian Rogersa910e462019-11-15 23:46:52 -0800611 bzero(&parse_error, sizeof(parse_error));
Andi Kleenb18f3e32017-08-31 12:40:31 -0700612 ret = parse_events(perf_evlist, extra_events.buf, &parse_error);
613 if (ret) {
Andi Kleen333b5662017-09-13 14:50:06 -0700614 parse_events_print_error(&parse_error, extra_events.buf);
Andi Kleenb18f3e32017-08-31 12:40:31 -0700615 goto out;
616 }
617 strbuf_release(&extra_events);
618 ret = metricgroup__setup_events(&group_list, perf_evlist,
619 metric_events);
620out:
621 metricgroup__free_egroups(&group_list);
622 return ret;
623}
Thomas Richter742d92f2018-06-26 09:17:01 +0200624
625bool metricgroup__has_metric(const char *metric)
626{
627 struct pmu_events_map *map = perf_pmu__find_map(NULL);
628 struct pmu_event *pe;
629 int i;
630
631 if (!map)
632 return false;
633
634 for (i = 0; ; i++) {
635 pe = &map->table[i];
636
637 if (!pe->name && !pe->metric_group && !pe->metric_name)
638 break;
639 if (!pe->metric_expr)
640 continue;
641 if (match_metric(pe->metric_name, metric))
642 return true;
643 }
644 return false;
645}