Skip to content

Commit 002bb86

Browse files
fweisbecIngo Molnar
authored andcommitted
tracing/ftrace: separate events tracing and stats tracing engine
Impact: tracing's Api change Currently, the stat tracing depends on the events tracing. When you switch to a new tracer, the stats files of the previous tracer will disappear. But it's more scalable to separate those two engines. This way, we can keep the stat files of one or several tracers when we want, without bothering of multiple tracer stat files or tracer switching. To build/destroys its stats files, a tracer just have to call register_stat_tracer/unregister_stat_tracer everytimes it wants to. Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com> Signed-off-by: Steven Rostedt <srostedt@redhat.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
1 parent a14a07b commit 002bb86

File tree

5 files changed

+172
-180
lines changed

5 files changed

+172
-180
lines changed

kernel/trace/trace.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2353,7 +2353,6 @@ static int tracing_set_tracer(char *buf)
23532353
if (ret)
23542354
goto out;
23552355
}
2356-
init_tracer_stat(t);
23572356

23582357
trace_branch_enable(tr);
23592358
out:
@@ -3218,7 +3217,6 @@ __init static int tracer_alloc_buffers(void)
32183217
#else
32193218
current_trace = &nop_trace;
32203219
#endif
3221-
init_tracer_stat(current_trace);
32223220
/* All seems OK, enable tracing */
32233221
tracing_disabled = 0;
32243222

kernel/trace/trace.h

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -334,24 +334,6 @@ struct tracer_flags {
334334
/* Makes more easy to define a tracer opt */
335335
#define TRACER_OPT(s, b) .name = #s, .bit = b
336336

337-
/*
338-
* If you want to provide a stat file (one-shot statistics), fill
339-
* an iterator with stat_start/stat_next and a stat_show callbacks.
340-
* The others callbacks are optional.
341-
*/
342-
struct tracer_stat {
343-
/* The name of your stat file */
344-
const char *name;
345-
/* Iteration over statistic entries */
346-
void *(*stat_start)(void);
347-
void *(*stat_next)(void *prev, int idx);
348-
/* Compare two entries for sorting (optional) for stats */
349-
int (*stat_cmp)(void *p1, void *p2);
350-
/* Print a stat entry */
351-
int (*stat_show)(struct seq_file *s, void *p);
352-
/* Print the headers of your stat entries */
353-
int (*stat_headers)(struct seq_file *s);
354-
};
355337

356338
/*
357339
* A specific tracer, represented by methods that operate on a trace array:
@@ -466,8 +448,6 @@ void tracing_start_sched_switch_record(void);
466448
int register_tracer(struct tracer *type);
467449
void unregister_tracer(struct tracer *type);
468450

469-
void init_tracer_stat(struct tracer *trace);
470-
471451
extern unsigned long nsecs_to_usecs(unsigned long nsecs);
472452

473453
extern unsigned long tracing_max_latency;

kernel/trace/trace_branch.c

Lines changed: 60 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
#include <asm/local.h>
1717

1818
#include "trace.h"
19+
#include "trace_stat.h"
1920
#include "trace_output.h"
2021

21-
static struct tracer branch_trace;
22-
2322
#ifdef CONFIG_BRANCH_TRACER
2423

24+
static struct tracer branch_trace;
2525
static int branch_tracing_enabled __read_mostly;
2626
static DEFINE_MUTEX(branch_tracing_mutex);
2727

@@ -191,6 +191,30 @@ static struct trace_event trace_branch_event = {
191191
.binary = trace_nop_print,
192192
};
193193

194+
static struct tracer branch_trace __read_mostly =
195+
{
196+
.name = "branch",
197+
.init = branch_trace_init,
198+
.reset = branch_trace_reset,
199+
#ifdef CONFIG_FTRACE_SELFTEST
200+
.selftest = trace_selftest_startup_branch,
201+
#endif /* CONFIG_FTRACE_SELFTEST */
202+
};
203+
204+
__init static int init_branch_tracer(void)
205+
{
206+
int ret;
207+
208+
ret = register_ftrace_event(&trace_branch_event);
209+
if (!ret) {
210+
printk(KERN_WARNING "Warning: could not register "
211+
"branch events\n");
212+
return 1;
213+
}
214+
return register_tracer(&branch_trace);
215+
}
216+
device_initcall(init_branch_tracer);
217+
194218
#else
195219
static inline
196220
void trace_likely_condition(struct ftrace_branch_data *f, int val, int expect)
@@ -305,6 +329,29 @@ static int annotated_branch_stat_cmp(void *p1, void *p2)
305329
return 0;
306330
}
307331

332+
static struct tracer_stat annotated_branch_stats = {
333+
.name = "branch_annotated",
334+
.stat_start = annotated_branch_stat_start,
335+
.stat_next = annotated_branch_stat_next,
336+
.stat_cmp = annotated_branch_stat_cmp,
337+
.stat_headers = annotated_branch_stat_headers,
338+
.stat_show = branch_stat_show
339+
};
340+
341+
__init static int init_annotated_branch_stats(void)
342+
{
343+
int ret;
344+
345+
ret = register_stat_tracer(&annotated_branch_stats);
346+
if (!ret) {
347+
printk(KERN_WARNING "Warning: could not register "
348+
"annotated branches stats\n");
349+
return 1;
350+
}
351+
return 0;
352+
}
353+
fs_initcall(init_annotated_branch_stats);
354+
308355
#ifdef CONFIG_PROFILE_ALL_BRANCHES
309356

310357
extern unsigned long __start_branch_profile[];
@@ -339,60 +386,25 @@ all_branch_stat_next(void *v, int idx)
339386
return p;
340387
}
341388

342-
static struct tracer_stat branch_stats[] = {
343-
{.name = "annotated",
344-
.stat_start = annotated_branch_stat_start,
345-
.stat_next = annotated_branch_stat_next,
346-
.stat_cmp = annotated_branch_stat_cmp,
347-
.stat_headers = annotated_branch_stat_headers,
348-
.stat_show = branch_stat_show},
349-
350-
{.name = "all",
389+
static struct tracer_stat all_branch_stats = {
390+
.name = "branch_all",
351391
.stat_start = all_branch_stat_start,
352392
.stat_next = all_branch_stat_next,
353393
.stat_headers = all_branch_stat_headers,
354-
.stat_show = branch_stat_show},
355-
356-
{ }
357-
};
358-
#else
359-
static struct tracer_stat branch_stats[] = {
360-
{.name = "annotated",
361-
.stat_start = annotated_branch_stat_start,
362-
.stat_next = annotated_branch_stat_next,
363-
.stat_cmp = annotated_branch_stat_cmp,
364-
.stat_headers = annotated_branch_stat_headers,
365-
.stat_show = branch_stat_show},
366-
367-
{ }
394+
.stat_show = branch_stat_show
368395
};
369-
#endif /* CONFIG_PROFILE_ALL_BRANCHES */
370396

371-
372-
static struct tracer branch_trace __read_mostly =
397+
__init static int all_annotated_branch_stats(void)
373398
{
374-
.name = "branch",
375-
#ifdef CONFIG_BRANCH_TRACER
376-
.init = branch_trace_init,
377-
.reset = branch_trace_reset,
378-
#ifdef CONFIG_FTRACE_SELFTEST
379-
.selftest = trace_selftest_startup_branch,
380-
#endif /* CONFIG_FTRACE_SELFTEST */
381-
#endif
382-
.stats = branch_stats
383-
};
384-
385-
__init static int init_branch_trace(void)
386-
{
387-
#ifdef CONFIG_BRANCH_TRACER
388399
int ret;
389-
ret = register_ftrace_event(&trace_branch_event);
400+
401+
ret = register_stat_tracer(&all_branch_stats);
390402
if (!ret) {
391-
printk(KERN_WARNING "Warning: could not register branch events\n");
403+
printk(KERN_WARNING "Warning: could not register "
404+
"all branches stats\n");
392405
return 1;
393406
}
394-
#endif
395-
396-
return register_tracer(&branch_trace);
407+
return 0;
397408
}
398-
device_initcall(init_branch_trace);
409+
fs_initcall(all_annotated_branch_stats);
410+
#endif /* CONFIG_PROFILE_ALL_BRANCHES */

0 commit comments

Comments
 (0)