diff options
author | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-16 11:03:07 -0500 |
---|---|---|
committer | Arnaldo Carvalho de Melo <acme@redhat.com> | 2011-11-28 07:11:28 -0500 |
commit | ebf294bf4f147aff29df5a16bfb0f8ebca15feaa (patch) | |
tree | 37464624abf9243100eab47fdc663def4be121fe /tools/perf/util | |
parent | c168fbfb93a1c4044287858c6784f0bd1f6cfe33 (diff) |
perf tools: Simplify debugfs mountpoint handling code
We don't need to have two PATH_MAX char sized arrays holding it, just
one in util/debugfs.c will do.
Also rename debugfs_path to tracing_events_path, as it is not the path
to debugfs, that is debugfs_mountpoint. Both are now accessible.
This will allow accessing this code in the perf python binding without
having to drag in perf.c and util/parse-events.c.
The defaults for these variables are the canonical "/sys/kernel/debug"
and "/sys/kernel/debug/tracing/events/", removing the need for simple
tools to call debugfs_mount(NULL).
Cc: David Ahern <dsahern@gmail.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Mike Galbraith <efault@gmx.de>
Cc: Paul Mackerras <paulus@samba.org>
Cc: Peter Zijlstra <peterz@infradead.org>
Cc: Stephane Eranian <eranian@google.com>
Link: http://lkml.kernel.org/n/tip-ug9jvtjrsqbluuhqqxpvg30f@git.kernel.org
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r-- | tools/perf/util/debugfs.c | 25 | ||||
-rw-r--r-- | tools/perf/util/debugfs.h | 4 | ||||
-rw-r--r-- | tools/perf/util/parse-events.c | 28 | ||||
-rw-r--r-- | tools/perf/util/parse-events.h | 1 |
4 files changed, 37 insertions, 21 deletions
diff --git a/tools/perf/util/debugfs.c b/tools/perf/util/debugfs.c index 680be3460e86..ffc35e748e89 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 | ||
7 | static int debugfs_premounted; | 8 | static int debugfs_premounted; |
8 | static char debugfs_mountpoint[PATH_MAX + 1]; | 9 | char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug"; |
10 | char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events"; | ||
9 | 11 | ||
10 | static const char *debugfs_known_mountpoints[] = { | 12 | static 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 | ||
111 | static 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 | ||
111 | char *debugfs_mount(const char *mountpoint) | 119 | char *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)); | |
142 | out: | ||
143 | debugfs_set_tracing_events_path(debugfs_mountpoint); | ||
135 | return debugfs_mountpoint; | 144 | return debugfs_mountpoint; |
136 | } | 145 | } |
137 | 146 | ||
147 | void 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 | ||
140 | int debugfs_umount(void) | 155 | int debugfs_umount(void) |
diff --git a/tools/perf/util/debugfs.h b/tools/perf/util/debugfs.h index 8cd3fa0af880..4a878f735eb0 100644 --- a/tools/perf/util/debugfs.h +++ b/tools/perf/util/debugfs.h | |||
@@ -6,9 +6,13 @@ int debugfs_valid_mountpoint(const char *debugfs); | |||
6 | int debugfs_valid_entry(const char *path); | 6 | int debugfs_valid_entry(const char *path); |
7 | char *debugfs_mount(const char *mountpoint); | 7 | char *debugfs_mount(const char *mountpoint); |
8 | int debugfs_umount(void); | 8 | int debugfs_umount(void); |
9 | void debugfs_set_path(const char *mountpoint); | ||
9 | int debugfs_write(const char *entry, const char *value); | 10 | int debugfs_write(const char *entry, const char *value); |
10 | int debugfs_read(const char *entry, char *buffer, size_t size); | 11 | int debugfs_read(const char *entry, char *buffer, size_t size); |
11 | void debugfs_force_cleanup(void); | 12 | void debugfs_force_cleanup(void); |
12 | int debugfs_make_path(const char *element, char *buffer, int size); | 13 | int debugfs_make_path(const char *element, char *buffer, int size); |
13 | 14 | ||
15 | extern char debugfs_mountpoint[]; | ||
16 | extern 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 928918b796b2..586ab3fe60f8 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 | ||
28 | char 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 2f8e375e038d..7e0cbe75d5f1 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); | |||
39 | int print_hwcache_events(const char *event_glob); | 39 | int print_hwcache_events(const char *event_glob); |
40 | extern int is_valid_tracepoint(const char *event_string); | 40 | extern int is_valid_tracepoint(const char *event_string); |
41 | 41 | ||
42 | extern char debugfs_path[]; | ||
43 | extern int valid_debugfs_mount(const char *debugfs); | 42 | extern int valid_debugfs_mount(const char *debugfs); |
44 | 43 | ||
45 | #endif /* __PERF_PARSE_EVENTS_H */ | 44 | #endif /* __PERF_PARSE_EVENTS_H */ |