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