Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Function graph tracer. |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 4 | * Copyright (c) 2008-2009 Frederic Weisbecker <fweisbec@gmail.com> |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 5 | * Mostly borrowed from function tracer which |
| 6 | * is Copyright (c) Steven Rostedt <srostedt@redhat.com> |
| 7 | * |
| 8 | */ |
| 9 | #include <linux/debugfs.h> |
| 10 | #include <linux/uaccess.h> |
| 11 | #include <linux/ftrace.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 12 | #include <linux/slab.h> |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 13 | #include <linux/fs.h> |
| 14 | |
| 15 | #include "trace.h" |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 16 | #include "trace_output.h" |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 17 | |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 18 | struct fgraph_cpu_data { |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 19 | pid_t last_pid; |
| 20 | int depth; |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 21 | int ignore; |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 22 | unsigned long enter_funcs[FTRACE_RETFUNC_DEPTH]; |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 23 | }; |
| 24 | |
| 25 | struct fgraph_data { |
| 26 | struct fgraph_cpu_data *cpu_data; |
| 27 | |
| 28 | /* Place to preserve last processed entry. */ |
| 29 | struct ftrace_graph_ent_entry ent; |
| 30 | struct ftrace_graph_ret_entry ret; |
| 31 | int failed; |
| 32 | int cpu; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 33 | }; |
| 34 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 35 | #define TRACE_GRAPH_INDENT 2 |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 36 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 37 | /* Flag options */ |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 38 | #define TRACE_GRAPH_PRINT_OVERRUN 0x1 |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 39 | #define TRACE_GRAPH_PRINT_CPU 0x2 |
| 40 | #define TRACE_GRAPH_PRINT_OVERHEAD 0x4 |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 41 | #define TRACE_GRAPH_PRINT_PROC 0x8 |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 42 | #define TRACE_GRAPH_PRINT_DURATION 0x10 |
Jiri Olsa | 9106b69 | 2010-04-02 19:01:20 +0200 | [diff] [blame] | 43 | #define TRACE_GRAPH_PRINT_ABS_TIME 0x20 |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 44 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 45 | static struct tracer_opt trace_opts[] = { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 46 | /* Display overruns? (for self-debug purpose) */ |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 47 | { TRACER_OPT(funcgraph-overrun, TRACE_GRAPH_PRINT_OVERRUN) }, |
| 48 | /* Display CPU ? */ |
| 49 | { TRACER_OPT(funcgraph-cpu, TRACE_GRAPH_PRINT_CPU) }, |
| 50 | /* Display Overhead ? */ |
| 51 | { TRACER_OPT(funcgraph-overhead, TRACE_GRAPH_PRINT_OVERHEAD) }, |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 52 | /* Display proc name/pid */ |
| 53 | { TRACER_OPT(funcgraph-proc, TRACE_GRAPH_PRINT_PROC) }, |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 54 | /* Display duration of execution */ |
| 55 | { TRACER_OPT(funcgraph-duration, TRACE_GRAPH_PRINT_DURATION) }, |
| 56 | /* Display absolute time of an entry */ |
| 57 | { TRACER_OPT(funcgraph-abstime, TRACE_GRAPH_PRINT_ABS_TIME) }, |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 58 | { } /* Empty entry */ |
| 59 | }; |
| 60 | |
| 61 | static struct tracer_flags tracer_flags = { |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 62 | /* Don't display overruns and proc by default */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 63 | .val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD | |
| 64 | TRACE_GRAPH_PRINT_DURATION, |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 65 | .opts = trace_opts |
| 66 | }; |
| 67 | |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 68 | static struct trace_array *graph_array; |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 69 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 70 | |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 71 | /* Add a function return address to the trace stack on thread info.*/ |
| 72 | int |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 73 | ftrace_push_return_trace(unsigned long ret, unsigned long func, int *depth, |
| 74 | unsigned long frame_pointer) |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 75 | { |
Steven Rostedt | 5d1a03d | 2009-03-23 23:38:49 -0400 | [diff] [blame] | 76 | unsigned long long calltime; |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 77 | int index; |
| 78 | |
| 79 | if (!current->ret_stack) |
| 80 | return -EBUSY; |
| 81 | |
Steven Rostedt | 82310a3 | 2009-06-02 12:26:07 -0400 | [diff] [blame] | 82 | /* |
| 83 | * We must make sure the ret_stack is tested before we read |
| 84 | * anything else. |
| 85 | */ |
| 86 | smp_rmb(); |
| 87 | |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 88 | /* The return trace stack is full */ |
| 89 | if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) { |
| 90 | atomic_inc(¤t->trace_overrun); |
| 91 | return -EBUSY; |
| 92 | } |
| 93 | |
Steven Rostedt | 5d1a03d | 2009-03-23 23:38:49 -0400 | [diff] [blame] | 94 | calltime = trace_clock_local(); |
| 95 | |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 96 | index = ++current->curr_ret_stack; |
| 97 | barrier(); |
| 98 | current->ret_stack[index].ret = ret; |
| 99 | current->ret_stack[index].func = func; |
Steven Rostedt | 5d1a03d | 2009-03-23 23:38:49 -0400 | [diff] [blame] | 100 | current->ret_stack[index].calltime = calltime; |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 101 | current->ret_stack[index].subtime = 0; |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 102 | current->ret_stack[index].fp = frame_pointer; |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 103 | *depth = index; |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | /* Retrieve a function return address to the trace stack on thread info.*/ |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 109 | static void |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 110 | ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret, |
| 111 | unsigned long frame_pointer) |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 112 | { |
| 113 | int index; |
| 114 | |
| 115 | index = current->curr_ret_stack; |
| 116 | |
| 117 | if (unlikely(index < 0)) { |
| 118 | ftrace_graph_stop(); |
| 119 | WARN_ON(1); |
| 120 | /* Might as well panic, otherwise we have no where to go */ |
| 121 | *ret = (unsigned long)panic; |
| 122 | return; |
| 123 | } |
| 124 | |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 125 | #ifdef CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST |
| 126 | /* |
| 127 | * The arch may choose to record the frame pointer used |
| 128 | * and check it here to make sure that it is what we expect it |
| 129 | * to be. If gcc does not set the place holder of the return |
| 130 | * address in the frame pointer, and does a copy instead, then |
| 131 | * the function graph trace will fail. This test detects this |
| 132 | * case. |
| 133 | * |
| 134 | * Currently, x86_32 with optimize for size (-Os) makes the latest |
| 135 | * gcc do the above. |
| 136 | */ |
| 137 | if (unlikely(current->ret_stack[index].fp != frame_pointer)) { |
| 138 | ftrace_graph_stop(); |
| 139 | WARN(1, "Bad frame pointer: expected %lx, received %lx\n" |
Steven Rostedt | b375a11 | 2009-09-17 00:05:58 -0400 | [diff] [blame] | 140 | " from func %ps return to %lx\n", |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 141 | current->ret_stack[index].fp, |
| 142 | frame_pointer, |
| 143 | (void *)current->ret_stack[index].func, |
| 144 | current->ret_stack[index].ret); |
| 145 | *ret = (unsigned long)panic; |
| 146 | return; |
| 147 | } |
| 148 | #endif |
| 149 | |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 150 | *ret = current->ret_stack[index].ret; |
| 151 | trace->func = current->ret_stack[index].func; |
| 152 | trace->calltime = current->ret_stack[index].calltime; |
| 153 | trace->overrun = atomic_read(¤t->trace_overrun); |
| 154 | trace->depth = index; |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | /* |
| 158 | * Send the trace to the ring-buffer. |
| 159 | * @return the original return address. |
| 160 | */ |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 161 | unsigned long ftrace_return_to_handler(unsigned long frame_pointer) |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 162 | { |
| 163 | struct ftrace_graph_ret trace; |
| 164 | unsigned long ret; |
| 165 | |
Steven Rostedt | 71e308a | 2009-06-18 12:45:08 -0400 | [diff] [blame] | 166 | ftrace_pop_return_trace(&trace, &ret, frame_pointer); |
Frederic Weisbecker | 0012693 | 2009-03-05 01:49:22 +0100 | [diff] [blame] | 167 | trace.rettime = trace_clock_local(); |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 168 | ftrace_graph_return(&trace); |
Steven Rostedt | a2a16d6 | 2009-03-24 23:17:58 -0400 | [diff] [blame] | 169 | barrier(); |
| 170 | current->curr_ret_stack--; |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 171 | |
| 172 | if (unlikely(!ret)) { |
| 173 | ftrace_graph_stop(); |
| 174 | WARN_ON(1); |
| 175 | /* Might as well panic. What else to do? */ |
| 176 | ret = (unsigned long)panic; |
| 177 | } |
| 178 | |
| 179 | return ret; |
| 180 | } |
| 181 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 182 | int __trace_graph_entry(struct trace_array *tr, |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 183 | struct ftrace_graph_ent *trace, |
| 184 | unsigned long flags, |
| 185 | int pc) |
| 186 | { |
| 187 | struct ftrace_event_call *call = &event_funcgraph_entry; |
| 188 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 189 | struct ring_buffer *buffer = tr->buffer; |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 190 | struct ftrace_graph_ent_entry *entry; |
| 191 | |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 192 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 193 | return 0; |
| 194 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 195 | event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_ENT, |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 196 | sizeof(*entry), flags, pc); |
| 197 | if (!event) |
| 198 | return 0; |
| 199 | entry = ring_buffer_event_data(event); |
| 200 | entry->graph_ent = *trace; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 201 | if (!filter_current_check_discard(buffer, call, entry, event)) |
| 202 | ring_buffer_unlock_commit(buffer, event); |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 203 | |
| 204 | return 1; |
| 205 | } |
| 206 | |
| 207 | int trace_graph_entry(struct ftrace_graph_ent *trace) |
| 208 | { |
| 209 | struct trace_array *tr = graph_array; |
| 210 | struct trace_array_cpu *data; |
| 211 | unsigned long flags; |
| 212 | long disabled; |
| 213 | int ret; |
| 214 | int cpu; |
| 215 | int pc; |
| 216 | |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 217 | if (!ftrace_trace_task(current)) |
| 218 | return 0; |
| 219 | |
Lai Jiangshan | ea2c68a | 2010-01-13 19:38:30 +0800 | [diff] [blame] | 220 | /* trace it when it is-nested-in or is a function enabled. */ |
| 221 | if (!(trace->depth || ftrace_graph_addr(trace->func))) |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 222 | return 0; |
| 223 | |
| 224 | local_irq_save(flags); |
| 225 | cpu = raw_smp_processor_id(); |
| 226 | data = tr->data[cpu]; |
| 227 | disabled = atomic_inc_return(&data->disabled); |
| 228 | if (likely(disabled == 1)) { |
| 229 | pc = preempt_count(); |
| 230 | ret = __trace_graph_entry(tr, trace, flags, pc); |
| 231 | } else { |
| 232 | ret = 0; |
| 233 | } |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 234 | |
| 235 | atomic_dec(&data->disabled); |
| 236 | local_irq_restore(flags); |
| 237 | |
| 238 | return ret; |
| 239 | } |
| 240 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 241 | int trace_graph_thresh_entry(struct ftrace_graph_ent *trace) |
| 242 | { |
| 243 | if (tracing_thresh) |
| 244 | return 1; |
| 245 | else |
| 246 | return trace_graph_entry(trace); |
| 247 | } |
| 248 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 249 | void __trace_graph_return(struct trace_array *tr, |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 250 | struct ftrace_graph_ret *trace, |
| 251 | unsigned long flags, |
| 252 | int pc) |
| 253 | { |
| 254 | struct ftrace_event_call *call = &event_funcgraph_exit; |
| 255 | struct ring_buffer_event *event; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 256 | struct ring_buffer *buffer = tr->buffer; |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 257 | struct ftrace_graph_ret_entry *entry; |
| 258 | |
Rusty Russell | dd17c8f | 2009-10-29 22:34:15 +0900 | [diff] [blame] | 259 | if (unlikely(__this_cpu_read(ftrace_cpu_disabled))) |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 260 | return; |
| 261 | |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 262 | event = trace_buffer_lock_reserve(buffer, TRACE_GRAPH_RET, |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 263 | sizeof(*entry), flags, pc); |
| 264 | if (!event) |
| 265 | return; |
| 266 | entry = ring_buffer_event_data(event); |
| 267 | entry->ret = *trace; |
Steven Rostedt | e77405a | 2009-09-02 14:17:06 -0400 | [diff] [blame] | 268 | if (!filter_current_check_discard(buffer, call, entry, event)) |
| 269 | ring_buffer_unlock_commit(buffer, event); |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 270 | } |
| 271 | |
| 272 | void trace_graph_return(struct ftrace_graph_ret *trace) |
| 273 | { |
| 274 | struct trace_array *tr = graph_array; |
| 275 | struct trace_array_cpu *data; |
| 276 | unsigned long flags; |
| 277 | long disabled; |
| 278 | int cpu; |
| 279 | int pc; |
| 280 | |
| 281 | local_irq_save(flags); |
| 282 | cpu = raw_smp_processor_id(); |
| 283 | data = tr->data[cpu]; |
| 284 | disabled = atomic_inc_return(&data->disabled); |
| 285 | if (likely(disabled == 1)) { |
| 286 | pc = preempt_count(); |
| 287 | __trace_graph_return(tr, trace, flags, pc); |
| 288 | } |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 289 | atomic_dec(&data->disabled); |
| 290 | local_irq_restore(flags); |
| 291 | } |
| 292 | |
Frederic Weisbecker | 24a5365 | 2010-01-14 08:23:15 +0100 | [diff] [blame] | 293 | void set_graph_array(struct trace_array *tr) |
| 294 | { |
| 295 | graph_array = tr; |
| 296 | |
| 297 | /* Make graph_array visible before we start tracing */ |
| 298 | |
| 299 | smp_mb(); |
| 300 | } |
| 301 | |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 302 | void trace_graph_thresh_return(struct ftrace_graph_ret *trace) |
| 303 | { |
| 304 | if (tracing_thresh && |
| 305 | (trace->rettime - trace->calltime < tracing_thresh)) |
| 306 | return; |
| 307 | else |
| 308 | trace_graph_return(trace); |
| 309 | } |
| 310 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 311 | static int graph_trace_init(struct trace_array *tr) |
| 312 | { |
Frederic Weisbecker | 1a0799a | 2009-07-29 18:59:58 +0200 | [diff] [blame] | 313 | int ret; |
| 314 | |
Frederic Weisbecker | 24a5365 | 2010-01-14 08:23:15 +0100 | [diff] [blame] | 315 | set_graph_array(tr); |
Tim Bird | 0e95017 | 2010-02-25 15:36:43 -0800 | [diff] [blame] | 316 | if (tracing_thresh) |
| 317 | ret = register_ftrace_graph(&trace_graph_thresh_return, |
| 318 | &trace_graph_thresh_entry); |
| 319 | else |
| 320 | ret = register_ftrace_graph(&trace_graph_return, |
| 321 | &trace_graph_entry); |
Steven Rostedt | 660c7f9 | 2008-11-26 00:16:26 -0500 | [diff] [blame] | 322 | if (ret) |
| 323 | return ret; |
| 324 | tracing_start_cmdline_record(); |
| 325 | |
| 326 | return 0; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | static void graph_trace_reset(struct trace_array *tr) |
| 330 | { |
Steven Rostedt | 660c7f9 | 2008-11-26 00:16:26 -0500 | [diff] [blame] | 331 | tracing_stop_cmdline_record(); |
| 332 | unregister_ftrace_graph(); |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 333 | } |
| 334 | |
Lai Jiangshan | 0c9e6f6 | 2009-07-28 20:26:06 +0800 | [diff] [blame] | 335 | static int max_bytes_for_cpu; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 336 | |
| 337 | static enum print_line_t |
| 338 | print_graph_cpu(struct trace_seq *s, int cpu) |
| 339 | { |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 340 | int ret; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 341 | |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 342 | /* |
| 343 | * Start with a space character - to make it stand out |
| 344 | * to the right a bit when trace output is pasted into |
| 345 | * email: |
| 346 | */ |
Lai Jiangshan | 0c9e6f6 | 2009-07-28 20:26:06 +0800 | [diff] [blame] | 347 | ret = trace_seq_printf(s, " %*d) ", max_bytes_for_cpu, cpu); |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 348 | if (!ret) |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 349 | return TRACE_TYPE_PARTIAL_LINE; |
| 350 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 351 | return TRACE_TYPE_HANDLED; |
| 352 | } |
| 353 | |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 354 | #define TRACE_GRAPH_PROCINFO_LENGTH 14 |
| 355 | |
| 356 | static enum print_line_t |
| 357 | print_graph_proc(struct trace_seq *s, pid_t pid) |
| 358 | { |
Steven Rostedt | 4ca5308 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 359 | char comm[TASK_COMM_LEN]; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 360 | /* sign + log10(MAX_INT) + '\0' */ |
| 361 | char pid_str[11]; |
Steven Rostedt | 4ca5308 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 362 | int spaces = 0; |
| 363 | int ret; |
| 364 | int len; |
| 365 | int i; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 366 | |
Steven Rostedt | 4ca5308 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 367 | trace_find_cmdline(pid, comm); |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 368 | comm[7] = '\0'; |
| 369 | sprintf(pid_str, "%d", pid); |
| 370 | |
| 371 | /* 1 stands for the "-" character */ |
| 372 | len = strlen(comm) + strlen(pid_str) + 1; |
| 373 | |
| 374 | if (len < TRACE_GRAPH_PROCINFO_LENGTH) |
| 375 | spaces = TRACE_GRAPH_PROCINFO_LENGTH - len; |
| 376 | |
| 377 | /* First spaces to align center */ |
| 378 | for (i = 0; i < spaces / 2; i++) { |
| 379 | ret = trace_seq_printf(s, " "); |
| 380 | if (!ret) |
| 381 | return TRACE_TYPE_PARTIAL_LINE; |
| 382 | } |
| 383 | |
| 384 | ret = trace_seq_printf(s, "%s-%s", comm, pid_str); |
| 385 | if (!ret) |
| 386 | return TRACE_TYPE_PARTIAL_LINE; |
| 387 | |
| 388 | /* Last spaces to align center */ |
| 389 | for (i = 0; i < spaces - (spaces / 2); i++) { |
| 390 | ret = trace_seq_printf(s, " "); |
| 391 | if (!ret) |
| 392 | return TRACE_TYPE_PARTIAL_LINE; |
| 393 | } |
| 394 | return TRACE_TYPE_HANDLED; |
| 395 | } |
| 396 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 397 | |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 398 | static enum print_line_t |
| 399 | print_graph_lat_fmt(struct trace_seq *s, struct trace_entry *entry) |
| 400 | { |
Steven Rostedt | f81c972 | 2009-09-11 14:24:13 -0400 | [diff] [blame] | 401 | if (!trace_seq_putc(s, ' ')) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 402 | return 0; |
| 403 | |
Steven Rostedt | f81c972 | 2009-09-11 14:24:13 -0400 | [diff] [blame] | 404 | return trace_print_lat_fmt(s, entry); |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 405 | } |
| 406 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 407 | /* If the pid changed since the last trace, output this event */ |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 408 | static enum print_line_t |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 409 | verif_pid(struct trace_seq *s, pid_t pid, int cpu, struct fgraph_data *data) |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 410 | { |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 411 | pid_t prev_pid; |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 412 | pid_t *last_pid; |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 413 | int ret; |
Steven Rostedt | 660c7f9 | 2008-11-26 00:16:26 -0500 | [diff] [blame] | 414 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 415 | if (!data) |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 416 | return TRACE_TYPE_HANDLED; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 417 | |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 418 | last_pid = &(per_cpu_ptr(data->cpu_data, cpu)->last_pid); |
Steven Rostedt | 660c7f9 | 2008-11-26 00:16:26 -0500 | [diff] [blame] | 419 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 420 | if (*last_pid == pid) |
| 421 | return TRACE_TYPE_HANDLED; |
| 422 | |
| 423 | prev_pid = *last_pid; |
| 424 | *last_pid = pid; |
| 425 | |
| 426 | if (prev_pid == -1) |
| 427 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 428 | /* |
| 429 | * Context-switch trace line: |
| 430 | |
| 431 | ------------------------------------------ |
| 432 | | 1) migration/0--1 => sshd-1755 |
| 433 | ------------------------------------------ |
| 434 | |
| 435 | */ |
| 436 | ret = trace_seq_printf(s, |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 437 | " ------------------------------------------\n"); |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 438 | if (!ret) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 439 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 440 | |
| 441 | ret = print_graph_cpu(s, cpu); |
| 442 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 443 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 444 | |
| 445 | ret = print_graph_proc(s, prev_pid); |
| 446 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 447 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 448 | |
| 449 | ret = trace_seq_printf(s, " => "); |
| 450 | if (!ret) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 451 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 452 | |
| 453 | ret = print_graph_proc(s, pid); |
| 454 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 455 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 456 | |
| 457 | ret = trace_seq_printf(s, |
| 458 | "\n ------------------------------------------\n\n"); |
| 459 | if (!ret) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 460 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 461 | |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 462 | return TRACE_TYPE_HANDLED; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 463 | } |
| 464 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 465 | static struct ftrace_graph_ret_entry * |
| 466 | get_return_for_leaf(struct trace_iterator *iter, |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 467 | struct ftrace_graph_ent_entry *curr) |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 468 | { |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 469 | struct fgraph_data *data = iter->private; |
| 470 | struct ring_buffer_iter *ring_iter = NULL; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 471 | struct ring_buffer_event *event; |
| 472 | struct ftrace_graph_ret_entry *next; |
| 473 | |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 474 | /* |
| 475 | * If the previous output failed to write to the seq buffer, |
| 476 | * then we just reuse the data from before. |
| 477 | */ |
| 478 | if (data && data->failed) { |
| 479 | curr = &data->ent; |
| 480 | next = &data->ret; |
| 481 | } else { |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 482 | |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 483 | ring_iter = iter->buffer_iter[iter->cpu]; |
| 484 | |
| 485 | /* First peek to compare current entry and the next one */ |
| 486 | if (ring_iter) |
| 487 | event = ring_buffer_iter_peek(ring_iter, NULL); |
| 488 | else { |
| 489 | /* |
| 490 | * We need to consume the current entry to see |
| 491 | * the next one. |
| 492 | */ |
Steven Rostedt | 66a8cb9 | 2010-03-31 13:21:56 -0400 | [diff] [blame] | 493 | ring_buffer_consume(iter->tr->buffer, iter->cpu, |
| 494 | NULL, NULL); |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 495 | event = ring_buffer_peek(iter->tr->buffer, iter->cpu, |
Steven Rostedt | 66a8cb9 | 2010-03-31 13:21:56 -0400 | [diff] [blame] | 496 | NULL, NULL); |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | if (!event) |
| 500 | return NULL; |
| 501 | |
| 502 | next = ring_buffer_event_data(event); |
| 503 | |
| 504 | if (data) { |
| 505 | /* |
| 506 | * Save current and next entries for later reference |
| 507 | * if the output fails. |
| 508 | */ |
| 509 | data->ent = *curr; |
| 510 | data->ret = *next; |
| 511 | } |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 512 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 513 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 514 | if (next->ent.type != TRACE_GRAPH_RET) |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 515 | return NULL; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 516 | |
| 517 | if (curr->ent.pid != next->ent.pid || |
| 518 | curr->graph_ent.func != next->ret.func) |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 519 | return NULL; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 520 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 521 | /* this is a leaf, now advance the iterator */ |
| 522 | if (ring_iter) |
| 523 | ring_buffer_read(ring_iter, NULL); |
| 524 | |
| 525 | return next; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 526 | } |
| 527 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 528 | /* Signal a overhead of time execution to the output */ |
| 529 | static int |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 530 | print_graph_overhead(unsigned long long duration, struct trace_seq *s, |
| 531 | u32 flags) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 532 | { |
| 533 | /* If duration disappear, we don't need anything */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 534 | if (!(flags & TRACE_GRAPH_PRINT_DURATION)) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 535 | return 1; |
| 536 | |
| 537 | /* Non nested entry or return */ |
| 538 | if (duration == -1) |
| 539 | return trace_seq_printf(s, " "); |
| 540 | |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 541 | if (flags & TRACE_GRAPH_PRINT_OVERHEAD) { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 542 | /* Duration exceeded 100 msecs */ |
| 543 | if (duration > 100000ULL) |
| 544 | return trace_seq_printf(s, "! "); |
| 545 | |
| 546 | /* Duration exceeded 10 msecs */ |
| 547 | if (duration > 10000ULL) |
| 548 | return trace_seq_printf(s, "+ "); |
| 549 | } |
| 550 | |
| 551 | return trace_seq_printf(s, " "); |
| 552 | } |
| 553 | |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 554 | static int print_graph_abs_time(u64 t, struct trace_seq *s) |
| 555 | { |
| 556 | unsigned long usecs_rem; |
| 557 | |
| 558 | usecs_rem = do_div(t, NSEC_PER_SEC); |
| 559 | usecs_rem /= 1000; |
| 560 | |
| 561 | return trace_seq_printf(s, "%5lu.%06lu | ", |
| 562 | (unsigned long)t, usecs_rem); |
| 563 | } |
| 564 | |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 565 | static enum print_line_t |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 566 | print_graph_irq(struct trace_iterator *iter, unsigned long addr, |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 567 | enum trace_type type, int cpu, pid_t pid, u32 flags) |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 568 | { |
| 569 | int ret; |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 570 | struct trace_seq *s = &iter->seq; |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 571 | |
| 572 | if (addr < (unsigned long)__irqentry_text_start || |
| 573 | addr >= (unsigned long)__irqentry_text_end) |
| 574 | return TRACE_TYPE_UNHANDLED; |
| 575 | |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 576 | /* Absolute time */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 577 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) { |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 578 | ret = print_graph_abs_time(iter->ts, s); |
| 579 | if (!ret) |
| 580 | return TRACE_TYPE_PARTIAL_LINE; |
| 581 | } |
| 582 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 583 | /* Cpu */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 584 | if (flags & TRACE_GRAPH_PRINT_CPU) { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 585 | ret = print_graph_cpu(s, cpu); |
| 586 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 587 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 588 | } |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 589 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 590 | /* Proc */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 591 | if (flags & TRACE_GRAPH_PRINT_PROC) { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 592 | ret = print_graph_proc(s, pid); |
| 593 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 594 | return TRACE_TYPE_PARTIAL_LINE; |
| 595 | ret = trace_seq_printf(s, " | "); |
| 596 | if (!ret) |
| 597 | return TRACE_TYPE_PARTIAL_LINE; |
| 598 | } |
| 599 | |
| 600 | /* No overhead */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 601 | ret = print_graph_overhead(-1, s, flags); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 602 | if (!ret) |
| 603 | return TRACE_TYPE_PARTIAL_LINE; |
| 604 | |
| 605 | if (type == TRACE_GRAPH_ENT) |
| 606 | ret = trace_seq_printf(s, "==========>"); |
| 607 | else |
| 608 | ret = trace_seq_printf(s, "<=========="); |
| 609 | |
| 610 | if (!ret) |
| 611 | return TRACE_TYPE_PARTIAL_LINE; |
| 612 | |
| 613 | /* Don't close the duration column if haven't one */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 614 | if (flags & TRACE_GRAPH_PRINT_DURATION) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 615 | trace_seq_printf(s, " |"); |
| 616 | ret = trace_seq_printf(s, "\n"); |
| 617 | |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 618 | if (!ret) |
| 619 | return TRACE_TYPE_PARTIAL_LINE; |
| 620 | return TRACE_TYPE_HANDLED; |
| 621 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 622 | |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 623 | enum print_line_t |
| 624 | trace_print_graph_duration(unsigned long long duration, struct trace_seq *s) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 625 | { |
| 626 | unsigned long nsecs_rem = do_div(duration, 1000); |
Frederic Weisbecker | 166d3c7 | 2008-12-03 02:32:12 +0100 | [diff] [blame] | 627 | /* log10(ULONG_MAX) + '\0' */ |
| 628 | char msecs_str[21]; |
| 629 | char nsecs_str[5]; |
| 630 | int ret, len; |
| 631 | int i; |
| 632 | |
| 633 | sprintf(msecs_str, "%lu", (unsigned long) duration); |
| 634 | |
| 635 | /* Print msecs */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 636 | ret = trace_seq_printf(s, "%s", msecs_str); |
Frederic Weisbecker | 166d3c7 | 2008-12-03 02:32:12 +0100 | [diff] [blame] | 637 | if (!ret) |
| 638 | return TRACE_TYPE_PARTIAL_LINE; |
| 639 | |
| 640 | len = strlen(msecs_str); |
| 641 | |
| 642 | /* Print nsecs (we don't want to exceed 7 numbers) */ |
| 643 | if (len < 7) { |
Chase Douglas | d62f85d | 2010-06-15 12:29:15 -0400 | [diff] [blame] | 644 | snprintf(nsecs_str, min(sizeof(nsecs_str), 8UL - len), "%03lu", |
| 645 | nsecs_rem); |
Frederic Weisbecker | 166d3c7 | 2008-12-03 02:32:12 +0100 | [diff] [blame] | 646 | ret = trace_seq_printf(s, ".%s", nsecs_str); |
| 647 | if (!ret) |
| 648 | return TRACE_TYPE_PARTIAL_LINE; |
| 649 | len += strlen(nsecs_str); |
| 650 | } |
| 651 | |
| 652 | ret = trace_seq_printf(s, " us "); |
| 653 | if (!ret) |
| 654 | return TRACE_TYPE_PARTIAL_LINE; |
| 655 | |
| 656 | /* Print remaining spaces to fit the row's width */ |
| 657 | for (i = len; i < 7; i++) { |
| 658 | ret = trace_seq_printf(s, " "); |
| 659 | if (!ret) |
| 660 | return TRACE_TYPE_PARTIAL_LINE; |
| 661 | } |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 662 | return TRACE_TYPE_HANDLED; |
| 663 | } |
| 664 | |
| 665 | static enum print_line_t |
| 666 | print_graph_duration(unsigned long long duration, struct trace_seq *s) |
| 667 | { |
| 668 | int ret; |
| 669 | |
| 670 | ret = trace_print_graph_duration(duration, s); |
| 671 | if (ret != TRACE_TYPE_HANDLED) |
| 672 | return ret; |
Frederic Weisbecker | 166d3c7 | 2008-12-03 02:32:12 +0100 | [diff] [blame] | 673 | |
| 674 | ret = trace_seq_printf(s, "| "); |
| 675 | if (!ret) |
| 676 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 166d3c7 | 2008-12-03 02:32:12 +0100 | [diff] [blame] | 677 | |
Steven Rostedt | 0706f1c | 2009-03-23 23:12:58 -0400 | [diff] [blame] | 678 | return TRACE_TYPE_HANDLED; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 679 | } |
| 680 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 681 | /* Case of a leaf function on its call entry */ |
| 682 | static enum print_line_t |
| 683 | print_graph_entry_leaf(struct trace_iterator *iter, |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 684 | struct ftrace_graph_ent_entry *entry, |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 685 | struct ftrace_graph_ret_entry *ret_entry, |
| 686 | struct trace_seq *s, u32 flags) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 687 | { |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 688 | struct fgraph_data *data = iter->private; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 689 | struct ftrace_graph_ret *graph_ret; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 690 | struct ftrace_graph_ent *call; |
| 691 | unsigned long long duration; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 692 | int ret; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 693 | int i; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 694 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 695 | graph_ret = &ret_entry->ret; |
| 696 | call = &entry->graph_ent; |
| 697 | duration = graph_ret->rettime - graph_ret->calltime; |
Steven Rostedt | 437f24fb | 2008-11-26 00:16:27 -0500 | [diff] [blame] | 698 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 699 | if (data) { |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 700 | struct fgraph_cpu_data *cpu_data; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 701 | int cpu = iter->cpu; |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 702 | |
| 703 | cpu_data = per_cpu_ptr(data->cpu_data, cpu); |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 704 | |
| 705 | /* |
| 706 | * Comments display at + 1 to depth. Since |
| 707 | * this is a leaf function, keep the comments |
| 708 | * equal to this depth. |
| 709 | */ |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 710 | cpu_data->depth = call->depth - 1; |
| 711 | |
| 712 | /* No need to keep this function around for this depth */ |
| 713 | if (call->depth < FTRACE_RETFUNC_DEPTH) |
| 714 | cpu_data->enter_funcs[call->depth] = 0; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 715 | } |
| 716 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 717 | /* Overhead */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 718 | ret = print_graph_overhead(duration, s, flags); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 719 | if (!ret) |
| 720 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 721 | |
| 722 | /* Duration */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 723 | if (flags & TRACE_GRAPH_PRINT_DURATION) { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 724 | ret = print_graph_duration(duration, s); |
| 725 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 726 | return TRACE_TYPE_PARTIAL_LINE; |
| 727 | } |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 728 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 729 | /* Function */ |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 730 | for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) { |
| 731 | ret = trace_seq_printf(s, " "); |
| 732 | if (!ret) |
| 733 | return TRACE_TYPE_PARTIAL_LINE; |
| 734 | } |
| 735 | |
Steven Rostedt | b375a11 | 2009-09-17 00:05:58 -0400 | [diff] [blame] | 736 | ret = trace_seq_printf(s, "%ps();\n", (void *)call->func); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 737 | if (!ret) |
| 738 | return TRACE_TYPE_PARTIAL_LINE; |
| 739 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 740 | return TRACE_TYPE_HANDLED; |
| 741 | } |
| 742 | |
| 743 | static enum print_line_t |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 744 | print_graph_entry_nested(struct trace_iterator *iter, |
| 745 | struct ftrace_graph_ent_entry *entry, |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 746 | struct trace_seq *s, int cpu, u32 flags) |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 747 | { |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 748 | struct ftrace_graph_ent *call = &entry->graph_ent; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 749 | struct fgraph_data *data = iter->private; |
| 750 | int ret; |
| 751 | int i; |
| 752 | |
| 753 | if (data) { |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 754 | struct fgraph_cpu_data *cpu_data; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 755 | int cpu = iter->cpu; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 756 | |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 757 | cpu_data = per_cpu_ptr(data->cpu_data, cpu); |
| 758 | cpu_data->depth = call->depth; |
| 759 | |
| 760 | /* Save this function pointer to see if the exit matches */ |
| 761 | if (call->depth < FTRACE_RETFUNC_DEPTH) |
| 762 | cpu_data->enter_funcs[call->depth] = call->func; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 763 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 764 | |
| 765 | /* No overhead */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 766 | ret = print_graph_overhead(-1, s, flags); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 767 | if (!ret) |
| 768 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 769 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 770 | /* No time */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 771 | if (flags & TRACE_GRAPH_PRINT_DURATION) { |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 772 | ret = trace_seq_printf(s, " | "); |
| 773 | if (!ret) |
| 774 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 775 | } |
| 776 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 777 | /* Function */ |
| 778 | for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) { |
| 779 | ret = trace_seq_printf(s, " "); |
| 780 | if (!ret) |
| 781 | return TRACE_TYPE_PARTIAL_LINE; |
| 782 | } |
| 783 | |
Steven Rostedt | b375a11 | 2009-09-17 00:05:58 -0400 | [diff] [blame] | 784 | ret = trace_seq_printf(s, "%ps() {\n", (void *)call->func); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 785 | if (!ret) |
| 786 | return TRACE_TYPE_PARTIAL_LINE; |
| 787 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 788 | /* |
| 789 | * we already consumed the current entry to check the next one |
| 790 | * and see if this is a leaf. |
| 791 | */ |
| 792 | return TRACE_TYPE_NO_CONSUME; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | static enum print_line_t |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 796 | print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s, |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 797 | int type, unsigned long addr, u32 flags) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 798 | { |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 799 | struct fgraph_data *data = iter->private; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 800 | struct trace_entry *ent = iter->ent; |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 801 | int cpu = iter->cpu; |
| 802 | int ret; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 803 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 804 | /* Pid */ |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 805 | if (verif_pid(s, ent->pid, cpu, data) == TRACE_TYPE_PARTIAL_LINE) |
Steven Rostedt | 437f24fb | 2008-11-26 00:16:27 -0500 | [diff] [blame] | 806 | return TRACE_TYPE_PARTIAL_LINE; |
| 807 | |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 808 | if (type) { |
| 809 | /* Interrupt */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 810 | ret = print_graph_irq(iter, addr, type, cpu, ent->pid, flags); |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 811 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 812 | return TRACE_TYPE_PARTIAL_LINE; |
| 813 | } |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 814 | |
| 815 | /* Absolute time */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 816 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 817 | ret = print_graph_abs_time(iter->ts, s); |
| 818 | if (!ret) |
| 819 | return TRACE_TYPE_PARTIAL_LINE; |
| 820 | } |
| 821 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 822 | /* Cpu */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 823 | if (flags & TRACE_GRAPH_PRINT_CPU) { |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 824 | ret = print_graph_cpu(s, cpu); |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 825 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 826 | return TRACE_TYPE_PARTIAL_LINE; |
| 827 | } |
| 828 | |
| 829 | /* Proc */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 830 | if (flags & TRACE_GRAPH_PRINT_PROC) { |
Ingo Molnar | 00a8bf8 | 2009-02-19 13:01:37 +0100 | [diff] [blame] | 831 | ret = print_graph_proc(s, ent->pid); |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 832 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 833 | return TRACE_TYPE_PARTIAL_LINE; |
| 834 | |
| 835 | ret = trace_seq_printf(s, " | "); |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 836 | if (!ret) |
| 837 | return TRACE_TYPE_PARTIAL_LINE; |
| 838 | } |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 839 | |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 840 | /* Latency format */ |
| 841 | if (trace_flags & TRACE_ITER_LATENCY_FMT) { |
| 842 | ret = print_graph_lat_fmt(s, ent); |
| 843 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 844 | return TRACE_TYPE_PARTIAL_LINE; |
| 845 | } |
| 846 | |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 847 | return 0; |
| 848 | } |
| 849 | |
| 850 | static enum print_line_t |
| 851 | print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 852 | struct trace_iterator *iter, u32 flags) |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 853 | { |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 854 | struct fgraph_data *data = iter->private; |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 855 | struct ftrace_graph_ent *call = &field->graph_ent; |
| 856 | struct ftrace_graph_ret_entry *leaf_ret; |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 857 | static enum print_line_t ret; |
| 858 | int cpu = iter->cpu; |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 859 | |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 860 | if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func, flags)) |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 861 | return TRACE_TYPE_PARTIAL_LINE; |
| 862 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 863 | leaf_ret = get_return_for_leaf(iter, field); |
| 864 | if (leaf_ret) |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 865 | ret = print_graph_entry_leaf(iter, field, leaf_ret, s, flags); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 866 | else |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 867 | ret = print_graph_entry_nested(iter, field, s, cpu, flags); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 868 | |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 869 | if (data) { |
| 870 | /* |
| 871 | * If we failed to write our output, then we need to make |
| 872 | * note of it. Because we already consumed our entry. |
| 873 | */ |
| 874 | if (s->full) { |
| 875 | data->failed = 1; |
| 876 | data->cpu = cpu; |
| 877 | } else |
| 878 | data->failed = 0; |
| 879 | } |
| 880 | |
| 881 | return ret; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 882 | } |
| 883 | |
| 884 | static enum print_line_t |
| 885 | print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 886 | struct trace_entry *ent, struct trace_iterator *iter, |
| 887 | u32 flags) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 888 | { |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 889 | unsigned long long duration = trace->rettime - trace->calltime; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 890 | struct fgraph_data *data = iter->private; |
| 891 | pid_t pid = ent->pid; |
| 892 | int cpu = iter->cpu; |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 893 | int func_match = 1; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 894 | int ret; |
| 895 | int i; |
| 896 | |
| 897 | if (data) { |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 898 | struct fgraph_cpu_data *cpu_data; |
| 899 | int cpu = iter->cpu; |
| 900 | |
| 901 | cpu_data = per_cpu_ptr(data->cpu_data, cpu); |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 902 | |
| 903 | /* |
| 904 | * Comments display at + 1 to depth. This is the |
| 905 | * return from a function, we now want the comments |
| 906 | * to display at the same level of the bracket. |
| 907 | */ |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 908 | cpu_data->depth = trace->depth - 1; |
| 909 | |
| 910 | if (trace->depth < FTRACE_RETFUNC_DEPTH) { |
| 911 | if (cpu_data->enter_funcs[trace->depth] != trace->func) |
| 912 | func_match = 0; |
| 913 | cpu_data->enter_funcs[trace->depth] = 0; |
| 914 | } |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 915 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 916 | |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 917 | if (print_graph_prologue(iter, s, 0, 0, flags)) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 918 | return TRACE_TYPE_PARTIAL_LINE; |
| 919 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 920 | /* Overhead */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 921 | ret = print_graph_overhead(duration, s, flags); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 922 | if (!ret) |
| 923 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 924 | |
| 925 | /* Duration */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 926 | if (flags & TRACE_GRAPH_PRINT_DURATION) { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 927 | ret = print_graph_duration(duration, s); |
| 928 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 929 | return TRACE_TYPE_PARTIAL_LINE; |
| 930 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 931 | |
| 932 | /* Closing brace */ |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 933 | for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++) { |
| 934 | ret = trace_seq_printf(s, " "); |
| 935 | if (!ret) |
| 936 | return TRACE_TYPE_PARTIAL_LINE; |
| 937 | } |
| 938 | |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 939 | /* |
| 940 | * If the return function does not have a matching entry, |
| 941 | * then the entry was lost. Instead of just printing |
| 942 | * the '}' and letting the user guess what function this |
| 943 | * belongs to, write out the function name. |
| 944 | */ |
| 945 | if (func_match) { |
| 946 | ret = trace_seq_printf(s, "}\n"); |
| 947 | if (!ret) |
| 948 | return TRACE_TYPE_PARTIAL_LINE; |
| 949 | } else { |
Steven Rostedt | a094fe0 | 2010-03-05 20:08:58 -0500 | [diff] [blame] | 950 | ret = trace_seq_printf(s, "} /* %ps */\n", (void *)trace->func); |
Steven Rostedt | f1c7f51 | 2010-02-26 17:08:16 -0500 | [diff] [blame] | 951 | if (!ret) |
| 952 | return TRACE_TYPE_PARTIAL_LINE; |
| 953 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 954 | |
| 955 | /* Overrun */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 956 | if (flags & TRACE_GRAPH_PRINT_OVERRUN) { |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 957 | ret = trace_seq_printf(s, " (Overruns: %lu)\n", |
| 958 | trace->overrun); |
| 959 | if (!ret) |
| 960 | return TRACE_TYPE_PARTIAL_LINE; |
| 961 | } |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 962 | |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 963 | ret = print_graph_irq(iter, trace->func, TRACE_GRAPH_RET, |
| 964 | cpu, pid, flags); |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 965 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 966 | return TRACE_TYPE_PARTIAL_LINE; |
| 967 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 968 | return TRACE_TYPE_HANDLED; |
| 969 | } |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 970 | |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 971 | static enum print_line_t |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 972 | print_graph_comment(struct trace_seq *s, struct trace_entry *ent, |
| 973 | struct trace_iterator *iter, u32 flags) |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 974 | { |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame] | 975 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 976 | struct fgraph_data *data = iter->private; |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame] | 977 | struct trace_event *event; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 978 | int depth = 0; |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 979 | int ret; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 980 | int i; |
| 981 | |
| 982 | if (data) |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 983 | depth = per_cpu_ptr(data->cpu_data, iter->cpu)->depth; |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 984 | |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 985 | if (print_graph_prologue(iter, s, 0, 0, flags)) |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 986 | return TRACE_TYPE_PARTIAL_LINE; |
| 987 | |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 988 | /* No overhead */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 989 | ret = print_graph_overhead(-1, s, flags); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 990 | if (!ret) |
| 991 | return TRACE_TYPE_PARTIAL_LINE; |
| 992 | |
| 993 | /* No time */ |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 994 | if (flags & TRACE_GRAPH_PRINT_DURATION) { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 995 | ret = trace_seq_printf(s, " | "); |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 996 | if (!ret) |
| 997 | return TRACE_TYPE_PARTIAL_LINE; |
| 998 | } |
| 999 | |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 1000 | /* Indentation */ |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 1001 | if (depth > 0) |
| 1002 | for (i = 0; i < (depth + 1) * TRACE_GRAPH_INDENT; i++) { |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 1003 | ret = trace_seq_printf(s, " "); |
| 1004 | if (!ret) |
| 1005 | return TRACE_TYPE_PARTIAL_LINE; |
| 1006 | } |
| 1007 | |
| 1008 | /* The comment */ |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 1009 | ret = trace_seq_printf(s, "/* "); |
| 1010 | if (!ret) |
| 1011 | return TRACE_TYPE_PARTIAL_LINE; |
| 1012 | |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame] | 1013 | switch (iter->ent->type) { |
| 1014 | case TRACE_BPRINT: |
| 1015 | ret = trace_print_bprintk_msg_only(iter); |
| 1016 | if (ret != TRACE_TYPE_HANDLED) |
| 1017 | return ret; |
| 1018 | break; |
| 1019 | case TRACE_PRINT: |
| 1020 | ret = trace_print_printk_msg_only(iter); |
| 1021 | if (ret != TRACE_TYPE_HANDLED) |
| 1022 | return ret; |
| 1023 | break; |
| 1024 | default: |
| 1025 | event = ftrace_find_event(ent->type); |
| 1026 | if (!event) |
| 1027 | return TRACE_TYPE_UNHANDLED; |
| 1028 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1029 | ret = event->funcs->trace(iter, sym_flags, event); |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame] | 1030 | if (ret != TRACE_TYPE_HANDLED) |
| 1031 | return ret; |
| 1032 | } |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 1033 | |
Frederic Weisbecker | 412d0bb | 2008-12-24 01:43:25 +0100 | [diff] [blame] | 1034 | /* Strip ending newline */ |
| 1035 | if (s->buffer[s->len - 1] == '\n') { |
| 1036 | s->buffer[s->len - 1] = '\0'; |
| 1037 | s->len--; |
| 1038 | } |
| 1039 | |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 1040 | ret = trace_seq_printf(s, " */\n"); |
| 1041 | if (!ret) |
| 1042 | return TRACE_TYPE_PARTIAL_LINE; |
| 1043 | |
| 1044 | return TRACE_TYPE_HANDLED; |
| 1045 | } |
| 1046 | |
| 1047 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1048 | enum print_line_t |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1049 | print_graph_function_flags(struct trace_iterator *iter, u32 flags) |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1050 | { |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1051 | struct ftrace_graph_ent_entry *field; |
| 1052 | struct fgraph_data *data = iter->private; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1053 | struct trace_entry *entry = iter->ent; |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame] | 1054 | struct trace_seq *s = &iter->seq; |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1055 | int cpu = iter->cpu; |
| 1056 | int ret; |
| 1057 | |
| 1058 | if (data && per_cpu_ptr(data->cpu_data, cpu)->ignore) { |
| 1059 | per_cpu_ptr(data->cpu_data, cpu)->ignore = 0; |
| 1060 | return TRACE_TYPE_HANDLED; |
| 1061 | } |
| 1062 | |
| 1063 | /* |
| 1064 | * If the last output failed, there's a possibility we need |
| 1065 | * to print out the missing entry which would never go out. |
| 1066 | */ |
| 1067 | if (data && data->failed) { |
| 1068 | field = &data->ent; |
| 1069 | iter->cpu = data->cpu; |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1070 | ret = print_graph_entry(field, s, iter, flags); |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1071 | if (ret == TRACE_TYPE_HANDLED && iter->cpu != cpu) { |
| 1072 | per_cpu_ptr(data->cpu_data, iter->cpu)->ignore = 1; |
| 1073 | ret = TRACE_TYPE_NO_CONSUME; |
| 1074 | } |
| 1075 | iter->cpu = cpu; |
| 1076 | return ret; |
| 1077 | } |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1078 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1079 | switch (entry->type) { |
| 1080 | case TRACE_GRAPH_ENT: { |
Lai Jiangshan | 38ceb59 | 2009-07-28 20:11:24 +0800 | [diff] [blame] | 1081 | /* |
| 1082 | * print_graph_entry() may consume the current event, |
| 1083 | * thus @field may become invalid, so we need to save it. |
| 1084 | * sizeof(struct ftrace_graph_ent_entry) is very small, |
| 1085 | * it can be safely saved at the stack. |
| 1086 | */ |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1087 | struct ftrace_graph_ent_entry saved; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1088 | trace_assign_type(field, entry); |
Lai Jiangshan | 38ceb59 | 2009-07-28 20:11:24 +0800 | [diff] [blame] | 1089 | saved = *field; |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1090 | return print_graph_entry(&saved, s, iter, flags); |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1091 | } |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1092 | case TRACE_GRAPH_RET: { |
| 1093 | struct ftrace_graph_ret_entry *field; |
| 1094 | trace_assign_type(field, entry); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1095 | return print_graph_return(&field->ret, s, entry, iter, flags); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1096 | } |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 1097 | case TRACE_STACK: |
| 1098 | case TRACE_FN: |
| 1099 | /* dont trace stack and functions as comments */ |
| 1100 | return TRACE_TYPE_UNHANDLED; |
| 1101 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1102 | default: |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1103 | return print_graph_comment(s, entry, iter, flags); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 1104 | } |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame] | 1105 | |
| 1106 | return TRACE_TYPE_HANDLED; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1107 | } |
| 1108 | |
Jiri Olsa | 9106b69 | 2010-04-02 19:01:20 +0200 | [diff] [blame] | 1109 | static enum print_line_t |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1110 | print_graph_function(struct trace_iterator *iter) |
| 1111 | { |
| 1112 | return print_graph_function_flags(iter, tracer_flags.val); |
| 1113 | } |
| 1114 | |
| 1115 | static enum print_line_t |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1116 | print_graph_function_event(struct trace_iterator *iter, int flags, |
| 1117 | struct trace_event *event) |
Jiri Olsa | 9106b69 | 2010-04-02 19:01:20 +0200 | [diff] [blame] | 1118 | { |
| 1119 | return print_graph_function(iter); |
| 1120 | } |
| 1121 | |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1122 | static void print_lat_header(struct seq_file *s, u32 flags) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1123 | { |
| 1124 | static const char spaces[] = " " /* 16 spaces */ |
| 1125 | " " /* 4 spaces */ |
| 1126 | " "; /* 17 spaces */ |
| 1127 | int size = 0; |
| 1128 | |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1129 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1130 | size += 16; |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1131 | if (flags & TRACE_GRAPH_PRINT_CPU) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1132 | size += 4; |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1133 | if (flags & TRACE_GRAPH_PRINT_PROC) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1134 | size += 17; |
| 1135 | |
| 1136 | seq_printf(s, "#%.*s _-----=> irqs-off \n", size, spaces); |
| 1137 | seq_printf(s, "#%.*s / _----=> need-resched \n", size, spaces); |
| 1138 | seq_printf(s, "#%.*s| / _---=> hardirq/softirq \n", size, spaces); |
| 1139 | seq_printf(s, "#%.*s|| / _--=> preempt-depth \n", size, spaces); |
Steven Rostedt | 637e7e8 | 2009-09-11 13:55:35 -0400 | [diff] [blame] | 1140 | seq_printf(s, "#%.*s||| / _-=> lock-depth \n", size, spaces); |
| 1141 | seq_printf(s, "#%.*s|||| / \n", size, spaces); |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1142 | } |
| 1143 | |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1144 | void print_graph_headers_flags(struct seq_file *s, u32 flags) |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 1145 | { |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1146 | int lat = trace_flags & TRACE_ITER_LATENCY_FMT; |
| 1147 | |
| 1148 | if (lat) |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1149 | print_lat_header(s, flags); |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1150 | |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 1151 | /* 1st line */ |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1152 | seq_printf(s, "#"); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1153 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1154 | seq_printf(s, " TIME "); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1155 | if (flags & TRACE_GRAPH_PRINT_CPU) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1156 | seq_printf(s, " CPU"); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1157 | if (flags & TRACE_GRAPH_PRINT_PROC) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1158 | seq_printf(s, " TASK/PID "); |
| 1159 | if (lat) |
Steven Rostedt | 637e7e8 | 2009-09-11 13:55:35 -0400 | [diff] [blame] | 1160 | seq_printf(s, "|||||"); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1161 | if (flags & TRACE_GRAPH_PRINT_DURATION) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1162 | seq_printf(s, " DURATION "); |
| 1163 | seq_printf(s, " FUNCTION CALLS\n"); |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 1164 | |
| 1165 | /* 2nd line */ |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1166 | seq_printf(s, "#"); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1167 | if (flags & TRACE_GRAPH_PRINT_ABS_TIME) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1168 | seq_printf(s, " | "); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1169 | if (flags & TRACE_GRAPH_PRINT_CPU) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1170 | seq_printf(s, " | "); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1171 | if (flags & TRACE_GRAPH_PRINT_PROC) |
Steven Rostedt | 49ff590 | 2009-09-11 00:30:26 -0400 | [diff] [blame] | 1172 | seq_printf(s, " | | "); |
| 1173 | if (lat) |
Steven Rostedt | 637e7e8 | 2009-09-11 13:55:35 -0400 | [diff] [blame] | 1174 | seq_printf(s, "|||||"); |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1175 | if (flags & TRACE_GRAPH_PRINT_DURATION) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1176 | seq_printf(s, " | | "); |
| 1177 | seq_printf(s, " | | | |\n"); |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 1178 | } |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1179 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 1180 | void print_graph_headers(struct seq_file *s) |
Jiri Olsa | d7a8d9e | 2010-04-02 19:01:21 +0200 | [diff] [blame] | 1181 | { |
| 1182 | print_graph_headers_flags(s, tracer_flags.val); |
| 1183 | } |
| 1184 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 1185 | void graph_trace_open(struct trace_iterator *iter) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1186 | { |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 1187 | /* pid and depth on the last trace processed */ |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1188 | struct fgraph_data *data; |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1189 | int cpu; |
| 1190 | |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1191 | iter->private = NULL; |
| 1192 | |
| 1193 | data = kzalloc(sizeof(*data), GFP_KERNEL); |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 1194 | if (!data) |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1195 | goto out_err; |
| 1196 | |
| 1197 | data->cpu_data = alloc_percpu(struct fgraph_cpu_data); |
| 1198 | if (!data->cpu_data) |
| 1199 | goto out_err_free; |
| 1200 | |
| 1201 | for_each_possible_cpu(cpu) { |
| 1202 | pid_t *pid = &(per_cpu_ptr(data->cpu_data, cpu)->last_pid); |
| 1203 | int *depth = &(per_cpu_ptr(data->cpu_data, cpu)->depth); |
| 1204 | int *ignore = &(per_cpu_ptr(data->cpu_data, cpu)->ignore); |
| 1205 | *pid = -1; |
| 1206 | *depth = 0; |
| 1207 | *ignore = 0; |
| 1208 | } |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1209 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 1210 | iter->private = data; |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1211 | |
| 1212 | return; |
| 1213 | |
| 1214 | out_err_free: |
| 1215 | kfree(data); |
| 1216 | out_err: |
| 1217 | pr_warning("function graph tracer: not enough memory\n"); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1218 | } |
| 1219 | |
Jiri Olsa | 62b915f | 2010-04-02 19:01:22 +0200 | [diff] [blame] | 1220 | void graph_trace_close(struct trace_iterator *iter) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1221 | { |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1222 | struct fgraph_data *data = iter->private; |
| 1223 | |
| 1224 | if (data) { |
| 1225 | free_percpu(data->cpu_data); |
| 1226 | kfree(data); |
| 1227 | } |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1228 | } |
| 1229 | |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1230 | static struct trace_event_functions graph_functions = { |
| 1231 | .trace = print_graph_function_event, |
| 1232 | }; |
| 1233 | |
Jiri Olsa | 9106b69 | 2010-04-02 19:01:20 +0200 | [diff] [blame] | 1234 | static struct trace_event graph_trace_entry_event = { |
| 1235 | .type = TRACE_GRAPH_ENT, |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1236 | .funcs = &graph_functions, |
Jiri Olsa | 9106b69 | 2010-04-02 19:01:20 +0200 | [diff] [blame] | 1237 | }; |
| 1238 | |
| 1239 | static struct trace_event graph_trace_ret_event = { |
| 1240 | .type = TRACE_GRAPH_RET, |
Steven Rostedt | a9a5776 | 2010-04-22 18:46:14 -0400 | [diff] [blame] | 1241 | .funcs = &graph_functions |
Jiri Olsa | 9106b69 | 2010-04-02 19:01:20 +0200 | [diff] [blame] | 1242 | }; |
| 1243 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1244 | static struct tracer graph_trace __read_mostly = { |
Steven Rostedt | ef18012 | 2009-03-10 14:10:56 -0400 | [diff] [blame] | 1245 | .name = "function_graph", |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1246 | .open = graph_trace_open, |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1247 | .pipe_open = graph_trace_open, |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 1248 | .close = graph_trace_close, |
Jiri Olsa | be1eca3 | 2009-11-24 13:57:38 +0100 | [diff] [blame] | 1249 | .pipe_close = graph_trace_close, |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 1250 | .wait_pipe = poll_wait_pipe, |
Steven Rostedt | ef18012 | 2009-03-10 14:10:56 -0400 | [diff] [blame] | 1251 | .init = graph_trace_init, |
| 1252 | .reset = graph_trace_reset, |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 1253 | .print_line = print_graph_function, |
| 1254 | .print_header = print_graph_headers, |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1255 | .flags = &tracer_flags, |
Frederic Weisbecker | 7447dce | 2009-02-07 21:33:57 +0100 | [diff] [blame] | 1256 | #ifdef CONFIG_FTRACE_SELFTEST |
| 1257 | .selftest = trace_selftest_startup_function_graph, |
| 1258 | #endif |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1259 | }; |
| 1260 | |
| 1261 | static __init int init_graph_trace(void) |
| 1262 | { |
Lai Jiangshan | 0c9e6f6 | 2009-07-28 20:26:06 +0800 | [diff] [blame] | 1263 | max_bytes_for_cpu = snprintf(NULL, 0, "%d", nr_cpu_ids - 1); |
| 1264 | |
Jiri Olsa | 9106b69 | 2010-04-02 19:01:20 +0200 | [diff] [blame] | 1265 | if (!register_ftrace_event(&graph_trace_entry_event)) { |
| 1266 | pr_warning("Warning: could not register graph trace events\n"); |
| 1267 | return 1; |
| 1268 | } |
| 1269 | |
| 1270 | if (!register_ftrace_event(&graph_trace_ret_event)) { |
| 1271 | pr_warning("Warning: could not register graph trace events\n"); |
| 1272 | return 1; |
| 1273 | } |
| 1274 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 1275 | return register_tracer(&graph_trace); |
| 1276 | } |
| 1277 | |
| 1278 | device_initcall(init_graph_trace); |