ftrace: add thread comm to function graph tracer
[linux-2.6.git] / kernel / trace / trace_functions_graph.c
blobbbb81e7b6c40022a5dfdbca88adb2568f1a9b348
1 /*
3 * Function graph tracer.
4 * Copyright (c) 2008 Frederic Weisbecker <fweisbec@gmail.com>
5 * Mostly borrowed from function tracer which
6 * is Copyright (c) Steven Rostedt <srostedt@redhat.com>
8 */
9 #include <linux/debugfs.h>
10 #include <linux/uaccess.h>
11 #include <linux/ftrace.h>
12 #include <linux/fs.h>
14 #include "trace.h"
16 #define TRACE_GRAPH_INDENT 2
18 #define TRACE_GRAPH_PRINT_OVERRUN 0x1
19 static struct tracer_opt trace_opts[] = {
20 /* Display overruns or not */
21 { TRACER_OPT(overrun, TRACE_GRAPH_PRINT_OVERRUN) },
22 { } /* Empty entry */
25 static struct tracer_flags tracer_flags = {
26 .val = 0, /* Don't display overruns by default */
27 .opts = trace_opts
30 /* pid on the last trace processed */
31 static pid_t last_pid = -1;
33 static int graph_trace_init(struct trace_array *tr)
35 int cpu, ret;
37 for_each_online_cpu(cpu)
38 tracing_reset(tr, cpu);
40 ret = register_ftrace_graph(&trace_graph_return,
41 &trace_graph_entry);
42 if (ret)
43 return ret;
44 tracing_start_cmdline_record();
46 return 0;
49 static void graph_trace_reset(struct trace_array *tr)
51 tracing_stop_cmdline_record();
52 unregister_ftrace_graph();
55 /* If the pid changed since the last trace, output this event */
56 static int verif_pid(struct trace_seq *s, pid_t pid)
58 char *comm;
60 if (last_pid != -1 && last_pid == pid)
61 return 1;
63 last_pid = pid;
64 comm = trace_find_cmdline(pid);
66 return trace_seq_printf(s, "\n------------8<---------- thread %s-%d"
67 " ------------8<----------\n\n",
68 comm, pid);
71 static enum print_line_t
72 print_graph_entry(struct ftrace_graph_ent *call, struct trace_seq *s,
73 struct trace_entry *ent)
75 int i;
76 int ret;
78 if (!verif_pid(s, ent->pid))
79 return TRACE_TYPE_PARTIAL_LINE;
81 for (i = 0; i < call->depth * TRACE_GRAPH_INDENT; i++) {
82 ret = trace_seq_printf(s, " ");
83 if (!ret)
84 return TRACE_TYPE_PARTIAL_LINE;
87 ret = seq_print_ip_sym(s, call->func, 0);
88 if (!ret)
89 return TRACE_TYPE_PARTIAL_LINE;
91 ret = trace_seq_printf(s, "() {\n");
92 if (!ret)
93 return TRACE_TYPE_PARTIAL_LINE;
94 return TRACE_TYPE_HANDLED;
97 static enum print_line_t
98 print_graph_return(struct ftrace_graph_ret *trace, struct trace_seq *s,
99 struct trace_entry *ent)
101 int i;
102 int ret;
104 if (!verif_pid(s, ent->pid))
105 return TRACE_TYPE_PARTIAL_LINE;
107 for (i = 0; i < trace->depth * TRACE_GRAPH_INDENT; i++) {
108 ret = trace_seq_printf(s, " ");
109 if (!ret)
110 return TRACE_TYPE_PARTIAL_LINE;
113 ret = trace_seq_printf(s, "} ");
114 if (!ret)
115 return TRACE_TYPE_PARTIAL_LINE;
117 ret = trace_seq_printf(s, "%llu\n", trace->rettime - trace->calltime);
118 if (!ret)
119 return TRACE_TYPE_PARTIAL_LINE;
121 if (tracer_flags.val & TRACE_GRAPH_PRINT_OVERRUN) {
122 ret = trace_seq_printf(s, " (Overruns: %lu)\n",
123 trace->overrun);
124 if (!ret)
125 return TRACE_TYPE_PARTIAL_LINE;
127 return TRACE_TYPE_HANDLED;
130 enum print_line_t
131 print_graph_function(struct trace_iterator *iter)
133 struct trace_seq *s = &iter->seq;
134 struct trace_entry *entry = iter->ent;
136 switch (entry->type) {
137 case TRACE_GRAPH_ENT: {
138 struct ftrace_graph_ent_entry *field;
139 trace_assign_type(field, entry);
140 return print_graph_entry(&field->graph_ent, s, entry);
142 case TRACE_GRAPH_RET: {
143 struct ftrace_graph_ret_entry *field;
144 trace_assign_type(field, entry);
145 return print_graph_return(&field->ret, s, entry);
147 default:
148 return TRACE_TYPE_UNHANDLED;
152 static struct tracer graph_trace __read_mostly = {
153 .name = "function-graph",
154 .init = graph_trace_init,
155 .reset = graph_trace_reset,
156 .print_line = print_graph_function,
157 .flags = &tracer_flags,
160 static __init int init_graph_trace(void)
162 return register_tracer(&graph_trace);
165 device_initcall(init_graph_trace);