aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorSteven Rostedt (Red Hat) <rostedt@goodmis.org>2015-02-02 14:35:07 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2015-02-11 10:37:08 -0500
commit23773ca18b399051eb94f98b689cf7a9173c795b (patch)
tree17629936892375049fd68b096389e8c24bc07a4a /tools/perf/util
parentdd6dda27a8be563eaebb3f38b1d1d50920bb7991 (diff)
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>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/cache.h1
-rw-r--r--tools/perf/util/evlist.c1
-rw-r--r--tools/perf/util/parse-events.h2
-rw-r--r--tools/perf/util/probe-event.c24
-rw-r--r--tools/perf/util/util.c60
-rw-r--r--tools/perf/util/util.h1
6 files changed, 68 insertions, 21 deletions
diff --git a/tools/perf/util/cache.h b/tools/perf/util/cache.h
index d04d770d90f6..fbcca21d66ab 100644
--- a/tools/perf/util/cache.h
+++ b/tools/perf/util/cache.h
@@ -17,6 +17,7 @@
17#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH" 17#define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
18#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf" 18#define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
19#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR" 19#define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
20#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
20 21
21typedef int (*config_fn_t)(const char *, const char *, void *); 22typedef int (*config_fn_t)(const char *, const char *, void *);
22extern int perf_default_config(const char *, const char *, void *); 23extern int perf_default_config(const char *, const char *, void *);
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index c602ebb5b991..a8b2c5726aba 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -7,7 +7,6 @@
7 * Released under the GPL v2. (and only v2, not any later version) 7 * Released under the GPL v2. (and only v2, not any later version)
8 */ 8 */
9#include "util.h" 9#include "util.h"
10#include <api/fs/debugfs.h>
11#include <api/fs/fs.h> 10#include <api/fs/fs.h>
12#include <poll.h> 11#include <poll.h>
13#include "cpumap.h" 12#include "cpumap.h"
diff --git a/tools/perf/util/parse-events.h b/tools/perf/util/parse-events.h
index ff6e1fa4111e..39c3b57965d1 100644
--- a/tools/perf/util/parse-events.h
+++ b/tools/perf/util/parse-events.h
@@ -122,6 +122,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
122int print_hwcache_events(const char *event_glob, bool name_only); 122int print_hwcache_events(const char *event_glob, bool name_only);
123extern int is_valid_tracepoint(const char *event_string); 123extern int is_valid_tracepoint(const char *event_string);
124 124
125extern int valid_debugfs_mount(const char *debugfs); 125int valid_event_mount(const char *eventfs);
126 126
127#endif /* __PERF_PARSE_EVENTS_H */ 127#endif /* __PERF_PARSE_EVENTS_H */
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 919937eb0be2..9dfbed96bf39 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -41,6 +41,7 @@
41#include "symbol.h" 41#include "symbol.h"
42#include "thread.h" 42#include "thread.h"
43#include <api/fs/debugfs.h> 43#include <api/fs/debugfs.h>
44#include <api/fs/tracefs.h>
44#include "trace-event.h" /* For __maybe_unused */ 45#include "trace-event.h" /* For __maybe_unused */
45#include "probe-event.h" 46#include "probe-event.h"
46#include "probe-finder.h" 47#include "probe-finder.h"
@@ -1805,7 +1806,7 @@ static void print_open_warning(int err, bool is_kprobe)
1805 " - please rebuild kernel with %s.\n", 1806 " - please rebuild kernel with %s.\n",
1806 is_kprobe ? 'k' : 'u', config); 1807 is_kprobe ? 'k' : 'u', config);
1807 } else if (err == -ENOTSUP) 1808 } else if (err == -ENOTSUP)
1808 pr_warning("Debugfs is not mounted.\n"); 1809 pr_warning("Tracefs or debugfs is not mounted.\n");
1809 else 1810 else
1810 pr_warning("Failed to open %cprobe_events: %s\n", 1811 pr_warning("Failed to open %cprobe_events: %s\n",
1811 is_kprobe ? 'k' : 'u', 1812 is_kprobe ? 'k' : 'u',
@@ -1816,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr)
1816{ 1817{
1817 /* Both kprobes and uprobes are disabled, warn it. */ 1818 /* Both kprobes and uprobes are disabled, warn it. */
1818 if (kerr == -ENOTSUP && uerr == -ENOTSUP) 1819 if (kerr == -ENOTSUP && uerr == -ENOTSUP)
1819 pr_warning("Debugfs is not mounted.\n"); 1820 pr_warning("Tracefs or debugfs is not mounted.\n");
1820 else if (kerr == -ENOENT && uerr == -ENOENT) 1821 else if (kerr == -ENOENT && uerr == -ENOENT)
1821 pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS " 1822 pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
1822 "or/and CONFIG_UPROBE_EVENTS.\n"); 1823 "or/and CONFIG_UPROBE_EVENTS.\n");
@@ -1833,13 +1834,20 @@ static int open_probe_events(const char *trace_file, bool readwrite)
1833{ 1834{
1834 char buf[PATH_MAX]; 1835 char buf[PATH_MAX];
1835 const char *__debugfs; 1836 const char *__debugfs;
1837 const char *tracing_dir = "";
1836 int ret; 1838 int ret;
1837 1839
1838 __debugfs = debugfs_find_mountpoint(); 1840 __debugfs = tracefs_find_mountpoint();
1839 if (__debugfs == NULL) 1841 if (__debugfs == NULL) {
1840 return -ENOTSUP; 1842 tracing_dir = "tracing/";
1841 1843
1842 ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file); 1844 __debugfs = debugfs_find_mountpoint();
1845 if (__debugfs == NULL)
1846 return -ENOTSUP;
1847 }
1848
1849 ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
1850 __debugfs, tracing_dir, trace_file);
1843 if (ret >= 0) { 1851 if (ret >= 0) {
1844 pr_debug("Opening %s write=%d\n", buf, readwrite); 1852 pr_debug("Opening %s write=%d\n", buf, readwrite);
1845 if (readwrite && !probe_event_dry_run) 1853 if (readwrite && !probe_event_dry_run)
@@ -1855,12 +1863,12 @@ static int open_probe_events(const char *trace_file, bool readwrite)
1855 1863
1856static int open_kprobe_events(bool readwrite) 1864static int open_kprobe_events(bool readwrite)
1857{ 1865{
1858 return open_probe_events("tracing/kprobe_events", readwrite); 1866 return open_probe_events("kprobe_events", readwrite);
1859} 1867}
1860 1868
1861static int open_uprobe_events(bool readwrite) 1869static int open_uprobe_events(bool readwrite)
1862{ 1870{
1863 return open_probe_events("tracing/uprobe_events", readwrite); 1871 return open_probe_events("uprobe_events", readwrite);
1864} 1872}
1865 1873
1866/* Get raw string list of current kprobe_events or uprobe_events */ 1874/* Get raw string list of current kprobe_events or uprobe_events */
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index b86744f29eef..92db3f156b63 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -303,13 +303,26 @@ void set_term_quiet_input(struct termios *old)
303 tcsetattr(0, TCSANOW, &tc); 303 tcsetattr(0, TCSANOW, &tc);
304} 304}
305 305
306static void set_tracing_events_path(const char *mountpoint) 306static void set_tracing_events_path(const char *tracing, const char *mountpoint)
307{ 307{
308 snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s", 308 snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
309 mountpoint, "tracing/events"); 309 mountpoint, tracing, "events");
310} 310}
311 311
312const char *perf_debugfs_mount(const char *mountpoint) 312static 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
325static const char *__perf_debugfs_mount(const char *mountpoint)
313{ 326{
314 const char *mnt; 327 const char *mnt;
315 328
@@ -317,7 +330,20 @@ const char *perf_debugfs_mount(const char *mountpoint)
317 if (!mnt) 330 if (!mnt)
318 return NULL; 331 return NULL;
319 332
320 set_tracing_events_path(mnt); 333 set_tracing_events_path("tracing/", mnt);
334
335 return mnt;
336}
337
338const char *perf_debugfs_mount(const char *mountpoint)
339{
340 const char *mnt;
341
342 mnt = __perf_tracefs_mount(mountpoint);
343 if (mnt)
344 return mnt;
345
346 mnt = __perf_debugfs_mount(mountpoint);
321 347
322 return mnt; 348 return mnt;
323} 349}
@@ -325,12 +351,19 @@ const char *perf_debugfs_mount(const char *mountpoint)
325void perf_debugfs_set_path(const char *mntpt) 351void perf_debugfs_set_path(const char *mntpt)
326{ 352{
327 snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt); 353 snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
328 set_tracing_events_path(mntpt); 354 set_tracing_events_path("tracing/", mntpt);
355}
356
357static const char *find_tracefs(void)
358{
359 const char *path = __perf_tracefs_mount(NULL);
360
361 return path;
329} 362}
330 363
331static const char *find_debugfs(void) 364static const char *find_debugfs(void)
332{ 365{
333 const char *path = perf_debugfs_mount(NULL); 366 const char *path = __perf_debugfs_mount(NULL);
334 367
335 if (!path) 368 if (!path)
336 fprintf(stderr, "Your kernel does not support the debugfs filesystem"); 369 fprintf(stderr, "Your kernel does not support the debugfs filesystem");
@@ -344,6 +377,7 @@ static const char *find_debugfs(void)
344 */ 377 */
345const char *find_tracing_dir(void) 378const char *find_tracing_dir(void)
346{ 379{
380 const char *tracing_dir = "";
347 static char *tracing; 381 static char *tracing;
348 static int tracing_found; 382 static int tracing_found;
349 const char *debugfs; 383 const char *debugfs;
@@ -351,11 +385,15 @@ const char *find_tracing_dir(void)
351 if (tracing_found) 385 if (tracing_found)
352 return tracing; 386 return tracing;
353 387
354 debugfs = find_debugfs(); 388 debugfs = find_tracefs();
355 if (!debugfs) 389 if (!debugfs) {
356 return NULL; 390 tracing_dir = "/tracing";
391 debugfs = find_debugfs();
392 if (!debugfs)
393 return NULL;
394 }
357 395
358 if (asprintf(&tracing, "%s/tracing", debugfs) < 0) 396 if (asprintf(&tracing, "%s%s", debugfs, tracing_dir) < 0)
359 return NULL; 397 return NULL;
360 398
361 tracing_found = 1; 399 tracing_found = 1;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 027a5153495c..73c2f8e557ab 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -75,6 +75,7 @@
75#include <linux/types.h> 75#include <linux/types.h>
76#include <sys/ttydefaults.h> 76#include <sys/ttydefaults.h>
77#include <api/fs/debugfs.h> 77#include <api/fs/debugfs.h>
78#include <api/fs/tracefs.h>
78#include <termios.h> 79#include <termios.h>
79#include <linux/bitops.h> 80#include <linux/bitops.h>
80#include <termios.h> 81#include <termios.h>