tracing: use defined fields to print formats
PATCH 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.
---
include/linux/ftrace_event.h +1 -1
@@ -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 +9 -68
129 lines not on this page · raw message
kernel/trace/trace.h +0 -2
@@ -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 +1 -1
@@ -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)
kernel/trace/trace_events.c +23 -36
95 lines not on this page · raw message
kernel/trace/trace_export.c +5 -90
125 lines not on this page · raw message
include/linux/ftrace_event.h
Quoted 15 lines · Lai Jiangshan
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 strcutftrace_event_call. We reuse them to print formats and remove ftrace_format_##call(). It make all things simpler.
TRACE_EVENT_FORMAT_NOFILTERis dropped. Because we should "trace_define_field()" fields for all structftrace_event_call, even it's no filter.Signed-off-by Lai Jiangshan <[email protected]>---
include/linux/ftrace_event.h +0
-0
Minor request for future patches: could you please include the diffstat all the time? Makes it much easier to see the general impact of a patch.
Ingo
Steven Rostedt
maintainerQuoted 11 lines · Lai Jiangshan
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 strcutftrace_event_call. We reuse them to print formats and remove ftrace_format_##call(). It make all things simpler.
TRACE_EVENT_FORMAT_NOFILTERis dropped. Because we should "trace_define_field()" fields for all structftrace_event_call, even it's no filter.
OK, I added this and did a diff of the formats before this patch and after the patch. Here they are (with a lot of duplicats cut out).
[
'<' represents the old format
'>' represents the new format (with patch applied)
]
4c4
< field:unsigned short common_type; offset:0; size:2;
---
Quoted 1 line
field:int common_type; offset:0; size:2;
We changed the common type from "unsigned short" to "int"?
45,46c45,46
< field:char rwbs[6]; offset:32; size:6;
< field:char comm[TASK_COMM_LEN]; offset:38; size:16;
---
Quoted 2 lines
field:char[6] rwbs; offset:32; size:6; field:char[TASK_COMM_LEN] comm; offset:38; size:16;
I have several parsers that expect the '[6]' to come after the declaration.
390c390
< print fmt: "type:%u call_site:%lx ptr:%p"
---
Quoted 1 line
print fmt: type:%u call_site:%lx ptr:%p
The 'ftrace' events lost their quotes around the print format.
394c394
< field:unsigned short common_type; offset:0; size:2;
---
Quoted 1 line
field:unsigned char common_type; offset:0; size:2;
And the ftrace events also now use "unsigned char" for the common_type instead of unsigned short?
408c408
< print fmt: "type:%u call_site:%lx ptr:%p req:%lu alloc:%lu flags:%x node:%d"
---
Quoted 1 line
print fmt: type:%u call_site:%lx ptr:%p req:%lu alloc:%lu flags:%x node:%d
423c423
< print fmt: "%llx->%llx type:%u state:%u"
---
Quoted 1 line
print fmt: %llx->%llx type:%u state:%u
436c436
< print fmt: "from: %llx to: %llx"
---
Quoted 1 line
print fmt: from: %llx to: %llx
Lots more quotes missing (I'll cut out the rest of the diff of quotes missing).
447,448c447,448
< field special:char func[TRACE_FUNC_SIZE+1]; offset:16; size:31;
< field special:char file[TRACE_FUNC_SIZE+1]; offset:47; size:21;
---
Quoted 2 lines
field:char func[TRACE_FUNC_SIZE+1][TRACE_FUNC_SIZE+1] func; offset:16; size:31; field:char file[TRACE_FUNC_SIZE+1][TRACE_FUNC_SIZE+1] file; offset:47; size:21;
This is interesting.
Quoted 2 lines
Signed-off-by Lai Jiangshan <[email protected]>
I really like the clean up this patch does, but it must not modify the current format of the files unless there is a really good reason to do so.
Thanks,
-- Steve
Quoted 84 lines · Steven Rostedt
Quoted 10 lines · Lai Jiangshan
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 strcutftrace_event_call. We reuse them to print formats and remove ftrace_format_##call(). It make all things simpler.
TRACE_EVENT_FORMAT_NOFILTERis dropped. Because we should "trace_define_field()" fields for all structftrace_event_call, even it's no filter.OK, I added this and did a diff of the formats before this patch and after the patch. Here they are (with a lot of duplicats cut out).
[
'<' represents the old format
'>' represents the new format (with patch applied)
]4c4
< field:unsigned shortcommon_type; offset:0; size:2;
---Quoted 1 line
field:int common_type; offset:0; size:2;We changed the common type from "unsigned short" to "int"?
45,46c45,46
< field:char rwbs[6]; offset:32; size:6;
< field:char comm[TASK_COMM_LEN]; offset:38; size:16;
---Quoted 2 lines
field:char[6] rwbs; offset:32; size:6; field:char[TASK_COMM_LEN] comm; offset:38; size:16;I have several parsers that expect the '[6]' to come after the declaration.
390c390
< print fmt: "type:%u call_site:%lx ptr:%p"
---Quoted 1 line
print fmt: type:%u call_site:%lx ptr:%p
The 'ftrace' events lost their quotes around the print format.
394c394
< field:unsigned shortcommon_type; offset:0; size:2;
---Quoted 1 line
field:unsigned char common_type; offset:0; size:2;And the ftrace events also now use "unsigned char" for the
common_typeinstead of unsigned short?408c408
< print fmt: "type:%u call_site:%lx ptr:%p req:%lu alloc:%lu flags:%x node:%d"
---Quoted 1 line
print fmt: type:%u call_site:%lx ptr:%p req:%lu alloc:%lu flags:%x node:%d
423c423
< print fmt: "%llx->%llx type:%u state:%u"
---Quoted 1 line
print fmt: %llx->%llx type:%u state:%u
436c436
< print fmt: "from: %llx to: %llx"
---Quoted 1 line
print fmt: from: %llx to: %llx
Lots more quotes missing (I'll cut out the rest of the diff of quotes missing).
447,448c447,448
< field special:char func[TRACE_FUNC_SIZE+1]; offset:16; size:31;
< field special:char file[TRACE_FUNC_SIZE+1]; offset:47; size:21;
---Quoted 2 lines
field:char func[TRACE_FUNC_SIZE+1][TRACE_FUNC_SIZE+1] func; offset:16; size:31; field:char file[TRACE_FUNC_SIZE+1][TRACE_FUNC_SIZE+1] file; offset:47; size:21;This is interesting.
Quoted 7 lines
Quoted 1 line
Signed-off-by Lai Jiangshan <[email protected]>I really like the clean up this patch does, but it must not modify the current format of the files unless there is a really good reason to do so.
Thanks,
I'll fix it.
There're 4 differences:
1) the type of "common_type" is changed.
It's brought by a bug __common_field(int, type, 1); It'll be fixed.
2) Type Item[Len] ==> Type[Len] Item.
(There are the same, )But it can't not be recovered as before.
Because it's brought by trace_define_field(event_call, #type "[" #len "]", #item, I'll fix trace-cmd and make it supports these two style together.
3) double quotation marks for the format is missing. It'll be fixed.
4) a line in events/ftrace/print/format is missing. It'll be fixed.
At the end(fixed patch), the only change is "Type Item[Len] ==> Type[Len] Item".
The values of this patch are:
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.
The difference between ftrace_format_##call() and
ftrace_define_fields_##call() implies a bug.
Example: __common_field(int, type, 1); in
ftrace_define_fields_##call() is a bug.
Thank you.
Lai.
Steven Rostedt
maintainerQuoted 11 lines · Lai Jiangshan
There're 4 differences:
1) the type of "
common_type" is changed.
It's brought by a bug__common_field(int, type, 1);It'll be fixed.2) Type Item[Len] ==> Type[Len] Item.
(There are the same, )But it can't not be recovered as before.
Because it's brought bytrace_define_field(event_call, #type "[" #len "]", #item,I'll fix trace-cmd and make it supports these two style together.
I'll wait for your next patch and see if I can take a crack at getting it back to the old way.
Quoted 4 lines
3) double quotation marks for the format is missing. It'll be fixed.
Quoted 8 lines
4) a line in events/ftrace/print/format is missing. It'll be fixed.
At the end(fixed patch), the only change is "Type Item[Len] ==> Type[Len] Item".
The values of this patch are:
1) A big function ftrace_format_##call() is defined for every event type. it waste a lot of memory. this patch saves these memory.
I agree.
Quoted 4 lines
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.
I agree.
Quoted 6 lines
The difference between ftrace_format_##call() and
ftrace_define_fields_##call() implies a bug.Example:
__common_field(int, type, 1);in
ftrace_define_fields_##call() is a bug.
The problem is that this will not make it until 32, and 31 already has the type item[x] format. Which means tools will be expecting it that way. We can make the tools handle both, but I would really like to prevent that.
I totally agree that your patch is a nice clean up, and saves space and prevents more bugs. On the other hand, we are changing an API to users where all tools that parse this must be able to cope.
I'll wait for your next patch and see if I can't pull something out of my CPP magic hat that can save the day ;-)
-- Steve