diff options
Diffstat (limited to 'tools/perf/util/debugfs.c')
-rw-r--r-- | tools/perf/util/debugfs.c | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/tools/perf/util/debugfs.c b/tools/perf/util/debugfs.c index a88fefc0cc0..ffc35e748e8 100644 --- a/tools/perf/util/debugfs.c +++ b/tools/perf/util/debugfs.c | |||
@@ -2,8 +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> | ||
6 | #include <sys/mount.h> | ||
7 | |||
5 | static int debugfs_premounted; | 8 | static int debugfs_premounted; |
6 | static char debugfs_mountpoint[MAX_PATH+1]; | 9 | char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug"; |
10 | char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events"; | ||
7 | 11 | ||
8 | static const char *debugfs_known_mountpoints[] = { | 12 | static const char *debugfs_known_mountpoints[] = { |
9 | "/sys/kernel/debug/", | 13 | "/sys/kernel/debug/", |
@@ -62,11 +66,9 @@ const char *debugfs_find_mountpoint(void) | |||
62 | /* give up and parse /proc/mounts */ | 66 | /* give up and parse /proc/mounts */ |
63 | fp = fopen("/proc/mounts", "r"); | 67 | fp = fopen("/proc/mounts", "r"); |
64 | if (fp == NULL) | 68 | if (fp == NULL) |
65 | die("Can't open /proc/mounts for read"); | 69 | return NULL; |
66 | 70 | ||
67 | while (fscanf(fp, "%*s %" | 71 | while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n", |
68 | STR(MAX_PATH) | ||
69 | "s %99s %*s %*d %*d\n", | ||
70 | debugfs_mountpoint, type) == 2) { | 72 | debugfs_mountpoint, type) == 2) { |
71 | if (strcmp(type, "debugfs") == 0) | 73 | if (strcmp(type, "debugfs") == 0) |
72 | break; | 74 | break; |
@@ -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) |
@@ -158,7 +173,7 @@ int debugfs_umount(void) | |||
158 | 173 | ||
159 | int debugfs_write(const char *entry, const char *value) | 174 | int debugfs_write(const char *entry, const char *value) |
160 | { | 175 | { |
161 | char path[MAX_PATH+1]; | 176 | char path[PATH_MAX + 1]; |
162 | int ret, count; | 177 | int ret, count; |
163 | int fd; | 178 | int fd; |
164 | 179 | ||
@@ -203,7 +218,7 @@ int debugfs_write(const char *entry, const char *value) | |||
203 | */ | 218 | */ |
204 | int debugfs_read(const char *entry, char *buffer, size_t size) | 219 | int debugfs_read(const char *entry, char *buffer, size_t size) |
205 | { | 220 | { |
206 | char path[MAX_PATH+1]; | 221 | char path[PATH_MAX + 1]; |
207 | int ret; | 222 | int ret; |
208 | int fd; | 223 | int fd; |
209 | 224 | ||