blob: d7c8719734b8be2b8064736226768fdb58d7ae52 [file] [log] [blame]
Steven Rostedt1b29b012008-05-12 21:20:42 +02001/*
2 * ring buffer based function tracer
3 *
4 * Copyright (C) 2007-2008 Steven Rostedt <srostedt@redhat.com>
5 * Copyright (C) 2008 Ingo Molnar <mingo@redhat.com>
6 *
7 * Based on code from the latency_tracer, that is:
8 *
9 * Copyright (C) 2004-2006 Ingo Molnar
Nadia Yvette Chambers6d49e352012-12-06 10:39:54 +010010 * Copyright (C) 2004 Nadia Yvette Chambers
Steven Rostedt1b29b012008-05-12 21:20:42 +020011 */
Steven Rostedt23b4ff32009-02-14 19:04:24 -050012#include <linux/ring_buffer.h>
Steven Rostedt1b29b012008-05-12 21:20:42 +020013#include <linux/debugfs.h>
14#include <linux/uaccess.h>
15#include <linux/ftrace.h>
Ingo Molnar2e0f5762008-05-12 21:20:49 +020016#include <linux/fs.h>
Steven Rostedt1b29b012008-05-12 21:20:42 +020017
18#include "trace.h"
19
Steven Rostedta225cdd2009-01-15 23:06:03 -050020/* function tracing enabled */
21static int ftrace_function_enabled;
22
Steven Rostedt53614992009-01-15 19:12:40 -050023static struct trace_array *func_trace;
24
Steven Rostedta225cdd2009-01-15 23:06:03 -050025static void tracing_start_function_trace(void);
26static void tracing_stop_function_trace(void);
27
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -020028static int function_trace_init(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020029{
Steven Rostedtbb3c3c92009-01-15 20:40:23 -050030 func_trace = tr;
Steven Rostedt (Red Hat)12883ef2013-03-05 09:24:35 -050031 tr->trace_buffer.cpu = get_cpu();
Steven Rostedt26bc83f2008-07-10 20:58:14 -040032 put_cpu();
33
Steven Rostedt41bc8142008-05-22 11:49:22 -040034 tracing_start_cmdline_record();
Steven Rostedt1b29b012008-05-12 21:20:42 +020035 tracing_start_function_trace();
Frederic Weisbecker1c800252008-11-16 05:57:26 +010036 return 0;
Steven Rostedt1b29b012008-05-12 21:20:42 +020037}
38
Ingo Molnare309b412008-05-12 21:20:51 +020039static void function_trace_reset(struct trace_array *tr)
Steven Rostedt1b29b012008-05-12 21:20:42 +020040{
Arnaldo Carvalho de Melob6f11df2009-02-05 18:02:00 -020041 tracing_stop_function_trace();
42 tracing_stop_cmdline_record();
Steven Rostedt1b29b012008-05-12 21:20:42 +020043}
44
Steven Rostedt90369902008-11-05 16:05:44 -050045static void function_trace_start(struct trace_array *tr)
46{
Steven Rostedt (Red Hat)12883ef2013-03-05 09:24:35 -050047 tracing_reset_online_cpus(&tr->trace_buffer);
Steven Rostedt90369902008-11-05 16:05:44 -050048}
49
Anton Vorontsov65f8c952012-07-17 14:26:15 -070050/* Our option */
Anton Vorontsov21f67942012-07-09 17:10:42 -070051enum {
52 TRACE_FUNC_OPT_STACK = 0x1,
Anton Vorontsov21f67942012-07-09 17:10:42 -070053};
54
55static struct tracer_flags func_flags;
56
Steven Rostedtbb3c3c92009-01-15 20:40:23 -050057static void
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -040058function_trace_call(unsigned long ip, unsigned long parent_ip,
Steven Rostedta1e2e312011-08-09 12:50:46 -040059 struct ftrace_ops *op, struct pt_regs *pt_regs)
Steven Rostedtbb3c3c92009-01-15 20:40:23 -050060{
61 struct trace_array *tr = func_trace;
62 struct trace_array_cpu *data;
63 unsigned long flags;
Steven Rostedtd41032a2013-01-24 07:52:34 -050064 int bit;
Steven Rostedtbb3c3c92009-01-15 20:40:23 -050065 int cpu;
66 int pc;
67
68 if (unlikely(!ftrace_function_enabled))
69 return;
70
Steven Rostedt897f68a2012-11-02 17:52:35 -040071 pc = preempt_count();
72 preempt_disable_notrace();
Steven Rostedtbb3c3c92009-01-15 20:40:23 -050073
Steven Rostedt897f68a2012-11-02 17:52:35 -040074 bit = trace_test_and_set_recursion(TRACE_FTRACE_START, TRACE_FTRACE_MAX);
75 if (bit < 0)
76 goto out;
77
78 cpu = smp_processor_id();
Steven Rostedt (Red Hat)12883ef2013-03-05 09:24:35 -050079 data = per_cpu_ptr(tr->trace_buffer.data, cpu);
Steven Rostedt897f68a2012-11-02 17:52:35 -040080 if (!atomic_read(&data->disabled)) {
81 local_save_flags(flags);
Arnaldo Carvalho de Melo7be42152009-02-05 01:13:37 -050082 trace_function(tr, ip, parent_ip, flags, pc);
Steven Rostedtbb3c3c92009-01-15 20:40:23 -050083 }
Steven Rostedt897f68a2012-11-02 17:52:35 -040084 trace_clear_recursion(bit);
Steven Rostedtbb3c3c92009-01-15 20:40:23 -050085
Steven Rostedt897f68a2012-11-02 17:52:35 -040086 out:
87 preempt_enable_notrace();
Steven Rostedtbb3c3c92009-01-15 20:40:23 -050088}
89
90static void
Steven Rostedt2f5f6ad2011-08-08 16:57:47 -040091function_stack_trace_call(unsigned long ip, unsigned long parent_ip,
Steven Rostedta1e2e312011-08-09 12:50:46 -040092 struct ftrace_ops *op, struct pt_regs *pt_regs)
Steven Rostedt53614992009-01-15 19:12:40 -050093{
94 struct trace_array *tr = func_trace;
95 struct trace_array_cpu *data;
96 unsigned long flags;
97 long disabled;
98 int cpu;
99 int pc;
100
101 if (unlikely(!ftrace_function_enabled))
102 return;
103
104 /*
105 * Need to use raw, since this must be called before the
106 * recursive protection is performed.
107 */
108 local_irq_save(flags);
109 cpu = raw_smp_processor_id();
Steven Rostedt (Red Hat)12883ef2013-03-05 09:24:35 -0500110 data = per_cpu_ptr(tr->trace_buffer.data, cpu);
Steven Rostedt53614992009-01-15 19:12:40 -0500111 disabled = atomic_inc_return(&data->disabled);
112
113 if (likely(disabled == 1)) {
114 pc = preempt_count();
Arnaldo Carvalho de Melo7be42152009-02-05 01:13:37 -0500115 trace_function(tr, ip, parent_ip, flags, pc);
Steven Rostedt53614992009-01-15 19:12:40 -0500116 /*
117 * skip over 5 funcs:
118 * __ftrace_trace_stack,
119 * __trace_stack,
120 * function_stack_trace_call
121 * ftrace_list_func
122 * ftrace_call
123 */
Arnaldo Carvalho de Melo7be42152009-02-05 01:13:37 -0500124 __trace_stack(tr, flags, 5, pc);
Steven Rostedt53614992009-01-15 19:12:40 -0500125 }
126
127 atomic_dec(&data->disabled);
128 local_irq_restore(flags);
129}
130
Steven Rostedtbb3c3c92009-01-15 20:40:23 -0500131
132static struct ftrace_ops trace_ops __read_mostly =
133{
134 .func = function_trace_call,
Steven Rostedt47409742012-07-20 11:04:44 -0400135 .flags = FTRACE_OPS_FL_GLOBAL | FTRACE_OPS_FL_RECURSION_SAFE,
Steven Rostedtbb3c3c92009-01-15 20:40:23 -0500136};
137
Steven Rostedt53614992009-01-15 19:12:40 -0500138static struct ftrace_ops trace_stack_ops __read_mostly =
139{
140 .func = function_stack_trace_call,
Steven Rostedt47409742012-07-20 11:04:44 -0400141 .flags = FTRACE_OPS_FL_GLOBAL | FTRACE_OPS_FL_RECURSION_SAFE,
Steven Rostedt53614992009-01-15 19:12:40 -0500142};
143
Steven Rostedt53614992009-01-15 19:12:40 -0500144static struct tracer_opt func_opts[] = {
145#ifdef CONFIG_STACKTRACE
146 { TRACER_OPT(func_stack_trace, TRACE_FUNC_OPT_STACK) },
147#endif
148 { } /* Always set a last empty entry */
149};
150
151static struct tracer_flags func_flags = {
152 .val = 0, /* By default: all flags disabled */
153 .opts = func_opts
154};
155
Steven Rostedta225cdd2009-01-15 23:06:03 -0500156static void tracing_start_function_trace(void)
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500157{
158 ftrace_function_enabled = 0;
159
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500160 if (func_flags.val & TRACE_FUNC_OPT_STACK)
161 register_ftrace_function(&trace_stack_ops);
162 else
163 register_ftrace_function(&trace_ops);
164
165 ftrace_function_enabled = 1;
166}
167
Steven Rostedta225cdd2009-01-15 23:06:03 -0500168static void tracing_stop_function_trace(void)
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500169{
170 ftrace_function_enabled = 0;
Frederic Weisbeckerc85a17e2009-06-20 05:45:14 +0200171
172 if (func_flags.val & TRACE_FUNC_OPT_STACK)
173 unregister_ftrace_function(&trace_stack_ops);
174 else
175 unregister_ftrace_function(&trace_ops);
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500176}
177
Steven Rostedt53614992009-01-15 19:12:40 -0500178static int func_set_flag(u32 old_flags, u32 bit, int set)
179{
Anton Vorontsovf555f122012-07-09 17:10:46 -0700180 switch (bit) {
181 case TRACE_FUNC_OPT_STACK:
Steven Rostedt53614992009-01-15 19:12:40 -0500182 /* do nothing if already set */
183 if (!!set == !!(func_flags.val & TRACE_FUNC_OPT_STACK))
Anton Vorontsovf555f122012-07-09 17:10:46 -0700184 break;
Steven Rostedt53614992009-01-15 19:12:40 -0500185
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500186 if (set) {
187 unregister_ftrace_function(&trace_ops);
Steven Rostedt53614992009-01-15 19:12:40 -0500188 register_ftrace_function(&trace_stack_ops);
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500189 } else {
Steven Rostedt53614992009-01-15 19:12:40 -0500190 unregister_ftrace_function(&trace_stack_ops);
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500191 register_ftrace_function(&trace_ops);
192 }
Steven Rostedt53614992009-01-15 19:12:40 -0500193
Anton Vorontsovf555f122012-07-09 17:10:46 -0700194 break;
Anton Vorontsovf555f122012-07-09 17:10:46 -0700195 default:
196 return -EINVAL;
Steven Rostedt53614992009-01-15 19:12:40 -0500197 }
198
Anton Vorontsovf555f122012-07-09 17:10:46 -0700199 return 0;
Steven Rostedt53614992009-01-15 19:12:40 -0500200}
201
Steven Rostedt1b29b012008-05-12 21:20:42 +0200202static struct tracer function_trace __read_mostly =
203{
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500204 .name = "function",
205 .init = function_trace_init,
206 .reset = function_trace_reset,
207 .start = function_trace_start,
Frederic Weisbecker6eaaa5d2009-02-11 02:25:00 +0100208 .wait_pipe = poll_wait_pipe,
Steven Rostedt53614992009-01-15 19:12:40 -0500209 .flags = &func_flags,
210 .set_flag = func_set_flag,
Steven Rostedt60a11772008-05-12 21:20:44 +0200211#ifdef CONFIG_FTRACE_SELFTEST
Steven Rostedt3eb36aa2009-01-15 22:21:43 -0500212 .selftest = trace_selftest_startup_function,
Steven Rostedt60a11772008-05-12 21:20:44 +0200213#endif
Steven Rostedt1b29b012008-05-12 21:20:42 +0200214};
215
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500216#ifdef CONFIG_DYNAMIC_FTRACE
Steven Rostedt (Red Hat)1c317142013-03-09 08:36:53 -0500217static int update_count(void **data)
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500218{
Steven Rostedt (Red Hat)1c317142013-03-09 08:36:53 -0500219 unsigned long *count = (long *)data;
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500220
221 if (!*count)
Steven Rostedt (Red Hat)1c317142013-03-09 08:36:53 -0500222 return 0;
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500223
224 if (*count != -1)
225 (*count)--;
226
Steven Rostedt (Red Hat)1c317142013-03-09 08:36:53 -0500227 return 1;
228}
229
230static void
Steven Rostedt (Red Hat)8380d242013-03-09 08:56:43 -0500231ftrace_traceon_count(unsigned long ip, unsigned long parent_ip, void **data)
Steven Rostedt (Red Hat)1c317142013-03-09 08:36:53 -0500232{
233 if (tracing_is_on())
234 return;
235
236 if (update_count(data))
237 tracing_on();
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500238}
239
240static void
Steven Rostedt (Red Hat)8380d242013-03-09 08:56:43 -0500241ftrace_traceoff_count(unsigned long ip, unsigned long parent_ip, void **data)
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500242{
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500243 if (!tracing_is_on())
244 return;
245
Steven Rostedt (Red Hat)1c317142013-03-09 08:36:53 -0500246 if (update_count(data))
247 tracing_off();
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500248}
249
Steven Rostedt (Red Hat)8380d242013-03-09 08:56:43 -0500250static void
251ftrace_traceon(unsigned long ip, unsigned long parent_ip, void **data)
252{
253 if (tracing_is_on())
254 return;
255
256 tracing_on();
257}
258
259static void
260ftrace_traceoff(unsigned long ip, unsigned long parent_ip, void **data)
261{
262 if (!tracing_is_on())
263 return;
264
265 tracing_off();
266}
267
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400268/*
269 * Skip 4:
270 * ftrace_stacktrace()
271 * function_trace_probe_call()
272 * ftrace_ops_list_func()
273 * ftrace_call()
274 */
275#define STACK_SKIP 4
Steven Rostedte110e3d2009-02-16 23:38:13 -0500276
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400277static void
278ftrace_stacktrace(unsigned long ip, unsigned long parent_ip, void **data)
279{
280 trace_dump_stack(STACK_SKIP);
281}
Steven Rostedt (Red Hat)8380d242013-03-09 08:56:43 -0500282
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400283static void
284ftrace_stacktrace_count(unsigned long ip, unsigned long parent_ip, void **data)
285{
286 if (!tracing_is_on())
287 return;
Steven Rostedt (Red Hat)8380d242013-03-09 08:56:43 -0500288
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400289 if (update_count(data))
290 trace_dump_stack(STACK_SKIP);
291}
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500292
Steven Rostedt (Red Hat)ad71d882013-04-30 15:46:14 -0400293static void
294ftrace_dump_probe(unsigned long ip, unsigned long parent_ip, void **data)
295{
296 if (update_count(data))
297 ftrace_dump(DUMP_ALL);
298}
299
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500300static int
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400301ftrace_probe_print(const char *name, struct seq_file *m,
302 unsigned long ip, void *data)
Steven Rostedte110e3d2009-02-16 23:38:13 -0500303{
Steven Rostedte110e3d2009-02-16 23:38:13 -0500304 long count = (long)data;
305
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400306 seq_printf(m, "%ps:%s", (void *)ip, name);
Steven Rostedte110e3d2009-02-16 23:38:13 -0500307
Steven Rostedt35ebf1c2009-02-17 13:12:12 -0500308 if (count == -1)
309 seq_printf(m, ":unlimited\n");
310 else
Li Zefan00e54d02009-06-25 14:05:27 +0800311 seq_printf(m, ":count=%ld\n", count);
Steven Rostedte110e3d2009-02-16 23:38:13 -0500312
313 return 0;
314}
315
316static int
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400317ftrace_traceon_print(struct seq_file *m, unsigned long ip,
318 struct ftrace_probe_ops *ops, void *data)
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500319{
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400320 return ftrace_probe_print("traceon", m, ip, data);
321}
322
323static int
324ftrace_traceoff_print(struct seq_file *m, unsigned long ip,
325 struct ftrace_probe_ops *ops, void *data)
326{
327 return ftrace_probe_print("traceoff", m, ip, data);
328}
329
330static int
331ftrace_stacktrace_print(struct seq_file *m, unsigned long ip,
332 struct ftrace_probe_ops *ops, void *data)
333{
334 return ftrace_probe_print("stacktrace", m, ip, data);
335}
336
Steven Rostedt (Red Hat)ad71d882013-04-30 15:46:14 -0400337static int
338ftrace_dump_print(struct seq_file *m, unsigned long ip,
339 struct ftrace_probe_ops *ops, void *data)
340{
341 return ftrace_probe_print("dump", m, ip, data);
342}
343
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400344static struct ftrace_probe_ops traceon_count_probe_ops = {
345 .func = ftrace_traceon_count,
346 .print = ftrace_traceon_print,
347};
348
349static struct ftrace_probe_ops traceoff_count_probe_ops = {
350 .func = ftrace_traceoff_count,
351 .print = ftrace_traceoff_print,
352};
353
354static struct ftrace_probe_ops stacktrace_count_probe_ops = {
355 .func = ftrace_stacktrace_count,
356 .print = ftrace_stacktrace_print,
357};
358
Steven Rostedt (Red Hat)ad71d882013-04-30 15:46:14 -0400359static struct ftrace_probe_ops dump_probe_ops = {
360 .func = ftrace_dump_probe,
361 .print = ftrace_dump_print,
362};
363
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400364static struct ftrace_probe_ops traceon_probe_ops = {
365 .func = ftrace_traceon,
366 .print = ftrace_traceon_print,
367};
368
369static struct ftrace_probe_ops traceoff_probe_ops = {
370 .func = ftrace_traceoff,
371 .print = ftrace_traceoff_print,
372};
373
374static struct ftrace_probe_ops stacktrace_probe_ops = {
375 .func = ftrace_stacktrace,
376 .print = ftrace_stacktrace_print,
377};
378
379static int
380ftrace_trace_probe_callback(struct ftrace_probe_ops *ops,
381 struct ftrace_hash *hash, char *glob,
382 char *cmd, char *param, int enable)
383{
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500384 void *count = (void *)-1;
385 char *number;
386 int ret;
387
388 /* hash funcs only work with set_ftrace_filter */
389 if (!enable)
390 return -EINVAL;
391
Steven Rostedt (Red Hat)8b8fa622013-03-12 09:25:00 -0400392 if (glob[0] == '!') {
393 unregister_ftrace_function_probe_func(glob+1, ops);
394 return 0;
395 }
396
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500397 if (!param)
398 goto out_reg;
399
400 number = strsep(&param, ":");
401
402 if (!strlen(number))
403 goto out_reg;
404
405 /*
406 * We use the callback data field (which is a pointer)
407 * as our counter.
408 */
Daniel Walterbcd83ea2012-09-26 22:08:38 +0200409 ret = kstrtoul(number, 0, (unsigned long *)&count);
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500410 if (ret)
411 return ret;
412
413 out_reg:
Steven Rostedtb6887d72009-02-17 12:32:04 -0500414 ret = register_ftrace_function_probe(glob, ops, count);
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500415
Xiao Guangrong04aef322009-07-15 12:29:06 +0800416 return ret < 0 ? ret : 0;
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500417}
418
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400419static int
420ftrace_trace_onoff_callback(struct ftrace_hash *hash,
421 char *glob, char *cmd, char *param, int enable)
422{
423 struct ftrace_probe_ops *ops;
424
425 /* we register both traceon and traceoff to this callback */
426 if (strcmp(cmd, "traceon") == 0)
427 ops = param ? &traceon_count_probe_ops : &traceon_probe_ops;
428 else
429 ops = param ? &traceoff_count_probe_ops : &traceoff_probe_ops;
430
431 return ftrace_trace_probe_callback(ops, hash, glob, cmd,
432 param, enable);
433}
434
435static int
436ftrace_stacktrace_callback(struct ftrace_hash *hash,
437 char *glob, char *cmd, char *param, int enable)
438{
439 struct ftrace_probe_ops *ops;
440
441 ops = param ? &stacktrace_count_probe_ops : &stacktrace_probe_ops;
442
443 return ftrace_trace_probe_callback(ops, hash, glob, cmd,
444 param, enable);
445}
446
Steven Rostedt (Red Hat)ad71d882013-04-30 15:46:14 -0400447static int
448ftrace_dump_callback(struct ftrace_hash *hash,
449 char *glob, char *cmd, char *param, int enable)
450{
451 struct ftrace_probe_ops *ops;
452
453 ops = &dump_probe_ops;
454
455 /* Only dump once. */
456 return ftrace_trace_probe_callback(ops, hash, glob, cmd,
457 "1", enable);
458}
459
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500460static struct ftrace_func_command ftrace_traceon_cmd = {
461 .name = "traceon",
462 .func = ftrace_trace_onoff_callback,
463};
464
465static struct ftrace_func_command ftrace_traceoff_cmd = {
466 .name = "traceoff",
467 .func = ftrace_trace_onoff_callback,
468};
469
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400470static struct ftrace_func_command ftrace_stacktrace_cmd = {
471 .name = "stacktrace",
472 .func = ftrace_stacktrace_callback,
473};
474
Steven Rostedt (Red Hat)ad71d882013-04-30 15:46:14 -0400475static struct ftrace_func_command ftrace_dump_cmd = {
476 .name = "dump",
477 .func = ftrace_dump_callback,
478};
479
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500480static int __init init_func_cmd_traceon(void)
481{
482 int ret;
483
484 ret = register_ftrace_command(&ftrace_traceoff_cmd);
485 if (ret)
486 return ret;
487
488 ret = register_ftrace_command(&ftrace_traceon_cmd);
489 if (ret)
Steven Rostedt (Red Hat)ad71d882013-04-30 15:46:14 -0400490 goto out_free_traceoff;
Steven Rostedt (Red Hat)dd42cd32013-03-13 10:17:50 -0400491
492 ret = register_ftrace_command(&ftrace_stacktrace_cmd);
Steven Rostedt (Red Hat)ad71d882013-04-30 15:46:14 -0400493 if (ret)
494 goto out_free_traceon;
495
496 ret = register_ftrace_command(&ftrace_dump_cmd);
497 if (ret)
498 goto out_free_stacktrace;
499
500 return 0;
501
502 out_free_stacktrace:
503 unregister_ftrace_command(&ftrace_stacktrace_cmd);
504 out_free_traceon:
505 unregister_ftrace_command(&ftrace_traceon_cmd);
506 out_free_traceoff:
507 unregister_ftrace_command(&ftrace_traceoff_cmd);
508
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500509 return ret;
510}
511#else
512static inline int init_func_cmd_traceon(void)
513{
514 return 0;
515}
516#endif /* CONFIG_DYNAMIC_FTRACE */
517
Steven Rostedt1b29b012008-05-12 21:20:42 +0200518static __init int init_function_trace(void)
519{
Steven Rostedt23b4ff32009-02-14 19:04:24 -0500520 init_func_cmd_traceon();
Steven Rostedt1b29b012008-05-12 21:20:42 +0200521 return register_tracer(&function_trace);
522}
Steven Rostedt6f415672012-10-05 12:13:07 -0400523core_initcall(init_function_trace);