xref: /linux/tools/perf/util/parse-events.c (revision 129c04cb8ce2e4bf3f17223f58ef16aa8a2cb3b8)
11b290d67SFrederic Weisbecker #include "../../../include/linux/hw_breakpoint.h"
286470930SIngo Molnar #include "util.h"
36b58e7f1SUlrich Drepper #include "../perf.h"
4361c99a6SArnaldo Carvalho de Melo #include "evlist.h"
569aad6f1SArnaldo Carvalho de Melo #include "evsel.h"
686470930SIngo Molnar #include "parse-options.h"
786470930SIngo Molnar #include "parse-events.h"
886470930SIngo Molnar #include "exec_cmd.h"
986470930SIngo Molnar #include "string.h"
105aab621bSArnaldo Carvalho de Melo #include "symbol.h"
115beeded1SJason Baron #include "cache.h"
128755a8f2SArjan van de Ven #include "header.h"
13549104f2SClark Williams #include "debugfs.h"
1486470930SIngo Molnar 
1586470930SIngo Molnar struct event_symbol {
169cffa8d5SPaul Mackerras 	u8		type;
179cffa8d5SPaul Mackerras 	u64		config;
1883a0944fSIngo Molnar 	const char	*symbol;
1983a0944fSIngo Molnar 	const char	*alias;
2086470930SIngo Molnar };
2186470930SIngo Molnar 
22bcd3279fSFrederic Weisbecker enum event_result {
23bcd3279fSFrederic Weisbecker 	EVT_FAILED,
24bcd3279fSFrederic Weisbecker 	EVT_HANDLED,
25bcd3279fSFrederic Weisbecker 	EVT_HANDLED_ALL
26bcd3279fSFrederic Weisbecker };
27bcd3279fSFrederic Weisbecker 
285beeded1SJason Baron char debugfs_path[MAXPATHLEN];
295beeded1SJason Baron 
3051e26842SJaswinder Singh Rajput #define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
3151e26842SJaswinder Singh Rajput #define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
3286470930SIngo Molnar 
3386470930SIngo Molnar static struct event_symbol event_symbols[] = {
3474d5b588SJaswinder Singh Rajput   { CHW(CPU_CYCLES),			"cpu-cycles",			"cycles"		},
35*129c04cbSIngo Molnar   { CHW(STALLED_CYCLES_FRONTEND),	"stalled-cycles-frontend",	"idle-cycles-frontend"	},
36*129c04cbSIngo Molnar   { CHW(STALLED_CYCLES_BACKEND),	"stalled-cycles-backend",	"idle-cycles-backend"	},
3774d5b588SJaswinder Singh Rajput   { CHW(INSTRUCTIONS),			"instructions",			""			},
3874d5b588SJaswinder Singh Rajput   { CHW(CACHE_REFERENCES),		"cache-references",		""			},
3974d5b588SJaswinder Singh Rajput   { CHW(CACHE_MISSES),			"cache-misses",			""			},
4074d5b588SJaswinder Singh Rajput   { CHW(BRANCH_INSTRUCTIONS),		"branch-instructions",		"branches"		},
4174d5b588SJaswinder Singh Rajput   { CHW(BRANCH_MISSES),			"branch-misses",		""			},
4274d5b588SJaswinder Singh Rajput   { CHW(BUS_CYCLES),			"bus-cycles",			""			},
4386470930SIngo Molnar 
4474d5b588SJaswinder Singh Rajput   { CSW(CPU_CLOCK),			"cpu-clock",			""			},
4574d5b588SJaswinder Singh Rajput   { CSW(TASK_CLOCK),			"task-clock",			""			},
46c0c22dbfSJaswinder Singh Rajput   { CSW(PAGE_FAULTS),			"page-faults",			"faults"		},
4774d5b588SJaswinder Singh Rajput   { CSW(PAGE_FAULTS_MIN),		"minor-faults",			""			},
4874d5b588SJaswinder Singh Rajput   { CSW(PAGE_FAULTS_MAJ),		"major-faults",			""			},
4974d5b588SJaswinder Singh Rajput   { CSW(CONTEXT_SWITCHES),		"context-switches",		"cs"			},
5074d5b588SJaswinder Singh Rajput   { CSW(CPU_MIGRATIONS),		"cpu-migrations",		"migrations"		},
51f7d79860SAnton Blanchard   { CSW(ALIGNMENT_FAULTS),		"alignment-faults",		""			},
52f7d79860SAnton Blanchard   { CSW(EMULATION_FAULTS),		"emulation-faults",		""			},
5386470930SIngo Molnar };
5486470930SIngo Molnar 
55cdd6c482SIngo Molnar #define __PERF_EVENT_FIELD(config, name) \
56cdd6c482SIngo Molnar 	((config & PERF_EVENT_##name##_MASK) >> PERF_EVENT_##name##_SHIFT)
5786470930SIngo Molnar 
58cdd6c482SIngo Molnar #define PERF_EVENT_RAW(config)		__PERF_EVENT_FIELD(config, RAW)
59cdd6c482SIngo Molnar #define PERF_EVENT_CONFIG(config)	__PERF_EVENT_FIELD(config, CONFIG)
60cdd6c482SIngo Molnar #define PERF_EVENT_TYPE(config)		__PERF_EVENT_FIELD(config, TYPE)
61cdd6c482SIngo Molnar #define PERF_EVENT_ID(config)		__PERF_EVENT_FIELD(config, EVENT)
6286470930SIngo Molnar 
6383a0944fSIngo Molnar static const char *hw_event_names[] = {
6486470930SIngo Molnar 	"cycles",
6586470930SIngo Molnar 	"instructions",
6686470930SIngo Molnar 	"cache-references",
6786470930SIngo Molnar 	"cache-misses",
6886470930SIngo Molnar 	"branches",
6986470930SIngo Molnar 	"branch-misses",
7086470930SIngo Molnar 	"bus-cycles",
711fc570adSIngo Molnar 	"stalled-cycles",
7286470930SIngo Molnar };
7386470930SIngo Molnar 
7483a0944fSIngo Molnar static const char *sw_event_names[] = {
75749141d9SIngo Molnar 	"cpu-clock",
76749141d9SIngo Molnar 	"task-clock",
7786470930SIngo Molnar 	"page-faults",
7886470930SIngo Molnar 	"context-switches",
7986470930SIngo Molnar 	"CPU-migrations",
8086470930SIngo Molnar 	"minor-faults",
8186470930SIngo Molnar 	"major-faults",
82f7d79860SAnton Blanchard 	"alignment-faults",
83f7d79860SAnton Blanchard 	"emulation-faults",
8486470930SIngo Molnar };
8586470930SIngo Molnar 
8686470930SIngo Molnar #define MAX_ALIASES 8
8786470930SIngo Molnar 
8883a0944fSIngo Molnar static const char *hw_cache[][MAX_ALIASES] = {
899590b7baSAnton Blanchard  { "L1-dcache",	"l1-d",		"l1d",		"L1-data",		},
909590b7baSAnton Blanchard  { "L1-icache",	"l1-i",		"l1i",		"L1-instruction",	},
91e5c59547SJaswinder Singh Rajput  { "LLC",	"L2"							},
92e5c59547SJaswinder Singh Rajput  { "dTLB",	"d-tlb",	"Data-TLB",				},
93e5c59547SJaswinder Singh Rajput  { "iTLB",	"i-tlb",	"Instruction-TLB",			},
94e5c59547SJaswinder Singh Rajput  { "branch",	"branches",	"bpu",		"btb",		"bpc",	},
9586470930SIngo Molnar };
9686470930SIngo Molnar 
9783a0944fSIngo Molnar static const char *hw_cache_op[][MAX_ALIASES] = {
98e5c59547SJaswinder Singh Rajput  { "load",	"loads",	"read",					},
99e5c59547SJaswinder Singh Rajput  { "store",	"stores",	"write",				},
100e5c59547SJaswinder Singh Rajput  { "prefetch",	"prefetches",	"speculative-read", "speculative-load",	},
10186470930SIngo Molnar };
10286470930SIngo Molnar 
10383a0944fSIngo Molnar static const char *hw_cache_result[][MAX_ALIASES] = {
104e5c59547SJaswinder Singh Rajput  { "refs",	"Reference",	"ops",		"access",		},
105e5c59547SJaswinder Singh Rajput  { "misses",	"miss",							},
10686470930SIngo Molnar };
10786470930SIngo Molnar 
10806813f6cSJaswinder Singh Rajput #define C(x)		PERF_COUNT_HW_CACHE_##x
10906813f6cSJaswinder Singh Rajput #define CACHE_READ	(1 << C(OP_READ))
11006813f6cSJaswinder Singh Rajput #define CACHE_WRITE	(1 << C(OP_WRITE))
11106813f6cSJaswinder Singh Rajput #define CACHE_PREFETCH	(1 << C(OP_PREFETCH))
11206813f6cSJaswinder Singh Rajput #define COP(x)		(1 << x)
11306813f6cSJaswinder Singh Rajput 
11406813f6cSJaswinder Singh Rajput /*
11506813f6cSJaswinder Singh Rajput  * cache operartion stat
11606813f6cSJaswinder Singh Rajput  * L1I : Read and prefetch only
11706813f6cSJaswinder Singh Rajput  * ITLB and BPU : Read-only
11806813f6cSJaswinder Singh Rajput  */
11906813f6cSJaswinder Singh Rajput static unsigned long hw_cache_stat[C(MAX)] = {
12006813f6cSJaswinder Singh Rajput  [C(L1D)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
12106813f6cSJaswinder Singh Rajput  [C(L1I)]	= (CACHE_READ | CACHE_PREFETCH),
12206813f6cSJaswinder Singh Rajput  [C(LL)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
12306813f6cSJaswinder Singh Rajput  [C(DTLB)]	= (CACHE_READ | CACHE_WRITE | CACHE_PREFETCH),
12406813f6cSJaswinder Singh Rajput  [C(ITLB)]	= (CACHE_READ),
12506813f6cSJaswinder Singh Rajput  [C(BPU)]	= (CACHE_READ),
12606813f6cSJaswinder Singh Rajput };
12706813f6cSJaswinder Singh Rajput 
1286b58e7f1SUlrich Drepper #define for_each_subsystem(sys_dir, sys_dirent, sys_next)	       \
129f6bdafefSJason Baron 	while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next)	       \
1306b58e7f1SUlrich Drepper 	if (sys_dirent.d_type == DT_DIR &&				       \
131f6bdafefSJason Baron 	   (strcmp(sys_dirent.d_name, ".")) &&				       \
132f6bdafefSJason Baron 	   (strcmp(sys_dirent.d_name, "..")))
133f6bdafefSJason Baron 
134ae07b63fSPeter Zijlstra static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
135ae07b63fSPeter Zijlstra {
136ae07b63fSPeter Zijlstra 	char evt_path[MAXPATHLEN];
137ae07b63fSPeter Zijlstra 	int fd;
138ae07b63fSPeter Zijlstra 
139ae07b63fSPeter Zijlstra 	snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
140ae07b63fSPeter Zijlstra 			sys_dir->d_name, evt_dir->d_name);
141ae07b63fSPeter Zijlstra 	fd = open(evt_path, O_RDONLY);
142ae07b63fSPeter Zijlstra 	if (fd < 0)
143ae07b63fSPeter Zijlstra 		return -EINVAL;
144ae07b63fSPeter Zijlstra 	close(fd);
145ae07b63fSPeter Zijlstra 
146ae07b63fSPeter Zijlstra 	return 0;
147ae07b63fSPeter Zijlstra }
148ae07b63fSPeter Zijlstra 
1496b58e7f1SUlrich Drepper #define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next)	       \
150f6bdafefSJason Baron 	while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next)        \
1516b58e7f1SUlrich Drepper 	if (evt_dirent.d_type == DT_DIR &&				       \
152f6bdafefSJason Baron 	   (strcmp(evt_dirent.d_name, ".")) &&				       \
153ae07b63fSPeter Zijlstra 	   (strcmp(evt_dirent.d_name, "..")) &&				       \
154ae07b63fSPeter Zijlstra 	   (!tp_event_has_id(&sys_dirent, &evt_dirent)))
155f6bdafefSJason Baron 
156270bbbe8SLi Zefan #define MAX_EVENT_LENGTH 512
157f6bdafefSJason Baron 
158f6bdafefSJason Baron 
1591ef2ed10SFrederic Weisbecker struct tracepoint_path *tracepoint_id_to_path(u64 config)
160f6bdafefSJason Baron {
1611ef2ed10SFrederic Weisbecker 	struct tracepoint_path *path = NULL;
162f6bdafefSJason Baron 	DIR *sys_dir, *evt_dir;
163f6bdafefSJason Baron 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
164f6bdafefSJason Baron 	char id_buf[4];
165725b1368SEric Dumazet 	int fd;
166f6bdafefSJason Baron 	u64 id;
167f6bdafefSJason Baron 	char evt_path[MAXPATHLEN];
168725b1368SEric Dumazet 	char dir_path[MAXPATHLEN];
169f6bdafefSJason Baron 
170549104f2SClark Williams 	if (debugfs_valid_mountpoint(debugfs_path))
1711ef2ed10SFrederic Weisbecker 		return NULL;
172f6bdafefSJason Baron 
1735beeded1SJason Baron 	sys_dir = opendir(debugfs_path);
174f6bdafefSJason Baron 	if (!sys_dir)
175725b1368SEric Dumazet 		return NULL;
176f6bdafefSJason Baron 
1776b58e7f1SUlrich Drepper 	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
178725b1368SEric Dumazet 
179725b1368SEric Dumazet 		snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
180725b1368SEric Dumazet 			 sys_dirent.d_name);
181725b1368SEric Dumazet 		evt_dir = opendir(dir_path);
182725b1368SEric Dumazet 		if (!evt_dir)
1836b58e7f1SUlrich Drepper 			continue;
184725b1368SEric Dumazet 
1856b58e7f1SUlrich Drepper 		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
186725b1368SEric Dumazet 
187725b1368SEric Dumazet 			snprintf(evt_path, MAXPATHLEN, "%s/%s/id", dir_path,
188f6bdafefSJason Baron 				 evt_dirent.d_name);
189725b1368SEric Dumazet 			fd = open(evt_path, O_RDONLY);
190f6bdafefSJason Baron 			if (fd < 0)
191f6bdafefSJason Baron 				continue;
192f6bdafefSJason Baron 			if (read(fd, id_buf, sizeof(id_buf)) < 0) {
193f6bdafefSJason Baron 				close(fd);
194f6bdafefSJason Baron 				continue;
195f6bdafefSJason Baron 			}
196f6bdafefSJason Baron 			close(fd);
197f6bdafefSJason Baron 			id = atoll(id_buf);
198f6bdafefSJason Baron 			if (id == config) {
199f6bdafefSJason Baron 				closedir(evt_dir);
200f6bdafefSJason Baron 				closedir(sys_dir);
20159b4caebSJulia Lawall 				path = zalloc(sizeof(*path));
2021ef2ed10SFrederic Weisbecker 				path->system = malloc(MAX_EVENT_LENGTH);
2031ef2ed10SFrederic Weisbecker 				if (!path->system) {
2041ef2ed10SFrederic Weisbecker 					free(path);
2051ef2ed10SFrederic Weisbecker 					return NULL;
2061ef2ed10SFrederic Weisbecker 				}
2071ef2ed10SFrederic Weisbecker 				path->name = malloc(MAX_EVENT_LENGTH);
2081ef2ed10SFrederic Weisbecker 				if (!path->name) {
2091ef2ed10SFrederic Weisbecker 					free(path->system);
2101ef2ed10SFrederic Weisbecker 					free(path);
2111ef2ed10SFrederic Weisbecker 					return NULL;
2121ef2ed10SFrederic Weisbecker 				}
2131ef2ed10SFrederic Weisbecker 				strncpy(path->system, sys_dirent.d_name,
2141ef2ed10SFrederic Weisbecker 					MAX_EVENT_LENGTH);
2151ef2ed10SFrederic Weisbecker 				strncpy(path->name, evt_dirent.d_name,
2161ef2ed10SFrederic Weisbecker 					MAX_EVENT_LENGTH);
2171ef2ed10SFrederic Weisbecker 				return path;
218f6bdafefSJason Baron 			}
219f6bdafefSJason Baron 		}
220f6bdafefSJason Baron 		closedir(evt_dir);
221f6bdafefSJason Baron 	}
222f6bdafefSJason Baron 
223f6bdafefSJason Baron 	closedir(sys_dir);
2241ef2ed10SFrederic Weisbecker 	return NULL;
2251ef2ed10SFrederic Weisbecker }
2261ef2ed10SFrederic Weisbecker 
2271ef2ed10SFrederic Weisbecker #define TP_PATH_LEN (MAX_EVENT_LENGTH * 2 + 1)
2281ef2ed10SFrederic Weisbecker static const char *tracepoint_id_to_name(u64 config)
2291ef2ed10SFrederic Weisbecker {
2301ef2ed10SFrederic Weisbecker 	static char buf[TP_PATH_LEN];
2311ef2ed10SFrederic Weisbecker 	struct tracepoint_path *path;
2321ef2ed10SFrederic Weisbecker 
2331ef2ed10SFrederic Weisbecker 	path = tracepoint_id_to_path(config);
2341ef2ed10SFrederic Weisbecker 	if (path) {
2351ef2ed10SFrederic Weisbecker 		snprintf(buf, TP_PATH_LEN, "%s:%s", path->system, path->name);
2361ef2ed10SFrederic Weisbecker 		free(path->name);
2371ef2ed10SFrederic Weisbecker 		free(path->system);
2381ef2ed10SFrederic Weisbecker 		free(path);
2391ef2ed10SFrederic Weisbecker 	} else
2401ef2ed10SFrederic Weisbecker 		snprintf(buf, TP_PATH_LEN, "%s:%s", "unknown", "unknown");
2411ef2ed10SFrederic Weisbecker 
2421ef2ed10SFrederic Weisbecker 	return buf;
243f6bdafefSJason Baron }
244f6bdafefSJason Baron 
24506813f6cSJaswinder Singh Rajput static int is_cache_op_valid(u8 cache_type, u8 cache_op)
24606813f6cSJaswinder Singh Rajput {
24706813f6cSJaswinder Singh Rajput 	if (hw_cache_stat[cache_type] & COP(cache_op))
24806813f6cSJaswinder Singh Rajput 		return 1;	/* valid */
24906813f6cSJaswinder Singh Rajput 	else
25006813f6cSJaswinder Singh Rajput 		return 0;	/* invalid */
25106813f6cSJaswinder Singh Rajput }
25206813f6cSJaswinder Singh Rajput 
253e5c59547SJaswinder Singh Rajput static char *event_cache_name(u8 cache_type, u8 cache_op, u8 cache_result)
254e5c59547SJaswinder Singh Rajput {
255e5c59547SJaswinder Singh Rajput 	static char name[50];
256e5c59547SJaswinder Singh Rajput 
257e5c59547SJaswinder Singh Rajput 	if (cache_result) {
258e5c59547SJaswinder Singh Rajput 		sprintf(name, "%s-%s-%s", hw_cache[cache_type][0],
259e5c59547SJaswinder Singh Rajput 			hw_cache_op[cache_op][0],
260e5c59547SJaswinder Singh Rajput 			hw_cache_result[cache_result][0]);
261e5c59547SJaswinder Singh Rajput 	} else {
262e5c59547SJaswinder Singh Rajput 		sprintf(name, "%s-%s", hw_cache[cache_type][0],
263e5c59547SJaswinder Singh Rajput 			hw_cache_op[cache_op][1]);
264e5c59547SJaswinder Singh Rajput 	}
265e5c59547SJaswinder Singh Rajput 
266e5c59547SJaswinder Singh Rajput 	return name;
267e5c59547SJaswinder Singh Rajput }
268e5c59547SJaswinder Singh Rajput 
2691424dc96SDavid Ahern const char *event_type(int type)
2701424dc96SDavid Ahern {
2711424dc96SDavid Ahern 	switch (type) {
2721424dc96SDavid Ahern 	case PERF_TYPE_HARDWARE:
2731424dc96SDavid Ahern 		return "hardware";
2741424dc96SDavid Ahern 
2751424dc96SDavid Ahern 	case PERF_TYPE_SOFTWARE:
2761424dc96SDavid Ahern 		return "software";
2771424dc96SDavid Ahern 
2781424dc96SDavid Ahern 	case PERF_TYPE_TRACEPOINT:
2791424dc96SDavid Ahern 		return "tracepoint";
2801424dc96SDavid Ahern 
2811424dc96SDavid Ahern 	case PERF_TYPE_HW_CACHE:
2821424dc96SDavid Ahern 		return "hardware-cache";
2831424dc96SDavid Ahern 
2841424dc96SDavid Ahern 	default:
2851424dc96SDavid Ahern 		break;
2861424dc96SDavid Ahern 	}
2871424dc96SDavid Ahern 
2881424dc96SDavid Ahern 	return "unknown";
2891424dc96SDavid Ahern }
2901424dc96SDavid Ahern 
29169aad6f1SArnaldo Carvalho de Melo const char *event_name(struct perf_evsel *evsel)
29286470930SIngo Molnar {
29369aad6f1SArnaldo Carvalho de Melo 	u64 config = evsel->attr.config;
29469aad6f1SArnaldo Carvalho de Melo 	int type = evsel->attr.type;
2958f18aec5SPeter Zijlstra 
296f0c55bcfSStephane Eranian 	if (evsel->name)
297f0c55bcfSStephane Eranian 		return evsel->name;
298f0c55bcfSStephane Eranian 
2998f18aec5SPeter Zijlstra 	return __event_name(type, config);
3008f18aec5SPeter Zijlstra }
3018f18aec5SPeter Zijlstra 
30283a0944fSIngo Molnar const char *__event_name(int type, u64 config)
3038f18aec5SPeter Zijlstra {
30486470930SIngo Molnar 	static char buf[32];
30586470930SIngo Molnar 
3068f18aec5SPeter Zijlstra 	if (type == PERF_TYPE_RAW) {
3079486aa38SArnaldo Carvalho de Melo 		sprintf(buf, "raw 0x%" PRIx64, config);
30886470930SIngo Molnar 		return buf;
30986470930SIngo Molnar 	}
31086470930SIngo Molnar 
31186470930SIngo Molnar 	switch (type) {
31286470930SIngo Molnar 	case PERF_TYPE_HARDWARE:
3131fc570adSIngo Molnar 		if (config < PERF_COUNT_HW_MAX && hw_event_names[config])
31486470930SIngo Molnar 			return hw_event_names[config];
31586470930SIngo Molnar 		return "unknown-hardware";
31686470930SIngo Molnar 
31786470930SIngo Molnar 	case PERF_TYPE_HW_CACHE: {
3189cffa8d5SPaul Mackerras 		u8 cache_type, cache_op, cache_result;
31986470930SIngo Molnar 
32086470930SIngo Molnar 		cache_type   = (config >>  0) & 0xff;
32186470930SIngo Molnar 		if (cache_type > PERF_COUNT_HW_CACHE_MAX)
32286470930SIngo Molnar 			return "unknown-ext-hardware-cache-type";
32386470930SIngo Molnar 
32486470930SIngo Molnar 		cache_op     = (config >>  8) & 0xff;
32586470930SIngo Molnar 		if (cache_op > PERF_COUNT_HW_CACHE_OP_MAX)
32686470930SIngo Molnar 			return "unknown-ext-hardware-cache-op";
32786470930SIngo Molnar 
32886470930SIngo Molnar 		cache_result = (config >> 16) & 0xff;
32986470930SIngo Molnar 		if (cache_result > PERF_COUNT_HW_CACHE_RESULT_MAX)
33086470930SIngo Molnar 			return "unknown-ext-hardware-cache-result";
33186470930SIngo Molnar 
33206813f6cSJaswinder Singh Rajput 		if (!is_cache_op_valid(cache_type, cache_op))
33306813f6cSJaswinder Singh Rajput 			return "invalid-cache";
33486470930SIngo Molnar 
335e5c59547SJaswinder Singh Rajput 		return event_cache_name(cache_type, cache_op, cache_result);
33686470930SIngo Molnar 	}
33786470930SIngo Molnar 
33886470930SIngo Molnar 	case PERF_TYPE_SOFTWARE:
3391fc570adSIngo Molnar 		if (config < PERF_COUNT_SW_MAX && sw_event_names[config])
34086470930SIngo Molnar 			return sw_event_names[config];
34186470930SIngo Molnar 		return "unknown-software";
34286470930SIngo Molnar 
343f6bdafefSJason Baron 	case PERF_TYPE_TRACEPOINT:
344f6bdafefSJason Baron 		return tracepoint_id_to_name(config);
345f6bdafefSJason Baron 
34686470930SIngo Molnar 	default:
34786470930SIngo Molnar 		break;
34886470930SIngo Molnar 	}
34986470930SIngo Molnar 
35086470930SIngo Molnar 	return "unknown";
35186470930SIngo Molnar }
35286470930SIngo Molnar 
35383a0944fSIngo Molnar static int parse_aliases(const char **str, const char *names[][MAX_ALIASES], int size)
35486470930SIngo Molnar {
35586470930SIngo Molnar 	int i, j;
35661c45981SPaul Mackerras 	int n, longest = -1;
35786470930SIngo Molnar 
35886470930SIngo Molnar 	for (i = 0; i < size; i++) {
35961c45981SPaul Mackerras 		for (j = 0; j < MAX_ALIASES && names[i][j]; j++) {
36061c45981SPaul Mackerras 			n = strlen(names[i][j]);
36161c45981SPaul Mackerras 			if (n > longest && !strncasecmp(*str, names[i][j], n))
36261c45981SPaul Mackerras 				longest = n;
36361c45981SPaul Mackerras 		}
36461c45981SPaul Mackerras 		if (longest > 0) {
36561c45981SPaul Mackerras 			*str += longest;
36686470930SIngo Molnar 			return i;
36786470930SIngo Molnar 		}
36886470930SIngo Molnar 	}
36986470930SIngo Molnar 
3708953645fSIngo Molnar 	return -1;
37186470930SIngo Molnar }
37286470930SIngo Molnar 
373bcd3279fSFrederic Weisbecker static enum event_result
374cdd6c482SIngo Molnar parse_generic_hw_event(const char **str, struct perf_event_attr *attr)
37586470930SIngo Molnar {
37661c45981SPaul Mackerras 	const char *s = *str;
37761c45981SPaul Mackerras 	int cache_type = -1, cache_op = -1, cache_result = -1;
37886470930SIngo Molnar 
37961c45981SPaul Mackerras 	cache_type = parse_aliases(&s, hw_cache, PERF_COUNT_HW_CACHE_MAX);
38086470930SIngo Molnar 	/*
38186470930SIngo Molnar 	 * No fallback - if we cannot get a clear cache type
38286470930SIngo Molnar 	 * then bail out:
38386470930SIngo Molnar 	 */
38486470930SIngo Molnar 	if (cache_type == -1)
385bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
38686470930SIngo Molnar 
38761c45981SPaul Mackerras 	while ((cache_op == -1 || cache_result == -1) && *s == '-') {
38861c45981SPaul Mackerras 		++s;
38961c45981SPaul Mackerras 
39061c45981SPaul Mackerras 		if (cache_op == -1) {
39161c45981SPaul Mackerras 			cache_op = parse_aliases(&s, hw_cache_op,
39261c45981SPaul Mackerras 						PERF_COUNT_HW_CACHE_OP_MAX);
39361c45981SPaul Mackerras 			if (cache_op >= 0) {
39461c45981SPaul Mackerras 				if (!is_cache_op_valid(cache_type, cache_op))
39561c45981SPaul Mackerras 					return 0;
39661c45981SPaul Mackerras 				continue;
39761c45981SPaul Mackerras 			}
39861c45981SPaul Mackerras 		}
39961c45981SPaul Mackerras 
40061c45981SPaul Mackerras 		if (cache_result == -1) {
40161c45981SPaul Mackerras 			cache_result = parse_aliases(&s, hw_cache_result,
40261c45981SPaul Mackerras 						PERF_COUNT_HW_CACHE_RESULT_MAX);
40361c45981SPaul Mackerras 			if (cache_result >= 0)
40461c45981SPaul Mackerras 				continue;
40561c45981SPaul Mackerras 		}
40661c45981SPaul Mackerras 
40761c45981SPaul Mackerras 		/*
40861c45981SPaul Mackerras 		 * Can't parse this as a cache op or result, so back up
40961c45981SPaul Mackerras 		 * to the '-'.
41061c45981SPaul Mackerras 		 */
41161c45981SPaul Mackerras 		--s;
41261c45981SPaul Mackerras 		break;
41361c45981SPaul Mackerras 	}
41461c45981SPaul Mackerras 
41586470930SIngo Molnar 	/*
41686470930SIngo Molnar 	 * Fall back to reads:
41786470930SIngo Molnar 	 */
4188953645fSIngo Molnar 	if (cache_op == -1)
4198953645fSIngo Molnar 		cache_op = PERF_COUNT_HW_CACHE_OP_READ;
42086470930SIngo Molnar 
42186470930SIngo Molnar 	/*
42286470930SIngo Molnar 	 * Fall back to accesses:
42386470930SIngo Molnar 	 */
42486470930SIngo Molnar 	if (cache_result == -1)
42586470930SIngo Molnar 		cache_result = PERF_COUNT_HW_CACHE_RESULT_ACCESS;
42686470930SIngo Molnar 
42786470930SIngo Molnar 	attr->config = cache_type | (cache_op << 8) | (cache_result << 16);
42886470930SIngo Molnar 	attr->type = PERF_TYPE_HW_CACHE;
42986470930SIngo Molnar 
43061c45981SPaul Mackerras 	*str = s;
431bcd3279fSFrederic Weisbecker 	return EVT_HANDLED;
43286470930SIngo Molnar }
43386470930SIngo Molnar 
434bcd3279fSFrederic Weisbecker static enum event_result
435bcd3279fSFrederic Weisbecker parse_single_tracepoint_event(char *sys_name,
436bcd3279fSFrederic Weisbecker 			      const char *evt_name,
437bcd3279fSFrederic Weisbecker 			      unsigned int evt_length,
438cdd6c482SIngo Molnar 			      struct perf_event_attr *attr,
439bcd3279fSFrederic Weisbecker 			      const char **strp)
440bcd3279fSFrederic Weisbecker {
441bcd3279fSFrederic Weisbecker 	char evt_path[MAXPATHLEN];
442bcd3279fSFrederic Weisbecker 	char id_buf[4];
443bcd3279fSFrederic Weisbecker 	u64 id;
444bcd3279fSFrederic Weisbecker 	int fd;
445bcd3279fSFrederic Weisbecker 
446bcd3279fSFrederic Weisbecker 	snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
447bcd3279fSFrederic Weisbecker 		 sys_name, evt_name);
448bcd3279fSFrederic Weisbecker 
449bcd3279fSFrederic Weisbecker 	fd = open(evt_path, O_RDONLY);
450bcd3279fSFrederic Weisbecker 	if (fd < 0)
451bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
452bcd3279fSFrederic Weisbecker 
453bcd3279fSFrederic Weisbecker 	if (read(fd, id_buf, sizeof(id_buf)) < 0) {
454bcd3279fSFrederic Weisbecker 		close(fd);
455bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
456bcd3279fSFrederic Weisbecker 	}
457bcd3279fSFrederic Weisbecker 
458bcd3279fSFrederic Weisbecker 	close(fd);
459bcd3279fSFrederic Weisbecker 	id = atoll(id_buf);
460bcd3279fSFrederic Weisbecker 	attr->config = id;
461bcd3279fSFrederic Weisbecker 	attr->type = PERF_TYPE_TRACEPOINT;
4624c635a4eSCorey Ashford 	*strp += strlen(sys_name) + evt_length + 1; /* + 1 for the ':' */
463bcd3279fSFrederic Weisbecker 
4645710fcadSStephane Eranian 	attr->sample_type |= PERF_SAMPLE_RAW;
4655710fcadSStephane Eranian 	attr->sample_type |= PERF_SAMPLE_TIME;
4665710fcadSStephane Eranian 	attr->sample_type |= PERF_SAMPLE_CPU;
4675710fcadSStephane Eranian 
4685710fcadSStephane Eranian 	attr->sample_period = 1;
4695710fcadSStephane Eranian 
4705710fcadSStephane Eranian 
471bcd3279fSFrederic Weisbecker 	return EVT_HANDLED;
472bcd3279fSFrederic Weisbecker }
473bcd3279fSFrederic Weisbecker 
474bcd3279fSFrederic Weisbecker /* sys + ':' + event + ':' + flags*/
475bcd3279fSFrederic Weisbecker #define MAX_EVOPT_LEN	(MAX_EVENT_LENGTH * 2 + 2 + 128)
476bcd3279fSFrederic Weisbecker static enum event_result
47717ea1b70SArnaldo Carvalho de Melo parse_multiple_tracepoint_event(const struct option *opt, char *sys_name,
47817ea1b70SArnaldo Carvalho de Melo 				const char *evt_exp, char *flags)
479bcd3279fSFrederic Weisbecker {
480bcd3279fSFrederic Weisbecker 	char evt_path[MAXPATHLEN];
481bcd3279fSFrederic Weisbecker 	struct dirent *evt_ent;
482bcd3279fSFrederic Weisbecker 	DIR *evt_dir;
483bcd3279fSFrederic Weisbecker 
484bcd3279fSFrederic Weisbecker 	snprintf(evt_path, MAXPATHLEN, "%s/%s", debugfs_path, sys_name);
485bcd3279fSFrederic Weisbecker 	evt_dir = opendir(evt_path);
486bcd3279fSFrederic Weisbecker 
487bcd3279fSFrederic Weisbecker 	if (!evt_dir) {
488bcd3279fSFrederic Weisbecker 		perror("Can't open event dir");
489bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
490bcd3279fSFrederic Weisbecker 	}
491bcd3279fSFrederic Weisbecker 
492bcd3279fSFrederic Weisbecker 	while ((evt_ent = readdir(evt_dir))) {
493bcd3279fSFrederic Weisbecker 		char event_opt[MAX_EVOPT_LEN + 1];
494bcd3279fSFrederic Weisbecker 		int len;
495bcd3279fSFrederic Weisbecker 
496bcd3279fSFrederic Weisbecker 		if (!strcmp(evt_ent->d_name, ".")
497bcd3279fSFrederic Weisbecker 		    || !strcmp(evt_ent->d_name, "..")
498bcd3279fSFrederic Weisbecker 		    || !strcmp(evt_ent->d_name, "enable")
499bcd3279fSFrederic Weisbecker 		    || !strcmp(evt_ent->d_name, "filter"))
500bcd3279fSFrederic Weisbecker 			continue;
501bcd3279fSFrederic Weisbecker 
502fb1d2edfSMasami Hiramatsu 		if (!strglobmatch(evt_ent->d_name, evt_exp))
503fb1d2edfSMasami Hiramatsu 			continue;
504fb1d2edfSMasami Hiramatsu 
505180570fdSUlrich Drepper 		len = snprintf(event_opt, MAX_EVOPT_LEN, "%s:%s%s%s", sys_name,
506180570fdSUlrich Drepper 			       evt_ent->d_name, flags ? ":" : "",
507180570fdSUlrich Drepper 			       flags ?: "");
508bcd3279fSFrederic Weisbecker 		if (len < 0)
509bcd3279fSFrederic Weisbecker 			return EVT_FAILED;
510bcd3279fSFrederic Weisbecker 
51117ea1b70SArnaldo Carvalho de Melo 		if (parse_events(opt, event_opt, 0))
512bcd3279fSFrederic Weisbecker 			return EVT_FAILED;
513bcd3279fSFrederic Weisbecker 	}
514bcd3279fSFrederic Weisbecker 
515bcd3279fSFrederic Weisbecker 	return EVT_HANDLED_ALL;
516bcd3279fSFrederic Weisbecker }
517bcd3279fSFrederic Weisbecker 
51817ea1b70SArnaldo Carvalho de Melo static enum event_result
51917ea1b70SArnaldo Carvalho de Melo parse_tracepoint_event(const struct option *opt, const char **strp,
520cdd6c482SIngo Molnar 		       struct perf_event_attr *attr)
521f6bdafefSJason Baron {
522f6bdafefSJason Baron 	const char *evt_name;
5234c635a4eSCorey Ashford 	char *flags = NULL, *comma_loc;
524f6bdafefSJason Baron 	char sys_name[MAX_EVENT_LENGTH];
525f6bdafefSJason Baron 	unsigned int sys_length, evt_length;
526f6bdafefSJason Baron 
527549104f2SClark Williams 	if (debugfs_valid_mountpoint(debugfs_path))
528f6bdafefSJason Baron 		return 0;
529f6bdafefSJason Baron 
530f6bdafefSJason Baron 	evt_name = strchr(*strp, ':');
531f6bdafefSJason Baron 	if (!evt_name)
532bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
533f6bdafefSJason Baron 
534f6bdafefSJason Baron 	sys_length = evt_name - *strp;
535f6bdafefSJason Baron 	if (sys_length >= MAX_EVENT_LENGTH)
536f6bdafefSJason Baron 		return 0;
537f6bdafefSJason Baron 
538f6bdafefSJason Baron 	strncpy(sys_name, *strp, sys_length);
539f6bdafefSJason Baron 	sys_name[sys_length] = '\0';
540f6bdafefSJason Baron 	evt_name = evt_name + 1;
5413a9f131fSFrederic Weisbecker 
5424c635a4eSCorey Ashford 	comma_loc = strchr(evt_name, ',');
5434c635a4eSCorey Ashford 	if (comma_loc) {
5444c635a4eSCorey Ashford 		/* take the event name up to the comma */
5454c635a4eSCorey Ashford 		evt_name = strndup(evt_name, comma_loc - evt_name);
5464c635a4eSCorey Ashford 	}
5473a9f131fSFrederic Weisbecker 	flags = strchr(evt_name, ':');
5483a9f131fSFrederic Weisbecker 	if (flags) {
5491fc35b29SIngo Molnar 		/* split it out: */
5501fc35b29SIngo Molnar 		evt_name = strndup(evt_name, flags - evt_name);
5513a9f131fSFrederic Weisbecker 		flags++;
5523a9f131fSFrederic Weisbecker 	}
5533a9f131fSFrederic Weisbecker 
554f6bdafefSJason Baron 	evt_length = strlen(evt_name);
555f6bdafefSJason Baron 	if (evt_length >= MAX_EVENT_LENGTH)
556bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
557fb1d2edfSMasami Hiramatsu 	if (strpbrk(evt_name, "*?")) {
558dd9a9ad5SArnaldo Carvalho de Melo 		*strp += strlen(sys_name) + evt_length + 1; /* 1 == the ':' */
55917ea1b70SArnaldo Carvalho de Melo 		return parse_multiple_tracepoint_event(opt, sys_name, evt_name,
560fb1d2edfSMasami Hiramatsu 						       flags);
561f006d25aSHan Pingtian 	} else {
562bcd3279fSFrederic Weisbecker 		return parse_single_tracepoint_event(sys_name, evt_name,
563bdef3b02SFrederic Weisbecker 						     evt_length, attr, strp);
564f6bdafefSJason Baron 	}
565f006d25aSHan Pingtian }
566f6bdafefSJason Baron 
5671b290d67SFrederic Weisbecker static enum event_result
5681b290d67SFrederic Weisbecker parse_breakpoint_type(const char *type, const char **strp,
5691b290d67SFrederic Weisbecker 		      struct perf_event_attr *attr)
5701b290d67SFrederic Weisbecker {
5711b290d67SFrederic Weisbecker 	int i;
5721b290d67SFrederic Weisbecker 
5731b290d67SFrederic Weisbecker 	for (i = 0; i < 3; i++) {
5741b290d67SFrederic Weisbecker 		if (!type[i])
5751b290d67SFrederic Weisbecker 			break;
5761b290d67SFrederic Weisbecker 
5771b290d67SFrederic Weisbecker 		switch (type[i]) {
5781b290d67SFrederic Weisbecker 		case 'r':
5791b290d67SFrederic Weisbecker 			attr->bp_type |= HW_BREAKPOINT_R;
5801b290d67SFrederic Weisbecker 			break;
5811b290d67SFrederic Weisbecker 		case 'w':
5821b290d67SFrederic Weisbecker 			attr->bp_type |= HW_BREAKPOINT_W;
5831b290d67SFrederic Weisbecker 			break;
5841b290d67SFrederic Weisbecker 		case 'x':
5851b290d67SFrederic Weisbecker 			attr->bp_type |= HW_BREAKPOINT_X;
5861b290d67SFrederic Weisbecker 			break;
5871b290d67SFrederic Weisbecker 		default:
5881b290d67SFrederic Weisbecker 			return EVT_FAILED;
5891b290d67SFrederic Weisbecker 		}
5901b290d67SFrederic Weisbecker 	}
5911b290d67SFrederic Weisbecker 	if (!attr->bp_type) /* Default */
5921b290d67SFrederic Weisbecker 		attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W;
5931b290d67SFrederic Weisbecker 
5941b290d67SFrederic Weisbecker 	*strp = type + i;
5951b290d67SFrederic Weisbecker 
5961b290d67SFrederic Weisbecker 	return EVT_HANDLED;
5971b290d67SFrederic Weisbecker }
5981b290d67SFrederic Weisbecker 
5991b290d67SFrederic Weisbecker static enum event_result
6001b290d67SFrederic Weisbecker parse_breakpoint_event(const char **strp, struct perf_event_attr *attr)
6011b290d67SFrederic Weisbecker {
6021b290d67SFrederic Weisbecker 	const char *target;
6031b290d67SFrederic Weisbecker 	const char *type;
6041b290d67SFrederic Weisbecker 	char *endaddr;
6051b290d67SFrederic Weisbecker 	u64 addr;
6061b290d67SFrederic Weisbecker 	enum event_result err;
6071b290d67SFrederic Weisbecker 
6081b290d67SFrederic Weisbecker 	target = strchr(*strp, ':');
6091b290d67SFrederic Weisbecker 	if (!target)
6101b290d67SFrederic Weisbecker 		return EVT_FAILED;
6111b290d67SFrederic Weisbecker 
6121b290d67SFrederic Weisbecker 	if (strncmp(*strp, "mem", target - *strp) != 0)
6131b290d67SFrederic Weisbecker 		return EVT_FAILED;
6141b290d67SFrederic Weisbecker 
6151b290d67SFrederic Weisbecker 	target++;
6161b290d67SFrederic Weisbecker 
6171b290d67SFrederic Weisbecker 	addr = strtoull(target, &endaddr, 0);
6181b290d67SFrederic Weisbecker 	if (target == endaddr)
6191b290d67SFrederic Weisbecker 		return EVT_FAILED;
6201b290d67SFrederic Weisbecker 
6211b290d67SFrederic Weisbecker 	attr->bp_addr = addr;
6221b290d67SFrederic Weisbecker 	*strp = endaddr;
6231b290d67SFrederic Weisbecker 
6241b290d67SFrederic Weisbecker 	type = strchr(target, ':');
6251b290d67SFrederic Weisbecker 
6261b290d67SFrederic Weisbecker 	/* If no type is defined, just rw as default */
6271b290d67SFrederic Weisbecker 	if (!type) {
6281b290d67SFrederic Weisbecker 		attr->bp_type = HW_BREAKPOINT_R | HW_BREAKPOINT_W;
6291b290d67SFrederic Weisbecker 	} else {
6301b290d67SFrederic Weisbecker 		err = parse_breakpoint_type(++type, strp, attr);
6311b290d67SFrederic Weisbecker 		if (err == EVT_FAILED)
6321b290d67SFrederic Weisbecker 			return EVT_FAILED;
6331b290d67SFrederic Weisbecker 	}
6341b290d67SFrederic Weisbecker 
635aa59a485SFrederic Weisbecker 	/*
636aa59a485SFrederic Weisbecker 	 * We should find a nice way to override the access length
637aa59a485SFrederic Weisbecker 	 * Provide some defaults for now
638aa59a485SFrederic Weisbecker 	 */
639aa59a485SFrederic Weisbecker 	if (attr->bp_type == HW_BREAKPOINT_X)
640aa59a485SFrederic Weisbecker 		attr->bp_len = sizeof(long);
641aa59a485SFrederic Weisbecker 	else
6421b290d67SFrederic Weisbecker 		attr->bp_len = HW_BREAKPOINT_LEN_4;
643aa59a485SFrederic Weisbecker 
6441b290d67SFrederic Weisbecker 	attr->type = PERF_TYPE_BREAKPOINT;
6451b290d67SFrederic Weisbecker 
6461b290d67SFrederic Weisbecker 	return EVT_HANDLED;
6471b290d67SFrederic Weisbecker }
6481b290d67SFrederic Weisbecker 
64974d5b588SJaswinder Singh Rajput static int check_events(const char *str, unsigned int i)
65074d5b588SJaswinder Singh Rajput {
65161c45981SPaul Mackerras 	int n;
65274d5b588SJaswinder Singh Rajput 
65361c45981SPaul Mackerras 	n = strlen(event_symbols[i].symbol);
654b908debdSIngo Molnar 	if (!strncasecmp(str, event_symbols[i].symbol, n))
65561c45981SPaul Mackerras 		return n;
65661c45981SPaul Mackerras 
65761c45981SPaul Mackerras 	n = strlen(event_symbols[i].alias);
658b908debdSIngo Molnar 	if (n) {
659b908debdSIngo Molnar 		if (!strncasecmp(str, event_symbols[i].alias, n))
66061c45981SPaul Mackerras 			return n;
661b908debdSIngo Molnar 	}
662b908debdSIngo Molnar 
66361c45981SPaul Mackerras 	return 0;
66461c45981SPaul Mackerras }
66561c45981SPaul Mackerras 
666bcd3279fSFrederic Weisbecker static enum event_result
667cdd6c482SIngo Molnar parse_symbolic_event(const char **strp, struct perf_event_attr *attr)
66861c45981SPaul Mackerras {
66961c45981SPaul Mackerras 	const char *str = *strp;
67061c45981SPaul Mackerras 	unsigned int i;
67161c45981SPaul Mackerras 	int n;
67261c45981SPaul Mackerras 
67361c45981SPaul Mackerras 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++) {
67461c45981SPaul Mackerras 		n = check_events(str, i);
67561c45981SPaul Mackerras 		if (n > 0) {
67661c45981SPaul Mackerras 			attr->type = event_symbols[i].type;
67761c45981SPaul Mackerras 			attr->config = event_symbols[i].config;
67861c45981SPaul Mackerras 			*strp = str + n;
679bcd3279fSFrederic Weisbecker 			return EVT_HANDLED;
68061c45981SPaul Mackerras 		}
68161c45981SPaul Mackerras 	}
682bcd3279fSFrederic Weisbecker 	return EVT_FAILED;
68361c45981SPaul Mackerras }
68461c45981SPaul Mackerras 
685bcd3279fSFrederic Weisbecker static enum event_result
686cdd6c482SIngo Molnar parse_raw_event(const char **strp, struct perf_event_attr *attr)
68761c45981SPaul Mackerras {
68861c45981SPaul Mackerras 	const char *str = *strp;
68961c45981SPaul Mackerras 	u64 config;
69061c45981SPaul Mackerras 	int n;
69161c45981SPaul Mackerras 
69261c45981SPaul Mackerras 	if (*str != 'r')
693bcd3279fSFrederic Weisbecker 		return EVT_FAILED;
69461c45981SPaul Mackerras 	n = hex2u64(str + 1, &config);
69561c45981SPaul Mackerras 	if (n > 0) {
69661c45981SPaul Mackerras 		*strp = str + n + 1;
69761c45981SPaul Mackerras 		attr->type = PERF_TYPE_RAW;
69861c45981SPaul Mackerras 		attr->config = config;
699bcd3279fSFrederic Weisbecker 		return EVT_HANDLED;
70061c45981SPaul Mackerras 	}
701bcd3279fSFrederic Weisbecker 	return EVT_FAILED;
70261c45981SPaul Mackerras }
70361c45981SPaul Mackerras 
704bcd3279fSFrederic Weisbecker static enum event_result
705cdd6c482SIngo Molnar parse_numeric_event(const char **strp, struct perf_event_attr *attr)
70661c45981SPaul Mackerras {
70761c45981SPaul Mackerras 	const char *str = *strp;
70861c45981SPaul Mackerras 	char *endp;
70961c45981SPaul Mackerras 	unsigned long type;
71061c45981SPaul Mackerras 	u64 config;
71161c45981SPaul Mackerras 
71261c45981SPaul Mackerras 	type = strtoul(str, &endp, 0);
71361c45981SPaul Mackerras 	if (endp > str && type < PERF_TYPE_MAX && *endp == ':') {
71461c45981SPaul Mackerras 		str = endp + 1;
71561c45981SPaul Mackerras 		config = strtoul(str, &endp, 0);
71661c45981SPaul Mackerras 		if (endp > str) {
71761c45981SPaul Mackerras 			attr->type = type;
71861c45981SPaul Mackerras 			attr->config = config;
71961c45981SPaul Mackerras 			*strp = endp;
720bcd3279fSFrederic Weisbecker 			return EVT_HANDLED;
72161c45981SPaul Mackerras 		}
72261c45981SPaul Mackerras 	}
723bcd3279fSFrederic Weisbecker 	return EVT_FAILED;
72461c45981SPaul Mackerras }
72561c45981SPaul Mackerras 
726ceb53fbfSIngo Molnar static int
727cdd6c482SIngo Molnar parse_event_modifier(const char **strp, struct perf_event_attr *attr)
72861c45981SPaul Mackerras {
72961c45981SPaul Mackerras 	const char *str = *strp;
730ab608344SPeter Zijlstra 	int exclude = 0;
731ab608344SPeter Zijlstra 	int eu = 0, ek = 0, eh = 0, precise = 0;
73261c45981SPaul Mackerras 
733ceb53fbfSIngo Molnar 	if (!*str)
73461c45981SPaul Mackerras 		return 0;
735ceb53fbfSIngo Molnar 
736ceb53fbfSIngo Molnar 	if (*str++ != ':')
737ceb53fbfSIngo Molnar 		return -1;
738ceb53fbfSIngo Molnar 
73961c45981SPaul Mackerras 	while (*str) {
740ab608344SPeter Zijlstra 		if (*str == 'u') {
741ab608344SPeter Zijlstra 			if (!exclude)
742ab608344SPeter Zijlstra 				exclude = eu = ek = eh = 1;
74361c45981SPaul Mackerras 			eu = 0;
744ab608344SPeter Zijlstra 		} else if (*str == 'k') {
745ab608344SPeter Zijlstra 			if (!exclude)
746ab608344SPeter Zijlstra 				exclude = eu = ek = eh = 1;
74761c45981SPaul Mackerras 			ek = 0;
748ab608344SPeter Zijlstra 		} else if (*str == 'h') {
749ab608344SPeter Zijlstra 			if (!exclude)
750ab608344SPeter Zijlstra 				exclude = eu = ek = eh = 1;
75161c45981SPaul Mackerras 			eh = 0;
752ab608344SPeter Zijlstra 		} else if (*str == 'p') {
753ab608344SPeter Zijlstra 			precise++;
754ab608344SPeter Zijlstra 		} else
75561c45981SPaul Mackerras 			break;
756ab608344SPeter Zijlstra 
75761c45981SPaul Mackerras 		++str;
75861c45981SPaul Mackerras 	}
759ceb53fbfSIngo Molnar 	if (str < *strp + 2)
760ceb53fbfSIngo Molnar 		return -1;
761ceb53fbfSIngo Molnar 
76261c45981SPaul Mackerras 	*strp = str;
763ceb53fbfSIngo Molnar 
76461c45981SPaul Mackerras 	attr->exclude_user   = eu;
76561c45981SPaul Mackerras 	attr->exclude_kernel = ek;
76661c45981SPaul Mackerras 	attr->exclude_hv     = eh;
767ab608344SPeter Zijlstra 	attr->precise_ip     = precise;
768ceb53fbfSIngo Molnar 
76974d5b588SJaswinder Singh Rajput 	return 0;
77074d5b588SJaswinder Singh Rajput }
77174d5b588SJaswinder Singh Rajput 
77286470930SIngo Molnar /*
77386470930SIngo Molnar  * Each event can have multiple symbolic names.
77486470930SIngo Molnar  * Symbolic names are (almost) exactly matched.
77586470930SIngo Molnar  */
776bcd3279fSFrederic Weisbecker static enum event_result
77717ea1b70SArnaldo Carvalho de Melo parse_event_symbols(const struct option *opt, const char **str,
77817ea1b70SArnaldo Carvalho de Melo 		    struct perf_event_attr *attr)
77986470930SIngo Molnar {
780bcd3279fSFrederic Weisbecker 	enum event_result ret;
78186470930SIngo Molnar 
78217ea1b70SArnaldo Carvalho de Melo 	ret = parse_tracepoint_event(opt, str, attr);
783bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
784bcd3279fSFrederic Weisbecker 		goto modifier;
785bcd3279fSFrederic Weisbecker 
786bcd3279fSFrederic Weisbecker 	ret = parse_raw_event(str, attr);
787bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
788bcd3279fSFrederic Weisbecker 		goto modifier;
789bcd3279fSFrederic Weisbecker 
790bcd3279fSFrederic Weisbecker 	ret = parse_numeric_event(str, attr);
791bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
792bcd3279fSFrederic Weisbecker 		goto modifier;
793bcd3279fSFrederic Weisbecker 
794bcd3279fSFrederic Weisbecker 	ret = parse_symbolic_event(str, attr);
795bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
796bcd3279fSFrederic Weisbecker 		goto modifier;
797bcd3279fSFrederic Weisbecker 
798bcd3279fSFrederic Weisbecker 	ret = parse_generic_hw_event(str, attr);
799bcd3279fSFrederic Weisbecker 	if (ret != EVT_FAILED)
800bcd3279fSFrederic Weisbecker 		goto modifier;
801bcd3279fSFrederic Weisbecker 
8021b290d67SFrederic Weisbecker 	ret = parse_breakpoint_event(str, attr);
8031b290d67SFrederic Weisbecker 	if (ret != EVT_FAILED)
8041b290d67SFrederic Weisbecker 		goto modifier;
8051b290d67SFrederic Weisbecker 
80685df6f68SMarti Raudsepp 	fprintf(stderr, "invalid or unsupported event: '%s'\n", *str);
80785df6f68SMarti Raudsepp 	fprintf(stderr, "Run 'perf list' for a list of valid events\n");
808bcd3279fSFrederic Weisbecker 	return EVT_FAILED;
809bcd3279fSFrederic Weisbecker 
810bcd3279fSFrederic Weisbecker modifier:
811ceb53fbfSIngo Molnar 	if (parse_event_modifier(str, attr) < 0) {
812ceb53fbfSIngo Molnar 		fprintf(stderr, "invalid event modifier: '%s'\n", *str);
813ceb53fbfSIngo Molnar 		fprintf(stderr, "Run 'perf list' for a list of valid events and modifiers\n");
814ceb53fbfSIngo Molnar 
815ceb53fbfSIngo Molnar 		return EVT_FAILED;
816ceb53fbfSIngo Molnar 	}
81786470930SIngo Molnar 
818bcd3279fSFrederic Weisbecker 	return ret;
81986470930SIngo Molnar }
82086470930SIngo Molnar 
821361c99a6SArnaldo Carvalho de Melo int parse_events(const struct option *opt, const char *str, int unset __used)
82286470930SIngo Molnar {
823361c99a6SArnaldo Carvalho de Melo 	struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
824cdd6c482SIngo Molnar 	struct perf_event_attr attr;
825bcd3279fSFrederic Weisbecker 	enum event_result ret;
826f0c55bcfSStephane Eranian 	const char *ostr;
82786470930SIngo Molnar 
82861c45981SPaul Mackerras 	for (;;) {
829f0c55bcfSStephane Eranian 		ostr = str;
83061c45981SPaul Mackerras 		memset(&attr, 0, sizeof(attr));
83117ea1b70SArnaldo Carvalho de Melo 		ret = parse_event_symbols(opt, &str, &attr);
832bcd3279fSFrederic Weisbecker 		if (ret == EVT_FAILED)
83361c45981SPaul Mackerras 			return -1;
83461c45981SPaul Mackerras 
83561c45981SPaul Mackerras 		if (!(*str == 0 || *str == ',' || isspace(*str)))
83661c45981SPaul Mackerras 			return -1;
83786470930SIngo Molnar 
838bcd3279fSFrederic Weisbecker 		if (ret != EVT_HANDLED_ALL) {
83969aad6f1SArnaldo Carvalho de Melo 			struct perf_evsel *evsel;
840361c99a6SArnaldo Carvalho de Melo 			evsel = perf_evsel__new(&attr, evlist->nr_entries);
84169aad6f1SArnaldo Carvalho de Melo 			if (evsel == NULL)
84269aad6f1SArnaldo Carvalho de Melo 				return -1;
843361c99a6SArnaldo Carvalho de Melo 			perf_evlist__add(evlist, evsel);
844f0c55bcfSStephane Eranian 
845f0c55bcfSStephane Eranian 			evsel->name = calloc(str - ostr + 1, 1);
846f0c55bcfSStephane Eranian 			if (!evsel->name)
847f0c55bcfSStephane Eranian 				return -1;
848f0c55bcfSStephane Eranian 			strncpy(evsel->name, ostr, str - ostr);
849bcd3279fSFrederic Weisbecker 		}
85086470930SIngo Molnar 
85161c45981SPaul Mackerras 		if (*str == 0)
85261c45981SPaul Mackerras 			break;
85361c45981SPaul Mackerras 		if (*str == ',')
85461c45981SPaul Mackerras 			++str;
85561c45981SPaul Mackerras 		while (isspace(*str))
85661c45981SPaul Mackerras 			++str;
85786470930SIngo Molnar 	}
85886470930SIngo Molnar 
85986470930SIngo Molnar 	return 0;
86086470930SIngo Molnar }
86186470930SIngo Molnar 
862361c99a6SArnaldo Carvalho de Melo int parse_filter(const struct option *opt, const char *str,
863c171b552SLi Zefan 		 int unset __used)
864c171b552SLi Zefan {
865361c99a6SArnaldo Carvalho de Melo 	struct perf_evlist *evlist = *(struct perf_evlist **)opt->value;
86669aad6f1SArnaldo Carvalho de Melo 	struct perf_evsel *last = NULL;
867c171b552SLi Zefan 
868361c99a6SArnaldo Carvalho de Melo 	if (evlist->nr_entries > 0)
869361c99a6SArnaldo Carvalho de Melo 		last = list_entry(evlist->entries.prev, struct perf_evsel, node);
87069aad6f1SArnaldo Carvalho de Melo 
87169aad6f1SArnaldo Carvalho de Melo 	if (last == NULL || last->attr.type != PERF_TYPE_TRACEPOINT) {
872c171b552SLi Zefan 		fprintf(stderr,
873c171b552SLi Zefan 			"-F option should follow a -e tracepoint option\n");
874c171b552SLi Zefan 		return -1;
875c171b552SLi Zefan 	}
876c171b552SLi Zefan 
87769aad6f1SArnaldo Carvalho de Melo 	last->filter = strdup(str);
87869aad6f1SArnaldo Carvalho de Melo 	if (last->filter == NULL) {
879c171b552SLi Zefan 		fprintf(stderr, "not enough memory to hold filter string\n");
880c171b552SLi Zefan 		return -1;
881c171b552SLi Zefan 	}
882c171b552SLi Zefan 
883c171b552SLi Zefan 	return 0;
884c171b552SLi Zefan }
885c171b552SLi Zefan 
88686470930SIngo Molnar static const char * const event_type_descriptors[] = {
88786470930SIngo Molnar 	"Hardware event",
88886470930SIngo Molnar 	"Software event",
88986470930SIngo Molnar 	"Tracepoint event",
89086470930SIngo Molnar 	"Hardware cache event",
89141bdcb23SLiming Wang 	"Raw hardware event descriptor",
89241bdcb23SLiming Wang 	"Hardware breakpoint",
89386470930SIngo Molnar };
89486470930SIngo Molnar 
89586470930SIngo Molnar /*
896f6bdafefSJason Baron  * Print the events from <debugfs_mount_point>/tracing/events
897f6bdafefSJason Baron  */
898f6bdafefSJason Baron 
899668b8788SArnaldo Carvalho de Melo void print_tracepoint_events(const char *subsys_glob, const char *event_glob)
900f6bdafefSJason Baron {
901f6bdafefSJason Baron 	DIR *sys_dir, *evt_dir;
902f6bdafefSJason Baron 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
903f6bdafefSJason Baron 	char evt_path[MAXPATHLEN];
904725b1368SEric Dumazet 	char dir_path[MAXPATHLEN];
905f6bdafefSJason Baron 
906549104f2SClark Williams 	if (debugfs_valid_mountpoint(debugfs_path))
907f6bdafefSJason Baron 		return;
908f6bdafefSJason Baron 
9095beeded1SJason Baron 	sys_dir = opendir(debugfs_path);
910f6bdafefSJason Baron 	if (!sys_dir)
911725b1368SEric Dumazet 		return;
912f6bdafefSJason Baron 
9136b58e7f1SUlrich Drepper 	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
914668b8788SArnaldo Carvalho de Melo 		if (subsys_glob != NULL &&
915668b8788SArnaldo Carvalho de Melo 		    !strglobmatch(sys_dirent.d_name, subsys_glob))
916668b8788SArnaldo Carvalho de Melo 			continue;
917725b1368SEric Dumazet 
918725b1368SEric Dumazet 		snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
919725b1368SEric Dumazet 			 sys_dirent.d_name);
920725b1368SEric Dumazet 		evt_dir = opendir(dir_path);
921725b1368SEric Dumazet 		if (!evt_dir)
9226b58e7f1SUlrich Drepper 			continue;
923725b1368SEric Dumazet 
9246b58e7f1SUlrich Drepper 		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
925668b8788SArnaldo Carvalho de Melo 			if (event_glob != NULL &&
926668b8788SArnaldo Carvalho de Melo 			    !strglobmatch(evt_dirent.d_name, event_glob))
927668b8788SArnaldo Carvalho de Melo 				continue;
928668b8788SArnaldo Carvalho de Melo 
929f6bdafefSJason Baron 			snprintf(evt_path, MAXPATHLEN, "%s:%s",
930f6bdafefSJason Baron 				 sys_dirent.d_name, evt_dirent.d_name);
931689d3018SMarti Raudsepp 			printf("  %-42s [%s]\n", evt_path,
93241bdcb23SLiming Wang 				event_type_descriptors[PERF_TYPE_TRACEPOINT]);
933f6bdafefSJason Baron 		}
934f6bdafefSJason Baron 		closedir(evt_dir);
935f6bdafefSJason Baron 	}
936f6bdafefSJason Baron 	closedir(sys_dir);
937f6bdafefSJason Baron }
938f6bdafefSJason Baron 
939f6bdafefSJason Baron /*
94020c457b8SThomas Renninger  * Check whether event is in <debugfs_mount_point>/tracing/events
94120c457b8SThomas Renninger  */
94220c457b8SThomas Renninger 
94320c457b8SThomas Renninger int is_valid_tracepoint(const char *event_string)
94420c457b8SThomas Renninger {
94520c457b8SThomas Renninger 	DIR *sys_dir, *evt_dir;
94620c457b8SThomas Renninger 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
94720c457b8SThomas Renninger 	char evt_path[MAXPATHLEN];
94820c457b8SThomas Renninger 	char dir_path[MAXPATHLEN];
94920c457b8SThomas Renninger 
95020c457b8SThomas Renninger 	if (debugfs_valid_mountpoint(debugfs_path))
95120c457b8SThomas Renninger 		return 0;
95220c457b8SThomas Renninger 
95320c457b8SThomas Renninger 	sys_dir = opendir(debugfs_path);
95420c457b8SThomas Renninger 	if (!sys_dir)
95520c457b8SThomas Renninger 		return 0;
95620c457b8SThomas Renninger 
95720c457b8SThomas Renninger 	for_each_subsystem(sys_dir, sys_dirent, sys_next) {
95820c457b8SThomas Renninger 
95920c457b8SThomas Renninger 		snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path,
96020c457b8SThomas Renninger 			 sys_dirent.d_name);
96120c457b8SThomas Renninger 		evt_dir = opendir(dir_path);
96220c457b8SThomas Renninger 		if (!evt_dir)
96320c457b8SThomas Renninger 			continue;
96420c457b8SThomas Renninger 
96520c457b8SThomas Renninger 		for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next) {
96620c457b8SThomas Renninger 			snprintf(evt_path, MAXPATHLEN, "%s:%s",
96720c457b8SThomas Renninger 				 sys_dirent.d_name, evt_dirent.d_name);
96820c457b8SThomas Renninger 			if (!strcmp(evt_path, event_string)) {
96920c457b8SThomas Renninger 				closedir(evt_dir);
97020c457b8SThomas Renninger 				closedir(sys_dir);
97120c457b8SThomas Renninger 				return 1;
97220c457b8SThomas Renninger 			}
97320c457b8SThomas Renninger 		}
97420c457b8SThomas Renninger 		closedir(evt_dir);
97520c457b8SThomas Renninger 	}
97620c457b8SThomas Renninger 	closedir(sys_dir);
97720c457b8SThomas Renninger 	return 0;
97820c457b8SThomas Renninger }
97920c457b8SThomas Renninger 
980668b8788SArnaldo Carvalho de Melo void print_events_type(u8 type)
981668b8788SArnaldo Carvalho de Melo {
982668b8788SArnaldo Carvalho de Melo 	struct event_symbol *syms = event_symbols;
983668b8788SArnaldo Carvalho de Melo 	unsigned int i;
984668b8788SArnaldo Carvalho de Melo 	char name[64];
985668b8788SArnaldo Carvalho de Melo 
986668b8788SArnaldo Carvalho de Melo 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
987668b8788SArnaldo Carvalho de Melo 		if (type != syms->type)
988668b8788SArnaldo Carvalho de Melo 			continue;
989668b8788SArnaldo Carvalho de Melo 
990668b8788SArnaldo Carvalho de Melo 		if (strlen(syms->alias))
991668b8788SArnaldo Carvalho de Melo 			snprintf(name, sizeof(name),  "%s OR %s",
992668b8788SArnaldo Carvalho de Melo 				 syms->symbol, syms->alias);
993668b8788SArnaldo Carvalho de Melo 		else
994668b8788SArnaldo Carvalho de Melo 			snprintf(name, sizeof(name), "%s", syms->symbol);
995668b8788SArnaldo Carvalho de Melo 
996668b8788SArnaldo Carvalho de Melo 		printf("  %-42s [%s]\n", name,
997668b8788SArnaldo Carvalho de Melo 			event_type_descriptors[type]);
998668b8788SArnaldo Carvalho de Melo 	}
999668b8788SArnaldo Carvalho de Melo }
1000668b8788SArnaldo Carvalho de Melo 
1001668b8788SArnaldo Carvalho de Melo int print_hwcache_events(const char *event_glob)
1002668b8788SArnaldo Carvalho de Melo {
1003668b8788SArnaldo Carvalho de Melo 	unsigned int type, op, i, printed = 0;
1004668b8788SArnaldo Carvalho de Melo 
1005668b8788SArnaldo Carvalho de Melo 	for (type = 0; type < PERF_COUNT_HW_CACHE_MAX; type++) {
1006668b8788SArnaldo Carvalho de Melo 		for (op = 0; op < PERF_COUNT_HW_CACHE_OP_MAX; op++) {
1007668b8788SArnaldo Carvalho de Melo 			/* skip invalid cache type */
1008668b8788SArnaldo Carvalho de Melo 			if (!is_cache_op_valid(type, op))
1009668b8788SArnaldo Carvalho de Melo 				continue;
1010668b8788SArnaldo Carvalho de Melo 
1011668b8788SArnaldo Carvalho de Melo 			for (i = 0; i < PERF_COUNT_HW_CACHE_RESULT_MAX; i++) {
1012668b8788SArnaldo Carvalho de Melo 				char *name = event_cache_name(type, op, i);
1013668b8788SArnaldo Carvalho de Melo 
1014668b8788SArnaldo Carvalho de Melo 				if (event_glob != NULL &&
1015668b8788SArnaldo Carvalho de Melo 				    !strglobmatch(name, event_glob))
1016668b8788SArnaldo Carvalho de Melo 					continue;
1017668b8788SArnaldo Carvalho de Melo 
1018668b8788SArnaldo Carvalho de Melo 				printf("  %-42s [%s]\n", name,
1019668b8788SArnaldo Carvalho de Melo 					event_type_descriptors[PERF_TYPE_HW_CACHE]);
1020668b8788SArnaldo Carvalho de Melo 				++printed;
1021668b8788SArnaldo Carvalho de Melo 			}
1022668b8788SArnaldo Carvalho de Melo 		}
1023668b8788SArnaldo Carvalho de Melo 	}
1024668b8788SArnaldo Carvalho de Melo 
1025668b8788SArnaldo Carvalho de Melo 	return printed;
1026668b8788SArnaldo Carvalho de Melo }
1027668b8788SArnaldo Carvalho de Melo 
102820c457b8SThomas Renninger /*
102986470930SIngo Molnar  * Print the help text for the event symbols:
103086470930SIngo Molnar  */
1031668b8788SArnaldo Carvalho de Melo void print_events(const char *event_glob)
103286470930SIngo Molnar {
103386470930SIngo Molnar 	struct event_symbol *syms = event_symbols;
1034668b8788SArnaldo Carvalho de Melo 	unsigned int i, type, prev_type = -1, printed = 0, ntypes_printed = 0;
103574d5b588SJaswinder Singh Rajput 	char name[40];
103686470930SIngo Molnar 
1037689d3018SMarti Raudsepp 	printf("\n");
1038689d3018SMarti Raudsepp 	printf("List of pre-defined events (to be used in -e):\n");
103986470930SIngo Molnar 
104086470930SIngo Molnar 	for (i = 0; i < ARRAY_SIZE(event_symbols); i++, syms++) {
104141bdcb23SLiming Wang 		type = syms->type;
104286470930SIngo Molnar 
1043668b8788SArnaldo Carvalho de Melo 		if (type != prev_type && printed) {
1044689d3018SMarti Raudsepp 			printf("\n");
1045668b8788SArnaldo Carvalho de Melo 			printed = 0;
1046668b8788SArnaldo Carvalho de Melo 			ntypes_printed++;
1047668b8788SArnaldo Carvalho de Melo 		}
1048668b8788SArnaldo Carvalho de Melo 
1049668b8788SArnaldo Carvalho de Melo 		if (event_glob != NULL &&
1050668b8788SArnaldo Carvalho de Melo 		    !(strglobmatch(syms->symbol, event_glob) ||
1051668b8788SArnaldo Carvalho de Melo 		      (syms->alias && strglobmatch(syms->alias, event_glob))))
1052668b8788SArnaldo Carvalho de Melo 			continue;
105386470930SIngo Molnar 
105474d5b588SJaswinder Singh Rajput 		if (strlen(syms->alias))
105574d5b588SJaswinder Singh Rajput 			sprintf(name, "%s OR %s", syms->symbol, syms->alias);
105674d5b588SJaswinder Singh Rajput 		else
105774d5b588SJaswinder Singh Rajput 			strcpy(name, syms->symbol);
1058689d3018SMarti Raudsepp 		printf("  %-42s [%s]\n", name,
105986470930SIngo Molnar 			event_type_descriptors[type]);
106086470930SIngo Molnar 
106186470930SIngo Molnar 		prev_type = type;
1062668b8788SArnaldo Carvalho de Melo 		++printed;
106386470930SIngo Molnar 	}
106486470930SIngo Molnar 
1065668b8788SArnaldo Carvalho de Melo 	if (ntypes_printed) {
1066668b8788SArnaldo Carvalho de Melo 		printed = 0;
1067689d3018SMarti Raudsepp 		printf("\n");
1068668b8788SArnaldo Carvalho de Melo 	}
1069668b8788SArnaldo Carvalho de Melo 	print_hwcache_events(event_glob);
107073c24cb8SJaswinder Singh Rajput 
1071668b8788SArnaldo Carvalho de Melo 	if (event_glob != NULL)
1072668b8788SArnaldo Carvalho de Melo 		return;
107373c24cb8SJaswinder Singh Rajput 
1074689d3018SMarti Raudsepp 	printf("\n");
107541bdcb23SLiming Wang 	printf("  %-42s [%s]\n",
10761cf4a063SArnaldo Carvalho de Melo 		"rNNN (see 'perf list --help' on how to encode it)",
10771cf4a063SArnaldo Carvalho de Melo 	       event_type_descriptors[PERF_TYPE_RAW]);
1078689d3018SMarti Raudsepp 	printf("\n");
107986470930SIngo Molnar 
108041bdcb23SLiming Wang 	printf("  %-42s [%s]\n",
108141bdcb23SLiming Wang 			"mem:<addr>[:access]",
108241bdcb23SLiming Wang 			event_type_descriptors[PERF_TYPE_BREAKPOINT]);
10831b290d67SFrederic Weisbecker 	printf("\n");
10841b290d67SFrederic Weisbecker 
1085668b8788SArnaldo Carvalho de Melo 	print_tracepoint_events(NULL, NULL);
1086f6bdafefSJason Baron 
108786470930SIngo Molnar 	exit(129);
108886470930SIngo Molnar }
1089