Skip to content

Commit 034939b

Browse files
fweisbecIngo Molnar
authored and
Ingo Molnar
committed
tracing/ftrace: handle more than one stat file per tracer
Impact: new API for tracers Make the stat tracing API reentrant. And also provide the new directory /debugfs/tracing/trace_stat which will contain all the stat files for the current active tracer. Now a tracer will, if desired, want to provide a zero terminated array of tracer_stat structures. Each one contains the callbacks necessary for one stat file. It have to provide at least a name for its stat file, an iterator with stat_start/start_next callback and an output callback for one stat entry. Also adapt the branch tracer to this new API. We create two files "all" and "annotated" inside the /debugfs/tracing/trace_stat directory, making the both stats simultaneously available instead of needing to change an option to switch from one stat file to another. The output of these stats haven't changed. Changes in v2: _ Apply the previous memory leak fix (rebase against tip/master) Changes in v3: _ Merge the patch that adapted the branch tracer to this Api in this patch to not break the kernel build. 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 67d3472 commit 034939b

File tree

3 files changed

+217
-117
lines changed

3 files changed

+217
-117
lines changed

kernel/trace/trace.h

+20-15
Original file line numberDiff line numberDiff line change
@@ -334,6 +334,25 @@ 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+
};
355+
337356
/*
338357
* A specific tracer, represented by methods that operate on a trace array:
339358
*/
@@ -361,21 +380,7 @@ struct tracer {
361380
struct tracer *next;
362381
int print_max;
363382
struct tracer_flags *flags;
364-
365-
/*
366-
* If you change one of the following on tracing runtime, recall
367-
* init_tracer_stat()
368-
*/
369-
370-
/* Iteration over statistic entries */
371-
void *(*stat_start)(void);
372-
void *(*stat_next)(void *prev, int idx);
373-
/* Compare two entries for sorting (optional) for stats */
374-
int (*stat_cmp)(void *p1, void *p2);
375-
/* Print a stat entry */
376-
int (*stat_show)(struct seq_file *s, void *p);
377-
/* Print the headers of your stat entries */
378-
int (*stat_headers)(struct seq_file *s);
383+
struct tracer_stat *stats;
379384
};
380385

381386
struct trace_seq {

kernel/trace/trace_branch.c

+28-41
Original file line numberDiff line numberDiff line change
@@ -306,19 +306,6 @@ static int annotated_branch_stat_cmp(void *p1, void *p2)
306306
}
307307

308308
#ifdef CONFIG_PROFILE_ALL_BRANCHES
309-
enum {
310-
TRACE_BRANCH_OPT_ALL = 0x1
311-
};
312-
313-
static struct tracer_opt branch_opts[] = {
314-
{ TRACER_OPT(stat_all_branch, TRACE_BRANCH_OPT_ALL) },
315-
{ }
316-
};
317-
318-
static struct tracer_flags branch_flags = {
319-
.val = 0,
320-
.opts = branch_opts
321-
};
322309

323310
extern unsigned long __start_branch_profile[];
324311
extern unsigned long __stop_branch_profile[];
@@ -352,28 +339,36 @@ all_branch_stat_next(void *v, int idx)
352339
return p;
353340
}
354341

355-
static int branch_set_flag(u32 old_flags, u32 bit, int set)
356-
{
357-
if (bit == TRACE_BRANCH_OPT_ALL) {
358-
if (set) {
359-
branch_trace.stat_headers = all_branch_stat_headers;
360-
branch_trace.stat_start = all_branch_stat_start;
361-
branch_trace.stat_next = all_branch_stat_next;
362-
branch_trace.stat_cmp = NULL;
363-
} else {
364-
branch_trace.stat_headers =
365-
annotated_branch_stat_headers;
366-
branch_trace.stat_start = annotated_branch_stat_start;
367-
branch_trace.stat_next = annotated_branch_stat_next;
368-
branch_trace.stat_cmp = annotated_branch_stat_cmp;
369-
}
370-
init_tracer_stat(&branch_trace);
371-
}
372-
return 0;
373-
}
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},
374349

350+
{.name = "all",
351+
.stat_start = all_branch_stat_start,
352+
.stat_next = all_branch_stat_next,
353+
.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+
{ }
368+
};
375369
#endif /* CONFIG_PROFILE_ALL_BRANCHES */
376370

371+
377372
static struct tracer branch_trace __read_mostly =
378373
{
379374
.name = "branch",
@@ -383,16 +378,8 @@ static struct tracer branch_trace __read_mostly =
383378
#ifdef CONFIG_FTRACE_SELFTEST
384379
.selftest = trace_selftest_startup_branch,
385380
#endif /* CONFIG_FTRACE_SELFTEST */
386-
#endif /* CONFIG_BRANCH_TRACER */
387-
.stat_start = annotated_branch_stat_start,
388-
.stat_next = annotated_branch_stat_next,
389-
.stat_show = branch_stat_show,
390-
.stat_headers = annotated_branch_stat_headers,
391-
.stat_cmp = annotated_branch_stat_cmp,
392-
#ifdef CONFIG_PROFILE_ALL_BRANCHES
393-
.flags = &branch_flags,
394-
.set_flag = branch_set_flag,
395381
#endif
382+
.stats = branch_stats
396383
};
397384

398385
__init static int init_branch_trace(void)

0 commit comments

Comments
 (0)