aboutsummaryrefslogtreecommitdiffstats
path: root/Documentation/perf_counter/util/parse-events.c
diff options
context:
space:
mode:
Diffstat (limited to 'Documentation/perf_counter/util/parse-events.c')
-rw-r--r--Documentation/perf_counter/util/parse-events.c82
1 files changed, 72 insertions, 10 deletions
diff --git a/Documentation/perf_counter/util/parse-events.c b/Documentation/perf_counter/util/parse-events.c
index 77d0917d55d3..88c903eb260a 100644
--- a/Documentation/perf_counter/util/parse-events.c
+++ b/Documentation/perf_counter/util/parse-events.c
@@ -8,6 +8,7 @@
8int nr_counters; 8int nr_counters;
9 9
10__u64 event_id[MAX_COUNTERS] = { }; 10__u64 event_id[MAX_COUNTERS] = { };
11int event_mask[MAX_COUNTERS];
11 12
12struct event_symbol { 13struct event_symbol {
13 __u64 event; 14 __u64 event;
@@ -37,6 +38,64 @@ static struct event_symbol event_symbols[] = {
37 {EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CPU_MIGRATIONS), "migrations", }, 38 {EID(PERF_TYPE_SOFTWARE, PERF_COUNT_CPU_MIGRATIONS), "migrations", },
38}; 39};
39 40
41#define __PERF_COUNTER_FIELD(config, name) \
42 ((config & PERF_COUNTER_##name##_MASK) >> PERF_COUNTER_##name##_SHIFT)
43
44#define PERF_COUNTER_RAW(config) __PERF_COUNTER_FIELD(config, RAW)
45#define PERF_COUNTER_CONFIG(config) __PERF_COUNTER_FIELD(config, CONFIG)
46#define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE)
47#define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT)
48
49static char *hw_event_names[] = {
50 "CPU cycles",
51 "instructions",
52 "cache references",
53 "cache misses",
54 "branches",
55 "branch misses",
56 "bus cycles",
57};
58
59static char *sw_event_names[] = {
60 "cpu clock ticks",
61 "task clock ticks",
62 "pagefaults",
63 "context switches",
64 "CPU migrations",
65 "minor faults",
66 "major faults",
67};
68
69char *event_name(int ctr)
70{
71 __u64 config = event_id[ctr];
72 int type = PERF_COUNTER_TYPE(config);
73 int id = PERF_COUNTER_ID(config);
74 static char buf[32];
75
76 if (PERF_COUNTER_RAW(config)) {
77 sprintf(buf, "raw 0x%llx", PERF_COUNTER_CONFIG(config));
78 return buf;
79 }
80
81 switch (type) {
82 case PERF_TYPE_HARDWARE:
83 if (id < PERF_HW_EVENTS_MAX)
84 return hw_event_names[id];
85 return "unknown-hardware";
86
87 case PERF_TYPE_SOFTWARE:
88 if (id < PERF_SW_EVENTS_MAX)
89 return sw_event_names[id];
90 return "unknown-software";
91
92 default:
93 break;
94 }
95
96 return "unknown";
97}
98
40/* 99/*
41 * Each event can have multiple symbolic names. 100 * Each event can have multiple symbolic names.
42 * Symbolic names are (almost) exactly matched. 101 * Symbolic names are (almost) exactly matched.
@@ -46,12 +105,23 @@ static __u64 match_event_symbols(const char *str)
46 __u64 config, id; 105 __u64 config, id;
47 int type; 106 int type;
48 unsigned int i; 107 unsigned int i;
108 char mask_str[4];
49 109
50 if (sscanf(str, "r%llx", &config) == 1) 110 if (sscanf(str, "r%llx", &config) == 1)
51 return config | PERF_COUNTER_RAW_MASK; 111 return config | PERF_COUNTER_RAW_MASK;
52 112
53 if (sscanf(str, "%d:%llu", &type, &id) == 2) 113 switch (sscanf(str, "%d:%llu:%2s", &type, &id, mask_str)) {
54 return EID(type, id); 114 case 3:
115 if (strchr(mask_str, 'k'))
116 event_mask[nr_counters] |= EVENT_MASK_USER;
117 if (strchr(mask_str, 'u'))
118 event_mask[nr_counters] |= EVENT_MASK_KERNEL;
119 case 2:
120 return EID(type, id);
121
122 default:
123 break;
124 }
55 125
56 for (i = 0; i < ARRAY_SIZE(event_symbols); i++) { 126 for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
57 if (!strncmp(str, event_symbols[i].symbol, 127 if (!strncmp(str, event_symbols[i].symbol,
@@ -86,14 +156,6 @@ again:
86 return 0; 156 return 0;
87} 157}
88 158
89#define __PERF_COUNTER_FIELD(config, name) \
90 ((config & PERF_COUNTER_##name##_MASK) >> PERF_COUNTER_##name##_SHIFT)
91
92#define PERF_COUNTER_RAW(config) __PERF_COUNTER_FIELD(config, RAW)
93#define PERF_COUNTER_CONFIG(config) __PERF_COUNTER_FIELD(config, CONFIG)
94#define PERF_COUNTER_TYPE(config) __PERF_COUNTER_FIELD(config, TYPE)
95#define PERF_COUNTER_ID(config) __PERF_COUNTER_FIELD(config, EVENT)
96
97/* 159/*
98 * Create the help text for the event symbols: 160 * Create the help text for the event symbols:
99 */ 161 */