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 unsigned int old_userobj;
26 trace_init_global_iter(&iter);
28 for_each_tracing_cpu(cpu) {
29 atomic_inc(&iter.tr->data[cpu]->disabled);
32 old_userobj = trace_flags;
34 /* don't look at user memory in panic mode */
35 trace_flags &= ~TRACE_ITER_SYM_USEROBJ;
37 kdb_printf("Dumping ftrace buffer:\n");
39 /* reset all but tr, trace, and overruns */
41 sizeof(struct trace_iterator) -
42 offsetof(struct trace_iterator, seq));
43 iter.iter_flags |= TRACE_FILE_LAT_FMT;
46 if (cpu_file == TRACE_PIPE_ALL_CPU) {
47 for_each_tracing_cpu(cpu) {
48 iter.buffer_iter[cpu] =
49 ring_buffer_read_prepare(iter.tr->buffer, cpu);
50 ring_buffer_read_start(iter.buffer_iter[cpu]);
51 tracing_iter_reset(&iter, cpu);
54 iter.cpu_file = cpu_file;
55 iter.buffer_iter[cpu_file] =
56 ring_buffer_read_prepare(iter.tr->buffer, cpu_file);
57 ring_buffer_read_start(iter.buffer_iter[cpu_file]);
58 tracing_iter_reset(&iter, cpu_file);
60 if (!trace_empty(&iter))
61 trace_find_next_entry_inc(&iter);
62 while (!trace_empty(&iter)) {
64 kdb_printf("---------------------------------\n");
67 if (trace_find_next_entry_inc(&iter) != NULL && !skip_lines)
68 print_trace_line(&iter);
70 trace_printk_seq(&iter.seq);
73 if (KDB_FLAG(CMD_INTERRUPT))
78 kdb_printf(" (ftrace buffer empty)\n");
80 kdb_printf("---------------------------------\n");
83 trace_flags = old_userobj;
85 for_each_tracing_cpu(cpu) {
86 atomic_dec(&iter.tr->data[cpu]->disabled);
89 for_each_tracing_cpu(cpu)
90 if (iter.buffer_iter[cpu])
91 ring_buffer_read_finish(iter.buffer_iter[cpu]);
95 * kdb_ftdump - Dump the ftrace log buffer
97 static int kdb_ftdump(int argc, const char **argv)
107 skip_lines = simple_strtol(argv[1], &cp, 0);
113 cpu_file = simple_strtol(argv[2], &cp, 0);
114 if (*cp || cpu_file >= NR_CPUS || cpu_file < 0 ||
115 !cpu_online(cpu_file))
118 cpu_file = TRACE_PIPE_ALL_CPU;
122 ftrace_dump_buf(skip_lines, cpu_file);
128 static __init int kdb_ftrace_register(void)
130 kdb_register_repeat("ftdump", kdb_ftdump, "[skip_#lines] [cpu]",
131 "Dump ftrace log", 0, KDB_REPEAT_NONE);
135 late_initcall(kdb_ftrace_register);