pub struct GameTracer { /* private fields */ }Expand description
High-level game tracer that integrates all tracing components.
Provides a simple API for recording and querying game traces:
begin_frame(): Start recording a new framerecord_input(): Record an input eventend_frame(): Finish the frame and optionally take a snapshotstats(): Get trace statistics for debugging
§Example
use jugar_web::trace::{GameTracer, TracerConfig, InputEvent, InputEventType};
let mut tracer = GameTracer::new(TracerConfig::default());
// Each frame:
tracer.begin_frame();
tracer.record_input(InputEvent {
event_type: InputEventType::KeyDown(32), // Space
frame_offset_us: 0,
});
tracer.end_frame(None); // Or provide state hashImplementations§
Source§impl GameTracer
impl GameTracer
Sourcepub fn new(config: TracerConfig) -> Self
pub fn new(config: TracerConfig) -> Self
Create a new game tracer with the given configuration.
Sourcepub fn production() -> Self
pub fn production() -> Self
Create a production tracer (drop oldest on overflow).
Sourcepub fn begin_frame(&mut self)
pub fn begin_frame(&mut self)
Start recording a new frame.
Must be called at the start of each frame before recording inputs.
Sourcepub fn record_input(&mut self, event: InputEvent)
pub fn record_input(&mut self, event: InputEvent)
Record an input event for the current frame.
§Panics
Panics in debug builds if begin_frame() was not called.
Sourcepub fn record_inputs(&mut self, events: impl IntoIterator<Item = InputEvent>)
pub fn record_inputs(&mut self, events: impl IntoIterator<Item = InputEvent>)
Record multiple input events for the current frame.
Sourcepub fn stats(&self) -> TraceStats
pub fn stats(&self) -> TraceStats
Get trace statistics for debugging display.
Sourcepub fn start_recording(&mut self)
pub fn start_recording(&mut self)
Start recording.
Sourcepub fn stop_recording(&mut self)
pub fn stop_recording(&mut self)
Stop recording.
Sourcepub const fn is_recording(&self) -> bool
pub const fn is_recording(&self) -> bool
Check if recording is active.
Sourcepub const fn current_frame(&self) -> u64
pub const fn current_frame(&self) -> u64
Get current frame number.
Sourcepub const fn buffer(&self) -> &TraceBuffer
pub const fn buffer(&self) -> &TraceBuffer
Get a reference to the underlying buffer.
Sourcepub fn query(&self) -> TraceQuery<'_>
pub fn query(&self) -> TraceQuery<'_>
Create a query interface for the trace buffer.
Sourcepub fn drain(&mut self, count: usize) -> Vec<FrameRecord>
pub fn drain(&mut self, count: usize) -> Vec<FrameRecord>
Drain frames from the buffer for export.
Sourcepub fn export_json(&self) -> Result<String, TraceError>
pub fn export_json(&self) -> Result<String, TraceError>
Export all frames as JSON.
§Errors
Returns a serialization error if the frames cannot be serialized.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for GameTracer
impl RefUnwindSafe for GameTracer
impl Send for GameTracer
impl Sync for GameTracer
impl Unpin for GameTracer
impl UnwindSafe for GameTracer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more