linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jiri Olsa <jolsa@kernel.org>
To: Arnaldo Carvalho de Melo <acme@kernel.org>
Cc: lkml <linux-kernel@vger.kernel.org>,
	"David Ahern" <dsahern@gmail.com>,
	"Ingo Molnar" <mingo@kernel.org>,
	"Namhyung Kim" <namhyung@kernel.org>,
	"Peter Zijlstra" <a.p.zijlstra@chello.nl>,
	"Matt Fleming" <matt@codeblueprint.co.uk>,
	"Raphaël Beamonte" <raphael.beamonte@gmail.com>
Subject: [PATCH 06/11] perf tools: Move tracing_path interface into trace-event-path.c
Date: Wed, 26 Aug 2015 15:46:48 +0200	[thread overview]
Message-ID: <1440596813-12844-7-git-send-email-jolsa@kernel.org> (raw)
In-Reply-To: <1440596813-12844-1-git-send-email-jolsa@kernel.org>

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

Link: http://lkml.kernel.org/n/tip-xqvrud2e3z4uynvnu3imlu2y@git.kernel.org
Signed-off-by: Jiri Olsa <jolsa@kernel.org>
---
 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


  parent reply	other threads:[~2015-08-26 13:48 UTC|newest]

Thread overview: 35+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-08-26 13:46 [RFC 00/11] perf tools: Enhance parsing events tracepoint error output Jiri Olsa
2015-08-26 13:46 ` [PATCH 01/11] tools: Add err.h with ERR_PTR PTR_ERR interface Jiri Olsa
2015-08-28 16:21   ` Arnaldo Carvalho de Melo
2015-08-31  7:37     ` Jiri Olsa
2015-08-31 15:27       ` Arnaldo Carvalho de Melo
2015-08-26 13:46 ` [PATCH 02/11] perf tools: Add tracing_path and remove unneeded functions Jiri Olsa
2015-08-27 22:47   ` Matt Fleming
2015-08-28 16:27     ` Arnaldo Carvalho de Melo
2015-08-29 10:25       ` Jiri Olsa
2015-08-31  8:32   ` [tip:perf/core] " tip-bot for Jiri Olsa
2015-08-26 13:46 ` [PATCH 03/11] perf tools: Do not change lib/api/fs/debugfs directly Jiri Olsa
     [not found]   ` <CAE_Gge2cn8LpuETTTkf2nP8JLj=9RDiuW3M8BXzv7ZTJpY9x7w@mail.gmail.com>
2015-08-26 14:17     ` Jiri Olsa
2015-08-26 14:27     ` Arnaldo Carvalho de Melo
2015-08-28 12:26       ` Matt Fleming
2015-08-28 12:19   ` Matt Fleming
2015-08-31  8:33   ` [tip:perf/core] perf tools: Do not change lib/api/fs/ debugfs directly tip-bot for Jiri Olsa
2015-08-26 13:46 ` [PATCH 04/11] perf tools: Move debugfs__strerror_open into util.c object Jiri Olsa
2015-08-26 13:52   ` Arnaldo Carvalho de Melo
2015-08-26 14:16     ` Jiri Olsa
2015-08-28 12:59   ` Matt Fleming
2015-08-26 13:46 ` [PATCH 05/11] perf tools: Move tracing_path stuff under same namespace Jiri Olsa
2015-08-26 14:42   ` Arnaldo Carvalho de Melo
2015-08-26 14:48     ` Jiri Olsa
2015-08-26 14:58       ` Arnaldo Carvalho de Melo
2015-08-26 15:06         ` Jiri Olsa
2015-08-28 13:06           ` Matt Fleming
2015-08-31  7:43             ` Jiri Olsa
2015-08-26 13:46 ` Jiri Olsa [this message]
2015-08-26 13:46 ` [PATCH 07/11] perf tools: Make tracing_path_strerror_open message generic Jiri Olsa
2015-08-26 13:46 ` [PATCH 08/11] perf tools: Do not export debugfs_mountpoint and tracefs_mountpoint Jiri Olsa
2015-08-26 13:46 ` [PATCH 09/11] perf tools: Propagate error info for the tracepoint parsing Jiri Olsa
2015-08-28 13:20   ` Matt Fleming
2015-08-28 13:32     ` Jiri Olsa
2015-08-26 13:46 ` [PATCH 10/11] perf tools: Propagate error info from tp_format Jiri Olsa
2015-08-26 13:46 ` [PATCH 11/11] perf tools: Enhance parsing events tracepoint error output Jiri Olsa

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1440596813-12844-7-git-send-email-jolsa@kernel.org \
    --to=jolsa@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@kernel.org \
    --cc=dsahern@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=matt@codeblueprint.co.uk \
    --cc=mingo@kernel.org \
    --cc=namhyung@kernel.org \
    --cc=raphael.beamonte@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).