mirror of
https://github.com/qemu/qemu.git
synced 2026-02-04 02:24:38 +00:00
rust: add trace crate
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. [Write commit message, add #[allow()]. - Paolo] Signed-off-by: Tanish Desai <tanishdesai37@gmail.com> Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com> Message-ID: <20250929154938.594389-10-pbonzini@redhat.com> Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
This commit is contained in:
committed by
Stefan Hajnoczi
parent
e2e182bef7
commit
54140102d2
4
rust/Cargo.lock
generated
4
rust/Cargo.lock
generated
@@ -258,6 +258,10 @@ dependencies = [
|
||||
"util",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "trace"
|
||||
version = "0.1.0"
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.12"
|
||||
|
||||
@@ -11,6 +11,7 @@ members = [
|
||||
"hw/core",
|
||||
"hw/char/pl011",
|
||||
"hw/timer/hpet",
|
||||
"trace",
|
||||
"util",
|
||||
"tests",
|
||||
]
|
||||
|
||||
@@ -34,7 +34,7 @@ subdir('system')
|
||||
subdir('chardev')
|
||||
subdir('hw/core')
|
||||
subdir('tests')
|
||||
|
||||
subdir('trace')
|
||||
subdir('hw')
|
||||
|
||||
cargo = find_program('cargo', required: false)
|
||||
|
||||
16
rust/trace/Cargo.toml
Normal file
16
rust/trace/Cargo.toml
Normal file
@@ -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
|
||||
19
rust/trace/meson.build
Normal file
19
rust/trace/meson.build
Normal file
@@ -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)
|
||||
35
rust/trace/src/lib.rs
Normal file
35
rust/trace/src/lib.rs
Normal file
@@ -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"));
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -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'),
|
||||
|
||||
Reference in New Issue
Block a user