Include inline functions when profiling

This commit is contained in:
2025-08-31 23:01:50 -04:00
parent 04c92c1454
commit 841ded3bee
9 changed files with 342 additions and 52 deletions
+15 -8
View File
@@ -89,14 +89,21 @@ impl Recording {
thread: ThreadHandle,
frames: &[StackFrame],
) -> Option<StackHandle> {
self.profile.intern_stack_frames(
thread,
frames.iter().map(|f| FrameInfo {
frame: Frame::InstructionPointer(f.address as u64),
category_pair: CategoryHandle::OTHER.into(),
flags: FrameFlags::empty(),
}),
)
let frames = frames
.iter()
.map(|f| {
let frame = match f {
StackFrame::Address(address) => Frame::InstructionPointer(*address as u64),
StackFrame::Label(label) => Frame::Label(self.profile.intern_string(label)),
};
FrameInfo {
frame,
category_pair: CategoryHandle::OTHER.into(),
flags: FrameFlags::empty(),
}
})
.collect::<Vec<_>>();
self.profile.intern_stack_frames(thread, frames.into_iter())
}
}
+23 -11
View File
@@ -3,7 +3,7 @@ use std::{collections::HashMap, sync::Arc};
use anyhow::{Result, bail};
use fxprof_processed_profile::LibraryInfo;
use crate::emulator::GameInfo;
use crate::emulator::{GameInfo, InlineStack};
pub struct ProgramState {
info: Arc<GameInfo>,
@@ -11,20 +11,16 @@ pub struct ProgramState {
context_stack: Vec<u16>,
}
pub struct StackFrame {
pub address: u32,
pub enum StackFrame {
Address(u32),
Label(Arc<String>),
}
pub const RESET_CODE: u16 = 0xfff0;
impl ProgramState {
pub async fn new(info: Arc<GameInfo>) -> Self {
let mut call_stacks = HashMap::new();
call_stacks.insert(
RESET_CODE,
vec![StackFrame {
address: 0xfffffff0,
}],
);
call_stacks.insert(RESET_CODE, vec![StackFrame::Address(0xfffffff0)]);
Self {
info,
call_stacks,
@@ -53,7 +49,7 @@ impl ProgramState {
let Some(stack) = self.call_stacks.get_mut(code) else {
bail!("missing stack {code:04x}");
};
stack.push(StackFrame { address });
stack.push(StackFrame::Address(address));
Ok(())
}
@@ -89,7 +85,7 @@ impl ProgramState {
self.context_stack.push(code);
if self
.call_stacks
.insert(code, vec![StackFrame { address }])
.insert(code, vec![StackFrame::Address(address)])
.is_some()
{
bail!("{code:04x} fired twice");
@@ -109,4 +105,20 @@ impl ProgramState {
}
Ok(())
}
pub fn track_inline_stack(&mut self, inline_stack: InlineStack) {
let Some(code) = self.context_stack.last() else {
return;
};
let Some(call_stack) = self.call_stacks.get_mut(code) else {
return;
};
while call_stack
.pop_if(|f| matches!(f, StackFrame::Label(_)))
.is_some()
{}
for label in inline_stack.iter() {
call_stack.push(StackFrame::Label(label.clone()));
}
}
}