mirror of
https://github.com/torvalds/linux.git
synced 2026-10-07 05:31:08 -04:00
tracing/events: Add __vstring() and __assign_vstr() helper macros
There's several places that open code the following logic:
TP_STRUCT__entry(__dynamic_array(char, msg, MSG_MAX)),
TP_fast_assign(vsnprintf(__get_str(msg), MSG_MAX, vaf->fmt, *vaf->va);)
To load a string created by variable array va_list.
The main issue with this approach is that "MSG_MAX" usage in the
__dynamic_array() portion. That actually just reserves the MSG_MAX in the
event, and even wastes space because there's dynamic meta data also saved
in the event to denote the offset and size of the dynamic array. It would
have been better to just use a static __array() field.
Instead, create __vstring() and __assign_vstr() that work like __string
and __assign_str() but instead of taking a destination string to copy,
take a format string and a va_list pointer and fill in the values.
It uses the helper:
#define __trace_event_vstr_len(fmt, va) \
({ \
va_list __ap; \
int __ret; \
\
va_copy(__ap, *(va)); \
__ret = vsnprintf(NULL, 0, fmt, __ap) + 1; \
va_end(__ap); \
\
min(__ret, TRACE_EVENT_STR_MAX); \
})
To figure out the length to store the string. It may be slightly slower as
it needs to run the vsnprintf() twice, but it now saves space on the ring
buffer.
Link: https://lkml.kernel.org/r/[email protected]
Cc: Dennis Dalessandro <[email protected]>
Cc: Ingo Molnar <[email protected]>
Cc: Andrew Morton <[email protected]>
Cc: Jason Gunthorpe <[email protected]>
Cc: Leon Romanovsky <[email protected]>
Cc: Kalle Valo <[email protected]>
Cc: "David S. Miller" <[email protected]>
Cc: Eric Dumazet <[email protected]>
Cc: Jakub Kicinski <[email protected]>
Cc: Paolo Abeni <[email protected]>
Cc: Arend van Spriel <[email protected]>
Cc: Franky Lin <[email protected]>
Cc: Hante Meuleman <[email protected]>
Cc: Gregory Greenman <[email protected]>
Cc: Peter Chen <[email protected]>
Cc: Greg Kroah-Hartman <[email protected]>
Cc: Mathias Nyman <[email protected]>
Cc: Chunfeng Yun <[email protected]>
Cc: Bin Liu <[email protected]>
Cc: Marek Lindner <[email protected]>
Cc: Simon Wunderlich <[email protected]>
Cc: Antonio Quartulli <[email protected]>
Cc: Sven Eckelmann <[email protected]>
Cc: Johannes Berg <[email protected]>
Cc: Jim Cromie <[email protected]>
Signed-off-by: Steven Rostedt (Google) <[email protected]>
This commit is contained in:
1 parent
43b2aef373
commit
0563231f93
6 files changed
+38
No files matched your search
@@ -916,6 +916,24 @@ perf_trace_buf_submit(void *raw_data, int size, int rctx, u16 type,
|
||||
|
||||
#endif
|
||||
|
||||
#define TRACE_EVENT_STR_MAX 512
|
||||
|
||||
/*
|
||||
* gcc warns that you can not use a va_list in an inlined
|
||||
* function. But lets me make it into a macro :-/
|
||||
*/
|
||||
#define __trace_event_vstr_len(fmt, va) \
|
||||
({ \
|
||||
va_list __ap; \
|
||||
int __ret; \
|
||||
\
|
||||
va_copy(__ap, *(va)); \
|
||||
__ret = vsnprintf(NULL, 0, fmt, __ap) + 1; \
|
||||
va_end(__ap); \
|
||||
\
|
||||
min(__ret, TRACE_EVENT_STR_MAX); \
|
||||
})
|
||||
|
||||
#endif /* _LINUX_TRACE_EVENT_H */
|
||||
|
||||
/*
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
#undef __string_len
|
||||
#define __string_len(item, src, len) __dynamic_array(char, item, -1)
|
||||
|
||||
#undef __vstring
|
||||
#define __vstring(item, fmt, ap) __dynamic_array(char, item, -1)
|
||||
|
||||
#undef __bitmask
|
||||
#define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
|
||||
|
||||
|
||||
@@ -32,6 +32,9 @@
|
||||
#undef __string_len
|
||||
#define __string_len(item, src, len) __dynamic_array(char, item, -1)
|
||||
|
||||
#undef __vstring
|
||||
#define __vstring(item, fmt, ap) __dynamic_array(char, item, -1)
|
||||
|
||||
#undef __bitmask
|
||||
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
|
||||
|
||||
|
||||
@@ -38,6 +38,9 @@
|
||||
#undef __string_len
|
||||
#define __string_len(item, src, len) __dynamic_array(char, item, -1)
|
||||
|
||||
#undef __vstring
|
||||
#define __vstring(item, fmt, ap) __dynamic_array(char, item, -1)
|
||||
|
||||
#undef __bitmask
|
||||
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
|
||||
|
||||
|
||||
@@ -39,6 +39,10 @@
|
||||
#undef __string_len
|
||||
#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
|
||||
|
||||
#undef __vstring
|
||||
#define __vstring(item, fmt, ap) __dynamic_array(char, item, \
|
||||
__trace_event_vstr_len(fmt, ap))
|
||||
|
||||
#undef __rel_dynamic_array
|
||||
#define __rel_dynamic_array(type, item, len) \
|
||||
__item_length = (len) * sizeof(type); \
|
||||
|
||||
@@ -24,6 +24,9 @@
|
||||
#undef __string_len
|
||||
#define __string_len(item, src, len) __dynamic_array(char, item, -1)
|
||||
|
||||
#undef __vstring
|
||||
#define __vstring(item, fmt, ap) __dynamic_array(char, item, -1)
|
||||
|
||||
#undef __assign_str
|
||||
#define __assign_str(dst, src) \
|
||||
strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
|
||||
@@ -35,6 +38,10 @@
|
||||
__get_str(dst)[len] = '\0'; \
|
||||
} while(0)
|
||||
|
||||
#undef __assign_vstr
|
||||
#define __assign_vstr(dst, fmt, va) \
|
||||
vsnprintf(__get_str(dst), TRACE_EVENT_STR_MAX, fmt, *(va))
|
||||
|
||||
#undef __bitmask
|
||||
#define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
|
||||
|
||||
|
||||
Reference in new issue
Block a user