Skip to contentSkip to conversation

trace: don't print an extra separator of flags

PATCH In review Andrew Vagin 3 participants 7 messages Feb 19, 2012 – Feb 27, 2012 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 trace: don't print an extra separator of flags

From: Andrey Vagin <[email protected]>

It occurs if __print_flags is used more than once

---
 kernel/trace/trace_output.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +4 -2
index 0d6ff35..3efd718 100644
@@ -300,7 +300,7 @@ ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
 	unsigned long mask;
 	const char *str;
 	const char *ret = p->buffer + p->len;
-	int i;
+	int i, first = 1;
 
 	for (i = 0;  flag_array[i].name && flags; i++) {
 
@@ -310,8 +310,10 @@ ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
 
 		str = flag_array[i].name;
 		flags &= ~mask;
-		if (p->len && delim)
+		if (!first && delim)
 			trace_seq_puts(p, delim);
+		else
+			first = 0;
 		trace_seq_puts(p, str);
 	}
 
Signature · 1 line
1.7.1
maintainer
#1 lore raw
Quoted 3 lines · Andrew Vagin

From: Andrey Vagin <[email protected]>

It occurs if __print_flags is used more than once

Hi, which tracepoint does this? I like to see what the issue is.

Thanks,

-- Steve

Quoted 31 lines
---
 kernel/trace/trace_output.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +4 -2
index 0d6ff35..3efd718 100644
@@ -300,7 +300,7 @@ ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
 	unsigned long mask;
 	const char *str;
 	const char *ret = p->buffer + p->len;
-	int i;
+	int i, first = 1;
 
 	for (i = 0;  flag_array[i].name && flags; i++) {
 
@@ -310,8 +310,10 @@ ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
 
 		str = flag_array[i].name;
 		flags &= ~mask;
-		if (p->len && delim)
+		if (!first && delim)
 			trace_seq_puts(p, delim);
+		else
+			first = 0;
 		trace_seq_puts(p, str);
 	}
 
#2 lore raw
Quoted 6 lines · Steven Rostedt
Quoted 3 lines · Andrew Vagin

From: Andrey Vagin<[email protected]>

It occurs if __print_flags is used more than once

Hi, which tracepoint does this? I like to see what the issue is.

The mainstream kernel doesn't have such trace-point, but I have.

Do you want to say that this bug should not be fixed in this case? :)

Quoted 43 lines

Thanks,

-- Steve

Quoted 21 lines
---
  kernel/trace/trace_output.c |    6 ++++--
  1 files changed, 4 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +1 -1
index 0d6ff35..3efd718 100644
@@ -300,7 +300,7 @@ ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
  	unsigned long mask;
  	const char *str;
  	const char *ret = p->buffer + p->len;
-	int i;
+	int i, first = 1;
 
  	for (i = 0;  flag_array[i].name&&  flags; i++) {
 
@@ -310,8 +310,10 @@ ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
 

kernel/trace/trace_output.c ftrace_print_flags_seq(struct trace_seq *p, const char *delim, · line 319

Quoted 10 lines
kernel/trace/trace_output.c +3 -1
  		str = flag_array[i].name;
  		flags&= ~mask;
-		if (p->len&&  delim)
+		if (!first&&  delim)
  			trace_seq_puts(p, delim);
+		else
+			first = 0;
  		trace_seq_puts(p, str);
  	}
 

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

maintainer
#3 lore raw
Quoted 9 lines · On Mon, 2012-02-20 at 23:39 +0400, [email protected] wrote:
Quoted 6 lines · Steven Rostedt
Quoted 3 lines · Andrew Vagin

From: Andrey Vagin<[email protected]>

It occurs if __print_flags is used more than once

Hi, which tracepoint does this? I like to see what the issue is.

The mainstream kernel doesn't have such trace-point, but I have.

Could you send me that patch. Or a change to the kernel that shows the problem.

Quoted 2 lines

Do you want to say that this bug should not be fixed in this case? :)

No, if it is a issue with the infrastructure, even though nothing triggers the problem, it should still be fixed, especially if new code in the future will be triggering it.

-- Steve

#4 lore raw
Quoted 2 lines

Could you send me that patch. Or a change to the kernel that shows the problemi.

Without my patch:

    event-sample-1731  [000] ...1 546886.253576: foo_bar: foo hello 3 |A B
    event-sample-1731  [000] ...1 546887.253677: foo_bar: foo hello 4 |A B

With my patch:

    event-sample-1731  [000] ...1 546886.253576: foo_bar: foo hello 3 A B
    event-sample-1731  [000] ...1 546887.253677: foo_bar: foo hello 4 A B
---
 samples/trace_events/trace-events-sample.h |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)
samples/trace_events/trace-events-sample.h +1 -1
index 6af3732..812be4b 100644
@@ -90,7 +90,7 @@ TRACE_EVENT(foo_bar,
 		__entry->bar	= bar;
 	),
 
-	TP_printk("foo %s %d", __entry->foo, __entry->bar)
+	TP_printk("foo %s %d %s %s", __entry->foo, __entry->bar, __print_flags(1, "|", {1, "A"}), __print_flags(2, "&", {2, "B"}))
 );
 #endif
 
Signature · 1 line
1.7.1
maintainer
#5 lore raw
Quoted 10 lines · Andrew Vagin
Quoted 2 lines

Could you send me that patch. Or a change to the kernel that shows the problemi.

Without my patch:

    event-sample-1731  [000] ...1 546886.253576: foo_bar: foo hello 3 |A B
    event-sample-1731  [000] ...1 546887.253677: foo_bar: foo hello 4 |A B

With my patch:

    event-sample-1731  [000] ...1 546886.253576: foo_bar: foo hello 3 A B
    event-sample-1731  [000] ...1 546887.253677: foo_bar: foo hello 4 A B

Ah, nevermind. This bug actually does show up in another tracepoint somewhere (I don't remember which). But I've been meaning to fix it.

Thanks! I'll take your patch. But since it is such a minor bug. I'll put it into the v3.4 queue.

-- Steve

#6 lore raw

[tip:perf/core] tracing: Don't print an extra separator of flags

In reply to Andrew Vagin
Commit-ID:  e404b321dbb2d6e438522b7dce9c1d0c6a8c5275
Gitweb:     http://git.kernel.org/tip/e404b321dbb2d6e438522b7dce9c1d0c6a8c5275
Author:     Andrey Vagin <[email protected]>
AuthorDate: Sun, 19 Feb 2012 14:16:07 +0300
Committer:  Steven Rostedt <[email protected]>
CommitDate: Mon, 20 Feb 2012 20:33:31 -0500

tracing: Don't print an extra separator of flags

If __print_flags() is used after another __print_*() function, the temp seq_file buffer will not be empty on entry, and the delimiter will be printed even though there's just one field. We get something like:

	|S

instead of just:

S

This is because the length of the temp seq buffer is used to determine if the delimiter is printed or not. But this algorithm fails when the seq buffer is not empty on entry, and the delimiter will be printed because it thinks that a previous field was already printed.

Cc Ingo Molnar <[email protected]>
Cc Frederic Weisbecker <[email protected]>
---
 kernel/trace/trace_output.c |    6 ++++--
 1 files changed, 4 insertions(+), 2 deletions(-)
kernel/trace/trace_output.c +4 -2
index 0d6ff355..3efd718 100644
@@ -300,7 +300,7 @@ ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
 	unsigned long mask;
 	const char *str;
 	const char *ret = p->buffer + p->len;
-	int i;
+	int i, first = 1;
 
 	for (i = 0;  flag_array[i].name && flags; i++) {
 
@@ -310,8 +310,10 @@ ftrace_print_flags_seq(struct trace_seq *p, const char *delim,
 
 		str = flag_array[i].name;
 		flags &= ~mask;
-		if (p->len && delim)
+		if (!first && delim)
 			trace_seq_puts(p, delim);
+		else
+			first = 0;
 		trace_seq_puts(p, str);
 	}