aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tools/perf/builtin-test.c3
-rw-r--r--tools/perf/perf.c33
-rw-r--r--tools/perf/util/debugfs.c25
-rw-r--r--tools/perf/util/debugfs.h4
-rw-r--r--tools/perf/util/parse-events.c28
-rw-r--r--tools/perf/util/parse-events.h1
6 files changed, 43 insertions, 51 deletions
diff --git a/tools/perf/builtin-test.c b/tools/perf/builtin-test.c
index 831d1baeac3..77d68bfb79d 100644
--- a/tools/perf/builtin-test.c
+++ b/tools/perf/builtin-test.c
@@ -7,6 +7,7 @@
7 7
8#include "util/cache.h" 8#include "util/cache.h"
9#include "util/debug.h" 9#include "util/debug.h"
10#include "util/debugfs.h"
10#include "util/evlist.h" 11#include "util/evlist.h"
11#include "util/parse-options.h" 12#include "util/parse-options.h"
12#include "util/parse-events.h" 13#include "util/parse-events.h"
@@ -247,7 +248,7 @@ static int trace_event__id(const char *evname)
247 248
248 if (asprintf(&filename, 249 if (asprintf(&filename,
249 "%s/syscalls/%s/id", 250 "%s/syscalls/%s/id",
250 debugfs_path, evname) < 0) 251 tracing_events_path, evname) < 0)
251 return -1; 252 return -1;
252 253
253 fd = open(filename, O_RDONLY); 254 fd = open(filename, O_RDONLY);
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 73d0cac8b67..2b2e225a4d4 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -29,8 +29,6 @@ struct pager_config {
29 int val; 29 int val;
30}; 30};
31 31
32static char debugfs_mntpt[MAXPATHLEN];
33
34static int pager_command_config(const char *var, const char *value, void *data) 32static int pager_command_config(const char *var, const char *value, void *data)
35{ 33{
36 struct pager_config *c = data; 34 struct pager_config *c = data;
@@ -81,15 +79,6 @@ static void commit_pager_choice(void)
81 } 79 }
82} 80}
83 81
84static void set_debugfs_path(void)
85{
86 char *path;
87
88 path = getenv(PERF_DEBUGFS_ENVIRONMENT);
89 snprintf(debugfs_path, MAXPATHLEN, "%s/%s", path ?: debugfs_mntpt,
90 "tracing/events");
91}
92
93static int handle_options(const char ***argv, int *argc, int *envchanged) 82static int handle_options(const char ***argv, int *argc, int *envchanged)
94{ 83{
95 int handled = 0; 84 int handled = 0;
@@ -161,15 +150,14 @@ static int handle_options(const char ***argv, int *argc, int *envchanged)
161 fprintf(stderr, "No directory given for --debugfs-dir.\n"); 150 fprintf(stderr, "No directory given for --debugfs-dir.\n");
162 usage(perf_usage_string); 151 usage(perf_usage_string);
163 } 152 }
164 strncpy(debugfs_mntpt, (*argv)[1], MAXPATHLEN); 153 debugfs_set_path((*argv)[1]);
165 debugfs_mntpt[MAXPATHLEN - 1] = '\0';
166 if (envchanged) 154 if (envchanged)
167 *envchanged = 1; 155 *envchanged = 1;
168 (*argv)++; 156 (*argv)++;
169 (*argc)--; 157 (*argc)--;
170 } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) { 158 } else if (!prefixcmp(cmd, CMD_DEBUGFS_DIR)) {
171 strncpy(debugfs_mntpt, cmd + strlen(CMD_DEBUGFS_DIR), MAXPATHLEN); 159 debugfs_set_path(cmd + strlen(CMD_DEBUGFS_DIR));
172 debugfs_mntpt[MAXPATHLEN - 1] = '\0'; 160 fprintf(stderr, "dir: %s\n", debugfs_mountpoint);
173 if (envchanged) 161 if (envchanged)
174 *envchanged = 1; 162 *envchanged = 1;
175 } else { 163 } else {
@@ -281,7 +269,6 @@ static int run_builtin(struct cmd_struct *p, int argc, const char **argv)
281 if (use_pager == -1 && p->option & USE_PAGER) 269 if (use_pager == -1 && p->option & USE_PAGER)
282 use_pager = 1; 270 use_pager = 1;
283 commit_pager_choice(); 271 commit_pager_choice();
284 set_debugfs_path();
285 272
286 status = p->fn(argc, argv, prefix); 273 status = p->fn(argc, argv, prefix);
287 exit_browser(status); 274 exit_browser(status);
@@ -416,17 +403,6 @@ static int run_argv(int *argcp, const char ***argv)
416 return done_alias; 403 return done_alias;
417} 404}
418 405
419/* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */
420static void get_debugfs_mntpt(void)
421{
422 const char *path = debugfs_mount(NULL);
423
424 if (path)
425 strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt));
426 else
427 debugfs_mntpt[0] = '\0';
428}
429
430static void pthread__block_sigwinch(void) 406static void pthread__block_sigwinch(void)
431{ 407{
432 sigset_t set; 408 sigset_t set;
@@ -453,7 +429,7 @@ int main(int argc, const char **argv)
453 if (!cmd) 429 if (!cmd)
454 cmd = "perf-help"; 430 cmd = "perf-help";
455 /* get debugfs mount point from /proc/mounts */ 431 /* get debugfs mount point from /proc/mounts */
456 get_debugfs_mntpt(); 432 debugfs_mount(NULL);
457 /* 433 /*
458 * "perf-xxxx" is the same as "perf xxxx", but we obviously: 434 * "perf-xxxx" is the same as "perf xxxx", but we obviously:
459 * 435 *
@@ -476,7 +452,6 @@ int main(int argc, const char **argv)
476 argc--; 452 argc--;
477 handle_options(&argv, &argc, NULL); 453 handle_options(&argv, &argc, NULL);
478 commit_pager_choice(); 454 commit_pager_choice();
479 set_debugfs_path();
480 set_buildid_dir(); 455 set_buildid_dir();
481 456
482 if (argc > 0) { 457 if (argc > 0) {
diff --git a/tools/perf/util/debugfs.c b/tools/perf/util/debugfs.c
index 680be3460e8..ffc35e748e8 100644
--- a/tools/perf/util/debugfs.c
+++ b/tools/perf/util/debugfs.c
@@ -2,10 +2,12 @@
2#include "debugfs.h" 2#include "debugfs.h"
3#include "cache.h" 3#include "cache.h"
4 4
5#include <linux/kernel.h>
5#include <sys/mount.h> 6#include <sys/mount.h>
6 7
7static int debugfs_premounted; 8static int debugfs_premounted;
8static char debugfs_mountpoint[PATH_MAX + 1]; 9char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug";
10char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events";
9 11
10static const char *debugfs_known_mountpoints[] = { 12static const char *debugfs_known_mountpoints[] = {
11 "/sys/kernel/debug/", 13 "/sys/kernel/debug/",
@@ -64,7 +66,7 @@ const char *debugfs_find_mountpoint(void)
64 /* give up and parse /proc/mounts */ 66 /* give up and parse /proc/mounts */
65 fp = fopen("/proc/mounts", "r"); 67 fp = fopen("/proc/mounts", "r");
66 if (fp == NULL) 68 if (fp == NULL)
67 die("Can't open /proc/mounts for read"); 69 return NULL;
68 70
69 while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", 71 while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
70 debugfs_mountpoint, type) == 2) { 72 debugfs_mountpoint, type) == 2) {
@@ -106,6 +108,12 @@ int debugfs_valid_entry(const char *path)
106 return 0; 108 return 0;
107} 109}
108 110
111static void debugfs_set_tracing_events_path(const char *mountpoint)
112{
113 snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
114 mountpoint, "tracing/events");
115}
116
109/* mount the debugfs somewhere if it's not mounted */ 117/* mount the debugfs somewhere if it's not mounted */
110 118
111char *debugfs_mount(const char *mountpoint) 119char *debugfs_mount(const char *mountpoint)
@@ -113,7 +121,7 @@ char *debugfs_mount(const char *mountpoint)
113 /* see if it's already mounted */ 121 /* see if it's already mounted */
114 if (debugfs_find_mountpoint()) { 122 if (debugfs_find_mountpoint()) {
115 debugfs_premounted = 1; 123 debugfs_premounted = 1;
116 return debugfs_mountpoint; 124 goto out;
117 } 125 }
118 126
119 /* if not mounted and no argument */ 127 /* if not mounted and no argument */
@@ -129,12 +137,19 @@ char *debugfs_mount(const char *mountpoint)
129 return NULL; 137 return NULL;
130 138
131 /* save the mountpoint */ 139 /* save the mountpoint */
132 strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint));
133 debugfs_found = 1; 140 debugfs_found = 1;
134 141 strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint));
142out:
143 debugfs_set_tracing_events_path(debugfs_mountpoint);
135 return debugfs_mountpoint; 144 return debugfs_mountpoint;
136} 145}
137 146
147void debugfs_set_path(const char *mountpoint)
148{
149 snprintf(debugfs_mountpoint, sizeof(debugfs_mountpoint), "%s", mountpoint);
150 debugfs_set_tracing_events_path(mountpoint);
151}
152
138/* umount the debugfs */ 153/* umount the debugfs */
139 154
140int debugfs_umount(void) 155int debugfs_umount(void)
diff --git a/tools/perf/util/debugfs.h b/tools/perf/util/debugfs.h
index 8cd3fa0af88..4a878f735eb 100644
--- a/tools/perf/util/debugfs.h
+++ b/tools/perf/util/debugfs.h
@@ -6,9 +6,13 @@ int debugfs_valid_mountpoint(const char *debugfs);
6int debugfs_valid_entry(const char *path); 6int debugfs_valid_entry(const char *path);
7char *debugfs_mount(const char *mountpoint); 7char *debugfs_mount(const char *mountpoint);
8int debugfs_umount(void); 8int debugfs_umount(void);
9void debugfs_set_path(const char *mountpoint);
9int debugfs_write(const char *entry, const char *value); 10int debugfs_write(const char *entry, const char *value);
10int debugfs_read(const char *entry, char *buffer, size_t size); 11int debugfs_read(const char *entry, char *buffer, size_t size);
11void debugfs_force_cleanup(void); 12void debugfs_force_cleanup(void);
12int debugfs_make_path(const char *element, char *buffer, int size); 13int debugfs_make_path(const char *element, char *buffer, int size);
13 14
15extern char debugfs_mountpoint[];
16extern char tracing_events_path[];
17
14#endif /* __DEBUGFS_H__ */ 18#endif /* __DEBUGFS_H__ */
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index 928918b796b..586ab3fe60f 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -25,8 +25,6 @@ enum event_result {
25 EVT_HANDLED_ALL 25 EVT_HANDLED_ALL
26}; 26};
27 27
28char debugfs_path[MAXPATHLEN];
29
30#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x 28#define CHW(x) .type = PERF_TYPE_HARDWARE, .config = PERF_COUNT_HW_##x
31#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x 29#define CSW(x) .type = PERF_TYPE_SOFTWARE, .config = PERF_COUNT_SW_##x
32 30
@@ -140,7 +138,7 @@ static int tp_event_has_id(struct dirent *sys_dir, struct dirent *evt_dir)
140 char evt_path[MAXPATHLEN]; 138 char evt_path[MAXPATHLEN];
141 int fd; 139 int fd;
142 140
143 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, 141 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path,
144 sys_dir->d_name, evt_dir->d_name); 142 sys_dir->d_name, evt_dir->d_name);
145 fd = open(evt_path, O_RDONLY); 143 fd = open(evt_path, O_RDONLY);
146 if (fd < 0) 144 if (fd < 0)
@@ -171,16 +169,16 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
171 char evt_path[MAXPATHLEN]; 169 char evt_path[MAXPATHLEN];
172 char dir_path[MAXPATHLEN]; 170 char dir_path[MAXPATHLEN];
173 171
174 if (debugfs_valid_mountpoint(debugfs_path)) 172 if (debugfs_valid_mountpoint(tracing_events_path))
175 return NULL; 173 return NULL;
176 174
177 sys_dir = opendir(debugfs_path); 175 sys_dir = opendir(tracing_events_path);
178 if (!sys_dir) 176 if (!sys_dir)
179 return NULL; 177 return NULL;
180 178
181 for_each_subsystem(sys_dir, sys_dirent, sys_next) { 179 for_each_subsystem(sys_dir, sys_dirent, sys_next) {
182 180
183 snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, 181 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
184 sys_dirent.d_name); 182 sys_dirent.d_name);
185 evt_dir = opendir(dir_path); 183 evt_dir = opendir(dir_path);
186 if (!evt_dir) 184 if (!evt_dir)
@@ -447,7 +445,7 @@ parse_single_tracepoint_event(char *sys_name,
447 u64 id; 445 u64 id;
448 int fd; 446 int fd;
449 447
450 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", debugfs_path, 448 snprintf(evt_path, MAXPATHLEN, "%s/%s/%s/id", tracing_events_path,
451 sys_name, evt_name); 449 sys_name, evt_name);
452 450
453 fd = open(evt_path, O_RDONLY); 451 fd = open(evt_path, O_RDONLY);
@@ -485,7 +483,7 @@ parse_multiple_tracepoint_event(struct perf_evlist *evlist, char *sys_name,
485 struct dirent *evt_ent; 483 struct dirent *evt_ent;
486 DIR *evt_dir; 484 DIR *evt_dir;
487 485
488 snprintf(evt_path, MAXPATHLEN, "%s/%s", debugfs_path, sys_name); 486 snprintf(evt_path, MAXPATHLEN, "%s/%s", tracing_events_path, sys_name);
489 evt_dir = opendir(evt_path); 487 evt_dir = opendir(evt_path);
490 488
491 if (!evt_dir) { 489 if (!evt_dir) {
@@ -528,7 +526,7 @@ parse_tracepoint_event(struct perf_evlist *evlist, const char **strp,
528 char sys_name[MAX_EVENT_LENGTH]; 526 char sys_name[MAX_EVENT_LENGTH];
529 unsigned int sys_length, evt_length; 527 unsigned int sys_length, evt_length;
530 528
531 if (debugfs_valid_mountpoint(debugfs_path)) 529 if (debugfs_valid_mountpoint(tracing_events_path))
532 return 0; 530 return 0;
533 531
534 evt_name = strchr(*strp, ':'); 532 evt_name = strchr(*strp, ':');
@@ -920,10 +918,10 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob)
920 char evt_path[MAXPATHLEN]; 918 char evt_path[MAXPATHLEN];
921 char dir_path[MAXPATHLEN]; 919 char dir_path[MAXPATHLEN];
922 920
923 if (debugfs_valid_mountpoint(debugfs_path)) 921 if (debugfs_valid_mountpoint(tracing_events_path))
924 return; 922 return;
925 923
926 sys_dir = opendir(debugfs_path); 924 sys_dir = opendir(tracing_events_path);
927 if (!sys_dir) 925 if (!sys_dir)
928 return; 926 return;
929 927
@@ -932,7 +930,7 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob)
932 !strglobmatch(sys_dirent.d_name, subsys_glob)) 930 !strglobmatch(sys_dirent.d_name, subsys_glob))
933 continue; 931 continue;
934 932
935 snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, 933 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
936 sys_dirent.d_name); 934 sys_dirent.d_name);
937 evt_dir = opendir(dir_path); 935 evt_dir = opendir(dir_path);
938 if (!evt_dir) 936 if (!evt_dir)
@@ -964,16 +962,16 @@ int is_valid_tracepoint(const char *event_string)
964 char evt_path[MAXPATHLEN]; 962 char evt_path[MAXPATHLEN];
965 char dir_path[MAXPATHLEN]; 963 char dir_path[MAXPATHLEN];
966 964
967 if (debugfs_valid_mountpoint(debugfs_path)) 965 if (debugfs_valid_mountpoint(tracing_events_path))
968 return 0; 966 return 0;
969 967
970 sys_dir = opendir(debugfs_path); 968 sys_dir = opendir(tracing_events_path);
971 if (!sys_dir) 969 if (!sys_dir)
972 return 0; 970 return 0;
973 971
974 for_each_subsystem(sys_dir, sys_dirent, sys_next) { 972 for_each_subsystem(sys_dir, sys_dirent, sys_next) {
975 973
976 snprintf(dir_path, MAXPATHLEN, "%s/%s", debugfs_path, 974 snprintf(dir_path, MAXPATHLEN, "%s/%s", tracing_events_path,
977 sys_dirent.d_name); 975 sys_dirent.d_name);
978 evt_dir = opendir(dir_path); 976 evt_dir = opendir(dir_path);
979 if (!evt_dir) 977 if (!evt_dir)
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index 2f8e375e038..7e0cbe75d5f 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -39,7 +39,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob);
39int print_hwcache_events(const char *event_glob); 39int print_hwcache_events(const char *event_glob);
40extern int is_valid_tracepoint(const char *event_string); 40extern int is_valid_tracepoint(const char *event_string);
41 41
42extern char debugfs_path[];
43extern int valid_debugfs_mount(const char *debugfs); 42extern int valid_debugfs_mount(const char *debugfs);
44 43
45#endif /* __PERF_PARSE_EVENTS_H */ 44#endif /* __PERF_PARSE_EVENTS_H */