Skip to content

Commit

Permalink
Upgrade edition and apply clippy fixes
Browse files Browse the repository at this point in the history
Signed-off-by: Alex Saveau <[email protected]>
  • Loading branch information
SUPERCILEX authored and nagisa committed Dec 27, 2023
1 parent 1618816 commit 9af6ee0
Show file tree
Hide file tree
Showing 16 changed files with 64 additions and 58 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ members = [
"tracy-client",
"tracing-tracy",
]
resolver = "2"
2 changes: 1 addition & 1 deletion tracing-tracy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "tracing-tracy"
version = "0.10.4"
authors = ["Simonas Kazlauskas <[email protected]>"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"
readme = "README.mkd"
repository = "https://github.com/nagisa/rust_tracy_client"
homepage = "https://github.com/nagisa/rust_tracy_client"
Expand Down
36 changes: 16 additions & 20 deletions tracing-tracy/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ impl TracyLayer<DefaultFields> {
/// Create a new `TracyLayer`.
///
/// Defaults to collecting stack traces.
#[must_use]
pub fn new() -> Self {
Self {
fmt: DefaultFields::default(),
Expand All @@ -99,12 +100,14 @@ impl<F> TracyLayer<F> {
/// Note that enabling callstack collection can and will introduce a non-trivial overhead at
/// every instrumentation point. Specifying 0 frames (which is the default) will disable stack
/// trace collection.
pub fn with_stackdepth(mut self, stack_depth: u16) -> Self {
#[must_use]
pub const fn with_stackdepth(mut self, stack_depth: u16) -> Self {
self.stack_depth = stack_depth;
self
}

/// Use a custom field formatting implementation.
#[must_use]
pub fn with_formatter<Fmt>(self, fmt: Fmt) -> TracyLayer<Fmt> {
TracyLayer {
fmt,
Expand Down Expand Up @@ -147,9 +150,7 @@ where
F: for<'writer> FormatFields<'writer> + 'static,
{
fn on_new_span(&self, attrs: &Attributes<'_>, id: &Id, ctx: Context<'_, S>) {
let Some(span) = ctx.span(id) else {
return;
};
let Some(span) = ctx.span(id) else { return };

let mut extensions = span.extensions_mut();
if extensions.get_mut::<FormattedFields<F>>().is_none() {
Expand All @@ -161,9 +162,7 @@ where
}

fn on_record(&self, id: &Id, values: &Record<'_>, ctx: Context<'_, S>) {
let Some(span) = ctx.span(id) else {
return;
};
let Some(span) = ctx.span(id) else { return };

let mut extensions = span.extensions_mut();
if let Some(fields) = extensions.get_mut::<FormattedFields<F>>() {
Expand Down Expand Up @@ -200,23 +199,20 @@ where
}

fn on_enter(&self, id: &Id, ctx: Context<S>) {
let Some(span_data) = ctx.span(id) else {
return;
};
let Some(span) = ctx.span(id) else { return };

let metadata = span_data.metadata();
let metadata = span.metadata();
let file = metadata.file().unwrap_or("<not available>");
let line = metadata.line().unwrap_or(0);
let name: Cow<str> =
if let Some(fields) = span_data.extensions().get::<FormattedFields<F>>() {
if fields.fields.is_empty() {
metadata.name().into()
} else {
format!("{}{{{}}}", metadata.name(), fields.fields.as_str()).into()
}
} else {
let name: Cow<str> = if let Some(fields) = span.extensions().get::<FormattedFields<F>>() {
if fields.fields.is_empty() {
metadata.name().into()
};
} else {
format!("{}{{{}}}", metadata.name(), fields.fields.as_str()).into()
}
} else {
metadata.name().into()
};
TRACY_SPAN_STACK.with(|s| {
s.borrow_mut().push_back((
self.client.clone().span_alloc(
Expand Down
8 changes: 4 additions & 4 deletions tracing-tracy/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ fn benchmark_span(c: &mut Criterion) {
bencher.iter(|| {
let _span = tracing::error_span!("message").entered();
});
})
});
});

c.bench_function("span/no_callstack", |bencher| {
Expand All @@ -137,7 +137,7 @@ fn benchmark_span(c: &mut Criterion) {
bencher.iter(|| {
let _span = tracing::error_span!("message").entered();
});
})
});
});
}

Expand All @@ -149,7 +149,7 @@ fn benchmark_message(c: &mut Criterion) {
bencher.iter(|| {
tracing::error!("message");
});
})
});
});

c.bench_function("event/no_callstack", |bencher| {
Expand All @@ -159,7 +159,7 @@ fn benchmark_message(c: &mut Criterion) {
bencher.iter(|| {
tracing::error!("message");
});
})
});
});
}

Expand Down
2 changes: 1 addition & 1 deletion tracy-client-sys/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ version = "0.22.0" # AUTO-BUMP
authors = ["Simonas Kazlauskas <[email protected]>"]
build = "build.rs"
license = "(MIT OR Apache-2.0) AND BSD-3-Clause"
edition = "2018"
edition = "2021"
readme = "README.mkd"
repository = "https://github.com/nagisa/rust_tracy_client"
homepage = "https://github.com/nagisa/rust_tracy_client"
Expand Down
6 changes: 3 additions & 3 deletions tracy-client-sys/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ fn link_dependencies() {
Ok("windows") => println!("cargo:rustc-link-lib=user32"),
Ok(_) => {}
Err(e) => {
writeln!(::std::io::stderr(), "Unable to get target_os=`{}`!", e)
writeln!(::std::io::stderr(), "Unable to get target_os=`{e}`!")
.expect("could not report the error");
::std::process::exit(0xfd);
}
Expand Down Expand Up @@ -84,7 +84,7 @@ fn build_tracy_client() {
fn main() {
if let Ok(lib) = std::env::var("TRACY_CLIENT_LIB") {
if let Ok(lib_path) = std::env::var("TRACY_CLIENT_LIB_PATH") {
println!("cargo:rustc-link-search=native={}", lib_path);
println!("cargo:rustc-link-search=native={lib_path}");
}
let kind = std::env::var_os("TRACY_CLIENT_STATIC");
let mode = if kind.is_none() || kind.as_deref() == Some(std::ffi::OsStr::new("0")) {
Expand All @@ -93,7 +93,7 @@ fn main() {
link_dependencies();
"static"
};
println!("cargo:rustc-link-lib={}={}", mode, lib);
println!("cargo:rustc-link-lib={mode}={lib}");
} else {
build_tracy_client();
}
Expand Down
2 changes: 1 addition & 1 deletion tracy-client-sys/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,5 @@ mod tests {

fn main() {
#[cfg(all(feature = "enable", test))]
tests::main()
tests::main();
}
2 changes: 1 addition & 1 deletion tracy-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name = "tracy-client"
version = "0.16.4" # AUTO-BUMP
authors = ["Simonas Kazlauskas <[email protected]>"]
license = "MIT/Apache-2.0"
edition = "2018"
edition = "2021"
readme = "README.mkd"
repository = "https://github.com/nagisa/rust_tracy_client"
homepage = "https://github.com/nagisa/rust_tracy_client"
Expand Down
2 changes: 1 addition & 1 deletion tracy-client/benches/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ fn client_clone(c: &mut Criterion) {

fn client_running(c: &mut Criterion) {
let _client = Client::start();
c.bench_function("running", |b| b.iter(|| Client::running()));
c.bench_function("running", |b| b.iter(Client::running));
}

fn ops_alloc(c: &mut Criterion) {
Expand Down
2 changes: 2 additions & 0 deletions tracy-client/src/frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ impl FrameName {
///
/// The resulting value may be used as an argument for the the [`Client::secondary_frame_mark`]
/// and [`Client::non_continuous_frame`] methods.
#[must_use]
pub fn new_leak(name: String) -> Self {
#[cfg(feature = "enable")]
{
Expand Down Expand Up @@ -104,6 +105,7 @@ impl Client {
/// .expect("client must be running")
/// .non_continuous_frame(frame_name!("a frame"));
/// ```
#[must_use]
pub fn non_continuous_frame(&self, name: FrameName) -> Frame {
#[cfg(feature = "enable")]
unsafe {
Expand Down
24 changes: 12 additions & 12 deletions tracy-client/src/gpu.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,10 +155,10 @@ impl std::error::Error for GpuSpanCreationError {}
impl Client {
/// Creates a new GPU context.
///
/// - 'name' is the name of the context.
/// - 'ty' is the type (backend) of the context.
/// - 'gpu_timestamp' is the gpu side timestamp the corresponds (as close as possible) to this call.
/// - 'period' is the period of the gpu clock in nanoseconds (setting 1.0 means the clock is 1GHz, 1000.0 means 1MHz, etc).
/// - `name` is the name of the context.
/// - `ty` is the type (backend) of the context.
/// - `gpu_timestamp` is the gpu side timestamp the corresponds (as close as possible) to this call.
/// - `period` is the period of the gpu clock in nanoseconds (setting 1.0 means the clock is 1GHz, 1000.0 means 1MHz, etc).
///
/// See the [type level documentation](GpuContext) for more information.
///
Expand Down Expand Up @@ -194,7 +194,7 @@ impl Client {
context,
flags: 0,
type_: ty as u8,
})
});
};

if let Some(name) = name {
Expand All @@ -208,7 +208,7 @@ impl Client {
name: name.as_ptr().cast(),
len: name.len().try_into().unwrap_or(u16::MAX),
},
)
);
}
}

Expand Down Expand Up @@ -258,10 +258,10 @@ impl GpuContext {
// always be smaller than u64, so no data will be lost.
unsafe {
sys::___tracy_emit_gpu_zone_begin_serial(sys::___tracy_gpu_zone_begin_data {
srcloc: (&span_location.data) as *const _ as usize as u64,
srcloc: std::ptr::addr_of!(span_location.data) as usize as u64,
queryId: start_query_id,
context: self.value,
})
});
};

Ok(GpuSpan {
Expand Down Expand Up @@ -312,7 +312,7 @@ impl GpuContext {
srcloc,
queryId: start_query_id,
context: self.value,
})
});
};

Ok(GpuSpan {
Expand Down Expand Up @@ -345,7 +345,7 @@ impl GpuSpan {
sys::___tracy_emit_gpu_zone_end_serial(sys::___tracy_gpu_zone_end_data {
queryId: self.end_query_id,
context: self.context.value,
})
});
};
self.state = GpuSpanState::Ended;
}
Expand All @@ -370,15 +370,15 @@ impl GpuSpan {
gpuTime: start_timestamp,
queryId: self.start_query_id,
context: self.context.value,
})
});
};

unsafe {
sys::___tracy_emit_gpu_time_serial(sys::___tracy_gpu_time_data {
gpuTime: end_timestamp,
queryId: self.end_query_id,
context: self.context.value,
})
});
};

// Put the ids back into the freelist.
Expand Down
11 changes: 7 additions & 4 deletions tracy-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ pub mod internal {
pub use std::ptr::null;

#[inline(always)]
#[must_use]
pub fn make_span_location(
type_name: &'static str,
span_name: *const u8,
Expand All @@ -77,11 +78,13 @@ pub mod internal {
}

#[inline(always)]
#[must_use]
pub const unsafe fn create_frame_name(name: &'static str) -> crate::frame::FrameName {
crate::frame::FrameName(name)
}

#[inline(always)]
#[must_use]
pub const unsafe fn create_plot(name: &'static str) -> crate::plot::PlotName {
crate::plot::PlotName(name)
}
Expand All @@ -91,7 +94,7 @@ pub mod internal {
pub unsafe fn set_thread_name(name: *const u8) {
#[cfg(feature = "enable")]
unsafe {
sys::___tracy_set_thread_name(name.cast())
sys::___tracy_set_thread_name(name.cast());
}
}
}
Expand Down Expand Up @@ -127,7 +130,7 @@ impl Client {
#[cfg(feature = "enable")]
unsafe {
let stack_depth = adjust_stack_depth(callstack_depth).into();
sys::___tracy_emit_message(message.as_ptr().cast(), message.len(), stack_depth)
sys::___tracy_emit_message(message.as_ptr().cast(), message.len(), stack_depth);
}
}

Expand All @@ -143,7 +146,7 @@ impl Client {
#[cfg(feature = "enable")]
unsafe {
let depth = adjust_stack_depth(callstack_depth).into();
sys::___tracy_emit_messageC(message.as_ptr().cast(), message.len(), rgba >> 8, depth)
sys::___tracy_emit_messageC(message.as_ptr().cast(), message.len(), rgba >> 8, depth);
}
}
}
Expand Down Expand Up @@ -250,7 +253,7 @@ unsafe impl<T: alloc::GlobalAlloc> alloc::GlobalAlloc for ProfiledAllocator<T> {
self.emit_free(ptr);
unsafe {
// SAFE: all invariants satisfied by the caller.
self.0.dealloc(ptr, layout)
self.0.dealloc(ptr, layout);
}
}

Expand Down
1 change: 1 addition & 0 deletions tracy-client/src/plot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ impl PlotName {
///
/// The resulting value may be used as an argument for the the [`Client::secondary_frame_mark`]
/// and [`Client::non_continuous_frame`] methods.
#[must_use]
pub fn new_leak(name: String) -> Self {
#[cfg(feature = "enable")]
{
Expand Down
4 changes: 3 additions & 1 deletion tracy-client/src/span.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ impl Client {
/// } // _span ends
/// ```
#[inline]
#[must_use]
pub fn span(self, loc: &'static SpanLocation, callstack_depth: u16) -> Span {
#[cfg(feature = "enable")]
unsafe {
Expand Down Expand Up @@ -104,6 +105,7 @@ impl Client {
/// } // _span ends
/// ```
#[inline]
#[must_use]
pub fn span_alloc(
self,
name: Option<&str>,
Expand All @@ -120,7 +122,7 @@ impl Client {
file.len(),
function.as_ptr().cast(),
function.len(),
name.map(|n| n.as_ptr().cast()).unwrap_or(std::ptr::null()),
name.map_or(std::ptr::null(), |n| n.as_ptr().cast()),
name.unwrap_or("").len(),
);
let zone = if callstack_depth == 0 {
Expand Down
Loading

0 comments on commit 9af6ee0

Please sign in to comment.