10 #include <sys/mount.h>
11 #include <linux/kernel.h>
15 #ifndef TRACEFS_DEFAULT_PATH
16 #define TRACEFS_DEFAULT_PATH "/sys/kernel/tracing"
19 char tracefs_mountpoint[PATH_MAX + 1] = TRACEFS_DEFAULT_PATH;
21 static const char * const tracefs_known_mountpoints[] = {
23 "/sys/kernel/debug/tracing",
29 static bool tracefs_found;
31 bool tracefs_configured(void)
33 return tracefs_find_mountpoint() != NULL;
36 /* find the path to the mounted tracefs */
37 const char *tracefs_find_mountpoint(void)
42 return (const char *)tracefs_mountpoint;
44 ret = find_mountpoint("tracefs", (long) TRACEFS_MAGIC,
45 tracefs_mountpoint, PATH_MAX + 1,
46 tracefs_known_mountpoints);
54 /* mount the tracefs somewhere if it's not mounted */
55 char *tracefs_mount(const char *mountpoint)
57 /* see if it's already mounted */
58 if (tracefs_find_mountpoint())
61 /* if not mounted and no argument */
62 if (mountpoint == NULL) {
63 /* see if environment variable set */
64 mountpoint = getenv(PERF_TRACEFS_ENVIRONMENT);
65 /* if no environment variable, use default */
66 if (mountpoint == NULL)
67 mountpoint = TRACEFS_DEFAULT_PATH;
70 if (mount(NULL, mountpoint, "tracefs", 0, NULL) < 0)
73 /* save the mountpoint */
75 strncpy(tracefs_mountpoint, mountpoint, sizeof(tracefs_mountpoint));
77 return tracefs_mountpoint;