Skip to contentSkip to conversation

tracing: use defined fields to print formats

PATCH Superseded Lai Jiangshan 1 participant 1 message Jul 30, 2009

Subsystems (2)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 tracing: use defined fields to print formats

It seems that ftrace_format_##call() and ftrace_define_fields_##call() are duplicate more or less.

trace_define_field() defines fields and links them into strcut ftrace_event_call. We reuse them to print formats and remove ftrace_format_##call(). It make all things simpler.

TRACE_EVENT_FORMAT_NOFILTER is dropped. Because we should "trace_define_field()" fields for all struct ftrace_event_call, even it's no filter.

The advantages of this fix:

1) A big function ftrace_format_##call() is defined for every event type. It waste a lot of memory. this patch saves these memory.

2) Reduce coupling: ftrace_format_##call() and ftrace_define_fields_##call() are almost the same. We need to maintain them together, it's not good design.

What have been changed for the foramt file after this fix applied:

1) tracing/events/block/block_rq_abort/format:

	field:__data_loc char[] cmd;	offset:36;	size:4;
==>
	field:__data_loc char cmd[];	offset:36;	size:4;

"[]" is added for __dynamic_array() in tip-tree several days ago, it's not in stable kernel yet. It will not break userland tools. This change makes __dynamic_array() and __array() are the same style.

2) tracing/events/ftrace/branch/format:

	field special:char func[TRACE_FUNC_SIZE+1];	offset:16;	size:31;
	field special:char file[TRACE_FUNC_SIZE+1];	offset:47;	size:21;
==>
	field:char func[TRACE_FUNC_SIZE+1];	offset:16;	size:31;
	field:char file[TRACE_FUNC_SIZE+1];	offset:47;	size:21;

This format is exactly the same as __array(). So " special" is not needed. TRACE_FIELD_SPECIAL() is renamed to TRACE_FIELD_ARRAY(). Userland parser for parsing __array() will parse this correctly.

3) tracing/events/ftrace/bprint/format:

	field:char buf;	offset:20;	size:0;
==>
	field:u32 buf[];	offset:20;	size:0;
   tracing/events/ftrace/print/format:
	field:char buf;	offset:16;	size:0;
==>
	field:char buf[];	offset:16;	size:0;

Make its format more correct.

changed from v1:
carefully compare the old and the new format, and fix the difference.

changed from v2:
make __array() generates TYPE ITEM[LEN] again.
changelog itself contains full details.

---
 include/linux/ftrace_event.h     |    2
 include/trace/ftrace.h           |   79 +++------------------------
 kernel/trace/trace.h             |    2
 kernel/trace/trace_event_types.h |   12 +---
 kernel/trace/trace_events.c      |   69 +++++++++++------------
 kernel/trace/trace_export.c      |  114 +++++----------------------------------
 6 files changed, 66 insertions(+), 212 deletions(-)
include/linux/ftrace_event.h +1 -1
index 5c093ff..738b33d 100644
@@ -111,8 +111,8 @@ struct ftrace_event_call {
 	int			(*regfunc)(void);
 	void			(*unregfunc)(void);
 	int			id;
+	const char		*print_fmt;
 	int			(*raw_init)(void);
-	int			(*show_format)(struct trace_seq *s);
 	int			(*define_fields)(void);
 	struct list_head	fields;
 	int			filter_active;
include/trace/ftrace.h +10 -69

137 lines not on this page · raw message

kernel/trace/trace.h +0 -2
index 06886a0..1551c45 100644
@@ -867,8 +867,6 @@ extern const char *__stop___trace_bprintk_fmt[];
 #undef TRACE_EVENT_FORMAT
 #define TRACE_EVENT_FORMAT(call, proto, args, fmt, tstruct, tpfmt)	\
 	extern struct ftrace_event_call event_##call;
-#undef TRACE_EVENT_FORMAT_NOFILTER
-#define TRACE_EVENT_FORMAT_NOFILTER(call, proto, args, fmt, tstruct, tpfmt)
 #include "trace_event_types.h"
 
 #endif /* _LINUX_KERNEL_TRACE_H */
kernel/trace/trace_event_types.h +5 -7
index 6db005e..82534b5 100644
@@ -60,7 +60,7 @@ TRACE_EVENT_FORMAT(context_switch, TRACE_CTX, ctx_switch_entry, ignore,
 	TP_RAW_FMT("%u:%u:%u  ==+ %u:%u:%u [%03u]")
 );
 
-TRACE_EVENT_FORMAT_NOFILTER(special, TRACE_SPECIAL, special_entry, ignore,
+TRACE_EVENT_FORMAT(special, TRACE_SPECIAL, special_entry, ignore,
 	TRACE_STRUCT(
 		TRACE_FIELD(unsigned long, arg1, arg1)
 		TRACE_FIELD(unsigned long, arg2, arg2)
@@ -109,7 +109,7 @@ TRACE_EVENT_FORMAT(bprint, TRACE_BPRINT, bprint_entry, ignore,
 	TRACE_STRUCT(
 		TRACE_FIELD(unsigned long, ip, ip)
 		TRACE_FIELD(char *, fmt, fmt)
-		TRACE_FIELD_ZERO_CHAR(buf)
+		TRACE_FIELD_DYNAMIC_ARRAY(u32, buf)
 	),
 	TP_RAW_FMT("%08lx (%d) fmt:%p %s")
 );
@@ -117,7 +117,7 @@ TRACE_EVENT_FORMAT(bprint, TRACE_BPRINT, bprint_entry, ignore,
 TRACE_EVENT_FORMAT(print, TRACE_PRINT, print_entry, ignore,
 	TRACE_STRUCT(
 		TRACE_FIELD(unsigned long, ip, ip)
-		TRACE_FIELD_ZERO_CHAR(buf)
+		TRACE_FIELD_DYNAMIC_ARRAY(char, buf)
 	),
 	TP_RAW_FMT("%08lx (%d) fmt:%p %s")
 );
@@ -125,10 +125,8 @@ TRACE_EVENT_FORMAT(print, TRACE_PRINT, print_entry, ignore,
 TRACE_EVENT_FORMAT(branch, TRACE_BRANCH, trace_branch, ignore,
 	TRACE_STRUCT(
 		TRACE_FIELD(unsigned int, line, line)
-		TRACE_FIELD_SPECIAL(char func[TRACE_FUNC_SIZE+1], func,
-				    TRACE_FUNC_SIZE+1, func)
-		TRACE_FIELD_SPECIAL(char file[TRACE_FUNC_SIZE+1], file,
-				    TRACE_FUNC_SIZE+1, file)
+		TRACE_FIELD_ARRAY(char, func, TRACE_FUNC_SIZE+1, func)
+		TRACE_FIELD_ARRAY(char, file, TRACE_FUNC_SIZE+1, file)
 		TRACE_FIELD(char, correct, correct)
 	),
 	TP_RAW_FMT("%u:%s:%s (%u)")
kernel/trace/trace_events.c +33 -36

105 lines not on this page · raw message

kernel/trace/trace_export.c +17 -97

164 lines not on this page · raw message