2009-04-13 16:25:37 +00:00
|
|
|
/*
|
|
|
|
* Stage 1 of the trace events.
|
|
|
|
*
|
|
|
|
* Override the macros in <trace/trace_events.h> to include the following:
|
|
|
|
*
|
2015-05-13 19:27:47 +00:00
|
|
|
* struct trace_event_raw_<call> {
|
2009-04-13 16:25:37 +00:00
|
|
|
* struct trace_entry ent;
|
|
|
|
* <type> <item>;
|
|
|
|
* <type2> <item2>[<len>];
|
|
|
|
* [...]
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* The <type> <item> is created by the __field(type, item) macro or
|
|
|
|
* the __array(type2, item2, len) macro.
|
|
|
|
* We simply do "type item;", and that will create the fields
|
|
|
|
* in the structure.
|
|
|
|
*/
|
|
|
|
|
2015-04-29 18:36:05 +00:00
|
|
|
#include <linux/trace_events.h>
|
2009-04-13 16:25:37 +00:00
|
|
|
|
2015-03-31 18:37:12 +00:00
|
|
|
#ifndef TRACE_SYSTEM_VAR
|
|
|
|
#define TRACE_SYSTEM_VAR TRACE_SYSTEM
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define __app__(x, y) str__##x##y
|
|
|
|
#define __app(x, y) __app__(x, y)
|
|
|
|
|
|
|
|
#define TRACE_SYSTEM_STRING __app(TRACE_SYSTEM_VAR,__trace_system_name)
|
|
|
|
|
|
|
|
#define TRACE_MAKE_SYSTEM_STR() \
|
|
|
|
static const char TRACE_SYSTEM_STRING[] = \
|
|
|
|
__stringify(TRACE_SYSTEM)
|
|
|
|
|
|
|
|
TRACE_MAKE_SYSTEM_STR();
|
|
|
|
|
tracing: Add TRACE_DEFINE_ENUM() macro to map enums to their values
Several tracepoints use the helper functions __print_symbolic() or
__print_flags() and pass in enums that do the mapping between the
binary data stored and the value to print. This works well for reading
the ASCII trace files, but when the data is read via userspace tools
such as perf and trace-cmd, the conversion of the binary value to a
human string format is lost if an enum is used, as userspace does not
have access to what the ENUM is.
For example, the tracepoint trace_tlb_flush() has:
__print_symbolic(REC->reason,
{ TLB_FLUSH_ON_TASK_SWITCH, "flush on task switch" },
{ TLB_REMOTE_SHOOTDOWN, "remote shootdown" },
{ TLB_LOCAL_SHOOTDOWN, "local shootdown" },
{ TLB_LOCAL_MM_SHOOTDOWN, "local mm shootdown" })
Which maps the enum values to the strings they represent. But perf and
trace-cmd do no know what value TLB_LOCAL_MM_SHOOTDOWN is, and would
not be able to map it.
With TRACE_DEFINE_ENUM(), developers can place these in the event header
files and ftrace will convert the enums to their values:
By adding:
TRACE_DEFINE_ENUM(TLB_FLUSH_ON_TASK_SWITCH);
TRACE_DEFINE_ENUM(TLB_REMOTE_SHOOTDOWN);
TRACE_DEFINE_ENUM(TLB_LOCAL_SHOOTDOWN);
TRACE_DEFINE_ENUM(TLB_LOCAL_MM_SHOOTDOWN);
$ cat /sys/kernel/debug/tracing/events/tlb/tlb_flush/format
[...]
__print_symbolic(REC->reason,
{ 0, "flush on task switch" },
{ 1, "remote shootdown" },
{ 2, "local shootdown" },
{ 3, "local mm shootdown" })
The above is what userspace expects to see, and tools do not need to
be modified to parse them.
Link: http://lkml.kernel.org/r/20150403013802.220157513@goodmis.org
Cc: Guilherme Cox <cox@computer.org>
Cc: Tony Luck <tony.luck@gmail.com>
Cc: Xie XiuQi <xiexiuqi@huawei.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2015-03-24 21:58:09 +00:00
|
|
|
#undef TRACE_DEFINE_ENUM
|
|
|
|
#define TRACE_DEFINE_ENUM(a) \
|
|
|
|
static struct trace_enum_map __used __initdata \
|
|
|
|
__##TRACE_SYSTEM##_##a = \
|
|
|
|
{ \
|
|
|
|
.system = TRACE_SYSTEM_STRING, \
|
|
|
|
.enum_string = #a, \
|
|
|
|
.enum_value = a \
|
|
|
|
}; \
|
|
|
|
static struct trace_enum_map __used \
|
|
|
|
__attribute__((section("_ftrace_enum_map"))) \
|
|
|
|
*TRACE_SYSTEM##_##a = &__##TRACE_SYSTEM##_##a
|
|
|
|
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
/*
|
2009-11-26 08:04:55 +00:00
|
|
|
* DECLARE_EVENT_CLASS can be used to add a generic function
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
* handlers for events. That is, if all events have the same
|
|
|
|
* parameters and just have distinct trace points.
|
|
|
|
* Each tracepoint can be defined with DEFINE_EVENT and that
|
2009-11-26 08:04:55 +00:00
|
|
|
* will map the DECLARE_EVENT_CLASS to the tracepoint.
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
*
|
|
|
|
* TRACE_EVENT is a one to one mapping between tracepoint and template.
|
|
|
|
*/
|
|
|
|
#undef TRACE_EVENT
|
|
|
|
#define TRACE_EVENT(name, proto, args, tstruct, assign, print) \
|
2009-11-26 08:04:55 +00:00
|
|
|
DECLARE_EVENT_CLASS(name, \
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
PARAMS(proto), \
|
|
|
|
PARAMS(args), \
|
|
|
|
PARAMS(tstruct), \
|
|
|
|
PARAMS(assign), \
|
|
|
|
PARAMS(print)); \
|
|
|
|
DEFINE_EVENT(name, name, PARAMS(proto), PARAMS(args));
|
|
|
|
|
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#undef __field
|
|
|
|
#define __field(type, item) type item;
|
|
|
|
|
2009-08-07 02:33:22 +00:00
|
|
|
#undef __field_ext
|
|
|
|
#define __field_ext(type, item, filter_type) type item;
|
|
|
|
|
2014-06-17 12:59:16 +00:00
|
|
|
#undef __field_struct
|
|
|
|
#define __field_struct(type, item) type item;
|
|
|
|
|
|
|
|
#undef __field_struct_ext
|
|
|
|
#define __field_struct_ext(type, item, filter_type) type item;
|
|
|
|
|
2009-04-13 16:25:37 +00:00
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, len) type item[len];
|
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#undef __dynamic_array
|
2009-07-16 02:54:02 +00:00
|
|
|
#define __dynamic_array(type, item, len) u32 __data_loc_##item;
|
2009-04-13 16:25:37 +00:00
|
|
|
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
#undef __string
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#define __string(item, src) __dynamic_array(char, item, -1)
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
|
tracing: Add __bitmask() macro to trace events to cpumasks and other bitmasks
Being able to show a cpumask of events can be useful as some events
may affect only some CPUs. There is no standard way to record the
cpumask and converting it to a string is rather expensive during
the trace as traces happen in hotpaths. It would be better to record
the raw event mask and be able to parse it at print time.
The following macros were added for use with the TRACE_EVENT() macro:
__bitmask()
__assign_bitmask()
__get_bitmask()
To test this, I added this to the sched_migrate_task event, which
looked like this:
TRACE_EVENT(sched_migrate_task,
TP_PROTO(struct task_struct *p, int dest_cpu, const struct cpumask *cpus),
TP_ARGS(p, dest_cpu, cpus),
TP_STRUCT__entry(
__array( char, comm, TASK_COMM_LEN )
__field( pid_t, pid )
__field( int, prio )
__field( int, orig_cpu )
__field( int, dest_cpu )
__bitmask( cpumask, num_possible_cpus() )
),
TP_fast_assign(
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
__entry->pid = p->pid;
__entry->prio = p->prio;
__entry->orig_cpu = task_cpu(p);
__entry->dest_cpu = dest_cpu;
__assign_bitmask(cpumask, cpumask_bits(cpus), num_possible_cpus());
),
TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d cpumask=%s",
__entry->comm, __entry->pid, __entry->prio,
__entry->orig_cpu, __entry->dest_cpu,
__get_bitmask(cpumask))
);
With the output of:
ksmtuned-3613 [003] d..2 485.220508: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=3 dest_cpu=2 cpumask=00000000,0000000f
migration/1-13 [001] d..5 485.221202: sched_migrate_task: comm=ksmtuned pid=3614 prio=120 orig_cpu=1 dest_cpu=0 cpumask=00000000,0000000f
awk-3615 [002] d.H5 485.221747: sched_migrate_task: comm=rcu_preempt pid=7 prio=120 orig_cpu=0 dest_cpu=1 cpumask=00000000,000000ff
migration/2-18 [002] d..5 485.222062: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=2 dest_cpu=3 cpumask=00000000,0000000f
Link: http://lkml.kernel.org/r/1399377998-14870-6-git-send-email-javi.merino@arm.com
Link: http://lkml.kernel.org/r/20140506132238.22e136d1@gandalf.local.home
Suggested-by: Javi Merino <javi.merino@arm.com>
Tested-by: Javi Merino <javi.merino@arm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-06 17:10:24 +00:00
|
|
|
#undef __bitmask
|
|
|
|
#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
|
|
|
|
|
2009-04-13 16:25:37 +00:00
|
|
|
#undef TP_STRUCT__entry
|
|
|
|
#define TP_STRUCT__entry(args...) args
|
|
|
|
|
2009-11-26 08:04:55 +00:00
|
|
|
#undef DECLARE_EVENT_CLASS
|
|
|
|
#define DECLARE_EVENT_CLASS(name, proto, args, tstruct, assign, print) \
|
2015-05-13 19:27:47 +00:00
|
|
|
struct trace_event_raw_##name { \
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
struct trace_entry ent; \
|
|
|
|
tstruct \
|
|
|
|
char __data[0]; \
|
2010-04-20 14:47:33 +00:00
|
|
|
}; \
|
|
|
|
\
|
2015-05-05 15:45:27 +00:00
|
|
|
static struct trace_event_class event_class_##name;
|
2010-04-20 14:47:33 +00:00
|
|
|
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
#undef DEFINE_EVENT
|
|
|
|
#define DEFINE_EVENT(template, name, proto, args) \
|
2015-05-05 15:45:27 +00:00
|
|
|
static struct trace_event_call __used \
|
2010-02-24 18:59:23 +00:00
|
|
|
__attribute__((__aligned__(4))) event_##name
|
2009-04-13 16:25:37 +00:00
|
|
|
|
2013-06-20 15:44:44 +00:00
|
|
|
#undef DEFINE_EVENT_FN
|
|
|
|
#define DEFINE_EVENT_FN(template, name, proto, args, reg, unreg) \
|
|
|
|
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
|
|
|
|
|
2009-11-19 01:36:26 +00:00
|
|
|
#undef DEFINE_EVENT_PRINT
|
|
|
|
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
|
|
|
|
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
|
|
|
|
|
2009-08-24 21:43:13 +00:00
|
|
|
/* Callbacks are meaningless to ftrace. */
|
|
|
|
#undef TRACE_EVENT_FN
|
tracing: Fix double CPP substitution in TRACE_EVENT_FN
TRACE_EVENT_FN relays on TRACE_EVENT by reprocessing its parameters
into the ftrace events CPP macro. This leads to a double substitution
in some cases.
For example, a bad consequence is a format always prefixed by
"%s, %s\n" for every TRACE_EVENT_FN based events.
Eg:
cat /debug/tracing/events/syscalls/sys_enter/format
[...]
print fmt: "%s, %s\n", "\"NR %ld (%lx, %lx, %lx, %lx, %lx, %lx)\"",\
"REC->id, REC->args[0], REC->args[1], REC->args[2], REC->args[3],\
REC->args[4], REC->args[5]"
This creates a failure in post-processing tools such as perf trace or
trace-cmd.
Then drop this double substitution and replace it by a new __cpparg()
macro that relays CPP arguments containing commas.
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Josh Stone <jistone@redhat.com>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Steven Rostedt <srostedt@redhat.com>
Cc: Jason Baron <jbaron@redhat.com>
LKML-Reference: <1251413406-6704-1-git-send-email-fweisbec@gmail.com>
Signed-off-by: Ingo Molnar <mingo@elte.hu>
2009-08-27 22:50:06 +00:00
|
|
|
#define TRACE_EVENT_FN(name, proto, args, tstruct, \
|
|
|
|
assign, print, reg, unreg) \
|
2010-07-20 16:41:24 +00:00
|
|
|
TRACE_EVENT(name, PARAMS(proto), PARAMS(args), \
|
|
|
|
PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
|
2015-12-14 20:18:05 +00:00
|
|
|
|
|
|
|
#undef TRACE_EVENT_FN_COND
|
|
|
|
#define TRACE_EVENT_FN_COND(name, proto, args, cond, tstruct, \
|
|
|
|
assign, print, reg, unreg) \
|
|
|
|
TRACE_EVENT_CONDITION(name, PARAMS(proto), PARAMS(args), PARAMS(cond), \
|
|
|
|
PARAMS(tstruct), PARAMS(assign), PARAMS(print)) \
|
2009-08-24 21:43:13 +00:00
|
|
|
|
2010-11-18 00:46:57 +00:00
|
|
|
#undef TRACE_EVENT_FLAGS
|
|
|
|
#define TRACE_EVENT_FLAGS(name, value) \
|
2010-11-18 01:11:42 +00:00
|
|
|
__TRACE_EVENT_FLAGS(name, value)
|
2010-11-18 00:46:57 +00:00
|
|
|
|
2013-11-14 15:23:04 +00:00
|
|
|
#undef TRACE_EVENT_PERF_PERM
|
|
|
|
#define TRACE_EVENT_PERF_PERM(name, expr...) \
|
|
|
|
__TRACE_EVENT_PERF_PERM(name, expr)
|
|
|
|
|
2009-04-13 16:25:37 +00:00
|
|
|
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stage 2 of the trace events.
|
|
|
|
*
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
* Include the following:
|
|
|
|
*
|
2015-05-13 19:33:52 +00:00
|
|
|
* struct trace_event_data_offsets_<call> {
|
2009-07-16 02:54:02 +00:00
|
|
|
* u32 <item1>;
|
|
|
|
* u32 <item2>;
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
* [...]
|
|
|
|
* };
|
|
|
|
*
|
2009-07-16 02:54:02 +00:00
|
|
|
* The __dynamic_array() macro will create each u32 <item>, this is
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
* to keep the offset of each array from the beginning of the event.
|
2009-07-16 02:54:02 +00:00
|
|
|
* The size of an array is also encoded, in the higher 16 bits of <item>.
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
*/
|
|
|
|
|
tracing: Add TRACE_DEFINE_ENUM() macro to map enums to their values
Several tracepoints use the helper functions __print_symbolic() or
__print_flags() and pass in enums that do the mapping between the
binary data stored and the value to print. This works well for reading
the ASCII trace files, but when the data is read via userspace tools
such as perf and trace-cmd, the conversion of the binary value to a
human string format is lost if an enum is used, as userspace does not
have access to what the ENUM is.
For example, the tracepoint trace_tlb_flush() has:
__print_symbolic(REC->reason,
{ TLB_FLUSH_ON_TASK_SWITCH, "flush on task switch" },
{ TLB_REMOTE_SHOOTDOWN, "remote shootdown" },
{ TLB_LOCAL_SHOOTDOWN, "local shootdown" },
{ TLB_LOCAL_MM_SHOOTDOWN, "local mm shootdown" })
Which maps the enum values to the strings they represent. But perf and
trace-cmd do no know what value TLB_LOCAL_MM_SHOOTDOWN is, and would
not be able to map it.
With TRACE_DEFINE_ENUM(), developers can place these in the event header
files and ftrace will convert the enums to their values:
By adding:
TRACE_DEFINE_ENUM(TLB_FLUSH_ON_TASK_SWITCH);
TRACE_DEFINE_ENUM(TLB_REMOTE_SHOOTDOWN);
TRACE_DEFINE_ENUM(TLB_LOCAL_SHOOTDOWN);
TRACE_DEFINE_ENUM(TLB_LOCAL_MM_SHOOTDOWN);
$ cat /sys/kernel/debug/tracing/events/tlb/tlb_flush/format
[...]
__print_symbolic(REC->reason,
{ 0, "flush on task switch" },
{ 1, "remote shootdown" },
{ 2, "local shootdown" },
{ 3, "local mm shootdown" })
The above is what userspace expects to see, and tools do not need to
be modified to parse them.
Link: http://lkml.kernel.org/r/20150403013802.220157513@goodmis.org
Cc: Guilherme Cox <cox@computer.org>
Cc: Tony Luck <tony.luck@gmail.com>
Cc: Xie XiuQi <xiexiuqi@huawei.com>
Acked-by: Namhyung Kim <namhyung@kernel.org>
Reviewed-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Tested-by: Masami Hiramatsu <masami.hiramatsu.pt@hitachi.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2015-03-24 21:58:09 +00:00
|
|
|
#undef TRACE_DEFINE_ENUM
|
|
|
|
#define TRACE_DEFINE_ENUM(a)
|
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#undef __field
|
2009-08-07 02:33:22 +00:00
|
|
|
#define __field(type, item)
|
|
|
|
|
|
|
|
#undef __field_ext
|
|
|
|
#define __field_ext(type, item, filter_type)
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
|
2014-06-17 12:59:16 +00:00
|
|
|
#undef __field_struct
|
|
|
|
#define __field_struct(type, item)
|
|
|
|
|
|
|
|
#undef __field_struct_ext
|
|
|
|
#define __field_struct_ext(type, item, filter_type)
|
|
|
|
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, len)
|
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#undef __dynamic_array
|
2009-07-16 02:54:02 +00:00
|
|
|
#define __dynamic_array(type, item, len) u32 item;
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
|
|
|
|
#undef __string
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#define __string(item, src) __dynamic_array(char, item, -1)
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
|
tracing: Add __bitmask() macro to trace events to cpumasks and other bitmasks
Being able to show a cpumask of events can be useful as some events
may affect only some CPUs. There is no standard way to record the
cpumask and converting it to a string is rather expensive during
the trace as traces happen in hotpaths. It would be better to record
the raw event mask and be able to parse it at print time.
The following macros were added for use with the TRACE_EVENT() macro:
__bitmask()
__assign_bitmask()
__get_bitmask()
To test this, I added this to the sched_migrate_task event, which
looked like this:
TRACE_EVENT(sched_migrate_task,
TP_PROTO(struct task_struct *p, int dest_cpu, const struct cpumask *cpus),
TP_ARGS(p, dest_cpu, cpus),
TP_STRUCT__entry(
__array( char, comm, TASK_COMM_LEN )
__field( pid_t, pid )
__field( int, prio )
__field( int, orig_cpu )
__field( int, dest_cpu )
__bitmask( cpumask, num_possible_cpus() )
),
TP_fast_assign(
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
__entry->pid = p->pid;
__entry->prio = p->prio;
__entry->orig_cpu = task_cpu(p);
__entry->dest_cpu = dest_cpu;
__assign_bitmask(cpumask, cpumask_bits(cpus), num_possible_cpus());
),
TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d cpumask=%s",
__entry->comm, __entry->pid, __entry->prio,
__entry->orig_cpu, __entry->dest_cpu,
__get_bitmask(cpumask))
);
With the output of:
ksmtuned-3613 [003] d..2 485.220508: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=3 dest_cpu=2 cpumask=00000000,0000000f
migration/1-13 [001] d..5 485.221202: sched_migrate_task: comm=ksmtuned pid=3614 prio=120 orig_cpu=1 dest_cpu=0 cpumask=00000000,0000000f
awk-3615 [002] d.H5 485.221747: sched_migrate_task: comm=rcu_preempt pid=7 prio=120 orig_cpu=0 dest_cpu=1 cpumask=00000000,000000ff
migration/2-18 [002] d..5 485.222062: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=2 dest_cpu=3 cpumask=00000000,0000000f
Link: http://lkml.kernel.org/r/1399377998-14870-6-git-send-email-javi.merino@arm.com
Link: http://lkml.kernel.org/r/20140506132238.22e136d1@gandalf.local.home
Suggested-by: Javi Merino <javi.merino@arm.com>
Tested-by: Javi Merino <javi.merino@arm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-06 17:10:24 +00:00
|
|
|
#undef __bitmask
|
|
|
|
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
|
|
|
|
|
2009-11-26 08:04:55 +00:00
|
|
|
#undef DECLARE_EVENT_CLASS
|
|
|
|
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
|
2015-05-13 19:33:52 +00:00
|
|
|
struct trace_event_data_offsets_##call { \
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
tstruct; \
|
|
|
|
};
|
|
|
|
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
#undef DEFINE_EVENT
|
|
|
|
#define DEFINE_EVENT(template, name, proto, args)
|
|
|
|
|
2009-11-19 01:36:26 +00:00
|
|
|
#undef DEFINE_EVENT_PRINT
|
|
|
|
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
|
|
|
|
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
|
|
|
|
|
2010-11-18 00:46:57 +00:00
|
|
|
#undef TRACE_EVENT_FLAGS
|
|
|
|
#define TRACE_EVENT_FLAGS(event, flag)
|
|
|
|
|
2013-11-14 15:23:04 +00:00
|
|
|
#undef TRACE_EVENT_PERF_PERM
|
|
|
|
#define TRACE_EVENT_PERF_PERM(event, expr...)
|
|
|
|
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Stage 3 of the trace events.
|
|
|
|
*
|
2009-04-13 16:25:37 +00:00
|
|
|
* Override the macros in <trace/trace_events.h> to include the following:
|
|
|
|
*
|
|
|
|
* enum print_line_t
|
2015-05-05 18:18:11 +00:00
|
|
|
* trace_raw_output_<call>(struct trace_iterator *iter, int flags)
|
2009-04-13 16:25:37 +00:00
|
|
|
* {
|
|
|
|
* struct trace_seq *s = &iter->seq;
|
2015-05-13 19:27:47 +00:00
|
|
|
* struct trace_event_raw_<call> *field; <-- defined in stage 1
|
2009-04-13 16:25:37 +00:00
|
|
|
* struct trace_entry *entry;
|
2010-06-03 10:26:24 +00:00
|
|
|
* struct trace_seq *p = &iter->tmp_seq;
|
2009-04-13 16:25:37 +00:00
|
|
|
* int ret;
|
|
|
|
*
|
|
|
|
* entry = iter->ent;
|
|
|
|
*
|
2010-04-23 14:38:03 +00:00
|
|
|
* if (entry->type != event_<call>->event.type) {
|
2009-04-13 16:25:37 +00:00
|
|
|
* WARN_ON_ONCE(1);
|
|
|
|
* return TRACE_TYPE_UNHANDLED;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* field = (typeof(field))entry;
|
|
|
|
*
|
2009-06-03 13:52:03 +00:00
|
|
|
* trace_seq_init(p);
|
2010-03-24 02:58:24 +00:00
|
|
|
* ret = trace_seq_printf(s, "%s: ", <call>);
|
|
|
|
* if (ret)
|
|
|
|
* ret = trace_seq_printf(s, <TP_printk> "\n");
|
2009-04-13 16:25:37 +00:00
|
|
|
* if (!ret)
|
|
|
|
* return TRACE_TYPE_PARTIAL_LINE;
|
|
|
|
*
|
|
|
|
* return TRACE_TYPE_HANDLED;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* This is the method used to print the raw event to the trace
|
|
|
|
* output format. Note, this is not needed if the data is read
|
|
|
|
* in binary.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef __entry
|
|
|
|
#define __entry field
|
|
|
|
|
|
|
|
#undef TP_printk
|
|
|
|
#define TP_printk(fmt, args...) fmt "\n", args
|
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#undef __get_dynamic_array
|
|
|
|
#define __get_dynamic_array(field) \
|
2009-07-16 02:54:02 +00:00
|
|
|
((void *)__entry + (__entry->__data_loc_##field & 0xffff))
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
|
2014-06-04 18:29:33 +00:00
|
|
|
#undef __get_dynamic_array_len
|
|
|
|
#define __get_dynamic_array_len(field) \
|
|
|
|
((__entry->__data_loc_##field >> 16) & 0xffff)
|
|
|
|
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
#undef __get_str
|
2016-07-01 23:44:34 +00:00
|
|
|
#define __get_str(field) ((char *)__get_dynamic_array(field))
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
|
tracing: Add __bitmask() macro to trace events to cpumasks and other bitmasks
Being able to show a cpumask of events can be useful as some events
may affect only some CPUs. There is no standard way to record the
cpumask and converting it to a string is rather expensive during
the trace as traces happen in hotpaths. It would be better to record
the raw event mask and be able to parse it at print time.
The following macros were added for use with the TRACE_EVENT() macro:
__bitmask()
__assign_bitmask()
__get_bitmask()
To test this, I added this to the sched_migrate_task event, which
looked like this:
TRACE_EVENT(sched_migrate_task,
TP_PROTO(struct task_struct *p, int dest_cpu, const struct cpumask *cpus),
TP_ARGS(p, dest_cpu, cpus),
TP_STRUCT__entry(
__array( char, comm, TASK_COMM_LEN )
__field( pid_t, pid )
__field( int, prio )
__field( int, orig_cpu )
__field( int, dest_cpu )
__bitmask( cpumask, num_possible_cpus() )
),
TP_fast_assign(
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
__entry->pid = p->pid;
__entry->prio = p->prio;
__entry->orig_cpu = task_cpu(p);
__entry->dest_cpu = dest_cpu;
__assign_bitmask(cpumask, cpumask_bits(cpus), num_possible_cpus());
),
TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d cpumask=%s",
__entry->comm, __entry->pid, __entry->prio,
__entry->orig_cpu, __entry->dest_cpu,
__get_bitmask(cpumask))
);
With the output of:
ksmtuned-3613 [003] d..2 485.220508: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=3 dest_cpu=2 cpumask=00000000,0000000f
migration/1-13 [001] d..5 485.221202: sched_migrate_task: comm=ksmtuned pid=3614 prio=120 orig_cpu=1 dest_cpu=0 cpumask=00000000,0000000f
awk-3615 [002] d.H5 485.221747: sched_migrate_task: comm=rcu_preempt pid=7 prio=120 orig_cpu=0 dest_cpu=1 cpumask=00000000,000000ff
migration/2-18 [002] d..5 485.222062: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=2 dest_cpu=3 cpumask=00000000,0000000f
Link: http://lkml.kernel.org/r/1399377998-14870-6-git-send-email-javi.merino@arm.com
Link: http://lkml.kernel.org/r/20140506132238.22e136d1@gandalf.local.home
Suggested-by: Javi Merino <javi.merino@arm.com>
Tested-by: Javi Merino <javi.merino@arm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-06 17:10:24 +00:00
|
|
|
#undef __get_bitmask
|
|
|
|
#define __get_bitmask(field) \
|
|
|
|
({ \
|
|
|
|
void *__bitmask = __get_dynamic_array(field); \
|
|
|
|
unsigned int __bitmask_size; \
|
2014-06-04 18:29:33 +00:00
|
|
|
__bitmask_size = __get_dynamic_array_len(field); \
|
2015-05-04 22:12:44 +00:00
|
|
|
trace_print_bitmask_seq(p, __bitmask, __bitmask_size); \
|
tracing: Add __bitmask() macro to trace events to cpumasks and other bitmasks
Being able to show a cpumask of events can be useful as some events
may affect only some CPUs. There is no standard way to record the
cpumask and converting it to a string is rather expensive during
the trace as traces happen in hotpaths. It would be better to record
the raw event mask and be able to parse it at print time.
The following macros were added for use with the TRACE_EVENT() macro:
__bitmask()
__assign_bitmask()
__get_bitmask()
To test this, I added this to the sched_migrate_task event, which
looked like this:
TRACE_EVENT(sched_migrate_task,
TP_PROTO(struct task_struct *p, int dest_cpu, const struct cpumask *cpus),
TP_ARGS(p, dest_cpu, cpus),
TP_STRUCT__entry(
__array( char, comm, TASK_COMM_LEN )
__field( pid_t, pid )
__field( int, prio )
__field( int, orig_cpu )
__field( int, dest_cpu )
__bitmask( cpumask, num_possible_cpus() )
),
TP_fast_assign(
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
__entry->pid = p->pid;
__entry->prio = p->prio;
__entry->orig_cpu = task_cpu(p);
__entry->dest_cpu = dest_cpu;
__assign_bitmask(cpumask, cpumask_bits(cpus), num_possible_cpus());
),
TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d cpumask=%s",
__entry->comm, __entry->pid, __entry->prio,
__entry->orig_cpu, __entry->dest_cpu,
__get_bitmask(cpumask))
);
With the output of:
ksmtuned-3613 [003] d..2 485.220508: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=3 dest_cpu=2 cpumask=00000000,0000000f
migration/1-13 [001] d..5 485.221202: sched_migrate_task: comm=ksmtuned pid=3614 prio=120 orig_cpu=1 dest_cpu=0 cpumask=00000000,0000000f
awk-3615 [002] d.H5 485.221747: sched_migrate_task: comm=rcu_preempt pid=7 prio=120 orig_cpu=0 dest_cpu=1 cpumask=00000000,000000ff
migration/2-18 [002] d..5 485.222062: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=2 dest_cpu=3 cpumask=00000000,0000000f
Link: http://lkml.kernel.org/r/1399377998-14870-6-git-send-email-javi.merino@arm.com
Link: http://lkml.kernel.org/r/20140506132238.22e136d1@gandalf.local.home
Suggested-by: Javi Merino <javi.merino@arm.com>
Tested-by: Javi Merino <javi.merino@arm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-06 17:10:24 +00:00
|
|
|
})
|
|
|
|
|
2009-05-26 18:25:22 +00:00
|
|
|
#undef __print_flags
|
|
|
|
#define __print_flags(flag, delim, flag_array...) \
|
|
|
|
({ \
|
2009-09-14 15:18:02 +00:00
|
|
|
static const struct trace_print_flags __flags[] = \
|
2009-05-26 18:25:22 +00:00
|
|
|
{ flag_array, { -1, NULL }}; \
|
2015-05-04 22:12:44 +00:00
|
|
|
trace_print_flags_seq(p, delim, flag, __flags); \
|
2009-05-26 18:25:22 +00:00
|
|
|
})
|
|
|
|
|
2009-05-20 23:21:47 +00:00
|
|
|
#undef __print_symbolic
|
|
|
|
#define __print_symbolic(value, symbol_array...) \
|
|
|
|
({ \
|
|
|
|
static const struct trace_print_flags symbols[] = \
|
|
|
|
{ symbol_array, { -1, NULL }}; \
|
2015-05-04 22:12:44 +00:00
|
|
|
trace_print_symbols_seq(p, value, symbols); \
|
2009-05-20 23:21:47 +00:00
|
|
|
})
|
|
|
|
|
2011-04-19 01:35:28 +00:00
|
|
|
#undef __print_symbolic_u64
|
|
|
|
#if BITS_PER_LONG == 32
|
|
|
|
#define __print_symbolic_u64(value, symbol_array...) \
|
|
|
|
({ \
|
|
|
|
static const struct trace_print_flags_u64 symbols[] = \
|
|
|
|
{ symbol_array, { -1, NULL } }; \
|
2015-05-04 22:12:44 +00:00
|
|
|
trace_print_symbols_seq_u64(p, value, symbols); \
|
2011-04-19 01:35:28 +00:00
|
|
|
})
|
|
|
|
#else
|
|
|
|
#define __print_symbolic_u64(value, symbol_array...) \
|
|
|
|
__print_symbolic(value, symbol_array)
|
|
|
|
#endif
|
|
|
|
|
2010-04-01 11:40:58 +00:00
|
|
|
#undef __print_hex
|
2017-01-25 01:28:16 +00:00
|
|
|
#define __print_hex(buf, buf_len) \
|
|
|
|
trace_print_hex_seq(p, buf, buf_len, true)
|
|
|
|
|
|
|
|
#undef __print_hex_str
|
|
|
|
#define __print_hex_str(buf, buf_len) \
|
|
|
|
trace_print_hex_seq(p, buf, buf_len, false)
|
2010-04-01 11:40:58 +00:00
|
|
|
|
2015-01-28 12:48:53 +00:00
|
|
|
#undef __print_array
|
|
|
|
#define __print_array(array, count, el_size) \
|
|
|
|
({ \
|
|
|
|
BUILD_BUG_ON(el_size != 1 && el_size != 2 && \
|
|
|
|
el_size != 4 && el_size != 8); \
|
2015-05-04 22:12:44 +00:00
|
|
|
trace_print_array_seq(p, array, count, el_size); \
|
2015-01-28 12:48:53 +00:00
|
|
|
})
|
|
|
|
|
2009-11-26 08:04:55 +00:00
|
|
|
#undef DECLARE_EVENT_CLASS
|
|
|
|
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
|
2010-02-16 15:38:47 +00:00
|
|
|
static notrace enum print_line_t \
|
2015-05-05 18:18:11 +00:00
|
|
|
trace_raw_output_##call(struct trace_iterator *iter, int flags, \
|
|
|
|
struct trace_event *trace_event) \
|
2009-04-13 16:25:37 +00:00
|
|
|
{ \
|
|
|
|
struct trace_seq *s = &iter->seq; \
|
2013-02-21 02:32:38 +00:00
|
|
|
struct trace_seq __maybe_unused *p = &iter->tmp_seq; \
|
2015-05-13 19:27:47 +00:00
|
|
|
struct trace_event_raw_##call *field; \
|
2009-04-13 16:25:37 +00:00
|
|
|
int ret; \
|
|
|
|
\
|
2013-02-21 02:32:38 +00:00
|
|
|
field = (typeof(field))iter->ent; \
|
2010-04-23 14:00:22 +00:00
|
|
|
\
|
2015-05-05 18:18:11 +00:00
|
|
|
ret = trace_raw_output_prep(iter, trace_event); \
|
2014-11-14 16:42:06 +00:00
|
|
|
if (ret != TRACE_TYPE_HANDLED) \
|
2013-02-21 02:32:38 +00:00
|
|
|
return ret; \
|
|
|
|
\
|
2014-11-12 15:29:54 +00:00
|
|
|
trace_seq_printf(s, print); \
|
2009-04-13 16:25:37 +00:00
|
|
|
\
|
2014-11-12 15:29:54 +00:00
|
|
|
return trace_handle_return(s); \
|
2010-04-23 14:00:22 +00:00
|
|
|
} \
|
2015-05-13 19:35:44 +00:00
|
|
|
static struct trace_event_functions trace_event_type_funcs_##call = { \
|
2015-05-05 18:18:11 +00:00
|
|
|
.trace = trace_raw_output_##call, \
|
2010-04-23 14:00:22 +00:00
|
|
|
};
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
|
2009-11-19 01:36:26 +00:00
|
|
|
#undef DEFINE_EVENT_PRINT
|
|
|
|
#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
|
2010-02-16 15:38:47 +00:00
|
|
|
static notrace enum print_line_t \
|
2015-05-05 18:18:11 +00:00
|
|
|
trace_raw_output_##call(struct trace_iterator *iter, int flags, \
|
2010-04-22 22:46:14 +00:00
|
|
|
struct trace_event *event) \
|
2009-11-19 01:36:26 +00:00
|
|
|
{ \
|
2015-05-13 19:27:47 +00:00
|
|
|
struct trace_event_raw_##template *field; \
|
2009-11-19 01:36:26 +00:00
|
|
|
struct trace_entry *entry; \
|
2010-06-03 10:26:24 +00:00
|
|
|
struct trace_seq *p = &iter->tmp_seq; \
|
2009-04-13 16:25:37 +00:00
|
|
|
\
|
|
|
|
entry = iter->ent; \
|
|
|
|
\
|
2010-04-23 14:38:03 +00:00
|
|
|
if (entry->type != event_##call.event.type) { \
|
2009-04-13 16:25:37 +00:00
|
|
|
WARN_ON_ONCE(1); \
|
|
|
|
return TRACE_TYPE_UNHANDLED; \
|
|
|
|
} \
|
|
|
|
\
|
|
|
|
field = (typeof(field))entry; \
|
|
|
|
\
|
2009-06-03 13:52:03 +00:00
|
|
|
trace_seq_init(p); \
|
2015-05-05 18:18:11 +00:00
|
|
|
return trace_output_call(iter, #call, print); \
|
2010-04-23 14:00:22 +00:00
|
|
|
} \
|
2015-05-13 19:35:44 +00:00
|
|
|
static struct trace_event_functions trace_event_type_funcs_##call = { \
|
2015-05-05 18:18:11 +00:00
|
|
|
.trace = trace_raw_output_##call, \
|
2010-04-23 14:00:22 +00:00
|
|
|
};
|
2009-11-19 01:36:26 +00:00
|
|
|
|
2009-04-13 16:25:37 +00:00
|
|
|
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
|
|
|
|
|
2009-08-07 02:33:22 +00:00
|
|
|
#undef __field_ext
|
|
|
|
#define __field_ext(type, item, filter_type) \
|
2009-04-13 16:25:37 +00:00
|
|
|
ret = trace_define_field(event_call, #type, #item, \
|
|
|
|
offsetof(typeof(field), item), \
|
2009-08-07 02:33:22 +00:00
|
|
|
sizeof(field.item), \
|
|
|
|
is_signed_type(type), filter_type); \
|
2009-04-13 16:25:37 +00:00
|
|
|
if (ret) \
|
|
|
|
return ret;
|
|
|
|
|
2014-06-17 12:59:16 +00:00
|
|
|
#undef __field_struct_ext
|
|
|
|
#define __field_struct_ext(type, item, filter_type) \
|
|
|
|
ret = trace_define_field(event_call, #type, #item, \
|
|
|
|
offsetof(typeof(field), item), \
|
|
|
|
sizeof(field.item), \
|
|
|
|
0, filter_type); \
|
|
|
|
if (ret) \
|
|
|
|
return ret;
|
|
|
|
|
2009-08-07 02:33:22 +00:00
|
|
|
#undef __field
|
|
|
|
#define __field(type, item) __field_ext(type, item, FILTER_OTHER)
|
|
|
|
|
2014-06-17 12:59:16 +00:00
|
|
|
#undef __field_struct
|
|
|
|
#define __field_struct(type, item) __field_struct_ext(type, item, FILTER_OTHER)
|
|
|
|
|
2009-04-13 16:25:37 +00:00
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, len) \
|
2010-11-13 03:32:11 +00:00
|
|
|
do { \
|
2014-02-14 03:51:48 +00:00
|
|
|
char *type_str = #type"["__stringify(len)"]"; \
|
2010-11-13 03:32:11 +00:00
|
|
|
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
|
2014-02-14 03:51:48 +00:00
|
|
|
ret = trace_define_field(event_call, type_str, #item, \
|
2009-04-13 16:25:37 +00:00
|
|
|
offsetof(typeof(field), item), \
|
2009-12-15 07:39:38 +00:00
|
|
|
sizeof(field.item), \
|
|
|
|
is_signed_type(type), FILTER_OTHER); \
|
2010-11-13 03:32:11 +00:00
|
|
|
if (ret) \
|
|
|
|
return ret; \
|
|
|
|
} while (0);
|
2009-04-13 16:25:37 +00:00
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#undef __dynamic_array
|
|
|
|
#define __dynamic_array(type, item, len) \
|
2009-07-16 02:53:34 +00:00
|
|
|
ret = trace_define_field(event_call, "__data_loc " #type "[]", #item, \
|
2009-08-07 02:33:22 +00:00
|
|
|
offsetof(typeof(field), __data_loc_##item), \
|
2009-12-15 07:39:38 +00:00
|
|
|
sizeof(field.__data_loc_##item), \
|
|
|
|
is_signed_type(type), FILTER_OTHER);
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
#undef __string
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#define __string(item, src) __dynamic_array(char, item, -1)
|
tracing/events: provide string with undefined size support
This patch provides the support for dynamic size strings on
event tracing.
The key concept is to use a structure with an ending char array field of
undefined size and use such ability to allocate the minimal size on the
ring buffer to make one or more string entries fit inside, as opposite
to a fixed length strings with upper bound.
The strings themselves are represented using fields which have an offset
value from the beginning of the entry.
This patch provides three new macros:
__string(item, src)
This one declares a string to the structure inside TP_STRUCT__entry.
You need to provide the name of the string field and the source that will
be copied inside.
This will also add the dynamic size of the string needed for the ring
buffer entry allocation.
A stack allocated structure is used to temporarily store the offset
of each strings, avoiding double calls to strlen() on each event
insertion.
__get_str(field)
This one will give you a pointer to the string you have created. This
is an abstract helper to resolve the absolute address given the field
name which is a relative address from the beginning of the trace_structure.
__assign_str(dst, src)
Use this macro to automatically perform the string copy from src to
dst. src must be a variable to assign and dst is the name of a __string
field.
Example on how to use it:
TRACE_EVENT(my_event,
TP_PROTO(char *src1, char *src2),
TP_ARGS(src1, src2),
TP_STRUCT__entry(
__string(str1, src1)
__string(str2, src2)
),
TP_fast_assign(
__assign_str(str1, src1);
__assign_str(str2, src2);
),
TP_printk("%s %s", __get_str(src1), __get_str(src2))
)
Of course you can mix-up any __field or __array inside this
TRACE_EVENT. The position of the __string or __assign_str
doesn't matter.
Changes in v2:
Address the suggestion of Steven Rostedt: drop the opening_string() macro
and redefine __ending_string() to get the size of the string to be copied
instead of overwritting the whole ring buffer allocation.
Changes in v3:
Address other suggestions of Steven Rostedt and Peter Zijlstra with
some changes: drop the __ending_string and the need to have only one
string field.
Use offsets instead of absolute addresses.
[ Impact: allow more compact memory usage for string tracing ]
Signed-off-by: Frederic Weisbecker <fweisbec@gmail.com>
Cc: Steven Rostedt <rostedt@goodmis.org>
Cc: Li Zefan <lizf@cn.fujitsu.com>
Cc: Peter Zijlstra <a.p.zijlstra@chello.nl>
2009-04-19 02:51:29 +00:00
|
|
|
|
tracing: Add __bitmask() macro to trace events to cpumasks and other bitmasks
Being able to show a cpumask of events can be useful as some events
may affect only some CPUs. There is no standard way to record the
cpumask and converting it to a string is rather expensive during
the trace as traces happen in hotpaths. It would be better to record
the raw event mask and be able to parse it at print time.
The following macros were added for use with the TRACE_EVENT() macro:
__bitmask()
__assign_bitmask()
__get_bitmask()
To test this, I added this to the sched_migrate_task event, which
looked like this:
TRACE_EVENT(sched_migrate_task,
TP_PROTO(struct task_struct *p, int dest_cpu, const struct cpumask *cpus),
TP_ARGS(p, dest_cpu, cpus),
TP_STRUCT__entry(
__array( char, comm, TASK_COMM_LEN )
__field( pid_t, pid )
__field( int, prio )
__field( int, orig_cpu )
__field( int, dest_cpu )
__bitmask( cpumask, num_possible_cpus() )
),
TP_fast_assign(
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
__entry->pid = p->pid;
__entry->prio = p->prio;
__entry->orig_cpu = task_cpu(p);
__entry->dest_cpu = dest_cpu;
__assign_bitmask(cpumask, cpumask_bits(cpus), num_possible_cpus());
),
TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d cpumask=%s",
__entry->comm, __entry->pid, __entry->prio,
__entry->orig_cpu, __entry->dest_cpu,
__get_bitmask(cpumask))
);
With the output of:
ksmtuned-3613 [003] d..2 485.220508: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=3 dest_cpu=2 cpumask=00000000,0000000f
migration/1-13 [001] d..5 485.221202: sched_migrate_task: comm=ksmtuned pid=3614 prio=120 orig_cpu=1 dest_cpu=0 cpumask=00000000,0000000f
awk-3615 [002] d.H5 485.221747: sched_migrate_task: comm=rcu_preempt pid=7 prio=120 orig_cpu=0 dest_cpu=1 cpumask=00000000,000000ff
migration/2-18 [002] d..5 485.222062: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=2 dest_cpu=3 cpumask=00000000,0000000f
Link: http://lkml.kernel.org/r/1399377998-14870-6-git-send-email-javi.merino@arm.com
Link: http://lkml.kernel.org/r/20140506132238.22e136d1@gandalf.local.home
Suggested-by: Javi Merino <javi.merino@arm.com>
Tested-by: Javi Merino <javi.merino@arm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-06 17:10:24 +00:00
|
|
|
#undef __bitmask
|
|
|
|
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
|
|
|
|
|
2009-11-26 08:04:55 +00:00
|
|
|
#undef DECLARE_EVENT_CLASS
|
|
|
|
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, func, print) \
|
2013-02-21 02:33:33 +00:00
|
|
|
static int notrace __init \
|
2015-05-13 19:37:57 +00:00
|
|
|
trace_event_define_fields_##call(struct trace_event_call *event_call) \
|
2009-04-13 16:25:37 +00:00
|
|
|
{ \
|
2015-05-13 19:27:47 +00:00
|
|
|
struct trace_event_raw_##call field; \
|
2009-04-13 16:25:37 +00:00
|
|
|
int ret; \
|
|
|
|
\
|
|
|
|
tstruct; \
|
|
|
|
\
|
|
|
|
return ret; \
|
|
|
|
}
|
|
|
|
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
#undef DEFINE_EVENT
|
|
|
|
#define DEFINE_EVENT(template, name, proto, args)
|
|
|
|
|
2009-11-19 01:36:26 +00:00
|
|
|
#undef DEFINE_EVENT_PRINT
|
|
|
|
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
|
|
|
|
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
|
|
|
|
|
2009-04-13 16:25:37 +00:00
|
|
|
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
|
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
/*
|
|
|
|
* remember the offset of each array from the beginning of the event.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef __entry
|
|
|
|
#define __entry entry
|
|
|
|
|
|
|
|
#undef __field
|
|
|
|
#define __field(type, item)
|
|
|
|
|
2009-08-07 02:33:22 +00:00
|
|
|
#undef __field_ext
|
|
|
|
#define __field_ext(type, item, filter_type)
|
|
|
|
|
2014-06-17 12:59:16 +00:00
|
|
|
#undef __field_struct
|
|
|
|
#define __field_struct(type, item)
|
|
|
|
|
|
|
|
#undef __field_struct_ext
|
|
|
|
#define __field_struct_ext(type, item, filter_type)
|
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, len)
|
|
|
|
|
|
|
|
#undef __dynamic_array
|
|
|
|
#define __dynamic_array(type, item, len) \
|
2014-03-01 05:32:17 +00:00
|
|
|
__item_length = (len) * sizeof(type); \
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
__data_offsets->item = __data_size + \
|
|
|
|
offsetof(typeof(*entry), __data); \
|
2014-03-01 05:32:17 +00:00
|
|
|
__data_offsets->item |= __item_length << 16; \
|
|
|
|
__data_size += __item_length;
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
|
|
|
|
#undef __string
|
2013-11-26 14:22:54 +00:00
|
|
|
#define __string(item, src) __dynamic_array(char, item, \
|
|
|
|
strlen((src) ? (const char *)(src) : "(null)") + 1)
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
|
tracing: Add __bitmask() macro to trace events to cpumasks and other bitmasks
Being able to show a cpumask of events can be useful as some events
may affect only some CPUs. There is no standard way to record the
cpumask and converting it to a string is rather expensive during
the trace as traces happen in hotpaths. It would be better to record
the raw event mask and be able to parse it at print time.
The following macros were added for use with the TRACE_EVENT() macro:
__bitmask()
__assign_bitmask()
__get_bitmask()
To test this, I added this to the sched_migrate_task event, which
looked like this:
TRACE_EVENT(sched_migrate_task,
TP_PROTO(struct task_struct *p, int dest_cpu, const struct cpumask *cpus),
TP_ARGS(p, dest_cpu, cpus),
TP_STRUCT__entry(
__array( char, comm, TASK_COMM_LEN )
__field( pid_t, pid )
__field( int, prio )
__field( int, orig_cpu )
__field( int, dest_cpu )
__bitmask( cpumask, num_possible_cpus() )
),
TP_fast_assign(
memcpy(__entry->comm, p->comm, TASK_COMM_LEN);
__entry->pid = p->pid;
__entry->prio = p->prio;
__entry->orig_cpu = task_cpu(p);
__entry->dest_cpu = dest_cpu;
__assign_bitmask(cpumask, cpumask_bits(cpus), num_possible_cpus());
),
TP_printk("comm=%s pid=%d prio=%d orig_cpu=%d dest_cpu=%d cpumask=%s",
__entry->comm, __entry->pid, __entry->prio,
__entry->orig_cpu, __entry->dest_cpu,
__get_bitmask(cpumask))
);
With the output of:
ksmtuned-3613 [003] d..2 485.220508: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=3 dest_cpu=2 cpumask=00000000,0000000f
migration/1-13 [001] d..5 485.221202: sched_migrate_task: comm=ksmtuned pid=3614 prio=120 orig_cpu=1 dest_cpu=0 cpumask=00000000,0000000f
awk-3615 [002] d.H5 485.221747: sched_migrate_task: comm=rcu_preempt pid=7 prio=120 orig_cpu=0 dest_cpu=1 cpumask=00000000,000000ff
migration/2-18 [002] d..5 485.222062: sched_migrate_task: comm=ksmtuned pid=3615 prio=120 orig_cpu=2 dest_cpu=3 cpumask=00000000,0000000f
Link: http://lkml.kernel.org/r/1399377998-14870-6-git-send-email-javi.merino@arm.com
Link: http://lkml.kernel.org/r/20140506132238.22e136d1@gandalf.local.home
Suggested-by: Javi Merino <javi.merino@arm.com>
Tested-by: Javi Merino <javi.merino@arm.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2014-05-06 17:10:24 +00:00
|
|
|
/*
|
|
|
|
* __bitmask_size_in_bytes_raw is the number of bytes needed to hold
|
|
|
|
* num_possible_cpus().
|
|
|
|
*/
|
|
|
|
#define __bitmask_size_in_bytes_raw(nr_bits) \
|
|
|
|
(((nr_bits) + 7) / 8)
|
|
|
|
|
|
|
|
#define __bitmask_size_in_longs(nr_bits) \
|
|
|
|
((__bitmask_size_in_bytes_raw(nr_bits) + \
|
|
|
|
((BITS_PER_LONG / 8) - 1)) / (BITS_PER_LONG / 8))
|
|
|
|
|
|
|
|
/*
|
|
|
|
* __bitmask_size_in_bytes is the number of bytes needed to hold
|
|
|
|
* num_possible_cpus() padded out to the nearest long. This is what
|
|
|
|
* is saved in the buffer, just to be consistent.
|
|
|
|
*/
|
|
|
|
#define __bitmask_size_in_bytes(nr_bits) \
|
|
|
|
(__bitmask_size_in_longs(nr_bits) * (BITS_PER_LONG / 8))
|
|
|
|
|
|
|
|
#undef __bitmask
|
|
|
|
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, \
|
|
|
|
__bitmask_size_in_longs(nr_bits))
|
|
|
|
|
2009-11-26 08:04:55 +00:00
|
|
|
#undef DECLARE_EVENT_CLASS
|
|
|
|
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
|
2015-05-13 19:40:23 +00:00
|
|
|
static inline notrace int trace_event_get_offsets_##call( \
|
2015-05-13 19:33:52 +00:00
|
|
|
struct trace_event_data_offsets_##call *__data_offsets, proto) \
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
{ \
|
|
|
|
int __data_size = 0; \
|
2014-03-01 05:32:17 +00:00
|
|
|
int __maybe_unused __item_length; \
|
2015-05-13 19:27:47 +00:00
|
|
|
struct trace_event_raw_##call __maybe_unused *entry; \
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
\
|
|
|
|
tstruct; \
|
|
|
|
\
|
|
|
|
return __data_size; \
|
|
|
|
}
|
|
|
|
|
tracing: Create new TRACE_EVENT_TEMPLATE
There are some places in the kernel that define several tracepoints and
they are all identical besides the name. The code to enable, disable and
record is created for every trace point even if most of the code is
identical.
This patch adds TRACE_EVENT_TEMPLATE that lets the developer create
a template TRACE_EVENT and create trace points with DEFINE_EVENT, which
is based off of a given template. Each trace point used by this
will share most of the code, and bring down the size of the kernel
when there are several duplicate events.
Usage is:
TRACE_EVENT_TEMPLATE(name, proto, args, tstruct, assign, print);
Which would be the same as defining a normal TRACE_EVENT.
To create the trace events that the trace points will use:
DEFINE_EVENT(template, name, proto, args) is done. The template
is the name of the TRACE_EVENT_TEMPLATE to use. The name is the
name of the trace point. The parameters proto and args must be the same
as the proto and args of the template. If they are not the same,
then a compile error will result. I tried hard removing this duplication
but the C preprocessor is not powerful enough (or my CPP magic
experience points is not at a high enough level) to not need them.
A lot of trace events are coming in with new XFS development. Most of
the trace points are identical except for the name. The following shows
the advantage of having TRACE_EVENT_TEMPLATE:
$ size fs/xfs/xfs.o.*
text data bss dec hex filename
452114 2788 3520 458422 6feb6 fs/xfs/xfs.o.old
638482 38116 3744 680342 a6196 fs/xfs/xfs.o.template
996954 38116 4480 1039550 fdcbe fs/xfs/xfs.o.trace
xfs.o.old is without any tracepoints.
xfs.o.template uses the new TRACE_EVENT_TEMPLATE.
xfs.o.trace uses the current TRACE_EVENT macros.
Requested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-11-19 01:27:27 +00:00
|
|
|
#undef DEFINE_EVENT
|
|
|
|
#define DEFINE_EVENT(template, name, proto, args)
|
|
|
|
|
2009-11-19 01:36:26 +00:00
|
|
|
#undef DEFINE_EVENT_PRINT
|
|
|
|
#define DEFINE_EVENT_PRINT(template, name, proto, args, print) \
|
|
|
|
DEFINE_EVENT(template, name, PARAMS(proto), PARAMS(args))
|
|
|
|
|
tracing/events: introduce __dynamic_array()
__string() is limited:
- it's a char array, but we may want to define array with other types
- a source string should be available, but we may just know the string size
We introduce __dynamic_array() to break those limitations, and __string()
becomes a wrapper of it. As a side effect, now __get_str() can be used
in TP_fast_assign but not only TP_print.
Take XFS for example, we have the string length in the dirent, but the
string itself is not NULL-terminated, so __dynamic_array() can be used:
TRACE_EVENT(xfs_dir2,
TP_PROTO(struct xfs_da_args *args),
TP_ARGS(args),
TP_STRUCT__entry(
__field(int, namelen)
__dynamic_array(char, name, args->namelen + 1)
...
),
TP_fast_assign(
char *name = __get_str(name);
if (args->namelen)
memcpy(name, args->name, args->namelen);
name[args->namelen] = '\0';
__entry->namelen = args->namelen;
),
TP_printk("name %.*s namelen %d",
__entry->namelen ? __get_str(name) : NULL
__entry->namelen)
);
[ Impact: allow defining dynamic size arrays ]
Signed-off-by: Li Zefan <lizf@cn.fujitsu.com>
LKML-Reference: <4A2384D2.3080403@cn.fujitsu.com>
Signed-off-by: Steven Rostedt <rostedt@goodmis.org>
2009-06-01 07:35:46 +00:00
|
|
|
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
|
|
|
|
|
2015-09-23 13:26:27 +00:00
|
|
|
/*
|
|
|
|
* Stage 4 of the trace events.
|
|
|
|
*
|
|
|
|
* Override the macros in <trace/trace_events.h> to include the following:
|
|
|
|
*
|
|
|
|
* For those macros defined with TRACE_EVENT:
|
|
|
|
*
|
|
|
|
* static struct trace_event_call event_<call>;
|
|
|
|
*
|
|
|
|
* static void trace_event_raw_event_<call>(void *__data, proto)
|
|
|
|
* {
|
|
|
|
* struct trace_event_file *trace_file = __data;
|
|
|
|
* struct trace_event_call *event_call = trace_file->event_call;
|
|
|
|
* struct trace_event_data_offsets_<call> __maybe_unused __data_offsets;
|
|
|
|
* unsigned long eflags = trace_file->flags;
|
|
|
|
* enum event_trigger_type __tt = ETT_NONE;
|
|
|
|
* struct ring_buffer_event *event;
|
|
|
|
* struct trace_event_raw_<call> *entry; <-- defined in stage 1
|
|
|
|
* struct ring_buffer *buffer;
|
|
|
|
* unsigned long irq_flags;
|
|
|
|
* int __data_size;
|
|
|
|
* int pc;
|
|
|
|
*
|
|
|
|
* if (!(eflags & EVENT_FILE_FL_TRIGGER_COND)) {
|
|
|
|
* if (eflags & EVENT_FILE_FL_TRIGGER_MODE)
|
|
|
|
* event_triggers_call(trace_file, NULL);
|
|
|
|
* if (eflags & EVENT_FILE_FL_SOFT_DISABLED)
|
|
|
|
* return;
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* local_save_flags(irq_flags);
|
|
|
|
* pc = preempt_count();
|
|
|
|
*
|
|
|
|
* __data_size = trace_event_get_offsets_<call>(&__data_offsets, args);
|
|
|
|
*
|
|
|
|
* event = trace_event_buffer_lock_reserve(&buffer, trace_file,
|
|
|
|
* event_<call>->event.type,
|
|
|
|
* sizeof(*entry) + __data_size,
|
|
|
|
* irq_flags, pc);
|
|
|
|
* if (!event)
|
|
|
|
* return;
|
|
|
|
* entry = ring_buffer_event_data(event);
|
|
|
|
*
|
|
|
|
* { <assign>; } <-- Here we assign the entries by the __field and
|
|
|
|
* __array macros.
|
|
|
|
*
|
|
|
|
* if (eflags & EVENT_FILE_FL_TRIGGER_COND)
|
|
|
|
* __tt = event_triggers_call(trace_file, entry);
|
|
|
|
*
|
|
|
|
* if (test_bit(EVENT_FILE_FL_SOFT_DISABLED_BIT,
|
|
|
|
* &trace_file->flags))
|
|
|
|
* ring_buffer_discard_commit(buffer, event);
|
|
|
|
* else if (!filter_check_discard(trace_file, entry, buffer, event))
|
|
|
|
* trace_buffer_unlock_commit(buffer, event, irq_flags, pc);
|
|
|
|
*
|
|
|
|
* if (__tt)
|
|
|
|
* event_triggers_post_call(trace_file, __tt);
|
|
|
|
* }
|
|
|
|
*
|
|
|
|
* static struct trace_event ftrace_event_type_<call> = {
|
|
|
|
* .trace = trace_raw_output_<call>, <-- stage 2
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* static char print_fmt_<call>[] = <TP_printk>;
|
|
|
|
*
|
|
|
|
* static struct trace_event_class __used event_class_<template> = {
|
|
|
|
* .system = "<system>",
|
|
|
|
* .define_fields = trace_event_define_fields_<call>,
|
|
|
|
* .fields = LIST_HEAD_INIT(event_class_##call.fields),
|
|
|
|
* .raw_init = trace_event_raw_init,
|
|
|
|
* .probe = trace_event_raw_event_##call,
|
|
|
|
* .reg = trace_event_reg,
|
|
|
|
* };
|
|
|
|
*
|
|
|
|
* static struct trace_event_call event_<call> = {
|
|
|
|
* .class = event_class_<template>,
|
|
|
|
* {
|
|
|
|
* .tp = &__tracepoint_<call>,
|
|
|
|
* },
|
|
|
|
* .event = &ftrace_event_type_<call>,
|
|
|
|
* .print_fmt = print_fmt_<call>,
|
|
|
|
* .flags = TRACE_EVENT_FL_TRACEPOINT,
|
|
|
|
* };
|
|
|
|
* // its only safe to use pointers when doing linker tricks to
|
|
|
|
* // create an array.
|
|
|
|
* static struct trace_event_call __used
|
|
|
|
* __attribute__((section("_ftrace_events"))) *__event_<call> = &event_<call>;
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef CONFIG_PERF_EVENTS
|
|
|
|
|
|
|
|
#define _TRACE_PERF_PROTO(call, proto) \
|
|
|
|
static notrace void \
|
|
|
|
perf_trace_##call(void *__data, proto);
|
|
|
|
|
|
|
|
#define _TRACE_PERF_INIT(call) \
|
|
|
|
.perf_probe = perf_trace_##call,
|
|
|
|
|
|
|
|
#else
|
|
|
|
#define _TRACE_PERF_PROTO(call, proto)
|
|
|
|
#define _TRACE_PERF_INIT(call)
|
|
|
|
#endif /* CONFIG_PERF_EVENTS */
|
|
|
|
|
|
|
|
#undef __entry
|
|
|
|
#define __entry entry
|
|
|
|
|
|
|
|
#undef __field
|
|
|
|
#define __field(type, item)
|
|
|
|
|
|
|
|
#undef __field_struct
|
|
|
|
#define __field_struct(type, item)
|
|
|
|
|
|
|
|
#undef __array
|
|
|
|
#define __array(type, item, len)
|
|
|
|
|
|
|
|
#undef __dynamic_array
|
|
|
|
#define __dynamic_array(type, item, len) \
|
|
|
|
__entry->__data_loc_##item = __data_offsets.item;
|
|
|
|
|
|
|
|
#undef __string
|
|
|
|
#define __string(item, src) __dynamic_array(char, item, -1)
|
|
|
|
|
|
|
|
#undef __assign_str
|
|
|
|
#define __assign_str(dst, src) \
|
|
|
|
strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
|
|
|
|
|
|
|
|
#undef __bitmask
|
|
|
|
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
|
|
|
|
|
|
|
|
#undef __get_bitmask
|
|
|
|
#define __get_bitmask(field) (char *)__get_dynamic_array(field)
|
|
|
|
|
|
|
|
#undef __assign_bitmask
|
|
|
|
#define __assign_bitmask(dst, src, nr_bits) \
|
|
|
|
memcpy(__get_bitmask(dst), (src), __bitmask_size_in_bytes(nr_bits))
|
|
|
|
|
|
|
|
#undef TP_fast_assign
|
|
|
|
#define TP_fast_assign(args...) args
|
|
|
|
|
|
|
|
#undef __perf_count
|
|
|
|
#define __perf_count(c) (c)
|
|
|
|
|
|
|
|
#undef __perf_task
|
|
|
|
#define __perf_task(t) (t)
|
|
|
|
|
|
|
|
#undef DECLARE_EVENT_CLASS
|
|
|
|
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
|
|
|
|
\
|
|
|
|
static notrace void \
|
|
|
|
trace_event_raw_event_##call(void *__data, proto) \
|
|
|
|
{ \
|
|
|
|
struct trace_event_file *trace_file = __data; \
|
|
|
|
struct trace_event_data_offsets_##call __maybe_unused __data_offsets;\
|
|
|
|
struct trace_event_buffer fbuffer; \
|
|
|
|
struct trace_event_raw_##call *entry; \
|
|
|
|
int __data_size; \
|
|
|
|
\
|
|
|
|
if (trace_trigger_soft_disabled(trace_file)) \
|
|
|
|
return; \
|
|
|
|
\
|
|
|
|
__data_size = trace_event_get_offsets_##call(&__data_offsets, args); \
|
|
|
|
\
|
|
|
|
entry = trace_event_buffer_reserve(&fbuffer, trace_file, \
|
|
|
|
sizeof(*entry) + __data_size); \
|
|
|
|
\
|
|
|
|
if (!entry) \
|
|
|
|
return; \
|
|
|
|
\
|
|
|
|
tstruct \
|
|
|
|
\
|
|
|
|
{ assign; } \
|
|
|
|
\
|
|
|
|
trace_event_buffer_commit(&fbuffer); \
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* The ftrace_test_probe is compiled out, it is only here as a build time check
|
|
|
|
* to make sure that if the tracepoint handling changes, the ftrace probe will
|
|
|
|
* fail to compile unless it too is updated.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#undef DEFINE_EVENT
|
|
|
|
#define DEFINE_EVENT(template, call, proto, args) \
|
|
|
|
static inline void ftrace_test_probe_##call(void) \
|
|
|
|
{ \
|
|
|
|
check_trace_callback_type_##call(trace_event_raw_event_##template); \
|
|
|
|
}
|
|
|
|
|
|
|
|
#undef DEFINE_EVENT_PRINT
|
|
|
|
#define DEFINE_EVENT_PRINT(template, name, proto, args, print)
|
|
|
|
|
|
|
|
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
|
|
|
|
|
|
|
|
#undef __entry
|
|
|
|
#define __entry REC
|
|
|
|
|
|
|
|
#undef __print_flags
|
|
|
|
#undef __print_symbolic
|
|
|
|
#undef __print_hex
|
2017-01-25 01:28:16 +00:00
|
|
|
#undef __print_hex_str
|
2015-09-23 13:26:27 +00:00
|
|
|
#undef __get_dynamic_array
|
|
|
|
#undef __get_dynamic_array_len
|
|
|
|
#undef __get_str
|
|
|
|
#undef __get_bitmask
|
|
|
|
#undef __print_array
|
|
|
|
|
|
|
|
#undef TP_printk
|
|
|
|
#define TP_printk(fmt, args...) "\"" fmt "\", " __stringify(args)
|
|
|
|
|
|
|
|
#undef DECLARE_EVENT_CLASS
|
|
|
|
#define DECLARE_EVENT_CLASS(call, proto, args, tstruct, assign, print) \
|
|
|
|
_TRACE_PERF_PROTO(call, PARAMS(proto)); \
|
|
|
|
static char print_fmt_##call[] = print; \
|
|
|
|
static struct trace_event_class __used __refdata event_class_##call = { \
|
|
|
|
.system = TRACE_SYSTEM_STRING, \
|
|
|
|
.define_fields = trace_event_define_fields_##call, \
|
|
|
|
.fields = LIST_HEAD_INIT(event_class_##call.fields),\
|
|
|
|
.raw_init = trace_event_raw_init, \
|
|
|
|
.probe = trace_event_raw_event_##call, \
|
|
|
|
.reg = trace_event_reg, \
|
|
|
|
_TRACE_PERF_INIT(call) \
|
|
|
|
};
|
|
|
|
|
|
|
|
#undef DEFINE_EVENT
|
|
|
|
#define DEFINE_EVENT(template, call, proto, args) \
|
|
|
|
\
|
|
|
|
static struct trace_event_call __used event_##call = { \
|
|
|
|
.class = &event_class_##template, \
|
|
|
|
{ \
|
|
|
|
.tp = &__tracepoint_##call, \
|
|
|
|
}, \
|
|
|
|
.event.funcs = &trace_event_type_funcs_##template, \
|
|
|
|
.print_fmt = print_fmt_##template, \
|
|
|
|
.flags = TRACE_EVENT_FL_TRACEPOINT, \
|
|
|
|
}; \
|
|
|
|
static struct trace_event_call __used \
|
|
|
|
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
|
|
|
|
|
|
|
|
#undef DEFINE_EVENT_PRINT
|
|
|
|
#define DEFINE_EVENT_PRINT(template, call, proto, args, print) \
|
|
|
|
\
|
|
|
|
static char print_fmt_##call[] = print; \
|
|
|
|
\
|
|
|
|
static struct trace_event_call __used event_##call = { \
|
|
|
|
.class = &event_class_##template, \
|
|
|
|
{ \
|
|
|
|
.tp = &__tracepoint_##call, \
|
|
|
|
}, \
|
|
|
|
.event.funcs = &trace_event_type_funcs_##call, \
|
|
|
|
.print_fmt = print_fmt_##call, \
|
|
|
|
.flags = TRACE_EVENT_FL_TRACEPOINT, \
|
|
|
|
}; \
|
|
|
|
static struct trace_event_call __used \
|
|
|
|
__attribute__((section("_ftrace_events"))) *__event_##call = &event_##call
|
|
|
|
|
|
|
|
#include TRACE_INCLUDE(TRACE_INCLUDE_FILE)
|