From 20b92da6db74490a6ffdf01f3ec8d99fcb7c2c18 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 29 Sep 2025 17:49:25 +0200 Subject: treewide: remove unnessary "coding" header The "-*- coding: utf-8 -*-" header was needed in Python 2, but in Python 3 UTF-8 is already the default encoding of source files. It is even less necessary in .css files that do not have UTF-8 sequences at all. Suggested-by: Manos Pitsidianakis Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-ID: <20250929154938.594389-4-pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi --- scripts/tracetool/backend/syslog.py | 2 -- 1 file changed, 2 deletions(-) (limited to 'scripts/tracetool/backend/syslog.py') diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py index 3f82e54aab..74af038089 100644 --- a/scripts/tracetool/backend/syslog.py +++ b/scripts/tracetool/backend/syslog.py @@ -1,5 +1,3 @@ -# -*- coding: utf-8 -*- - """ Syslog built-in backend. """ -- cgit 1.4.1 From 6f94ad27f0014c04a2aa403988acc22740a21196 Mon Sep 17 00:00:00 2001 From: Paolo Bonzini Date: Mon, 29 Sep 2025 17:49:26 +0200 Subject: tracetool: add SPDX headers Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-ID: <20250929154938.594389-5-pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi --- scripts/tracetool/__init__.py | 2 ++ scripts/tracetool/backend/__init__.py | 2 ++ scripts/tracetool/backend/dtrace.py | 2 ++ scripts/tracetool/backend/ftrace.py | 2 ++ scripts/tracetool/backend/log.py | 2 ++ scripts/tracetool/backend/simple.py | 2 ++ scripts/tracetool/backend/syslog.py | 2 ++ scripts/tracetool/backend/ust.py | 2 ++ scripts/tracetool/format/__init__.py | 2 ++ scripts/tracetool/format/c.py | 2 ++ scripts/tracetool/format/d.py | 2 ++ scripts/tracetool/format/h.py | 2 ++ scripts/tracetool/format/log_stap.py | 2 ++ scripts/tracetool/format/simpletrace_stap.py | 2 ++ scripts/tracetool/format/stap.py | 2 ++ scripts/tracetool/format/ust_events_c.py | 2 ++ scripts/tracetool/format/ust_events_h.py | 2 ++ 17 files changed, 34 insertions(+) (limited to 'scripts/tracetool/backend/syslog.py') diff --git a/scripts/tracetool/__init__.py b/scripts/tracetool/__init__.py index 9dd8ec27e1..c4fa0f74e6 100644 --- a/scripts/tracetool/__init__.py +++ b/scripts/tracetool/__init__.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Machinery for generating tracing-related intermediate files. """ diff --git a/scripts/tracetool/backend/__init__.py b/scripts/tracetool/backend/__init__.py index 7040130919..bf91e443e9 100644 --- a/scripts/tracetool/backend/__init__.py +++ b/scripts/tracetool/backend/__init__.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Backend management. diff --git a/scripts/tracetool/backend/dtrace.py b/scripts/tracetool/backend/dtrace.py index 4835454193..b4af403025 100644 --- a/scripts/tracetool/backend/dtrace.py +++ b/scripts/tracetool/backend/dtrace.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ DTrace/SystemTAP backend. """ diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backend/ftrace.py index e6317ca4bf..a14aafcee6 100644 --- a/scripts/tracetool/backend/ftrace.py +++ b/scripts/tracetool/backend/ftrace.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Ftrace built-in backend. """ diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py index 9842522b18..faacec4610 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Stderr built-in backend. """ diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py index 066e5e9f11..97e40495ee 100644 --- a/scripts/tracetool/backend/simple.py +++ b/scripts/tracetool/backend/simple.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Simple built-in backend. """ diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py index 74af038089..78ee67136b 100644 --- a/scripts/tracetool/backend/syslog.py +++ b/scripts/tracetool/backend/syslog.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Syslog built-in backend. """ diff --git a/scripts/tracetool/backend/ust.py b/scripts/tracetool/backend/ust.py index 6cc651646d..3aa9bb1da2 100644 --- a/scripts/tracetool/backend/ust.py +++ b/scripts/tracetool/backend/ust.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ LTTng User Space Tracing backend. """ diff --git a/scripts/tracetool/format/__init__.py b/scripts/tracetool/format/__init__.py index 94a37bfce9..7b9d1b5782 100644 --- a/scripts/tracetool/format/__init__.py +++ b/scripts/tracetool/format/__init__.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Format management. diff --git a/scripts/tracetool/format/c.py b/scripts/tracetool/format/c.py index 3c4398c237..50e03313cb 100644 --- a/scripts/tracetool/format/c.py +++ b/scripts/tracetool/format/c.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ trace/generated-tracers.c """ diff --git a/scripts/tracetool/format/d.py b/scripts/tracetool/format/d.py index 684598c183..e9e33dfe30 100644 --- a/scripts/tracetool/format/d.py +++ b/scripts/tracetool/format/d.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ trace/generated-tracers.dtrace (DTrace only). """ diff --git a/scripts/tracetool/format/h.py b/scripts/tracetool/format/h.py index 2119753be1..be7f32e67b 100644 --- a/scripts/tracetool/format/h.py +++ b/scripts/tracetool/format/h.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ trace/generated-tracers.h """ diff --git a/scripts/tracetool/format/log_stap.py b/scripts/tracetool/format/log_stap.py index 02f23bfb8d..259303a189 100644 --- a/scripts/tracetool/format/log_stap.py +++ b/scripts/tracetool/format/log_stap.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Generate .stp file that printfs log messages (DTrace with SystemTAP only). """ diff --git a/scripts/tracetool/format/simpletrace_stap.py b/scripts/tracetool/format/simpletrace_stap.py index 3c3584a931..c7bde97a85 100644 --- a/scripts/tracetool/format/simpletrace_stap.py +++ b/scripts/tracetool/format/simpletrace_stap.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Generate .stp file that outputs simpletrace binary traces (DTrace with SystemTAP only). """ diff --git a/scripts/tracetool/format/stap.py b/scripts/tracetool/format/stap.py index 04c7a35a25..285c9203ba 100644 --- a/scripts/tracetool/format/stap.py +++ b/scripts/tracetool/format/stap.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ Generate .stp file (DTrace with SystemTAP only). """ diff --git a/scripts/tracetool/format/ust_events_c.py b/scripts/tracetool/format/ust_events_c.py index ea5f0ae99f..074226bfd3 100644 --- a/scripts/tracetool/format/ust_events_c.py +++ b/scripts/tracetool/format/ust_events_c.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ trace/generated-ust.c """ diff --git a/scripts/tracetool/format/ust_events_h.py b/scripts/tracetool/format/ust_events_h.py index 242c9814fd..cee7970a40 100644 --- a/scripts/tracetool/format/ust_events_h.py +++ b/scripts/tracetool/format/ust_events_h.py @@ -1,3 +1,5 @@ +# SPDX-License-Identifier: GPL-2.0-or-later + """ trace/generated-ust-provider.h """ -- cgit 1.4.1 From 494492c5c5a145e04f3ebc9eb40fd34ffbcc2061 Mon Sep 17 00:00:00 2001 From: Tanish Desai Date: Mon, 29 Sep 2025 17:49:29 +0200 Subject: tracetool/backend: remove redundant trace event checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Use CHECK_TRACE_EVENT_GET_STATE in log, syslog, dtrace and simple backend, so that the "if (trace_event_get_state)" is created from common code and unified when multiple backends are active. When a single backend is active there is no code change (except for the log backend, as shown in tests/tracetool/log.h), but the code in the backends is simpler. Signed-off-by: Tanish Desai Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Reviewed-by: Daniel P. Berrangé Message-ID: <20250929154938.594389-8-pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi --- scripts/tracetool/backend/ftrace.py | 6 ++---- scripts/tracetool/backend/log.py | 10 ++++------ scripts/tracetool/backend/simple.py | 8 ++------ scripts/tracetool/backend/syslog.py | 8 ++------ tests/tracetool/log.h | 16 ++++++++++------ 5 files changed, 20 insertions(+), 28 deletions(-) (limited to 'scripts/tracetool/backend/syslog.py') diff --git a/scripts/tracetool/backend/ftrace.py b/scripts/tracetool/backend/ftrace.py index 8c0ce3f23a..7ddd5d11a6 100644 --- a/scripts/tracetool/backend/ftrace.py +++ b/scripts/tracetool/backend/ftrace.py @@ -16,6 +16,7 @@ from tracetool import out 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 - out(' if (trace_event_get_state(%(event_id)s)) {', - '#line %(event_lineno)d "%(event_filename)s"', + out('#line %(event_lineno)d "%(event_filename)s"', ' ftrace_write("%(name)s " %(fmt)s "\\n" %(argnames)s);', '#line %(out_next_lineno)d "%(out_filename)s"', - ' }', 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"), diff --git a/scripts/tracetool/backend/log.py b/scripts/tracetool/backend/log.py index faacec4610..d01d234289 100644 --- a/scripts/tracetool/backend/log.py +++ b/scripts/tracetool/backend/log.py @@ -16,6 +16,7 @@ from tracetool import out 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, diff --git a/scripts/tracetool/backend/simple.py b/scripts/tracetool/backend/simple.py index 97e40495ee..b5a6b7205a 100644 --- a/scripts/tracetool/backend/simple.py +++ b/scripts/tracetool/backend/simple.py @@ -16,6 +16,7 @@ from tracetool import out PUBLIC = True +CHECK_TRACE_EVENT_GET_STATE = True def is_string(arg): @@ -36,13 +37,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 78ee67136b..177414d56a 100644 --- a/scripts/tracetool/backend/syslog.py +++ b/scripts/tracetool/backend/syslog.py @@ -16,6 +16,7 @@ from tracetool import out 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, diff --git a/tests/tracetool/log.h b/tests/tracetool/log.h index edcc7f9d47..c7795871f8 100644 --- a/tests/tracetool/log.h +++ b/tests/tracetool/log.h @@ -21,10 +21,12 @@ extern uint16_t _TRACE_TEST_WIBBLE_DSTATE; static inline void trace_test_blah(void *context, const char *filename) { - if (trace_event_get_state(TRACE_TEST_BLAH) && qemu_loglevel_mask(LOG_TRACE)) { + if (trace_event_get_state(TRACE_TEST_BLAH)) { + if (qemu_loglevel_mask(LOG_TRACE)) { #line 4 "trace-events" - qemu_log("test_blah " "Blah context=%p filename=%s" "\n", context, filename); -#line 28 "log.h" + qemu_log("test_blah " "Blah context=%p filename=%s" "\n", context, filename); +#line 29 "log.h" + } } } @@ -34,10 +36,12 @@ static inline void trace_test_blah(void *context, const char *filename) static inline void trace_test_wibble(void *context, int value) { - if (trace_event_get_state(TRACE_TEST_WIBBLE) && qemu_loglevel_mask(LOG_TRACE)) { + if (trace_event_get_state(TRACE_TEST_WIBBLE)) { + if (qemu_loglevel_mask(LOG_TRACE)) { #line 5 "trace-events" - qemu_log("test_wibble " "Wibble context=%p value=%d" "\n", context, value); -#line 41 "log.h" + qemu_log("test_wibble " "Wibble context=%p value=%d" "\n", context, value); +#line 44 "log.h" + } } } #endif /* TRACE_TESTSUITE_GENERATED_TRACERS_H */ -- cgit 1.4.1 From 1461752f0fa4bcd7e60d51fe47e3430f8a81cdd8 Mon Sep 17 00:00:00 2001 From: Tanish Desai Date: Mon, 29 Sep 2025 17:49:38 +0200 Subject: tracetool/syslog: add Rust support The syslog backend needs the syslog function from libc and the LOG_INFO enum value; they are re-exported as "::trace::syslog" and "::trace::LOG_INFO" so that device crates do not all have to add the libc dependency, but otherwise there is nothing special. Signed-off-by: Tanish Desai Reviewed-by: Stefan Hajnoczi Signed-off-by: Paolo Bonzini Message-ID: <20250929154938.594389-17-pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi --- rust/Cargo.lock | 3 +++ rust/trace/Cargo.toml | 3 +++ rust/trace/src/lib.rs | 4 ++++ scripts/tracetool/backend/syslog.py | 7 ++++++- tests/tracetool/syslog.rs | 40 +++++++++++++++++++++++++++++++++++++ tests/tracetool/tracetool-test.py | 2 +- 6 files changed, 57 insertions(+), 2 deletions(-) create mode 100644 tests/tracetool/syslog.rs (limited to 'scripts/tracetool/backend/syslog.py') diff --git a/rust/Cargo.lock b/rust/Cargo.lock index f84a3dd076..444ef516a7 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -262,6 +262,9 @@ dependencies = [ [[package]] name = "trace" version = "0.1.0" +dependencies = [ + "libc", +] [[package]] name = "unicode-ident" diff --git a/rust/trace/Cargo.toml b/rust/trace/Cargo.toml index 13ac0b33d6..fc81bce580 100644 --- a/rust/trace/Cargo.toml +++ b/rust/trace/Cargo.toml @@ -12,5 +12,8 @@ license.workspace = true repository.workspace = true rust-version.workspace = true +[dependencies] +libc = { workspace = true } + [lints] workspace = true diff --git a/rust/trace/src/lib.rs b/rust/trace/src/lib.rs index 0955461573..e03bce43c4 100644 --- a/rust/trace/src/lib.rs +++ b/rust/trace/src/lib.rs @@ -3,6 +3,10 @@ //! This crate provides macros that aid in using QEMU's tracepoint //! functionality. +#[doc(hidden)] +/// Re-exported item to avoid adding libc as a dependency everywhere. +pub use libc::{syslog, LOG_INFO}; + #[macro_export] /// Define the trace-points from the named directory (which should have slashes /// replaced by underscore characters) as functions in a module called `trace`. diff --git a/scripts/tracetool/backend/syslog.py b/scripts/tracetool/backend/syslog.py index 177414d56a..12b826593d 100644 --- a/scripts/tracetool/backend/syslog.py +++ b/scripts/tracetool/backend/syslog.py @@ -12,7 +12,7 @@ __maintainer__ = "Stefan Hajnoczi" __email__ = "stefanha@redhat.com" -from tracetool import out +from tracetool import out, expand_format_string PUBLIC = True @@ -38,6 +38,11 @@ def generate_h(event, group): fmt=event.fmt.rstrip("\n"), argnames=argnames) +def generate_rs(event, group): + out(' let format_string = c"%(fmt)s";', + ' unsafe {::trace::syslog(::trace::LOG_INFO, format_string.as_ptr() as *const c_char, %(args)s);}', + fmt=expand_format_string(event.fmt), + args=event.args.rust_call_varargs()) def generate_h_backend_dstate(event, group): out(' trace_event_get_state_dynamic_by_id(%(event_id)s) || \\', diff --git a/tests/tracetool/syslog.rs b/tests/tracetool/syslog.rs new file mode 100644 index 0000000000..9d3675a0b5 --- /dev/null +++ b/tests/tracetool/syslog.rs @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +// This file is @generated by tracetool, do not edit. + +#[allow(unused_imports)] +use std::ffi::c_char; +#[allow(unused_imports)] +use util::bindings; + +#[inline(always)] +fn trace_event_state_is_enabled(dstate: u16) -> bool { + (unsafe { trace_events_enabled_count }) != 0 && dstate != 0 +} + +extern "C" { + static mut trace_events_enabled_count: u32; +} +extern "C" { + static mut _TRACE_TEST_BLAH_DSTATE: u16; + static mut _TRACE_TEST_WIBBLE_DSTATE: u16; +} + +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_blah(_context: *mut (), _filename: &std::ffi::CStr) +{ + if trace_event_state_is_enabled(unsafe { _TRACE_TEST_BLAH_DSTATE}) { + let format_string = c"Blah context=%p filename=%s"; + unsafe {::trace::syslog(::trace::LOG_INFO, format_string.as_ptr() as *const c_char, _context /* as *mut () */, _filename.as_ptr());} + } +} + +#[inline(always)] +#[allow(dead_code)] +pub fn trace_test_wibble(_context: *mut (), _value: std::ffi::c_int) +{ + if trace_event_state_is_enabled(unsafe { _TRACE_TEST_WIBBLE_DSTATE}) { + let format_string = c"Wibble context=%p value=%d"; + unsafe {::trace::syslog(::trace::LOG_INFO, format_string.as_ptr() as *const c_char, _context /* as *mut () */, _value /* as std::ffi::c_int */);} + } +} diff --git a/tests/tracetool/tracetool-test.py b/tests/tracetool/tracetool-test.py index 3341fb18f9..786083ad7f 100755 --- a/tests/tracetool/tracetool-test.py +++ b/tests/tracetool/tracetool-test.py @@ -14,7 +14,7 @@ def get_formats(backend): "c", "h", ] - if backend in {"ftrace", "log", "simple"}: + if backend in {"ftrace", "log", "simple", "syslog"}: formats += ["rs"] if backend == "dtrace": formats += [ -- cgit 1.4.1