aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/parse-events.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/perf/util/parse-events.c')
-rw-r--r--tools/perf/util/parse-events.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 5a3cd3a34af1..7bdad8df22a6 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -5,6 +5,7 @@
5#include "parse-events.h" 5#include "parse-events.h"
6#include "exec_cmd.h" 6#include "exec_cmd.h"
7#include "string.h" 7#include "string.h"
8#include "cache.h"
8 9
9extern char *strcasestr(const char *haystack, const char *needle); 10extern char *strcasestr(const char *haystack, const char *needle);
10 11
@@ -12,8 +13,6 @@ int nr_counters;
12 13
13struct perf_counter_attr attrs[MAX_COUNTERS]; 14struct perf_counter_attr attrs[MAX_COUNTERS];
14 15
15static char default_debugfs_path[] = "/sys/kernel/debug/tracing/events";
16
17struct event_symbol { 16struct event_symbol {
18 u8 type; 17 u8 type;
19 u64 config; 18 u64 config;
@@ -21,6 +20,8 @@ struct event_symbol {
21 char *alias; 20 char *alias;
22}; 21};
23 22
23char debugfs_path[MAXPATHLEN];
24
24#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x 25#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
25#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x 26#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
26 27
@@ -114,27 +115,27 @@ static unsigned long hw_cache_stat[C(MAX)] = {
114 115
115#define for_each_subsystem(sys_dir, sys_dirent, sys_next, file, st) \ 116#define for_each_subsystem(sys_dir, sys_dirent, sys_next, file, st) \
116 while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \ 117 while (!readdir_r(sys_dir, &sys_dirent, &sys_next) && sys_next) \
117 if (snprintf(file, MAXPATHLEN, "%s/%s", default_debugfs_path, \ 118 if (snprintf(file, MAXPATHLEN, "%s/%s", debugfs_path, \
118 sys_dirent.d_name) && \ 119 sys_dirent.d_name) && \
119 (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \ 120 (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \
120 (strcmp(sys_dirent.d_name, ".")) && \ 121 (strcmp(sys_dirent.d_name, ".")) && \
121 (strcmp(sys_dirent.d_name, ".."))) 122 (strcmp(sys_dirent.d_name, "..")))
122 123
123#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next, file, st) \ 124#define for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next, file, st) \
124 while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \ 125 while (!readdir_r(evt_dir, &evt_dirent, &evt_next) && evt_next) \
125 if (snprintf(file, MAXPATHLEN, "%s/%s/%s", default_debugfs_path, \ 126 if (snprintf(file, MAXPATHLEN, "%s/%s/%s", debugfs_path, \
126 sys_dirent.d_name, evt_dirent.d_name) && \ 127 sys_dirent.d_name, evt_dirent.d_name) && \
127 (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \ 128 (!stat(file, &st)) && (S_ISDIR(st.st_mode)) && \
128 (strcmp(evt_dirent.d_name, ".")) && \ 129 (strcmp(evt_dirent.d_name, ".")) && \
129 (strcmp(evt_dirent.d_name, ".."))) 130 (strcmp(evt_dirent.d_name, "..")))
130 131
131#define MAX_EVENT_LENGTH 30 132#define MAX_EVENT_LENGTH 30
132 133
133static int valid_debugfs_mount(void) 134int valid_debugfs_mount(const char *debugfs)
134{ 135{
135 struct statfs st_fs; 136 struct statfs st_fs;
136 137
137 if (statfs(default_debugfs_path, &st_fs) < 0) 138 if (statfs(debugfs, &st_fs) < 0)
138 return -ENOENT; 139 return -ENOENT;
139 else if (st_fs.f_type != (long) DEBUGFS_MAGIC) 140 else if (st_fs.f_type != (long) DEBUGFS_MAGIC)
140 return -ENOENT; 141 return -ENOENT;
@@ -152,10 +153,10 @@ static char *tracepoint_id_to_name(u64 config)
152 u64 id; 153 u64 id;
153 char evt_path[MAXPATHLEN]; 154 char evt_path[MAXPATHLEN];
154 155
155 if (valid_debugfs_mount()) 156 if (valid_debugfs_mount(debugfs_path))
156 return "unkown"; 157 return "unkown";
157 158
158 sys_dir = opendir(default_debugfs_path); 159 sys_dir = opendir(debugfs_path);
159 if (!sys_dir) 160 if (!sys_dir)
160 goto cleanup; 161 goto cleanup;
161 162
@@ -166,7 +167,7 @@ static char *tracepoint_id_to_name(u64 config)
166 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next, 167 for_each_event(sys_dirent, evt_dir, evt_dirent, evt_next,
167 evt_path, st) { 168 evt_path, st) {
168 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", 169 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id",
169 default_debugfs_path, sys_dirent.d_name, 170 debugfs_path, sys_dirent.d_name,
170 evt_dirent.d_name); 171 evt_dirent.d_name);
171 fd = open(evt_path, O_RDONLY); 172 fd = open(evt_path, O_RDONLY);
172 if (fd < 0) 173 if (fd < 0)
@@ -363,7 +364,7 @@ static int parse_tracepoint_event(const char **strp,
363 u64 id; 364 u64 id;
364 char evt_path[MAXPATHLEN]; 365 char evt_path[MAXPATHLEN];
365 366
366 if (valid_debugfs_mount()) 367 if (valid_debugfs_mount(debugfs_path))
367 return 0; 368 return 0;
368 369
369 evt_name = strchr(*strp, ':'); 370 evt_name = strchr(*strp, ':');
@@ -381,8 +382,8 @@ static int parse_tracepoint_event(const char **strp,
381 if (evt_length >= MAX_EVENT_LENGTH) 382 if (evt_length >= MAX_EVENT_LENGTH)
382 return 0; 383 return 0;
383 384
384 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", default_debugfs_path, 385 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path,
385 sys_name, evt_name); 386 sys_name, evt_name);
386 fd = open(evt_path, O_RDONLY); 387 fd = open(evt_path, O_RDONLY);
387 if (fd < 0) 388 if (fd < 0)
388 return 0; 389 return 0;
@@ -568,10 +569,10 @@ static void print_tracepoint_events(void)
568 struct stat st; 569 struct stat st;
569 char evt_path[MAXPATHLEN]; 570 char evt_path[MAXPATHLEN];
570 571
571 if (valid_debugfs_mount()) 572 if (valid_debugfs_mount(debugfs_path))
572 return; 573 return;
573 574
574 sys_dir = opendir(default_debugfs_path); 575 sys_dir = opendir(debugfs_path);
575 if (!sys_dir) 576 if (!sys_dir)
576 goto cleanup; 577 goto cleanup;
577 578