aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util/debugfs.c
diff options
context:
space:
mode:
authorArnaldo Carvalho de Melo <acme@redhat.com>2011-11-16 11:03:07 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2011-11-28 07:11:28 -0500
commitebf294bf4f147aff29df5a16bfb0f8ebca15feaa (patch)
tree37464624abf9243100eab47fdc663def4be121fe /tools/perf/util/debugfs.c
parentc168fbfb93a1c4044287858c6784f0bd1f6cfe33 (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/debugfs.c')
-rw-r--r--tools/perf/util/debugfs.c25
1 files changed, 20 insertions, 5 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
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)