3 * Function graph tracer.
4 * Copyright (c) 2008-2009 Frederic Weisbecker <fweisbec@gmail.com>
5 * Mostly borrowed from function tracer which
6 * is Copyright (c) Steven Rostedt <srostedt@redhat.com>
9 #include <linux/debugfs.h>
10 #include <linux/uaccess.h>
11 #include <linux/ftrace.h>
15 #include "trace_output.h"
17 #define TRACE_GRAPH_INDENT 2
20 #define TRACE_GRAPH_PRINT_OVERRUN 0x1
21 #define TRACE_GRAPH_PRINT_CPU 0x2
22 #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
23 #define TRACE_GRAPH_PRINT_PROC 0x8
24 #define TRACE_GRAPH_PRINT_DURATION 0x10
25 #define TRACE_GRAPH_PRINT_ABS_TIME 0X20
27 static struct tracer_opt trace_opts
[] = {
28 /* Display overruns? (for self-debug purpose) */
29 { TRACER_OPT(funcgraph
-overrun
, TRACE_GRAPH_PRINT_OVERRUN
) },
31 { TRACER_OPT(funcgraph
-cpu
, TRACE_GRAPH_PRINT_CPU
) },
32 /* Display Overhead ? */
33 { TRACER_OPT(funcgraph
-overhead
, TRACE_GRAPH_PRINT_OVERHEAD
) },
34 /* Display proc name/pid */
35 { TRACER_OPT(funcgraph
-proc
, TRACE_GRAPH_PRINT_PROC
) },
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
) },
43 static struct tracer_flags tracer_flags
= {
44 /* Don't display overruns and proc by default */
45 .val
= TRACE_GRAPH_PRINT_CPU
| TRACE_GRAPH_PRINT_OVERHEAD
|
46 TRACE_GRAPH_PRINT_DURATION
,
50 /* pid on the last trace processed */
53 /* Add a function return address to the trace stack on thread info.*/
55 ftrace_push_return_trace(unsigned long ret
, unsigned long long time
,
56 unsigned long func
, int *depth
)
60 if (!current
->ret_stack
)
63 /* The return trace stack is full */
64 if (current
->curr_ret_stack
== FTRACE_RETFUNC_DEPTH
- 1) {
65 atomic_inc(¤t
->trace_overrun
);
69 index
= ++current
->curr_ret_stack
;
71 current
->ret_stack
[index
].ret
= ret
;
72 current
->ret_stack
[index
].func
= func
;
73 current
->ret_stack
[index
].calltime
= time
;
79 /* Retrieve a function return address to the trace stack on thread info.*/
81 ftrace_pop_return_trace(struct ftrace_graph_ret
*trace
, unsigned long *ret
)
85 index
= current
->curr_ret_stack
;
87 if (unlikely(index
< 0)) {
90 /* Might as well panic, otherwise we have no where to go */
91 *ret
= (unsigned long)panic
;
95 *ret
= current
->ret_stack
[index
].ret
;
96 trace
->func
= current
->ret_stack
[index
].func
;
97 trace
->calltime
= current
->ret_stack
[index
].calltime
;
98 trace
->overrun
= atomic_read(¤t
->trace_overrun
);
101 current
->curr_ret_stack
--;
106 * Send the trace to the ring-buffer.
107 * @return the original return address.
109 unsigned long ftrace_return_to_handler(void)
111 struct ftrace_graph_ret trace
;
114 ftrace_pop_return_trace(&trace
, &ret
);
115 trace
.rettime
= trace_clock_local();
116 ftrace_graph_return(&trace
);
118 if (unlikely(!ret
)) {
121 /* Might as well panic. What else to do? */
122 ret
= (unsigned long)panic
;
128 static int graph_trace_init(struct trace_array
*tr
)
130 int ret
= register_ftrace_graph(&trace_graph_return
,
134 tracing_start_cmdline_record();
139 static void graph_trace_reset(struct trace_array
*tr
)
141 tracing_stop_cmdline_record();
142 unregister_ftrace_graph();
145 static inline int log10_cpu(int nb
)
154 static enum print_line_t
155 print_graph_cpu(struct trace_seq
*s
, int cpu
)
159 int log10_this
= log10_cpu(cpu
);
160 int log10_all
= log10_cpu(cpumask_weight(cpu_online_mask
));
164 * Start with a space character - to make it stand out
165 * to the right a bit when trace output is pasted into
168 ret
= trace_seq_printf(s
, " ");
171 * Tricky - we space the CPU field according to the max
172 * number of online CPUs. On a 2-cpu system it would take
173 * a maximum of 1 digit - on a 128 cpu system it would
174 * take up to 3 digits:
176 for (i
= 0; i
< log10_all
- log10_this
; i
++) {
177 ret
= trace_seq_printf(s
, " ");
179 return TRACE_TYPE_PARTIAL_LINE
;
181 ret
= trace_seq_printf(s
, "%d) ", cpu
);
183 return TRACE_TYPE_PARTIAL_LINE
;
185 return TRACE_TYPE_HANDLED
;
188 #define TRACE_GRAPH_PROCINFO_LENGTH 14
190 static enum print_line_t
191 print_graph_proc(struct trace_seq
*s
, pid_t pid
)
193 char comm
[TASK_COMM_LEN
];
194 /* sign + log10(MAX_INT) + '\0' */
201 trace_find_cmdline(pid
, comm
);
203 sprintf(pid_str
, "%d", pid
);
205 /* 1 stands for the "-" character */
206 len
= strlen(comm
) + strlen(pid_str
) + 1;
208 if (len
< TRACE_GRAPH_PROCINFO_LENGTH
)
209 spaces
= TRACE_GRAPH_PROCINFO_LENGTH
- len
;
211 /* First spaces to align center */
212 for (i
= 0; i
< spaces
/ 2; i
++) {
213 ret
= trace_seq_printf(s
, " ");
215 return TRACE_TYPE_PARTIAL_LINE
;
218 ret
= trace_seq_printf(s
, "%s-%s", comm
, pid_str
);
220 return TRACE_TYPE_PARTIAL_LINE
;
222 /* Last spaces to align center */
223 for (i
= 0; i
< spaces
- (spaces
/ 2); i
++) {
224 ret
= trace_seq_printf(s
, " ");
226 return TRACE_TYPE_PARTIAL_LINE
;
228 return TRACE_TYPE_HANDLED
;
232 /* If the pid changed since the last trace, output this event */
233 static enum print_line_t
234 verif_pid(struct trace_seq
*s
, pid_t pid
, int cpu
, pid_t
*last_pids_cpu
)
241 return TRACE_TYPE_HANDLED
;
243 last_pid
= per_cpu_ptr(last_pids_cpu
, cpu
);
245 if (*last_pid
== pid
)
246 return TRACE_TYPE_HANDLED
;
248 prev_pid
= *last_pid
;
252 return TRACE_TYPE_HANDLED
;
254 * Context-switch trace line:
256 ------------------------------------------
257 | 1) migration/0--1 => sshd-1755
258 ------------------------------------------
261 ret
= trace_seq_printf(s
,
262 " ------------------------------------------\n");
264 return TRACE_TYPE_PARTIAL_LINE
;
266 ret
= print_graph_cpu(s
, cpu
);
267 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
268 return TRACE_TYPE_PARTIAL_LINE
;
270 ret
= print_graph_proc(s
, prev_pid
);
271 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
272 return TRACE_TYPE_PARTIAL_LINE
;
274 ret
= trace_seq_printf(s
, " => ");
276 return TRACE_TYPE_PARTIAL_LINE
;
278 ret
= print_graph_proc(s
, pid
);
279 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
280 return TRACE_TYPE_PARTIAL_LINE
;
282 ret
= trace_seq_printf(s
,
283 "\n ------------------------------------------\n\n");
285 return TRACE_TYPE_PARTIAL_LINE
;
287 return TRACE_TYPE_HANDLED
;
290 static struct ftrace_graph_ret_entry
*
291 get_return_for_leaf(struct trace_iterator
*iter
,
292 struct ftrace_graph_ent_entry
*curr
)
294 struct ring_buffer_iter
*ring_iter
;
295 struct ring_buffer_event
*event
;
296 struct ftrace_graph_ret_entry
*next
;
298 ring_iter
= iter
->buffer_iter
[iter
->cpu
];
300 /* First peek to compare current entry and the next one */
302 event
= ring_buffer_iter_peek(ring_iter
, NULL
);
304 /* We need to consume the current entry to see the next one */
305 ring_buffer_consume(iter
->tr
->buffer
, iter
->cpu
, NULL
);
306 event
= ring_buffer_peek(iter
->tr
->buffer
, iter
->cpu
,
313 next
= ring_buffer_event_data(event
);
315 if (next
->ent
.type
!= TRACE_GRAPH_RET
)
318 if (curr
->ent
.pid
!= next
->ent
.pid
||
319 curr
->graph_ent
.func
!= next
->ret
.func
)
322 /* this is a leaf, now advance the iterator */
324 ring_buffer_read(ring_iter
, NULL
);
329 /* Signal a overhead of time execution to the output */
331 print_graph_overhead(unsigned long long duration
, struct trace_seq
*s
)
333 /* If duration disappear, we don't need anything */
334 if (!(tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
))
337 /* Non nested entry or return */
339 return trace_seq_printf(s
, " ");
341 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_OVERHEAD
) {
342 /* Duration exceeded 100 msecs */
343 if (duration
> 100000ULL)
344 return trace_seq_printf(s
, "! ");
346 /* Duration exceeded 10 msecs */
347 if (duration
> 10000ULL)
348 return trace_seq_printf(s
, "+ ");
351 return trace_seq_printf(s
, " ");
354 static int print_graph_abs_time(u64 t
, struct trace_seq
*s
)
356 unsigned long usecs_rem
;
358 usecs_rem
= do_div(t
, NSEC_PER_SEC
);
361 return trace_seq_printf(s
, "%5lu.%06lu | ",
362 (unsigned long)t
, usecs_rem
);
365 static enum print_line_t
366 print_graph_irq(struct trace_iterator
*iter
, unsigned long addr
,
367 enum trace_type type
, int cpu
, pid_t pid
)
370 struct trace_seq
*s
= &iter
->seq
;
372 if (addr
< (unsigned long)__irqentry_text_start
||
373 addr
>= (unsigned long)__irqentry_text_end
)
374 return TRACE_TYPE_UNHANDLED
;
377 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
) {
378 ret
= print_graph_abs_time(iter
->ts
, s
);
380 return TRACE_TYPE_PARTIAL_LINE
;
384 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
) {
385 ret
= print_graph_cpu(s
, cpu
);
386 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
387 return TRACE_TYPE_PARTIAL_LINE
;
390 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
) {
391 ret
= print_graph_proc(s
, pid
);
392 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
393 return TRACE_TYPE_PARTIAL_LINE
;
394 ret
= trace_seq_printf(s
, " | ");
396 return TRACE_TYPE_PARTIAL_LINE
;
400 ret
= print_graph_overhead(-1, s
);
402 return TRACE_TYPE_PARTIAL_LINE
;
404 if (type
== TRACE_GRAPH_ENT
)
405 ret
= trace_seq_printf(s
, "==========>");
407 ret
= trace_seq_printf(s
, "<==========");
410 return TRACE_TYPE_PARTIAL_LINE
;
412 /* Don't close the duration column if haven't one */
413 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
414 trace_seq_printf(s
, " |");
415 ret
= trace_seq_printf(s
, "\n");
418 return TRACE_TYPE_PARTIAL_LINE
;
419 return TRACE_TYPE_HANDLED
;
422 static enum print_line_t
423 print_graph_duration(unsigned long long duration
, struct trace_seq
*s
)
425 unsigned long nsecs_rem
= do_div(duration
, 1000);
426 /* log10(ULONG_MAX) + '\0' */
432 sprintf(msecs_str
, "%lu", (unsigned long) duration
);
435 ret
= trace_seq_printf(s
, "%s", msecs_str
);
437 return TRACE_TYPE_PARTIAL_LINE
;
439 len
= strlen(msecs_str
);
441 /* Print nsecs (we don't want to exceed 7 numbers) */
443 snprintf(nsecs_str
, 8 - len
, "%03lu", nsecs_rem
);
444 ret
= trace_seq_printf(s
, ".%s", nsecs_str
);
446 return TRACE_TYPE_PARTIAL_LINE
;
447 len
+= strlen(nsecs_str
);
450 ret
= trace_seq_printf(s
, " us ");
452 return TRACE_TYPE_PARTIAL_LINE
;
454 /* Print remaining spaces to fit the row's width */
455 for (i
= len
; i
< 7; i
++) {
456 ret
= trace_seq_printf(s
, " ");
458 return TRACE_TYPE_PARTIAL_LINE
;
461 ret
= trace_seq_printf(s
, "| ");
463 return TRACE_TYPE_PARTIAL_LINE
;
464 return TRACE_TYPE_HANDLED
;
468 /* Case of a leaf function on its call entry */
469 static enum print_line_t
470 print_graph_entry_leaf(struct trace_iterator
*iter
,
471 struct ftrace_graph_ent_entry
*entry
,
472 struct ftrace_graph_ret_entry
*ret_entry
, struct trace_seq
*s
)
474 struct ftrace_graph_ret
*graph_ret
;
475 struct ftrace_graph_ent
*call
;
476 unsigned long long duration
;
480 graph_ret
= &ret_entry
->ret
;
481 call
= &entry
->graph_ent
;
482 duration
= graph_ret
->rettime
- graph_ret
->calltime
;
485 ret
= print_graph_overhead(duration
, s
);
487 return TRACE_TYPE_PARTIAL_LINE
;
490 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
491 ret
= print_graph_duration(duration
, s
);
492 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
493 return TRACE_TYPE_PARTIAL_LINE
;
497 for (i
= 0; i
< call
->depth
* TRACE_GRAPH_INDENT
; i
++) {
498 ret
= trace_seq_printf(s
, " ");
500 return TRACE_TYPE_PARTIAL_LINE
;
503 ret
= seq_print_ip_sym(s
, call
->func
, 0);
505 return TRACE_TYPE_PARTIAL_LINE
;
507 ret
= trace_seq_printf(s
, "();\n");
509 return TRACE_TYPE_PARTIAL_LINE
;
511 return TRACE_TYPE_HANDLED
;
514 static enum print_line_t
515 print_graph_entry_nested(struct ftrace_graph_ent_entry
*entry
,
516 struct trace_seq
*s
, pid_t pid
, int cpu
)
520 struct ftrace_graph_ent
*call
= &entry
->graph_ent
;
523 ret
= print_graph_overhead(-1, s
);
525 return TRACE_TYPE_PARTIAL_LINE
;
528 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
529 ret
= trace_seq_printf(s
, " | ");
531 return TRACE_TYPE_PARTIAL_LINE
;
535 for (i
= 0; i
< call
->depth
* TRACE_GRAPH_INDENT
; i
++) {
536 ret
= trace_seq_printf(s
, " ");
538 return TRACE_TYPE_PARTIAL_LINE
;
541 ret
= seq_print_ip_sym(s
, call
->func
, 0);
543 return TRACE_TYPE_PARTIAL_LINE
;
545 ret
= trace_seq_printf(s
, "() {\n");
547 return TRACE_TYPE_PARTIAL_LINE
;
550 * we already consumed the current entry to check the next one
551 * and see if this is a leaf.
553 return TRACE_TYPE_NO_CONSUME
;
556 static enum print_line_t
557 print_graph_entry(struct ftrace_graph_ent_entry
*field
, struct trace_seq
*s
,
558 struct trace_iterator
*iter
)
562 pid_t
*last_entry
= iter
->private;
563 struct trace_entry
*ent
= iter
->ent
;
564 struct ftrace_graph_ent
*call
= &field
->graph_ent
;
565 struct ftrace_graph_ret_entry
*leaf_ret
;
568 if (verif_pid(s
, ent
->pid
, cpu
, last_entry
) == TRACE_TYPE_PARTIAL_LINE
)
569 return TRACE_TYPE_PARTIAL_LINE
;
572 ret
= print_graph_irq(iter
, call
->func
, TRACE_GRAPH_ENT
, cpu
, ent
->pid
);
573 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
574 return TRACE_TYPE_PARTIAL_LINE
;
577 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
) {
578 ret
= print_graph_abs_time(iter
->ts
, s
);
580 return TRACE_TYPE_PARTIAL_LINE
;
584 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
) {
585 ret
= print_graph_cpu(s
, cpu
);
586 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
587 return TRACE_TYPE_PARTIAL_LINE
;
591 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
) {
592 ret
= print_graph_proc(s
, ent
->pid
);
593 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
594 return TRACE_TYPE_PARTIAL_LINE
;
596 ret
= trace_seq_printf(s
, " | ");
598 return TRACE_TYPE_PARTIAL_LINE
;
601 leaf_ret
= get_return_for_leaf(iter
, field
);
603 return print_graph_entry_leaf(iter
, field
, leaf_ret
, s
);
605 return print_graph_entry_nested(field
, s
, iter
->ent
->pid
, cpu
);
609 static enum print_line_t
610 print_graph_return(struct ftrace_graph_ret
*trace
, struct trace_seq
*s
,
611 struct trace_entry
*ent
, struct trace_iterator
*iter
)
616 pid_t
*last_pid
= iter
->private, pid
= ent
->pid
;
617 unsigned long long duration
= trace
->rettime
- trace
->calltime
;
620 if (verif_pid(s
, pid
, cpu
, last_pid
) == TRACE_TYPE_PARTIAL_LINE
)
621 return TRACE_TYPE_PARTIAL_LINE
;
624 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
) {
625 ret
= print_graph_abs_time(iter
->ts
, s
);
627 return TRACE_TYPE_PARTIAL_LINE
;
631 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
) {
632 ret
= print_graph_cpu(s
, cpu
);
633 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
634 return TRACE_TYPE_PARTIAL_LINE
;
638 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
) {
639 ret
= print_graph_proc(s
, ent
->pid
);
640 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
641 return TRACE_TYPE_PARTIAL_LINE
;
643 ret
= trace_seq_printf(s
, " | ");
645 return TRACE_TYPE_PARTIAL_LINE
;
649 ret
= print_graph_overhead(duration
, s
);
651 return TRACE_TYPE_PARTIAL_LINE
;
654 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
655 ret
= print_graph_duration(duration
, s
);
656 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
657 return TRACE_TYPE_PARTIAL_LINE
;
661 for (i
= 0; i
< trace
->depth
* TRACE_GRAPH_INDENT
; i
++) {
662 ret
= trace_seq_printf(s
, " ");
664 return TRACE_TYPE_PARTIAL_LINE
;
667 ret
= trace_seq_printf(s
, "}\n");
669 return TRACE_TYPE_PARTIAL_LINE
;
672 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_OVERRUN
) {
673 ret
= trace_seq_printf(s
, " (Overruns: %lu)\n",
676 return TRACE_TYPE_PARTIAL_LINE
;
679 ret
= print_graph_irq(iter
, trace
->func
, TRACE_GRAPH_RET
, cpu
, pid
);
680 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
681 return TRACE_TYPE_PARTIAL_LINE
;
683 return TRACE_TYPE_HANDLED
;
686 static enum print_line_t
687 print_graph_comment(struct bprint_entry
*trace
, struct trace_seq
*s
,
688 struct trace_entry
*ent
, struct trace_iterator
*iter
)
693 pid_t
*last_pid
= iter
->private;
696 if (verif_pid(s
, ent
->pid
, cpu
, last_pid
) == TRACE_TYPE_PARTIAL_LINE
)
697 return TRACE_TYPE_PARTIAL_LINE
;
700 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
) {
701 ret
= print_graph_abs_time(iter
->ts
, s
);
703 return TRACE_TYPE_PARTIAL_LINE
;
707 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
) {
708 ret
= print_graph_cpu(s
, cpu
);
709 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
710 return TRACE_TYPE_PARTIAL_LINE
;
714 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
) {
715 ret
= print_graph_proc(s
, ent
->pid
);
716 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
717 return TRACE_TYPE_PARTIAL_LINE
;
719 ret
= trace_seq_printf(s
, " | ");
721 return TRACE_TYPE_PARTIAL_LINE
;
725 ret
= print_graph_overhead(-1, s
);
727 return TRACE_TYPE_PARTIAL_LINE
;
730 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
731 ret
= trace_seq_printf(s
, " | ");
733 return TRACE_TYPE_PARTIAL_LINE
;
737 if (trace
->depth
> 0)
738 for (i
= 0; i
< (trace
->depth
+ 1) * TRACE_GRAPH_INDENT
; i
++) {
739 ret
= trace_seq_printf(s
, " ");
741 return TRACE_TYPE_PARTIAL_LINE
;
745 ret
= trace_seq_printf(s
, "/* ");
747 return TRACE_TYPE_PARTIAL_LINE
;
749 ret
= trace_seq_bprintf(s
, trace
->fmt
, trace
->buf
);
751 return TRACE_TYPE_PARTIAL_LINE
;
753 /* Strip ending newline */
754 if (s
->buffer
[s
->len
- 1] == '\n') {
755 s
->buffer
[s
->len
- 1] = '\0';
759 ret
= trace_seq_printf(s
, " */\n");
761 return TRACE_TYPE_PARTIAL_LINE
;
763 return TRACE_TYPE_HANDLED
;
768 print_graph_function(struct trace_iterator
*iter
)
770 struct trace_seq
*s
= &iter
->seq
;
771 struct trace_entry
*entry
= iter
->ent
;
773 switch (entry
->type
) {
774 case TRACE_GRAPH_ENT
: {
775 struct ftrace_graph_ent_entry
*field
;
776 trace_assign_type(field
, entry
);
777 return print_graph_entry(field
, s
, iter
);
779 case TRACE_GRAPH_RET
: {
780 struct ftrace_graph_ret_entry
*field
;
781 trace_assign_type(field
, entry
);
782 return print_graph_return(&field
->ret
, s
, entry
, iter
);
785 struct bprint_entry
*field
;
786 trace_assign_type(field
, entry
);
787 return print_graph_comment(field
, s
, entry
, iter
);
790 return TRACE_TYPE_UNHANDLED
;
794 static void print_graph_headers(struct seq_file
*s
)
798 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
)
799 seq_printf(s
, " TIME ");
800 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
)
801 seq_printf(s
, "CPU");
802 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
)
803 seq_printf(s
, " TASK/PID ");
804 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
805 seq_printf(s
, " DURATION ");
806 seq_printf(s
, " FUNCTION CALLS\n");
810 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
)
811 seq_printf(s
, " | ");
812 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
)
814 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
)
815 seq_printf(s
, " | | ");
816 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
817 seq_printf(s
, " | | ");
818 seq_printf(s
, " | | | |\n");
821 static void graph_trace_open(struct trace_iterator
*iter
)
823 /* pid on the last trace processed */
824 pid_t
*last_pid
= alloc_percpu(pid_t
);
828 pr_warning("function graph tracer: not enough memory\n");
830 for_each_possible_cpu(cpu
) {
831 pid_t
*pid
= per_cpu_ptr(last_pid
, cpu
);
835 iter
->private = last_pid
;
838 static void graph_trace_close(struct trace_iterator
*iter
)
840 free_percpu(iter
->private);
843 static struct tracer graph_trace __read_mostly
= {
844 .name
= "function_graph",
845 .open
= graph_trace_open
,
846 .close
= graph_trace_close
,
847 .wait_pipe
= poll_wait_pipe
,
848 .init
= graph_trace_init
,
849 .reset
= graph_trace_reset
,
850 .print_line
= print_graph_function
,
851 .print_header
= print_graph_headers
,
852 .flags
= &tracer_flags
,
853 #ifdef CONFIG_FTRACE_SELFTEST
854 .selftest
= trace_selftest_startup_function_graph
,
858 static __init
int init_graph_trace(void)
860 return register_tracer(&graph_trace
);
863 device_initcall(init_graph_trace
);