* [PATCH] trace/ftrace: move snprintf+write from tracepoints to ftrace.c
@ 2025-08-08 9:11 Paolo Bonzini
2025-08-19 12:16 ` Daniel P. Berrangé
0 siblings, 1 reply; 2+ messages in thread
From: Paolo Bonzini @ 2025-08-08 9:11 UTC (permalink / raw)
To: qemu-devel
This simplifies the Python code and reduces the size of the tracepoints.
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
tests/tracetool/ftrace.h | 26 ++++----------------------
trace/ftrace.h | 1 +
trace/ftrace.c | 13 +++++++++++++
scripts/tracetool/backend/ftrace.py | 13 ++-----------
4 files changed, 20 insertions(+), 33 deletions(-)
diff --git a/tests/tracetool/ftrace.h b/tests/tracetool/ftrace.h
index aa8d720a922..83e4adeed4d 100644
--- a/tests/tracetool/ftrace.h
+++ b/tests/tracetool/ftrace.h
@@ -21,18 +21,9 @@ extern uint16_t _TRACE_TEST_WIBBLE_DSTATE;
static inline void trace_test_blah(void *context, const char *filename)
{
- {
- char ftrace_buf[MAX_TRACE_STRLEN];
- int unused __attribute__ ((unused));
- int trlen;
- if (trace_event_get_state(TRACE_TEST_BLAH)) {
+ if (trace_event_get_state(TRACE_TEST_BLAH)) {
#line 4 "trace-events"
- trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,
- "test_blah " "Blah context=%p filename=%s" "\n" , context, filename);
-#line 33 "[stdout]"
- trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);
- unused = write(trace_marker_fd, ftrace_buf, trlen);
- }
+ ftrace_write("test_blah " "Blah context=%p filename=%s" "\n" , context, filename);
}
}
@@ -42,18 +33,9 @@ static inline void trace_test_blah(void *context, const char *filename)
static inline void trace_test_wibble(void *context, int value)
{
- {
- char ftrace_buf[MAX_TRACE_STRLEN];
- int unused __attribute__ ((unused));
- int trlen;
- if (trace_event_get_state(TRACE_TEST_WIBBLE)) {
+ if (trace_event_get_state(TRACE_TEST_WIBBLE)) {
#line 5 "trace-events"
- trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,
- "test_wibble " "Wibble context=%p value=%d" "\n" , context, value);
-#line 54 "[stdout]"
- trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);
- unused = write(trace_marker_fd, ftrace_buf, trlen);
- }
+ ftrace_write("test_wibble " "Wibble context=%p value=%d" "\n" , context, value);
}
}
#endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */
diff --git a/trace/ftrace.h b/trace/ftrace.h
index cb5e35d2171..16c122816d1 100644
--- a/trace/ftrace.h
+++ b/trace/ftrace.h
@@ -8,5 +8,6 @@
extern int trace_marker_fd;
bool ftrace_init(void);
+G_GNUC_PRINTF(1, 2) void ftrace_write(const char *fmt, ...);
#endif /* TRACE_FTRACE_H */
diff --git a/trace/ftrace.c b/trace/ftrace.c
index 9749543d9b2..1d7e1ee6f6d 100644
--- a/trace/ftrace.c
+++ b/trace/ftrace.c
@@ -38,6 +38,19 @@ static int find_mount(char *mount_point, const char *fstype)
return ret;
}
+void ftrace_write(const char *fmt, ...)
+{
+ char ftrace_buf[MAX_TRACE_STRLEN];
+ int unused __attribute__ ((unused));
+ int trlen;
+ va_list ap;
+
+ va_start(ap, fmt);
+ trlen = vsnprintf(ftrace_buf, MAX_TRACE_STRLEN, fmt, ap);
+ trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);
+ unused = write(trace_marker_fd, ftrace_buf, trlen);
+}
+
bool ftrace_init(void)
{
char mount_point[PATH_MAX];
diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backend/ftrace.py
index 5fa30ccc08e..1a96231dbab 100644
--- a/scripts/tracetool/backend/ftrace.py
+++ b/scripts/tracetool/backend/ftrace.py
@@ -28,18 +28,9 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- out(' {',
- ' char ftrace_buf[MAX_TRACE_STRLEN];',
- ' int unused __attribute__ ((unused));',
- ' int trlen;',
- ' if (trace_event_get_state(%(event_id)s)) {',
+ out(' if (trace_event_get_state(%(event_id)s)) {',
'#line %(event_lineno)d "%(event_filename)s"',
- ' trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
- ' "%(name)s " %(fmt)s "\\n" %(argnames)s);',
- '#line %(out_next_lineno)d "%(out_filename)s"',
- ' trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);',
- ' unused = write(trace_marker_fd, ftrace_buf, trlen);',
- ' }',
+ ' ftrace_write("%(name)s " %(fmt)s "\\n" %(argnames)s);',
' }',
name=event.name,
args=event.args,
--
2.50.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] trace/ftrace: move snprintf+write from tracepoints to ftrace.c
2025-08-08 9:11 [PATCH] trace/ftrace: move snprintf+write from tracepoints to ftrace.c Paolo Bonzini
@ 2025-08-19 12:16 ` Daniel P. Berrangé
0 siblings, 0 replies; 2+ messages in thread
From: Daniel P. Berrangé @ 2025-08-19 12:16 UTC (permalink / raw)
To: Paolo Bonzini; +Cc: qemu-devel
On Fri, Aug 08, 2025 at 11:11:10AM +0200, Paolo Bonzini wrote:
> This simplifies the Python code and reduces the size of the tracepoints.
>
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
> ---
> tests/tracetool/ftrace.h | 26 ++++----------------------
> trace/ftrace.h | 1 +
> trace/ftrace.c | 13 +++++++++++++
> scripts/tracetool/backend/ftrace.py | 13 ++-----------
> 4 files changed, 20 insertions(+), 33 deletions(-)
> diff --git a/trace/ftrace.c b/trace/ftrace.c
> index 9749543d9b2..1d7e1ee6f6d 100644
> --- a/trace/ftrace.c
> +++ b/trace/ftrace.c
> @@ -38,6 +38,19 @@ static int find_mount(char *mount_point, const char *fstype)
> return ret;
> }
>
> +void ftrace_write(const char *fmt, ...)
> +{
> + char ftrace_buf[MAX_TRACE_STRLEN];
> + int unused __attribute__ ((unused));
> + int trlen;
> + va_list ap;
> +
> + va_start(ap, fmt);
> + trlen = vsnprintf(ftrace_buf, MAX_TRACE_STRLEN, fmt, ap);
va_end(ap);
> + trlen = MIN(trlen, MAX_TRACE_STRLEN - 1);
> + unused = write(trace_marker_fd, ftrace_buf, trlen);
> +}
> +
> bool ftrace_init(void)
> {
> char mount_point[PATH_MAX];
With regards,
Daniel
--
|: https://berrange.com -o- https://www.flickr.com/photos/dberrange :|
|: https://libvirt.org -o- https://fstop138.berrange.com :|
|: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2025-08-19 12:17 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-08-08 9:11 [PATCH] trace/ftrace: move snprintf+write from tracepoints to ftrace.c Paolo Bonzini
2025-08-19 12:16 ` Daniel P. Berrangé
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).