aboutsummaryrefslogtreecommitdiffstats
path: root/tools/perf
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
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')
-rw-r--r--tools/perf/MANIFEST1
-rw-r--r--tools/perf/Makefile34
-rw-r--r--tools/perf/builtin-kvm.c2
-rw-r--r--tools/perf/builtin-probe.c2
-rw-r--r--tools/perf/perf.c2
-rw-r--r--tools/perf/tests/parse-events.c2
-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
15 files changed, 39 insertions, 141 deletions
diff --git a/tools/perf/MANIFEST b/tools/perf/MANIFEST
index 39d41068484f..025de796067c 100644
--- a/tools/perf/MANIFEST
+++ b/tools/perf/MANIFEST
@@ -1,6 +1,7 @@
1tools/perf 1tools/perf
2tools/scripts 2tools/scripts
3tools/lib/traceevent 3tools/lib/traceevent
4tools/lib/lk
4include/linux/const.h 5include/linux/const.h
5include/linux/perf_event.h 6include/linux/perf_event.h
6include/linux/rbtree.h 7include/linux/rbtree.h
diff --git a/tools/perf/Makefile b/tools/perf/Makefile
index bb74c79cd16e..3dcd6273a90b 100644
--- a/tools/perf/Makefile
+++ b/tools/perf/Makefile
@@ -215,6 +215,7 @@ BASIC_CFLAGS = \
215 -Iutil \ 215 -Iutil \
216 -I. \ 216 -I. \
217 -I$(TRACE_EVENT_DIR) \ 217 -I$(TRACE_EVENT_DIR) \
218 -I../lib/ \
218 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE 219 -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64 -D_GNU_SOURCE
219 220
220BASIC_LDFLAGS = 221BASIC_LDFLAGS =
@@ -240,19 +241,28 @@ SCRIPT_SH += perf-archive.sh
240grep-libs = $(filter -l%,$(1)) 241grep-libs = $(filter -l%,$(1))
241strip-libs = $(filter-out -l%,$(1)) 242strip-libs = $(filter-out -l%,$(1))
242 243
244LK_DIR = ../lib/lk/
243TRACE_EVENT_DIR = ../lib/traceevent/ 245TRACE_EVENT_DIR = ../lib/traceevent/
244 246
247LK_PATH=$(LK_DIR)
248
245ifneq ($(OUTPUT),) 249ifneq ($(OUTPUT),)
246 TE_PATH=$(OUTPUT) 250 TE_PATH=$(OUTPUT)
251ifneq ($(subdir),)
252 LK_PATH=$(OUTPUT)$(LK_DIR)
253else
254 LK_PATH=$(OUTPUT)
255endif
247else 256else
248 TE_PATH=$(TRACE_EVENT_DIR) 257 TE_PATH=$(TRACE_EVENT_DIR)
249endif 258endif
250 259
251LIBTRACEEVENT = $(TE_PATH)libtraceevent.a 260LIBTRACEEVENT = $(TE_PATH)libtraceevent.a
252TE_LIB := -L$(TE_PATH) -ltraceevent
253
254export LIBTRACEEVENT 261export LIBTRACEEVENT
255 262
263LIBLK = $(LK_PATH)liblk.a
264export LIBLK
265
256# python extension build directories 266# python extension build directories
257PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/ 267PYTHON_EXTBUILD := $(OUTPUT)python_ext_build/
258PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/ 268PYTHON_EXTBUILD_LIB := $(PYTHON_EXTBUILD)lib/
@@ -355,7 +365,6 @@ LIB_H += util/cache.h
355LIB_H += util/callchain.h 365LIB_H += util/callchain.h
356LIB_H += util/build-id.h 366LIB_H += util/build-id.h
357LIB_H += util/debug.h 367LIB_H += util/debug.h
358LIB_H += util/debugfs.h
359LIB_H += util/sysfs.h 368LIB_H += util/sysfs.h
360LIB_H += util/pmu.h 369LIB_H += util/pmu.h
361LIB_H += util/event.h 370LIB_H += util/event.h
@@ -416,7 +425,6 @@ LIB_OBJS += $(OUTPUT)util/annotate.o
416LIB_OBJS += $(OUTPUT)util/build-id.o 425LIB_OBJS += $(OUTPUT)util/build-id.o
417LIB_OBJS += $(OUTPUT)util/config.o 426LIB_OBJS += $(OUTPUT)util/config.o
418LIB_OBJS += $(OUTPUT)util/ctype.o 427LIB_OBJS += $(OUTPUT)util/ctype.o
419LIB_OBJS += $(OUTPUT)util/debugfs.o
420LIB_OBJS += $(OUTPUT)util/sysfs.o 428LIB_OBJS += $(OUTPUT)util/sysfs.o
421LIB_OBJS += $(OUTPUT)util/pmu.o 429LIB_OBJS += $(OUTPUT)util/pmu.o
422LIB_OBJS += $(OUTPUT)util/environment.o 430LIB_OBJS += $(OUTPUT)util/environment.o
@@ -536,7 +544,7 @@ BUILTIN_OBJS += $(OUTPUT)builtin-kvm.o
536BUILTIN_OBJS += $(OUTPUT)builtin-inject.o 544BUILTIN_OBJS += $(OUTPUT)builtin-inject.o
537BUILTIN_OBJS += $(OUTPUT)tests/builtin-test.o 545BUILTIN_OBJS += $(OUTPUT)tests/builtin-test.o
538 546
539PERFLIBS = $(LIB_FILE) $(LIBTRACEEVENT) 547PERFLIBS = $(LIB_FILE) $(LIBLK) $(LIBTRACEEVENT)
540 548
541# 549#
542# Platform specific tweaks 550# Platform specific tweaks
@@ -1051,6 +1059,18 @@ $(LIBTRACEEVENT):
1051$(LIBTRACEEVENT)-clean: 1059$(LIBTRACEEVENT)-clean:
1052 $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) clean 1060 $(QUIET_SUBDIR0)$(TRACE_EVENT_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) clean
1053 1061
1062# if subdir is set, we've been called from above so target has been built
1063# already
1064$(LIBLK):
1065ifeq ($(subdir),)
1066 $(QUIET_SUBDIR0)$(LK_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) liblk.a
1067endif
1068
1069$(LIBLK)-clean:
1070ifeq ($(subdir),)
1071 $(QUIET_SUBDIR0)$(LK_DIR) $(QUIET_SUBDIR1) O=$(OUTPUT) clean
1072endif
1073
1054help: 1074help:
1055 @echo 'Perf make targets:' 1075 @echo 'Perf make targets:'
1056 @echo ' doc - make *all* documentation (see below)' 1076 @echo ' doc - make *all* documentation (see below)'
@@ -1171,7 +1191,7 @@ $(INSTALL_DOC_TARGETS):
1171 1191
1172### Cleaning rules 1192### Cleaning rules
1173 1193
1174clean: $(LIBTRACEEVENT)-clean 1194clean: $(LIBTRACEEVENT)-clean $(LIBLK)-clean
1175 $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS) 1195 $(RM) $(LIB_OBJS) $(BUILTIN_OBJS) $(LIB_FILE) $(OUTPUT)perf-archive $(OUTPUT)perf.o $(LANG_BINDINGS)
1176 $(RM) $(ALL_PROGRAMS) perf 1196 $(RM) $(ALL_PROGRAMS) perf
1177 $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope* 1197 $(RM) *.spec *.pyc *.pyo */*.pyc */*.pyo $(OUTPUT)common-cmds.h TAGS tags cscope*
@@ -1181,6 +1201,6 @@ clean: $(LIBTRACEEVENT)-clean
1181 $(RM) $(OUTPUT)util/*-flex* 1201 $(RM) $(OUTPUT)util/*-flex*
1182 $(python-clean) 1202 $(python-clean)
1183 1203
1184.PHONY: all install clean strip $(LIBTRACEEVENT) 1204.PHONY: all install clean strip $(LIBTRACEEVENT) $(LIBLK)
1185.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell 1205.PHONY: shell_compatibility_test please_set_SHELL_PATH_to_a_more_modern_shell
1186.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope .FORCE-PERF-CFLAGS 1206.PHONY: .FORCE-PERF-VERSION-FILE TAGS tags cscope .FORCE-PERF-CFLAGS
diff --git a/tools/perf/builtin-kvm.c b/tools/perf/builtin-kvm.c
index 37a769d7f9fe..533501e2b07c 100644
--- a/tools/perf/builtin-kvm.c
+++ b/tools/perf/builtin-kvm.c
@@ -12,7 +12,7 @@
12#include "util/parse-options.h" 12#include "util/parse-options.h"
13#include "util/trace-event.h" 13#include "util/trace-event.h"
14#include "util/debug.h" 14#include "util/debug.h"
15#include "util/debugfs.h" 15#include <lk/debugfs.h>
16#include "util/tool.h" 16#include "util/tool.h"
17#include "util/stat.h" 17#include "util/stat.h"
18 18
diff --git a/tools/perf/builtin-probe.c b/tools/perf/builtin-probe.c
index de38a034b129..e8a66f9a6715 100644
--- a/tools/perf/builtin-probe.c
+++ b/tools/perf/builtin-probe.c
@@ -37,7 +37,7 @@
37#include "util/strfilter.h" 37#include "util/strfilter.h"
38#include "util/symbol.h" 38#include "util/symbol.h"
39#include "util/debug.h" 39#include "util/debug.h"
40#include "util/debugfs.h" 40#include <lk/debugfs.h>
41#include "util/parse-options.h" 41#include "util/parse-options.h"
42#include "util/probe-finder.h" 42#include "util/probe-finder.h"
43#include "util/probe-event.h" 43#include "util/probe-event.h"
diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index 095b88207cd3..f53b735e2822 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -13,7 +13,7 @@
13#include "util/quote.h" 13#include "util/quote.h"
14#include "util/run-command.h" 14#include "util/run-command.h"
15#include "util/parse-events.h" 15#include "util/parse-events.h"
16#include "util/debugfs.h" 16#include <lk/debugfs.h>
17#include <pthread.h> 17#include <pthread.h>
18 18
19const char perf_usage_string[] = 19const char perf_usage_string[] =
diff --git a/tools/perf/tests/parse-events.c b/tools/perf/tests/parse-events.c
index c5636f36fe31..0d3d0c59f924 100644
--- a/tools/perf/tests/parse-events.c
+++ b/tools/perf/tests/parse-events.c
@@ -3,7 +3,7 @@
3#include "evsel.h" 3#include "evsel.h"
4#include "evlist.h" 4#include "evlist.h"
5#include "sysfs.h" 5#include "sysfs.h"
6#include "debugfs.h" 6#include <lk/debugfs.h>
7#include "tests.h" 7#include "tests.h"
8#include <linux/hw_breakpoint.h> 8#include <linux/hw_breakpoint.h>
9 9
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"