Include inline functions when profiling
This commit is contained in:
+23
-11
@@ -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()));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user