Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

perf tools: Make perf aware of tracefs

As tracefs may be mounted instead of debugfs to get to the event
directories, have perf know about tracefs, and use that file system over
debugfs if it is present.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Acked-by: Jiri Olsa <jolsa@kernel.org>
Cc: Andrew Morton <akpm@linux-foundation.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20150202193553.340946602@goodmis.org
[ Fixed up error messages about tracefs pointed out by Namhyung ]
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>

authored by

Steven Rostedt (Red Hat) and committed by
Arnaldo Carvalho de Melo
23773ca1 dd6dda27

+91 -25
+6 -1
tools/perf/tests/open-syscall-all-cpus.c
··· 29 29 30 30 evsel = perf_evsel__newtp("syscalls", "sys_enter_open"); 31 31 if (evsel == NULL) { 32 - pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); 32 + if (tracefs_configured()) 33 + pr_debug("is tracefs mounted on /sys/kernel/tracing?\n"); 34 + else if (debugfs_configured()) 35 + pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); 36 + else 37 + pr_debug("Neither tracefs or debugfs is enabled in this kernel\n"); 33 38 goto out_thread_map_delete; 34 39 } 35 40
+6 -1
tools/perf/tests/open-syscall.c
··· 18 18 19 19 evsel = perf_evsel__newtp("syscalls", "sys_enter_open"); 20 20 if (evsel == NULL) { 21 - pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); 21 + if (tracefs_configured()) 22 + pr_debug("is tracefs mounted on /sys/kernel/tracing?\n"); 23 + else if (debugfs_configured()) 24 + pr_debug("is debugfs mounted on /sys/kernel/debug?\n"); 25 + else 26 + pr_debug("Neither tracefs or debugfs is enabled in this kernel\n"); 22 27 goto out_thread_map_delete; 23 28 } 24 29
+11 -2
tools/perf/tests/parse-events.c
··· 3 3 #include "evsel.h" 4 4 #include "evlist.h" 5 5 #include <api/fs/fs.h> 6 + #include <api/fs/tracefs.h> 6 7 #include <api/fs/debugfs.h> 7 8 #include "tests.h" 8 9 #include "debug.h" ··· 1193 1192 { 1194 1193 char events_path[PATH_MAX]; 1195 1194 struct dirent *events_ent; 1195 + const char *mountpoint; 1196 1196 DIR *events_dir; 1197 1197 int cnt = 0; 1198 1198 1199 - scnprintf(events_path, PATH_MAX, "%s/tracing/events", 1200 - debugfs_find_mountpoint()); 1199 + mountpoint = tracefs_find_mountpoint(); 1200 + if (mountpoint) { 1201 + scnprintf(events_path, PATH_MAX, "%s/events", 1202 + mountpoint); 1203 + } else { 1204 + mountpoint = debugfs_find_mountpoint(); 1205 + scnprintf(events_path, PATH_MAX, "%s/tracing/events", 1206 + mountpoint); 1207 + } 1201 1208 1202 1209 events_dir = opendir(events_path); 1203 1210
+1
tools/perf/util/cache.h
··· 17 17 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" 18 18 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" 19 19 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" 20 + #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR" 20 21 21 22 typedef int (*config_fn_t)(const char *, const char *, void *); 22 23 extern int perf_default_config(const char *, const char *, void *);
-1
tools/perf/util/evlist.c
··· 7 7 * Released under the GPL v2. (and only v2, not any later version) 8 8 */ 9 9 #include "util.h" 10 - #include <api/fs/debugfs.h> 11 10 #include <api/fs/fs.h> 12 11 #include <poll.h> 13 12 #include "cpumap.h"
+1 -1
tools/perf/util/parse-events.h
··· 122 122 int print_hwcache_events(const char *event_glob, bool name_only); 123 123 extern int is_valid_tracepoint(const char *event_string); 124 124 125 - extern int valid_debugfs_mount(const char *debugfs); 125 + int valid_event_mount(const char *eventfs); 126 126 127 127 #endif /* __PERF_PARSE_EVENTS_H */
+16 -8
tools/perf/util/probe-event.c
··· 41 41 #include "symbol.h" 42 42 #include "thread.h" 43 43 #include <api/fs/debugfs.h> 44 + #include <api/fs/tracefs.h> 44 45 #include "trace-event.h" /* For __maybe_unused */ 45 46 #include "probe-event.h" 46 47 #include "probe-finder.h" ··· 1806 1805 " - please rebuild kernel with %s.\n", 1807 1806 is_kprobe ? 'k' : 'u', config); 1808 1807 } else if (err == -ENOTSUP) 1809 - pr_warning("Debugfs is not mounted.\n"); 1808 + pr_warning("Tracefs or debugfs is not mounted.\n"); 1810 1809 else 1811 1810 pr_warning("Failed to open %cprobe_events: %s\n", 1812 1811 is_kprobe ? 'k' : 'u', ··· 1817 1816 { 1818 1817 /* Both kprobes and uprobes are disabled, warn it. */ 1819 1818 if (kerr == -ENOTSUP && uerr == -ENOTSUP) 1820 - pr_warning("Debugfs is not mounted.\n"); 1819 + pr_warning("Tracefs or debugfs is not mounted.\n"); 1821 1820 else if (kerr == -ENOENT && uerr == -ENOENT) 1822 1821 pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS " 1823 1822 "or/and CONFIG_UPROBE_EVENTS.\n"); ··· 1834 1833 { 1835 1834 char buf[PATH_MAX]; 1836 1835 const char *__debugfs; 1836 + const char *tracing_dir = ""; 1837 1837 int ret; 1838 1838 1839 - __debugfs = debugfs_find_mountpoint(); 1840 - if (__debugfs == NULL) 1841 - return -ENOTSUP; 1839 + __debugfs = tracefs_find_mountpoint(); 1840 + if (__debugfs == NULL) { 1841 + tracing_dir = "tracing/"; 1842 1842 1843 - ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file); 1843 + __debugfs = debugfs_find_mountpoint(); 1844 + if (__debugfs == NULL) 1845 + return -ENOTSUP; 1846 + } 1847 + 1848 + ret = e_snprintf(buf, PATH_MAX, "%s/%s%s", 1849 + __debugfs, tracing_dir, trace_file); 1844 1850 if (ret >= 0) { 1845 1851 pr_debug("Opening %s write=%d\n", buf, readwrite); 1846 1852 if (readwrite && !probe_event_dry_run) ··· 1863 1855 1864 1856 static int open_kprobe_events(bool readwrite) 1865 1857 { 1866 - return open_probe_events("tracing/kprobe_events", readwrite); 1858 + return open_probe_events("kprobe_events", readwrite); 1867 1859 } 1868 1860 1869 1861 static int open_uprobe_events(bool readwrite) 1870 1862 { 1871 - return open_probe_events("tracing/uprobe_events", readwrite); 1863 + return open_probe_events("uprobe_events", readwrite); 1872 1864 } 1873 1865 1874 1866 /* Get raw string list of current kprobe_events or uprobe_events */
+49 -11
tools/perf/util/util.c
··· 303 303 tcsetattr(0, TCSANOW, &tc); 304 304 } 305 305 306 - static void set_tracing_events_path(const char *mountpoint) 306 + static void set_tracing_events_path(const char *tracing, const char *mountpoint) 307 307 { 308 - snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s", 309 - mountpoint, "tracing/events"); 308 + snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s", 309 + mountpoint, tracing, "events"); 310 310 } 311 311 312 - const char *perf_debugfs_mount(const char *mountpoint) 312 + static const char *__perf_tracefs_mount(const char *mountpoint) 313 + { 314 + const char *mnt; 315 + 316 + mnt = tracefs_mount(mountpoint); 317 + if (!mnt) 318 + return NULL; 319 + 320 + set_tracing_events_path("", mnt); 321 + 322 + return mnt; 323 + } 324 + 325 + static const char *__perf_debugfs_mount(const char *mountpoint) 313 326 { 314 327 const char *mnt; 315 328 ··· 330 317 if (!mnt) 331 318 return NULL; 332 319 333 - set_tracing_events_path(mnt); 320 + set_tracing_events_path("tracing/", mnt); 321 + 322 + return mnt; 323 + } 324 + 325 + const char *perf_debugfs_mount(const char *mountpoint) 326 + { 327 + const char *mnt; 328 + 329 + mnt = __perf_tracefs_mount(mountpoint); 330 + if (mnt) 331 + return mnt; 332 + 333 + mnt = __perf_debugfs_mount(mountpoint); 334 334 335 335 return mnt; 336 336 } ··· 351 325 void perf_debugfs_set_path(const char *mntpt) 352 326 { 353 327 snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt); 354 - set_tracing_events_path(mntpt); 328 + set_tracing_events_path("tracing/", mntpt); 329 + } 330 + 331 + static const char *find_tracefs(void) 332 + { 333 + const char *path = __perf_tracefs_mount(NULL); 334 + 335 + return path; 355 336 } 356 337 357 338 static const char *find_debugfs(void) 358 339 { 359 - const char *path = perf_debugfs_mount(NULL); 340 + const char *path = __perf_debugfs_mount(NULL); 360 341 361 342 if (!path) 362 343 fprintf(stderr, "Your kernel does not support the debugfs filesystem"); ··· 377 344 */ 378 345 const char *find_tracing_dir(void) 379 346 { 347 + const char *tracing_dir = ""; 380 348 static char *tracing; 381 349 static int tracing_found; 382 350 const char *debugfs; ··· 385 351 if (tracing_found) 386 352 return tracing; 387 353 388 - debugfs = find_debugfs(); 389 - if (!debugfs) 390 - return NULL; 354 + debugfs = find_tracefs(); 355 + if (!debugfs) { 356 + tracing_dir = "/tracing"; 357 + debugfs = find_debugfs(); 358 + if (!debugfs) 359 + return NULL; 360 + } 391 361 392 - if (asprintf(&tracing, "%s/tracing", debugfs) < 0) 362 + if (asprintf(&tracing, "%s%s", debugfs, tracing_dir) < 0) 393 363 return NULL; 394 364 395 365 tracing_found = 1;
+1
tools/perf/util/util.h
··· 75 75 #include <linux/types.h> 76 76 #include <sys/ttydefaults.h> 77 77 #include <api/fs/debugfs.h> 78 + #include <api/fs/tracefs.h> 78 79 #include <termios.h> 79 80 #include <linux/bitops.h> 80 81 #include <termios.h>