pub struct Client(_);
Expand description

A type representing an enabled Tracy client.

Obtaining a Client is required in order to instrument the application.

Multiple copies of a Client may be live at once. As long as at least one Client value lives, the Tracy client is enabled globally. In addition to collecting information through the instrumentation inserted by you, the Tracy client may automatically collect information about execution of the program while it is enabled. All this information may be stored in memory until a profiler application connects to the client to read the data.

Depending on the build configuration, the client may collect and make available machine and source code of the application as well as other potentially sensitive information.

When all of the Client values are dropped, the underlying Tracy client will be shut down as well. Shutting down the Client will discard any information gathered up to that point that still hasn’t been delivered to the profiler application.

Implementations

Instrumentation for global frame indicators.

Indicate that rendering of a continuous frame has ended.

Examples

In a traditional rendering scenarios a frame mark should be inserted after a buffer swap.

use tracy_client::Client;
// loop {
//     ...
       swap_buffers();
       Client::running().expect("client must be running").frame_mark();
// }

Indicate that rendering of a secondary (named) continuous frame has ended.

Examples

Much like with the primary frame mark, the secondary (named) frame mark should be inserted after some continuously repeating operation finishes one iteration of its processing.

use tracy_client::frame_name;
// loop {
//     ...
       physics_tick();
       tracy_client::Client::running()
           .expect("client must be running")
           .secondary_frame_mark(frame_name!("physics"));
// }

Indicate that a processing of a non-continuous frame has begun.

Dropping the returned Frame will terminate the non-continuous frame.

Examples
use tracy_client::frame_name;
tracy_client::Client::running()
    .expect("client must be running")
    .non_continuous_frame(frame_name!("a frame"));

Instrumentation for drawing 2D plots.

Add a point with an y-axis value of value to the plot named plot_name.

Examples
tracy_client::Client::running()
    .expect("client must be running")
    .plot(tracy_client::plot_name!("temperature"), 37.0);

Instrumentation for timed regions, spans or zones of execution.

Start a new Tracy span/zone.

In order to obtain a SpanLocation value to provide to this function use the span_location! macro.

Specifying a non-zero callstack_depth will enable collection of callstack for this message. The number provided will limit the number of call frames collected. Note that enabling callstack collection introduces a non-trivial amount of overhead to this call. On some systems this value may be clamped to a maximum value supported by the target.

The span! macro is a convenience wrapper over this method.

Example

In the following example the span is created with the location at which the span_location! macro appears and will measure the execution of the 100ms long sleep.

use tracy_client::{Client, span_location};
let client = Client::start();
{
    let _span = client.span(span_location!("sleeping"), 100);
    std::thread::sleep(std::time::Duration::from_millis(100));
} // _span ends

Start a new Tracy span/zone.

This function allocates the span information on the heap until it is read out by the profiler. Prefer the Client::span as a allocation-free and faster alternative when possible.

Specifying a non-zero callstack_depth will enable collection of callstack for this message. The number provided will limit the number of call frames collected. Note that enabling callstack collection introduces a non-trivial amount of overhead to this call. On some systems this value may be clamped to a maximum value supported by the target.

Example

In the following example the span is created with custom span source data and will measure the execution of the 100ms long sleep.

use tracy_client::Client;
let client = Client::start();
{
    let _span = client.span_alloc("hello", "my_function", "hello.rs", 42, 100);
    std::thread::sleep(std::time::Duration::from_millis(100));
} // _span ends

Client initialization and lifetime management.

Start the client.

The client must be started with this function before any instrumentation is invoked anywhere in the process. This function can be called multiple times to obtain multiple Client values.

The underying 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.

Example
// fn main() {
    let _client = tracy_client::Client::start();
    // ...
// }

Obtain a client handle, but only if the client is already running.

Is the client already running?

Instrumentation methods for outputting events occurring at a specific instant.

Data provided by this instrumentation can largely be considered to be equivalent to logs.

Output a message.

Specifying a non-zero callstack_depth will enable collection of callstack for this message. The number provided will limit the number of call frames collected. Note that enabling callstack collection introduces a non-trivial amount of overhead to this call.

Output a message with an associated color.

Specifying a non-zero callstack_depth will enable collection of callstack for this message. The number provided will limit the number of call frames collected. Note that enabling callstack collection introduces a non-trivial amount of overhead to this call.

The colour shall be provided as RGBA, where the least significant 8 bits represent the alpha component and most significant 8 bits represent the red component.

Set the current thread name to the provided value.

Panics

This function will panic if the name contains interior null characters.

Trait Implementations

A cheaper alternative to Client::start or Client::running when there is already a handle handy.

Performs copy-assignment from source. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.