mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Namhyung Kim <namhyung@kernel.org>
To: Arnaldo Carvalho de Melo <acme@ghostprotocols.net>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>,
	Paul Mackerras <paulus@samba.org>, Ingo Molnar <mingo@kernel.org>,
	Namhyung Kim <namhyung.kim@lge.com>,
	LKML <linux-kernel@vger.kernel.org>,
	Steven Rostedt <rostedt@goodmis.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Jiri Olsa <jolsa@redhat.com>,
	Stephane Eranian <eranian@google.com>,
	Jeremy Eder <jeder@redhat.com>
Subject: [PATCH 18/18] perf ftrace: Add --filter option
Date: Wed, 16 Oct 2013 14:00:21 +0900	[thread overview]
Message-ID: <1381899621-14638-19-git-send-email-namhyung@kernel.org> (raw)
In-Reply-To: <1381899621-14638-1-git-send-email-namhyung@kernel.org>

From: Namhyung Kim <namhyung.kim@lge.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@goodmis.org>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Signed-off-by: Namhyung Kim <namhyung@kernel.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


      parent reply	other threads:[~2013-10-16  5:01 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-10-16  5:00 [PATCHSET 00/18] perf tools: Introduce new 'ftrace' command (5) Namhyung Kim
2013-10-16  5:00 ` [PATCH 01/18] perf util: Save pid-cmdline mapping into tracing header Namhyung Kim
2013-10-16  5:00 ` [PATCH 02/18] perf util: Add more debug message on failure path Namhyung Kim
2013-10-16  5:00 ` [PATCH 03/18] perf tools: Introduce new 'ftrace' tool Namhyung Kim
2013-10-16  5:00 ` [PATCH 04/18] perf ftrace: Add support for --pid option Namhyung Kim
2013-10-16  5:00 ` [PATCH 05/18] perf ftrace: Add support for -a and -C option Namhyung Kim
2013-10-16  5:00 ` [PATCH 06/18] perf ftrace: Split "live" sub-command Namhyung Kim
2013-10-16  5:00 ` [PATCH 07/18] perf ftrace: Add 'record' sub-command Namhyung Kim
2013-10-16  5:00 ` [PATCH 08/18] perf ftrace: Add 'show' sub-command Namhyung Kim
2013-10-16  5:00 ` [PATCH 09/18] perf ftrace: Add 'report' sub-command Namhyung Kim
2013-10-16  5:00 ` [PATCH 10/18] perf ftrace: Add dump_printf() for low-level debugging Namhyung Kim
2013-10-16  5:00 ` [PATCH 11/18] perf ftrace: Use pager for displaying result Namhyung Kim
2013-10-16  5:00 ` [PATCH 12/18] perf ftrace: Cleanup using ftrace_setup/teardown() Namhyung Kim
2013-10-16  5:00 ` [PATCH 13/18] perf tools: Add document for perf-ftrace command Namhyung Kim
2013-10-16  5:00 ` [PATCH 14/18] perf ftrace: Add a signal handler for SIGSEGV Namhyung Kim
2013-10-16  5:00 ` [PATCH 15/18] perf ftrace: Add --clock option Namhyung Kim
2013-10-16  5:00 ` [PATCH 16/18] perf ftrace: Show leaf-functions as oneliner Namhyung Kim
2013-10-16  5:00 ` [PATCH 17/18] perf ftrace: Tidy up the function graph output of 'show' subcommand Namhyung Kim
2013-10-16  5:00 ` Namhyung Kim [this message]

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=1381899621-14638-19-git-send-email-namhyung@kernel.org \
    --to=namhyung@kernel.org \
    --cc=a.p.zijlstra@chello.nl \
    --cc=acme@ghostprotocols.net \
    --cc=eranian@google.com \
    --cc=fweisbec@gmail.com \
    --cc=jeder@redhat.com \
    --cc=jolsa@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=namhyung.kim@lge.com \
    --cc=paulus@samba.org \
    --cc=rostedt@goodmis.org \
    /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

all inboxes | Powered by JetHome®