public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 08/10] trace_kprobe: init print_fmt
@ 2009-12-09  7:15 Lai Jiangshan
  2009-12-09 17:54 ` Masami Hiramatsu
  0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2009-12-09  7:15 UTC (permalink / raw)
  To: Ingo Molnar, Steven Rostedt, Frederic Weisbecker,
	Masami Hiramatsu, Jason Baron, LKML

Init print_fmt for trace_kprobe.
It will be used for replacing ->show_format().

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
---
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 3ef66d4..a12d39b 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1212,6 +1212,55 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
 					 ", REC->" FIELD_STRING_RETIP);
 }
 
+static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
+{
+	int i;
+	int pos = 0;
+
+	const char *fmt, *arg;
+
+	if (!probe_is_return(tp)) {
+		fmt = "(%lx)";
+		arg = "REC->" FIELD_STRING_IP;
+	} else {
+		fmt = "(%lx <- %lx)";
+		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
+	}
+
+	pos += snprintf(buf + pos, len > pos ? len - pos : 0, "\"%s", fmt);
+
+	for (i = 0; i < tp->nr_args; i++) {
+		pos += snprintf(buf + pos, len > pos ? len - pos : 0,
+				" %s=%%lx", tp->args[i].name);
+	}
+
+	pos += snprintf(buf + pos, len > pos ? len - pos : 0, "\", %s", arg);
+
+	for (i = 0; i < tp->nr_args; i++) {
+		pos += snprintf(buf + pos, len > pos ? len - pos : 0,
+				", REC->%s", tp->args[i].name);
+	}
+
+	/* return the length of print_fmt */
+	return pos;
+}
+
+static int set_print_fmt(struct trace_probe *tp)
+{
+	int len;
+	char *print_fmt;
+
+	len = __set_print_fmt(tp, NULL, 0);
+	print_fmt = kmalloc(len + 1, GFP_KERNEL);
+	if (!print_fmt)
+		return -ENOMEM;
+
+	__set_print_fmt(tp, print_fmt, len + 1);
+	tp->call.print_fmt = print_fmt;
+
+	return 0;
+}
+
 #ifdef CONFIG_EVENT_PROFILE
 
 /* Kprobe profile handler */
@@ -1418,10 +1467,14 @@ static int register_probe_event(struct trace_probe *tp)
 		call->show_format = kprobe_event_show_format;
 		call->define_fields = kprobe_event_define_fields;
 	}
+	if (set_print_fmt(tp) < 0)
+		return -ENOMEM;
 	call->event = &tp->event;
 	call->id = register_ftrace_event(&tp->event);
-	if (!call->id)
+	if (!call->id) {
+		kfree(call->print_fmt);
 		return -ENODEV;
+	}
 	call->enabled = 0;
 	call->regfunc = probe_event_enable;
 	call->unregfunc = probe_event_disable;
@@ -1435,6 +1488,7 @@ static int register_probe_event(struct trace_probe *tp)
 	ret = trace_add_event_call(call);
 	if (ret) {
 		pr_info("Failed to register kprobe event: %s\n", call->name);
+		kfree(call->print_fmt);
 		unregister_ftrace_event(&tp->event);
 	}
 	return ret;
@@ -1444,6 +1498,7 @@ static void unregister_probe_event(struct trace_probe *tp)
 {
 	/* tp->event is unregistered in trace_remove_event_call() */
 	trace_remove_event_call(&tp->call);
+	kfree(tp->call.print_fmt);
 }
 
 /* Make a debugfs interface for controling probe points */


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 08/10] trace_kprobe: init print_fmt
  2009-12-09  7:15 [PATCH 08/10] trace_kprobe: init print_fmt Lai Jiangshan
@ 2009-12-09 17:54 ` Masami Hiramatsu
  0 siblings, 0 replies; 4+ messages in thread
From: Masami Hiramatsu @ 2009-12-09 17:54 UTC (permalink / raw)
  To: Lai Jiangshan
  Cc: Ingo Molnar, Steven Rostedt, Frederic Weisbecker, Jason Baron,
	LKML

Lai Jiangshan wrote:
> Init print_fmt for trace_kprobe.
> It will be used for replacing ->show_format().
>
> Signed-off-by: Lai Jiangshan<laijs@cn.fujitsu.com>

Looks good to me.

Acked-by: Masami Hiramatsu <mhiramat@redhat.com>

> ---
> diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
> index 3ef66d4..a12d39b 100644
> --- a/kernel/trace/trace_kprobe.c
> +++ b/kernel/trace/trace_kprobe.c
> @@ -1212,6 +1212,55 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
>   					 ", REC->" FIELD_STRING_RETIP);
>   }
>
> +static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
> +{
> +	int i;
> +	int pos = 0;
> +
> +	const char *fmt, *arg;
> +
> +	if (!probe_is_return(tp)) {
> +		fmt = "(%lx)";
> +		arg = "REC->" FIELD_STRING_IP;
> +	} else {
> +		fmt = "(%lx<- %lx)";
> +		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
> +	}
> +
> +	pos += snprintf(buf + pos, len>  pos ? len - pos : 0, "\"%s", fmt);
> +
> +	for (i = 0; i<  tp->nr_args; i++) {
> +		pos += snprintf(buf + pos, len>  pos ? len - pos : 0,
> +				" %s=%%lx", tp->args[i].name);
> +	}
> +
> +	pos += snprintf(buf + pos, len>  pos ? len - pos : 0, "\", %s", arg);
> +
> +	for (i = 0; i<  tp->nr_args; i++) {
> +		pos += snprintf(buf + pos, len>  pos ? len - pos : 0,
> +				", REC->%s", tp->args[i].name);
> +	}
> +
> +	/* return the length of print_fmt */
> +	return pos;
> +}
> +
> +static int set_print_fmt(struct trace_probe *tp)
> +{
> +	int len;
> +	char *print_fmt;
> +
> +	len = __set_print_fmt(tp, NULL, 0);
> +	print_fmt = kmalloc(len + 1, GFP_KERNEL);
> +	if (!print_fmt)
> +		return -ENOMEM;
> +
> +	__set_print_fmt(tp, print_fmt, len + 1);
> +	tp->call.print_fmt = print_fmt;
> +
> +	return 0;
> +}
> +
>   #ifdef CONFIG_EVENT_PROFILE
>
>   /* Kprobe profile handler */
> @@ -1418,10 +1467,14 @@ static int register_probe_event(struct trace_probe *tp)
>   		call->show_format = kprobe_event_show_format;
>   		call->define_fields = kprobe_event_define_fields;
>   	}
> +	if (set_print_fmt(tp)<  0)
> +		return -ENOMEM;
>   	call->event =&tp->event;
>   	call->id = register_ftrace_event(&tp->event);
> -	if (!call->id)
> +	if (!call->id) {
> +		kfree(call->print_fmt);
>   		return -ENODEV;
> +	}
>   	call->enabled = 0;
>   	call->regfunc = probe_event_enable;
>   	call->unregfunc = probe_event_disable;
> @@ -1435,6 +1488,7 @@ static int register_probe_event(struct trace_probe *tp)
>   	ret = trace_add_event_call(call);
>   	if (ret) {
>   		pr_info("Failed to register kprobe event: %s\n", call->name);
> +		kfree(call->print_fmt);
>   		unregister_ftrace_event(&tp->event);
>   	}
>   	return ret;
> @@ -1444,6 +1498,7 @@ static void unregister_probe_event(struct trace_probe *tp)
>   {
>   	/* tp->event is unregistered in trace_remove_event_call() */
>   	trace_remove_event_call(&tp->call);
> +	kfree(tp->call.print_fmt);
>   }
>
>   /* Make a debugfs interface for controling probe points */
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> Please read the FAQ at  http://www.tux.org/lkml/

-- 
Masami Hiramatsu

Software Engineer
Hitachi Computer Products (America), Inc.
Software Solutions Division

e-mail: mhiramat@redhat.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [PATCH 08/10] trace_kprobe: init print_fmt
@ 2009-12-15  7:39 Lai Jiangshan
  2010-01-13 10:22 ` [tip:tracing/core] tracing/kprobes: Init print_fmt for kprobe events tip-bot for Lai Jiangshan
  0 siblings, 1 reply; 4+ messages in thread
From: Lai Jiangshan @ 2009-12-15  7:39 UTC (permalink / raw)
  To: Ingo Molnar, Steven Rostedt, Frederic Weisbecker,
	Masami Hiramatsu, Jason Baron, LKML

Init print_fmt for trace_kprobe.

But this field is still not used now,
the next patches will use it and replace the ->show_format().

It is preparing patch for new way of printing format files which
uses defined fields and a defined print_fmt to print formats.

How will the new way works(and how print_fmt will be used)?
print name
print ID
print string "format:"
use struct ftrace_event_call->fields to print fields
use struct ftrace_event_call->print_fmt to print "print fmt: XXXXXXXXXXX"

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
Acked-by: Masami Hiramatsu <mhiramat@redhat.com>
---
diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 83f1e6e..1ccf39f 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1231,6 +1231,62 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
 					 ", REC->" FIELD_STRING_RETIP);
 }
 
+static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
+{
+	int i;
+	int pos = 0;
+
+	const char *fmt, *arg;
+
+	if (!probe_is_return(tp)) {
+		fmt = "(%lx)";
+		arg = "REC->" FIELD_STRING_IP;
+	} else {
+		fmt = "(%lx <- %lx)";
+		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
+	}
+
+	/* When len=0, we just calculate the needed length */
+#define LEN_OR_ZERO (len ? len - pos : 0)
+
+	pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
+
+	for (i = 0; i < tp->nr_args; i++) {
+		pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%%lx",
+				tp->args[i].name);
+	}
+
+	pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
+
+	for (i = 0; i < tp->nr_args; i++) {
+		pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
+				tp->args[i].name);
+	}
+
+#undef LEN_OR_ZERO
+
+	/* return the length of print_fmt */
+	return pos;
+}
+
+static int set_print_fmt(struct trace_probe *tp)
+{
+	int len;
+	char *print_fmt;
+
+	/* First: called with 0 length to calculate the needed length */
+	len = __set_print_fmt(tp, NULL, 0);
+	print_fmt = kmalloc(len + 1, GFP_KERNEL);
+	if (!print_fmt)
+		return -ENOMEM;
+
+	/* Second: actually write the @print_fmt */
+	__set_print_fmt(tp, print_fmt, len + 1);
+	tp->call.print_fmt = print_fmt;
+
+	return 0;
+}
+
 #ifdef CONFIG_EVENT_PROFILE
 
 /* Kprobe profile handler */
@@ -1437,10 +1493,14 @@ static int register_probe_event(struct trace_probe *tp)
 		call->show_format = kprobe_event_show_format;
 		call->define_fields = kprobe_event_define_fields;
 	}
+	if (set_print_fmt(tp) < 0)
+		return -ENOMEM;
 	call->event = &tp->event;
 	call->id = register_ftrace_event(&tp->event);
-	if (!call->id)
+	if (!call->id) {
+		kfree(call->print_fmt);
 		return -ENODEV;
+	}
 	call->enabled = 0;
 	call->regfunc = probe_event_enable;
 	call->unregfunc = probe_event_disable;
@@ -1453,6 +1513,7 @@ static int register_probe_event(struct trace_probe *tp)
 	ret = trace_add_event_call(call);
 	if (ret) {
 		pr_info("Failed to register kprobe event: %s\n", call->name);
+		kfree(call->print_fmt);
 		unregister_ftrace_event(&tp->event);
 	}
 	return ret;
@@ -1462,6 +1523,7 @@ static void unregister_probe_event(struct trace_probe *tp)
 {
 	/* tp->event is unregistered in trace_remove_event_call() */
 	trace_remove_event_call(&tp->call);
+	kfree(tp->call.print_fmt);
 }
 
 /* Make a debugfs interface for controling probe points */




^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [tip:tracing/core] tracing/kprobes: Init print_fmt for kprobe events
  2009-12-15  7:39 [PATCH 08/10] trace_kprobe: init print_fmt Lai Jiangshan
@ 2010-01-13 10:22 ` tip-bot for Lai Jiangshan
  0 siblings, 0 replies; 4+ messages in thread
From: tip-bot for Lai Jiangshan @ 2010-01-13 10:22 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: linux-kernel, hpa, mingo, rostedt, tglx, mhiramat, laijs

Commit-ID:  a342a0280b981c130e32dbb94dbd3a57959c4d04
Gitweb:     http://git.kernel.org/tip/a342a0280b981c130e32dbb94dbd3a57959c4d04
Author:     Lai Jiangshan <laijs@cn.fujitsu.com>
AuthorDate: Tue, 15 Dec 2009 15:39:49 +0800
Committer:  Steven Rostedt <rostedt@goodmis.org>
CommitDate: Wed, 6 Jan 2010 12:01:35 -0500

tracing/kprobes: Init print_fmt for kprobe events

This is part of a patch set that removes the show_format method
in the ftrace event macros.

Add the print_fmt initialization to the kprobe events.
The print_fmt is still not used, but will be in the follow up
patches.

Signed-off-by: Lai Jiangshan <laijs@cn.fujitsu.com>
LKML-Reference: <4B273D45.3080100@cn.fujitsu.com>
Acked-by: Masami Hiramatsu <mhiramat@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
---
 kernel/trace/trace_kprobe.c |   64 ++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 63 insertions(+), 1 deletions(-)

diff --git a/kernel/trace/trace_kprobe.c b/kernel/trace/trace_kprobe.c
index 6ea90c0..147491d 100644
--- a/kernel/trace/trace_kprobe.c
+++ b/kernel/trace/trace_kprobe.c
@@ -1250,6 +1250,62 @@ static int kretprobe_event_show_format(struct ftrace_event_call *call,
 					 ", REC->" FIELD_STRING_RETIP);
 }
 
+static int __set_print_fmt(struct trace_probe *tp, char *buf, int len)
+{
+	int i;
+	int pos = 0;
+
+	const char *fmt, *arg;
+
+	if (!probe_is_return(tp)) {
+		fmt = "(%lx)";
+		arg = "REC->" FIELD_STRING_IP;
+	} else {
+		fmt = "(%lx <- %lx)";
+		arg = "REC->" FIELD_STRING_FUNC ", REC->" FIELD_STRING_RETIP;
+	}
+
+	/* When len=0, we just calculate the needed length */
+#define LEN_OR_ZERO (len ? len - pos : 0)
+
+	pos += snprintf(buf + pos, LEN_OR_ZERO, "\"%s", fmt);
+
+	for (i = 0; i < tp->nr_args; i++) {
+		pos += snprintf(buf + pos, LEN_OR_ZERO, " %s=%%lx",
+				tp->args[i].name);
+	}
+
+	pos += snprintf(buf + pos, LEN_OR_ZERO, "\", %s", arg);
+
+	for (i = 0; i < tp->nr_args; i++) {
+		pos += snprintf(buf + pos, LEN_OR_ZERO, ", REC->%s",
+				tp->args[i].name);
+	}
+
+#undef LEN_OR_ZERO
+
+	/* return the length of print_fmt */
+	return pos;
+}
+
+static int set_print_fmt(struct trace_probe *tp)
+{
+	int len;
+	char *print_fmt;
+
+	/* First: called with 0 length to calculate the needed length */
+	len = __set_print_fmt(tp, NULL, 0);
+	print_fmt = kmalloc(len + 1, GFP_KERNEL);
+	if (!print_fmt)
+		return -ENOMEM;
+
+	/* Second: actually write the @print_fmt */
+	__set_print_fmt(tp, print_fmt, len + 1);
+	tp->call.print_fmt = print_fmt;
+
+	return 0;
+}
+
 #ifdef CONFIG_EVENT_PROFILE
 
 /* Kprobe profile handler */
@@ -1456,10 +1512,14 @@ static int register_probe_event(struct trace_probe *tp)
 		call->show_format = kprobe_event_show_format;
 		call->define_fields = kprobe_event_define_fields;
 	}
+	if (set_print_fmt(tp) < 0)
+		return -ENOMEM;
 	call->event = &tp->event;
 	call->id = register_ftrace_event(&tp->event);
-	if (!call->id)
+	if (!call->id) {
+		kfree(call->print_fmt);
 		return -ENODEV;
+	}
 	call->enabled = 0;
 	call->regfunc = probe_event_enable;
 	call->unregfunc = probe_event_disable;
@@ -1472,6 +1532,7 @@ static int register_probe_event(struct trace_probe *tp)
 	ret = trace_add_event_call(call);
 	if (ret) {
 		pr_info("Failed to register kprobe event: %s\n", call->name);
+		kfree(call->print_fmt);
 		unregister_ftrace_event(&tp->event);
 	}
 	return ret;
@@ -1481,6 +1542,7 @@ static void unregister_probe_event(struct trace_probe *tp)
 {
 	/* tp->event is unregistered in trace_remove_event_call() */
 	trace_remove_event_call(&tp->call);
+	kfree(tp->call.print_fmt);
 }
 
 /* Make a debugfs interface for controling probe points */

^ permalink raw reply related	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2010-01-13 10:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-12-15  7:39 [PATCH 08/10] trace_kprobe: init print_fmt Lai Jiangshan
2010-01-13 10:22 ` [tip:tracing/core] tracing/kprobes: Init print_fmt for kprobe events tip-bot for Lai Jiangshan
  -- strict thread matches above, loose matches on Subject: below --
2009-12-09  7:15 [PATCH 08/10] trace_kprobe: init print_fmt Lai Jiangshan
2009-12-09 17:54 ` Masami Hiramatsu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox