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> |
| 12 | #include <linux/fs.h> |
| 13 | |
| 14 | #include "trace.h" |
Steven Rostedt | f0868d1 | 2008-12-23 23:24:12 -0500 | [diff] [blame] | 15 | #include "trace_output.h" |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 16 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 17 | struct fgraph_data { |
| 18 | pid_t last_pid; |
| 19 | int depth; |
| 20 | }; |
| 21 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 22 | #define TRACE_GRAPH_INDENT 2 |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 23 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 24 | /* Flag options */ |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 25 | #define TRACE_GRAPH_PRINT_OVERRUN 0x1 |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 26 | #define TRACE_GRAPH_PRINT_CPU 0x2 |
| 27 | #define TRACE_GRAPH_PRINT_OVERHEAD 0x4 |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 28 | #define TRACE_GRAPH_PRINT_PROC 0x8 |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 29 | #define TRACE_GRAPH_PRINT_DURATION 0x10 |
| 30 | #define TRACE_GRAPH_PRINT_ABS_TIME 0X20 |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 31 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 32 | static struct tracer_opt trace_opts[] = { |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 33 | /* Display overruns? (for self-debug purpose) */ |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 34 | { TRACER_OPT(funcgraph-overrun, TRACE_GRAPH_PRINT_OVERRUN) }, |
| 35 | /* Display CPU ? */ |
| 36 | { TRACER_OPT(funcgraph-cpu, TRACE_GRAPH_PRINT_CPU) }, |
| 37 | /* Display Overhead ? */ |
| 38 | { TRACER_OPT(funcgraph-overhead, TRACE_GRAPH_PRINT_OVERHEAD) }, |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 39 | /* Display proc name/pid */ |
| 40 | { TRACER_OPT(funcgraph-proc, TRACE_GRAPH_PRINT_PROC) }, |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 41 | /* Display duration of execution */ |
| 42 | { TRACER_OPT(funcgraph-duration, TRACE_GRAPH_PRINT_DURATION) }, |
| 43 | /* Display absolute time of an entry */ |
| 44 | { TRACER_OPT(funcgraph-abstime, TRACE_GRAPH_PRINT_ABS_TIME) }, |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 45 | { } /* Empty entry */ |
| 46 | }; |
| 47 | |
| 48 | static struct tracer_flags tracer_flags = { |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 49 | /* Don't display overruns and proc by default */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 50 | .val = TRACE_GRAPH_PRINT_CPU | TRACE_GRAPH_PRINT_OVERHEAD | |
| 51 | TRACE_GRAPH_PRINT_DURATION, |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 52 | .opts = trace_opts |
| 53 | }; |
| 54 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 55 | /* pid on the last trace processed */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 56 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 57 | |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 58 | /* Add a function return address to the trace stack on thread info.*/ |
| 59 | int |
| 60 | ftrace_push_return_trace(unsigned long ret, unsigned long long time, |
| 61 | unsigned long func, int *depth) |
| 62 | { |
| 63 | int index; |
| 64 | |
| 65 | if (!current->ret_stack) |
| 66 | return -EBUSY; |
| 67 | |
| 68 | /* The return trace stack is full */ |
| 69 | if (current->curr_ret_stack == FTRACE_RETFUNC_DEPTH - 1) { |
| 70 | atomic_inc(¤t->trace_overrun); |
| 71 | return -EBUSY; |
| 72 | } |
| 73 | |
| 74 | index = ++current->curr_ret_stack; |
| 75 | barrier(); |
| 76 | current->ret_stack[index].ret = ret; |
| 77 | current->ret_stack[index].func = func; |
| 78 | current->ret_stack[index].calltime = time; |
| 79 | *depth = index; |
| 80 | |
| 81 | return 0; |
| 82 | } |
| 83 | |
| 84 | /* Retrieve a function return address to the trace stack on thread info.*/ |
| 85 | void |
| 86 | ftrace_pop_return_trace(struct ftrace_graph_ret *trace, unsigned long *ret) |
| 87 | { |
| 88 | int index; |
| 89 | |
| 90 | index = current->curr_ret_stack; |
| 91 | |
| 92 | if (unlikely(index < 0)) { |
| 93 | ftrace_graph_stop(); |
| 94 | WARN_ON(1); |
| 95 | /* Might as well panic, otherwise we have no where to go */ |
| 96 | *ret = (unsigned long)panic; |
| 97 | return; |
| 98 | } |
| 99 | |
| 100 | *ret = current->ret_stack[index].ret; |
| 101 | trace->func = current->ret_stack[index].func; |
| 102 | trace->calltime = current->ret_stack[index].calltime; |
| 103 | trace->overrun = atomic_read(¤t->trace_overrun); |
| 104 | trace->depth = index; |
| 105 | barrier(); |
| 106 | current->curr_ret_stack--; |
| 107 | |
| 108 | } |
| 109 | |
| 110 | /* |
| 111 | * Send the trace to the ring-buffer. |
| 112 | * @return the original return address. |
| 113 | */ |
| 114 | unsigned long ftrace_return_to_handler(void) |
| 115 | { |
| 116 | struct ftrace_graph_ret trace; |
| 117 | unsigned long ret; |
| 118 | |
| 119 | ftrace_pop_return_trace(&trace, &ret); |
Frederic Weisbecker | 0012693 | 2009-03-05 01:49:22 +0100 | [diff] [blame] | 120 | trace.rettime = trace_clock_local(); |
Steven Rostedt | 712406a | 2009-02-09 10:54:03 -0800 | [diff] [blame] | 121 | ftrace_graph_return(&trace); |
| 122 | |
| 123 | if (unlikely(!ret)) { |
| 124 | ftrace_graph_stop(); |
| 125 | WARN_ON(1); |
| 126 | /* Might as well panic. What else to do? */ |
| 127 | ret = (unsigned long)panic; |
| 128 | } |
| 129 | |
| 130 | return ret; |
| 131 | } |
| 132 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 133 | static int graph_trace_init(struct trace_array *tr) |
| 134 | { |
Arnaldo Carvalho de Melo | f04109b | 2009-01-28 13:02:12 -0200 | [diff] [blame] | 135 | int ret = register_ftrace_graph(&trace_graph_return, |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 136 | &trace_graph_entry); |
Steven Rostedt | 660c7f9 | 2008-11-26 00:16:26 -0500 | [diff] [blame] | 137 | if (ret) |
| 138 | return ret; |
| 139 | tracing_start_cmdline_record(); |
| 140 | |
| 141 | return 0; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 142 | } |
| 143 | |
| 144 | static void graph_trace_reset(struct trace_array *tr) |
| 145 | { |
Steven Rostedt | 660c7f9 | 2008-11-26 00:16:26 -0500 | [diff] [blame] | 146 | tracing_stop_cmdline_record(); |
| 147 | unregister_ftrace_graph(); |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 150 | static inline int log10_cpu(int nb) |
| 151 | { |
| 152 | if (nb / 100) |
| 153 | return 3; |
| 154 | if (nb / 10) |
| 155 | return 2; |
| 156 | return 1; |
| 157 | } |
| 158 | |
| 159 | static enum print_line_t |
| 160 | print_graph_cpu(struct trace_seq *s, int cpu) |
| 161 | { |
| 162 | int i; |
| 163 | int ret; |
| 164 | int log10_this = log10_cpu(cpu); |
Rusty Russell | 4462344 | 2009-01-01 10:12:23 +1030 | [diff] [blame] | 165 | int log10_all = log10_cpu(cpumask_weight(cpu_online_mask)); |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 166 | |
| 167 | |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 168 | /* |
| 169 | * Start with a space character - to make it stand out |
| 170 | * to the right a bit when trace output is pasted into |
| 171 | * email: |
| 172 | */ |
| 173 | ret = trace_seq_printf(s, " "); |
| 174 | |
| 175 | /* |
| 176 | * Tricky - we space the CPU field according to the max |
| 177 | * number of online CPUs. On a 2-cpu system it would take |
| 178 | * a maximum of 1 digit - on a 128 cpu system it would |
| 179 | * take up to 3 digits: |
| 180 | */ |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 181 | for (i = 0; i < log10_all - log10_this; i++) { |
| 182 | ret = trace_seq_printf(s, " "); |
| 183 | if (!ret) |
| 184 | return TRACE_TYPE_PARTIAL_LINE; |
| 185 | } |
| 186 | ret = trace_seq_printf(s, "%d) ", cpu); |
| 187 | if (!ret) |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 188 | return TRACE_TYPE_PARTIAL_LINE; |
| 189 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 190 | return TRACE_TYPE_HANDLED; |
| 191 | } |
| 192 | |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 193 | #define TRACE_GRAPH_PROCINFO_LENGTH 14 |
| 194 | |
| 195 | static enum print_line_t |
| 196 | print_graph_proc(struct trace_seq *s, pid_t pid) |
| 197 | { |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 198 | char comm[TASK_COMM_LEN]; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 199 | /* sign + log10(MAX_INT) + '\0' */ |
| 200 | char pid_str[11]; |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 201 | int spaces = 0; |
| 202 | int ret; |
| 203 | int len; |
| 204 | int i; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 205 | |
Steven Rostedt | 4ca53085 | 2009-03-16 19:20:15 -0400 | [diff] [blame] | 206 | trace_find_cmdline(pid, comm); |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 207 | comm[7] = '\0'; |
| 208 | sprintf(pid_str, "%d", pid); |
| 209 | |
| 210 | /* 1 stands for the "-" character */ |
| 211 | len = strlen(comm) + strlen(pid_str) + 1; |
| 212 | |
| 213 | if (len < TRACE_GRAPH_PROCINFO_LENGTH) |
| 214 | spaces = TRACE_GRAPH_PROCINFO_LENGTH - len; |
| 215 | |
| 216 | /* First spaces to align center */ |
| 217 | for (i = 0; i < spaces / 2; i++) { |
| 218 | ret = trace_seq_printf(s, " "); |
| 219 | if (!ret) |
| 220 | return TRACE_TYPE_PARTIAL_LINE; |
| 221 | } |
| 222 | |
| 223 | ret = trace_seq_printf(s, "%s-%s", comm, pid_str); |
| 224 | if (!ret) |
| 225 | return TRACE_TYPE_PARTIAL_LINE; |
| 226 | |
| 227 | /* Last spaces to align center */ |
| 228 | for (i = 0; i < spaces - (spaces / 2); i++) { |
| 229 | ret = trace_seq_printf(s, " "); |
| 230 | if (!ret) |
| 231 | return TRACE_TYPE_PARTIAL_LINE; |
| 232 | } |
| 233 | return TRACE_TYPE_HANDLED; |
| 234 | } |
| 235 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 236 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 237 | /* If the pid changed since the last trace, output this event */ |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 238 | static enum print_line_t |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 239 | 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] | 240 | { |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 241 | pid_t prev_pid; |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 242 | pid_t *last_pid; |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 243 | int ret; |
Steven Rostedt | 660c7f9 | 2008-11-26 00:16:26 -0500 | [diff] [blame] | 244 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 245 | if (!data) |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 246 | return TRACE_TYPE_HANDLED; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 247 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 248 | last_pid = &(per_cpu_ptr(data, cpu)->last_pid); |
Steven Rostedt | 660c7f9 | 2008-11-26 00:16:26 -0500 | [diff] [blame] | 249 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 250 | if (*last_pid == pid) |
| 251 | return TRACE_TYPE_HANDLED; |
| 252 | |
| 253 | prev_pid = *last_pid; |
| 254 | *last_pid = pid; |
| 255 | |
| 256 | if (prev_pid == -1) |
| 257 | return TRACE_TYPE_HANDLED; |
Ingo Molnar | d51090b | 2008-11-28 09:55:16 +0100 | [diff] [blame] | 258 | /* |
| 259 | * Context-switch trace line: |
| 260 | |
| 261 | ------------------------------------------ |
| 262 | | 1) migration/0--1 => sshd-1755 |
| 263 | ------------------------------------------ |
| 264 | |
| 265 | */ |
| 266 | ret = trace_seq_printf(s, |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 267 | " ------------------------------------------\n"); |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 268 | if (!ret) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 269 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 270 | |
| 271 | ret = print_graph_cpu(s, cpu); |
| 272 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 273 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 274 | |
| 275 | ret = print_graph_proc(s, prev_pid); |
| 276 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 277 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 278 | |
| 279 | ret = trace_seq_printf(s, " => "); |
| 280 | if (!ret) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 281 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 282 | |
| 283 | ret = print_graph_proc(s, pid); |
| 284 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 285 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 286 | |
| 287 | ret = trace_seq_printf(s, |
| 288 | "\n ------------------------------------------\n\n"); |
| 289 | if (!ret) |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 290 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 291 | |
Wenji Huang | 810dc73 | 2009-02-10 01:03:05 -0500 | [diff] [blame] | 292 | return TRACE_TYPE_HANDLED; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 293 | } |
| 294 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 295 | static struct ftrace_graph_ret_entry * |
| 296 | get_return_for_leaf(struct trace_iterator *iter, |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 297 | struct ftrace_graph_ent_entry *curr) |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 298 | { |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 299 | struct ring_buffer_iter *ring_iter; |
| 300 | struct ring_buffer_event *event; |
| 301 | struct ftrace_graph_ret_entry *next; |
| 302 | |
| 303 | ring_iter = iter->buffer_iter[iter->cpu]; |
| 304 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 305 | /* First peek to compare current entry and the next one */ |
| 306 | if (ring_iter) |
| 307 | event = ring_buffer_iter_peek(ring_iter, NULL); |
| 308 | else { |
| 309 | /* We need to consume the current entry to see the next one */ |
| 310 | ring_buffer_consume(iter->tr->buffer, iter->cpu, NULL); |
| 311 | event = ring_buffer_peek(iter->tr->buffer, iter->cpu, |
| 312 | NULL); |
| 313 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 314 | |
| 315 | if (!event) |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 316 | return NULL; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 317 | |
| 318 | next = ring_buffer_event_data(event); |
| 319 | |
| 320 | if (next->ent.type != TRACE_GRAPH_RET) |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 321 | return NULL; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 322 | |
| 323 | if (curr->ent.pid != next->ent.pid || |
| 324 | curr->graph_ent.func != next->ret.func) |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 325 | return NULL; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 326 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 327 | /* this is a leaf, now advance the iterator */ |
| 328 | if (ring_iter) |
| 329 | ring_buffer_read(ring_iter, NULL); |
| 330 | |
| 331 | return next; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 334 | /* Signal a overhead of time execution to the output */ |
| 335 | static int |
| 336 | print_graph_overhead(unsigned long long duration, struct trace_seq *s) |
| 337 | { |
| 338 | /* If duration disappear, we don't need anything */ |
| 339 | if (!(tracer_flags.val & TRACE_GRAPH_PRINT_DURATION)) |
| 340 | return 1; |
| 341 | |
| 342 | /* Non nested entry or return */ |
| 343 | if (duration == -1) |
| 344 | return trace_seq_printf(s, " "); |
| 345 | |
| 346 | if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERHEAD) { |
| 347 | /* Duration exceeded 100 msecs */ |
| 348 | if (duration > 100000ULL) |
| 349 | return trace_seq_printf(s, "! "); |
| 350 | |
| 351 | /* Duration exceeded 10 msecs */ |
| 352 | if (duration > 10000ULL) |
| 353 | return trace_seq_printf(s, "+ "); |
| 354 | } |
| 355 | |
| 356 | return trace_seq_printf(s, " "); |
| 357 | } |
| 358 | |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 359 | static int print_graph_abs_time(u64 t, struct trace_seq *s) |
| 360 | { |
| 361 | unsigned long usecs_rem; |
| 362 | |
| 363 | usecs_rem = do_div(t, NSEC_PER_SEC); |
| 364 | usecs_rem /= 1000; |
| 365 | |
| 366 | return trace_seq_printf(s, "%5lu.%06lu | ", |
| 367 | (unsigned long)t, usecs_rem); |
| 368 | } |
| 369 | |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 370 | static enum print_line_t |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 371 | print_graph_irq(struct trace_iterator *iter, unsigned long addr, |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 372 | enum trace_type type, int cpu, pid_t pid) |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 373 | { |
| 374 | int ret; |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 375 | struct trace_seq *s = &iter->seq; |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 376 | |
| 377 | if (addr < (unsigned long)__irqentry_text_start || |
| 378 | addr >= (unsigned long)__irqentry_text_end) |
| 379 | return TRACE_TYPE_UNHANDLED; |
| 380 | |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 381 | /* Absolute time */ |
| 382 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) { |
| 383 | ret = print_graph_abs_time(iter->ts, s); |
| 384 | if (!ret) |
| 385 | return TRACE_TYPE_PARTIAL_LINE; |
| 386 | } |
| 387 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 388 | /* Cpu */ |
| 389 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) { |
| 390 | ret = print_graph_cpu(s, cpu); |
| 391 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 392 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 393 | } |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 394 | /* Proc */ |
| 395 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) { |
| 396 | ret = print_graph_proc(s, pid); |
| 397 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 398 | return TRACE_TYPE_PARTIAL_LINE; |
| 399 | ret = trace_seq_printf(s, " | "); |
| 400 | if (!ret) |
| 401 | return TRACE_TYPE_PARTIAL_LINE; |
| 402 | } |
| 403 | |
| 404 | /* No overhead */ |
| 405 | ret = print_graph_overhead(-1, s); |
| 406 | if (!ret) |
| 407 | return TRACE_TYPE_PARTIAL_LINE; |
| 408 | |
| 409 | if (type == TRACE_GRAPH_ENT) |
| 410 | ret = trace_seq_printf(s, "==========>"); |
| 411 | else |
| 412 | ret = trace_seq_printf(s, "<=========="); |
| 413 | |
| 414 | if (!ret) |
| 415 | return TRACE_TYPE_PARTIAL_LINE; |
| 416 | |
| 417 | /* Don't close the duration column if haven't one */ |
| 418 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) |
| 419 | trace_seq_printf(s, " |"); |
| 420 | ret = trace_seq_printf(s, "\n"); |
| 421 | |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 422 | if (!ret) |
| 423 | return TRACE_TYPE_PARTIAL_LINE; |
| 424 | return TRACE_TYPE_HANDLED; |
| 425 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 426 | |
Frederic Weisbecker | 166d3c7 | 2008-12-03 02:32:12 +0100 | [diff] [blame] | 427 | static enum print_line_t |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 428 | print_graph_duration(unsigned long long duration, struct trace_seq *s) |
| 429 | { |
| 430 | unsigned long nsecs_rem = do_div(duration, 1000); |
Frederic Weisbecker | 166d3c7 | 2008-12-03 02:32:12 +0100 | [diff] [blame] | 431 | /* log10(ULONG_MAX) + '\0' */ |
| 432 | char msecs_str[21]; |
| 433 | char nsecs_str[5]; |
| 434 | int ret, len; |
| 435 | int i; |
| 436 | |
| 437 | sprintf(msecs_str, "%lu", (unsigned long) duration); |
| 438 | |
| 439 | /* Print msecs */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 440 | ret = trace_seq_printf(s, "%s", msecs_str); |
Frederic Weisbecker | 166d3c7 | 2008-12-03 02:32:12 +0100 | [diff] [blame] | 441 | if (!ret) |
| 442 | return TRACE_TYPE_PARTIAL_LINE; |
| 443 | |
| 444 | len = strlen(msecs_str); |
| 445 | |
| 446 | /* Print nsecs (we don't want to exceed 7 numbers) */ |
| 447 | if (len < 7) { |
| 448 | snprintf(nsecs_str, 8 - len, "%03lu", nsecs_rem); |
| 449 | ret = trace_seq_printf(s, ".%s", nsecs_str); |
| 450 | if (!ret) |
| 451 | return TRACE_TYPE_PARTIAL_LINE; |
| 452 | len += strlen(nsecs_str); |
| 453 | } |
| 454 | |
| 455 | ret = trace_seq_printf(s, " us "); |
| 456 | if (!ret) |
| 457 | return TRACE_TYPE_PARTIAL_LINE; |
| 458 | |
| 459 | /* Print remaining spaces to fit the row's width */ |
| 460 | for (i = len; i < 7; i++) { |
| 461 | ret = trace_seq_printf(s, " "); |
| 462 | if (!ret) |
| 463 | return TRACE_TYPE_PARTIAL_LINE; |
| 464 | } |
| 465 | |
| 466 | ret = trace_seq_printf(s, "| "); |
| 467 | if (!ret) |
| 468 | return TRACE_TYPE_PARTIAL_LINE; |
| 469 | return TRACE_TYPE_HANDLED; |
| 470 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 471 | } |
| 472 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 473 | /* Case of a leaf function on its call entry */ |
| 474 | static enum print_line_t |
| 475 | print_graph_entry_leaf(struct trace_iterator *iter, |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 476 | struct ftrace_graph_ent_entry *entry, |
| 477 | struct ftrace_graph_ret_entry *ret_entry, struct trace_seq *s) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 478 | { |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 479 | struct fgraph_data *data = iter->private; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 480 | struct ftrace_graph_ret *graph_ret; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 481 | struct ftrace_graph_ent *call; |
| 482 | unsigned long long duration; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 483 | int ret; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 484 | int i; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 485 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 486 | graph_ret = &ret_entry->ret; |
| 487 | call = &entry->graph_ent; |
| 488 | duration = graph_ret->rettime - graph_ret->calltime; |
Steven Rostedt | 437f24fb | 2008-11-26 00:16:27 -0500 | [diff] [blame] | 489 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 490 | if (data) { |
| 491 | int cpu = iter->cpu; |
| 492 | int *depth = &(per_cpu_ptr(data, cpu)->depth); |
| 493 | |
| 494 | /* |
| 495 | * Comments display at + 1 to depth. Since |
| 496 | * this is a leaf function, keep the comments |
| 497 | * equal to this depth. |
| 498 | */ |
| 499 | *depth = call->depth - 1; |
| 500 | } |
| 501 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 502 | /* Overhead */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 503 | ret = print_graph_overhead(duration, s); |
| 504 | if (!ret) |
| 505 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 506 | |
| 507 | /* Duration */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 508 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) { |
| 509 | ret = print_graph_duration(duration, s); |
| 510 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 511 | return TRACE_TYPE_PARTIAL_LINE; |
| 512 | } |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 513 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 514 | /* Function */ |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 515 | for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) { |
| 516 | ret = trace_seq_printf(s, " "); |
| 517 | if (!ret) |
| 518 | return TRACE_TYPE_PARTIAL_LINE; |
| 519 | } |
| 520 | |
| 521 | ret = seq_print_ip_sym(s, call->func, 0); |
| 522 | if (!ret) |
| 523 | return TRACE_TYPE_PARTIAL_LINE; |
| 524 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 525 | ret = trace_seq_printf(s, "();\n"); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 526 | if (!ret) |
| 527 | return TRACE_TYPE_PARTIAL_LINE; |
| 528 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 529 | return TRACE_TYPE_HANDLED; |
| 530 | } |
| 531 | |
| 532 | static enum print_line_t |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 533 | print_graph_entry_nested(struct trace_iterator *iter, |
| 534 | struct ftrace_graph_ent_entry *entry, |
| 535 | struct trace_seq *s, int cpu) |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 536 | { |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 537 | struct ftrace_graph_ent *call = &entry->graph_ent; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 538 | struct fgraph_data *data = iter->private; |
| 539 | int ret; |
| 540 | int i; |
| 541 | |
| 542 | if (data) { |
| 543 | int cpu = iter->cpu; |
| 544 | int *depth = &(per_cpu_ptr(data, cpu)->depth); |
| 545 | |
| 546 | *depth = call->depth; |
| 547 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 548 | |
| 549 | /* No overhead */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 550 | ret = print_graph_overhead(-1, s); |
| 551 | if (!ret) |
| 552 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 553 | |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 554 | /* No time */ |
| 555 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) { |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 556 | ret = trace_seq_printf(s, " | "); |
| 557 | if (!ret) |
| 558 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 559 | } |
| 560 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 561 | /* Function */ |
| 562 | for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) { |
| 563 | ret = trace_seq_printf(s, " "); |
| 564 | if (!ret) |
| 565 | return TRACE_TYPE_PARTIAL_LINE; |
| 566 | } |
| 567 | |
| 568 | ret = seq_print_ip_sym(s, call->func, 0); |
| 569 | if (!ret) |
| 570 | return TRACE_TYPE_PARTIAL_LINE; |
| 571 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 572 | ret = trace_seq_printf(s, "() {\n"); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 573 | if (!ret) |
| 574 | return TRACE_TYPE_PARTIAL_LINE; |
| 575 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 576 | /* |
| 577 | * we already consumed the current entry to check the next one |
| 578 | * and see if this is a leaf. |
| 579 | */ |
| 580 | return TRACE_TYPE_NO_CONSUME; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 581 | } |
| 582 | |
| 583 | static enum print_line_t |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 584 | print_graph_prologue(struct trace_iterator *iter, struct trace_seq *s, |
| 585 | int type, unsigned long addr) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 586 | { |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 587 | struct fgraph_data *data = iter->private; |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 588 | struct trace_entry *ent = iter->ent; |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 589 | int cpu = iter->cpu; |
| 590 | int ret; |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 591 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 592 | /* Pid */ |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 593 | if (verif_pid(s, ent->pid, cpu, data) == TRACE_TYPE_PARTIAL_LINE) |
Steven Rostedt | 437f24fb | 2008-11-26 00:16:27 -0500 | [diff] [blame] | 594 | return TRACE_TYPE_PARTIAL_LINE; |
| 595 | |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 596 | if (type) { |
| 597 | /* Interrupt */ |
| 598 | ret = print_graph_irq(iter, addr, type, cpu, ent->pid); |
| 599 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 600 | return TRACE_TYPE_PARTIAL_LINE; |
| 601 | } |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 602 | |
| 603 | /* Absolute time */ |
| 604 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) { |
| 605 | ret = print_graph_abs_time(iter->ts, s); |
| 606 | if (!ret) |
| 607 | return TRACE_TYPE_PARTIAL_LINE; |
| 608 | } |
| 609 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 610 | /* Cpu */ |
| 611 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) { |
| 612 | ret = print_graph_cpu(s, cpu); |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 613 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 614 | return TRACE_TYPE_PARTIAL_LINE; |
| 615 | } |
| 616 | |
| 617 | /* Proc */ |
| 618 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) { |
Ingo Molnar | 00a8bf8 | 2009-02-19 13:01:37 +0100 | [diff] [blame] | 619 | ret = print_graph_proc(s, ent->pid); |
Frederic Weisbecker | 11e84ac | 2008-12-03 02:30:37 +0100 | [diff] [blame] | 620 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 621 | return TRACE_TYPE_PARTIAL_LINE; |
| 622 | |
| 623 | ret = trace_seq_printf(s, " | "); |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 624 | if (!ret) |
| 625 | return TRACE_TYPE_PARTIAL_LINE; |
| 626 | } |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 627 | |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 628 | return 0; |
| 629 | } |
| 630 | |
| 631 | static enum print_line_t |
| 632 | print_graph_entry(struct ftrace_graph_ent_entry *field, struct trace_seq *s, |
| 633 | struct trace_iterator *iter) |
| 634 | { |
| 635 | int cpu = iter->cpu; |
| 636 | struct ftrace_graph_ent *call = &field->graph_ent; |
| 637 | struct ftrace_graph_ret_entry *leaf_ret; |
| 638 | |
| 639 | if (print_graph_prologue(iter, s, TRACE_GRAPH_ENT, call->func)) |
| 640 | return TRACE_TYPE_PARTIAL_LINE; |
| 641 | |
Frederic Weisbecker | b91facc | 2009-02-06 18:30:44 +0100 | [diff] [blame] | 642 | leaf_ret = get_return_for_leaf(iter, field); |
| 643 | if (leaf_ret) |
| 644 | return print_graph_entry_leaf(iter, field, leaf_ret, s); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 645 | else |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 646 | return print_graph_entry_nested(iter, field, s, cpu); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 647 | |
| 648 | } |
| 649 | |
| 650 | static enum print_line_t |
| 651 | print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s, |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 652 | struct trace_entry *ent, struct trace_iterator *iter) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 653 | { |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 654 | unsigned long long duration = trace->rettime - trace->calltime; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 655 | struct fgraph_data *data = iter->private; |
| 656 | pid_t pid = ent->pid; |
| 657 | int cpu = iter->cpu; |
| 658 | int ret; |
| 659 | int i; |
| 660 | |
| 661 | if (data) { |
| 662 | int cpu = iter->cpu; |
| 663 | int *depth = &(per_cpu_ptr(data, cpu)->depth); |
| 664 | |
| 665 | /* |
| 666 | * Comments display at + 1 to depth. This is the |
| 667 | * return from a function, we now want the comments |
| 668 | * to display at the same level of the bracket. |
| 669 | */ |
| 670 | *depth = trace->depth - 1; |
| 671 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 672 | |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 673 | if (print_graph_prologue(iter, s, 0, 0)) |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 674 | return TRACE_TYPE_PARTIAL_LINE; |
| 675 | |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 676 | /* Overhead */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 677 | ret = print_graph_overhead(duration, s); |
| 678 | if (!ret) |
| 679 | return TRACE_TYPE_PARTIAL_LINE; |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 680 | |
| 681 | /* Duration */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 682 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) { |
| 683 | ret = print_graph_duration(duration, s); |
| 684 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 685 | return TRACE_TYPE_PARTIAL_LINE; |
| 686 | } |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 687 | |
| 688 | /* Closing brace */ |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 689 | for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++) { |
| 690 | ret = trace_seq_printf(s, " "); |
| 691 | if (!ret) |
| 692 | return TRACE_TYPE_PARTIAL_LINE; |
| 693 | } |
| 694 | |
Frederic Weisbecker | 1a05615 | 2008-11-28 00:42:46 +0100 | [diff] [blame] | 695 | ret = trace_seq_printf(s, "}\n"); |
Frederic Weisbecker | 83a8df6 | 2008-11-27 01:46:33 +0100 | [diff] [blame] | 696 | if (!ret) |
| 697 | return TRACE_TYPE_PARTIAL_LINE; |
| 698 | |
| 699 | /* Overrun */ |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 700 | if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERRUN) { |
| 701 | ret = trace_seq_printf(s, " (Overruns: %lu)\n", |
| 702 | trace->overrun); |
| 703 | if (!ret) |
| 704 | return TRACE_TYPE_PARTIAL_LINE; |
| 705 | } |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 706 | |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 707 | ret = print_graph_irq(iter, trace->func, TRACE_GRAPH_RET, cpu, pid); |
Frederic Weisbecker | f8b755a | 2008-12-09 23:55:25 +0100 | [diff] [blame] | 708 | if (ret == TRACE_TYPE_PARTIAL_LINE) |
| 709 | return TRACE_TYPE_PARTIAL_LINE; |
| 710 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 711 | return TRACE_TYPE_HANDLED; |
| 712 | } |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 713 | |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 714 | static enum print_line_t |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame^] | 715 | print_graph_comment(struct trace_seq *s, struct trace_entry *ent, |
| 716 | struct trace_iterator *iter) |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 717 | { |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame^] | 718 | unsigned long sym_flags = (trace_flags & TRACE_ITER_SYM_MASK); |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 719 | struct fgraph_data *data = iter->private; |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame^] | 720 | struct trace_event *event; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 721 | int depth = 0; |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 722 | int ret; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 723 | int i; |
| 724 | |
| 725 | if (data) |
| 726 | depth = per_cpu_ptr(data, iter->cpu)->depth; |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 727 | |
Steven Rostedt | ac5f6c9 | 2009-03-19 11:29:23 -0400 | [diff] [blame] | 728 | if (print_graph_prologue(iter, s, 0, 0)) |
Frederic Weisbecker | d1f9cbd | 2009-02-18 04:25:25 +0100 | [diff] [blame] | 729 | return TRACE_TYPE_PARTIAL_LINE; |
| 730 | |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 731 | /* No overhead */ |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 732 | ret = print_graph_overhead(-1, s); |
| 733 | if (!ret) |
| 734 | return TRACE_TYPE_PARTIAL_LINE; |
| 735 | |
| 736 | /* No time */ |
| 737 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) { |
| 738 | ret = trace_seq_printf(s, " | "); |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 739 | if (!ret) |
| 740 | return TRACE_TYPE_PARTIAL_LINE; |
| 741 | } |
| 742 | |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 743 | /* Indentation */ |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 744 | if (depth > 0) |
| 745 | for (i = 0; i < (depth + 1) * TRACE_GRAPH_INDENT; i++) { |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 746 | ret = trace_seq_printf(s, " "); |
| 747 | if (!ret) |
| 748 | return TRACE_TYPE_PARTIAL_LINE; |
| 749 | } |
| 750 | |
| 751 | /* The comment */ |
Frederic Weisbecker | 769b044 | 2009-03-06 17:21:49 +0100 | [diff] [blame] | 752 | ret = trace_seq_printf(s, "/* "); |
| 753 | if (!ret) |
| 754 | return TRACE_TYPE_PARTIAL_LINE; |
| 755 | |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame^] | 756 | switch (iter->ent->type) { |
| 757 | case TRACE_BPRINT: |
| 758 | ret = trace_print_bprintk_msg_only(iter); |
| 759 | if (ret != TRACE_TYPE_HANDLED) |
| 760 | return ret; |
| 761 | break; |
| 762 | case TRACE_PRINT: |
| 763 | ret = trace_print_printk_msg_only(iter); |
| 764 | if (ret != TRACE_TYPE_HANDLED) |
| 765 | return ret; |
| 766 | break; |
| 767 | default: |
| 768 | event = ftrace_find_event(ent->type); |
| 769 | if (!event) |
| 770 | return TRACE_TYPE_UNHANDLED; |
| 771 | |
| 772 | ret = event->trace(iter, sym_flags); |
| 773 | if (ret != TRACE_TYPE_HANDLED) |
| 774 | return ret; |
| 775 | } |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 776 | |
Frederic Weisbecker | 412d0bb | 2008-12-24 01:43:25 +0100 | [diff] [blame] | 777 | /* Strip ending newline */ |
| 778 | if (s->buffer[s->len - 1] == '\n') { |
| 779 | s->buffer[s->len - 1] = '\0'; |
| 780 | s->len--; |
| 781 | } |
| 782 | |
Frederic Weisbecker | 1fd8f2a | 2008-12-03 23:45:11 +0100 | [diff] [blame] | 783 | ret = trace_seq_printf(s, " */\n"); |
| 784 | if (!ret) |
| 785 | return TRACE_TYPE_PARTIAL_LINE; |
| 786 | |
| 787 | return TRACE_TYPE_HANDLED; |
| 788 | } |
| 789 | |
| 790 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 791 | enum print_line_t |
| 792 | print_graph_function(struct trace_iterator *iter) |
| 793 | { |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 794 | struct trace_entry *entry = iter->ent; |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame^] | 795 | struct trace_seq *s = &iter->seq; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 796 | |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 797 | switch (entry->type) { |
| 798 | case TRACE_GRAPH_ENT: { |
| 799 | struct ftrace_graph_ent_entry *field; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 800 | trace_assign_type(field, entry); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 801 | return print_graph_entry(field, s, iter); |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 802 | } |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 803 | case TRACE_GRAPH_RET: { |
| 804 | struct ftrace_graph_ret_entry *field; |
| 805 | trace_assign_type(field, entry); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 806 | return print_graph_return(&field->ret, s, entry, iter); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 807 | } |
| 808 | default: |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame^] | 809 | return print_graph_comment(s, entry, iter); |
Frederic Weisbecker | 287b6e6 | 2008-11-26 00:57:25 +0100 | [diff] [blame] | 810 | } |
Steven Rostedt | 5087f8d | 2009-03-19 15:14:46 -0400 | [diff] [blame^] | 811 | |
| 812 | return TRACE_TYPE_HANDLED; |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 813 | } |
| 814 | |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 815 | static void print_graph_headers(struct seq_file *s) |
| 816 | { |
| 817 | /* 1st line */ |
| 818 | seq_printf(s, "# "); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 819 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) |
| 820 | seq_printf(s, " TIME "); |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 821 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 822 | seq_printf(s, "CPU"); |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 823 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 824 | seq_printf(s, " TASK/PID "); |
| 825 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) |
| 826 | seq_printf(s, " DURATION "); |
| 827 | seq_printf(s, " FUNCTION CALLS\n"); |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 828 | |
| 829 | /* 2nd line */ |
| 830 | seq_printf(s, "# "); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 831 | if (tracer_flags.val & TRACE_GRAPH_PRINT_ABS_TIME) |
| 832 | seq_printf(s, " | "); |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 833 | if (tracer_flags.val & TRACE_GRAPH_PRINT_CPU) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 834 | seq_printf(s, "| "); |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 835 | if (tracer_flags.val & TRACE_GRAPH_PRINT_PROC) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 836 | seq_printf(s, " | | "); |
| 837 | if (tracer_flags.val & TRACE_GRAPH_PRINT_DURATION) |
| 838 | seq_printf(s, " | | "); |
| 839 | seq_printf(s, " | | | |\n"); |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 840 | } |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 841 | |
| 842 | static void graph_trace_open(struct trace_iterator *iter) |
| 843 | { |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 844 | /* pid and depth on the last trace processed */ |
| 845 | struct fgraph_data *data = alloc_percpu(struct fgraph_data); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 846 | int cpu; |
| 847 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 848 | if (!data) |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 849 | pr_warning("function graph tracer: not enough memory\n"); |
| 850 | else |
| 851 | for_each_possible_cpu(cpu) { |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 852 | pid_t *pid = &(per_cpu_ptr(data, cpu)->last_pid); |
| 853 | int *depth = &(per_cpu_ptr(data, cpu)->depth); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 854 | *pid = -1; |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 855 | *depth = 0; |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 856 | } |
| 857 | |
Steven Rostedt | 2fbcdb3 | 2009-03-19 13:24:42 -0400 | [diff] [blame] | 858 | iter->private = data; |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 859 | } |
| 860 | |
| 861 | static void graph_trace_close(struct trace_iterator *iter) |
| 862 | { |
Ingo Molnar | 8293dd6 | 2009-03-10 10:16:17 +0100 | [diff] [blame] | 863 | free_percpu(iter->private); |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 864 | } |
| 865 | |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 866 | static struct tracer graph_trace __read_mostly = { |
Steven Rostedt | ef18012 | 2009-03-10 14:10:56 -0400 | [diff] [blame] | 867 | .name = "function_graph", |
Frederic Weisbecker | 9005f3e | 2009-01-22 17:04:53 -0800 | [diff] [blame] | 868 | .open = graph_trace_open, |
| 869 | .close = graph_trace_close, |
Frederic Weisbecker | 6eaaa5d | 2009-02-11 02:25:00 +0100 | [diff] [blame] | 870 | .wait_pipe = poll_wait_pipe, |
Steven Rostedt | ef18012 | 2009-03-10 14:10:56 -0400 | [diff] [blame] | 871 | .init = graph_trace_init, |
| 872 | .reset = graph_trace_reset, |
Frederic Weisbecker | decbec3 | 2008-12-08 01:56:06 +0100 | [diff] [blame] | 873 | .print_line = print_graph_function, |
| 874 | .print_header = print_graph_headers, |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 875 | .flags = &tracer_flags, |
Frederic Weisbecker | 7447dce | 2009-02-07 21:33:57 +0100 | [diff] [blame] | 876 | #ifdef CONFIG_FTRACE_SELFTEST |
| 877 | .selftest = trace_selftest_startup_function_graph, |
| 878 | #endif |
Frederic Weisbecker | fb52607 | 2008-11-25 21:07:04 +0100 | [diff] [blame] | 879 | }; |
| 880 | |
| 881 | static __init int init_graph_trace(void) |
| 882 | { |
| 883 | return register_tracer(&graph_trace); |
| 884 | } |
| 885 | |
| 886 | device_initcall(init_graph_trace); |