linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [for-linus][PATCH] tracing: Add trace_event helper macros __string_len() and __assign_str_len()
@ 2021-07-13 14:24 Steven Rostedt
  0 siblings, 0 replies; only message in thread
From: Steven Rostedt @ 2021-07-13 14:24 UTC (permalink / raw)
  To: LKML; +Cc: Ingo Molnar, Andrew Morton, Chuck Lever


Hoping to be able to squeeze this into an rc release.

  git://git.kernel.org/pub/scm/linux/kernel/git/rostedt/linux-trace.git
for-next

Head SHA1: ac58f4f28369ce3287982da131ad3c6fb283d4e6


Steven Rostedt (VMware) (1):
      tracing: Add trace_event helper macros __string_len() and __assign_str_len()

----
 include/trace/trace_events.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
---------------------------
commit ac58f4f28369ce3287982da131ad3c6fb283d4e6
Author: Steven Rostedt (VMware) <rostedt@goodmis.org>
Date:   Thu May 13 10:50:18 2021 -0400

    tracing: Add trace_event helper macros __string_len() and __assign_str_len()
    
    There's a few cases that a string that is to be recorded in a trace event,
    does not have a terminating 'nul' character, and instead, the tracepoint
    passes in the length of the string to record.
    
    Add two helper macros to the trace event code that lets this work easier,
    than tricks with "%.*s" logic.
    
      __string_len() which is similar to __string() for declaration, but takes a
                     length argument.
    
      __assign_str_len() which is similar to __assign_str() for assiging the
                     string, but it too takes a length argument.
    
    This string can still use __get_str() just like strings created with
    __string() can use to retrieve the string.
    
    Link: https://lore.kernel.org/linux-nfs/20210513105018.7539996a@gandalf.local.home/
    
    Tested-by: Chuck Lever <chuck.lever@oracle.com>
    Signed-off-by: Steven Rostedt (VMware) <rostedt@goodmis.org>

diff --git a/include/trace/trace_events.h b/include/trace/trace_events.h
index acc17194c160..a0fa8a3a691c 100644
--- a/include/trace/trace_events.h
+++ b/include/trace/trace_events.h
@@ -102,6 +102,9 @@ TRACE_MAKE_SYSTEM_STR();
 #undef __string
 #define __string(item, src) __dynamic_array(char, item, -1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
 #undef __bitmask
 #define __bitmask(item, nr_bits) __dynamic_array(char, item, -1)
 
@@ -197,6 +200,9 @@ TRACE_MAKE_SYSTEM_STR();
 #undef __string
 #define __string(item, src) __dynamic_array(char, item, -1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
 #undef __bitmask
 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
 
@@ -459,6 +465,9 @@ static struct trace_event_functions trace_event_type_funcs_##call = {	\
 #undef __string
 #define __string(item, src) __dynamic_array(char, item, -1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
 #undef __bitmask
 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
 
@@ -507,6 +516,9 @@ static struct trace_event_fields trace_event_fields_##call[] = {	\
 #define __string(item, src) __dynamic_array(char, item,			\
 		    strlen((src) ? (const char *)(src) : "(null)") + 1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, (len) + 1)
+
 /*
  * __bitmask_size_in_bytes_raw is the number of bytes needed to hold
  * num_possible_cpus().
@@ -670,10 +682,18 @@ static inline notrace int trace_event_get_offsets_##call(		\
 #undef __string
 #define __string(item, src) __dynamic_array(char, item, -1)
 
+#undef __string_len
+#define __string_len(item, src, len) __dynamic_array(char, item, -1)
+
 #undef __assign_str
 #define __assign_str(dst, src)						\
 	strcpy(__get_str(dst), (src) ? (const char *)(src) : "(null)");
 
+#undef __assign_str_len
+#define __assign_str_len(dst, src, len)						\
+	strncpy(__get_str(dst), (src) ? (const char *)(src) : "(null)", len);	\
+	__get_str(dst)[len] = '\0';
+
 #undef __bitmask
 #define __bitmask(item, nr_bits) __dynamic_array(unsigned long, item, -1)
 

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2021-07-13 14:24 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-13 14:24 [for-linus][PATCH] tracing: Add trace_event helper macros __string_len() and __assign_str_len() Steven Rostedt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).