Skip to contentSkip to conversation

tracing/ftrace: provide the base infrastructure for stat tracing

PATCH New Frederic Weisbecker 1 participant 1 message Dec 29, 2008 Tracing

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 tracing/ftrace: provide the base infrastructure for stat tracing

Impact: enhance the tracing API to provide statistical tracing

The goal of this patch is to normalize and make more easy the implementation of statistical (histogram) tracing.

It implements a trace_stat file into the /debugfs/tracing directory where one can print a one-shot output of statistics/histogram entries.

A tracer has to provide two basic iterator callbacks:

stat_start() => the first entry
stat_next(prev, idx) => the next one.

Note that it is adapted for arrays or hash tables or lists.... since it provides a pointer to the previous entry and the current index of the iterator.

These two callbacks are called to get a snapshot of the statistics at each opening of the trace_stat file because.
The values are so updated between two "cat trace_stat". And the tracer is free to lock its datas during the iteration to keep consistent values.

Since it is almost always interesting to sort statisticals values to address the problems by priority, this infrastructure provides a "sorting" of the stat entries too if desired. A tracer has just to provide a stat_cmp callback to compare two entries and the stat tracing infrastructure will build a sorted list of the given entries.

A last callback, called stat_headers, can be implemented by a tracer to output headers on its trace.

If one of these callbacks is changed on runtime, it just have to signal it to the stat tracing API by calling the init_tracer_stat() helper.

Changes in V2:

_ Fix a memory leak if the user opens multiple times the trace_stat file without closing it.
Now we always free our list before rebuilding it.

---
 kernel/trace/Makefile     |    1 +
 kernel/trace/trace.c      |    3 +-
 kernel/trace/trace.h      |   17 +++
 kernel/trace/trace_stat.c |  251 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 271 insertions(+), 1 deletions(-)
kernel/trace/Makefile +1 -0
index 549f93c..31cd5fb 100644
@@ -20,6 +20,7 @@ obj-$(CONFIG_RING_BUFFER) += ring_buffer.o
 
 obj-$(CONFIG_TRACING) += trace.o
 obj-$(CONFIG_TRACING) += trace_output.o
+obj-$(CONFIG_TRACING) += trace_stat.o
 obj-$(CONFIG_CONTEXT_SWITCH_TRACER) += trace_sched_switch.o
 obj-$(CONFIG_SYSPROF_TRACER) += trace_sysprof.o
 obj-$(CONFIG_FUNCTION_TRACER) += trace_functions.o
kernel/trace/trace.c +2 -1
index a087add..bf75d10 100644
@@ -2354,6 +2354,7 @@ static int tracing_set_tracer(char *buf)
 		if (ret)
 			goto out;
 	}
+	init_tracer_stat(t);
 
 	trace_branch_enable(tr);
  out:
@@ -3206,7 +3207,7 @@ __init static int tracer_alloc_buffers(void)
 #else
 	current_trace = &nop_trace;
 #endif
-
+	init_tracer_stat(current_trace);
 	/* All seems OK, enable tracing */
 	tracing_disabled = 0;
 
kernel/trace/trace.h +17 -0
index 6bd71fa..05fa804 100644
@@ -336,6 +336,21 @@ struct tracer {
 	struct tracer		*next;
 	int			print_max;
 	struct tracer_flags 	*flags;
+
+	/*
+	 * If you change one of the following on tracing runtime, recall
+	 * init_tracer_stat()
+	 */
+
+	/* Iteration over statistic entries */
+	void			*(*stat_start)(void);
+	void			*(*stat_next)(void *prev, int idx);
+	/* Compare two entries for sorting (optional) for stats */
+	int			(*stat_cmp)(void *p1, void *p2);
+	/* Print a stat entry */
+	int			(*stat_show)(struct seq_file *s, void *p);
+	/* Print the headers of your stat entries */
+	int			(*stat_headers)(struct seq_file *s);
 };
 
 struct trace_seq {
@@ -421,6 +436,8 @@ void tracing_start_sched_switch_record(void);
 int register_tracer(struct tracer *type);
 void unregister_tracer(struct tracer *type);
 
+void init_tracer_stat(struct tracer *trace);
+
 extern unsigned long nsecs_to_usecs(unsigned long nsecs);
 
 extern unsigned long tracing_max_latency;
kernel/trace/trace_stat.c new file +251 -0

251 lines not on this page · raw message

Signature · 1 line
1.6.0.4