From: Tanish Desai <tanishdesai37@gmail.com>
To: qemu-devel@nongnu.org
Cc: "Lluís Vilanova" <vilanova@ac.upc.edu>,
"Paolo Bonzini" <pbonzini@redhat.com>,
"Mads Ynddal" <mads@ynddal.dk>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Tanish Desai" <tanishdesai37@gmail.com>
Subject: [PATCH 3/3] tracetool: remove redundant event_get_state checks
Date: Mon, 16 Jun 2025 20:12:22 +0000 [thread overview]
Message-ID: <20250616201222.6416-4-tanishdesai37@gmail.com> (raw)
In-Reply-To: <20250616201222.6416-1-tanishdesai37@gmail.com>
Moved trace_event_get_state check from _no_check_trace_foo to trace_foo, and removed
if (true) checks. The _no_check_trace_foo now only emits backend-specific core
logic, avoiding trace event conditionals entirely.
This brings conditional logic in format/h.py, reducing duplication across
backends and simplifying their code generation. It also removes one conditional
branch instruction from the fast path (trace_foo), improving runtime performance slightly(for some old compiler).
---
scripts/tracetool/backend/ftrace.py | 3 ---
scripts/tracetool/backend/log.py | 5 +----
scripts/tracetool/backend/simple.py | 7 +------
scripts/tracetool/backend/syslog.py | 7 +------
scripts/tracetool/format/h.py | 3 ++-
5 files changed, 5 insertions(+), 20 deletions(-)
diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backend/ftrace.py
index baed2ae61c..2d6d608add 100644
--- a/scripts/tracetool/backend/ftrace.py
+++ b/scripts/tracetool/backend/ftrace.py
@@ -34,18 +34,15 @@ def generate_h(event, group):
' char ftrace_buf[MAX_TRACE_STRLEN];',
' int unused __attribute__ ((unused));',
' int trlen;',
- ' 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);',
- ' }',
' }',
name=event.name,
args=event.args,
- event_id="TRACE_" + event.name.upper(),
event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename),
fmt=event.fmt.rstrip("\n"),
diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py
index f24acad74c..35a3aeee55 100644
--- a/scripts/tracetool/backend/log.py
+++ b/scripts/tracetool/backend/log.py
@@ -31,9 +31,7 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
-
- out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {',
+ out(' if (qemu_loglevel_mask(LOG_TRACE)) {',
' if (message_with_timestamp) {',
' struct timeval _now;',
' gettimeofday(&_now, NULL);',
@@ -49,7 +47,6 @@ def generate_h(event, group):
'#line %(out_next_lineno)d "%(out_filename)s"',
' }',
' }',
- cond=cond,
event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename),
name=event.name,
diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py
index 7c84c06b20..ce8036f5da 100644
--- a/scripts/tracetool/backend/simple.py
+++ b/scripts/tracetool/backend/simple.py
@@ -36,13 +36,8 @@ def generate_h_begin(events, group):
def generate_h(event, group):
- event_id = 'TRACE_' + event.name.upper()
- cond = "trace_event_get_state(%s)" % event_id
- out(' if (%(cond)s) {',
- ' _simple_%(api)s(%(args)s);',
- ' }',
+ out(' _simple_%(api)s(%(args)s);',
api=event.api(),
- cond=cond,
args=", ".join(event.args.names()))
diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py
index 6fdc1142fb..f84cec641c 100644
--- a/scripts/tracetool/backend/syslog.py
+++ b/scripts/tracetool/backend/syslog.py
@@ -30,14 +30,9 @@ def generate_h(event, group):
if len(event.args) > 0:
argnames = ", " + argnames
- cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper())
-
- out(' if (%(cond)s) {',
- '#line %(event_lineno)d "%(event_filename)s"',
+ out('#line %(event_lineno)d "%(event_filename)s"',
' syslog(LOG_INFO, "%(name)s " %(fmt)s %(argnames)s);',
'#line %(out_next_lineno)d "%(out_filename)s"',
- ' }',
- cond=cond,
event_lineno=event.lineno,
event_filename=os.path.relpath(event.filename),
name=event.name,
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index 89d54b9aff..7bbe6d3148 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -71,7 +71,8 @@ def generate(events, backend, group):
out('}')
- cond = "true"
+ event_id = 'TRACE_' + e.name.upper()
+ cond = "trace_event_get_state(%s)" % event_id
out('',
'static inline void %(api)s(%(args)s)',
--
2.34.1
next prev parent reply other threads:[~2025-06-16 20:13 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-06-16 20:12 [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo() Tanish Desai
2025-06-16 20:12 ` [PATCH 1/3] tracetool: removed the unused vcpu property Tanish Desai
2025-06-17 14:07 ` Stefan Hajnoczi
2025-06-17 18:36 ` [PATCH v2] " Tanish Desai
2025-06-17 19:43 ` [PATCH 1/3] " Alex Bennée
2025-06-16 20:12 ` [PATCH 2/3] tracetool: introduce generate_unconditional Tanish Desai
2025-06-17 22:42 ` Alex Bennée
2025-06-18 16:23 ` Tanish Desai
2025-06-16 20:12 ` Tanish Desai [this message]
2025-06-17 14:09 ` [PATCH 0/3] tracetool:cleanup "if(true)" check from trace_foo() Stefan Hajnoczi
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=20250616201222.6416-4-tanishdesai37@gmail.com \
--to=tanishdesai37@gmail.com \
--cc=mads@ynddal.dk \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=vilanova@ac.upc.edu \
/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).