From: Steven Rostedt <rostedt@goodmis.org>
To: linux-kernel@vger.kernel.org, linux-trace-kernel@vger.kernel.org
Cc: "Masami Hiramatsu" <mhiramat@kernel.org>,
"Mark Rutland" <mark.rutland@arm.com>,
"Mathieu Desnoyers" <mathieu.desnoyers@efficios.com>,
"Andrew Morton" <akpm@linux-foundation.org>,
"Ville Syrjälä" <ville.syrjala@linux.intel.com>,
"Rodrigo Vivi" <rodrigo.vivi@intel.com>,
"Chuck Lever" <chuck.lever@oracle.com>
Subject: [PATCH v2 2/4] tracing: Do not calculate strlen() twice for __string() fields
Date: Thu, 22 Feb 2024 16:14:17 -0500 [thread overview]
Message-ID: <20240222211442.793074999@goodmis.org> (raw)
In-Reply-To: 20240222211415.255659509@goodmis.org
From: "Steven Rostedt (Google)" <rostedt@goodmis.org>
The TRACE_EVENT() macro handles dynamic strings by having:
TP_PROTO(struct some_struct *s),
TP_ARGS(s),
TP_STRUCT__entry(
__string(my_string, s->string)
),
TP_fast_assign(
__assign_str(my_string, s->string);
)
TP_printk("%s", __get_str(my_string))
There's even some code that may call a function helper to find the
s->string value. The problem with the above is that the work to get the
s->string is done twice. Once at the __string() and again in the
__assign_str().
The length of the string is calculated via a strlen(), not once, but
twice. Once during the __string() macro and again in __assign_str(). But
the length is actually already recorded in the data location and here's no
reason to call strlen() again.
Just use the saved length that was saved in the __string() code for the
__assign_str() code.
Signed-off-by: Steven Rostedt (Google) <rostedt@goodmis.org>
---
include/trace/stages/stage6_event_callback.h | 10 ++++++----
1 file changed, 6 insertions(+), 4 deletions(-)
diff --git a/include/trace/stages/stage6_event_callback.h b/include/trace/stages/stage6_event_callback.h
index b3e2f321e787..c0e5d097324e 100644
--- a/include/trace/stages/stage6_event_callback.h
+++ b/include/trace/stages/stage6_event_callback.h
@@ -32,8 +32,9 @@
#undef __assign_str
#define __assign_str(dst, src) \
- strcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \
- __data_offsets.dst##_ptr_ : "(null)")
+ memcpy(__get_str(dst), __data_offsets.dst##_ptr_ ? \
+ __data_offsets.dst##_ptr_ : "(null)", \
+ __get_dynamic_array_len(dst))
#undef __assign_str_len
#define __assign_str_len(dst, src, len) \
@@ -94,8 +95,9 @@
#undef __assign_rel_str
#define __assign_rel_str(dst, src) \
- strcpy(__get_rel_str(dst), __data_offsets.dst##_ptr_ ? \
- __data_offsets.dst##_ptr_ : "(null)")
+ memcpy(__get_rel_str(dst), __data_offsets.dst##_ptr_ ? \
+ __data_offsets.dst##_ptr_ : "(null)", \
+ __get_rel_dynamic_array_len(dst))
#undef __assign_rel_str_len
#define __assign_rel_str_len(dst, src, len) \
--
2.43.0
next prev parent reply other threads:[~2024-02-22 21:12 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-02-22 21:14 [PATCH v2 0/4] tracing: Optimize __string()/__assign_str() processing Steven Rostedt
2024-02-22 21:14 ` [PATCH v2 1/4] tracing: Rework __assign_str() and __string() to not duplicate getting the string Steven Rostedt
2024-02-22 21:14 ` Steven Rostedt [this message]
2024-02-22 21:14 ` [PATCH v2 3/4] tracing: Use ? : shortcut in trace macros Steven Rostedt
2024-02-22 21:14 ` [PATCH v2 4/4] tracing: Use EVENT_NULL_STR macro instead of open coding "(null)" Steven Rostedt
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240222211442.793074999@goodmis.org \
--to=rostedt@goodmis.org \
--cc=akpm@linux-foundation.org \
--cc=chuck.lever@oracle.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=mark.rutland@arm.com \
--cc=mathieu.desnoyers@efficios.com \
--cc=mhiramat@kernel.org \
--cc=rodrigo.vivi@intel.com \
--cc=ville.syrjala@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).