Skip to contentSkip to conversation

perf: Have perf become tracefs aware

PATCH Superseded Steven Rostedt 5 participants 18 messages Feb 2, 2015 – Feb 18, 2015 perf events

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover perf: Have perf become tracefs aware

As I'm trying to move the tracing directory from debugfs, perf needs to be aware of this as system admins will now be able to mount the tracing directory without needing to mount debugfs. This patch series addresses this and makes perf aware of tracefs.

I based this series on a recent tip branch: perf/core.

You can also get this series from my repo as stated below.

Changes since v1:

o Added a patch to nuke the debugfs_valid_mountpoint.
Well, it doesn't totally nuke it. It still uses that function (static though) to test if the "default" debugfs locations may already contain a debugfs file system. I also have tracefs do the same.

o Fixed setting of debugfs_found and tracefs_found

o Moved STR macro and PATH_MAX macros from debugfs.h to findfs.h

o Changed debugfs_configured() and tracefs_configured() to use find_mountpoint() to see if they are configured.

o Fixed directory name (debugfs before "/tracing").

Internal SHA1: 42b3093519e049d12dfa02c230c10bfee14712b0

Steven Rostedt (Red Hat) (6):
perf: Do not check debugfs MAGIC for tracing files tools lib fs: Add helper to find mounted file systems tools lib api fs: Add tracefs mount helper functions tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro tools lib api fs: Add {tracefs,debugfs}_configured() functions
perf: Make perf aware of tracefs

----

 tools/lib/api/Makefile                   |  4 ++
 tools/lib/api/fs/debugfs.c               | 69 +++++++++-------------------
 tools/lib/api/fs/debugfs.h               | 13 +-----
 tools/lib/api/fs/findfs.c                | 63 ++++++++++++++++++++++++++
 tools/lib/api/fs/findfs.h                | 23 ++++++++++
 tools/lib/api/fs/tracefs.c               | 78 ++++++++++++++++++++++++++++++++
 tools/lib/api/fs/tracefs.h               | 21 +++++++++
 tools/perf/tests/open-syscall-all-cpus.c |  7 ++-
 tools/perf/tests/open-syscall.c          |  7 ++-
 tools/perf/tests/parse-events.c          | 13 +++++-
 tools/perf/util/cache.h                  |  1 +
 tools/perf/util/evlist.c                 |  1 -
 tools/perf/util/parse-events.c           | 19 --------
 tools/perf/util/parse-events.h           |  2 +-
 tools/perf/util/probe-event.c            | 24 ++++++----
 tools/perf/util/util.c                   | 60 +++++++++++++++++++-----
 tools/perf/util/util.h                   |  1 +
 17 files changed, 304 insertions(+), 102 deletions(-)
#1 lore raw

PATCH v2 1/6 perf: Do not check debugfs MAGIC for tracing files

From: "Steven Rostedt (Red Hat)" <[email protected]>

It's rather strange to be checking the debugfs MAGIC number for the tracing directory. A system admin may want to have a custom set of events to trace and it should be allowed to let the admin make a temp file (even for tracing virtual boxes, this is useful).

Also with the coming tracefs, the files may not even be under debugfs, so checking the debugfs MAGIC number is pointless.

---
 tools/lib/api/fs/debugfs.c     | 28 ++++++++++++++--------------
 tools/lib/api/fs/debugfs.h     |  1 -
 tools/perf/util/parse-events.c | 19 -------------------
 3 files changed, 14 insertions(+), 34 deletions(-)
tools/lib/api/fs/debugfs.c +14 -14
index d2b18e887071..d21d4d6b4fd2 100644
@@ -20,6 +20,20 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
+/* verify that a mountpoint is actually a debugfs instance */
+
+static int debugfs_valid_mountpoint(const char *debugfs)
+{
+	struct statfs st_fs;
+
+	if (statfs(debugfs, &st_fs) < 0)
+		return -ENOENT;
+	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
+		return -ENOENT;
+
+	return 0;
+}
+
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
@@ -60,20 +74,6 @@ const char *debugfs_find_mountpoint(void)
 	return debugfs_mountpoint;
 }
 
-/* verify that a mountpoint is actually a debugfs instance */
-
-int debugfs_valid_mountpoint(const char *debugfs)
-{
-	struct statfs st_fs;
-
-	if (statfs(debugfs, &st_fs) < 0)
-		return -ENOENT;
-	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
-		return -ENOENT;
-
-	return 0;
-}
-
 /* mount the debugfs somewhere if it's not mounted */
 char *debugfs_mount(const char *mountpoint)
 {
tools/lib/api/fs/debugfs.h +0 -1
index 0739881a9897..77bb36a95b07 100644
@@ -21,7 +21,6 @@
 #endif
 
 const char *debugfs_find_mountpoint(void);
-int debugfs_valid_mountpoint(const char *debugfs);
 char *debugfs_mount(const char *mountpoint);
 
 extern char debugfs_mountpoint[];
tools/perf/util/parse-events.c +0 -19
index 7f8ec6ce2823..ecf069b1661f 100644
@@ -175,9 +175,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
 
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return NULL;
-
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
 		return NULL;
@@ -473,12 +470,6 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
 int parse_events_add_tracepoint(struct list_head *list, int *idx,
 				char *sys, char *event)
 {
-	int ret;
-
-	ret = debugfs_valid_mountpoint(tracing_events_path);
-	if (ret)
-		return ret;
-
 	if (strpbrk(sys, "*?"))
 		return add_tracepoint_multi_sys(list, idx, sys, event);
 	else
@@ -1109,13 +1100,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
-	char sbuf[STRERR_BUFSIZE];
-
-	if (debugfs_valid_mountpoint(tracing_events_path)) {
-		printf("  [ Tracepoints not available: %s ]\n",
-			strerror_r(errno, sbuf, sizeof(sbuf)));
-		return;
-	}
 
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
@@ -1163,9 +1147,6 @@ int is_valid_tracepoint(const char *event_string)
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
 
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return 0;
-
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
 		return 0;
Signature · 1 line
2.1.4
#2 lore raw

[tip:perf/core] perf tools: Do not check debugfs MAGIC for tracing files

perf tools: Do not check debugfs MAGIC for tracing files
Commit-ID:  5693c92660970851e95f769ff27397f5098a6296
Gitweb:     http://git.kernel.org/tip/5693c92660970851e95f769ff27397f5098a6296
Author:     Steven Rostedt (Red Hat) <[email protected]>
AuthorDate: Mon, 2 Feb 2015 14:35:02 -0500
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sat, 7 Feb 2015 13:51:30 +0100

perf tools: Do not check debugfs MAGIC for tracing files

It's rather strange to be checking the debugfs MAGIC number for the tracing directory. A system admin may want to have a custom set of events to trace and it should be allowed to let the admin make a temp file (even for tracing virtual boxes, this is useful).

Also with the coming tracefs, the files may not even be under debugfs, so checking the debugfs MAGIC number is pointless.

---
 tools/lib/api/fs/debugfs.c     | 28 ++++++++++++++--------------
 tools/lib/api/fs/debugfs.h     |  1 -
 tools/perf/util/parse-events.c | 19 -------------------
 3 files changed, 14 insertions(+), 34 deletions(-)
tools/lib/api/fs/debugfs.c +14 -14
index d2b18e8..d21d4d6 100644
@@ -20,6 +20,20 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
+/* verify that a mountpoint is actually a debugfs instance */
+
+static int debugfs_valid_mountpoint(const char *debugfs)
+{
+	struct statfs st_fs;
+
+	if (statfs(debugfs, &st_fs) < 0)
+		return -ENOENT;
+	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
+		return -ENOENT;
+
+	return 0;
+}
+
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
@@ -60,20 +74,6 @@ const char *debugfs_find_mountpoint(void)
 	return debugfs_mountpoint;
 }
 
-/* verify that a mountpoint is actually a debugfs instance */
-
-int debugfs_valid_mountpoint(const char *debugfs)
-{
-	struct statfs st_fs;
-
-	if (statfs(debugfs, &st_fs) < 0)
-		return -ENOENT;
-	else if ((long)st_fs.f_type != (long)DEBUGFS_MAGIC)
-		return -ENOENT;
-
-	return 0;
-}
-
 /* mount the debugfs somewhere if it's not mounted */
 char *debugfs_mount(const char *mountpoint)
 {
tools/lib/api/fs/debugfs.h +0 -1
index 0739881..77bb36a 100644
@@ -21,7 +21,6 @@
 #endif
 
 const char *debugfs_find_mountpoint(void);
-int debugfs_valid_mountpoint(const char *debugfs);
 char *debugfs_mount(const char *mountpoint);
 
 extern char debugfs_mountpoint[];
tools/perf/util/parse-events.c +0 -19
index 7f8ec6c..ecf069b 100644
@@ -175,9 +175,6 @@ struct tracepoint_path *tracepoint_id_to_path(u64 config)
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
 
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return NULL;
-
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
 		return NULL;
@@ -473,12 +470,6 @@ static int add_tracepoint_multi_sys(struct list_head *list, int *idx,
 int parse_events_add_tracepoint(struct list_head *list, int *idx,
 				char *sys, char *event)
 {
-	int ret;
-
-	ret = debugfs_valid_mountpoint(tracing_events_path);
-	if (ret)
-		return ret;
-
 	if (strpbrk(sys, "*?"))
 		return add_tracepoint_multi_sys(list, idx, sys, event);
 	else
@@ -1109,13 +1100,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 	struct dirent *sys_next, *evt_next, sys_dirent, evt_dirent;
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
-	char sbuf[STRERR_BUFSIZE];
-
-	if (debugfs_valid_mountpoint(tracing_events_path)) {
-		printf("  [ Tracepoints not available: %s ]\n",
-			strerror_r(errno, sbuf, sizeof(sbuf)));
-		return;
-	}
 
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
@@ -1163,9 +1147,6 @@ int is_valid_tracepoint(const char *event_string)
 	char evt_path[MAXPATHLEN];
 	char dir_path[MAXPATHLEN];
 
-	if (debugfs_valid_mountpoint(tracing_events_path))
-		return 0;
-
 	sys_dir = opendir(tracing_events_path);
 	if (!sys_dir)
 		return 0;
#3 lore raw

PATCH v2 2/6 tools lib fs: Add helper to find mounted file systems

In reply to Steven Rostedt

From: "Steven Rostedt (Red Hat)" <[email protected]>

In preparation for adding tracefs for perf to use, create a findfs helper utility that find_debugfs uses instead of hard coding the search in the code. This will allow for a find_tracefs to be used as well.

---
 tools/lib/api/Makefile     |  2 ++
 tools/lib/api/fs/debugfs.c | 51 ++++++-------------------------------
 tools/lib/api/fs/debugfs.h | 11 +-------
 tools/lib/api/fs/findfs.c  | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/api/fs/findfs.h  | 21 ++++++++++++++++
 5 files changed, 94 insertions(+), 54 deletions(-)
 create mode 100644 tools/lib/api/fs/findfs.c
 create mode 100644 tools/lib/api/fs/findfs.h
tools/lib/api/Makefile +2 -0
index 36c08b1f4afb..22b2f15d7255 100644
@@ -9,11 +9,13 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += fs/debugfs.h
+LIB_H += fs/findfs.h
 LIB_H += fs/fs.h
 # See comment below about piggybacking...
 LIB_H += fd/array.h
 
 LIB_OBJS += $(OUTPUT)fs/debugfs.o
+LIB_OBJS += $(OUTPUT)fs/findfs.o
 LIB_OBJS += $(OUTPUT)fs/fs.o
 # XXX piggybacking here, need to introduce libapikfd, or rename this
 # to plain libapik.a and make it have it all api goodies
tools/lib/api/fs/debugfs.c +7 -44

65 lines not on this page · raw message

tools/lib/api/fs/debugfs.h +1 -10
index 77bb36a95b07..1074ac81358e 100644
@@ -1,16 +1,7 @@
 #ifndef __API_DEBUGFS_H__
 #define __API_DEBUGFS_H__
 
-#define _STR(x) #x
-#define STR(x) _STR(x)
-
-/*
- * On most systems <limits.h> would have given us this, but  not on some systems
- * (e.g. GNU/Hurd).
- */
-#ifndef PATH_MAX
-#define PATH_MAX 4096
-#endif
+#include "findfs.h"
 
 #ifndef DEBUGFS_MAGIC
 #define DEBUGFS_MAGIC          0x64626720
tools/lib/api/fs/findfs.c new file +63 -0

63 lines not on this page · raw message

tools/lib/api/fs/findfs.h new file +21 -0
new file mode 100644
index 000000000000..9e7d876791e1
@@ -0,0 +1,21 @@
+#ifndef __API_FINDFS_H__
+#define __API_FINDFS_H__
+
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+/*
+ * On most systems <limits.h> would have given us this, but  not on some systems
+ * (e.g. GNU/Hurd).
+ */
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
+const char *find_mountpoint(const char *fstype, long magic,
+			    char *mountpoint, int len,
+			    const char * const *known_mountpoints);
+
+int valid_mountpoint(const char *mount, long magic);
+
+#endif /* __API_FINDFS_H__ */
Signature · 1 line
2.1.4
#4 lore raw

[tip:perf/core] tools lib fs: Add helper to find mounted file systems

tools lib fs: Add helper to find mounted file systems
Commit-ID:  cde164aee9e0343831467035eb96dd5506742648
Gitweb:     http://git.kernel.org/tip/cde164aee9e0343831467035eb96dd5506742648
Author:     Steven Rostedt (Red Hat) <[email protected]>
AuthorDate: Mon, 2 Feb 2015 14:35:03 -0500
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sat, 7 Feb 2015 13:51:34 +0100

tools lib fs: Add helper to find mounted file systems

In preparation for adding tracefs for perf to use, create a findfs helper utility that find_debugfs uses instead of hard coding the search in the code. This will allow for a find_tracefs to be used as well.

---
 tools/lib/api/Makefile     |  2 ++
 tools/lib/api/fs/debugfs.c | 51 ++++++-------------------------------
 tools/lib/api/fs/debugfs.h | 11 +-------
 tools/lib/api/fs/findfs.c  | 63 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/api/fs/findfs.h  | 21 ++++++++++++++++
 5 files changed, 94 insertions(+), 54 deletions(-)
tools/lib/api/Makefile +2 -0
index 36c08b1..22b2f15 100644
@@ -9,11 +9,13 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += fs/debugfs.h
+LIB_H += fs/findfs.h
 LIB_H += fs/fs.h
 # See comment below about piggybacking...
 LIB_H += fd/array.h
 
 LIB_OBJS += $(OUTPUT)fs/debugfs.o
+LIB_OBJS += $(OUTPUT)fs/findfs.o
 LIB_OBJS += $(OUTPUT)fs/fs.o
 # XXX piggybacking here, need to introduce libapikfd, or rename this
 # to plain libapik.a and make it have it all api goodies
tools/lib/api/fs/debugfs.c +7 -44

65 lines not on this page · raw message

tools/lib/api/fs/debugfs.h +1 -10
index 77bb36a..1074ac8 100644
@@ -1,16 +1,7 @@
 #ifndef __API_DEBUGFS_H__
 #define __API_DEBUGFS_H__
 
-#define _STR(x) #x
-#define STR(x) _STR(x)
-
-/*
- * On most systems <limits.h> would have given us this, but  not on some systems
- * (e.g. GNU/Hurd).
- */
-#ifndef PATH_MAX
-#define PATH_MAX 4096
-#endif
+#include "findfs.h"
 
 #ifndef DEBUGFS_MAGIC
 #define DEBUGFS_MAGIC          0x64626720
tools/lib/api/fs/findfs.c new file +63 -0

63 lines not on this page · raw message

tools/lib/api/fs/findfs.h new file +21 -0
new file mode 100644
index 0000000..9e7d876
@@ -0,0 +1,21 @@
+#ifndef __API_FINDFS_H__
+#define __API_FINDFS_H__
+
+#define _STR(x) #x
+#define STR(x) _STR(x)
+
+/*
+ * On most systems <limits.h> would have given us this, but  not on some systems
+ * (e.g. GNU/Hurd).
+ */
+#ifndef PATH_MAX
+#define PATH_MAX 4096
+#endif
+
+const char *find_mountpoint(const char *fstype, long magic,
+			    char *mountpoint, int len,
+			    const char * const *known_mountpoints);
+
+int valid_mountpoint(const char *mount, long magic);
+
+#endif /* __API_FINDFS_H__ */
#5 lore raw

PATCH v2 3/6 tools lib api fs: Add tracefs mount helper functions

In reply to Steven Rostedt

From: "Steven Rostedt (Red Hat)" <[email protected]>

Since tracefs will now hold the event directory for perf, and even though by default, debugfs still mounts tracefs on the debugfs/tracing directory, the system admin may now choose to not mount debugfs and instead just mount tracefs instead.

Having tracefs helper functions will facilitate having perf look for tracefs first, and then try debugfs as a fallback.

---
 tools/lib/api/Makefile     |  2 ++
 tools/lib/api/fs/tracefs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/api/fs/tracefs.h | 20 +++++++++++++
 3 files changed, 92 insertions(+)
 create mode 100644 tools/lib/api/fs/tracefs.c
 create mode 100644 tools/lib/api/fs/tracefs.h
tools/lib/api/Makefile +2 -0
index 22b2f15d7255..212aa4fd65a0 100644
@@ -9,12 +9,14 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += fs/debugfs.h
+LIB_H += fs/tracefs.h
 LIB_H += fs/findfs.h
 LIB_H += fs/fs.h
 # See comment below about piggybacking...
 LIB_H += fd/array.h
 
 LIB_OBJS += $(OUTPUT)fs/debugfs.o
+LIB_OBJS += $(OUTPUT)fs/tracefs.o
 LIB_OBJS += $(OUTPUT)fs/findfs.o
 LIB_OBJS += $(OUTPUT)fs/fs.o
 # XXX piggybacking here, need to introduce libapikfd, or rename this
tools/lib/api/fs/tracefs.c new file +70 -0

70 lines not on this page · raw message

tools/lib/api/fs/tracefs.h new file +20 -0
new file mode 100644
index 000000000000..e6f7f5183c87
@@ -0,0 +1,20 @@
+#ifndef __API_TRACEFS_H__
+#define __API_TRACEFS_H__
+
+#include "findfs.h"
+
+#ifndef TRACEFS_MAGIC
+#define TRACEFS_MAGIC          0x74726163
+#endif
+
+#ifndef PERF_TRACEFS_ENVIRONMENT
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+#endif
+
+const char *tracefs_find_mountpoint(void);
+int tracefs_valid_mountpoint(const char *debugfs);
+char *tracefs_mount(const char *mountpoint);
+
+extern char tracefs_mountpoint[];
+
+#endif /* __API_DEBUGFS_H__ */
Signature · 1 line
2.1.4
#6 lore raw

[tip:perf/core] tools lib api fs: Add tracefs mount helper functions

tools lib api fs: Add tracefs mount helper functions
Commit-ID:  4ef92c2ecd96ebad171e554020c83ce9fdb343ae
Gitweb:     http://git.kernel.org/tip/4ef92c2ecd96ebad171e554020c83ce9fdb343ae
Author:     Steven Rostedt (Red Hat) <[email protected]>
AuthorDate: Mon, 2 Feb 2015 14:35:04 -0500
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sat, 7 Feb 2015 13:55:20 +0100

tools lib api fs: Add tracefs mount helper functions

Since tracefs will now hold the event directory for perf, and even though by default, debugfs still mounts tracefs on the debugfs/tracing directory, the system admin may now choose to not mount debugfs and instead just mount tracefs instead.

Having tracefs helper functions will facilitate having perf look for tracefs first, and then try debugfs as a fallback.

---
 tools/lib/api/Makefile     |  2 ++
 tools/lib/api/fs/tracefs.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++
 tools/lib/api/fs/tracefs.h | 20 +++++++++++++
 3 files changed, 92 insertions(+)
tools/lib/api/Makefile +2 -0
index 22b2f15..212aa4f 100644
@@ -9,12 +9,14 @@ LIB_H=
 LIB_OBJS=
 
 LIB_H += fs/debugfs.h
+LIB_H += fs/tracefs.h
 LIB_H += fs/findfs.h
 LIB_H += fs/fs.h
 # See comment below about piggybacking...
 LIB_H += fd/array.h
 
 LIB_OBJS += $(OUTPUT)fs/debugfs.o
+LIB_OBJS += $(OUTPUT)fs/tracefs.o
 LIB_OBJS += $(OUTPUT)fs/findfs.o
 LIB_OBJS += $(OUTPUT)fs/fs.o
 # XXX piggybacking here, need to introduce libapikfd, or rename this
tools/lib/api/fs/tracefs.c new file +70 -0

70 lines not on this page · raw message

tools/lib/api/fs/tracefs.h new file +20 -0
new file mode 100644
index 0000000..e6f7f51
@@ -0,0 +1,20 @@
+#ifndef __API_TRACEFS_H__
+#define __API_TRACEFS_H__
+
+#include "findfs.h"
+
+#ifndef TRACEFS_MAGIC
+#define TRACEFS_MAGIC          0x74726163
+#endif
+
+#ifndef PERF_TRACEFS_ENVIRONMENT
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
+#endif
+
+const char *tracefs_find_mountpoint(void);
+int tracefs_valid_mountpoint(const char *debugfs);
+char *tracefs_mount(const char *mountpoint);
+
+extern char tracefs_mountpoint[];
+
+#endif /* __API_DEBUGFS_H__ */
#7 lore raw

PATCH v2 4/6 tools lib api fs: Add DEBUGFS_DEFAULT_PATH macro

In reply to Steven Rostedt

From: "Steven Rostedt (Red Hat)" <[email protected]>

Instead of hard coding "/sys/kernel/debug" everywhere, create a macro to hold where the default path exists.

---
 tools/lib/api/fs/debugfs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/lib/api/fs/debugfs.c +7 -3
index 91e1668348ce..07d74b03d828 100644
@@ -10,10 +10,14 @@
 
 #include "debugfs.h"
 
-char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug";
+#ifndef DEBUGFS_DEFAULT_PATH
+#define DEBUGFS_DEFAULT_PATH		"/sys/kernel/debug"
+#endif
+
+char debugfs_mountpoint[PATH_MAX + 1] = DEBUGFS_DEFAULT_PATH;
 
 static const char * const debugfs_known_mountpoints[] = {
-	"/sys/kernel/debug",
+	DEBUGFS_DEFAULT_PATH,
 	"/debug",
 	0,
 };
@@ -50,7 +54,7 @@ char *debugfs_mount(const char *mountpoint)
 		mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
 		/* if no environment variable, use default */
 		if (mountpoint == NULL)
-			mountpoint = "/sys/kernel/debug";
+			mountpoint = DEBUGFS_DEFAULT_PATH;
 	}
 
 	if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)
Signature · 1 line
2.1.4
#8 lore raw

[tip:perf/core] tools lib api debugfs: Add DEBUGFS_DEFAULT_PATH macro

tools lib api debugfs: Add DEBUGFS_DEFAULT_PATH macro
Commit-ID:  a9edf60749a9483341facfa7c28bcf8afb3c8311
Gitweb:     http://git.kernel.org/tip/a9edf60749a9483341facfa7c28bcf8afb3c8311
Author:     Steven Rostedt (Red Hat) <[email protected]>
AuthorDate: Mon, 2 Feb 2015 14:35:05 -0500
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sat, 7 Feb 2015 13:56:32 +0100

tools lib api debugfs: Add DEBUGFS_DEFAULT_PATH macro

Instead of hard coding "/sys/kernel/debug" everywhere, create a macro to hold where the default path exists.

---
 tools/lib/api/fs/debugfs.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
tools/lib/api/fs/debugfs.c +7 -3
index 91e1668..07d74b0 100644
@@ -10,10 +10,14 @@
 
 #include "debugfs.h"
 
-char debugfs_mountpoint[PATH_MAX + 1] = "/sys/kernel/debug";
+#ifndef DEBUGFS_DEFAULT_PATH
+#define DEBUGFS_DEFAULT_PATH		"/sys/kernel/debug"
+#endif
+
+char debugfs_mountpoint[PATH_MAX + 1] = DEBUGFS_DEFAULT_PATH;
 
 static const char * const debugfs_known_mountpoints[] = {
-	"/sys/kernel/debug",
+	DEBUGFS_DEFAULT_PATH,
 	"/debug",
 	0,
 };
@@ -50,7 +54,7 @@ char *debugfs_mount(const char *mountpoint)
 		mountpoint = getenv(PERF_DEBUGFS_ENVIRONMENT);
 		/* if no environment variable, use default */
 		if (mountpoint == NULL)
-			mountpoint = "/sys/kernel/debug";
+			mountpoint = DEBUGFS_DEFAULT_PATH;
 	}
 
 	if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0)
#9 lore raw

PATCH v2 5/6 tools lib api fs: Add {tracefs,debugfs}_configured() functions

In reply to Steven Rostedt

From: "Steven Rostedt (Red Hat)" <[email protected]>

Add tracefs_configured() to return true if tracefs is configured in the kernel (succeeds to find tracefs), and debugfs_configured() if debugfs is configured in the kernel (succeeds to find debugfs).

---
 tools/lib/api/fs/debugfs.c | 8 ++++++++
 tools/lib/api/fs/debugfs.h | 1 +
 tools/lib/api/fs/findfs.h  | 2 ++
 tools/lib/api/fs/tracefs.c | 8 ++++++++
 tools/lib/api/fs/tracefs.h | 1 +
 5 files changed, 20 insertions(+)
tools/lib/api/fs/debugfs.c +8 -0
index 07d74b03d828..8305b3e9d48e 100644
@@ -3,8 +3,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mount.h>
 #include <linux/kernel.h>
 
@@ -24,6 +27,11 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
+bool debugfs_configured(void)
+{
+	return debugfs_find_mountpoint() != NULL;
+}
+
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
tools/lib/api/fs/debugfs.h +1 -0
index 1074ac81358e..455023698d2b 100644
@@ -11,6 +11,7 @@
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #endif
 
+bool debugfs_configured(void);
 const char *debugfs_find_mountpoint(void);
 char *debugfs_mount(const char *mountpoint);
 
tools/lib/api/fs/findfs.h +2 -0
index 9e7d876791e1..b6f5d05acc42 100644
@@ -1,6 +1,8 @@
 #ifndef __API_FINDFS_H__
 #define __API_FINDFS_H__
 
+#include <stdbool.h>
+
 #define _STR(x) #x
 #define STR(x) _STR(x)
 
tools/lib/api/fs/tracefs.c +8 -0
index ef40d15821e9..e4aa9688b71e 100644
@@ -2,8 +2,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mount.h>
 #include <linux/kernel.h>
 
@@ -25,6 +28,11 @@ static const char * const tracefs_known_mountpoints[] = {
 
 static bool tracefs_found;
 
+bool tracefs_configured(void)
+{
+	return tracefs_find_mountpoint() != NULL;
+}
+
 /* find the path to the mounted tracefs */
 const char *tracefs_find_mountpoint(void)
 {
tools/lib/api/fs/tracefs.h +1 -0
index e6f7f5183c87..da780ac49acb 100644
@@ -11,6 +11,7 @@
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 #endif
 
+bool tracefs_configured(void);
 const char *tracefs_find_mountpoint(void);
 int tracefs_valid_mountpoint(const char *debugfs);
 char *tracefs_mount(const char *mountpoint);
Signature · 1 line
2.1.4
#10 lore raw

[tip:perf/core] tools lib api fs: Add {tracefs, debugfs}_configured() functions

tools lib api fs: Add {tracefs,debugfs}_configured() functions
Commit-ID:  dd6dda27a8be563eaebb3f38b1d1d50920bb7991
Gitweb:     http://git.kernel.org/tip/dd6dda27a8be563eaebb3f38b1d1d50920bb7991
Author:     Steven Rostedt (Red Hat) <[email protected]>
AuthorDate: Mon, 2 Feb 2015 14:35:06 -0500
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Sat, 7 Feb 2015 14:00:10 +0100

tools lib api fs: Add {tracefs,debugfs}_configured() functions

Add tracefs_configured() to return true if tracefs is configured in the kernel (succeeds to find tracefs), and debugfs_configured() if debugfs is configured in the kernel (succeeds to find debugfs).

---
 tools/lib/api/fs/debugfs.c | 8 ++++++++
 tools/lib/api/fs/debugfs.h | 1 +
 tools/lib/api/fs/findfs.h  | 2 ++
 tools/lib/api/fs/tracefs.c | 8 ++++++++
 tools/lib/api/fs/tracefs.h | 1 +
 5 files changed, 20 insertions(+)
tools/lib/api/fs/debugfs.c +8 -0
index 07d74b0..8305b3e 100644
@@ -3,8 +3,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mount.h>
 #include <linux/kernel.h>
 
@@ -24,6 +27,11 @@ static const char * const debugfs_known_mountpoints[] = {
 
 static bool debugfs_found;
 
+bool debugfs_configured(void)
+{
+	return debugfs_find_mountpoint() != NULL;
+}
+
 /* find the path to the mounted debugfs */
 const char *debugfs_find_mountpoint(void)
 {
tools/lib/api/fs/debugfs.h +1 -0
index 1074ac8..4550236 100644
@@ -11,6 +11,7 @@
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
 #endif
 
+bool debugfs_configured(void);
 const char *debugfs_find_mountpoint(void);
 char *debugfs_mount(const char *mountpoint);
 
tools/lib/api/fs/findfs.h +2 -0
index 9e7d876..b6f5d05 100644
@@ -1,6 +1,8 @@
 #ifndef __API_FINDFS_H__
 #define __API_FINDFS_H__
 
+#include <stdbool.h>
+
 #define _STR(x) #x
 #define STR(x) _STR(x)
 
tools/lib/api/fs/tracefs.c +8 -0
index ef40d15..e4aa968 100644
@@ -2,8 +2,11 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <unistd.h>
 #include <stdbool.h>
 #include <sys/vfs.h>
+#include <sys/types.h>
+#include <sys/stat.h>
 #include <sys/mount.h>
 #include <linux/kernel.h>
 
@@ -25,6 +28,11 @@ static const char * const tracefs_known_mountpoints[] = {
 
 static bool tracefs_found;
 
+bool tracefs_configured(void)
+{
+	return tracefs_find_mountpoint() != NULL;
+}
+
 /* find the path to the mounted tracefs */
 const char *tracefs_find_mountpoint(void)
 {
tools/lib/api/fs/tracefs.h +1 -0
index e6f7f51..da780ac 100644
@@ -11,6 +11,7 @@
 #define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 #endif
 
+bool tracefs_configured(void);
 const char *tracefs_find_mountpoint(void);
 int tracefs_valid_mountpoint(const char *debugfs);
 char *tracefs_mount(const char *mountpoint);
#11 lore raw

PATCH v2 6/6 perf: Make perf aware of tracefs

In reply to Steven Rostedt

From: "Steven Rostedt (Red Hat)" <[email protected]>

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.

---
 tools/perf/tests/open-syscall-all-cpus.c |  7 +++-
 tools/perf/tests/open-syscall.c          |  7 +++-
 tools/perf/tests/parse-events.c          | 13 +++++--
 tools/perf/util/cache.h                  |  1 +
 tools/perf/util/evlist.c                 |  1 -
 tools/perf/util/parse-events.h           |  2 +-
 tools/perf/util/probe-event.c            | 24 ++++++++-----
 tools/perf/util/util.c                   | 60 ++++++++++++++++++++++++++------
 tools/perf/util/util.h                   |  1 +
 9 files changed, 91 insertions(+), 25 deletions(-)
tools/perf/tests/open-syscall-all-cpus.c +6 -1
index 8fa82d1700c7..21969e99ea46 100644
@@ -29,7 +29,12 @@ int test__open_syscall_event_on_all_cpus(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
tools/perf/tests/open-syscall.c +6 -1
index a33b2daae40f..4250e40234d2 100644
@@ -18,7 +18,12 @@ int test__open_syscall_event(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
tools/perf/tests/parse-events.c +11 -2
index 1cdab0ce00e2..ac243ebcb20a 100644
@@ -3,6 +3,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include <api/fs/fs.h>
+#include <api/fs/tracefs.h>
 #include <api/fs/debugfs.h>
 #include "tests.h"
 #include "debug.h"
@@ -1192,11 +1193,19 @@ static int count_tracepoints(void)
 {
 	char events_path[PATH_MAX];
 	struct dirent *events_ent;
+	const char *mountpoint;
 	DIR *events_dir;
 	int cnt = 0;
 
-	scnprintf(events_path, PATH_MAX, "%s/tracing/events",
-		  debugfs_find_mountpoint());
+	mountpoint = tracefs_find_mountpoint();
+	if (mountpoint) {
+		scnprintf(events_path, PATH_MAX, "%s/events",
+			  mountpoint);
+	} else {
+		mountpoint = debugfs_find_mountpoint();
+		scnprintf(events_path, PATH_MAX, "%s/tracing/events",
+			  mountpoint);
+	}
 
 	events_dir = opendir(events_path);
 
tools/perf/util/cache.h +1 -0
index d04d770d90f6..fbcca21d66ab 100644
@@ -17,6 +17,7 @@
 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
tools/perf/util/evlist.c +0 -1
index 28b8ce86bf12..42f1a2dfead3 100644
@@ -7,7 +7,6 @@
  * Released under the GPL v2. (and only v2, not any later version)
  */
 #include "util.h"
-#include <api/fs/debugfs.h>
 #include <api/fs/fs.h>
 #include <poll.h>
 #include "cpumap.h"
tools/perf/util/parse-events.h +1 -1
index ff6e1fa4111e..39c3b57965d1 100644
@@ -122,6 +122,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 int print_hwcache_events(const char *event_glob, bool name_only);
 extern int is_valid_tracepoint(const char *event_string);
 
-extern int valid_debugfs_mount(const char *debugfs);
+int valid_event_mount(const char *eventfs);
 
 #endif /* __PERF_PARSE_EVENTS_H */
tools/perf/util/probe-event.c +16 -8
index 919937eb0be2..9dfbed96bf39 100644
@@ -41,6 +41,7 @@
 #include "symbol.h"
 #include "thread.h"
 #include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
 #include "trace-event.h"	/* For __maybe_unused */
 #include "probe-event.h"
 #include "probe-finder.h"
@@ -1805,7 +1806,7 @@ static void print_open_warning(int err, bool is_kprobe)
 			   " - please rebuild kernel with %s.\n",
 			   is_kprobe ? 'k' : 'u', config);
 	} else if (err == -ENOTSUP)
-		pr_warning("Debugfs is not mounted.\n");
+		pr_warning("Tracefs or debugfs is not mounted.\n");
 	else
 		pr_warning("Failed to open %cprobe_events: %s\n",
 			   is_kprobe ? 'k' : 'u',
@@ -1816,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr)
 {
 	/* Both kprobes and uprobes are disabled, warn it. */
 	if (kerr == -ENOTSUP && uerr == -ENOTSUP)
-		pr_warning("Debugfs is not mounted.\n");
+		pr_warning("Tracefs or debugfs is not mounted.\n");
 	else if (kerr == -ENOENT && uerr == -ENOENT)
 		pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
 			   "or/and CONFIG_UPROBE_EVENTS.\n");
@@ -1833,13 +1834,20 @@ static int open_probe_events(const char *trace_file, bool readwrite)
 {
 	char buf[PATH_MAX];
 	const char *__debugfs;
+	const char *tracing_dir = "";
 	int ret;
 
-	__debugfs = debugfs_find_mountpoint();
-	if (__debugfs == NULL)
-		return -ENOTSUP;
+	__debugfs = tracefs_find_mountpoint();
+	if (__debugfs == NULL) {
+		tracing_dir = "tracing/";
 
-	ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file);
+		__debugfs = debugfs_find_mountpoint();
+		if (__debugfs == NULL)
+			return -ENOTSUP;
+	}
+
+	ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
+			 __debugfs, tracing_dir, trace_file);
 	if (ret >= 0) {
 		pr_debug("Opening %s write=%d\n", buf, readwrite);
 		if (readwrite && !probe_event_dry_run)
@@ -1855,12 +1863,12 @@ static int open_probe_events(const char *trace_file, bool readwrite)
 
 static int open_kprobe_events(bool readwrite)
 {
-	return open_probe_events("tracing/kprobe_events", readwrite);
+	return open_probe_events("kprobe_events", readwrite);
 }
 
 static int open_uprobe_events(bool readwrite)
 {
-	return open_probe_events("tracing/uprobe_events", readwrite);
+	return open_probe_events("uprobe_events", readwrite);
 }
 
 /* Get raw string list of current kprobe_events  or uprobe_events */
tools/perf/util/util.c +49 -11

98 lines not on this page · raw message

tools/perf/util/util.h +1 -0
index 027a5153495c..73c2f8e557ab 100644
@@ -75,6 +75,7 @@
 #include <linux/types.h>
 #include <sys/ttydefaults.h>
 #include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
 #include <termios.h>
 #include <linux/bitops.h>
 #include <termios.h>
Signature · 1 line
2.1.4
Acked-by on v2 6/6
#12 lore raw

Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs

On Mon, Feb 02, 2015 at 02:35:07PM -0500, Steven Rostedt wrote:

SNIP

Quoted 4 lines

}

tools/perf/util/util.c +0 -0
@@ -325,12 +351,19 @@ const char *perf_debugfs_mount(const char *mountpoint)
 void perf_debugfs_set_path(const char *mntpt)
 {

tools/perf/util/util.c const char *perf_debugfs_mount(const char *mountpoint) · line 361

Quoted 10 lines
tools/perf/util/util.c +8 -1
 	snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
-	set_tracing_events_path(mntpt);
+	set_tracing_events_path("tracing/", mntpt);
+}
+
+static const char *find_tracefs(void)
+{
+	const char *path = __perf_tracefs_mount(NULL);
+
+	return path;

I guess you ommited the fprint(stderr... ) warning on purpose (like in find_debugfs), because the tracefs is not upstream yet, right?

maybe we want at least pr_debug warning here.. anyway, other than that the patchset looks ok to me:

thanks,
jirka

Quoted 11 lines
tools/perf/util/util.c +1 -1
 }
 
 static const char *find_debugfs(void)
 {
-	const char *path = perf_debugfs_mount(NULL);
+	const char *path = __perf_debugfs_mount(NULL);
 
 	if (!path)
 		fprintf(stderr, "Your kernel does not support the debugfs filesystem");
@@ -344,6 +377,7 @@ static const char *find_debugfs(void)
  */

SNIP

#13 lore raw

Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs

Quoted 13 lines · On Tue, 3 Feb 2015 15:16:25 +0100 Jiri Olsa <[email protected]> wrote:

On Mon, Feb 02, 2015 at 02:35:07PM -0500, Steven Rostedt wrote:

SNIP

Quoted 9 lines

}

tools/perf/util/util.c +3 -1
@@ -325,12 +351,19 @@ const char *perf_debugfs_mount(const char *mountpoint)
 void perf_debugfs_set_path(const char *mntpt)
 {
 	snprintf(debugfs_mountpoint, strlen(debugfs_mountpoint), "%s", mntpt);
-	set_tracing_events_path(mntpt);
+	set_tracing_events_path("tracing/", mntpt);
+}
+
Quoted 8 lines

tools/perf/util/util.c const char *perf_debugfs_mount(const char *mountpoint) · line 361

Quoted 5 lines
tools/perf/util/util.c +5 -0
+static const char *find_tracefs(void)
+{
+	const char *path = __perf_tracefs_mount(NULL);
+
+	return path;

I guess you ommited the fprint(stderr... ) warning on purpose (like in find_debugfs), because the tracefs is not upstream yet, right?

Right, because I didn't want people complaining about using a new perf with an old kernel, and suddenly get warnings.

Quoted 3 lines

maybe we want at least pr_debug warning here.. anyway, other than that the patchset looks ok to me:

I was thinking that we could add one later, when tracefs is more common.

Quoted 2 lines

Thanks!

Arnaldo, do you want to pick this up?

-- Steve

#14 lore raw

Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs

Em Tue, Feb 03, 2015 at 11:45:50AM -0500, Steven Rostedt escreveu:

Quoted 8 lines
Quoted 2 lines · On Tue, 3 Feb 2015 15:16:25 +0100 Jiri Olsa <[email protected]> wrote:

I guess you ommited the fprint(stderr... ) warning on purpose (like in find_debugfs), because the tracefs is not upstream yet, right?

Right, because I didn't want people complaining about using a new perf with an old kernel, and suddenly get warnings.

Quoted 8 lines
Quoted 2 lines

maybe we want at least pr_debug warning here.. anyway, other than that the patchset looks ok to me:

I was thinking that we could add one later, when tracefs is more common.

Quoted 1 line

Arnaldo, do you want to pick this up?

I will, but traveling now, as soon as I can I'll look at it and put it in my perf/core branch.

- Arnaldo

maintainer
#15 lore raw

Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs

In reply to Steven Rostedt

Hi Steve,

Quoted 24 lines · Steven Rostedt

From: "Steven Rostedt (Red Hat)" <[email protected]>

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.

---
 tools/perf/tests/open-syscall-all-cpus.c |  7 +++-
 tools/perf/tests/open-syscall.c          |  7 +++-
 tools/perf/tests/parse-events.c          | 13 +++++--
 tools/perf/util/cache.h                  |  1 +
 tools/perf/util/evlist.c                 |  1 -
 tools/perf/util/parse-events.h           |  2 +-
 tools/perf/util/probe-event.c            | 24 ++++++++-----
 tools/perf/util/util.c                   | 60 ++++++++++++++++++++++++++------
 tools/perf/util/util.h                   |  1 +
 9 files changed, 91 insertions(+), 25 deletions(-)
tools/perf/tests/open-syscall-all-cpus.c +0 -0
index 8fa82d1700c7..21969e99ea46 100644

tools/perf/tests/open-syscall-all-cpus.c int test__open_syscall_event_on_all_cpus(void) · line 33

Quoted 6 lines
tools/perf/tests/open-syscall-all-cpus.c +2 -1
@@ -29,7 +29,12 @@ int test__open_syscall_event_on_all_cpus(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");

Shouldn't it be /sys/kernel/tracing/ ?

Quoted 12 lines
tools/perf/tests/open-syscall-all-cpus.c +4 -0
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
tools/perf/tests/open-syscall.c +0 -0
index a33b2daae40f..4250e40234d2 100644

tools/perf/tests/open-syscall.c int test__open_syscall_event(void) · line 22

Quoted 6 lines
tools/perf/tests/open-syscall.c +2 -1
@@ -18,7 +18,12 @@ int test__open_syscall_event(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");

Ditto.

Thanks,
Namhyung

Quoted 6 lines
tools/perf/tests/open-syscall.c +4 -0
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
#16 lore raw

Re: [PATCH 6/6 v2] perf: Make perf aware of tracefs

Quoted 8 lines · On Sun, 8 Feb 2015 23:12:46 +0900 Namhyung Kim <[email protected]> wrote:

Shouldn't it be /sys/kernel/tracing/ ?

tools/perf/tests/open-syscall-all-cpus.c int test__open_syscall_event_on_all_cpus(void) · line 33

Quoted 4 lines
tools/perf/tests/open-syscall-all-cpus.c +2 -1
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/debug?\n");

Ditto.

Fixing, thanks!

-- Steve

#17 lore raw

[tip:perf/core] perf tools: Make perf aware of tracefs

In reply to Steven Rostedt
perf tools: Make perf aware of tracefs
Commit-ID:  23773ca18b399051eb94f98b689cf7a9173c795b
Gitweb:     http://git.kernel.org/tip/23773ca18b399051eb94f98b689cf7a9173c795b
Author:     Steven Rostedt (Red Hat) <[email protected]>
AuthorDate: Mon, 2 Feb 2015 14:35:07 -0500
Committer:  Arnaldo Carvalho de Melo <[email protected]>
CommitDate: Wed, 11 Feb 2015 12:37:08 -0300

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.

Cc Andrew Morton <[email protected]>
Cc Ingo Molnar <[email protected]>
Cc Masami Hiramatsu <[email protected]>
Cc Namhyung Kim <[email protected]>
[ Fixed up error messages about tracefs pointed out by Namhyung ]
---
 tools/perf/tests/open-syscall-all-cpus.c |  7 +++-
 tools/perf/tests/open-syscall.c          |  7 +++-
 tools/perf/tests/parse-events.c          | 13 +++++--
 tools/perf/util/cache.h                  |  1 +
 tools/perf/util/evlist.c                 |  1 -
 tools/perf/util/parse-events.h           |  2 +-
 tools/perf/util/probe-event.c            | 24 ++++++++-----
 tools/perf/util/util.c                   | 60 ++++++++++++++++++++++++++------
 tools/perf/util/util.h                   |  1 +
 9 files changed, 91 insertions(+), 25 deletions(-)
tools/perf/tests/open-syscall-all-cpus.c +6 -1
index 8fa82d1..3ec885c 100644
@@ -29,7 +29,12 @@ int test__open_syscall_event_on_all_cpus(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/tracing?\n");
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
tools/perf/tests/open-syscall.c +6 -1
index a33b2da..07aa319 100644
@@ -18,7 +18,12 @@ int test__open_syscall_event(void)
 
 	evsel = perf_evsel__newtp("syscalls", "sys_enter_open");
 	if (evsel == NULL) {
-		pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		if (tracefs_configured())
+			pr_debug("is tracefs mounted on /sys/kernel/tracing?\n");
+		else if (debugfs_configured())
+			pr_debug("is debugfs mounted on /sys/kernel/debug?\n");
+		else
+			pr_debug("Neither tracefs or debugfs is enabled in this kernel\n");
 		goto out_thread_map_delete;
 	}
 
tools/perf/tests/parse-events.c +11 -2
index 1cdab0c..ac243eb 100644
@@ -3,6 +3,7 @@
 #include "evsel.h"
 #include "evlist.h"
 #include <api/fs/fs.h>
+#include <api/fs/tracefs.h>
 #include <api/fs/debugfs.h>
 #include "tests.h"
 #include "debug.h"
@@ -1192,11 +1193,19 @@ static int count_tracepoints(void)
 {
 	char events_path[PATH_MAX];
 	struct dirent *events_ent;
+	const char *mountpoint;
 	DIR *events_dir;
 	int cnt = 0;
 
-	scnprintf(events_path, PATH_MAX, "%s/tracing/events",
-		  debugfs_find_mountpoint());
+	mountpoint = tracefs_find_mountpoint();
+	if (mountpoint) {
+		scnprintf(events_path, PATH_MAX, "%s/events",
+			  mountpoint);
+	} else {
+		mountpoint = debugfs_find_mountpoint();
+		scnprintf(events_path, PATH_MAX, "%s/tracing/events",
+			  mountpoint);
+	}
 
 	events_dir = opendir(events_path);
 
tools/perf/util/cache.h +1 -0
index d04d770..fbcca21 100644
@@ -17,6 +17,7 @@
 #define EXEC_PATH_ENVIRONMENT "PERF_EXEC_PATH"
 #define DEFAULT_PERF_DIR_ENVIRONMENT ".perf"
 #define PERF_DEBUGFS_ENVIRONMENT "PERF_DEBUGFS_DIR"
+#define PERF_TRACEFS_ENVIRONMENT "PERF_TRACEFS_DIR"
 
 typedef int (*config_fn_t)(const char *, const char *, void *);
 extern int perf_default_config(const char *, const char *, void *);
tools/perf/util/evlist.c +0 -1
index c602ebb..a8b2c57 100644
@@ -7,7 +7,6 @@
  * Released under the GPL v2. (and only v2, not any later version)
  */
 #include "util.h"
-#include <api/fs/debugfs.h>
 #include <api/fs/fs.h>
 #include <poll.h>
 #include "cpumap.h"
tools/perf/util/parse-events.h +1 -1
index ff6e1fa..39c3b57 100644
@@ -122,6 +122,6 @@ void print_tracepoint_events(const char *subsys_glob, const char *event_glob,
 int print_hwcache_events(const char *event_glob, bool name_only);
 extern int is_valid_tracepoint(const char *event_string);
 
-extern int valid_debugfs_mount(const char *debugfs);
+int valid_event_mount(const char *eventfs);
 
 #endif /* __PERF_PARSE_EVENTS_H */
tools/perf/util/probe-event.c +16 -8
index 919937e..9dfbed9 100644
@@ -41,6 +41,7 @@
 #include "symbol.h"
 #include "thread.h"
 #include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
 #include "trace-event.h"	/* For __maybe_unused */
 #include "probe-event.h"
 #include "probe-finder.h"
@@ -1805,7 +1806,7 @@ static void print_open_warning(int err, bool is_kprobe)
 			   " - please rebuild kernel with %s.\n",
 			   is_kprobe ? 'k' : 'u', config);
 	} else if (err == -ENOTSUP)
-		pr_warning("Debugfs is not mounted.\n");
+		pr_warning("Tracefs or debugfs is not mounted.\n");
 	else
 		pr_warning("Failed to open %cprobe_events: %s\n",
 			   is_kprobe ? 'k' : 'u',
@@ -1816,7 +1817,7 @@ static void print_both_open_warning(int kerr, int uerr)
 {
 	/* Both kprobes and uprobes are disabled, warn it. */
 	if (kerr == -ENOTSUP && uerr == -ENOTSUP)
-		pr_warning("Debugfs is not mounted.\n");
+		pr_warning("Tracefs or debugfs is not mounted.\n");
 	else if (kerr == -ENOENT && uerr == -ENOENT)
 		pr_warning("Please rebuild kernel with CONFIG_KPROBE_EVENTS "
 			   "or/and CONFIG_UPROBE_EVENTS.\n");
@@ -1833,13 +1834,20 @@ static int open_probe_events(const char *trace_file, bool readwrite)
 {
 	char buf[PATH_MAX];
 	const char *__debugfs;
+	const char *tracing_dir = "";
 	int ret;
 
-	__debugfs = debugfs_find_mountpoint();
-	if (__debugfs == NULL)
-		return -ENOTSUP;
+	__debugfs = tracefs_find_mountpoint();
+	if (__debugfs == NULL) {
+		tracing_dir = "tracing/";
 
-	ret = e_snprintf(buf, PATH_MAX, "%s/%s", __debugfs, trace_file);
+		__debugfs = debugfs_find_mountpoint();
+		if (__debugfs == NULL)
+			return -ENOTSUP;
+	}
+
+	ret = e_snprintf(buf, PATH_MAX, "%s/%s%s",
+			 __debugfs, tracing_dir, trace_file);
 	if (ret >= 0) {
 		pr_debug("Opening %s write=%d\n", buf, readwrite);
 		if (readwrite && !probe_event_dry_run)
@@ -1855,12 +1863,12 @@ static int open_probe_events(const char *trace_file, bool readwrite)
 
 static int open_kprobe_events(bool readwrite)
 {
-	return open_probe_events("tracing/kprobe_events", readwrite);
+	return open_probe_events("kprobe_events", readwrite);
 }
 
 static int open_uprobe_events(bool readwrite)
 {
-	return open_probe_events("tracing/uprobe_events", readwrite);
+	return open_probe_events("uprobe_events", readwrite);
 }
 
 /* Get raw string list of current kprobe_events  or uprobe_events */
tools/perf/util/util.c +49 -11

98 lines not on this page · raw message

tools/perf/util/util.h +1 -0
index 027a515..73c2f8e 100644
@@ -75,6 +75,7 @@
 #include <linux/types.h>
 #include <sys/ttydefaults.h>
 #include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
 #include <termios.h>
 #include <linux/bitops.h>
 #include <termios.h>