Linux Perf
event_update.c
Go to the documentation of this file.
1 // SPDX-License-Identifier: GPL-2.0
2 #include <linux/compiler.h>
3 #include "evlist.h"
4 #include "evsel.h"
5 #include "machine.h"
6 #include "tests.h"
7 #include "debug.h"
8 
9 static int process_event_unit(struct perf_tool *tool __maybe_unused,
10  union perf_event *event,
11  struct perf_sample *sample __maybe_unused,
12  struct machine *machine __maybe_unused)
13 {
14  struct event_update_event *ev = (struct event_update_event *) event;
15 
16  TEST_ASSERT_VAL("wrong id", ev->id == 123);
17  TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__UNIT);
18  TEST_ASSERT_VAL("wrong unit", !strcmp(ev->data, "KRAVA"));
19  return 0;
20 }
21 
22 static int process_event_scale(struct perf_tool *tool __maybe_unused,
23  union perf_event *event,
24  struct perf_sample *sample __maybe_unused,
25  struct machine *machine __maybe_unused)
26 {
27  struct event_update_event *ev = (struct event_update_event *) event;
28  struct event_update_event_scale *ev_data;
29 
30  ev_data = (struct event_update_event_scale *) ev->data;
31 
32  TEST_ASSERT_VAL("wrong id", ev->id == 123);
33  TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__SCALE);
34  TEST_ASSERT_VAL("wrong scale", ev_data->scale == 0.123);
35  return 0;
36 }
37 
38 struct event_name {
39  struct perf_tool tool;
40  const char *name;
41 };
42 
43 static int process_event_name(struct perf_tool *tool,
44  union perf_event *event,
45  struct perf_sample *sample __maybe_unused,
46  struct machine *machine __maybe_unused)
47 {
48  struct event_name *tmp = container_of(tool, struct event_name, tool);
49  struct event_update_event *ev = (struct event_update_event*) event;
50 
51  TEST_ASSERT_VAL("wrong id", ev->id == 123);
52  TEST_ASSERT_VAL("wrong id", ev->type == PERF_EVENT_UPDATE__NAME);
53  TEST_ASSERT_VAL("wrong name", !strcmp(ev->data, tmp->name));
54  return 0;
55 }
56 
57 static int process_event_cpus(struct perf_tool *tool __maybe_unused,
58  union perf_event *event,
59  struct perf_sample *sample __maybe_unused,
60  struct machine *machine __maybe_unused)
61 {
62  struct event_update_event *ev = (struct event_update_event*) event;
63  struct event_update_event_cpus *ev_data;
64  struct cpu_map *map;
65 
66  ev_data = (struct event_update_event_cpus*) ev->data;
67 
68  map = cpu_map__new_data(&ev_data->cpus);
69 
70  TEST_ASSERT_VAL("wrong id", ev->id == 123);
71  TEST_ASSERT_VAL("wrong type", ev->type == PERF_EVENT_UPDATE__CPUS);
72  TEST_ASSERT_VAL("wrong cpus", map->nr == 3);
73  TEST_ASSERT_VAL("wrong cpus", map->map[0] == 1);
74  TEST_ASSERT_VAL("wrong cpus", map->map[1] == 2);
75  TEST_ASSERT_VAL("wrong cpus", map->map[2] == 3);
76  cpu_map__put(map);
77  return 0;
78 }
79 
80 int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused)
81 {
82  struct perf_evlist *evlist;
83  struct perf_evsel *evsel;
84  struct event_name tmp;
85 
86  evlist = perf_evlist__new_default();
87  TEST_ASSERT_VAL("failed to get evlist", evlist);
88 
89  evsel = perf_evlist__first(evlist);
90 
91  TEST_ASSERT_VAL("failed to allos ids",
92  !perf_evsel__alloc_id(evsel, 1, 1));
93 
94  perf_evlist__id_add(evlist, evsel, 0, 0, 123);
95 
96  evsel->unit = strdup("KRAVA");
97 
98  TEST_ASSERT_VAL("failed to synthesize attr update unit",
100 
101  evsel->scale = 0.123;
102 
103  TEST_ASSERT_VAL("failed to synthesize attr update scale",
105 
106  tmp.name = perf_evsel__name(evsel);
107 
108  TEST_ASSERT_VAL("failed to synthesize attr update name",
110 
111  evsel->own_cpus = cpu_map__new("1,2,3");
112 
113  TEST_ASSERT_VAL("failed to synthesize attr update cpus",
115 
116  cpu_map__put(evsel->own_cpus);
117  return 0;
118 }
int nr
Definition: cpumap.h:14
int perf_event__synthesize_event_update_unit(struct perf_tool *tool, struct perf_evsel *evsel, perf_event__handler_t process)
Definition: header.c:3507
struct perf_evlist * perf_evlist__new_default(void)
Definition: evlist.c:64
#define TEST_ASSERT_VAL(text, cond)
Definition: tests.h:7
static int process_event_unit(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused)
Definition: event_update.c:9
struct cpu_map * cpu_map__new_data(struct cpu_map_data *data)
Definition: cpumap.c:234
struct cpu_map_data cpus
Definition: event.h:458
Definition: cpumap.h:12
const char * unit
Definition: evsel.h:104
int perf_evsel__alloc_id(struct perf_evsel *evsel, int ncpus, int nthreads)
Definition: evsel.c:1189
int perf_event__synthesize_event_update_scale(struct perf_tool *tool, struct perf_evsel *evsel, perf_event__handler_t process)
Definition: header.c:3526
void cpu_map__put(struct cpu_map *map)
Definition: cpumap.c:298
void perf_evlist__id_add(struct perf_evlist *evlist, struct perf_evsel *evsel, int cpu, int thread, u64 id)
Definition: evlist.c:509
static int process_event_scale(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused)
Definition: event_update.c:22
Definition: tool.h:44
static struct perf_tool tool
Definition: builtin-diff.c:362
#define event
struct cpu_map * own_cpus
Definition: evsel.h:113
int map[]
Definition: cpumap.h:15
double scale
Definition: evsel.h:103
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
int test__event_update(struct test *test __maybe_unused, int subtest __maybe_unused)
Definition: event_update.c:80
static int process_event_cpus(struct perf_tool *tool __maybe_unused, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused)
Definition: event_update.c:57
static int process_event_name(struct perf_tool *tool, union perf_event *event, struct perf_sample *sample __maybe_unused, struct machine *machine __maybe_unused)
Definition: event_update.c:43
Definition: tests.h:30
int perf_event__synthesize_event_update_name(struct perf_tool *tool, struct perf_evsel *evsel, perf_event__handler_t process)
Definition: header.c:3546
const char * name
Definition: event_update.c:40
struct perf_tool tool
Definition: event_update.c:39
int perf_event__synthesize_event_update_cpus(struct perf_tool *tool, struct perf_evsel *evsel, perf_event__handler_t process)
Definition: header.c:3565
struct cpu_map * cpu_map__new(const char *cpu_list)
Definition: cpumap.c:125