public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org
Cc: Ingo Molnar <mingo@elte.hu>,
	Andrew Morton <akpm@linux-foundation.org>,
	Peter Zijlstra <peterz@infradead.org>,
	Frederic Weisbecker <fweisbec@gmail.com>,
	Arnaldo Carvalho de Melo <acme@redhat.com>,
	Steven Rostedt <srostedt@redhat.com>
Subject: [PATCH 12/15] ftrace: add traceon traceoff commands to enable/disable the buffers
Date: Tue, 17 Feb 2009 00:12:39 -0500	[thread overview]
Message-ID: <20090217051407.422977785@goodmis.org> (raw)
In-Reply-To: 20090217051227.957864159@goodmis.org

[-- Attachment #1: 0012-ftrace-add-traceon-traceoff-commands-to-enable-disa.patch --]
[-- Type: text/plain, Size: 4069 bytes --]

From: Steven Rostedt <srostedt@redhat.com>

This patch adds the new function selection commands traceon and
traceoff. traceon sets the function to enable the ring buffers
while traceoff disables the ring buffers.  You can pass in the
number of times you want the command to be executed when the function
is hit. It will only execute if the state of the buffers are not
already in that state.

Example:

 # echo do_fork:traceon:4

Will enable the ring buffers if they are disabled every time it
hits do_fork, up to 4 times.

 # echo sys_close:traceoff

This will disable the ring buffers every time (unlimited) when
sys_close is called.

Signed-off-by: Steven Rostedt <srostedt@redhat.com>
---
 kernel/trace/trace_functions.c |  135 ++++++++++++++++++++++++++++++++++++++++
 1 files changed, 135 insertions(+), 0 deletions(-)

diff --git a/kernel/trace/trace_functions.c b/kernel/trace/trace_functions.c
index 36bf956..5c95708 100644
--- a/kernel/trace/trace_functions.c
+++ b/kernel/trace/trace_functions.c
@@ -9,6 +9,7 @@
  *  Copyright (C) 2004-2006 Ingo Molnar
  *  Copyright (C) 2004 William Lee Irwin III
  */
+#include <linux/ring_buffer.h>
 #include <linux/debugfs.h>
 #include <linux/uaccess.h>
 #include <linux/ftrace.h>
@@ -231,9 +232,143 @@ static struct tracer function_trace __read_mostly =
 #endif
 };
 
+#ifdef CONFIG_DYNAMIC_FTRACE
+static void
+ftrace_traceon(unsigned long ip, unsigned long parent_ip, void **data)
+{
+	long *count = (long *)data;
+
+	if (tracing_is_on())
+		return;
+
+	if (!*count)
+		return;
+
+	if (*count != -1)
+		(*count)--;
+
+	tracing_on();
+}
+
+static void
+ftrace_traceoff(unsigned long ip, unsigned long parent_ip, void **data)
+{
+	long *count = (long *)data;
+
+	if (!tracing_is_on())
+		return;
+
+	if (!*count)
+		return;
+
+	if (*count != -1)
+		(*count)--;
+
+	tracing_off();
+}
+
+static struct ftrace_hook_ops traceon_hook_ops = {
+	.func			= ftrace_traceon,
+};
+
+static struct ftrace_hook_ops traceoff_hook_ops = {
+	.func			= ftrace_traceoff,
+};
+
+static int
+ftrace_trace_onoff_unreg(char *glob, char *cmd, char *param)
+{
+	struct ftrace_hook_ops *ops;
+
+	/* we register both traceon and traceoff to this callback */
+	if (strcmp(cmd, "traceon") == 0)
+		ops = &traceon_hook_ops;
+	else
+		ops = &traceoff_hook_ops;
+
+	unregister_ftrace_function_hook_func(glob, ops);
+
+	return 0;
+}
+
+static int
+ftrace_trace_onoff_callback(char *glob, char *cmd, char *param, int enable)
+{
+	struct ftrace_hook_ops *ops;
+	void *count = (void *)-1;
+	char *number;
+	int ret;
+
+	/* hash funcs only work with set_ftrace_filter */
+	if (!enable)
+		return -EINVAL;
+
+	if (glob[0] == '!')
+		return ftrace_trace_onoff_unreg(glob+1, cmd, param);
+
+	/* we register both traceon and traceoff to this callback */
+	if (strcmp(cmd, "traceon") == 0)
+		ops = &traceon_hook_ops;
+	else
+		ops = &traceoff_hook_ops;
+
+	if (!param)
+		goto out_reg;
+
+	number = strsep(&param, ":");
+
+	if (!strlen(number))
+		goto out_reg;
+
+	/*
+	 * We use the callback data field (which is a pointer)
+	 * as our counter.
+	 */
+	ret = strict_strtoul(number, 0, (unsigned long *)&count);
+	if (ret)
+		return ret;
+
+ out_reg:
+	ret = register_ftrace_function_hook(glob, ops, count);
+
+	return ret;
+}
+
+static struct ftrace_func_command ftrace_traceon_cmd = {
+	.name			= "traceon",
+	.func			= ftrace_trace_onoff_callback,
+};
+
+static struct ftrace_func_command ftrace_traceoff_cmd = {
+	.name			= "traceoff",
+	.func			= ftrace_trace_onoff_callback,
+};
+
+static int __init init_func_cmd_traceon(void)
+{
+	int ret;
+
+	ret = register_ftrace_command(&ftrace_traceoff_cmd);
+	if (ret)
+		return ret;
+
+	ret = register_ftrace_command(&ftrace_traceon_cmd);
+	if (ret)
+		unregister_ftrace_command(&ftrace_traceoff_cmd);
+	return ret;
+}
+#else
+static inline int init_func_cmd_traceon(void)
+{
+	return 0;
+}
+#endif /* CONFIG_DYNAMIC_FTRACE */
+
 static __init int init_function_trace(void)
 {
+	init_func_cmd_traceon();
 	return register_tracer(&function_trace);
 }
 
 device_initcall(init_function_trace);
+
-- 
1.5.6.5

-- 

  parent reply	other threads:[~2009-02-17  5:17 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-02-17  5:12 [PATCH 00/15] [git pull] for tip/tracing/ftrace Steven Rostedt
2009-02-17  5:12 ` [PATCH 01/15] ftrace: state that all functions are enabled in set_ftrace_filter Steven Rostedt
2009-02-17  5:12 ` [PATCH 02/15] ftrace: add do_for_each_ftrace_rec and while_for_each_ftrace_rec Steven Rostedt
2009-02-17  5:12 ` [PATCH 03/15] ftrace: rename ftrace_match to ftrace_match_records Steven Rostedt
2009-02-17  5:12 ` [PATCH 04/15] ftrace: break up ftrace_match_records into smaller components Steven Rostedt
2009-02-17 10:34   ` Ingo Molnar
2009-02-17  5:12 ` [PATCH 05/15] ftrace: add module command function filter selection Steven Rostedt
2009-02-17  5:12 ` [PATCH 06/15] ftrace: enable filtering only when a function is filtered on Steven Rostedt
2009-02-17  5:12 ` [PATCH 07/15] ftrace: add command interface for function selection Steven Rostedt
2009-02-17  5:12 ` [PATCH 08/15] ftrace: convert ftrace_lock from a spinlock to mutex Steven Rostedt
2009-02-17  5:12 ` [PATCH 09/15] ftrace: consolidate mutexes Steven Rostedt
2009-02-17  5:12 ` [PATCH 10/15] ftrace: trace different functions with a different tracer Steven Rostedt
2009-02-17 18:45   ` Paul E. McKenney
2009-02-17 18:53     ` Steven Rostedt
2009-02-17  5:12 ` [PATCH 11/15] ring-buffer: add tracing_is_on to test if ring buffer is enabled Steven Rostedt
2009-02-17  5:12 ` Steven Rostedt [this message]
2009-02-17 10:37   ` [PATCH 12/15] ftrace: add traceon traceoff commands to enable/disable the buffers Ingo Molnar
2009-02-17 12:45     ` Steven Rostedt
2009-02-17 12:47       ` Ingo Molnar
2009-02-17  5:12 ` [PATCH 13/15] ftrace: show selected functions in set_ftrace_filter Steven Rostedt
2009-02-17  5:12 ` [PATCH 14/15] ftrace: add pretty print to selected fuction traces Steven Rostedt
2009-02-17  5:12 ` [PATCH 15/15] ftrace: add pretty print function for traceon and traceoff hooks Steven Rostedt
2009-02-17 10:42 ` [PATCH 00/15] [git pull] for tip/tracing/ftrace Ingo Molnar
2009-02-17 12:49   ` Steven Rostedt
2009-02-17 14:37     ` Ingo Molnar
2009-02-18  0:41     ` Sam Ravnborg
2009-02-18  0:51       ` Ingo Molnar
2009-02-17 17:09   ` Steven Rostedt
2009-02-17 23:46     ` Ingo Molnar
2009-02-17 14:24 ` Frederic Weisbecker

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=20090217051407.422977785@goodmis.org \
    --to=rostedt@goodmis.org \
    --cc=acme@redhat.com \
    --cc=akpm@linux-foundation.org \
    --cc=fweisbec@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@elte.hu \
    --cc=peterz@infradead.org \
    --cc=srostedt@redhat.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