lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <1381899621-14638-19-git-send-email-namhyung@kernel.org>
Date:	Wed, 16 Oct 2013 14:00:21 +0900
From:	Namhyung Kim <namhyung@...nel.org>
To:	Arnaldo Carvalho de Melo <acme@...stprotocols.net>
Cc:	Peter Zijlstra <a.p.zijlstra@...llo.nl>,
	Paul Mackerras <paulus@...ba.org>,
	Ingo Molnar <mingo@...nel.org>,
	Namhyung Kim <namhyung.kim@....com>,
	LKML <linux-kernel@...r.kernel.org>,
	Steven Rostedt <rostedt@...dmis.org>,
	Frederic Weisbecker <fweisbec@...il.com>,
	Jiri Olsa <jolsa@...hat.com>,
	Stephane Eranian <eranian@...gle.com>,
	Jeremy Eder <jeder@...hat.com>
Subject: [PATCH 18/18] perf ftrace: Add --filter option

From: Namhyung Kim <namhyung.kim@....com>

The --filter (-l) option is for filtering specific functions.  If this
option is given, only these (and their children) functions will be
shown in the output.

Cc: Steven Rostedt <rostedt@...dmis.org>
Cc: Frederic Weisbecker <fweisbec@...il.com>
Signed-off-by: Namhyung Kim <namhyung@...nel.org>
---
 tools/perf/Documentation/perf-ftrace.txt |  5 +++
 tools/perf/builtin-ftrace.c              | 55 ++++++++++++++++++++++++++++++++
 2 files changed, 60 insertions(+)

diff --git a/tools/perf/Documentation/perf-ftrace.txt b/tools/perf/Documentation/perf-ftrace.txt
index 841699f3924d..b0ae286d3e28 100644
--- a/tools/perf/Documentation/perf-ftrace.txt
+++ b/tools/perf/Documentation/perf-ftrace.txt
@@ -50,6 +50,11 @@ OPTIONS
 	tracer in system and outputs trace result directly from the
 	ftrace's trace_pipe.
 
+-l::
+--filter=::
+	Filter given functions to suppress others in the output.
+	Used by 'live' and 'record' subcommands only.
+
 -p::
 --pid=::
 	Record events on existing process ID (comma separated list).
diff --git a/tools/perf/builtin-ftrace.c b/tools/perf/builtin-ftrace.c
index 6720d560d6f8..17f37c273b1b 100644
--- a/tools/perf/builtin-ftrace.c
+++ b/tools/perf/builtin-ftrace.c
@@ -22,6 +22,7 @@
 #include "util/thread_map.h"
 #include "util/cpumap.h"
 #include "util/sort.h"
+#include "util/strlist.h"
 #include "util/trace-event.h"
 #include "../lib/traceevent/kbuffer.h"
 #include "../lib/traceevent/event-parse.h"
@@ -36,6 +37,7 @@ struct perf_ftrace {
 	const char *tracer;
 	const char *dirname;
 	const char *clock;
+	struct strlist *filter;
 	struct pevent *pevent;
 	bool show_full_info;
 };
@@ -118,6 +120,12 @@ static int reset_tracing_files(struct perf_ftrace *ftrace __maybe_unused)
 	if (write_tracing_file("trace_clock", "local") < 0)
 		return -1;
 
+	if (write_tracing_file("set_ftrace_filter", " ") < 0)
+		return -1;
+
+	if (write_tracing_file("set_graph_function", " ") < 0)
+		return -1;
+
 	return 0;
 }
 
@@ -210,6 +218,28 @@ static int set_tracing_clock(struct perf_ftrace *ftrace)
 	return write_tracing_file("trace_clock", "local");
 }
 
+static int set_tracing_filter(struct perf_ftrace *ftrace)
+{
+	const char *filter_file;
+	struct str_node *func;
+
+	if (ftrace->filter == NULL)
+		return 0;
+
+	if (!strcmp(ftrace->tracer, "function_graph"))
+		filter_file = "set_graph_function";
+	else if (!strcmp(ftrace->tracer, "function"))
+		filter_file = "set_ftrace_filter";
+	else
+		return 0;
+
+	strlist__for_each(func, ftrace->filter) {
+		if (append_tracing_file(filter_file, func->s) < 0)
+			return -1;
+	}
+	return 0;
+}
+
 static int setup_tracing_files(struct perf_ftrace *ftrace)
 {
 	int ret = -1;
@@ -240,6 +270,11 @@ static int setup_tracing_files(struct perf_ftrace *ftrace)
 		goto out;
 	}
 
+	if (set_tracing_filter(ftrace) < 0) {
+		pr_err("failed to set ftrace filter\n");
+		goto out;
+	}
+
 	if (write_tracing_file("current_tracer", ftrace->tracer) < 0) {
 		pr_err("failed to set current_tracer to %s\n", ftrace->tracer);
 		goto out;
@@ -1596,6 +1631,22 @@ static void ftrace_teardown(struct perf_ftrace *ftrace)
 {
 	perf_evlist__delete_maps(ftrace->evlist);
 	perf_evlist__delete(ftrace->evlist);
+	strlist__delete(ftrace->filter);
+}
+
+static int function_filters(const struct option *opt, const char *str,
+			    int unset __maybe_unused)
+{
+	struct perf_ftrace *ftrace = opt->value;
+
+	if (ftrace->filter == NULL) {
+		ftrace->filter = strlist__new(true, NULL);
+		if (ftrace->filter == NULL)
+			return -ENOMEM;
+	}
+
+	strlist__parse_list(ftrace->filter, str);
+	return 0;
 }
 
 static int
@@ -1610,6 +1661,8 @@ __cmd_ftrace_live(struct perf_ftrace *ftrace, int argc, const char **argv)
 	const struct option live_options[] = {
 	OPT_STRING('t', "tracer", &ftrace->tracer, "tracer",
 		   "tracer to use: function_graph or function"),
+	OPT_CALLBACK('l', "filter", ftrace, "function[,function,...]",
+		     "show only these functions in the trace", function_filters),
 	OPT_STRING('p', "pid", &ftrace->target.pid, "pid",
 		   "trace on existing process id"),
 	OPT_INCR('v', "verbose", &verbose,
@@ -1652,6 +1705,8 @@ __cmd_ftrace_record(struct perf_ftrace *ftrace, int argc, const char **argv)
 	const struct option record_options[] = {
 	OPT_STRING('t', "tracer", &ftrace->tracer, "tracer",
 		   "tracer to use: function_graph or function"),
+	OPT_CALLBACK('l', "filter", ftrace, "function[,function,...]",
+		     "show only these functions in the trace", function_filters),
 	OPT_STRING('p', "pid", &ftrace->target.pid, "pid",
 		   "trace on existing process id"),
 	OPT_INCR('v', "verbose", &verbose,
-- 
1.7.11.7

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

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ