Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: nagisa/rust_tracy_client
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: tracy-client-v0.17.6
Choose a base ref
...
head repository: nagisa/rust_tracy_client
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: tracy-client-v0.18.0
Choose a head ref
  • 2 commits
  • 5 files changed
  • 2 contributors

Commits on Dec 25, 2024

  1. Allow GPU timestamps to be emitted in monotonically-increasing order, as

    Tracy requires.
    
    Tracy gets confused if you emit GPU timestamps in anything other than
    monotonically-increasing order. For example, nested spans *outer* and
    *inner*, you must supply the timestamps in this order: (1) *outer*
    start; (2) *inner* start; (3) *inner* end; (4) *outer* end. Following
    this restriction for nested spans isn't possible with the current API,
    because it requires the client to supply the start and end timestamps at
    the same time. So I changed the API to supply the start and end
    timestamps separately and documented Tracy's restriction.
    pcwalton authored and nagisa committed Dec 25, 2024

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    97395f7 View commit details
  2. tracy-client: 0.18.0

    nagisa committed Dec 25, 2024
    Copy the full SHA
    3369d33 View commit details
Showing with 45 additions and 49 deletions.
  1. +1 −0 README.mkd
  2. +3 −3 tracing-tracy/Cargo.toml
  3. +1 −1 tracy-client/Cargo.toml
  4. +36 −43 tracy-client/src/gpu.rs
  5. +4 −2 tracy-client/tests/tests.rs
1 change: 1 addition & 0 deletions README.mkd
Original file line number Diff line number Diff line change
@@ -56,4 +56,5 @@ The following table lists the version correspondence between the libraries.
| v0.10 | 0.22.0 | 0.17.0 | 0.11.0 |
| v0.11.0 | 0.23.0 | 0.17.1 | 0.11.1 |
| v0.11.1 | 0.24.0 | 0.17.3 | 0.11.2 |
| v0.11.1 | 0.24.3 | 0.18.0 | 0.11.4 |
<!-- AUTO-UPDATE -->
6 changes: 3 additions & 3 deletions tracing-tracy/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracing-tracy"
version = "0.11.3"
version = "0.11.4"
authors = ["Simonas Kazlauskas <tracing-tracy@kazlauskas.me>"]
license.workspace = true
edition.workspace = true
@@ -20,7 +20,7 @@ bench = true
[dependencies]
tracing-core = { version = "0.1", default-features = false, features = ["std"] }
tracing-subscriber = { version = "0.3", default-features = false, features = ["fmt", "registry"] }
client = { package = "tracy-client", path = "../tracy-client", version = "0.17.0", default-features = false }
client = { package = "tracy-client", path = "../tracy-client", version = ">=0.17.0,<0.19.0", default-features = false }

[dev-dependencies]
tracing = { version = "0.1", default-features = false, features = ["std"] }
@@ -58,5 +58,5 @@ rustdoc-args = ["--cfg", "tracing_tracy_docs"]
all-features = true

[lints.rust.unexpected_cfgs]
level = "warn"
level = "warn"
check-cfg = ['cfg(tracing_tracy_docs)']
2 changes: 1 addition & 1 deletion tracy-client/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "tracy-client"
version = "0.17.6" # AUTO-BUMP
version = "0.18.0" # AUTO-BUMP
authors = ["Simonas Kazlauskas <tracy-client@kazlauskas.me>"]
license.workspace = true
edition.workspace = true
79 changes: 36 additions & 43 deletions tracy-client/src/gpu.rs
Original file line number Diff line number Diff line change
@@ -66,8 +66,8 @@ pub enum GpuContextType {
/// // Some time later, once the written timestamp values are available on the cpu.
/// # let (starting_timestamp, ending_timestamp) = (0, 0);
///
/// // Consumes span.
/// span.upload_timestamp(starting_timestamp, ending_timestamp);
/// span.upload_timestamp_start(starting_timestamp);
/// span.upload_timestamp_end(ending_timestamp);
/// ```
#[derive(Clone)]
pub struct GpuContext {
@@ -76,8 +76,6 @@ pub struct GpuContext {
#[cfg(feature = "enable")]
value: u8,
#[cfg(feature = "enable")]
gpu_start_timestamp: i64,
#[cfg(feature = "enable")]
span_freelist: Arc<Mutex<Vec<u16>>>,
_private: (),
}
@@ -106,10 +104,9 @@ impl std::error::Error for GpuContextCreationError {}
enum GpuSpanState {
/// The span has been started. All gpu spans start in this state.
Started,
/// The span has been ended, waiting for timestamp upload.
/// The span has been ended, either waiting for timestamp upload or with
/// timestamp upload completed.
Ended,
/// All timestamps have been uploaded.
Uploaded,
}

/// Span for timing gpu work.
@@ -215,7 +212,6 @@ impl Client {
Ok(GpuContext {
_client: self,
value: context,
gpu_start_timestamp: gpu_timestamp,
span_freelist: Arc::new(Mutex::new((0..=u16::MAX).collect())),
_private: (),
})
@@ -352,64 +348,61 @@ impl GpuSpan {
}
}

/// Uploads the gpu timestamps associated with the span start and end to tracy,
/// closing out the span.
pub fn upload_timestamp(mut self, start_timestamp: i64, end_timestamp: i64) {
/// Supplies the GPU timestamp for the start of this span.
///
/// In order to avoid confusing Tracy, you must call
/// [`Self::upload_timestamp_start`] and [`Self::upload_timestamp_end`] in
/// monotonically increasing timestamp order. For example, if you have two
/// nested spans *outer* and *inner*, you must supply the timestamps in
/// this order: (1) *outer* start; (2) *inner* start; (3) *inner* end; (4)
/// *outer* end.
pub fn upload_timestamp_start(&self, start_timestamp: i64) {
#[cfg(feature = "enable")]
self.upload_timestamp_impl(start_timestamp, end_timestamp);
}

#[cfg(feature = "enable")]
fn upload_timestamp_impl(&mut self, start_timestamp: i64, end_timestamp: i64) {
assert_eq!(
self.state,
GpuSpanState::Ended,
"You must call end_zone before uploading timestamps."
);
unsafe {
sys::___tracy_emit_gpu_time_serial(sys::___tracy_gpu_time_data {
gpuTime: start_timestamp,
queryId: self.start_query_id,
context: self.context.value,
});
};
}

/// Supplies the GPU timestamp for the end of this span.
///
/// In order to avoid confusing Tracy, you must call
/// [`Self::upload_timestamp_start`] and [`Self::upload_timestamp_end`] in
/// monotonically increasing timestamp order. For example, if you have two
/// nested spans *outer* and *inner*, you must supply the timestamps in this
/// order: (1) *outer* start; (2) *inner* start; (3) *inner* end; (4)
/// *outer* end.
pub fn upload_timestamp_end(&self, end_timestamp: i64) {
#[cfg(feature = "enable")]
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.
let mut freelist = self.context.span_freelist.lock().unwrap();
freelist.push(self.start_query_id);
freelist.push(self.end_query_id);
drop(freelist);

self.state = GpuSpanState::Uploaded;
}
}

impl Drop for GpuSpan {
fn drop(&mut self) {
#[cfg(feature = "enable")]
match self.state {
GpuSpanState::Started => {
self.end_zone();
self.upload_timestamp_impl(
self.context.gpu_start_timestamp,
self.context.gpu_start_timestamp,
);
}
GpuSpanState::Ended => {
self.upload_timestamp_impl(
self.context.gpu_start_timestamp,
self.context.gpu_start_timestamp,
);
{
match self.state {
GpuSpanState::Started => {
self.end_zone();
}
GpuSpanState::Ended => {}
}
GpuSpanState::Uploaded => {}

// Put the ids back into the freelist.
let mut freelist = self.context.span_freelist.lock().unwrap();
freelist.push(self.start_query_id);
freelist.push(self.end_query_id);
drop(freelist);
}
}
}
6 changes: 4 additions & 2 deletions tracy-client/tests/tests.rs
Original file line number Diff line number Diff line change
@@ -126,8 +126,10 @@ fn gpu() {
span2.end_zone();

// Some time later, when the timestamps are back
span1.upload_timestamp(100_000, 110_000);
span2.upload_timestamp(120_000, 130_000);
span1.upload_timestamp_start(100_000);
span1.upload_timestamp_end(110_000);
span2.upload_timestamp_start(120_000);
span2.upload_timestamp_end(130_000);
}

fn main() {