Skip to contentSkip to conversation

tracetool: remove no_check_foo() and if(true){..} blocks

PATCH In review Tanish Desai 4 participants 9 messages Aug 6, 2025 – Aug 20, 2025

lore
Share & tools
lore
#0 lore raw

v2 cover tracetool: remove no_check_foo() and if(true){..} blocks

This patch series eliminates unnecessary if (true) { no_check_foo(...) } blocks and integrates the no_check_foo(...) logic directly into trace_foo(...). This results in cleaner, more maintainable code generation.

A new backend attribute, TRACE_EVENT_GET_STATE, is introduced. When enabled, it automatically generates conditional block :
if (trace_event_get_state(...)) { ... }. The generate() function emits code within this conditional structure for that backend.

Previously, without TRACE_EVENT_GET_STATE, each backend was required to manually implement out("if (trace_event_get_state(...)) {") in its generate() function, leading to code duplication.

Tanish Desai (2):
tracetool: add CHECK_TRACE_EVENT_GET_STATE tracetool/format: remove redundent trace-event checks

 scripts/tracetool/__init__.py         |  1 -
 scripts/tracetool/backend/__init__.py | 26 ++++++++++++++++-------
 scripts/tracetool/backend/ftrace.py   | 12 +++++------
 scripts/tracetool/backend/log.py      | 10 ++++-----
 scripts/tracetool/backend/simple.py   |  9 ++------
 scripts/tracetool/backend/syslog.py   |  8 ++-----
 scripts/tracetool/format/h.py         | 30 ++++++++++-----------------
 7 files changed, 43 insertions(+), 53 deletions(-)
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/2 tracetool: add CHECK_TRACE_EVENT_GET_STATE

New attributed added in backends CHECK_TRACE_EVENT_GET_STATE which when present and is True wraps the code generated by generate function in check_trace_event_get_state check else it is outside the conditional block.

---
 scripts/tracetool/__init__.py         |  1 -
 scripts/tracetool/backend/__init__.py | 26 ++++++++++++++++-------
 scripts/tracetool/format/h.py         | 30 ++++++++++-----------------
 3 files changed, 30 insertions(+), 27 deletions(-)
scripts/tracetool/__init__.py +0 -1
index 2ae2e562d6..d0a02c45d7 100644
@@ -332,7 +332,6 @@ def formats(self):
         return self._FMT.findall(self.fmt)
 
     QEMU_TRACE               = "trace_%(name)s"
-    QEMU_TRACE_NOCHECK       = "_nocheck__" + QEMU_TRACE
     QEMU_TRACE_TCG           = QEMU_TRACE + "_tcg"
     QEMU_DSTATE              = "_TRACE_%(NAME)s_DSTATE"
     QEMU_BACKEND_DSTATE      = "TRACE_%(NAME)s_BACKEND_DSTATE"
scripts/tracetool/backend/__init__.py +19 -7
index 7bfcc86cc5..4194719e52 100644
@@ -23,6 +23,8 @@
 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', generate function
+emits code inside check_trace_event_get_state check.
 ========= ====================================================================
 
 
@@ -101,22 +103,32 @@ 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)
scripts/tracetool/format/h.py +11 -19
index ea126b07ea..0ceb49eef5 100644
@@ -59,33 +59,25 @@ def generate(events, backend, group):
 
         out('    false)')
 
-        # tracer without checks
         out('',
             'static inline void %(api)s(%(args)s)',
             '{',
-            api=e.api(e.QEMU_TRACE_NOCHECK),
+            api=e.api(),
             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:
+            if "disable" not in e.properties:
+                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('}')
 
-        cond = "true"
-
-        out('',
-            'static inline void %(api)s(%(args)s)',
-            '{',
-            '    if (%(cond)s) {',
-            '        %(api_nocheck)s(%(names)s);',
-            '    }',
-            '}',
-            api=e.api(),
-            api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
-            args=e.args,
-            names=", ".join(e.args.names()),
-            cond=cond)
-
     backend.generate_end(events, group)
 
     out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v2 1/2] tracetool: add CHECK_TRACE_EVENT_GET_STATE

Quoted 18 lines · Tanish Desai

New attributed added in backends CHECK_TRACE_EVENT_GET_STATE which when present and is True wraps the code generated by generate function in check_trace_event_get_state check else it is outside the conditional block.

---
 scripts/tracetool/__init__.py         |  1 -
 scripts/tracetool/backend/__init__.py | 26 ++++++++++++++++-------
 scripts/tracetool/format/h.py         | 30 ++++++++++-----------------
 3 files changed, 30 insertions(+), 27 deletions(-)
scripts/tracetool/__init__.py +0 -0
index 2ae2e562d6..d0a02c45d7 100644

scripts/tracetool/__init__.py def formats(self): · line 335

Quoted 4 lines
scripts/tracetool/__init__.py +0 -1
@@ -332,7 +332,6 @@ def formats(self):
         return self._FMT.findall(self.fmt)
 
     QEMU_TRACE               = "trace_%(name)s"
-    QEMU_TRACE_NOCHECK       = "_nocheck__" + QEMU_TRACE

This is just removing obsolete code

Quoted 9 lines
scripts/tracetool/__init__.py +0 -0
     QEMU_TRACE_TCG           = QEMU_TRACE + "_tcg"
     QEMU_DSTATE              = "_TRACE_%(NAME)s_DSTATE"
     QEMU_BACKEND_DSTATE      = "TRACE_%(NAME)s_BACKEND_DSTATE"
scripts/tracetool/format/h.py +0 -0
index ea126b07ea..0ceb49eef5 100644

scripts/tracetool/format/h.py def generate(events, backend, group): · line 66

Quoted 10 lines
scripts/tracetool/format/h.py +1 -2
@@ -59,33 +59,25 @@ def generate(events, backend, group):
 
         out('    false)')
 
-        # tracer without checks
         out('',
             'static inline void %(api)s(%(args)s)',
             '{',
-            api=e.api(e.QEMU_TRACE_NOCHECK),
+            api=e.api(),
             args=e.args)

This bit is removing more obsolete code

Quoted 5 lines
scripts/tracetool/format/h.py +1 -2
         if "disable" not in e.properties:
-            backend.generate(e, group)
-
+            backend.generate(e, group, check_trace_event_get_state=False)

scripts/tracetool/format/h.py def generate(events, backend, group): · line 79

Quoted 10 lines
scripts/tracetool/format/h.py +9 -0
+
+        if backend.check_trace_event_get_state:
+            if "disable" not in e.properties:
+                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('}')

This is the actual new functionality

Quoted 6 lines
scripts/tracetool/format/h.py +0 -5
-        cond = "true"
-
-        out('',
-            'static inline void %(api)s(%(args)s)',
-            '{',

scripts/tracetool/format/h.py def generate(events, backend, group): · line 88

Quoted 10 lines
scripts/tracetool/format/h.py +0 -10
-            '    if (%(cond)s) {',
-            '        %(api_nocheck)s(%(names)s);',
-            '    }',
-            '}',
-            api=e.api(),
-            api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
-            args=e.args,
-            names=", ".join(e.args.names()),
-            cond=cond)
-

This is further obsolete code.

It is best to have new functionality added in a separate commit from the removal of obsolete code.

I've co-incidentally got removal of this obsolete code in the tracing test suite series I posted, so one will need to be rebased on top of the other, depending on what order Stefan wants to take the patches.

Quoted 7 lines
scripts/tracetool/format/h.py +0 -0
     backend.generate_end(events, group)
 
     out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())
Signature · 1 line
2.34.1

With regards,
Daniel

Signature · 3 lines
|: 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 :|
#3 lore raw

Re: [PATCH v2 1/2] tracetool: add CHECK_TRACE_EVENT_GET_STATE

Quoted 2 lines · Daniel P. Berrangé

It is best to have new functionality added in a separate commit from the removal of obsolete code.

My mistake - when Tanish and I "un-rebased" these patches from on top of yours, we placed the removal of the "nocheck" functions in patch 1 instead of patch 2 where it made more sense.

Quoted 4 lines

I've co-incidentally got removal of this obsolete code in the tracing test suite series I posted, so one will need to be rebased on top of the other, depending on what order Stefan wants to take the patches.

If the main blocker (the /dev/stdout issue) is fixed quickly, your patches should go in first because they aid in reviewing this one.

Tanish has started school again, so he'll probably concentrate on finishing what he has of the Rust work and I'll resubmit his patches later.

Paolo

#4 lore raw

Re: [PATCH v2 1/2] tracetool: add CHECK_TRACE_EVENT_GET_STATE

Quoted 8 lines · Paolo Bonzini
Quoted 2 lines · Daniel P. Berrangé

It is best to have new functionality added in a separate commit from the removal of obsolete code.

My mistake - when Tanish and I "un-rebased" these patches from on top of yours, we placed the removal of the "nocheck" functions in patch 1 instead of patch 2 where it made more sense.

Quoted 7 lines
Quoted 4 lines

I've co-incidentally got removal of this obsolete code in the tracing test suite series I posted, so one will need to be rebased on top of the other, depending on what order Stefan wants to take the patches.

If the main blocker (the /dev/stdout issue) is fixed quickly, your patches should go in first because they aid in reviewing this one.

I posted a new version that drops the stdout patch

https://lists.nongnu.org/archive/html/qemu-devel/2025-08/msg02716.html

With regards,
Daniel

Signature · 3 lines
|: 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 :|
#5 lore raw

Re: [PATCH v2 1/2] tracetool: add CHECK_TRACE_EVENT_GET_STATE

In reply to Tanish Desai
Quoted 30 lines · Tanish Desai

New attributed added in backends CHECK_TRACE_EVENT_GET_STATE which when present and is True wraps the code generated by generate function in check_trace_event_get_state check else it is outside the conditional block.

---
 scripts/tracetool/__init__.py         |  1 -
 scripts/tracetool/backend/__init__.py | 26 ++++++++++++++++-------
 scripts/tracetool/format/h.py         | 30 ++++++++++-----------------
 3 files changed, 30 insertions(+), 27 deletions(-)
scripts/tracetool/__init__.py +0 -1
index 2ae2e562d6..d0a02c45d7 100644
@@ -332,7 +332,6 @@ def formats(self):
         return self._FMT.findall(self.fmt)
 
     QEMU_TRACE               = "trace_%(name)s"
-    QEMU_TRACE_NOCHECK       = "_nocheck__" + QEMU_TRACE
     QEMU_TRACE_TCG           = QEMU_TRACE + "_tcg"
     QEMU_DSTATE              = "_TRACE_%(NAME)s_DSTATE"
     QEMU_BACKEND_DSTATE      = "TRACE_%(NAME)s_BACKEND_DSTATE"
scripts/tracetool/backend/__init__.py +0 -0
index 7bfcc86cc5..4194719e52 100644

scripts/tracetool/backend/__init__.py line 28

Quoted 6 lines
scripts/tracetool/backend/__init__.py +2 -0
@@ -23,6 +23,8 @@
 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', generate function
+emits code inside check_trace_event_get_state check.
 ========= ====================================================================

The '=' table formatting is broken. Further down in the file there is an example of a wider first column and how the second column cells wrap:

=============================== ==============================================
Function Description
=============================== ============================================== generate_<format>_begin(events) Generate backend- and format-specific file
header contents.

Please follow that style for consistency. You could also check reST markup syntax alternatives like an unordered list if tables are too clumsy.

Quoted 18 lines
scripts/tracetool/backend/__init__.py +5 -2
@@ -101,22 +103,32 @@ 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,

scripts/tracetool/backend/__init__.py class Wrapper: · line 122

Quoted 10 lines
scripts/tracetool/backend/__init__.py +7 -3
-                                        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)

Spaces are missing on this line: getattr(backend, name % self._format, None)

Quoted 26 lines
scripts/tracetool/backend/__init__.py +5 -2
+            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)
scripts/tracetool/format/h.py +0 -1
index ea126b07ea..0ceb49eef5 100644
@@ -59,33 +59,25 @@ def generate(events, backend, group):
 
         out('    false)')
 
-        # tracer without checks
         out('',
             'static inline void %(api)s(%(args)s)',
             '{',

scripts/tracetool/format/h.py def generate(events, backend, group): · line 71

Quoted 10 lines
scripts/tracetool/format/h.py +4 -3
-            api=e.api(e.QEMU_TRACE_NOCHECK),
+            api=e.api(),
             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:

This line can be indented...

scripts/tracetool/format/h.py def generate(events, backend, group): · line 72

Quoted 1 line
scripts/tracetool/format/h.py +1 -0
+            if "disable" not in e.properties:

...and this duplicate "disable" check can be dropped.

Quoted 29 lines
scripts/tracetool/format/h.py +6 -15
+                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('}')
 
-        cond = "true"
-
-        out('',
-            'static inline void %(api)s(%(args)s)',
-            '{',
-            '    if (%(cond)s) {',
-            '        %(api_nocheck)s(%(names)s);',
-            '    }',
-            '}',
-            api=e.api(),
-            api_nocheck=e.api(e.QEMU_TRACE_NOCHECK),
-            args=e.args,
-            names=", ".join(e.args.names()),
-            cond=cond)
-
     backend.generate_end(events, group)
 
     out('#endif /* TRACE_%s_GENERATED_TRACERS_H */' % group.upper())
Signature · 1 line
2.34.1
#6 lore raw

PATCH v2 2/2 tracetool/format: remove redundent trace-event checks

In reply to Tanish Desai

Remove redundent if(check_trace_event) check
from individual backends.
Adding CHECK_TRACE_EVENT_GET_STATE in log,syslog,
dtrace and simple backend.

---
 scripts/tracetool/backend/ftrace.py | 12 +++++-------
 scripts/tracetool/backend/log.py    | 10 ++++------
 scripts/tracetool/backend/simple.py |  9 ++-------
 scripts/tracetool/backend/syslog.py |  8 ++------
 4 files changed, 13 insertions(+), 26 deletions(-)
scripts/tracetool/backend/ftrace.py +5 -7
index 5fa30ccc08..c65d3b89b3 100644
@@ -16,6 +16,7 @@
 
 
 PUBLIC = True
+CHECK_TRACE_EVENT_GET_STATE = True
 
 
 def generate_h_begin(events, group):
@@ -28,11 +29,10 @@ 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('        {',
+        '            char ftrace_buf[MAX_TRACE_STRLEN];',
+        '            int unused __attribute__ ((unused));',
+        '            int trlen;',
         '#line %(event_lineno)d "%(event_filename)s"',
         '            trlen = snprintf(ftrace_buf, MAX_TRACE_STRLEN,',
         '                             "%(name)s " %(fmt)s "\\n" %(argnames)s);',
@@ -40,10 +40,8 @@ def generate_h(event, group):
         '            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=event.filename,
         fmt=event.fmt.rstrip("\n"),
scripts/tracetool/backend/log.py +4 -6
index eb50ceea34..2aa180f4b4 100644
@@ -16,6 +16,7 @@
 
 
 PUBLIC = True
+CHECK_TRACE_EVENT_GET_STATE = True
 
 
 def generate_h_begin(events, group):
@@ -28,14 +29,11 @@ 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)) {',
         '#line %(event_lineno)d "%(event_filename)s"',
-        '        qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);',
+        '            qemu_log("%(name)s " %(fmt)s "\\n"%(argnames)s);',
         '#line %(out_next_lineno)d "%(out_filename)s"',
-        '    }',
-        cond=cond,
+        '        }',
         event_lineno=event.lineno,
         event_filename=event.filename,
         name=event.name,
scripts/tracetool/backend/simple.py +2 -7
index 7c84c06b20..623ea7d8ed 100644
@@ -16,7 +16,7 @@
 
 
 PUBLIC = True
-
+CHECK_TRACE_EVENT_GET_STATE = True
 
 def is_string(arg):
     strtype = ('const char*', 'char*', 'const char *', 'char *')
@@ -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()))
 
 
scripts/tracetool/backend/syslog.py +2 -6
index 3f82e54aab..04ec85717a 100644
@@ -16,6 +16,7 @@
 
 
 PUBLIC = True
+CHECK_TRACE_EVENT_GET_STATE = True
 
 
 def generate_h_begin(events, group):
@@ -28,14 +29,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=event.filename,
         name=event.name,
Signature · 1 line
2.34.1
#7 lore raw

Re: [PATCH v2 2/2] tracetool/format: remove redundent trace-event checks

Quoted 28 lines · Tanish Desai

Remove redundent if(check_trace_event) check
from individual backends.
Adding CHECK_TRACE_EVENT_GET_STATE in log,syslog,
dtrace and simple backend.

---
 scripts/tracetool/backend/ftrace.py | 12 +++++-------
 scripts/tracetool/backend/log.py    | 10 ++++------
 scripts/tracetool/backend/simple.py |  9 ++-------
 scripts/tracetool/backend/syslog.py |  8 ++------
 4 files changed, 13 insertions(+), 26 deletions(-)
scripts/tracetool/backend/ftrace.py +1 -0
index 5fa30ccc08..c65d3b89b3 100644
@@ -16,6 +16,7 @@
 
 
 PUBLIC = True
+CHECK_TRACE_EVENT_GET_STATE = True
 
 
 def generate_h_begin(events, group):
@@ -28,11 +29,10 @@ def generate_h(event, group):
     if len(event.args) > 0:
         argnames = ", " + argnames

scripts/tracetool/backend/ftrace.py def generate_h(event, group): · line 35

Quoted 10 lines
scripts/tracetool/backend/ftrace.py +4 -5
 
-    out('    {',
-        '        char ftrace_buf[MAX_TRACE_STRLEN];',
-        '        int unused __attribute__ ((unused));',
-        '        int trlen;',
-        '        if (trace_event_get_state(%(event_id)s)) {',
+    out('        {',
+        '            char ftrace_buf[MAX_TRACE_STRLEN];',
+        '            int unused __attribute__ ((unused));',
+        '            int trlen;',

This results in unecessary nested code blocks & indent. For example:

static inline void trace_test_blah(void *context, const char *filename)

{
    if (trace_event_get_state(TRACE_TEST_BLAH)) {
        {
            char ftrace_buf[MAX_TRACE_STRLEN];
            int unused __attribute__ ((unused));
            int trlen;

#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);
        }
    }
}

Instead of

static inline void trace_test_blah(void *context, const char *filename)

{
    if (trace_event_get_state(TRACE_TEST_BLAH)) {
        char ftrace_buf[MAX_TRACE_STRLEN];
        int unused __attribute__ ((unused));
        int trlen;

#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);
    }
}

With regards,
Daniel

Signature · 3 lines
|: 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 :|
Reviewed-by on v2 2/2
#8 lore raw

Re: [PATCH v2 2/2] tracetool/format: remove redundent trace-event checks

In reply to Tanish Desai
Quoted 5 lines · Tanish Desai

Remove redundent if(check_trace_event) check
from individual backends.
Adding CHECK_TRACE_EVENT_GET_STATE in log,syslog,
dtrace and simple backend.

Quoted 7 lines
---
 scripts/tracetool/backend/ftrace.py | 12 +++++-------
 scripts/tracetool/backend/log.py    | 10 ++++------
 scripts/tracetool/backend/simple.py |  9 ++-------
 scripts/tracetool/backend/syslog.py |  8 ++------
 4 files changed, 13 insertions(+), 26 deletions(-)