diff options
author | Steven Rostedt <srostedt@redhat.com> | 2008-11-05 16:05:44 -0500 |
---|---|---|
committer | Ingo Molnar <mingo@elte.hu> | 2008-11-06 01:51:03 -0500 |
commit | 9036990d462e09366f7297a2d1da6582c3e6b1d3 (patch) | |
tree | e110393aad12177cb17fa68cb3fefb18ae2f1037 /kernel/trace/trace.c | |
parent | 0f04870148ecb825133bc2733f473b1c5773ac0b (diff) |
ftrace: restructure tracing start/stop infrastructure
Impact: change where tracing is started up and stopped
Currently, when a new tracer is selected via echo'ing a tracer name into
the current_tracer file, the startup is only done if tracing_enabled is
set to one. If tracing_enabled is changed to zero (by echo'ing 0 into
the tracing_enabled file) a full shutdown is performed.
The full startup and shutdown of a tracer can be expensive and the
user can lose out traces when echo'ing in 0 to the tracing_enabled file,
because the process takes too long. There can also be places that
the user would like to start and stop the tracer several times and
doing the full startup and shutdown of a tracer might be too expensive.
This patch performs the full startup and shutdown when a tracer is
selected. It also adds a way to do a quick start or stop of a tracer.
The quick version is just a flag that prevents the tracing from
taking place, but the overhead of the code is still there.
For example, the startup of a tracer may enable tracepoints, or enable
the function tracer. The stop and start will just set a flag to
have the tracer ignore the calls when the tracepoint or function trace
is called. The overhead of the tracer may still be present when
the tracer is stopped, but no tracing will occur. Setting the tracer
to the 'nop' tracer (or any other tracer) will perform the shutdown
of the tracer which will disable the tracepoint or disable the
function tracer.
The tracing_enabled file will simply start or stop tracing.
This change is all internal. The end result for the user should be the same
as before. If tracing_enabled is not set, no trace will happen.
If tracing_enabled is set, then the trace will happen. The tracing_enabled
variable is static between tracers. Enabling tracing_enabled and
going to another tracer will keep tracing_enabled enabled. Same
is true with disabling tracing_enabled.
This patch will now provide a fast start/stop method to the users
for enabling or disabling tracing.
Note: There were two methods to the struct tracer that were never
used: The methods start and stop. These were to be used as a hook
to the reading of the trace output, but ended up not being
necessary. These two methods are now used to enable the start
and stop of each tracer, in case the tracer needs to do more than
just not write into the buffer. For example, the irqsoff tracer
must stop recording max latencies when tracing is stopped.
Signed-off-by: Steven Rostedt <srostedt@redhat.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
Diffstat (limited to 'kernel/trace/trace.c')
-rw-r--r-- | kernel/trace/trace.c | 64 |
1 files changed, 28 insertions, 36 deletions
diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c index 113aea9447ec..ff1e9ed9b587 100644 --- a/kernel/trace/trace.c +++ b/kernel/trace/trace.c | |||
@@ -150,6 +150,19 @@ static DEFINE_PER_CPU(struct trace_array_cpu, max_data); | |||
150 | /* tracer_enabled is used to toggle activation of a tracer */ | 150 | /* tracer_enabled is used to toggle activation of a tracer */ |
151 | static int tracer_enabled = 1; | 151 | static int tracer_enabled = 1; |
152 | 152 | ||
153 | /** | ||
154 | * tracing_is_enabled - return tracer_enabled status | ||
155 | * | ||
156 | * This function is used by other tracers to know the status | ||
157 | * of the tracer_enabled flag. Tracers may use this function | ||
158 | * to know if it should enable their features when starting | ||
159 | * up. See irqsoff tracer for an example (start_irqsoff_tracer). | ||
160 | */ | ||
161 | int tracing_is_enabled(void) | ||
162 | { | ||
163 | return tracer_enabled; | ||
164 | } | ||
165 | |||
153 | /* function tracing enabled */ | 166 | /* function tracing enabled */ |
154 | int ftrace_function_enabled; | 167 | int ftrace_function_enabled; |
155 | 168 | ||
@@ -1041,8 +1054,7 @@ void tracing_start_function_trace(void) | |||
1041 | trace_ops.func = function_trace_call; | 1054 | trace_ops.func = function_trace_call; |
1042 | 1055 | ||
1043 | register_ftrace_function(&trace_ops); | 1056 | register_ftrace_function(&trace_ops); |
1044 | if (tracer_enabled) | 1057 | ftrace_function_enabled = 1; |
1045 | ftrace_function_enabled = 1; | ||
1046 | } | 1058 | } |
1047 | 1059 | ||
1048 | void tracing_stop_function_trace(void) | 1060 | void tracing_stop_function_trace(void) |
@@ -1189,10 +1201,6 @@ static void *s_start(struct seq_file *m, loff_t *pos) | |||
1189 | 1201 | ||
1190 | atomic_inc(&trace_record_cmdline_disabled); | 1202 | atomic_inc(&trace_record_cmdline_disabled); |
1191 | 1203 | ||
1192 | /* let the tracer grab locks here if needed */ | ||
1193 | if (current_trace->start) | ||
1194 | current_trace->start(iter); | ||
1195 | |||
1196 | if (*pos != iter->pos) { | 1204 | if (*pos != iter->pos) { |
1197 | iter->ent = NULL; | 1205 | iter->ent = NULL; |
1198 | iter->cpu = 0; | 1206 | iter->cpu = 0; |
@@ -1219,14 +1227,7 @@ static void *s_start(struct seq_file *m, loff_t *pos) | |||
1219 | 1227 | ||
1220 | static void s_stop(struct seq_file *m, void *p) | 1228 | static void s_stop(struct seq_file *m, void *p) |
1221 | { | 1229 | { |
1222 | struct trace_iterator *iter = m->private; | ||
1223 | |||
1224 | atomic_dec(&trace_record_cmdline_disabled); | 1230 | atomic_dec(&trace_record_cmdline_disabled); |
1225 | |||
1226 | /* let the tracer release locks here if needed */ | ||
1227 | if (current_trace && current_trace == iter->trace && iter->trace->stop) | ||
1228 | iter->trace->stop(iter); | ||
1229 | |||
1230 | mutex_unlock(&trace_types_lock); | 1231 | mutex_unlock(&trace_types_lock); |
1231 | } | 1232 | } |
1232 | 1233 | ||
@@ -2056,10 +2057,7 @@ __tracing_open(struct inode *inode, struct file *file, int *ret) | |||
2056 | m->private = iter; | 2057 | m->private = iter; |
2057 | 2058 | ||
2058 | /* stop the trace while dumping */ | 2059 | /* stop the trace while dumping */ |
2059 | if (iter->tr->ctrl) { | 2060 | tracing_stop(); |
2060 | tracer_enabled = 0; | ||
2061 | ftrace_function_enabled = 0; | ||
2062 | } | ||
2063 | 2061 | ||
2064 | if (iter->trace && iter->trace->open) | 2062 | if (iter->trace && iter->trace->open) |
2065 | iter->trace->open(iter); | 2063 | iter->trace->open(iter); |
@@ -2104,14 +2102,7 @@ int tracing_release(struct inode *inode, struct file *file) | |||
2104 | iter->trace->close(iter); | 2102 | iter->trace->close(iter); |
2105 | 2103 | ||
2106 | /* reenable tracing if it was previously enabled */ | 2104 | /* reenable tracing if it was previously enabled */ |
2107 | if (iter->tr->ctrl) { | 2105 | tracing_start(); |
2108 | tracer_enabled = 1; | ||
2109 | /* | ||
2110 | * It is safe to enable function tracing even if it | ||
2111 | * isn't used | ||
2112 | */ | ||
2113 | ftrace_function_enabled = 1; | ||
2114 | } | ||
2115 | mutex_unlock(&trace_types_lock); | 2106 | mutex_unlock(&trace_types_lock); |
2116 | 2107 | ||
2117 | seq_release(inode, file); | 2108 | seq_release(inode, file); |
@@ -2449,11 +2440,10 @@ static ssize_t | |||
2449 | tracing_ctrl_read(struct file *filp, char __user *ubuf, | 2440 | tracing_ctrl_read(struct file *filp, char __user *ubuf, |
2450 | size_t cnt, loff_t *ppos) | 2441 | size_t cnt, loff_t *ppos) |
2451 | { | 2442 | { |
2452 | struct trace_array *tr = filp->private_data; | ||
2453 | char buf[64]; | 2443 | char buf[64]; |
2454 | int r; | 2444 | int r; |
2455 | 2445 | ||
2456 | r = sprintf(buf, "%ld\n", tr->ctrl); | 2446 | r = sprintf(buf, "%u\n", tracer_enabled); |
2457 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); | 2447 | return simple_read_from_buffer(ubuf, cnt, ppos, buf, r); |
2458 | } | 2448 | } |
2459 | 2449 | ||
@@ -2481,16 +2471,18 @@ tracing_ctrl_write(struct file *filp, const char __user *ubuf, | |||
2481 | val = !!val; | 2471 | val = !!val; |
2482 | 2472 | ||
2483 | mutex_lock(&trace_types_lock); | 2473 | mutex_lock(&trace_types_lock); |
2484 | if (tr->ctrl ^ val) { | 2474 | if (tracer_enabled ^ val) { |
2485 | if (val) | 2475 | if (val) { |
2486 | tracer_enabled = 1; | 2476 | tracer_enabled = 1; |
2487 | else | 2477 | if (current_trace->start) |
2478 | current_trace->start(tr); | ||
2479 | tracing_start(); | ||
2480 | } else { | ||
2488 | tracer_enabled = 0; | 2481 | tracer_enabled = 0; |
2489 | 2482 | tracing_stop(); | |
2490 | tr->ctrl = val; | 2483 | if (current_trace->stop) |
2491 | 2484 | current_trace->stop(tr); | |
2492 | if (current_trace && current_trace->ctrl_update) | 2485 | } |
2493 | current_trace->ctrl_update(tr); | ||
2494 | } | 2486 | } |
2495 | mutex_unlock(&trace_types_lock); | 2487 | mutex_unlock(&trace_types_lock); |
2496 | 2488 | ||
@@ -3372,7 +3364,7 @@ __init static int tracer_alloc_buffers(void) | |||
3372 | #endif | 3364 | #endif |
3373 | 3365 | ||
3374 | /* All seems OK, enable tracing */ | 3366 | /* All seems OK, enable tracing */ |
3375 | global_trace.ctrl = tracer_enabled; | 3367 | global_trace.ctrl = 1; |
3376 | tracing_disabled = 0; | 3368 | tracing_disabled = 0; |
3377 | 3369 | ||
3378 | atomic_notifier_chain_register(&panic_notifier_list, | 3370 | atomic_notifier_chain_register(&panic_notifier_list, |