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 09/16] rust: add trace crate
Date: Mon, 29 Sep 2025 17:49:31 +0200 [thread overview]
Message-ID: <20250929154938.594389-10-pbonzini@redhat.com> (raw)
In-Reply-To: <20250929154938.594389-1-pbonzini@redhat.com>
From: Tanish Desai <tanishdesai37@gmail.com>
The trace crate is a minimal container for dependencies of tracepoints
(so that they do not have to be imported in all the crates that use
tracepoints); it also contains a macro called "include_trace!" that is
able to find the right include file from the trace/ directory.
Signed-off-by: Tanish Desai <tanishdesai37@gmail.com>
[Write commit message, add #[allow()]. - Paolo]
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>
---
rust/Cargo.lock | 4 ++++
rust/Cargo.toml | 1 +
rust/meson.build | 2 +-
rust/trace/Cargo.toml | 16 ++++++++++++++++
rust/trace/meson.build | 19 +++++++++++++++++++
rust/trace/src/lib.rs | 35 +++++++++++++++++++++++++++++++++++
trace/meson.build | 8 +++++++-
7 files changed, 83 insertions(+), 2 deletions(-)
create mode 100644 rust/trace/Cargo.toml
create mode 100644 rust/trace/meson.build
create mode 100644 rust/trace/src/lib.rs
diff --git a/rust/Cargo.lock b/rust/Cargo.lock
index 8315f98c46f..3428dbaf0b3 100644
--- a/rust/Cargo.lock
+++ b/rust/Cargo.lock
@@ -258,6 +258,10 @@ dependencies = [
"util",
]
+[[package]]
+name = "trace"
+version = "0.1.0"
+
[[package]]
name = "unicode-ident"
version = "1.0.12"
diff --git a/rust/Cargo.toml b/rust/Cargo.toml
index d8183c614d4..f372d7dbf70 100644
--- a/rust/Cargo.toml
+++ b/rust/Cargo.toml
@@ -11,6 +11,7 @@ members = [
"hw/core",
"hw/char/pl011",
"hw/timer/hpet",
+ "trace",
"util",
"tests",
]
diff --git a/rust/meson.build b/rust/meson.build
index b3ac3a71970..695d5a62de9 100644
--- a/rust/meson.build
+++ b/rust/meson.build
@@ -34,7 +34,7 @@ subdir('system')
subdir('chardev')
subdir('hw/core')
subdir('tests')
-
+subdir('trace')
subdir('hw')
cargo = find_program('cargo', required: false)
diff --git a/rust/trace/Cargo.toml b/rust/trace/Cargo.toml
new file mode 100644
index 00000000000..13ac0b33d6f
--- /dev/null
+++ b/rust/trace/Cargo.toml
@@ -0,0 +1,16 @@
+[package]
+name = "trace"
+version = "0.1.0"
+authors = ["Tanish Desai <tanishdesai37@gmail.com>"]
+description = "QEMU tracing infrastructure support"
+resolver = "2"
+publish = false
+
+edition.workspace = true
+homepage.workspace = true
+license.workspace = true
+repository.workspace = true
+rust-version.workspace = true
+
+[lints]
+workspace = true
diff --git a/rust/trace/meson.build b/rust/trace/meson.build
new file mode 100644
index 00000000000..adca57e5507
--- /dev/null
+++ b/rust/trace/meson.build
@@ -0,0 +1,19 @@
+rust = import('rust')
+
+lib_rs = configure_file(
+ input: 'src/lib.rs',
+ output: 'lib.rs',
+ configuration: {
+ 'MESON_BUILD_ROOT': meson.project_build_root(),
+ })
+
+_trace_rs = static_library(
+ 'trace', # Library name,
+ lib_rs,
+ trace_rs_targets, # List of generated `.rs` custom targets
+ override_options: ['rust_std=2021', 'build.rust_std=2021'],
+ dependencies: [libc_rs],
+ rust_abi: 'rust',
+)
+
+trace_rs = declare_dependency(link_with: _trace_rs)
diff --git a/rust/trace/src/lib.rs b/rust/trace/src/lib.rs
new file mode 100644
index 00000000000..0955461573d
--- /dev/null
+++ b/rust/trace/src/lib.rs
@@ -0,0 +1,35 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
+
+//! This crate provides macros that aid in using QEMU's tracepoint
+//! functionality.
+
+#[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`.
+///
+/// ```ignore
+/// ::trace::include_trace!("hw_char");
+/// // ...
+/// trace::trace_pl011_read_fifo_rx_full();
+/// ```
+macro_rules! include_trace {
+ ($name:literal) => {
+ #[allow(
+ clippy::ptr_as_ptr,
+ clippy::cast_lossless,
+ clippy::used_underscore_binding
+ )]
+ mod trace {
+ #[cfg(not(MESON))]
+ include!(concat!(
+ env!("MESON_BUILD_ROOT"),
+ "/trace/trace-",
+ $name,
+ ".rs"
+ ));
+
+ #[cfg(MESON)]
+ include!(concat!("@MESON_BUILD_ROOT@/trace/trace-", $name, ".rs"));
+ }
+ };
+}
diff --git a/trace/meson.build b/trace/meson.build
index 9c42a57a053..d89a0db82a1 100644
--- a/trace/meson.build
+++ b/trace/meson.build
@@ -1,5 +1,5 @@
system_ss.add(files('control-target.c', 'trace-hmp-cmds.c'))
-
+trace_rs_targets = []
trace_events_files = []
foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
if item in qapi_trace_events
@@ -24,6 +24,11 @@ foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
input: trace_events_file,
command: [ tracetool, group, '--format=c', '@INPUT@', '@OUTPUT@' ],
depend_files: tracetool_depends)
+ trace_rs = custom_target(fmt.format('trace', 'rs'),
+ output: fmt.format('trace', 'rs'),
+ input: trace_events_file,
+ command: [ tracetool, group, '--format=rs', '@INPUT@', '@OUTPUT@' ],
+ depend_files: tracetool_depends)
if 'ust' in get_option('trace_backends')
trace_ust_h = custom_target(fmt.format('trace-ust', 'h'),
output: fmt.format('trace-ust', 'h'),
@@ -34,6 +39,7 @@ foreach item : [ '.' ] + trace_events_subdirs + qapi_trace_events
genh += trace_ust_h
endif
trace_ss.add(trace_h, trace_c)
+ trace_rs_targets += trace_rs
if 'dtrace' in get_option('trace_backends')
trace_dtrace = custom_target(fmt.format('trace-dtrace', 'dtrace'),
output: fmt.format('trace-dtrace', 'dtrace'),
--
2.51.0
next prev parent reply other threads:[~2025-09-29 15:56 UTC|newest]
Thread overview: 20+ 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 ` [PATCH 06/16] tracetool: add CHECK_TRACE_EVENT_GET_STATE Paolo Bonzini
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 ` Paolo Bonzini [this message]
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 09/16] rust: add trace crate Paolo Bonzini
2025-09-23 19:29 ` Stefan Hajnoczi
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-10-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).