aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf/util
diff options
context:
space:
mode:
authorBorislav Petkov <bp@suse.de>2013-02-20 10:32:30 -0500
committerArnaldo Carvalho de Melo <acme@redhat.com>2013-03-15 12:06:00 -0400
commit85c66be101e1847f0eb46dcb48d5738572129694 (patch)
tree96900665b0edb1466da7b82bd7ca619858f4ba4d /tools/perf/util
parent9687b89d21999301ed386855c04b60d00ed1ec02 (diff)
perf tools: Introduce tools/lib/lk library
This introduces the tools/lib/lk library, that will gradually have the routines that now are used in tools/perf/ and other tools and that can be shared. Start by carving out debugfs routines for general use. Signed-off-by: Borislav Petkov <bp@suse.de> Cc: Ingo Molnar <mingo@kernel.org> Cc: Steven Rostedt <rostedt@goodmis.org> Link: http://lkml.kernel.org/r/1361374353-30385-5-git-send-email-bp@alien8.de [ committer note: Add tools/lib/lk/ to perf's MANIFEST so that its tarballs continue to build ] Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
Diffstat (limited to 'tools/perf/util')
-rw-r--r--tools/perf/util/debugfs.c111
-rw-r--r--tools/perf/util/debugfs.h12
-rw-r--r--tools/perf/util/evlist.c2
-rw-r--r--tools/perf/util/evsel.c2
-rw-r--r--tools/perf/util/parse-events.c2
-rw-r--r--tools/perf/util/probe-event.c2
-rw-r--r--tools/perf/util/python-ext-sources1
-rw-r--r--tools/perf/util/setup.py3
-rw-r--r--tools/perf/util/trace-event-info.c2
9 files changed, 7 insertions, 130 deletions
diff --git a/tools/perf/util/debugfs.c b/tools/perf/util/debugfs.c
deleted file mode 100644
index e55495c7823a..000000000000
--- a/tools/perf/util/debugfs.c
+++ /dev/null
@@ -1,111 +0,0 @@
1#include "util.h"
2#include "debugfs.h"
3#include "cache.h"
4
5#include <linux/kernel.h>
6#include <sys/mount.h>
7
8char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug";
9char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events";
10
11static const char *debugfs_known_mountpoints[] = {
12 "/sys/kernel/debug/",
13 "/debug/",
14 0,
15};
16
17static bool debugfs_found;
18
19/* find the path to the mounted debugfs */
20const char *debugfs_find_mountpoint(void)
21{
22 const char **ptr;
23 char type[100];
24 FILE *fp;
25
26 if (debugfs_found)
27 return (const char *) debugfs_mountpoint;
28
29 ptr = debugfs_known_mountpoints;
30 while (*ptr) {
31 if (debugfs_valid_mountpoint(*ptr) == 0) {
32 debugfs_found = true;
33 strcpy(debugfs_mountpoint, *ptr);
34 return debugfs_mountpoint;
35 }
36 ptr++;
37 }
38
39 /* give up and parse /proc/mounts */
40 fp = fopen("/proc/mounts", "r");
41 if (fp == NULL)
42 return NULL;
43
44 while (fscanf(fp, "%*s %" STR(PATH_MAX) "s %99s %*s %*d %*d\n",
45 debugfs_mountpoint, type) == 2) {
46 if (strcmp(type, "debugfs") == 0)
47 break;
48 }
49 fclose(fp);
50
51 if (strcmp(type, "debugfs") != 0)
52 return NULL;
53
54 debugfs_found = true;
55
56 return debugfs_mountpoint;
57}
58
59/* verify that a mountpoint is actually a debugfs instance */
60
61int debugfs_valid_mountpoint(const char *debugfs)
62{
63 struct statfs st_fs;
64
65 if (statfs(debugfs, &st_fs) < 0)
66 return -ENOENT;
67 else if (st_fs.f_type != (long) DEBUGFS_MAGIC)
68 return -ENOENT;
69
70 return 0;
71}
72
73static void debugfs_set_tracing_events_path(const char *mountpoint)
74{
75 snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s",
76 mountpoint, "tracing/events");
77}
78
79/* mount the debugfs somewhere if it's not mounted */
80
81char *debugfs_mount(const char *mountpoint)
82{
83 /* see if it's already mounted */
84 if (debugfs_find_mountpoint())
85 goto out;
86
87 /* if not mounted and no argument */
88 if (mountpoint == NULL) {
89 /* see if environment variable set */
90 mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
91 /* if no environment variable, use default */
92 if (mountpoint == NULL)
93 mountpoint = "/sys/kernel/debug";
94 }
95
96 if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)
97 return NULL;
98
99 /* save the mountpoint */
100 debugfs_found = true;
101 strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint));
102out:
103 debugfs_set_tracing_events_path(debugfs_mountpoint);
104 return debugfs_mountpoint;
105}
106
107void debugfs_set_path(const char *mountpoint)
108{
109 snprintf(debugfs_mountpoint, sizeof(debugfs_mountpoint), "%s", mountpoint);
110 debugfs_set_tracing_events_path(mountpoint);
111}
diff --git a/tools/perf/util/debugfs.h b/tools/perf/util/debugfs.h
deleted file mode 100644
index 68f3e87ec57f..000000000000
--- a/tools/perf/util/debugfs.h
+++ /dev/null
@@ -1,12 +0,0 @@
1#ifndef __DEBUGFS_H__
2#define __DEBUGFS_H__
3
4const char *debugfs_find_mountpoint(void);
5int debugfs_valid_mountpoint(const char *debugfs);
6char *debugfs_mount(const char *mountpoint);
7void debugfs_set_path(const char *mountpoint);
8
9extern char debugfs_mountpoint[];
10extern char tracing_events_path[];
11
12#endif /* __DEBUGFS_H__ */
diff --git a/tools/perf/util/evlist.c b/tools/perf/util/evlist.c
index bc4ad7977438..7626bb49508d 100644
--- a/tools/perf/util/evlist.c
+++ b/tools/perf/util/evlist.c
@@ -7,7 +7,7 @@
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 "debugfs.h" 10#include <lk/debugfs.h>
11#include <poll.h> 11#include <poll.h>
12#include "cpumap.h" 12#include "cpumap.h"
13#include "thread_map.h" 13#include "thread_map.h"
diff --git a/tools/perf/util/evsel.c b/tools/perf/util/evsel.c
index 9c82f98f26de..dc16231f7a5d 100644
--- a/tools/perf/util/evsel.c
+++ b/tools/perf/util/evsel.c
@@ -10,7 +10,7 @@
10#include <byteswap.h> 10#include <byteswap.h>
11#include <linux/bitops.h> 11#include <linux/bitops.h>
12#include "asm/bug.h" 12#include "asm/bug.h"
13#include "debugfs.h" 13#include <lk/debugfs.h>
14#include "event-parse.h" 14#include "event-parse.h"
15#include "evsel.h" 15#include "evsel.h"
16#include "evlist.h" 16#include "evlist.h"
diff --git a/tools/perf/util/parse-events.c b/tools/perf/util/parse-events.c
index c84f48cf9678..6c8bb0fb189b 100644
--- a/tools/perf/util/parse-events.c
+++ b/tools/perf/util/parse-events.c
@@ -10,7 +10,7 @@
10#include "symbol.h" 10#include "symbol.h"
11#include "cache.h" 11#include "cache.h"
12#include "header.h" 12#include "header.h"
13#include "debugfs.h" 13#include <lk/debugfs.h>
14#include "parse-events-bison.h" 14#include "parse-events-bison.h"
15#define YY_EXTRA_TYPE int 15#define YY_EXTRA_TYPE int
16#include "parse-events-flex.h" 16#include "parse-events-flex.h"
diff --git a/tools/perf/util/probe-event.c b/tools/perf/util/probe-event.c
index 49a256e6e0a2..aa04bf9c9ad7 100644
--- a/tools/perf/util/probe-event.c
+++ b/tools/perf/util/probe-event.c
@@ -40,7 +40,7 @@
40#include "color.h" 40#include "color.h"
41#include "symbol.h" 41#include "symbol.h"
42#include "thread.h" 42#include "thread.h"
43#include "debugfs.h" 43#include <lk/debugfs.h>
44#include "trace-event.h" /* For __maybe_unused */ 44#include "trace-event.h" /* For __maybe_unused */
45#include "probe-event.h" 45#include "probe-event.h"
46#include "probe-finder.h" 46#include "probe-finder.h"
diff --git a/tools/perf/util/python-ext-sources b/tools/perf/util/python-ext-sources
index 64536a993f4a..f75ae1b9900c 100644
--- a/tools/perf/util/python-ext-sources
+++ b/tools/perf/util/python-ext-sources
@@ -15,7 +15,6 @@ util/thread_map.c
15util/util.c 15util/util.c
16util/xyarray.c 16util/xyarray.c
17util/cgroup.c 17util/cgroup.c
18util/debugfs.c
19util/rblist.c 18util/rblist.c
20util/strlist.c 19util/strlist.c
21util/sysfs.c 20util/sysfs.c
diff --git a/tools/perf/util/setup.py b/tools/perf/util/setup.py
index 73d510269784..6b0ed322907e 100644
--- a/tools/perf/util/setup.py
+++ b/tools/perf/util/setup.py
@@ -24,6 +24,7 @@ cflags += getenv('CFLAGS', '').split()
24build_lib = getenv('PYTHON_EXTBUILD_LIB') 24build_lib = getenv('PYTHON_EXTBUILD_LIB')
25build_tmp = getenv('PYTHON_EXTBUILD_TMP') 25build_tmp = getenv('PYTHON_EXTBUILD_TMP')
26libtraceevent = getenv('LIBTRACEEVENT') 26libtraceevent = getenv('LIBTRACEEVENT')
27liblk = getenv('LIBLK')
27 28
28ext_sources = [f.strip() for f in file('util/python-ext-sources') 29ext_sources = [f.strip() for f in file('util/python-ext-sources')
29 if len(f.strip()) > 0 and f[0] != '#'] 30 if len(f.strip()) > 0 and f[0] != '#']
@@ -32,7 +33,7 @@ perf = Extension('perf',
32 sources = ext_sources, 33 sources = ext_sources,
33 include_dirs = ['util/include'], 34 include_dirs = ['util/include'],
34 extra_compile_args = cflags, 35 extra_compile_args = cflags,
35 extra_objects = [libtraceevent], 36 extra_objects = [libtraceevent, liblk],
36 ) 37 )
37 38
38setup(name='perf', 39setup(name='perf',
diff --git a/tools/perf/util/trace-event-info.c b/tools/perf/util/trace-event-info.c
index a8d81c35ef66..36b9b49d0177 100644
--- a/tools/perf/util/trace-event-info.c
+++ b/tools/perf/util/trace-event-info.c
@@ -38,7 +38,7 @@
38 38
39#include "../perf.h" 39#include "../perf.h"
40#include "trace-event.h" 40#include "trace-event.h"
41#include "debugfs.h" 41#include <lk/debugfs.h>
42#include "evsel.h" 42#include "evsel.h"
43 43
44#define VERSION "0.5" 44#define VERSION "0.5"