Linux Perf
evsel-roundtrip-name.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0
2 #include "evlist.h"
3 #include "evsel.h"
4 #include "parse-events.h"
5 #include "tests.h"
6 #include "debug.h"
7 #include <errno.h>
8 #include <linux/kernel.h>
9 
11 {
12  char name[128];
13  int type, op, err = 0, ret = 0, i, idx;
14  struct perf_evsel *evsel;
15  struct perf_evlist *evlist = perf_evlist__new();
16 
17  if (evlist == NULL)
18  return -ENOMEM;
19 
20  for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
21  for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
22  /* skip invalid cache type */
23  if (!perf_evsel__is_cache_op_valid(type, op))
24  continue;
25 
26  for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
28  name, sizeof(name));
29  err = parse_events(evlist, name, NULL);
30  if (err)
31  ret = err;
32  }
33  }
34  }
35 
36  idx = 0;
37  evsel = perf_evlist__first(evlist);
38 
39  for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
40  for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
41  /* skip invalid cache type */
42  if (!perf_evsel__is_cache_op_valid(type, op))
43  continue;
44 
45  for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
47  name, sizeof(name));
48  if (evsel->idx != idx)
49  continue;
50 
51  ++idx;
52 
53  if (strcmp(perf_evsel__name(evsel), name)) {
54  pr_debug("%s != %s\n", perf_evsel__name(evsel), name);
55  ret = -1;
56  }
57 
58  evsel = perf_evsel__next(evsel);
59  }
60  }
61  }
62 
63  perf_evlist__delete(evlist);
64  return ret;
65 }
66 
67 static int __perf_evsel__name_array_test(const char *names[], int nr_names)
68 {
69  int i, err;
70  struct perf_evsel *evsel;
71  struct perf_evlist *evlist = perf_evlist__new();
72 
73  if (evlist == NULL)
74  return -ENOMEM;
75 
76  for (i = 0; i < nr_names; ++i) {
77  err = parse_events(evlist, names[i], NULL);
78  if (err) {
79  pr_debug("failed to parse event '%s', err %d\n",
80  names[i], err);
81  goto out_delete_evlist;
82  }
83  }
84 
85  err = 0;
86  evlist__for_each_entry(evlist, evsel) {
87  if (strcmp(perf_evsel__name(evsel), names[evsel->idx])) {
88  --err;
89  pr_debug("%s != %s\n", perf_evsel__name(evsel), names[evsel->idx]);
90  }
91  }
92 
93 out_delete_evlist:
94  perf_evlist__delete(evlist);
95  return err;
96 }
97 
98 #define perf_evsel__name_array_test(names) \
99  __perf_evsel__name_array_test(names, ARRAY_SIZE(names))
100 
101 int test__perf_evsel__roundtrip_name_test(struct test *test __maybe_unused, int subtest __maybe_unused)
102 {
103  int err = 0, ret = 0;
104 
106  if (err)
107  ret = err;
108 
110  PERF_COUNT_SW_DUMMY + 1);
111  if (err)
112  ret = err;
113 
115  if (err)
116  ret = err;
117 
118  return ret;
119 }
bool perf_evsel__is_cache_op_valid(u8 type, u8 op)
Definition: evsel.c:517
int int err
Definition: 5sec.c:44
const char * perf_evsel__hw_names[PERF_COUNT_HW_MAX]
Definition: evsel.c:358
void perf_evlist__delete(struct perf_evlist *evlist)
Definition: evlist.c:133
int idx
Definition: evsel.h:100
int parse_events(struct perf_evlist *evlist, const char *str, struct parse_events_error *err)
static int perf_evsel__roundtrip_cache_name_test(void)
int __perf_evsel__hw_cache_type_op_res_name(u8 type, u8 op, u8 result, char *bf, size_t size)
Definition: evsel.c:525
static struct perf_evsel * perf_evsel__next(struct perf_evsel *evsel)
Definition: evsel.h:363
const char * perf_evsel__sw_names[PERF_COUNT_SW_MAX]
Definition: evsel.c:421
const char * name
#define pr_debug(fmt,...)
Definition: json.h:27
#define evlist__for_each_entry(evlist, evsel)
Definition: evlist.h:247
#define perf_evsel__name_array_test(names)
const char * perf_evsel__name(struct perf_evsel *evsel)
Definition: evsel.c:577
static struct perf_evsel * perf_evlist__first(struct perf_evlist *evlist)
Definition: evlist.h:215
Definition: tests.h:30
static int __perf_evsel__name_array_test(const char *names[], int nr_names)
struct perf_evlist * perf_evlist__new(void)
Definition: evlist.c:54
int test__perf_evsel__roundtrip_name_test(struct test *test __maybe_unused, int subtest __maybe_unused)