From: Paolo Bonzini <pbonzini@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Tanish Desai" <tanishdesai37@gmail.com>,
"Stefan Hajnoczi" <stefanha@redhat.com>,
"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
"Mads Ynddal" <mads@ynddal.dk>,
"Daniel P . Berrangé" <berrange@redhat.com>,
"Zhao Liu" <zhao1.liu@intel.com>,
qemu-rust@nongnu.org
Subject: [PATCH 06/16] tracetool: add CHECK_TRACE_EVENT_GET_STATE
Date: Mon, 29 Sep 2025 17:49:28 +0200 [thread overview]
Message-ID: <20250929154938.594389-7-pbonzini@redhat.com> (raw)
In-Reply-To: <20250929154938.594389-1-pbonzini@redhat.com>
From: Tanish Desai <tanishdesai37@gmail.com>
Add a new attribute CHECK_TRACE_EVENT_GET_STATE to the backends.
When present and True, the code generated by the generate function
is wrapped in a conditional that checks whether the event is enabled;
this removes the need for repeating the same conditional in multiple
backends.
Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
scripts/tracetool/backend/__init__.py | 39 ++++++++++++++++++---------
scripts/tracetool/format/h.py | 11 +++++---
2 files changed, 35 insertions(+), 15 deletions(-)
diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py
index bf91e443e99..9109a783c72 100644
--- a/scripts/tracetool/backend/__init__.py
+++ b/scripts/tracetool/backend/__init__.py
@@ -19,11 +19,15 @@
Backend attributes
------------------
-========= ====================================================================
-Attribute Description
-========= ====================================================================
-PUBLIC If exists and is set to 'True', the backend is considered "public".
-========= ====================================================================
+=========================== ====================================================
+Attribute Description
+=========================== ====================================================
+PUBLIC If exists and is set to 'True', the backend is
+ considered "public".
+CHECK_TRACE_EVENT_GET_STATE If exists and is set to 'True', the backend-specific
+ code inside the tracepoint is emitted within an
+ ``if trace_event_get_state()`` conditional.
+=========================== ====================================================
Backend functions
@@ -101,22 +105,33 @@ class Wrapper:
def __init__(self, backends, format):
self._backends = [backend.replace("-", "_") for backend in backends]
self._format = format.replace("-", "_")
+ self.check_trace_event_get_state = False
for backend in self._backends:
assert exists(backend)
assert tracetool.format.exists(self._format)
+ for backend in self.backend_modules():
+ check_trace_event_get_state = getattr(backend, "CHECK_TRACE_EVENT_GET_STATE", False)
+ self.check_trace_event_get_state = self.check_trace_event_get_state or check_trace_event_get_state
- def _run_function(self, name, *args, **kwargs):
+ def backend_modules(self):
for backend in self._backends:
- func = tracetool.try_import("tracetool.backend." + backend,
- name % self._format, None)[1]
- if func is not None:
- func(*args, **kwargs)
+ module = tracetool.try_import("tracetool.backend." + backend)[1]
+ if module is not None:
+ yield module
+
+ def _run_function(self, name, *args, check_trace_event_get_state=None, **kwargs):
+ for backend in self.backend_modules():
+ func = getattr(backend, name % self._format, None)
+ if func is not None and \
+ (check_trace_event_get_state is None or
+ check_trace_event_get_state == getattr(backend, 'CHECK_TRACE_EVENT_GET_STATE', False)):
+ func(*args, **kwargs)
def generate_begin(self, events, group):
self._run_function("generate_%s_begin", events, group)
- def generate(self, event, group):
- self._run_function("generate_%s", event, group)
+ def generate(self, event, group, check_trace_event_get_state=None):
+ self._run_function("generate_%s", event, group, check_trace_event_get_state=check_trace_event_get_state)
def generate_backend_dstate(self, event, group):
self._run_function("generate_%s_backend_dstate", event, group)
diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py
index be7f32e67b9..dd58713a158 100644
--- a/scripts/tracetool/format/h.py
+++ b/scripts/tracetool/format/h.py
@@ -55,7 +55,6 @@ def generate(events, backend, group):
out(' false)')
- # tracer without checks
out('',
'static inline void %(api)s(%(args)s)',
'{',
@@ -63,11 +62,17 @@ def generate(events, backend, group):
args=e.args)
if "disable" not in e.properties:
- backend.generate(e, group)
+ backend.generate(e, group, check_trace_event_get_state=False)
+ if backend.check_trace_event_get_state:
+ event_id = 'TRACE_' + e.name.upper()
+ cond = "trace_event_get_state(%s)" % event_id
+ out(' if (%(cond)s) {',
+ cond=cond)
+ backend.generate(e, group, check_trace_event_get_state=True)
+ out(' }')
out('}')
-
backend.generate_end(events, group)
out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())
--
2.51.0
next prev parent reply other threads:[~2025-09-29 15:52 UTC|newest]
Thread overview: 19+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-09-29 15:49 [PATCH v2 00/16] tracetool: add Rust support Paolo Bonzini
2025-09-29 15:49 ` [PATCH 01/16] tracetool: fix usage of try_import() Paolo Bonzini
2025-09-29 15:49 ` [PATCH 02/16] tracetool: remove dead code Paolo Bonzini
2025-09-29 15:49 ` [PATCH 03/16] treewide: remove unnessary "coding" header Paolo Bonzini
2025-09-29 15:49 ` [PATCH 04/16] tracetool: add SPDX headers Paolo Bonzini
2025-09-29 15:49 ` [PATCH 05/16] trace/ftrace: move snprintf+write from tracepoints to ftrace.c Paolo Bonzini
2025-09-29 15:49 ` Paolo Bonzini [this message]
2025-09-29 15:49 ` [PATCH 07/16] tracetool/backend: remove redundant trace event checks Paolo Bonzini
2025-09-29 15:49 ` [PATCH 08/16] tracetool: Add Rust format support Paolo Bonzini
2025-09-29 15:49 ` [PATCH 09/16] rust: add trace crate Paolo Bonzini
2025-09-29 15:49 ` [PATCH 10/16] rust: qdev: add minimal clock bindings Paolo Bonzini
2025-09-29 15:49 ` [PATCH 11/16] rust: pl011: add tracepoints Paolo Bonzini
2025-09-29 15:49 ` [PATCH 12/16] tracetool/simple: add Rust support Paolo Bonzini
2025-09-29 15:49 ` [PATCH 13/16] log: change qemu_loglevel to unsigned Paolo Bonzini
2025-09-29 15:49 ` [PATCH 14/16] tracetool/log: add Rust support Paolo Bonzini
2025-09-29 15:49 ` [PATCH 15/16] tracetool/ftrace: " Paolo Bonzini
2025-09-29 15:49 ` [PATCH 16/16] tracetool/syslog: " Paolo Bonzini
2025-10-01 15:24 ` [PATCH v2 00/16] tracetool: " Stefan Hajnoczi
-- strict thread matches above, loose matches on Subject: below --
2025-09-19 11:25 [PATCH " Paolo Bonzini
2025-09-19 11:25 ` [PATCH 06/16] tracetool: add CHECK_TRACE_EVENT_GET_STATE Paolo Bonzini
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=20250929154938.594389-7-pbonzini@redhat.com \
--to=pbonzini@redhat.com \
--cc=berrange@redhat.com \
--cc=mads@ynddal.dk \
--cc=manos.pitsidianakis@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-rust@nongnu.org \
--cc=stefanha@redhat.com \
--cc=tanishdesai37@gmail.com \
--cc=zhao1.liu@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).