Skip to content

Commit fb1b6d8

Browse files
tychoIngo Molnar
authored andcommitted
ftrace: add nop tracer
A no-op tracer which can serve two purposes: 1. A template for development of a new tracer. 2. A convenient way to see ftrace_printk() calls without an irrelevant trace making the output messy. [ mingo@elte.hu: resolved conflicts ] Signed-off-by: Steven Noonan <steven@uplinklabs.net> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent 5bf9a1e commit fb1b6d8

5 files changed

Lines changed: 89 additions & 0 deletions

File tree

‎kernel/trace/Kconfig‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,16 @@ config SCHED_TRACER
101101
This tracer tracks the latency of the highest priority task
102102
to be scheduled in, starting from the point it has woken up.
103103

104+
config NOP_TRACER
105+
bool "NOP Tracer"
106+
depends on HAVE_FTRACE
107+
depends on DEBUG_KERNEL
108+
select TRACING
109+
help
110+
This tracer does nothing. The primary purpose for it is to
111+
politely print the output of ftrace_printk() calls without
112+
the overhead of an irrelevant trace taking place.
113+
104114
config CONTEXT_SWITCH_TRACER
105115
bool "Trace process context switches"
106116
depends on HAVE_FTRACE

‎kernel/trace/Makefile‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ obj-$(CONFIG_FTRACE) += trace_functions.o
1919
obj-$(CONFIG_IRQSOFF_TRACER) += trace_irqsoff.o
2020
obj-$(CONFIG_PREEMPT_TRACER) += trace_irqsoff.o
2121
obj-$(CONFIG_SCHED_TRACER) += trace_sched_wakeup.o
22+
obj-$(CONFIG_NOP_TRACER) += trace_nop.o
2223
obj-$(CONFIG_STACK_TRACER) += trace_stack.o
2324
obj-$(CONFIG_MMIOTRACE) += trace_mmiotrace.o
2425

‎kernel/trace/trace.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,10 @@ extern int trace_selftest_startup_preemptirqsoff(struct tracer *trace,
339339
extern int trace_selftest_startup_wakeup(struct tracer *trace,
340340
struct trace_array *tr);
341341
#endif
342+
#ifdef CONFIG_NOP_TRACER
343+
extern int trace_selftest_startup_nop(struct tracer *trace,
344+
struct trace_array *tr);
345+
#endif
342346
#ifdef CONFIG_CONTEXT_SWITCH_TRACER
343347
extern int trace_selftest_startup_sched_switch(struct tracer *trace,
344348
struct trace_array *tr);

‎kernel/trace/trace_nop.c‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*
2+
* nop tracer
3+
*
4+
* Copyright (C) 2008 Steven Noonan <steven@uplinklabs.net>
5+
*
6+
*/
7+
8+
#include <linux/module.h>
9+
#include <linux/fs.h>
10+
#include <linux/debugfs.h>
11+
#include <linux/ftrace.h>
12+
13+
#include "trace.h"
14+
15+
static struct trace_array *ctx_trace;
16+
17+
static void start_nop_trace(struct trace_array *tr)
18+
{
19+
/* Nothing to do! */
20+
}
21+
22+
static void stop_nop_trace(struct trace_array *tr)
23+
{
24+
/* Nothing to do! */
25+
}
26+
27+
static void nop_trace_init(struct trace_array *tr)
28+
{
29+
ctx_trace = tr;
30+
31+
if (tr->ctrl)
32+
start_nop_trace(tr);
33+
}
34+
35+
static void nop_trace_reset(struct trace_array *tr)
36+
{
37+
if (tr->ctrl)
38+
stop_nop_trace(tr);
39+
}
40+
41+
static void nop_trace_ctrl_update(struct trace_array *tr)
42+
{
43+
/* When starting a new trace, reset the buffers */
44+
if (tr->ctrl)
45+
start_nop_trace(tr);
46+
else
47+
stop_nop_trace(tr);
48+
}
49+
50+
static struct tracer nop_trace __read_mostly =
51+
{
52+
.name = "nop",
53+
.init = nop_trace_init,
54+
.reset = nop_trace_reset,
55+
.ctrl_update = nop_trace_ctrl_update,
56+
#ifdef CONFIG_FTRACE_SELFTEST
57+
.selftest = trace_selftest_startup_nop,
58+
#endif
59+
};
60+
61+
__init static int init_nop_trace(void)
62+
{
63+
return register_tracer(&nop_trace);
64+
}
65+
device_initcall(init_nop_trace);

‎kernel/trace/trace_selftest.c‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -418,6 +418,15 @@ trace_selftest_startup_preemptirqsoff(struct tracer *trace, struct trace_array *
418418
}
419419
#endif /* CONFIG_IRQSOFF_TRACER && CONFIG_PREEMPT_TRACER */
420420

421+
#ifdef CONFIG_NOP_TRACER
422+
int
423+
trace_selftest_startup_nop(struct tracer *trace, struct trace_array *tr)
424+
{
425+
/* What could possibly go wrong? */
426+
return 0;
427+
}
428+
#endif
429+
421430
#ifdef CONFIG_SCHED_TRACER
422431
static int trace_wakeup_test_thread(void *data)
423432
{

0 commit comments

Comments
 (0)