qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Stefan Hajnoczi <stefanha@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Philippe Mathieu-Daudé" <philmd@linaro.org>,
	"Bandan Das" <bsd@redhat.com>,
	"Markus Armbruster" <armbru@redhat.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Mahmoud Mandour" <ma.mandourr@gmail.com>,
	"Manos Pitsidianakis" <manos.pitsidianakis@linaro.org>,
	"Richard Henderson" <rth@twiddle.net>,
	"Alexander Bulekov" <alxndr@bu.edu>,
	"Stefan Hajnoczi" <stefanha@redhat.com>,
	"Pierrick Bouvier" <pierrick.bouvier@linaro.org>,
	qemu-rust@nongnu.org,
	"Marc-André Lureau" <marcandre.lureau@redhat.com>,
	"Qiuhao Li" <Qiuhao.Li@outlook.com>,
	"Cleber Rosa" <crosa@redhat.com>,
	"Mauro Carvalho Chehab" <mchehab+huawei@kernel.org>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	"Darren Kenny" <darren.kenny@oracle.com>,
	"Michael Roth" <michael.roth@amd.com>,
	"Mads Ynddal" <mads@ynddal.dk>,
	"Alexandre Iooss" <erdnaxe@crans.org>,
	"John Snow" <jsnow@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Fabiano Rosas" <farosas@suse.de>,
	"Tanish Desai" <tanishdesai37@gmail.com>,
	"Daniel P. Berrangé" <berrange@redhat.com>
Subject: [PULL 06/16] tracetool: add CHECK_TRACE_EVENT_GET_STATE
Date: Wed,  1 Oct 2025 11:30:49 -0400	[thread overview]
Message-ID: <20251001153059.194991-7-stefanha@redhat.com> (raw)
In-Reply-To: <20251001153059.194991-1-stefanha@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>
Reviewed-by: Daniel P. Berrangé <berrange@redhat.com>
Message-ID: <20250929154938.594389-7-pbonzini@redhat.com>
Signed-off-by: Stefan Hajnoczi <stefanha@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 bf91e443e9..9109a783c7 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 be7f32e67b..dd58713a15 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



  parent reply	other threads:[~2025-10-01 15:35 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-10-01 15:30 [PULL 00/16] Tracing patches Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 01/16] tracetool: fix usage of try_import() Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 02/16] tracetool: remove dead code Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 03/16] treewide: remove unnessary "coding" header Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 04/16] tracetool: add SPDX headers Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 05/16] trace/ftrace: move snprintf+write from tracepoints to ftrace.c Stefan Hajnoczi
2025-10-01 15:30 ` Stefan Hajnoczi [this message]
2025-10-01 15:30 ` [PULL 07/16] tracetool/backend: remove redundant trace event checks Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 08/16] tracetool: Add Rust format support Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 09/16] rust: add trace crate Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 10/16] rust: qdev: add minimal clock bindings Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 11/16] rust: pl011: add tracepoints Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 12/16] tracetool/simple: add Rust support Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 13/16] log: change qemu_loglevel to unsigned Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 14/16] tracetool/log: add Rust support Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 15/16] tracetool/ftrace: " Stefan Hajnoczi
2025-10-01 15:30 ` [PULL 16/16] tracetool/syslog: " Stefan Hajnoczi
2025-10-03 11:54 ` [PULL 00/16] Tracing patches Richard Henderson

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=20251001153059.194991-7-stefanha@redhat.com \
    --to=stefanha@redhat.com \
    --cc=Qiuhao.Li@outlook.com \
    --cc=alex.bennee@linaro.org \
    --cc=alxndr@bu.edu \
    --cc=armbru@redhat.com \
    --cc=berrange@redhat.com \
    --cc=bsd@redhat.com \
    --cc=crosa@redhat.com \
    --cc=darren.kenny@oracle.com \
    --cc=erdnaxe@crans.org \
    --cc=farosas@suse.de \
    --cc=jsnow@redhat.com \
    --cc=ma.mandourr@gmail.com \
    --cc=mads@ynddal.dk \
    --cc=manos.pitsidianakis@linaro.org \
    --cc=marcandre.lureau@redhat.com \
    --cc=mchehab+huawei@kernel.org \
    --cc=michael.roth@amd.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=philmd@linaro.org \
    --cc=pierrick.bouvier@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-rust@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=tanishdesai37@gmail.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).