Skip to content

Add span! macro #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions tracy-client/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,27 @@ use std::alloc;
use std::ffi::CString;
use tracy_client_sys as sys;

/// Start a new Tracy span with function, file, and line determined automatically.
#[macro_export]
macro_rules! span {
($name:expr, $callstack_depth:expr) => {{
fn f() {}
fn type_name_of<T>(_: T) -> &'static str {
std::any::type_name::<T>()
}
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

From what I can tell this can be simplified to a

struct S; 
let func_name = std::any::type_name::<S>();
let function = &func_name[..func_name.len() - 3];

let func_name = type_name_of(f);
let function = &func_name[..func_name.len() - 3];

tracy_client::Span::new(
$name,
function,
file!(),
line!(),
$callstack_depth,
)
}};
}

/// A handle representing a span of execution.
#[cfg(feature="enable")]
pub struct Span(
Expand Down