2 * kdb helper for dumping the ftrace buffer
4 * Copyright (C) 2010 Jason Wessel <jason.wessel@windriver.com>
6 * ftrace_dump_buf based on ftrace_dump:
7 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
8 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
11 #include <linux/init.h>
12 #include <linux/kgdb.h>
13 #include <linux/kdb.h>
14 #include <linux/ftrace.h>
17 #include "trace_output.h"
19 static void ftrace_dump_buf(int skip_lines
, long cpu_file
)
21 /* use static because iter can be a bit big for the stack */
22 static struct trace_iterator iter
;
23 static struct ring_buffer_iter
*buffer_iter
[CONFIG_NR_CPUS
];
24 unsigned int old_userobj
;
27 trace_init_global_iter(&iter
);
28 iter
.buffer_iter
= buffer_iter
;
30 for_each_tracing_cpu(cpu
) {
31 atomic_inc(&per_cpu_ptr(iter
.trace_buffer
->data
, cpu
)->disabled
);
34 old_userobj
= trace_flags
;
36 /* don't look at user memory in panic mode */
37 trace_flags
&= ~TRACE_ITER_SYM_USEROBJ
;
39 kdb_printf("Dumping ftrace buffer:\n");
41 /* reset all but tr, trace, and overruns */
43 sizeof(struct trace_iterator
) -
44 offsetof(struct trace_iterator
, seq
));
45 iter
.iter_flags
|= TRACE_FILE_LAT_FMT
;
48 if (cpu_file
== RING_BUFFER_ALL_CPUS
) {
49 for_each_tracing_cpu(cpu
) {
50 iter
.buffer_iter
[cpu
] =
51 ring_buffer_read_prepare(iter
.trace_buffer
->buffer
, cpu
);
52 ring_buffer_read_start(iter
.buffer_iter
[cpu
]);
53 tracing_iter_reset(&iter
, cpu
);
56 iter
.cpu_file
= cpu_file
;
57 iter
.buffer_iter
[cpu_file
] =
58 ring_buffer_read_prepare(iter
.trace_buffer
->buffer
, cpu_file
);
59 ring_buffer_read_start(iter
.buffer_iter
[cpu_file
]);
60 tracing_iter_reset(&iter
, cpu_file
);
63 while (trace_find_next_entry_inc(&iter
)) {
65 kdb_printf("---------------------------------\n");
69 print_trace_line(&iter
);
70 trace_printk_seq(&iter
.seq
);
75 if (KDB_FLAG(CMD_INTERRUPT
))
80 kdb_printf(" (ftrace buffer empty)\n");
82 kdb_printf("---------------------------------\n");
85 trace_flags
= old_userobj
;
87 for_each_tracing_cpu(cpu
) {
88 atomic_dec(&per_cpu_ptr(iter
.trace_buffer
->data
, cpu
)->disabled
);
91 for_each_tracing_cpu(cpu
) {
92 if (iter
.buffer_iter
[cpu
]) {
93 ring_buffer_read_finish(iter
.buffer_iter
[cpu
]);
94 iter
.buffer_iter
[cpu
] = NULL
;
100 * kdb_ftdump - Dump the ftrace log buffer
102 static int kdb_ftdump(int argc
, const char **argv
)
112 skip_lines
= simple_strtol(argv
[1], &cp
, 0);
118 cpu_file
= simple_strtol(argv
[2], &cp
, 0);
119 if (*cp
|| cpu_file
>= NR_CPUS
|| cpu_file
< 0 ||
120 !cpu_online(cpu_file
))
123 cpu_file
= RING_BUFFER_ALL_CPUS
;
127 ftrace_dump_buf(skip_lines
, cpu_file
);
133 static __init
int kdb_ftrace_register(void)
135 kdb_register_flags("ftdump", kdb_ftdump
, "[skip_#lines] [cpu]",
136 "Dump ftrace log", 0, KDB_ENABLE_ALWAYS_SAFE
);
140 late_initcall(kdb_ftrace_register
);