Skip to content

Commit 0429578

Browse files
Steven Rostedtrostedt
authored andcommitted
tracing/events: Show real number in array fields
Currently we have in something like the sched_switch event: field:char prev_comm[TASK_COMM_LEN]; offset:12; size:16; signed:1; When a userspace tool such as perf tries to parse this, the TASK_COMM_LEN is meaningless. This is done because the TRACE_EVENT() macro simply uses a #len to show the string of the length. When the length is an enum, we get a string that means nothing for tools. By adding a static buffer and a mutex to protect it, we can store the string into that buffer with snprintf and show the actual number. Now we get: field:char prev_comm[16]; offset:12; size:16; signed:1; Something much more useful. Signed-off-by: Steven Rostedt <[email protected]>
1 parent 4567745 commit 0429578

File tree

4 files changed

+30
-8
lines changed

4 files changed

+30
-8
lines changed

include/linux/ftrace_event.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,10 @@ enum {
225225
FILTER_PTR_STRING,
226226
};
227227

228+
#define EVENT_STORAGE_SIZE 128
229+
extern struct mutex event_storage_mutex;
230+
extern char event_storage[EVENT_STORAGE_SIZE];
231+
228232
extern int trace_event_raw_init(struct ftrace_event_call *call);
229233
extern int trace_define_field(struct ftrace_event_call *call, const char *type,
230234
const char *name, int offset, int size,

include/trace/ftrace.h

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,13 +296,19 @@ static struct trace_event_functions ftrace_event_type_funcs_##call = { \
296296

297297
#undef __array
298298
#define __array(type, item, len) \
299-
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
300-
ret = trace_define_field(event_call, #type "[" #len "]", #item, \
299+
do { \
300+
mutex_lock(&event_storage_mutex); \
301+
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
302+
snprintf(event_storage, sizeof(event_storage), \
303+
"%s[%d]", #type, len); \
304+
ret = trace_define_field(event_call, event_storage, #item, \
301305
offsetof(typeof(field), item), \
302306
sizeof(field.item), \
303307
is_signed_type(type), FILTER_OTHER); \
304-
if (ret) \
305-
return ret;
308+
mutex_unlock(&event_storage_mutex); \
309+
if (ret) \
310+
return ret; \
311+
} while (0);
306312

307313
#undef __dynamic_array
308314
#define __dynamic_array(type, item, len) \

kernel/trace/trace_events.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,12 @@
2727

2828
DEFINE_MUTEX(event_mutex);
2929

30+
DEFINE_MUTEX(event_storage_mutex);
31+
EXPORT_SYMBOL_GPL(event_storage_mutex);
32+
33+
char event_storage[EVENT_STORAGE_SIZE];
34+
EXPORT_SYMBOL_GPL(event_storage);
35+
3036
LIST_HEAD(ftrace_events);
3137
LIST_HEAD(ftrace_common_fields);
3238

kernel/trace/trace_export.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,19 @@ static void __always_unused ____ftrace_check_##name(void) \
8383

8484
#undef __array
8585
#define __array(type, item, len) \
86-
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
87-
ret = trace_define_field(event_call, #type "[" #len "]", #item, \
86+
do { \
87+
BUILD_BUG_ON(len > MAX_FILTER_STR_VAL); \
88+
mutex_lock(&event_storage_mutex); \
89+
snprintf(event_storage, sizeof(event_storage), \
90+
"%s[%d]", #type, len); \
91+
ret = trace_define_field(event_call, event_storage, #item, \
8892
offsetof(typeof(field), item), \
8993
sizeof(field.item), \
9094
is_signed_type(type), FILTER_OTHER); \
91-
if (ret) \
92-
return ret;
95+
mutex_unlock(&event_storage_mutex); \
96+
if (ret) \
97+
return ret; \
98+
} while (0);
9399

94100
#undef __array_desc
95101
#define __array_desc(type, container, item, len) \

0 commit comments

Comments
 (0)