[PATCH 06/11] perf tools: Move tracing_path interface into trace-event-path.c

From: Jiri Olsa
Date: Wed Aug 26 2015 - 09:48:46 EST


Moving tracing_path interface into trace-event-path.c
out of util.c.

Link: http://lkml.kernel.org/n/tip-xqvrud2e3z4uynvnu3imlu2y@xxxxxxxxxxxxxx
Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
tools/perf/perf.c | 1 +
tools/perf/tests/openat-syscall-all-cpus.c | 2 +
tools/perf/tests/openat-syscall.c | 2 +
tools/perf/util/Build | 1 +
tools/perf/util/trace-event-path.c | 129 +++++++++++++++++++++++++++++
tools/perf/util/trace-event.h | 12 +++
tools/perf/util/util.c | 122 ---------------------------
tools/perf/util/util.h | 10 ---
8 files changed, 147 insertions(+), 132 deletions(-)
create mode 100644 tools/perf/util/trace-event-path.c

diff --git a/tools/perf/perf.c b/tools/perf/perf.c
index c5acdadde347..952a1becfd6c 100644
--- a/tools/perf/perf.c
+++ b/tools/perf/perf.c
@@ -15,6 +15,7 @@
#include "util/parse-events.h"
#include "util/parse-options.h"
#include "util/debug.h"
+#include "util/trace-event.h"
#include <api/fs/debugfs.h>
#include <pthread.h>

diff --git a/tools/perf/tests/openat-syscall-all-cpus.c b/tools/perf/tests/openat-syscall-all-cpus.c
index a572f87e9c8d..caac16359b78 100644
--- a/tools/perf/tests/openat-syscall-all-cpus.c
+++ b/tools/perf/tests/openat-syscall-all-cpus.c
@@ -1,3 +1,5 @@
+#include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
#include "evsel.h"
#include "tests.h"
#include "thread_map.h"
diff --git a/tools/perf/tests/openat-syscall.c b/tools/perf/tests/openat-syscall.c
index c9a37bc6b33a..087c2b7b6296 100644
--- a/tools/perf/tests/openat-syscall.c
+++ b/tools/perf/tests/openat-syscall.c
@@ -1,3 +1,5 @@
+#include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
#include "thread_map.h"
#include "evsel.h"
#include "debug.h"
diff --git a/tools/perf/util/Build b/tools/perf/util/Build
index e912856cc4e5..9ac357016c56 100644
--- a/tools/perf/util/Build
+++ b/tools/perf/util/Build
@@ -56,6 +56,7 @@ libperf-y += pmu-bison.o
libperf-y += trace-event-read.o
libperf-y += trace-event-info.o
libperf-y += trace-event-scripting.o
+libperf-y += trace-event-path.o
libperf-y += trace-event.o
libperf-y += svghelper.o
libperf-y += sort.o
diff --git a/tools/perf/util/trace-event-path.c b/tools/perf/util/trace-event-path.c
new file mode 100644
index 000000000000..e557187dcfce
--- /dev/null
+++ b/tools/perf/util/trace-event-path.c
@@ -0,0 +1,129 @@
+#include <stdio.h>
+#include <unistd.h>
+#include <errno.h>
+#include "trace-event.h"
+#include <api/fs/debugfs.h>
+#include <api/fs/tracefs.h>
+
+char tracing_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing";
+char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events";
+
+static void tracing_path_set(const char *tracing, const char *mountpoint)
+{
+ snprintf(tracing_path, sizeof(tracing_path), "%s/%s",
+ mountpoint, tracing);
+ snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
+ mountpoint, tracing, "events");
+}
+
+static const char *tracing_path_tracefs_mount(const char *mountpoint)
+{
+ const char *mnt;
+
+ mnt = tracefs_mount(mountpoint);
+ if (!mnt)
+ return NULL;
+
+ tracing_path_set("", mnt);
+
+ return mnt;
+}
+
+static const char *tracing_path_debugfs_mount(const char *mountpoint)
+{
+ const char *mnt;
+
+ mnt = debugfs_mount(mountpoint);
+ if (!mnt)
+ return NULL;
+
+ tracing_path_set("tracing/", mnt);
+
+ return mnt;
+}
+
+const char *perf_tracing_path_mount(const char *mountpoint)
+{
+ const char *mnt;
+
+ mnt = tracing_path_tracefs_mount(mountpoint);
+ if (mnt)
+ return mnt;
+
+ mnt = tracing_path_debugfs_mount(mountpoint);
+
+ return mnt;
+}
+
+void perf_tracing_path_set(const char *mntpt)
+{
+ tracing_path_set("tracing/", mntpt);
+}
+
+int tracing_path_strerror_open(int err, char *buf, size_t size, const char *filename)
+{
+ char sbuf[128];
+
+ switch (err) {
+ case ENOENT:
+ if (debugfs_configured()) {
+ snprintf(buf, size,
+ "Error:\tFile %s/%s not found.\n"
+ "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n",
+ debugfs_mountpoint, filename);
+ break;
+ }
+ snprintf(buf, size, "%s",
+ "Error:\tUnable to find debugfs\n"
+ "Hint:\tWas your kernel compiled with debugfs support?\n"
+ "Hint:\tIs the debugfs filesystem mounted?\n"
+ "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'");
+ break;
+ case EACCES: {
+ const char *mountpoint = debugfs_mountpoint;
+
+ if (!access(debugfs_mountpoint, R_OK) && strncmp(filename, "tracing/", 8) == 0) {
+ const char *tracefs_mntpoint = tracefs_find_mountpoint();
+
+ if (tracefs_mntpoint)
+ mountpoint = tracefs_mntpoint;
+ }
+
+ snprintf(buf, size,
+ "Error:\tNo permissions to read %s/%s\n"
+ "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
+ debugfs_mountpoint, filename, mountpoint);
+ }
+ break;
+ default:
+ snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf)));
+ break;
+ }
+
+ return 0;
+}
+
+int tracing_path_strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name)
+{
+ char path[PATH_MAX];
+
+ snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*");
+
+ return tracing_path_strerror_open(err, buf, size, path);
+}
+
+char *get_tracing_file(const char *name)
+{
+ char *file;
+
+ if (asprintf(&file, "%s/%s", tracing_path, name) < 0)
+ return NULL;
+
+ return file;
+}
+
+void put_tracing_file(char *file)
+{
+ free(file);
+}
+
diff --git a/tools/perf/util/trace-event.h b/tools/perf/util/trace-event.h
index da6cc4cc2a4f..59bd98a26b25 100644
--- a/tools/perf/util/trace-event.h
+++ b/tools/perf/util/trace-event.h
@@ -92,4 +92,16 @@ int common_pc(struct scripting_context *context);
int common_flags(struct scripting_context *context);
int common_lock_depth(struct scripting_context *context);

+/*
+ * The tracing_path interface from trace-event-path.c object.
+ */
+extern char tracing_path[];
+extern char tracing_events_path[];
+extern void perf_tracing_path_set(const char *mountpoint);
+const char *perf_tracing_path_mount(const char *mountpoint);
+int tracing_path_strerror_open(int err, char *buf, size_t size, const char *filename);
+int tracing_path_strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
+char *get_tracing_file(const char *name);
+void put_tracing_file(char *file);
+
#endif /* _PERF_UTIL_TRACE_EVENT_H */
diff --git a/tools/perf/util/util.c b/tools/perf/util/util.c
index 675d112a887d..49a5c6ad55f5 100644
--- a/tools/perf/util/util.c
+++ b/tools/perf/util/util.c
@@ -34,9 +34,6 @@ bool test_attr__enabled;
bool perf_host = true;
bool perf_guest = false;

-char tracing_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing";
-char tracing_events_path[PATH_MAX + 1] = "/sys/kernel/debug/tracing/events";
-
void event_attr_init(struct perf_event_attr *attr)
{
if (!perf_host)
@@ -390,125 +387,6 @@ void set_term_quiet_input(struct termios *old)
tcsetattr(0, TCSANOW, &tc);
}

-static void tracing_path_set(const char *tracing, const char *mountpoint)
-{
- snprintf(tracing_path, sizeof(tracing_path), "%s/%s",
- mountpoint, tracing);
- snprintf(tracing_events_path, sizeof(tracing_events_path), "%s/%s%s",
- mountpoint, tracing, "events");
-}
-
-static const char *tracing_path_tracefs_mount(const char *mountpoint)
-{
- const char *mnt;
-
- mnt = tracefs_mount(mountpoint);
- if (!mnt)
- return NULL;
-
- tracing_path_set("", mnt);
-
- return mnt;
-}
-
-static const char *tracing_path_debugfs_mount(const char *mountpoint)
-{
- const char *mnt;
-
- mnt = debugfs_mount(mountpoint);
- if (!mnt)
- return NULL;
-
- tracing_path_set("tracing/", mnt);
-
- return mnt;
-}
-
-const char *perf_tracing_path_mount(const char *mountpoint)
-{
- const char *mnt;
-
- mnt = tracing_path_tracefs_mount(mountpoint);
- if (mnt)
- return mnt;
-
- mnt = tracing_path_debugfs_mount(mountpoint);
-
- return mnt;
-}
-
-void perf_tracing_path_set(const char *mntpt)
-{
- tracing_path_set("tracing/", mntpt);
-}
-
-int tracing_path_strerror_open(int err, char *buf, size_t size, const char *filename)
-{
- char sbuf[128];
-
- switch (err) {
- case ENOENT:
- if (debugfs_configured()) {
- snprintf(buf, size,
- "Error:\tFile %s/%s not found.\n"
- "Hint:\tPerhaps this kernel misses some CONFIG_ setting to enable this feature?.\n",
- debugfs_mountpoint, filename);
- break;
- }
- snprintf(buf, size, "%s",
- "Error:\tUnable to find debugfs\n"
- "Hint:\tWas your kernel compiled with debugfs support?\n"
- "Hint:\tIs the debugfs filesystem mounted?\n"
- "Hint:\tTry 'sudo mount -t debugfs nodev /sys/kernel/debug'");
- break;
- case EACCES: {
- const char *mountpoint = debugfs_mountpoint;
-
- if (!access(debugfs_mountpoint, R_OK) && strncmp(filename, "tracing/", 8) == 0) {
- const char *tracefs_mntpoint = tracefs_find_mountpoint();
-
- if (tracefs_mntpoint)
- mountpoint = tracefs_mntpoint;
- }
-
- snprintf(buf, size,
- "Error:\tNo permissions to read %s/%s\n"
- "Hint:\tTry 'sudo mount -o remount,mode=755 %s'\n",
- debugfs_mountpoint, filename, mountpoint);
- }
- break;
- default:
- snprintf(buf, size, "%s", strerror_r(err, sbuf, sizeof(sbuf)));
- break;
- }
-
- return 0;
-}
-
-int tracing_path_strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name)
-{
- char path[PATH_MAX];
-
- snprintf(path, PATH_MAX, "tracing/events/%s/%s", sys, name ?: "*");
-
- return tracing_path_strerror_open(err, buf, size, path);
-}
-
-char *get_tracing_file(const char *name)
-{
- char *file;
-
- if (asprintf(&file, "%s/%s", tracing_path, name) < 0)
- return NULL;
-
- return file;
-}
-
-void put_tracing_file(char *file)
-{
- free(file);
-}
-
int parse_nsec_time(const char *str, u64 *ptime)
{
u64 time_sec, time_nsec;
diff --git a/tools/perf/util/util.h b/tools/perf/util/util.h
index 34a68faf53fe..4c812f31557c 100644
--- a/tools/perf/util/util.h
+++ b/tools/perf/util/util.h
@@ -74,8 +74,6 @@
#include <linux/magic.h>
#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>
@@ -83,14 +81,6 @@
extern const char *graph_line;
extern const char *graph_dotted_line;
extern char buildid_dir[];
-extern char tracing_path[];
-extern char tracing_events_path[];
-extern void perf_tracing_path_set(const char *mountpoint);
-const char *perf_tracing_path_mount(const char *mountpoint);
-int tracing_path_strerror_open(int err, char *buf, size_t size, const char *filename);
-int tracing_path_strerror_open_tp(int err, char *buf, size_t size, const char *sys, const char *name);
-char *get_tracing_file(const char *name);
-void put_tracing_file(char *file);

/* On most systems <limits.h> would have given us this, but
* not on some systems (e.g. GNU/Hurd).
--
2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/