Skip to contentSkip to conversation

tracing/ftrace: add an option to not print the context info for events

PATCH In review Frederic Weisbecker 3 participants 6 messages Jan 21, 2009 – Jan 30, 2009 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tracing/ftrace: add an option to not print the context info for events

Impact: make trace_event more convenient for tracers

All tracers (for the moment) that use the struct trace_event want to have the context info printed before their own output: the pid/cmdline, cpu, and timestamp.

But some other tracers that want to implement their trace_event callbacks will not necessary need these information.

This patch adds a new default-enabled trace option: TRACE_ITER_CONTEXT_INFO When disabled through:

echo nocontext-info > /debugfs/tracing/trace_options

The pid, cpu and timestamps headers will not be printed.

IE with the sched_switch tracer with context-info (default):

            bash-2935  [001]   100.356561:   2935:120:S ==> [001]     0:140:R <idle>
          <idle>-0     [000]   100.412804:      0:140:R   + [000]    11:115:S events/0
          <idle>-0     [000]   100.412816:      0:140:R ==> [000]    11:115:R events/0
        events/0-11    [000]   100.412829:     11:115:S ==> [000]     0:140:R <idle>

Without context-info:

2935:120:S ==> [001] 0:140:R <idle>

     0:140:R   + [000]    11:115:S events/0
     0:140:R ==> [000]    11:115:R events/0
    11:115:S ==> [000]     0:140:R <idle>

A tracer can disable it at runtime by clearing the bit TRACE_ITER_CONTEXT_INFO in trace_flags.

---
 kernel/trace/trace.c |   61 ++++++++++++++++++++++++++++---------------------
 kernel/trace/trace.h |    3 +-
 2 files changed, 37 insertions(+), 27 deletions(-)
kernel/trace/trace.c +35 -26
index 220c264..a59ba48 100644
@@ -227,7 +227,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
 
 /* trace_flags holds trace_options default values */
 unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
-	TRACE_ITER_ANNOTATE;
+	TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO;
 
 /**
  * trace_wake_up - wake up tasks waiting for trace input
@@ -285,6 +285,7 @@ static const char *trace_options[] = {
 	"userstacktrace",
 	"sym-userobj",
 	"printk-msg-only",
+	"context-info",
 	NULL
 };
 
@@ -1487,21 +1488,23 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
 
 	test_cpu_buff_start(iter);
 
-	comm = trace_find_cmdline(iter->ent->pid);
-
-	t = ns2usecs(iter->ts);
-	usec_rem = do_div(t, 1000000ULL);
-	secs = (unsigned long)t;
-
-	ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
-	ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
-	ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
+	if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
+		comm = trace_find_cmdline(iter->ent->pid);
+
+		t = ns2usecs(iter->ts);
+		usec_rem = do_div(t, 1000000ULL);
+		secs = (unsigned long)t;
+
+		ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+		ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+		ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+	}
 
 	event = ftrace_find_event(entry->type);
 	if (event && event->trace) {
@@ -1526,10 +1529,12 @@ static enum print_line_t print_raw_fmt(struct trace_iterator *iter)
 
 	entry = iter->ent;
 
-	ret = trace_seq_printf(s, "%d %d %llu ",
-		entry->pid, iter->cpu, iter->ts);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
+	if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
+		ret = trace_seq_printf(s, "%d %d %llu ",
+			entry->pid, iter->cpu, iter->ts);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+	}
 
 	event = ftrace_find_event(entry->type);
 	if (event && event->raw) {
@@ -1554,9 +1559,11 @@ static enum print_line_t print_hex_fmt(struct trace_iterator *iter)
 
 	entry = iter->ent;
 
-	SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
-	SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
-	SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
+	if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
+		SEQ_PUT_HEX_FIELD_RET(s, entry->pid);
+		SEQ_PUT_HEX_FIELD_RET(s, iter->cpu);
+		SEQ_PUT_HEX_FIELD_RET(s, iter->ts);
+	}
 
 	event = ftrace_find_event(entry->type);
 	if (event && event->hex)
@@ -1591,9 +1598,11 @@ static enum print_line_t print_bin_fmt(struct trace_iterator *iter)
 
 	entry = iter->ent;
 
-	SEQ_PUT_FIELD_RET(s, entry->pid);
-	SEQ_PUT_FIELD_RET(s, entry->cpu);
-	SEQ_PUT_FIELD_RET(s, iter->ts);
+	if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
+		SEQ_PUT_FIELD_RET(s, entry->pid);
+		SEQ_PUT_FIELD_RET(s, entry->cpu);
+		SEQ_PUT_FIELD_RET(s, iter->ts);
+	}
 
 	event = ftrace_find_event(entry->type);
 	if (event && event->binary)
kernel/trace/trace.h +2 -1
index b96037d..282248e 100644
@@ -590,7 +590,8 @@ enum trace_iterator_flags {
 	TRACE_ITER_ANNOTATE		= 0x2000,
 	TRACE_ITER_USERSTACKTRACE       = 0x4000,
 	TRACE_ITER_SYM_USEROBJ          = 0x8000,
-	TRACE_ITER_PRINTK_MSGONLY	= 0x10000
+	TRACE_ITER_PRINTK_MSGONLY	= 0x10000,
+	TRACE_ITER_CONTEXT_INFO		= 0x20000 /* Print pid/cpu/time */
 };
 
 /*
Signature · 1 line
1.6.0.4
maintainer
#1 lore raw
Quoted 5 lines · Frederic Weisbecker

Impact: make trace_event more convenient for tracers

All tracers (for the moment) that use the struct trace_event want to have the context info printed before their own output: the pid/cmdline, cpu, and timestamp.

Quoted 7 lines

But some other tracers that want to implement their trace_event callbacks will not necessary need these information.

This patch adds a new default-enabled trace option: TRACE_ITER_CONTEXT_INFO When disabled through:

echo nocontext-info > /debugfs/tracing/trace_options

Thanks Frederic,

Quoted 10 lines

The pid, cpu and timestamps headers will not be printed.

IE with the sched_switch tracer with context-info (default):

            bash-2935  [001]   100.356561:   2935:120:S ==> [001]     0:140:R <idle>
          <idle>-0     [000]   100.412804:      0:140:R   + [000]    11:115:S events/0
          <idle>-0     [000]   100.412816:      0:140:R ==> [000]    11:115:R events/0
        events/0-11    [000]   100.412829:     11:115:S ==> [000]     0:140:R <idle>
Quoted 8 lines

Without context-info:

2935:120:S ==> [001] 0:140:R <idle>

     0:140:R   + [000]    11:115:S events/0
     0:140:R ==> [000]    11:115:R events/0
    11:115:S ==> [000]     0:140:R <idle>

A tracer can disable it at runtime by clearing the bit TRACE_ITER_CONTEXT_INFO in trace_flags.

How about adding another function method into the tracer, where it could be what is printed at the start. The default being what is now printed. This would be for trace and latency trace only.

Quoted 54 lines
---
 kernel/trace/trace.c |   61 ++++++++++++++++++++++++++++---------------------
 kernel/trace/trace.h |    3 +-
 2 files changed, 37 insertions(+), 27 deletions(-)
kernel/trace/trace.c +9 -16
index 220c264..a59ba48 100644
@@ -227,7 +227,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
 
 /* trace_flags holds trace_options default values */
 unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
-	TRACE_ITER_ANNOTATE;
+	TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO;
 
 /**
  * trace_wake_up - wake up tasks waiting for trace input
@@ -285,6 +285,7 @@ static const char *trace_options[] = {
 	"userstacktrace",
 	"sym-userobj",
 	"printk-msg-only",
+	"context-info",
 	NULL
 };
 
@@ -1487,21 +1488,23 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
 
 	test_cpu_buff_start(iter);
 
-	comm = trace_find_cmdline(iter->ent->pid);
-
-	t = ns2usecs(iter->ts);
-	usec_rem = do_div(t, 1000000ULL);
-	secs = (unsigned long)t;
-
-	ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
-	ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
-	ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
+	if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
+		comm = trace_find_cmdline(iter->ent->pid);
+
+		t = ns2usecs(iter->ts);
+		usec_rem = do_div(t, 1000000ULL);
+		secs = (unsigned long)t;
+

kernel/trace/trace.c static enum print_line_t print_trace_fmt(struct trace_iterator *iter) · line 1507

Quoted 10 lines
kernel/trace/trace.c +10 -0
+		ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+		ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+		ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+	}

Or here we can do a:

	if (iter->tr->context_info)
		ret = iter->tr->context_info(s, iter);
	else
		ret = default_context_info(s, iter);

This may give a tracer more control as to what to print for each entry.

-- Steve

#2 lore raw
Quoted 35 lines · Steven Rostedt
Quoted 5 lines · Frederic Weisbecker

Impact: make trace_event more convenient for tracers

All tracers (for the moment) that use the struct trace_event want to have the context info printed before their own output: the pid/cmdline, cpu, and timestamp.

Quoted 7 lines

But some other tracers that want to implement their trace_event callbacks will not necessary need these information.

This patch adds a new default-enabled trace option: TRACE_ITER_CONTEXT_INFO When disabled through:

echo nocontext-info > /debugfs/tracing/trace_options

Thanks Frederic,

Quoted 17 lines

The pid, cpu and timestamps headers will not be printed.

IE with the sched_switch tracer with context-info (default):

            bash-2935  [001]   100.356561:   2935:120:S ==> [001]     0:140:R <idle>
          <idle>-0     [000]   100.412804:      0:140:R   + [000]    11:115:S events/0
          <idle>-0     [000]   100.412816:      0:140:R ==> [000]    11:115:R events/0
        events/0-11    [000]   100.412829:     11:115:S ==> [000]     0:140:R <idle>

Without context-info:

2935:120:S ==> [001] 0:140:R <idle>

     0:140:R   + [000]    11:115:S events/0
     0:140:R ==> [000]    11:115:R events/0
    11:115:S ==> [000]     0:140:R <idle>
Quoted 6 lines
Quoted 1 line

A tracer can disable it at runtime by clearing the bit TRACE_ITER_CONTEXT_INFO in trace_flags.

How about adding another function method into the tracer, where it could be what is printed at the start. The default being what is now printed. This would be for trace and latency trace only.

Good idea. So it would be something coupled with TRACE_TER_CONTEXT_INFO ? I mean, without this option, the tracers would have to implement a dummy context_info callback for these cases if they don't want any.

Quoted 67 lines
Quoted 54 lines
---
 kernel/trace/trace.c |   61 ++++++++++++++++++++++++++++---------------------
 kernel/trace/trace.h |    3 +-
 2 files changed, 37 insertions(+), 27 deletions(-)
kernel/trace/trace.c +9 -16
index 220c264..a59ba48 100644
@@ -227,7 +227,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
 
 /* trace_flags holds trace_options default values */
 unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
-	TRACE_ITER_ANNOTATE;
+	TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO;
 
 /**
  * trace_wake_up - wake up tasks waiting for trace input
@@ -285,6 +285,7 @@ static const char *trace_options[] = {
 	"userstacktrace",
 	"sym-userobj",
 	"printk-msg-only",
+	"context-info",
 	NULL
 };
 
@@ -1487,21 +1488,23 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
 
 	test_cpu_buff_start(iter);
 
-	comm = trace_find_cmdline(iter->ent->pid);
-
-	t = ns2usecs(iter->ts);
-	usec_rem = do_div(t, 1000000ULL);
-	secs = (unsigned long)t;
-
-	ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
-	ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
-	ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
+	if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
+		comm = trace_find_cmdline(iter->ent->pid);
+
+		t = ns2usecs(iter->ts);
+		usec_rem = do_div(t, 1000000ULL);
+		secs = (unsigned long)t;
+

kernel/trace/trace.c static enum print_line_t print_trace_fmt(struct trace_iterator *iter) · line 1507

Quoted 10 lines
kernel/trace/trace.c +10 -0
+		ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+		ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+		ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+	}

Or here we can do a:

Quoted 8 lines
	if (iter->tr->context_info)
		ret = iter->tr->context_info(s, iter);
	else
		ret = default_context_info(s, iter);

This may give a tracer more control as to what to print for each entry.

-- Steve

Indeed, thanks!

#3 lore raw
In reply to Steven Rostedt
Quoted 109 lines · Steven Rostedt
Quoted 5 lines · Frederic Weisbecker

Impact: make trace_event more convenient for tracers

All tracers (for the moment) that use the struct trace_event want to have the context info printed before their own output: the pid/cmdline, cpu, and timestamp.

Quoted 7 lines

But some other tracers that want to implement their trace_event callbacks will not necessary need these information.

This patch adds a new default-enabled trace option: TRACE_ITER_CONTEXT_INFO When disabled through:

echo nocontext-info > /debugfs/tracing/trace_options

Thanks Frederic,

Quoted 10 lines

The pid, cpu and timestamps headers will not be printed.

IE with the sched_switch tracer with context-info (default):

            bash-2935  [001]   100.356561:   2935:120:S ==> [001]     0:140:R <idle>
          <idle>-0     [000]   100.412804:      0:140:R   + [000]    11:115:S events/0
          <idle>-0     [000]   100.412816:      0:140:R ==> [000]    11:115:R events/0
        events/0-11    [000]   100.412829:     11:115:S ==> [000]     0:140:R <idle>
Quoted 8 lines

Without context-info:

2935:120:S ==> [001] 0:140:R <idle>

     0:140:R   + [000]    11:115:S events/0
     0:140:R ==> [000]    11:115:R events/0
    11:115:S ==> [000]     0:140:R <idle>

A tracer can disable it at runtime by clearing the bit TRACE_ITER_CONTEXT_INFO in trace_flags.

How about adding another function method into the tracer, where it could be what is printed at the start. The default being what is now printed. This would be for trace and latency trace only.

Quoted 54 lines
---
 kernel/trace/trace.c |   61 ++++++++++++++++++++++++++++---------------------
 kernel/trace/trace.h |    3 +-
 2 files changed, 37 insertions(+), 27 deletions(-)
kernel/trace/trace.c +9 -16
index 220c264..a59ba48 100644
@@ -227,7 +227,7 @@ static DECLARE_WAIT_QUEUE_HEAD(trace_wait);
 
 /* trace_flags holds trace_options default values */
 unsigned long trace_flags = TRACE_ITER_PRINT_PARENT | TRACE_ITER_PRINTK |
-	TRACE_ITER_ANNOTATE;
+	TRACE_ITER_ANNOTATE | TRACE_ITER_CONTEXT_INFO;
 
 /**
  * trace_wake_up - wake up tasks waiting for trace input
@@ -285,6 +285,7 @@ static const char *trace_options[] = {
 	"userstacktrace",
 	"sym-userobj",
 	"printk-msg-only",
+	"context-info",
 	NULL
 };
 
@@ -1487,21 +1488,23 @@ static enum print_line_t print_trace_fmt(struct trace_iterator *iter)
 
 	test_cpu_buff_start(iter);
 
-	comm = trace_find_cmdline(iter->ent->pid);
-
-	t = ns2usecs(iter->ts);
-	usec_rem = do_div(t, 1000000ULL);
-	secs = (unsigned long)t;
-
-	ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
-	ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
-	ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
-	if (!ret)
-		return TRACE_TYPE_PARTIAL_LINE;
+	if (trace_flags & TRACE_ITER_CONTEXT_INFO) {
+		comm = trace_find_cmdline(iter->ent->pid);
+
+		t = ns2usecs(iter->ts);
+		usec_rem = do_div(t, 1000000ULL);
+		secs = (unsigned long)t;
+

kernel/trace/trace.c static enum print_line_t print_trace_fmt(struct trace_iterator *iter) · line 1507

Quoted 10 lines
kernel/trace/trace.c +10 -0
+		ret = trace_seq_printf(s, "%16s-%-5d ", comm, entry->pid);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+		ret = trace_seq_printf(s, "[%03d] ", iter->cpu);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+		ret = trace_seq_printf(s, "%5lu.%06lu: ", secs, usec_rem);
+		if (!ret)
+			return TRACE_TYPE_PARTIAL_LINE;
+	}

Or here we can do a:

Quoted 9 lines
	if (iter->tr->context_info)
		ret = iter->tr->context_info(s, iter);
	else
		ret = default_context_info(s, iter);

This may give a tracer more control as to what to print for each entry.

-- Steve

So what do you suggest actually? To keep TRACE_ITER_CONTEXT_INFO and add two callbacks to control trace and latency_trace?

Or completely drop the option and only add these callbacks?

Keeping both will let a tracer decide if it wants to keep the headers for binary, hex and raw too..

#4 lore raw
In reply to Frederic Weisbecker

kernel/trace/trace.c static enum print_line_t print_trace_fmt(struct trace_iterator *iter) · line 1495

Quoted 1 line · On Tue, 20 Jan 2009 16:52:36 -0800 (PST) Frederic Weisbecker…
kernel/trace/trace.c +1 -0
+		usec_rem = do_div(t, 1000000ULL);

The second argument to do_div() is in fact a u32. It's quite hard to track this down due to use of macros and lack of comemnts.

Doing

	usec_rem = do_div(t, USEC_PER_SEC);

would suit here.

#5 lore raw
Quoted 8 lines · Andrew Morton

kernel/trace/trace.c static enum print_line_t print_trace_fmt(struct trace_iterator *iter) · line 1495

Quoted 1 line · On Tue, 20 Jan 2009 16:52:36 -0800 (PST) Frederic Weisbecker…
kernel/trace/trace.c +1 -0
+		usec_rem = do_div(t, 1000000ULL);

The second argument to do_div() is in fact a u32. It's quite hard to track this down due to use of macros and lack of comemnts.

Quoted 5 lines

Doing

	usec_rem = do_div(t, USEC_PER_SEC);

would suit here.

Thanks, I've fixed it for the next version of this patch.