Skip to content

Commit

Permalink
ftrace: Add task_comm support for trace_event
Browse files Browse the repository at this point in the history
If we enable a trace event alone without any tracer running (such as
function tracer, sched switch tracer, etc...) it can't output enough
task command information.

We need to use the tracing_{start/stop}_cmdline_record() helpers
which are designed to keep track of cmdlines for any tasks that
were scheduled during the tracing.

Before this patch:
 # echo 1 > debugfs/tracing/events/sched/sched_switch/enable
 # cat debugfs/tracing/trace
 # tracer: nop
 #
 #           TASK-PID    CPU#    TIMESTAMP  FUNCTION
 #              | |       |          |         |
            <...>-2289  [000] 526276.724790: sched_switch: task bash:2289 [120] ==> sshd:2287 [120]
            <...>-2287  [000] 526276.725231: sched_switch: task sshd:2287 [120] ==> bash:2289 [120]
            <...>-2289  [000] 526276.725452: sched_switch: task bash:2289 [120] ==> sshd:2287 [120]
            <...>-2287  [000] 526276.727181: sched_switch: task sshd:2287 [120] ==> swapper:0 [140]
           <idle>-0     [000] 526277.032734: sched_switch: task swapper:0 [140] ==> events/0:5 [115]
            <...>-5     [000] 526277.032782: sched_switch: task events/0:5 [115] ==> swapper:0 [140]
 ...

After this patch:
 # tracer: nop
 #
 #           TASK-PID    CPU#    TIMESTAMP  FUNCTION
 #              | |       |          |         |
             bash-2269  [000] 527347.989229: sched_switch: task bash:2269 [120] ==> sshd:2267 [120]
             sshd-2267  [000] 527347.990960: sched_switch: task sshd:2267 [120] ==> bash:2269 [120]
             bash-2269  [000] 527347.991143: sched_switch: task bash:2269 [120] ==> sshd:2267 [120]
             sshd-2267  [000] 527347.992959: sched_switch: task sshd:2267 [120] ==> swapper:0 [140]
           <idle>-0     [000] 527348.531989: sched_switch: task swapper:0 [140] ==> events/0:5 [115]
         events/0-5     [000] 527348.532115: sched_switch: task events/0:5 [115] ==> swapper:0 [140]
 ...

Changelog:
v1->v2: Update Kconfig to select CONTEXT_SWITCH_TRACER in
        ENABLE_EVENT_TRACING
v2->v3: v2 can solve problem that was caused by config EVENT_TRACING
        alone, but when CONFIG_FTRACE is off and CONFIG_TRACING is
        selected by other config, compile fail happened again.
        This version solves it.

[ Impact: fix incomplete output of event tracing ]

Signed-off-by: Zhao Lei <zhaolei@cn.fujitsu.com>
Cc: Tom Zanussi <tzanussi@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
LKML-Reference: <4A14FDFE.2080402@cn.fujitsu.com>
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
  • Loading branch information
Zhaolei authored and Frederic Weisbecker committed May 26, 2009
1 parent 29fcefb commit b11c53e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
9 changes: 7 additions & 2 deletions kernel/trace/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ config FTRACE_NMI_ENTER
default y

config EVENT_TRACING
select CONTEXT_SWITCH_TRACER
bool

config CONTEXT_SWITCH_TRACER
select MARKERS
bool

config TRACING
Expand Down Expand Up @@ -176,10 +181,10 @@ config SCHED_TRACER
This tracer tracks the latency of the highest priority task
to be scheduled in, starting from the point it has woken up.

config CONTEXT_SWITCH_TRACER
config ENABLE_CONTEXT_SWITCH_TRACER
bool "Trace process context switches"
select TRACING
select MARKERS
select CONTEXT_SWITCH_TRACER
help
This tracer gets called from the context switch and records
all switching of tasks.
Expand Down
6 changes: 6 additions & 0 deletions kernel/trace/trace_events.c
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ static void ftrace_clear_events(void)

if (call->enabled) {
call->enabled = 0;
tracing_stop_cmdline_record();
call->unregfunc();
}
}
Expand All @@ -99,12 +100,14 @@ static void ftrace_event_enable_disable(struct ftrace_event_call *call,
case 0:
if (call->enabled) {
call->enabled = 0;
tracing_stop_cmdline_record();
call->unregfunc();
}
break;
case 1:
if (!call->enabled) {
call->enabled = 1;
tracing_start_cmdline_record();
call->regfunc();
}
break;
Expand Down Expand Up @@ -1058,6 +1061,7 @@ static void trace_module_remove_events(struct module *mod)
found = true;
if (call->enabled) {
call->enabled = 0;
tracing_stop_cmdline_record();
call->unregfunc();
}
if (call->event)
Expand Down Expand Up @@ -1262,11 +1266,13 @@ static __init void event_trace_self_tests(void)
}

call->enabled = 1;
tracing_start_cmdline_record();
call->regfunc();

event_test_stuff();

call->unregfunc();
tracing_stop_cmdline_record();
call->enabled = 0;

pr_cont("OK\n");
Expand Down

0 comments on commit b11c53e

Please sign in to comment.