Skip to content

Commit

Permalink
client: support not(manual-lifetime) mode after all…
Browse files Browse the repository at this point in the history
  • Loading branch information
nagisa committed Jan 14, 2024
1 parent 20b608c commit 5d73d3b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 7 deletions.
2 changes: 2 additions & 0 deletions tracing-tracy/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ only-localhost = ["client/only-localhost"]
sampling = ["client/sampling"]
system-tracing = ["client/system-tracing"]
callstack-inlines = ["client/callstack-inlines"]
manual-lifetime = ["client/manual-lifetime"]
delayed-init = ["client/delayed-init"]

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "tracing_tracy_docs"]
3 changes: 2 additions & 1 deletion tracy-client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ path = "../tracy-client-sys"
package = "tracy-client-sys"
version = ">=0.21.2, <0.23.0" # AUTO-UPDATE
default-features = false
features = ["manual-lifetime", "delayed-init"]

[target.'cfg(loom)'.dependencies.loom]
version = "0.7"
Expand All @@ -60,6 +59,8 @@ only-localhost = ["sys/only-localhost"]
sampling = ["sys/sampling"]
system-tracing = ["sys/system-tracing"]
callstack-inlines = ["sys/callstack-inlines"]
manual-lifetime = ["sys/manual-lifetime"]
delayed-init = ["sys/delayed-init"]

[package.metadata.docs.rs]
rustdoc-args = ["--cfg", "tracy_client_docs"]
20 changes: 14 additions & 6 deletions tracy-client/src/state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,10 @@ impl Client {
/// The underlying client implementation will be started up only if it wasn't already running
/// yet.
///
/// Note that there currently isn't a mechanism to stop the client once it has been started.
/// Note that when the `manual-lifetimes` feature is used, it is a responsibility of the user
/// to stop `tracy` using the [`sys::___tracy_shutdown_profiler`] function. Keep in mind that
/// at the time this function is called there can be no other invocations to the tracy
/// profiler, even from other threads (or you may get a crash!)
///
/// # Example
///
Expand All @@ -75,7 +78,7 @@ impl Client {
/// // }
/// ```
pub fn start() -> Self {
#[cfg(feature = "enable")]
#[cfg(all(feature = "enable", feature = "manual-lifetime"))]
{
let mut old_state = CLIENT_STATE.load(Ordering::Relaxed);
loop {
Expand Down Expand Up @@ -120,7 +123,7 @@ impl Client {
}
}
}
#[cfg(not(feature = "enable"))]
#[cfg(not(all(feature = "enable", feature = "manual-lifetime")))]
Client(())
}

Expand All @@ -136,10 +139,15 @@ impl Client {

/// Is the client already running?
pub fn is_running() -> bool {
#[cfg(feature = "enable")]
return CLIENT_STATE.load(Ordering::Relaxed) == STATE_ENABLED;
#![allow(unreachable_code)]
#[cfg(not(feature = "enable"))]
return true;
return true; // If the client is disabled, produce a "no-op" one so that users don’t need
// to wory about conditional use of the instrumentation in their own code.
#[cfg(not(feature = "manual-lifetime"))]
return true; // The client is started in life-before-main (or upon first use in case of
// `delayed-init`
#[cfg(not(feature = "manual-lifetime"))]
return CLIENT_STATE.load(Ordering::Relaxed) == STATE_ENABLED;
}
}

Expand Down

0 comments on commit 5d73d3b

Please sign in to comment.