tracetool:cleanup "if(true)" check from trace_foo()
cover tracetool:cleanup "if(true)" check from trace_foo()
This series of patch aims to removes the leftover if (true) condition from trace_foo, a remnant from the TCG tracing feature removal. It replaces it with a proper trace_event_get_state(...) check where necessary(for log/simple/syslog and ftrace backend). Additionally, this change centralizes the generation of trace_event_get_state(...) calls into format/h.py, eliminating redundant code across individual backends.
This cleanup results in more consistent and less repetitive backend code.
Tanish Desai (3):
tracetool: removed the unused vcpu property
tracetool: introduce generate_unconditional
tracetool: remove redundant event_get_state checks
scripts/tracetool/backend/__init__.py | 3 +++ scripts/tracetool/backend/dtrace.py | 3 ++- scripts/tracetool/backend/ftrace.py | 3 --- scripts/tracetool/backend/log.py | 9 +-------- scripts/tracetool/backend/simple.py | 11 +---------- scripts/tracetool/backend/syslog.py | 11 +---------- scripts/tracetool/backend/ust.py | 2 +- scripts/tracetool/format/h.py | 13 +++++++++---- 8 files changed, 18 insertions(+), 37 deletions(-)
Signature · 1 line
2.34.1
PATCH 1/3 tracetool: removed the unused vcpu property
The vcpu property is no longer used in these backends. Removing it avoids unnecessary checks and simplifies the code generation for these trace backends.
--- scripts/tracetool/backend/log.py | 6 +----- scripts/tracetool/backend/simple.py | 6 +----- scripts/tracetool/backend/syslog.py | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-)
scripts/tracetool/backend/log.py +1 -5
@@ -31,11 +31,7 @@ def generate_h(event, group): if len(event.args) > 0: argnames = ", " + argnames - if "vcpu" in event.properties: - # already checked on the generic format code - cond = "true" - else: - cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) + cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {', ' if (message_with_timestamp) {',
scripts/tracetool/backend/simple.py +1 -5
@@ -37,11 +37,7 @@ def generate_h_begin(events, group): def generate_h(event, group): event_id = 'TRACE_' + event.name.upper() - if "vcpu" in event.properties: - # already checked on the generic format code - cond = "true" - else: - cond = "trace_event_get_state(%s)" % event_id + cond = "trace_event_get_state(%s)" % event_id out(' if (%(cond)s) {', ' _simple_%(api)s(%(args)s);', ' }',
scripts/tracetool/backend/syslog.py +1 -5
@@ -30,11 +30,7 @@ def generate_h(event, group): if len(event.args) > 0: argnames = ", " + argnames - if "vcpu" in event.properties: - # already checked on the generic format code - cond = "true" - else: - cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) + cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) out(' if (%(cond)s) {', '#line %(event_lineno)d "%(event_filename)s"',
Signature · 1 line
2.34.1
Re: [PATCH 1/3] tracetool: removed the unused vcpu property
Quoted 9 lines · Tanish Desai
The vcpu property is no longer used in these backends. Removing it avoids unnecessary checks and simplifies the code generation for these trace backends.
Signed-off-by Tanish Desai <[email protected]>--- scripts/tracetool/backend/log.py | 6 +----- scripts/tracetool/backend/simple.py | 6 +----- scripts/tracetool/backend/syslog.py | 6 +----- 3 files changed, 3 insertions(+), 15 deletions(-)
Please also remove "vcpu" from scripts/tracetool/__init__.py:Event:
_VALID_PROPS = set(["disable", "vcpu"])
PATCH v2 1/1 tracetool: removed the unused vcpu property
The vcpu property is no longer used in these backends. Removing it avoids unnecessary checks and simplifies the code generation for these trace backends.
--- scripts/tracetool/__init__.py | 6 +++--- scripts/tracetool/backend/log.py | 6 +----- scripts/tracetool/backend/simple.py | 6 +----- scripts/tracetool/backend/syslog.py | 6 +----- 4 files changed, 6 insertions(+), 18 deletions(-)
scripts/tracetool/__init__.py +3 -3
@@ -216,9 +216,9 @@ class Event(object): r"\s*" r"(?:(?:(?P<fmt_trans>\".+),)?\s*(?P<fmt>\".+))?" r"\s*") - - _VALID_PROPS = set(["disable", "vcpu"]) - + + _VALID_PROPS = set(["disable"]) + def __init__(self, name, props, fmt, args, lineno, filename, orig=None, event_trans=None, event_exec=None): """
scripts/tracetool/backend/log.py +1 -5
@@ -31,11 +31,7 @@ def generate_h(event, group): if len(event.args) > 0: argnames = ", " + argnames - if "vcpu" in event.properties: - # already checked on the generic format code - cond = "true" - else: - cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) + cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) out(' if (%(cond)s && qemu_loglevel_mask(LOG_TRACE)) {', ' if (message_with_timestamp) {',
scripts/tracetool/backend/simple.py +1 -5
@@ -37,11 +37,7 @@ def generate_h_begin(events, group): def generate_h(event, group): event_id = 'TRACE_' + event.name.upper() - if "vcpu" in event.properties: - # already checked on the generic format code - cond = "true" - else: - cond = "trace_event_get_state(%s)" % event_id + cond = "trace_event_get_state(%s)" % event_id out(' if (%(cond)s) {', ' _simple_%(api)s(%(args)s);', ' }',
scripts/tracetool/backend/syslog.py +1 -5
@@ -30,11 +30,7 @@ def generate_h(event, group): if len(event.args) > 0: argnames = ", " + argnames - if "vcpu" in event.properties: - # already checked on the generic format code - cond = "true" - else: - cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) + cond = "trace_event_get_state(%s)" % ("TRACE_" + event.name.upper()) out(' if (%(cond)s) {', '#line %(event_lineno)d "%(event_filename)s"',
Signature · 1 line
2.34.1
Re: [PATCH 1/3] tracetool: removed the unused vcpu property
In reply to Tanish DesaiQuoted 4 lines · Tanish Desai
The vcpu property is no longer used in these backends. Removing it avoids unnecessary checks and simplifies the code generation for these trace backends.
Signed-off-by Tanish Desai <[email protected]>
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
PATCH 2/3 tracetool: introduce generate_unconditional
In reply to Tanish DesaiThis patch separates the generation logic of trace_foo() for the UST and DTrace backends from other backends.
The motivation is to remove the unnecessary if (true) in the _no_check function, as UST and DTrace do not require a trace_event_get_state check without introducing a seperate function it is very difficult to generate code which keeps them out of unified if condition. With this separation, we can safely move the trace_event_get_state check into trace_foo for the other backends only, keeping UST/DTrace generation paths clean.
A new generate_h_unconditional function has been introduced for UST and DTrace. It behaves similarly to generate_h, but is defined only in UST and DTrace backends. This ensures that generate_h is used by the other backends, while UST/DTrace selectively use generate_h_unconditional.
--- scripts/tracetool/backend/__init__.py | 3 +++ scripts/tracetool/backend/dtrace.py | 3 ++- scripts/tracetool/backend/ust.py | 2 +- scripts/tracetool/format/h.py | 10 +++++++--- 4 files changed, 13 insertions(+), 5 deletions(-)
scripts/tracetool/backend/__init__.py +3 -0
@@ -118,6 +118,9 @@ def generate_begin(self, events, group): def generate(self, event, group): self._run_function("generate_%s", event, group) + def generate_unconditional(self, event, group): + self._run_function("generate_%s_unconditional", event, group) + def generate_backend_dstate(self, event, group): self._run_function("generate_%s_backend_dstate", event, group)
scripts/tracetool/backend/dtrace.py +2 -1
@@ -61,7 +61,8 @@ def generate_h_begin(events, group): '#endif', uppername=e.name.upper()) -def generate_h(event, group): + +def generate_h_unconditional(event, group): out(' QEMU_%(uppername)s(%(argnames)s);', uppername=event.name.upper(), argnames=", ".join(event.args.names()))
scripts/tracetool/backend/ust.py +1 -1
@@ -30,7 +30,7 @@ def generate_h_begin(events, group): '') -def generate_h(event, group): +def generate_h_unconditional(event, group): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnames
scripts/tracetool/format/h.py +7 -3
@@ -76,13 +76,17 @@ def generate(events, backend, group): out('', 'static inline void %(api)s(%(args)s)', '{', - ' if (%(cond)s) {', + api=e.api(), + args=e.args) + + if "disable" not in e.properties: + backend.generate_unconditional(e, group) + + out(' 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)
Signature · 1 line
2.34.1
Re: [PATCH 2/3] tracetool: introduce generate_unconditional
Quoted 8 lines · Tanish Desai
This patch separates the generation logic of
trace_foo()for the UST and DTrace backends from other backends.
The motivation is to remove the unnecessary if (true) in the_no_checkfunction, as UST and DTrace do not require atrace_event_get_statecheck without introducing a seperate function it is very difficult to generate code which keeps them out of unified if condition. With this separation, we can safely move thetrace_event_get_statecheck intotrace_foofor the other backends only, keeping UST/DTrace generation paths clean.
A newgenerate_h_unconditionalfunction has been introduced for UST
and DTrace. It behaves similarly togenerate_h, but is defined only in
UST and DTrace backends. This ensures thatgenerate_his used by the
other backends, while UST/DTrace selectively usegenerate_h_unconditional.
Please fix the word wrap on the commit at 78 chars.
Quoted 28 lines
Signed-off-by Tanish Desai <[email protected]>--- scripts/tracetool/backend/__init__.py | 3 +++ scripts/tracetool/backend/dtrace.py | 3 ++- scripts/tracetool/backend/ust.py | 2 +- scripts/tracetool/format/h.py | 10 +++++++--- 4 files changed, 13 insertions(+), 5 deletions(-)scripts/tracetool/backend/__init__.py +3
-0@@ -118,6 +118,9 @@ def generate_begin(self, events, group): def generate(self, event, group): self._run_function("generate_%s", event, group) + def generate_unconditional(self, event, group): + self._run_function("generate_%s_unconditional", event, group) + def generate_backend_dstate(self, event, group): self._run_function("generate_%s_backend_dstate", event, group)scripts/tracetool/backend/dtrace.py +0
-0
scripts/tracetool/backend/dtrace.py def generate_h_begin(events, group): · line 64
Quoted 5 lines
scripts/tracetool/backend/dtrace.py +1
-1@@ -61,7 +61,8 @@ def generate_h_begin(events, group): '#endif', uppername=e.name.upper()) -def generate_h(event, group): +
stray newline
Quoted 31 lines
scripts/tracetool/backend/dtrace.py +1
-0+def generate_h_unconditional(event, group): out(' QEMU_%(uppername)s(%(argnames)s);', uppername=event.name.upper(), argnames=", ".join(event.args.names()))scripts/tracetool/backend/ust.py +1
-1@@ -30,7 +30,7 @@ def generate_h_begin(events, group): '') -def generate_h(event, group): +def generate_h_unconditional(event, group): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnamesscripts/tracetool/format/h.py +5
-1@@ -76,13 +76,17 @@ def generate(events, backend, group): out('', 'static inline void %(api)s(%(args)s)', '{', - ' if (%(cond)s) {', + api=e.api(), + args=e.args) + + if "disable" not in e.properties: + backend.generate_unconditional(e, group)
scripts/tracetool/format/h.py def generate(events, backend, group): · line 91
Quoted 10 lines
scripts/tracetool/format/h.py +2
-2+ + out(' 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)
Otherwise:
Signature · 2 lines
Alex Bennée Virtualisation Tech Lead @ Linaro
Re: [PATCH 2/3] tracetool: introduce generate_unconditional
Quoted 1 line
Please fix the word wrap on the commit at 78 chars.
I will send v2 with this fix
Quoted 1 line
stray newline
In tracetool/backend, every function is followed by two newline characters.
Quoted 110 lines · Alex Bennée
Quoted 1 line · Tanish Desai
This patch separates the generation logic of
trace_foo()for the UST andDTrace backends from other backends.
Quoted 1 line
The motivation is to remove the unnecessary if (true) in the
_no_checkfunction, as UST and DTrace do not require a
trace_event_get_statecheck without introducing a seperate function it is very difficult to generate code which keeps them out of unified if condition.Quoted 1 line
With this separation, we can safely move the
trace_event_get_statecheckinto
trace_foofor the other backends only, keeping UST/DTrace generation paths clean.Quoted 5 lines
A new
generate_h_unconditionalfunction has been introduced for UST and DTrace. It behaves similarly togenerate_h, but is defined only in UST and DTrace backends. This ensures thatgenerate_his used by the other backends, while UST/DTrace selectively usegenerate_h_unconditional.Please fix the word wrap on the commit at 78 chars.
Review
Quoted 10 lines
Signed-off-by Tanish Desai <[email protected]>--- scripts/tracetool/backend/__init__.py | 3 +++ scripts/tracetool/backend/dtrace.py | 3 ++- scripts/tracetool/backend/ust.py | 2 +- scripts/tracetool/format/h.py | 10 +++++++--- 4 files changed, 13 insertions(+), 5 deletions(-)(quoted diff) +0
-0
b/scripts/tracetool/backend/__init__.pyReview
Quoted 14 lines
index
7bfcc86cc5..c4456a5efd100644scripts/tracetool/backend/__init__.py +3
-0@@ -118,6 +118,9 @@ def generate_begin(self, events, group): def generate(self, event, group): self._run_function("generate_%s", event, group) + def generate_unconditional(self, event, group): + self._run_function("generate_%s_unconditional", event, group) + def generate_backend_dstate(self, event, group): self._run_function("generate_%s_backend_dstate", event, group)(quoted diff) +0
-0
b/scripts/tracetool/backend/dtrace.pyscripts/tracetool/backend/dtrace.py def generate_h_begin(events, group): · line 64
Quoted 9 lines
index
e17edc9b9d..171b7e09ed100644scripts/tracetool/backend/dtrace.py +1
-1@@ -61,7 +61,8 @@ def generate_h_begin(events, group): '#endif', uppername=e.name.upper()) -def generate_h(event, group): +stray newline
Review
Quoted 5 lines
scripts/tracetool/backend/dtrace.py +1
-0+def generate_h_unconditional(event, group): out(' QEMU_%(uppername)s(%(argnames)s);', uppername=event.name.upper(), argnames=", ".join(event.args.names()))(quoted diff) +0
-0
b/scripts/tracetool/backend/ust.pyReview
Quoted 13 lines
index
c857516f21..1564b490ec100644scripts/tracetool/backend/ust.py +1
-1@@ -30,7 +30,7 @@ def generate_h_begin(events, group): '') -def generate_h(event, group): +def generate_h_unconditional(event, group): argnames = ", ".join(event.args.names()) if len(event.args) > 0: argnames = ", " + argnames(quoted diff) +0
-0
b/scripts/tracetool/format/h.pyQuoted 13 lines
index
ea126b07ea..89d54b9aff100644scripts/tracetool/format/h.py +5
-1@@ -76,13 +76,17 @@ def generate(events, backend, group): out('', 'static inline void %(api)s(%(args)s)', '{', - ' if (%(cond)s) {', + api=e.api(), + args=e.args) + + if "disable" not in e.properties: + backend.generate_unconditional(e, group)scripts/tracetool/format/h.py def generate(events, backend, group): · line 91
Quoted 10 lines
scripts/tracetool/format/h.py +2
-2+ + out(' 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)Otherwise:
Reviewed-by Alex Bennée <[email protected]>--
Alex Bennée
Virtualisation Tech Lead @ Linaro
PATCH 3/3 tracetool: remove redundant event_get_state checks
In reply to Tanish DesaiMoved 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(-)
scripts/tracetool/backend/ftrace.py +0 -3
@@ -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"),
scripts/tracetool/backend/log.py +1 -4
@@ -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,
scripts/tracetool/backend/simple.py +1 -6
@@ -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 +1 -6
@@ -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,
scripts/tracetool/format/h.py +2 -1
@@ -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)',
Signature · 1 line
2.34.1
Quoted 5 lines · Tanish Desai
This series of patch aims to removes the leftover if (true) condition from
trace_foo, a remnant from the TCG tracing feature removal. It replaces it with a propertrace_event_get_state(...)check where necessary(for log/simple/syslog and ftrace backend). Additionally, this change centralizes the generation oftrace_event_get_state(...)calls intoformat/h.py, eliminating redundant code across individual backends.
This cleanup results in more consistent and less repetitive backend code.
CCing Alex Bennée, who authored commit 126d4123c50a ("tracing: excise the tcg related from tracetool").
Quoted 19 lines
Tanish Desai (3):
tracetool: removed the unused vcpu property
tracetool: introducegenerate_unconditional
tracetool: remove redundantevent_get_statechecksscripts/tracetool/backend/__init__.py | 3 +++ scripts/tracetool/backend/dtrace.py | 3 ++- scripts/tracetool/backend/ftrace.py | 3 --- scripts/tracetool/backend/log.py | 9 +-------- scripts/tracetool/backend/simple.py | 11 +---------- scripts/tracetool/backend/syslog.py | 11 +---------- scripts/tracetool/backend/ust.py | 2 +- scripts/tracetool/format/h.py | 13 +++++++++---- 8 files changed, 18 insertions(+), 37 deletions(-)Signature · 1 line
2.34.1