diff options
author | Steven Rostedt <srostedt@redhat.com> | 2009-12-11 09:48:22 -0500 |
---|---|---|
committer | Steven Rostedt <rostedt@goodmis.org> | 2009-12-11 10:38:47 -0500 |
commit | 03889384cee7a198a79447c1ea6aca2c8e54d155 (patch) | |
tree | 66794ab12e3196c4bee4d8d020f451e8cc8a1f6d /include/linux | |
parent | dd7f59435782a02ceb6d16b9ce823dd3345d75ec (diff) |
tracing: Add trace_dump_stack()
I've been asked a few times about how to find out what is calling
some location in the kernel. One way is to use dynamic function tracing
and implement the func_stack_trace. But this only finds out who is
calling a particular function. It does not tell you who is calling
that function and entering a specific if conditional.
I have myself implemented a quick version of trace_dump_stack() for
this purpose a few times, and just needed it now. This is when I realized
that this would be a good tool to have in the kernel like trace_printk().
Using trace_dump_stack() is similar to dump_stack() except that it
writes to the trace buffer instead and can be used in critical locations.
For example:
@@ -5485,8 +5485,12 @@ need_resched_nonpreemptible:
if (prev->state && !(preempt_count() & PREEMPT_ACTIVE)) {
if (unlikely(signal_pending_state(prev->state, prev)))
prev->state = TASK_RUNNING;
- else
+ else {
deactivate_task(rq, prev, 1);
+ trace_printk("Deactivating task %s:%d\n",
+ prev->comm, prev->pid);
+ trace_dump_stack();
+ }
switch_count = &prev->nvcsw;
}
Produces:
<...>-3249 [001] 296.105269: schedule: Deactivating task ntpd:3249
<...>-3249 [001] 296.105270: <stack trace>
=> schedule
=> schedule_hrtimeout_range
=> poll_schedule_timeout
=> do_select
=> core_sys_select
=> sys_select
=> system_call_fastpath
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
Diffstat (limited to 'include/linux')
-rw-r--r-- | include/linux/kernel.h | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/include/linux/kernel.h b/include/linux/kernel.h index 3fa4c590cf12..5ad4199fb073 100644 --- a/include/linux/kernel.h +++ b/include/linux/kernel.h | |||
@@ -492,6 +492,8 @@ extern int | |||
492 | __trace_printk(unsigned long ip, const char *fmt, ...) | 492 | __trace_printk(unsigned long ip, const char *fmt, ...) |
493 | __attribute__ ((format (printf, 2, 3))); | 493 | __attribute__ ((format (printf, 2, 3))); |
494 | 494 | ||
495 | extern void trace_dump_stack(void); | ||
496 | |||
495 | /* | 497 | /* |
496 | * The double __builtin_constant_p is because gcc will give us an error | 498 | * The double __builtin_constant_p is because gcc will give us an error |
497 | * if we try to allocate the static variable to fmt if it is not a | 499 | * if we try to allocate the static variable to fmt if it is not a |