linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] tools lib traceevent: Use helper trace-seq in print functions like kernel does
@ 2013-11-19 23:29 Steven Rostedt
  2013-11-20 13:27 ` Jiri Olsa
  2013-11-30 12:49 ` [tip:perf/core] " tip-bot for Steven Rostedt
  0 siblings, 2 replies; 3+ messages in thread
From: Steven Rostedt @ 2013-11-19 23:29 UTC (permalink / raw)
  To: LKML
  Cc: Arnaldo Carvalho de Melo, Jiri Olsa, Ingo Molnar,
	Frederic Weisbecker, Namhyung Kim

Jiri Olso reported that his plugin for scsi was chopping off part of
the output. Investigating this, I found that Jiri used the same
functions as what is in the kernel, which adds the following:

	trace_seq_putc(p, 0);

This adds a '\0' to the output string. The reason this works in the
kernel is that the "p" that is passed to the function helper is a
temporary trace_seq. But in the libtraceevent library, it's the pointer
to the trace_seq used to output. By adding the '\0', it truncates the
line and nothing added after that will be printed.

We can solve this in two ways. One is to have the helper functions for
the library not add the unnecessary '\0'. The other is to change the
library to also use a helper trace_seq structure that gets copied to
the main trace_seq just like the kernel does.

The latter allows the helper functions in the plugins to be the same as
the kernel, which is the better solution.

Reported-by: Jiri Olsa <jolsa@redhat.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 0362d57..27d2940 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4080,6 +4080,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 	unsigned long long val;
 	struct func_map *func;
 	const char *saveptr;
+	struct trace_seq p;
 	char *bprint_fmt = NULL;
 	char format[32];
 	int show_func;
@@ -4287,8 +4288,12 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 				format[len] = 0;
 				if (!len_as_arg)
 					len_arg = -1;
-				print_str_arg(s, data, size, event,
+				/* Use helper trace_seq */
+				trace_seq_init(&p);
+				print_str_arg(&p, data, size, event,
 					      format, len_arg, arg);
+				trace_seq_terminate(&p);
+				trace_seq_puts(s, p.buffer);
 				arg = arg->next;
 				break;
 			default:

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

* Re: [PATCH] tools lib traceevent: Use helper trace-seq in print functions like kernel does
  2013-11-19 23:29 [PATCH] tools lib traceevent: Use helper trace-seq in print functions like kernel does Steven Rostedt
@ 2013-11-20 13:27 ` Jiri Olsa
  2013-11-30 12:49 ` [tip:perf/core] " tip-bot for Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: Jiri Olsa @ 2013-11-20 13:27 UTC (permalink / raw)
  To: Steven Rostedt
  Cc: LKML, Arnaldo Carvalho de Melo, Ingo Molnar, Frederic Weisbecker,
	Namhyung Kim

On Tue, Nov 19, 2013 at 06:29:37PM -0500, Steven Rostedt wrote:
> Jiri Olso reported that his plugin for scsi was chopping off part of

s/Olso/Olsa/ 

;-)

> the output. Investigating this, I found that Jiri used the same
> functions as what is in the kernel, which adds the following:
> 
> 	trace_seq_putc(p, 0);
> 
> This adds a '\0' to the output string. The reason this works in the
> kernel is that the "p" that is passed to the function helper is a
> temporary trace_seq. But in the libtraceevent library, it's the pointer
> to the trace_seq used to output. By adding the '\0', it truncates the
> line and nothing added after that will be printed.
> 
> We can solve this in two ways. One is to have the helper functions for
> the library not add the unnecessary '\0'. The other is to change the
> library to also use a helper trace_seq structure that gets copied to
> the main trace_seq just like the kernel does.
> 
> The latter allows the helper functions in the plugins to be the same as
> the kernel, which is the better solution.
> 
> Reported-by: Jiri Olsa <jolsa@redhat.com>

Tested-by: Jiri Olsa <jolsa@redhat.com>

thanks,
jirka

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

* [tip:perf/core] tools lib traceevent: Use helper trace-seq in print functions like kernel does
  2013-11-19 23:29 [PATCH] tools lib traceevent: Use helper trace-seq in print functions like kernel does Steven Rostedt
  2013-11-20 13:27 ` Jiri Olsa
@ 2013-11-30 12:49 ` tip-bot for Steven Rostedt
  1 sibling, 0 replies; 3+ messages in thread
From: tip-bot for Steven Rostedt @ 2013-11-30 12:49 UTC (permalink / raw)
  To: linux-tip-commits
  Cc: acme, linux-kernel, hpa, mingo, namhyung, jolsa, fweisbec, rostedt, tglx

Commit-ID:  12e55569a244996a23cb401e8116e5a060b664f0
Gitweb:     http://git.kernel.org/tip/12e55569a244996a23cb401e8116e5a060b664f0
Author:     Steven Rostedt <rostedt@goodmis.org>
AuthorDate: Tue, 19 Nov 2013 18:29:37 -0500
Committer:  Arnaldo Carvalho de Melo <acme@redhat.com>
CommitDate: Wed, 27 Nov 2013 14:58:34 -0300

tools lib traceevent: Use helper trace-seq in print functions like kernel does

Jiri Olsa reported that his plugin for scsi was chopping off part of the
output. Investigating this, I found that Jiri used the same functions as
what is in the kernel, which adds the following:

	trace_seq_putc(p, 0);

This adds a '\0' to the output string. The reason this works in the
kernel is that the "p" that is passed to the function helper is a
temporary trace_seq. But in the libtraceevent library, it's the pointer
to the trace_seq used to output. By adding the '\0', it truncates the
line and nothing added after that will be printed.

We can solve this in two ways. One is to have the helper functions for
the library not add the unnecessary '\0'. The other is to change the
library to also use a helper trace_seq structure that gets copied to the
main trace_seq just like the kernel does.

The latter allows the helper functions in the plugins to be the same as
the kernel, which is the better solution.

Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Reported-by: Jiri Olsa <jolsa@redhat.com>
Tested-by: Jiri Olsa <jolsa@redhat.com>
Cc: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Jiri Olsa <jolsa@redhat.com>
Cc: Namhyung Kim <namhyung@kernel.org>
Link: http://lkml.kernel.org/r/20131119182937.401668e3@gandalf.local.home
Signed-off-by: Arnaldo Carvalho de Melo <acme@redhat.com>
---
 tools/lib/traceevent/event-parse.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/tools/lib/traceevent/event-parse.c b/tools/lib/traceevent/event-parse.c
index 217c82e..900fca0 100644
--- a/tools/lib/traceevent/event-parse.c
+++ b/tools/lib/traceevent/event-parse.c
@@ -4099,6 +4099,7 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 	unsigned long long val;
 	struct func_map *func;
 	const char *saveptr;
+	struct trace_seq p;
 	char *bprint_fmt = NULL;
 	char format[32];
 	int show_func;
@@ -4306,8 +4307,12 @@ static void pretty_print(struct trace_seq *s, void *data, int size, struct event
 				format[len] = 0;
 				if (!len_as_arg)
 					len_arg = -1;
-				print_str_arg(s, data, size, event,
+				/* Use helper trace_seq */
+				trace_seq_init(&p);
+				print_str_arg(&p, data, size, event,
 					      format, len_arg, arg);
+				trace_seq_terminate(&p);
+				trace_seq_puts(s, p.buffer);
 				arg = arg->next;
 				break;
 			default:

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

end of thread, other threads:[~2013-11-30 12:57 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-19 23:29 [PATCH] tools lib traceevent: Use helper trace-seq in print functions like kernel does Steven Rostedt
2013-11-20 13:27 ` Jiri Olsa
2013-11-30 12:49 ` [tip:perf/core] " tip-bot for Steven Rostedt

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).