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"
22 #define TRACE_GRAPH_INDENT 2
25 #define TRACE_GRAPH_PRINT_OVERRUN 0x1
26 #define TRACE_GRAPH_PRINT_CPU 0x2
27 #define TRACE_GRAPH_PRINT_OVERHEAD 0x4
28 #define TRACE_GRAPH_PRINT_PROC 0x8
29 #define TRACE_GRAPH_PRINT_DURATION 0x10
30 #define TRACE_GRAPH_PRINT_ABS_TIME 0X20
32 static struct tracer_opt trace_opts
[] = {
33 /* Display overruns? (for self-debug purpose) */
34 { TRACER_OPT(funcgraph
-overrun
, TRACE_GRAPH_PRINT_OVERRUN
) },
36 { TRACER_OPT(funcgraph
-cpu
, TRACE_GRAPH_PRINT_CPU
) },
37 /* Display Overhead ? */
38 { TRACER_OPT(funcgraph
-overhead
, TRACE_GRAPH_PRINT_OVERHEAD
) },
39 /* Display proc name/pid */
40 { TRACER_OPT(funcgraph
-proc
, TRACE_GRAPH_PRINT_PROC
) },
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
) },
48 static struct tracer_flags tracer_flags
= {
49 /* Don't display overruns and proc by default */
50 .val
= TRACE_GRAPH_PRINT_CPU
| TRACE_GRAPH_PRINT_OVERHEAD
|
51 TRACE_GRAPH_PRINT_DURATION
,
55 /* pid on the last trace processed */
58 /* Add a function return address to the trace stack on thread info.*/
60 ftrace_push_return_trace(unsigned long ret
, unsigned long func
, int *depth
)
62 unsigned long long calltime
;
65 if (!current
->ret_stack
)
68 /* The return trace stack is full */
69 if (current
->curr_ret_stack
== FTRACE_RETFUNC_DEPTH
- 1) {
70 atomic_inc(¤t
->trace_overrun
);
74 calltime
= trace_clock_local();
76 index
= ++current
->curr_ret_stack
;
78 current
->ret_stack
[index
].ret
= ret
;
79 current
->ret_stack
[index
].func
= func
;
80 current
->ret_stack
[index
].calltime
= calltime
;
86 /* Retrieve a function return address to the trace stack on thread info.*/
88 ftrace_pop_return_trace(struct ftrace_graph_ret
*trace
, unsigned long *ret
)
92 index
= current
->curr_ret_stack
;
94 if (unlikely(index
< 0)) {
97 /* Might as well panic, otherwise we have no where to go */
98 *ret
= (unsigned long)panic
;
102 *ret
= current
->ret_stack
[index
].ret
;
103 trace
->func
= current
->ret_stack
[index
].func
;
104 trace
->calltime
= current
->ret_stack
[index
].calltime
;
105 trace
->overrun
= atomic_read(¤t
->trace_overrun
);
106 trace
->depth
= index
;
108 current
->curr_ret_stack
--;
113 * Send the trace to the ring-buffer.
114 * @return the original return address.
116 unsigned long ftrace_return_to_handler(void)
118 struct ftrace_graph_ret trace
;
121 ftrace_pop_return_trace(&trace
, &ret
);
122 trace
.rettime
= trace_clock_local();
123 ftrace_graph_return(&trace
);
125 if (unlikely(!ret
)) {
128 /* Might as well panic. What else to do? */
129 ret
= (unsigned long)panic
;
135 static int graph_trace_init(struct trace_array
*tr
)
137 int ret
= register_ftrace_graph(&trace_graph_return
,
141 tracing_start_cmdline_record();
146 static void graph_trace_reset(struct trace_array
*tr
)
148 tracing_stop_cmdline_record();
149 unregister_ftrace_graph();
152 static inline int log10_cpu(int nb
)
161 static enum print_line_t
162 print_graph_cpu(struct trace_seq
*s
, int cpu
)
166 int log10_this
= log10_cpu(cpu
);
167 int log10_all
= log10_cpu(cpumask_weight(cpu_online_mask
));
171 * Start with a space character - to make it stand out
172 * to the right a bit when trace output is pasted into
175 ret
= trace_seq_printf(s
, " ");
178 * Tricky - we space the CPU field according to the max
179 * number of online CPUs. On a 2-cpu system it would take
180 * a maximum of 1 digit - on a 128 cpu system it would
181 * take up to 3 digits:
183 for (i
= 0; i
< log10_all
- log10_this
; i
++) {
184 ret
= trace_seq_printf(s
, " ");
186 return TRACE_TYPE_PARTIAL_LINE
;
188 ret
= trace_seq_printf(s
, "%d) ", cpu
);
190 return TRACE_TYPE_PARTIAL_LINE
;
192 return TRACE_TYPE_HANDLED
;
195 #define TRACE_GRAPH_PROCINFO_LENGTH 14
197 static enum print_line_t
198 print_graph_proc(struct trace_seq
*s
, pid_t pid
)
200 char comm
[TASK_COMM_LEN
];
201 /* sign + log10(MAX_INT) + '\0' */
208 trace_find_cmdline(pid
, comm
);
210 sprintf(pid_str
, "%d", pid
);
212 /* 1 stands for the "-" character */
213 len
= strlen(comm
) + strlen(pid_str
) + 1;
215 if (len
< TRACE_GRAPH_PROCINFO_LENGTH
)
216 spaces
= TRACE_GRAPH_PROCINFO_LENGTH
- len
;
218 /* First spaces to align center */
219 for (i
= 0; i
< spaces
/ 2; i
++) {
220 ret
= trace_seq_printf(s
, " ");
222 return TRACE_TYPE_PARTIAL_LINE
;
225 ret
= trace_seq_printf(s
, "%s-%s", comm
, pid_str
);
227 return TRACE_TYPE_PARTIAL_LINE
;
229 /* Last spaces to align center */
230 for (i
= 0; i
< spaces
- (spaces
/ 2); i
++) {
231 ret
= trace_seq_printf(s
, " ");
233 return TRACE_TYPE_PARTIAL_LINE
;
235 return TRACE_TYPE_HANDLED
;
239 /* If the pid changed since the last trace, output this event */
240 static enum print_line_t
241 verif_pid(struct trace_seq
*s
, pid_t pid
, int cpu
, struct fgraph_data
*data
)
248 return TRACE_TYPE_HANDLED
;
250 last_pid
= &(per_cpu_ptr(data
, cpu
)->last_pid
);
252 if (*last_pid
== pid
)
253 return TRACE_TYPE_HANDLED
;
255 prev_pid
= *last_pid
;
259 return TRACE_TYPE_HANDLED
;
261 * Context-switch trace line:
263 ------------------------------------------
264 | 1) migration/0--1 => sshd-1755
265 ------------------------------------------
268 ret
= trace_seq_printf(s
,
269 " ------------------------------------------\n");
271 return TRACE_TYPE_PARTIAL_LINE
;
273 ret
= print_graph_cpu(s
, cpu
);
274 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
275 return TRACE_TYPE_PARTIAL_LINE
;
277 ret
= print_graph_proc(s
, prev_pid
);
278 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
279 return TRACE_TYPE_PARTIAL_LINE
;
281 ret
= trace_seq_printf(s
, " => ");
283 return TRACE_TYPE_PARTIAL_LINE
;
285 ret
= print_graph_proc(s
, pid
);
286 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
287 return TRACE_TYPE_PARTIAL_LINE
;
289 ret
= trace_seq_printf(s
,
290 "\n ------------------------------------------\n\n");
292 return TRACE_TYPE_PARTIAL_LINE
;
294 return TRACE_TYPE_HANDLED
;
297 static struct ftrace_graph_ret_entry
*
298 get_return_for_leaf(struct trace_iterator
*iter
,
299 struct ftrace_graph_ent_entry
*curr
)
301 struct ring_buffer_iter
*ring_iter
;
302 struct ring_buffer_event
*event
;
303 struct ftrace_graph_ret_entry
*next
;
305 ring_iter
= iter
->buffer_iter
[iter
->cpu
];
307 /* First peek to compare current entry and the next one */
309 event
= ring_buffer_iter_peek(ring_iter
, NULL
);
311 /* We need to consume the current entry to see the next one */
312 ring_buffer_consume(iter
->tr
->buffer
, iter
->cpu
, NULL
);
313 event
= ring_buffer_peek(iter
->tr
->buffer
, iter
->cpu
,
320 next
= ring_buffer_event_data(event
);
322 if (next
->ent
.type
!= TRACE_GRAPH_RET
)
325 if (curr
->ent
.pid
!= next
->ent
.pid
||
326 curr
->graph_ent
.func
!= next
->ret
.func
)
329 /* this is a leaf, now advance the iterator */
331 ring_buffer_read(ring_iter
, NULL
);
336 /* Signal a overhead of time execution to the output */
338 print_graph_overhead(unsigned long long duration
, struct trace_seq
*s
)
340 /* If duration disappear, we don't need anything */
341 if (!(tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
))
344 /* Non nested entry or return */
346 return trace_seq_printf(s
, " ");
348 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_OVERHEAD
) {
349 /* Duration exceeded 100 msecs */
350 if (duration
> 100000ULL)
351 return trace_seq_printf(s
, "! ");
353 /* Duration exceeded 10 msecs */
354 if (duration
> 10000ULL)
355 return trace_seq_printf(s
, "+ ");
358 return trace_seq_printf(s
, " ");
361 static int print_graph_abs_time(u64 t
, struct trace_seq
*s
)
363 unsigned long usecs_rem
;
365 usecs_rem
= do_div(t
, NSEC_PER_SEC
);
368 return trace_seq_printf(s
, "%5lu.%06lu | ",
369 (unsigned long)t
, usecs_rem
);
372 static enum print_line_t
373 print_graph_irq(struct trace_iterator
*iter
, unsigned long addr
,
374 enum trace_type type
, int cpu
, pid_t pid
)
377 struct trace_seq
*s
= &iter
->seq
;
379 if (addr
< (unsigned long)__irqentry_text_start
||
380 addr
>= (unsigned long)__irqentry_text_end
)
381 return TRACE_TYPE_UNHANDLED
;
384 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
) {
385 ret
= print_graph_abs_time(iter
->ts
, s
);
387 return TRACE_TYPE_PARTIAL_LINE
;
391 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
) {
392 ret
= print_graph_cpu(s
, cpu
);
393 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
394 return TRACE_TYPE_PARTIAL_LINE
;
397 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
) {
398 ret
= print_graph_proc(s
, pid
);
399 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
400 return TRACE_TYPE_PARTIAL_LINE
;
401 ret
= trace_seq_printf(s
, " | ");
403 return TRACE_TYPE_PARTIAL_LINE
;
407 ret
= print_graph_overhead(-1, s
);
409 return TRACE_TYPE_PARTIAL_LINE
;
411 if (type
== TRACE_GRAPH_ENT
)
412 ret
= trace_seq_printf(s
, "==========>");
414 ret
= trace_seq_printf(s
, "<==========");
417 return TRACE_TYPE_PARTIAL_LINE
;
419 /* Don't close the duration column if haven't one */
420 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
421 trace_seq_printf(s
, " |");
422 ret
= trace_seq_printf(s
, "\n");
425 return TRACE_TYPE_PARTIAL_LINE
;
426 return TRACE_TYPE_HANDLED
;
429 static enum print_line_t
430 print_graph_duration(unsigned long long duration
, struct trace_seq
*s
)
432 unsigned long nsecs_rem
= do_div(duration
, 1000);
433 /* log10(ULONG_MAX) + '\0' */
439 sprintf(msecs_str
, "%lu", (unsigned long) duration
);
442 ret
= trace_seq_printf(s
, "%s", msecs_str
);
444 return TRACE_TYPE_PARTIAL_LINE
;
446 len
= strlen(msecs_str
);
448 /* Print nsecs (we don't want to exceed 7 numbers) */
450 snprintf(nsecs_str
, 8 - len
, "%03lu", nsecs_rem
);
451 ret
= trace_seq_printf(s
, ".%s", nsecs_str
);
453 return TRACE_TYPE_PARTIAL_LINE
;
454 len
+= strlen(nsecs_str
);
457 ret
= trace_seq_printf(s
, " us ");
459 return TRACE_TYPE_PARTIAL_LINE
;
461 /* Print remaining spaces to fit the row's width */
462 for (i
= len
; i
< 7; i
++) {
463 ret
= trace_seq_printf(s
, " ");
465 return TRACE_TYPE_PARTIAL_LINE
;
468 ret
= trace_seq_printf(s
, "| ");
470 return TRACE_TYPE_PARTIAL_LINE
;
471 return TRACE_TYPE_HANDLED
;
475 /* Case of a leaf function on its call entry */
476 static enum print_line_t
477 print_graph_entry_leaf(struct trace_iterator
*iter
,
478 struct ftrace_graph_ent_entry
*entry
,
479 struct ftrace_graph_ret_entry
*ret_entry
, struct trace_seq
*s
)
481 struct fgraph_data
*data
= iter
->private;
482 struct ftrace_graph_ret
*graph_ret
;
483 struct ftrace_graph_ent
*call
;
484 unsigned long long duration
;
488 graph_ret
= &ret_entry
->ret
;
489 call
= &entry
->graph_ent
;
490 duration
= graph_ret
->rettime
- graph_ret
->calltime
;
494 int *depth
= &(per_cpu_ptr(data
, cpu
)->depth
);
497 * Comments display at + 1 to depth. Since
498 * this is a leaf function, keep the comments
499 * equal to this depth.
501 *depth
= call
->depth
- 1;
505 ret
= print_graph_overhead(duration
, s
);
507 return TRACE_TYPE_PARTIAL_LINE
;
510 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
511 ret
= print_graph_duration(duration
, s
);
512 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
513 return TRACE_TYPE_PARTIAL_LINE
;
517 for (i
= 0; i
< call
->depth
* TRACE_GRAPH_INDENT
; i
++) {
518 ret
= trace_seq_printf(s
, " ");
520 return TRACE_TYPE_PARTIAL_LINE
;
523 ret
= seq_print_ip_sym(s
, call
->func
, 0);
525 return TRACE_TYPE_PARTIAL_LINE
;
527 ret
= trace_seq_printf(s
, "();\n");
529 return TRACE_TYPE_PARTIAL_LINE
;
531 return TRACE_TYPE_HANDLED
;
534 static enum print_line_t
535 print_graph_entry_nested(struct trace_iterator
*iter
,
536 struct ftrace_graph_ent_entry
*entry
,
537 struct trace_seq
*s
, int cpu
)
539 struct ftrace_graph_ent
*call
= &entry
->graph_ent
;
540 struct fgraph_data
*data
= iter
->private;
546 int *depth
= &(per_cpu_ptr(data
, cpu
)->depth
);
548 *depth
= call
->depth
;
552 ret
= print_graph_overhead(-1, s
);
554 return TRACE_TYPE_PARTIAL_LINE
;
557 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
558 ret
= trace_seq_printf(s
, " | ");
560 return TRACE_TYPE_PARTIAL_LINE
;
564 for (i
= 0; i
< call
->depth
* TRACE_GRAPH_INDENT
; i
++) {
565 ret
= trace_seq_printf(s
, " ");
567 return TRACE_TYPE_PARTIAL_LINE
;
570 ret
= seq_print_ip_sym(s
, call
->func
, 0);
572 return TRACE_TYPE_PARTIAL_LINE
;
574 ret
= trace_seq_printf(s
, "() {\n");
576 return TRACE_TYPE_PARTIAL_LINE
;
579 * we already consumed the current entry to check the next one
580 * and see if this is a leaf.
582 return TRACE_TYPE_NO_CONSUME
;
585 static enum print_line_t
586 print_graph_prologue(struct trace_iterator
*iter
, struct trace_seq
*s
,
587 int type
, unsigned long addr
)
589 struct fgraph_data
*data
= iter
->private;
590 struct trace_entry
*ent
= iter
->ent
;
595 if (verif_pid(s
, ent
->pid
, cpu
, data
) == TRACE_TYPE_PARTIAL_LINE
)
596 return TRACE_TYPE_PARTIAL_LINE
;
600 ret
= print_graph_irq(iter
, addr
, type
, cpu
, ent
->pid
);
601 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
602 return TRACE_TYPE_PARTIAL_LINE
;
606 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
) {
607 ret
= print_graph_abs_time(iter
->ts
, s
);
609 return TRACE_TYPE_PARTIAL_LINE
;
613 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
) {
614 ret
= print_graph_cpu(s
, cpu
);
615 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
616 return TRACE_TYPE_PARTIAL_LINE
;
620 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
) {
621 ret
= print_graph_proc(s
, ent
->pid
);
622 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
623 return TRACE_TYPE_PARTIAL_LINE
;
625 ret
= trace_seq_printf(s
, " | ");
627 return TRACE_TYPE_PARTIAL_LINE
;
633 static enum print_line_t
634 print_graph_entry(struct ftrace_graph_ent_entry
*field
, struct trace_seq
*s
,
635 struct trace_iterator
*iter
)
638 struct ftrace_graph_ent
*call
= &field
->graph_ent
;
639 struct ftrace_graph_ret_entry
*leaf_ret
;
641 if (print_graph_prologue(iter
, s
, TRACE_GRAPH_ENT
, call
->func
))
642 return TRACE_TYPE_PARTIAL_LINE
;
644 leaf_ret
= get_return_for_leaf(iter
, field
);
646 return print_graph_entry_leaf(iter
, field
, leaf_ret
, s
);
648 return print_graph_entry_nested(iter
, field
, s
, cpu
);
652 static enum print_line_t
653 print_graph_return(struct ftrace_graph_ret
*trace
, struct trace_seq
*s
,
654 struct trace_entry
*ent
, struct trace_iterator
*iter
)
656 unsigned long long duration
= trace
->rettime
- trace
->calltime
;
657 struct fgraph_data
*data
= iter
->private;
658 pid_t pid
= ent
->pid
;
665 int *depth
= &(per_cpu_ptr(data
, cpu
)->depth
);
668 * Comments display at + 1 to depth. This is the
669 * return from a function, we now want the comments
670 * to display at the same level of the bracket.
672 *depth
= trace
->depth
- 1;
675 if (print_graph_prologue(iter
, s
, 0, 0))
676 return TRACE_TYPE_PARTIAL_LINE
;
679 ret
= print_graph_overhead(duration
, s
);
681 return TRACE_TYPE_PARTIAL_LINE
;
684 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
685 ret
= print_graph_duration(duration
, s
);
686 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
687 return TRACE_TYPE_PARTIAL_LINE
;
691 for (i
= 0; i
< trace
->depth
* TRACE_GRAPH_INDENT
; i
++) {
692 ret
= trace_seq_printf(s
, " ");
694 return TRACE_TYPE_PARTIAL_LINE
;
697 ret
= trace_seq_printf(s
, "}\n");
699 return TRACE_TYPE_PARTIAL_LINE
;
702 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_OVERRUN
) {
703 ret
= trace_seq_printf(s
, " (Overruns: %lu)\n",
706 return TRACE_TYPE_PARTIAL_LINE
;
709 ret
= print_graph_irq(iter
, trace
->func
, TRACE_GRAPH_RET
, cpu
, pid
);
710 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
711 return TRACE_TYPE_PARTIAL_LINE
;
713 return TRACE_TYPE_HANDLED
;
716 static enum print_line_t
717 print_graph_comment(struct trace_seq
*s
, struct trace_entry
*ent
,
718 struct trace_iterator
*iter
)
720 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
721 struct fgraph_data
*data
= iter
->private;
722 struct trace_event
*event
;
728 depth
= per_cpu_ptr(data
, iter
->cpu
)->depth
;
730 if (print_graph_prologue(iter
, s
, 0, 0))
731 return TRACE_TYPE_PARTIAL_LINE
;
734 ret
= print_graph_overhead(-1, s
);
736 return TRACE_TYPE_PARTIAL_LINE
;
739 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
740 ret
= trace_seq_printf(s
, " | ");
742 return TRACE_TYPE_PARTIAL_LINE
;
747 for (i
= 0; i
< (depth
+ 1) * TRACE_GRAPH_INDENT
; i
++) {
748 ret
= trace_seq_printf(s
, " ");
750 return TRACE_TYPE_PARTIAL_LINE
;
754 ret
= trace_seq_printf(s
, "/* ");
756 return TRACE_TYPE_PARTIAL_LINE
;
758 switch (iter
->ent
->type
) {
760 ret
= trace_print_bprintk_msg_only(iter
);
761 if (ret
!= TRACE_TYPE_HANDLED
)
765 ret
= trace_print_printk_msg_only(iter
);
766 if (ret
!= TRACE_TYPE_HANDLED
)
770 event
= ftrace_find_event(ent
->type
);
772 return TRACE_TYPE_UNHANDLED
;
774 ret
= event
->trace(iter
, sym_flags
);
775 if (ret
!= TRACE_TYPE_HANDLED
)
779 /* Strip ending newline */
780 if (s
->buffer
[s
->len
- 1] == '\n') {
781 s
->buffer
[s
->len
- 1] = '\0';
785 ret
= trace_seq_printf(s
, " */\n");
787 return TRACE_TYPE_PARTIAL_LINE
;
789 return TRACE_TYPE_HANDLED
;
794 print_graph_function(struct trace_iterator
*iter
)
796 struct trace_entry
*entry
= iter
->ent
;
797 struct trace_seq
*s
= &iter
->seq
;
799 switch (entry
->type
) {
800 case TRACE_GRAPH_ENT
: {
801 struct ftrace_graph_ent_entry
*field
;
802 trace_assign_type(field
, entry
);
803 return print_graph_entry(field
, s
, iter
);
805 case TRACE_GRAPH_RET
: {
806 struct ftrace_graph_ret_entry
*field
;
807 trace_assign_type(field
, entry
);
808 return print_graph_return(&field
->ret
, s
, entry
, iter
);
811 return print_graph_comment(s
, entry
, iter
);
814 return TRACE_TYPE_HANDLED
;
817 static void print_graph_headers(struct seq_file
*s
)
821 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
)
822 seq_printf(s
, " TIME ");
823 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
)
824 seq_printf(s
, "CPU");
825 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
)
826 seq_printf(s
, " TASK/PID ");
827 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
828 seq_printf(s
, " DURATION ");
829 seq_printf(s
, " FUNCTION CALLS\n");
833 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
)
834 seq_printf(s
, " | ");
835 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
)
837 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
)
838 seq_printf(s
, " | | ");
839 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
840 seq_printf(s
, " | | ");
841 seq_printf(s
, " | | | |\n");
844 static void graph_trace_open(struct trace_iterator
*iter
)
846 /* pid and depth on the last trace processed */
847 struct fgraph_data
*data
= alloc_percpu(struct fgraph_data
);
851 pr_warning("function graph tracer: not enough memory\n");
853 for_each_possible_cpu(cpu
) {
854 pid_t
*pid
= &(per_cpu_ptr(data
, cpu
)->last_pid
);
855 int *depth
= &(per_cpu_ptr(data
, cpu
)->depth
);
860 iter
->private = data
;
863 static void graph_trace_close(struct trace_iterator
*iter
)
865 free_percpu(iter
->private);
868 static struct tracer graph_trace __read_mostly
= {
869 .name
= "function_graph",
870 .open
= graph_trace_open
,
871 .close
= graph_trace_close
,
872 .wait_pipe
= poll_wait_pipe
,
873 .init
= graph_trace_init
,
874 .reset
= graph_trace_reset
,
875 .print_line
= print_graph_function
,
876 .print_header
= print_graph_headers
,
877 .flags
= &tracer_flags
,
878 #ifdef CONFIG_FTRACE_SELFTEST
879 .selftest
= trace_selftest_startup_function_graph
,
883 static __init
int init_graph_trace(void)
885 return register_tracer(&graph_trace
);
888 device_initcall(init_graph_trace
);