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
,
61 unsigned long frame_pointer
)
63 unsigned long long calltime
;
66 if (!current
->ret_stack
)
70 * We must make sure the ret_stack is tested before we read
75 /* The return trace stack is full */
76 if (current
->curr_ret_stack
== FTRACE_RETFUNC_DEPTH
- 1) {
77 atomic_inc(¤t
->trace_overrun
);
81 calltime
= trace_clock_local();
83 index
= ++current
->curr_ret_stack
;
85 current
->ret_stack
[index
].ret
= ret
;
86 current
->ret_stack
[index
].func
= func
;
87 current
->ret_stack
[index
].calltime
= calltime
;
88 current
->ret_stack
[index
].subtime
= 0;
89 current
->ret_stack
[index
].fp
= frame_pointer
;
95 /* Retrieve a function return address to the trace stack on thread info.*/
97 ftrace_pop_return_trace(struct ftrace_graph_ret
*trace
, unsigned long *ret
,
98 unsigned long frame_pointer
)
102 index
= current
->curr_ret_stack
;
104 if (unlikely(index
< 0)) {
107 /* Might as well panic, otherwise we have no where to go */
108 *ret
= (unsigned long)panic
;
112 #ifdef CONFIG_HAVE_FUNCTION_GRAPH_FP_TEST
114 * The arch may choose to record the frame pointer used
115 * and check it here to make sure that it is what we expect it
116 * to be. If gcc does not set the place holder of the return
117 * address in the frame pointer, and does a copy instead, then
118 * the function graph trace will fail. This test detects this
121 * Currently, x86_32 with optimize for size (-Os) makes the latest
124 if (unlikely(current
->ret_stack
[index
].fp
!= frame_pointer
)) {
126 WARN(1, "Bad frame pointer: expected %lx, received %lx\n"
127 " from func %pF return to %lx\n",
128 current
->ret_stack
[index
].fp
,
130 (void *)current
->ret_stack
[index
].func
,
131 current
->ret_stack
[index
].ret
);
132 *ret
= (unsigned long)panic
;
137 *ret
= current
->ret_stack
[index
].ret
;
138 trace
->func
= current
->ret_stack
[index
].func
;
139 trace
->calltime
= current
->ret_stack
[index
].calltime
;
140 trace
->overrun
= atomic_read(¤t
->trace_overrun
);
141 trace
->depth
= index
;
145 * Send the trace to the ring-buffer.
146 * @return the original return address.
148 unsigned long ftrace_return_to_handler(unsigned long frame_pointer
)
150 struct ftrace_graph_ret trace
;
153 ftrace_pop_return_trace(&trace
, &ret
, frame_pointer
);
154 trace
.rettime
= trace_clock_local();
155 ftrace_graph_return(&trace
);
157 current
->curr_ret_stack
--;
159 if (unlikely(!ret
)) {
162 /* Might as well panic. What else to do? */
163 ret
= (unsigned long)panic
;
169 static int graph_trace_init(struct trace_array
*tr
)
171 int ret
= register_ftrace_graph(&trace_graph_return
,
175 tracing_start_cmdline_record();
180 static void graph_trace_reset(struct trace_array
*tr
)
182 tracing_stop_cmdline_record();
183 unregister_ftrace_graph();
186 static inline int log10_cpu(int nb
)
195 static enum print_line_t
196 print_graph_cpu(struct trace_seq
*s
, int cpu
)
200 int log10_this
= log10_cpu(cpu
);
201 int log10_all
= log10_cpu(cpumask_weight(cpu_online_mask
));
205 * Start with a space character - to make it stand out
206 * to the right a bit when trace output is pasted into
209 ret
= trace_seq_printf(s
, " ");
212 * Tricky - we space the CPU field according to the max
213 * number of online CPUs. On a 2-cpu system it would take
214 * a maximum of 1 digit - on a 128 cpu system it would
215 * take up to 3 digits:
217 for (i
= 0; i
< log10_all
- log10_this
; i
++) {
218 ret
= trace_seq_printf(s
, " ");
220 return TRACE_TYPE_PARTIAL_LINE
;
222 ret
= trace_seq_printf(s
, "%d) ", cpu
);
224 return TRACE_TYPE_PARTIAL_LINE
;
226 return TRACE_TYPE_HANDLED
;
229 #define TRACE_GRAPH_PROCINFO_LENGTH 14
231 static enum print_line_t
232 print_graph_proc(struct trace_seq
*s
, pid_t pid
)
234 char comm
[TASK_COMM_LEN
];
235 /* sign + log10(MAX_INT) + '\0' */
242 trace_find_cmdline(pid
, comm
);
244 sprintf(pid_str
, "%d", pid
);
246 /* 1 stands for the "-" character */
247 len
= strlen(comm
) + strlen(pid_str
) + 1;
249 if (len
< TRACE_GRAPH_PROCINFO_LENGTH
)
250 spaces
= TRACE_GRAPH_PROCINFO_LENGTH
- len
;
252 /* First spaces to align center */
253 for (i
= 0; i
< spaces
/ 2; i
++) {
254 ret
= trace_seq_printf(s
, " ");
256 return TRACE_TYPE_PARTIAL_LINE
;
259 ret
= trace_seq_printf(s
, "%s-%s", comm
, pid_str
);
261 return TRACE_TYPE_PARTIAL_LINE
;
263 /* Last spaces to align center */
264 for (i
= 0; i
< spaces
- (spaces
/ 2); i
++) {
265 ret
= trace_seq_printf(s
, " ");
267 return TRACE_TYPE_PARTIAL_LINE
;
269 return TRACE_TYPE_HANDLED
;
273 /* If the pid changed since the last trace, output this event */
274 static enum print_line_t
275 verif_pid(struct trace_seq
*s
, pid_t pid
, int cpu
, struct fgraph_data
*data
)
282 return TRACE_TYPE_HANDLED
;
284 last_pid
= &(per_cpu_ptr(data
, cpu
)->last_pid
);
286 if (*last_pid
== pid
)
287 return TRACE_TYPE_HANDLED
;
289 prev_pid
= *last_pid
;
293 return TRACE_TYPE_HANDLED
;
295 * Context-switch trace line:
297 ------------------------------------------
298 | 1) migration/0--1 => sshd-1755
299 ------------------------------------------
302 ret
= trace_seq_printf(s
,
303 " ------------------------------------------\n");
305 return TRACE_TYPE_PARTIAL_LINE
;
307 ret
= print_graph_cpu(s
, cpu
);
308 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
309 return TRACE_TYPE_PARTIAL_LINE
;
311 ret
= print_graph_proc(s
, prev_pid
);
312 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
313 return TRACE_TYPE_PARTIAL_LINE
;
315 ret
= trace_seq_printf(s
, " => ");
317 return TRACE_TYPE_PARTIAL_LINE
;
319 ret
= print_graph_proc(s
, pid
);
320 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
321 return TRACE_TYPE_PARTIAL_LINE
;
323 ret
= trace_seq_printf(s
,
324 "\n ------------------------------------------\n\n");
326 return TRACE_TYPE_PARTIAL_LINE
;
328 return TRACE_TYPE_HANDLED
;
331 static struct ftrace_graph_ret_entry
*
332 get_return_for_leaf(struct trace_iterator
*iter
,
333 struct ftrace_graph_ent_entry
*curr
)
335 struct ring_buffer_iter
*ring_iter
;
336 struct ring_buffer_event
*event
;
337 struct ftrace_graph_ret_entry
*next
;
339 ring_iter
= iter
->buffer_iter
[iter
->cpu
];
341 /* First peek to compare current entry and the next one */
343 event
= ring_buffer_iter_peek(ring_iter
, NULL
);
345 /* We need to consume the current entry to see the next one */
346 ring_buffer_consume(iter
->tr
->buffer
, iter
->cpu
, NULL
);
347 event
= ring_buffer_peek(iter
->tr
->buffer
, iter
->cpu
,
354 next
= ring_buffer_event_data(event
);
356 if (next
->ent
.type
!= TRACE_GRAPH_RET
)
359 if (curr
->ent
.pid
!= next
->ent
.pid
||
360 curr
->graph_ent
.func
!= next
->ret
.func
)
363 /* this is a leaf, now advance the iterator */
365 ring_buffer_read(ring_iter
, NULL
);
370 /* Signal a overhead of time execution to the output */
372 print_graph_overhead(unsigned long long duration
, struct trace_seq
*s
)
374 /* If duration disappear, we don't need anything */
375 if (!(tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
))
378 /* Non nested entry or return */
380 return trace_seq_printf(s
, " ");
382 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_OVERHEAD
) {
383 /* Duration exceeded 100 msecs */
384 if (duration
> 100000ULL)
385 return trace_seq_printf(s
, "! ");
387 /* Duration exceeded 10 msecs */
388 if (duration
> 10000ULL)
389 return trace_seq_printf(s
, "+ ");
392 return trace_seq_printf(s
, " ");
395 static int print_graph_abs_time(u64 t
, struct trace_seq
*s
)
397 unsigned long usecs_rem
;
399 usecs_rem
= do_div(t
, NSEC_PER_SEC
);
402 return trace_seq_printf(s
, "%5lu.%06lu | ",
403 (unsigned long)t
, usecs_rem
);
406 static enum print_line_t
407 print_graph_irq(struct trace_iterator
*iter
, unsigned long addr
,
408 enum trace_type type
, int cpu
, pid_t pid
)
411 struct trace_seq
*s
= &iter
->seq
;
413 if (addr
< (unsigned long)__irqentry_text_start
||
414 addr
>= (unsigned long)__irqentry_text_end
)
415 return TRACE_TYPE_UNHANDLED
;
418 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
) {
419 ret
= print_graph_abs_time(iter
->ts
, s
);
421 return TRACE_TYPE_PARTIAL_LINE
;
425 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
) {
426 ret
= print_graph_cpu(s
, cpu
);
427 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
428 return TRACE_TYPE_PARTIAL_LINE
;
431 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
) {
432 ret
= print_graph_proc(s
, pid
);
433 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
434 return TRACE_TYPE_PARTIAL_LINE
;
435 ret
= trace_seq_printf(s
, " | ");
437 return TRACE_TYPE_PARTIAL_LINE
;
441 ret
= print_graph_overhead(-1, s
);
443 return TRACE_TYPE_PARTIAL_LINE
;
445 if (type
== TRACE_GRAPH_ENT
)
446 ret
= trace_seq_printf(s
, "==========>");
448 ret
= trace_seq_printf(s
, "<==========");
451 return TRACE_TYPE_PARTIAL_LINE
;
453 /* Don't close the duration column if haven't one */
454 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
455 trace_seq_printf(s
, " |");
456 ret
= trace_seq_printf(s
, "\n");
459 return TRACE_TYPE_PARTIAL_LINE
;
460 return TRACE_TYPE_HANDLED
;
464 trace_print_graph_duration(unsigned long long duration
, struct trace_seq
*s
)
466 unsigned long nsecs_rem
= do_div(duration
, 1000);
467 /* log10(ULONG_MAX) + '\0' */
473 sprintf(msecs_str
, "%lu", (unsigned long) duration
);
476 ret
= trace_seq_printf(s
, "%s", msecs_str
);
478 return TRACE_TYPE_PARTIAL_LINE
;
480 len
= strlen(msecs_str
);
482 /* Print nsecs (we don't want to exceed 7 numbers) */
484 snprintf(nsecs_str
, 8 - len
, "%03lu", nsecs_rem
);
485 ret
= trace_seq_printf(s
, ".%s", nsecs_str
);
487 return TRACE_TYPE_PARTIAL_LINE
;
488 len
+= strlen(nsecs_str
);
491 ret
= trace_seq_printf(s
, " us ");
493 return TRACE_TYPE_PARTIAL_LINE
;
495 /* Print remaining spaces to fit the row's width */
496 for (i
= len
; i
< 7; i
++) {
497 ret
= trace_seq_printf(s
, " ");
499 return TRACE_TYPE_PARTIAL_LINE
;
501 return TRACE_TYPE_HANDLED
;
504 static enum print_line_t
505 print_graph_duration(unsigned long long duration
, struct trace_seq
*s
)
509 ret
= trace_print_graph_duration(duration
, s
);
510 if (ret
!= TRACE_TYPE_HANDLED
)
513 ret
= trace_seq_printf(s
, "| ");
515 return TRACE_TYPE_PARTIAL_LINE
;
517 return TRACE_TYPE_HANDLED
;
520 /* Case of a leaf function on its call entry */
521 static enum print_line_t
522 print_graph_entry_leaf(struct trace_iterator
*iter
,
523 struct ftrace_graph_ent_entry
*entry
,
524 struct ftrace_graph_ret_entry
*ret_entry
, struct trace_seq
*s
)
526 struct fgraph_data
*data
= iter
->private;
527 struct ftrace_graph_ret
*graph_ret
;
528 struct ftrace_graph_ent
*call
;
529 unsigned long long duration
;
533 graph_ret
= &ret_entry
->ret
;
534 call
= &entry
->graph_ent
;
535 duration
= graph_ret
->rettime
- graph_ret
->calltime
;
539 int *depth
= &(per_cpu_ptr(data
, cpu
)->depth
);
542 * Comments display at + 1 to depth. Since
543 * this is a leaf function, keep the comments
544 * equal to this depth.
546 *depth
= call
->depth
- 1;
550 ret
= print_graph_overhead(duration
, s
);
552 return TRACE_TYPE_PARTIAL_LINE
;
555 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
556 ret
= print_graph_duration(duration
, s
);
557 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
558 return TRACE_TYPE_PARTIAL_LINE
;
562 for (i
= 0; i
< call
->depth
* TRACE_GRAPH_INDENT
; i
++) {
563 ret
= trace_seq_printf(s
, " ");
565 return TRACE_TYPE_PARTIAL_LINE
;
568 ret
= seq_print_ip_sym(s
, call
->func
, 0);
570 return TRACE_TYPE_PARTIAL_LINE
;
572 ret
= trace_seq_printf(s
, "();\n");
574 return TRACE_TYPE_PARTIAL_LINE
;
576 return TRACE_TYPE_HANDLED
;
579 static enum print_line_t
580 print_graph_entry_nested(struct trace_iterator
*iter
,
581 struct ftrace_graph_ent_entry
*entry
,
582 struct trace_seq
*s
, int cpu
)
584 struct ftrace_graph_ent
*call
= &entry
->graph_ent
;
585 struct fgraph_data
*data
= iter
->private;
591 int *depth
= &(per_cpu_ptr(data
, cpu
)->depth
);
593 *depth
= call
->depth
;
597 ret
= print_graph_overhead(-1, s
);
599 return TRACE_TYPE_PARTIAL_LINE
;
602 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
603 ret
= trace_seq_printf(s
, " | ");
605 return TRACE_TYPE_PARTIAL_LINE
;
609 for (i
= 0; i
< call
->depth
* TRACE_GRAPH_INDENT
; i
++) {
610 ret
= trace_seq_printf(s
, " ");
612 return TRACE_TYPE_PARTIAL_LINE
;
615 ret
= seq_print_ip_sym(s
, call
->func
, 0);
617 return TRACE_TYPE_PARTIAL_LINE
;
619 ret
= trace_seq_printf(s
, "() {\n");
621 return TRACE_TYPE_PARTIAL_LINE
;
624 * we already consumed the current entry to check the next one
625 * and see if this is a leaf.
627 return TRACE_TYPE_NO_CONSUME
;
630 static enum print_line_t
631 print_graph_prologue(struct trace_iterator
*iter
, struct trace_seq
*s
,
632 int type
, unsigned long addr
)
634 struct fgraph_data
*data
= iter
->private;
635 struct trace_entry
*ent
= iter
->ent
;
640 if (verif_pid(s
, ent
->pid
, cpu
, data
) == TRACE_TYPE_PARTIAL_LINE
)
641 return TRACE_TYPE_PARTIAL_LINE
;
645 ret
= print_graph_irq(iter
, addr
, type
, cpu
, ent
->pid
);
646 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
647 return TRACE_TYPE_PARTIAL_LINE
;
651 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
) {
652 ret
= print_graph_abs_time(iter
->ts
, s
);
654 return TRACE_TYPE_PARTIAL_LINE
;
658 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
) {
659 ret
= print_graph_cpu(s
, cpu
);
660 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
661 return TRACE_TYPE_PARTIAL_LINE
;
665 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
) {
666 ret
= print_graph_proc(s
, ent
->pid
);
667 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
668 return TRACE_TYPE_PARTIAL_LINE
;
670 ret
= trace_seq_printf(s
, " | ");
672 return TRACE_TYPE_PARTIAL_LINE
;
678 static enum print_line_t
679 print_graph_entry(struct ftrace_graph_ent_entry
*field
, struct trace_seq
*s
,
680 struct trace_iterator
*iter
)
683 struct ftrace_graph_ent
*call
= &field
->graph_ent
;
684 struct ftrace_graph_ret_entry
*leaf_ret
;
686 if (print_graph_prologue(iter
, s
, TRACE_GRAPH_ENT
, call
->func
))
687 return TRACE_TYPE_PARTIAL_LINE
;
689 leaf_ret
= get_return_for_leaf(iter
, field
);
691 return print_graph_entry_leaf(iter
, field
, leaf_ret
, s
);
693 return print_graph_entry_nested(iter
, field
, s
, cpu
);
697 static enum print_line_t
698 print_graph_return(struct ftrace_graph_ret
*trace
, struct trace_seq
*s
,
699 struct trace_entry
*ent
, struct trace_iterator
*iter
)
701 unsigned long long duration
= trace
->rettime
- trace
->calltime
;
702 struct fgraph_data
*data
= iter
->private;
703 pid_t pid
= ent
->pid
;
710 int *depth
= &(per_cpu_ptr(data
, cpu
)->depth
);
713 * Comments display at + 1 to depth. This is the
714 * return from a function, we now want the comments
715 * to display at the same level of the bracket.
717 *depth
= trace
->depth
- 1;
720 if (print_graph_prologue(iter
, s
, 0, 0))
721 return TRACE_TYPE_PARTIAL_LINE
;
724 ret
= print_graph_overhead(duration
, s
);
726 return TRACE_TYPE_PARTIAL_LINE
;
729 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
730 ret
= print_graph_duration(duration
, s
);
731 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
732 return TRACE_TYPE_PARTIAL_LINE
;
736 for (i
= 0; i
< trace
->depth
* TRACE_GRAPH_INDENT
; i
++) {
737 ret
= trace_seq_printf(s
, " ");
739 return TRACE_TYPE_PARTIAL_LINE
;
742 ret
= trace_seq_printf(s
, "}\n");
744 return TRACE_TYPE_PARTIAL_LINE
;
747 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_OVERRUN
) {
748 ret
= trace_seq_printf(s
, " (Overruns: %lu)\n",
751 return TRACE_TYPE_PARTIAL_LINE
;
754 ret
= print_graph_irq(iter
, trace
->func
, TRACE_GRAPH_RET
, cpu
, pid
);
755 if (ret
== TRACE_TYPE_PARTIAL_LINE
)
756 return TRACE_TYPE_PARTIAL_LINE
;
758 return TRACE_TYPE_HANDLED
;
761 static enum print_line_t
762 print_graph_comment(struct trace_seq
*s
, struct trace_entry
*ent
,
763 struct trace_iterator
*iter
)
765 unsigned long sym_flags
= (trace_flags
& TRACE_ITER_SYM_MASK
);
766 struct fgraph_data
*data
= iter
->private;
767 struct trace_event
*event
;
773 depth
= per_cpu_ptr(data
, iter
->cpu
)->depth
;
775 if (print_graph_prologue(iter
, s
, 0, 0))
776 return TRACE_TYPE_PARTIAL_LINE
;
779 ret
= print_graph_overhead(-1, s
);
781 return TRACE_TYPE_PARTIAL_LINE
;
784 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
) {
785 ret
= trace_seq_printf(s
, " | ");
787 return TRACE_TYPE_PARTIAL_LINE
;
792 for (i
= 0; i
< (depth
+ 1) * TRACE_GRAPH_INDENT
; i
++) {
793 ret
= trace_seq_printf(s
, " ");
795 return TRACE_TYPE_PARTIAL_LINE
;
799 ret
= trace_seq_printf(s
, "/* ");
801 return TRACE_TYPE_PARTIAL_LINE
;
803 switch (iter
->ent
->type
) {
805 ret
= trace_print_bprintk_msg_only(iter
);
806 if (ret
!= TRACE_TYPE_HANDLED
)
810 ret
= trace_print_printk_msg_only(iter
);
811 if (ret
!= TRACE_TYPE_HANDLED
)
815 event
= ftrace_find_event(ent
->type
);
817 return TRACE_TYPE_UNHANDLED
;
819 ret
= event
->trace(iter
, sym_flags
);
820 if (ret
!= TRACE_TYPE_HANDLED
)
824 /* Strip ending newline */
825 if (s
->buffer
[s
->len
- 1] == '\n') {
826 s
->buffer
[s
->len
- 1] = '\0';
830 ret
= trace_seq_printf(s
, " */\n");
832 return TRACE_TYPE_PARTIAL_LINE
;
834 return TRACE_TYPE_HANDLED
;
839 print_graph_function(struct trace_iterator
*iter
)
841 struct trace_entry
*entry
= iter
->ent
;
842 struct trace_seq
*s
= &iter
->seq
;
844 switch (entry
->type
) {
845 case TRACE_GRAPH_ENT
: {
847 * print_graph_entry() may consume the current event,
848 * thus @field may become invalid, so we need to save it.
849 * sizeof(struct ftrace_graph_ent_entry) is very small,
850 * it can be safely saved at the stack.
852 struct ftrace_graph_ent_entry
*field
, saved
;
853 trace_assign_type(field
, entry
);
855 return print_graph_entry(&saved
, s
, iter
);
857 case TRACE_GRAPH_RET
: {
858 struct ftrace_graph_ret_entry
*field
;
859 trace_assign_type(field
, entry
);
860 return print_graph_return(&field
->ret
, s
, entry
, iter
);
863 return print_graph_comment(s
, entry
, iter
);
866 return TRACE_TYPE_HANDLED
;
869 static void print_graph_headers(struct seq_file
*s
)
873 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
)
874 seq_printf(s
, " TIME ");
875 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
)
876 seq_printf(s
, "CPU");
877 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
)
878 seq_printf(s
, " TASK/PID ");
879 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
880 seq_printf(s
, " DURATION ");
881 seq_printf(s
, " FUNCTION CALLS\n");
885 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_ABS_TIME
)
886 seq_printf(s
, " | ");
887 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_CPU
)
889 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_PROC
)
890 seq_printf(s
, " | | ");
891 if (tracer_flags
.val
& TRACE_GRAPH_PRINT_DURATION
)
892 seq_printf(s
, " | | ");
893 seq_printf(s
, " | | | |\n");
896 static void graph_trace_open(struct trace_iterator
*iter
)
898 /* pid and depth on the last trace processed */
899 struct fgraph_data
*data
= alloc_percpu(struct fgraph_data
);
903 pr_warning("function graph tracer: not enough memory\n");
905 for_each_possible_cpu(cpu
) {
906 pid_t
*pid
= &(per_cpu_ptr(data
, cpu
)->last_pid
);
907 int *depth
= &(per_cpu_ptr(data
, cpu
)->depth
);
912 iter
->private = data
;
915 static void graph_trace_close(struct trace_iterator
*iter
)
917 free_percpu(iter
->private);
920 static struct tracer graph_trace __read_mostly
= {
921 .name
= "function_graph",
922 .open
= graph_trace_open
,
923 .close
= graph_trace_close
,
924 .wait_pipe
= poll_wait_pipe
,
925 .init
= graph_trace_init
,
926 .reset
= graph_trace_reset
,
927 .print_line
= print_graph_function
,
928 .print_header
= print_graph_headers
,
929 .flags
= &tracer_flags
,
930 #ifdef CONFIG_FTRACE_SELFTEST
931 .selftest
= trace_selftest_startup_function_graph
,
935 static __init
int init_graph_trace(void)
937 return register_tracer(&graph_trace
);
940 device_initcall(init_graph_trace
);