### Setup GPU Profiling Context with wgpu Source: https://context7.com/sparkypotato/tracy_full/llms.txt Initializes a `ProfileContext` for GPU profiling. Requires the `wgpu` feature and `Features::TIMESTAMP_QUERY`. Specify the number of frames in flight and a resync interval to prevent clock drift. ```rust use std::time::Duration; use tracy::wgpu::ProfileContext; use tracy::{wgpu_command_encoder, wgpu_render_pass, wgpu_compute_pass}; fn setup(adapter: &wgpu::Adapter, device: &wgpu::Device, queue: &wgpu::Queue) -> ProfileContext { ProfileContext::with_name( "MainGPU", adapter, device, queue, 3, // buffer 3 frames in flight Duration::from_secs(4), // resync interval to prevent clock drift ) } ``` -------------------------------- ### Zone Marking Examples Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Examples of using the `zone!` macro to profile code blocks with different options for name, color, and runtime enabling. ```rust use tracy::zone; zone!(); // Zone with no name zone!("MyZone"); // Zone with name "MyZone" zone!(tracy::color::RED); // Zone with color red zone!("MyZone", true); // Zone with name "MyZone", and enabled with a runtime expression. zone!(tracy::color::RED, true); // Zone with color red, and enabled with a runtime expression. zone!("MyZone", tracy::color::RED, true); // Zone with name "MyZone", color red, and enabled with a runtime expression. ``` -------------------------------- ### Example of Sub-Frame Marking in a Loop Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Demonstrates marking input gathering, processing, and rendering as sub-frames within a main loop. ```rust loop { // Gather input frame!("Input"); // Process input frame!("Processing"); // Render frame!("Render"); swapchain.present(); frame!(); } ``` -------------------------------- ### Create WGPU Profile Context Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Initializes a `ProfileContext` for profiling wgpu operations. Requires careful synchronization of host and device. ```rust use tracy::wgpu::ProfileContext; let mut profile_context = ProfileContext::with_name("Name", &adapter, &device, &queue, buffered_frames); ``` -------------------------------- ### Manual Tracy Profiler Initialization and Teardown Source: https://context7.com/sparkypotato/tracy_full/llms.txt Manually initializes and tears down the Tracy profiler when the `manual-init` feature is enabled. `startup_tracy` must be called before any other Tracy API, and `shutdown_tracy` after all usage has stopped. Both functions are unsafe. ```rust fn main() { // Must be called before any other Tracy API unsafe { tracy::startup_tracy(); } run_application(); // Must be called after all Tracy API usage has stopped unsafe { tracy::shutdown_tracy(); } } ``` -------------------------------- ### Add tracy_full to Cargo.toml Source: https://context7.com/sparkypotato/tracy_full/llms.txt Add `tracy_full` to your `Cargo.toml` and enable the `enable` feature for profiling builds. Optional integrations can also be included. ```toml [dependencies.tracy] package = "tracy_full" version = "1.13.0" # Enable data capture. Omit for zero-overhead no-op builds. features = ["enable"] # Optional integrations: # features = ["enable", "futures", "tracing", "bevy", "wgpu"] ``` -------------------------------- ### Profile Bevy Systems with Tracy Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Integrates Tracy profiling into Bevy applications by wrapping systems with `tracy::bevy::timeline`. ```rust use tracy::bevy::timeline; App::new().add_system(timeline(my_system)).run(); ``` -------------------------------- ### Create Profiled WGPU Command Encoder and Passes Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Uses macros to create a profiled command encoder and subsequently profiled render or compute passes. ```rust use tracy::{wgpu_command_encoder, wgpu_render_pass, wgpu_compute_pass}; let mut command_encoder = wgpu_command_encoder!(device, profile_context, desc); { let render_pass = wgpu_render_pass!(command_encoder, desc) } { let compute_pass = wgpu_compute_pass!(command_encoder, desc) } ``` -------------------------------- ### Integrate Tracy with Tracing Subscriber Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Sets up the global tracing subscriber to include the TracyLayer for profiling. ```rust use tracy::tracing::TracyLayer; tracing::subscriber::set_global_default( tracing_subscriber::registry().with(TracyLayer) ); ``` -------------------------------- ### Enable WGPU Feature for Tracy Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Enable the 'wgpu' feature in Cargo.toml to profile wgpu command encoders and passes. ```toml [dependencies.tracy] ... features = ["enable", "wgpu"] ``` -------------------------------- ### zone_sample! Source: https://context7.com/sparkypotato/tracy_full/llms.txt Like `zone!`, but also captures a callstack snapshot of the given depth on zone entry, useful for identifying call-site origins. ```APIDOC ## zone_sample! ### Description Profiles the enclosing scope as a named zone in the Tracy timeline and captures a callstack snapshot on zone entry. ### Macro Usage `zone_sample!([name: string], [depth: u32], [enabled: bool])` ### Parameters #### Optional Parameters - **name** (string) - Optional - The name of the zone. - **depth** (u32) - Optional - The maximum depth of the callstack to capture (clamped to 62). - **enabled** (bool) - Optional - A boolean flag to conditionally enable the zone at runtime. ### Request Example ```rust use tracy::zone_sample; fn process_assets() { zone_sample!("AssetLoad", 16, true); // ... } ``` ``` -------------------------------- ### End WGPU Frame Profiling Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Call `end_frame` on the `ProfileContext` at the end of each frame to upload profiling data to Tracy. Panics if host and device are not synchronized. ```rust profile_context.end_frame(&device, &queue); ``` -------------------------------- ### Async Future Fiber Tracking with Tracy Source: https://context7.com/sparkypotato/tracy_full/llms.txt Wraps a `Future` so each poll appears as a distinct fiber in the Tracy timeline, making async scheduling visible alongside synchronous CPU work. Requires the `futures` feature. ```toml [dependencies.tracy] features = ["enable", "futures"] ``` ```rust use tracy::trace_future; async fn load_asset(path: &str) -> Vec { tokio::fs::read(path).await.unwrap() } async fn game_loop() { // The future appears as "LoadTerrain" fiber in Tracy let terrain = trace_future!("LoadTerrain", load_asset("terrain.bin")).await; // Multiple concurrent traced futures let (mesh, tex) = tokio::join!( trace_future!("LoadMesh", load_asset("player.mesh")), trace_future!("LoadTexture", load_asset("player.png")), ); } ``` -------------------------------- ### Enable Bevy Feature for Tracy Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Enable the 'bevy' feature in Cargo.toml to profile Bevy systems. ```toml [dependencies.tracy] ... features = ["enable", "bevy"] ``` -------------------------------- ### Add Tracy Dependency to Cargo.toml Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Add the tracy_full package to your Cargo.toml to include the Tracy profiler bindings. ```toml [dependencies.tracy] package = "tracy_full" version = "1.10.0" ``` -------------------------------- ### Track Bevy Systems as Timeline Fibers Source: https://context7.com/sparkypotato/tracy_full/llms.txt Wraps Bevy ECS systems with the `tracy::bevy::timeline` function to display them as distinct fibers in the Tracy timeline. Requires the `bevy` feature. ```rust use bevy::prelude::*; use tracy::bevy::timeline; fn physics_system(mut query: Query<(&mut Transform, &Velocity)>) { for (mut transform, vel) in &mut query { transform.translation += vel.0; } } fn render_system() { /* ... */ } fn main() { App::new() .add_plugins(DefaultPlugins) // Each system gets its own named fiber in Tracy .add_systems(Update, timeline(physics_system)) .add_systems(Update, timeline(render_system)) .run(); } ``` -------------------------------- ### Profile wgpu Command Encoder and Render Pass Source: https://context7.com/sparkypotato/tracy_full/llms.txt Wraps a wgpu command encoder and render pass for GPU profiling. The `wgpu_command_encoder!` macro profiles the entire encoder lifetime, and `wgpu_render_pass!` profiles the render pass. ```rust let mut encoder = wgpu_command_encoder!(device, ctx, &wgpu::CommandEncoderDescriptor { label: Some("Frame"), }); { // Profiled render pass let _rpass = wgpu_render_pass!(encoder, &wgpu::RenderPassDescriptor { label: Some("MainPass"), color_attachments: &[Some(wgpu::RenderPassColorAttachment { view: render_target, resolve_target: None, ops: wgpu::Operations::default(), })], depth_stencil_attachment: None, timestamp_writes: None, occlusion_query_set: None, }); // draw calls... } ``` -------------------------------- ### End GPU Frame and Upload Timings Source: https://context7.com/sparkypotato/tracy_full/llms.txt Completes the command encoder and submits it to the queue. Crucially, `ctx.end_frame` must be called once per frame to upload timing data to Tracy. ```rust queue.submit([encoder.finish()]); // Must be called once per frame to upload timing data to Tracy ctx.end_frame(device, queue); ``` -------------------------------- ### Enable Tracy Profiling Feature Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md To enable profiling for a build, add the 'enable' feature to the tracy dependency in Cargo.toml. ```toml [dependencies.tracy] ... features = ["enable"] ``` -------------------------------- ### Attach Frame Screenshot with tracy::frame_image Source: https://context7.com/sparkypotato/tracy_full/llms.txt Attaches an RGBA pixel buffer as a frame image to the current frame in Tracy, enabling visual thumbnails in the profiler UI. Must be called before (or inside) the associated frame mark. ```rust use tracy::frame::{frame_image, Image, Pixel}; fn capture_frame_thumbnail(pixels: &[u8], w: u16, h: u16) { let rgba: Vec = pixels .chunks_exact(4) .map(|c| Pixel { r: c[0], g: c[1], b: c[2], a: c[3] }) .collect(); frame_image(Image { data: &rgba, width: w, height: h, lag: 0, // 0 = captured same frame flip: false, }); // Must be called before (or inside) the associated frame mark frame!(); } ``` -------------------------------- ### Named Memory Pool Tracking with Tracy (Nightly) Source: https://context7.com/sparkypotato/tracy_full/llms.txt Tracks a specific allocator as a named memory pool in Tracy, enabling per-pool allocation graphs. Requires the `allocator_api` feature (nightly Rust). ```rust #![feature(allocator_api)] use tracy::tracked_allocator; use std::alloc::System; // Named pool, no callstack: let texture_alloc = tracked_allocator!("TexturePool", System); // Named pool with 16-frame callstack sampling: let mesh_alloc = tracked_allocator!("MeshPool", System, 16); // Use with a Vec via the nightly Allocator API: let mut textures: Vec = Vec::new_in(texture_alloc); textures.push(42); ``` -------------------------------- ### Enable Tracing Feature for Tracy Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Enable the 'tracing' feature in Cargo.toml to profile tracing spans. ```toml [dependencies.tracy] ... features = ["enable", "tracing"] ``` -------------------------------- ### Tracing Crate Integration with Tracy Source: https://context7.com/sparkypotato/tracy_full/llms.txt A `tracing_subscriber::Layer` that maps `tracing` spans directly to Tracy zones. Requires the `tracing` feature. ```toml [dependencies.tracy] features = ["enable", "tracing"] ``` ```rust use tracy::tracing::TracyLayer; use tracing::instrument; use tracing_subscriber::{layer::SubscriberExt, Registry}; fn init_tracing() { let subscriber = Registry::default().with(TracyLayer); tracing::subscriber::set_global_default(subscriber) .expect("setting global subscriber failed"); } #[instrument] fn render_scene(scene_id: u32) { // This span appears as a Tracy zone named "render_scene{scene_id=42}" prepare_geometry(scene_id); draw_calls(scene_id); } fn main() { init_tracing(); render_scene(42); } ``` -------------------------------- ### Global Allocation Tracking with Tracy Source: https://context7.com/sparkypotato/tracy_full/llms.txt Wraps the global allocator to record heap allocations and deallocations. `GlobalAllocatorSampled` additionally captures callstacks. ```rust use tracy::alloc::{GlobalAllocator, GlobalAllocatorSampled}; // Basic global tracking (default System allocator): #[global_allocator] static ALLOC: GlobalAllocator = GlobalAllocator::new(); // With callstack sampling (up to 8 frames deep): #[global_allocator] static ALLOC_SAMPLED: GlobalAllocatorSampled = GlobalAllocatorSampled::new(8); // Custom inner allocator: #[global_allocator] static CUSTOM_ALLOC: GlobalAllocator = GlobalAllocator::new_with(MyAllocator::new()); ``` -------------------------------- ### Create and Update a Plot in Tracy Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Instantiates a plotter for a graph named 'MyGraph' and updates its value. ```rust use tracy::plotter; let plotter = plotter!("MyGraph"); plotter.value(1.0); plotter.value(2.0); ``` -------------------------------- ### Zone Profiling with Callstack Sampling Source: https://context7.com/sparkypotato/tracy_full/llms.txt Like `zone!`, but also captures a callstack snapshot of the given depth on zone entry, useful for identifying call-site origins. ```rust use tracy::zone_sample; fn process_assets() { // Capture up to 16 frames of callstack on entry. zone_sample!("AssetLoad", 16, true); load_textures(); load_meshes(); } ``` -------------------------------- ### frame_image Source: https://context7.com/sparkypotato/tracy_full/llms.txt Attaches an RGBA pixel buffer as a frame image to the current frame in Tracy, enabling visual thumbnails in the profiler UI. ```APIDOC ## frame_image ### Description Attaches an RGBA pixel buffer as a frame image to the current frame in Tracy, enabling visual thumbnails in the profiler UI. ### Function Signature `fn frame_image(image: Image)` ### Parameters #### Path Parameters - **image** (Image) - Required - An `Image` struct containing the pixel data and metadata. - **data** (&[Pixel]) - Required - Slice of `Pixel` structs representing the image data. - **width** (u16) - Required - The width of the image. - **height** (u16) - Required - The height of the image. - **lag** (u8) - Optional - The lag in frames (0 = same frame). - **flip** (bool) - Optional - Whether to flip the image vertically. ### Request Example ```rust use tracy::frame::{frame_image, Image, Pixel}; fn capture_frame_thumbnail(pixels: &[u8], w: u16, h: u16) { let rgba: Vec = pixels .chunks_exact(4) .map(|c| Pixel { r: c[0], g: c[1], b: c[2], a: c[3] }) .collect(); frame_image(Image { data: &rgba, width: w, height: h, lag: 0, flip: false, }); } ``` ``` -------------------------------- ### Global Allocator Tracking Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Use the GlobalAllocator to track all memory allocations. For custom allocators, use `new_with`. ```rust #[global_allocator] static ALLOC: tracy::GlobalAllocator = tracy::GlobalAllocator::new(); ``` ```rust #[global_allocator] static ALLOC: tracy::GlobalAllocator = tracy::GlobalAllocator::new_with(MyAlloc::new()); ``` -------------------------------- ### Graph Plotting with Tracy Source: https://context7.com/sparkypotato/tracy_full/llms.txt Creates a named numeric graph in Tracy. Call `.value(f64)` to push data points; Tracy renders them as a time-series plot. ```rust use tracy::plotter; fn update_loop(dt: f32, entity_count: usize, memory_bytes: usize) { let fps_plot = plotter!("FPS"); let entity_plot = plotter!("EntityCount"); let mem_plot = plotter!("MemoryMB"); fps_plot.value(1.0 / dt as f64); entity_plot.value(entity_count as f64); mem_plot.value(memory_bytes as f64 / 1_048_576.0); } ``` -------------------------------- ### Enable Futures Feature for Tracy Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Enable the 'futures' feature in Cargo.toml to represent futures as fibers in Tracy. ```toml [dependencies.tracy] ... features = ["enable", "futures"] ``` -------------------------------- ### Profile wgpu Compute Pass Source: https://context7.com/sparkypotato/tracy_full/llms.txt Profiles a wgpu compute pass using the `wgpu_compute_pass!` macro. This allows tracking the execution time of compute shaders within the Tracy timeline. ```rust let _cpass = wgpu_compute_pass!(encoder, &wgpu::ComputePassDescriptor { label: Some("PostProcess"), timestamp_writes: None, }); // dispatches... ``` -------------------------------- ### Trace Async Function with Futures Feature Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Use the `trace_future!` macro to profile an async function as a fiber in Tracy. ```rust use tracy::future; trace_future!(async_function(), "Async Function").await; ``` -------------------------------- ### Track Custom Allocator with Allocator API Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Creates a memory pool named 'TrackedAllocator' in Tracy when using the 'allocator_api' feature. ```rust let alloc = TrackedAllocator::new(alloc, tracy::c_str!("TrackedAllocator")); ``` -------------------------------- ### CPU Zone Profiling with tracy::zone! Source: https://context7.com/sparkypotato/tracy_full/llms.txt Profiles the enclosing scope as a named zone in the Tracy timeline. The zone is active from macro invocation until the binding drops at end-of-scope. Supports optional name, color, and runtime `enabled` flag. ```rust use tracy::{zone, color}; fn render_frame() { zone!("RenderFrame", color::Color::RED, true); // named, colored, always active { zone!("Geometry"); // name only // geometry work ... } { zone!(color::Color::CYAN); // color only // lighting work ... } { let expensive = should_profile_physics(); zone!("Physics", expensive); // conditionally enabled at runtime // physics work ... } } ``` -------------------------------- ### Mark End of Main Frame Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Use the `frame!` macro to mark the end of the main profiling frame. ```rust use tracy::frame; frame!(); ``` -------------------------------- ### zone! Source: https://context7.com/sparkypotato/tracy_full/llms.txt Profiles the enclosing scope as a named zone in the Tracy timeline. The zone is active from macro invocation until the binding drops at end-of-scope. Supports optional name, color, and runtime `enabled` flag. ```APIDOC ## zone! ### Description Profiles the enclosing scope as a named zone in the Tracy timeline. The zone is active from macro invocation until the binding drops at end-of-scope. Supports optional name, color, and runtime `enabled` flag. ### Macro Usage `zone!([name: string], [color: Color], [enabled: bool])` ### Parameters #### Optional Parameters - **name** (string) - Optional - The name of the zone. - **color** (Color) - Optional - The color of the zone in the timeline. - **enabled** (bool) - Optional - A boolean flag to conditionally enable the zone at runtime. ### Request Example ```rust use tracy::{zone, color}; fn render_frame() { zone!("RenderFrame", color::Color::RED, true); zone!("Geometry"); zone!(color::Color::CYAN); let expensive = should_profile_physics(); zone!("Physics", expensive); } ``` ``` -------------------------------- ### frame! Source: https://context7.com/sparkypotato/tracy_full/llms.txt Signals frame boundaries to Tracy. Supports main continuous frame end, named sub-frame end, and scoped discontinuous frame. ```APIDOC ## frame! ### Description Signals frame boundaries to Tracy. Can be used for main continuous frame end, named sub-frame end, or scoped discontinuous frames. ### Macro Usage `frame!()` or `frame!([name: string])` or `frame!(discontinuous [name: string])` ### Parameters #### Optional Parameters - **name** (string) - Optional - The name of the frame or sub-frame. - **discontinuous** - Keyword to indicate a discontinuous frame. ### Request Example ```rust use tracy::frame; fn game_loop() { frame!("Input"); frame!(); // Main frame end } fn background_streaming() { frame!(discontinuous "AssetStreaming"); // ... } ``` ``` -------------------------------- ### Enable Unstable Feature for Tracy Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Enable the 'unstable' feature in Cargo.toml for optimizations requiring a nightly Rust compiler. ```toml [dependencies.tracy] ... features = ["enable", "unstable"] ``` -------------------------------- ### Frame Mark Signals with tracy::frame! Source: https://context7.com/sparkypotato/tracy_full/llms.txt Signals frame boundaries to Tracy. Three forms: main continuous frame end, named sub-frame end, and scoped discontinuous frame. ```rust use tracy::frame; fn game_loop() { loop { // Sub-frames for timeline breakdown process_input(); frame!("Input"); run_physics(); frame!("Physics"); render(); swapchain.present(); // Main frame mark — must come after present frame!(); } } fn background_streaming() { // Discontinuous frame: scope-based start/end, not tied to main loop frame!(discontinuous "AssetStreaming"); stream_next_chunk(); // DiscontinuousFrame guard drops here, closing the frame in Tracy } ``` -------------------------------- ### set_thread_name Source: https://context7.com/sparkypotato/tracy_full/llms.txt Assigns a human-readable label to the calling thread, visible in the Tracy timeline. Panics if `name` contains interior null bytes. ```APIDOC ## set_thread_name ### Description Assigns a human-readable label to the calling thread, visible in the Tracy timeline. Panics if `name` contains interior null bytes. ### Function Signature `fn set_thread_name(name: &str)` ### Parameters #### Path Parameters - **name** (string) - Required - The name to assign to the current thread. ### Request Example ```rust use tracy::set_thread_name; fn worker_thread() { set_thread_name("RenderThread"); // ... } ``` ``` -------------------------------- ### Compile-Time C String Literal with `c_str!` Source: https://context7.com/sparkypotato/tracy_full/llms.txt Converts a Rust string literal into a `&'static CStr` at compile time with no runtime allocation. Useful for calling lower-level Tracy functions that expect C strings. ```rust use tracy::c_str; use std::ffi::CStr; // Produces a &'static CStr at zero runtime cost let name: &'static CStr = c_str!("MyZone"); assert_eq!(name.to_str().unwrap(), "MyZone"); // Useful when calling frame/plot functions directly: tracy::frame::named_frame(c_str!("SubFrame")); let plotter = tracy::plot::Plotter::new(c_str!("CustomGraph")); plotter.value(3.14); ``` -------------------------------- ### Mark Discontinuous Frame Scope Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Use the `frame!` macro with `discontinuous` and a name to mark the scope of a discontinuous frame. ```rust frame!(discontinuous "Name"); ``` -------------------------------- ### Set Thread Name in Rust Source: https://context7.com/sparkypotato/tracy_full/llms.txt Assigns a human-readable label to the calling thread, visible in the Tracy timeline. Panics if `name` contains interior null bytes. ```rust use tracy::set_thread_name; fn worker_thread() { set_thread_name("RenderThread"); loop { // work ... } } fn main() { set_thread_name("MainThread"); std::thread::spawn(worker_thread).join().unwrap(); } ``` -------------------------------- ### Mark End of Sub-Frame Source: https://github.com/sparkypotato/tracy_full/blob/main/README.md Use the `frame!` macro with a string argument to mark the end of a named sub-frame. ```rust frame!("Name"); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.