From 491a9e3ab12ccb6a622df8f16912b779adc75faa Mon Sep 17 00:00:00 2001 From: Levi Morrison Date: Fri, 30 Jan 2026 20:10:39 -0700 Subject: [PATCH 1/8] refactor(profiling): extract Backtrace type In a future change, this may hold a refcount for another object, so we need to encapsulate it. --- profiling/src/profiling/backtrace.rs | 33 ++++++++++++++++++ profiling/src/profiling/mod.rs | 44 +++++++++++++----------- profiling/src/profiling/stack_walking.rs | 30 ++++++++-------- 3 files changed, 72 insertions(+), 35 deletions(-) create mode 100644 profiling/src/profiling/backtrace.rs diff --git a/profiling/src/profiling/backtrace.rs b/profiling/src/profiling/backtrace.rs new file mode 100644 index 00000000000..9dfcc359d96 --- /dev/null +++ b/profiling/src/profiling/backtrace.rs @@ -0,0 +1,33 @@ +use crate::profiling::stack_walking::ZendFrame; +use core::ops::Deref; + +#[derive(Debug)] +pub struct Backtrace { + frames: Vec, +} + +impl Backtrace { + pub const fn new(frames: Vec) -> Self { + Self { frames } + } + + pub fn len(&self) -> usize { + self.frames.len() + } + + pub fn is_empty(&self) -> bool { + self.frames.is_empty() + } + + pub fn iter(&self) -> impl Iterator { + self.frames.iter() + } +} + +impl Deref for Backtrace { + type Target = [ZendFrame]; + + fn deref(&self) -> &Self::Target { + self.frames.as_slice() + } +} diff --git a/profiling/src/profiling/mod.rs b/profiling/src/profiling/mod.rs index cc9cc845e60..271b192be54 100644 --- a/profiling/src/profiling/mod.rs +++ b/profiling/src/profiling/mod.rs @@ -1,9 +1,11 @@ +mod backtrace; mod interrupts; mod sample_type_filter; pub mod stack_walking; mod thread_utils; mod uploader; +pub use backtrace::Backtrace; pub use interrupts::*; pub use sample_type_filter::*; pub use stack_walking::*; @@ -170,7 +172,7 @@ pub struct ProfileIndex { #[derive(Debug)] pub struct SampleData { - pub frames: Vec, + pub frames: Backtrace, pub labels: Vec