Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add TracingInspector::into_traces #112

Merged
merged 1 commit into from
May 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 25 additions & 25 deletions src/tracing/arena.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,32 @@ pub struct CallTraceArena {
pub(crate) arena: Vec<CallTraceNode>,
}

impl Default for CallTraceArena {
fn default() -> Self {
// The first node is the root node
Self { arena: vec![Default::default()] }
}
}

impl CallTraceArena {
/// Returns the nodes in the arena
pub fn nodes(&self) -> &[CallTraceNode] {
&self.arena
}

/// Consumes the arena and returns the nodes
pub fn into_nodes(self) -> Vec<CallTraceNode> {
self.arena
}

/// Clears the arena
///
/// Note that this method has no effect on the allocated capacity of the arena.
#[inline]
pub fn clear(&mut self) {
self.arena.clear();
}

/// Pushes a new trace into the arena, returning the trace ID
///
/// This appends a new trace to the arena, and also inserts a new entry in the node's parent
Expand Down Expand Up @@ -57,24 +82,6 @@ impl CallTraceArena {
}
}
}

/// Returns the nodes in the arena
pub fn nodes(&self) -> &[CallTraceNode] {
&self.arena
}

/// Consumes the arena and returns the nodes
pub fn into_nodes(self) -> Vec<CallTraceNode> {
self.arena
}

/// Clears the arena
///
/// Note that this method has no effect on the allocated capacity of the arena.
#[inline]
pub fn clear(&mut self) {
self.arena.clear();
}
}

/// How to push a trace into the arena
Expand All @@ -92,10 +99,3 @@ impl PushTraceKind {
matches!(self, Self::PushAndAttachToParent)
}
}

impl Default for CallTraceArena {
fn default() -> Self {
// The first node is the root node
Self { arena: vec![Default::default()] }
}
}
5 changes: 5 additions & 0 deletions src/tracing/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,11 @@ impl TracingInspector {
&self.traces
}

/// Consumes the inspector and returns the recorded call traces.
pub fn into_traces(self) -> CallTraceArena {
self.traces
}

/// Gets a mutable reference to the recorded call traces.
pub fn get_traces_mut(&mut self) -> &mut CallTraceArena {
&mut self.traces
Expand Down
Loading