Profile without ELF data
This commit is contained in:
parent
529795481b
commit
981eeec9c6
|
@ -134,14 +134,14 @@ async fn handle_event(event: ProfileEvent, session: &mut ProfilerSession) -> Res
|
||||||
match event {
|
match event {
|
||||||
ProfileEvent::Start { file_path } => session.start_profiling(file_path).await,
|
ProfileEvent::Start { file_path } => session.start_profiling(file_path).await,
|
||||||
ProfileEvent::Update { cycles, event } => {
|
ProfileEvent::Update { cycles, event } => {
|
||||||
session.track_elapsed_cycles(cycles)?;
|
session.track_elapsed_cycles(cycles);
|
||||||
if let Some(event) = event {
|
if let Some(event) = event {
|
||||||
session.track_event(event)?;
|
session.track_event(event)?;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn handle_action(
|
fn handle_action(
|
||||||
action: RecordingAction,
|
action: RecordingAction,
|
||||||
|
@ -199,8 +199,8 @@ impl ProfilerSession {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn start_profiling(&mut self, file_path: PathBuf) -> Result<()> {
|
async fn start_profiling(&mut self, file_path: PathBuf) {
|
||||||
let program = ProgramState::new(file_path).await?;
|
let program = ProgramState::new(file_path).await;
|
||||||
let recording = if self.recording.is_some() {
|
let recording = if self.recording.is_some() {
|
||||||
Some(Recording::new(&program))
|
Some(Recording::new(&program))
|
||||||
} else {
|
} else {
|
||||||
|
@ -208,14 +208,12 @@ impl ProfilerSession {
|
||||||
};
|
};
|
||||||
self.program = Some(program);
|
self.program = Some(program);
|
||||||
self.recording = recording;
|
self.recording = recording;
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn track_elapsed_cycles(&mut self, cycles: u32) -> Result<()> {
|
fn track_elapsed_cycles(&mut self, cycles: u32) {
|
||||||
if let (Some(state), Some(recording)) = (&self.program, &mut self.recording) {
|
if let (Some(state), Some(recording)) = (&self.program, &mut self.recording) {
|
||||||
recording.track_elapsed_cycles(state, cycles);
|
recording.track_elapsed_cycles(state, cycles);
|
||||||
}
|
}
|
||||||
Ok(())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn track_event(&mut self, event: SimEvent) -> Result<()> {
|
fn track_event(&mut self, event: SimEvent) -> Result<()> {
|
||||||
|
|
|
@ -17,17 +17,17 @@ pub struct Recording {
|
||||||
|
|
||||||
impl Recording {
|
impl Recording {
|
||||||
pub fn new(state: &ProgramState) -> Self {
|
pub fn new(state: &ProgramState) -> Self {
|
||||||
let symbol_file = state.symbol_file();
|
|
||||||
|
|
||||||
let name = &symbol_file.name();
|
|
||||||
let reference_timestamp = ReferenceTimestamp::from_millis_since_unix_epoch(0.0);
|
let reference_timestamp = ReferenceTimestamp::from_millis_since_unix_epoch(0.0);
|
||||||
let interval = SamplingInterval::from_hz(20_000_000.0);
|
let interval = SamplingInterval::from_hz(20_000_000.0);
|
||||||
let mut profile = Profile::new(name, reference_timestamp, interval);
|
let mut profile = Profile::new(state.name(), reference_timestamp, interval);
|
||||||
|
|
||||||
let process = profile.add_process(name, 1, Timestamp::from_nanos_since_reference(0));
|
let process =
|
||||||
|
profile.add_process(state.name(), 1, Timestamp::from_nanos_since_reference(0));
|
||||||
|
|
||||||
|
if let Some(symbol_file) = state.symbol_file() {
|
||||||
let lib = profile.add_lib(symbol_file.library_info().clone());
|
let lib = profile.add_lib(symbol_file.library_info().clone());
|
||||||
profile.add_lib_mapping(process, lib, 0x00000000, 0xffffffff, 0);
|
profile.add_lib_mapping(process, lib, 0x00000000, 0xffffffff, 0);
|
||||||
|
}
|
||||||
|
|
||||||
let mut me = Self {
|
let mut me = Self {
|
||||||
profile,
|
profile,
|
||||||
|
|
|
@ -5,7 +5,8 @@ use anyhow::{Result, bail};
|
||||||
use crate::profiler::symbols::SymbolFile;
|
use crate::profiler::symbols::SymbolFile;
|
||||||
|
|
||||||
pub struct ProgramState {
|
pub struct ProgramState {
|
||||||
symbol_file: SymbolFile,
|
name: String,
|
||||||
|
symbol_file: Option<SymbolFile>,
|
||||||
call_stacks: HashMap<u16, Vec<StackFrame>>,
|
call_stacks: HashMap<u16, Vec<StackFrame>>,
|
||||||
context_stack: Vec<u16>,
|
context_stack: Vec<u16>,
|
||||||
}
|
}
|
||||||
|
@ -16,8 +17,17 @@ pub struct StackFrame {
|
||||||
|
|
||||||
pub const RESET_CODE: u16 = 0xfff0;
|
pub const RESET_CODE: u16 = 0xfff0;
|
||||||
impl ProgramState {
|
impl ProgramState {
|
||||||
pub async fn new(file_path: PathBuf) -> Result<Self> {
|
pub async fn new(file_path: PathBuf) -> Self {
|
||||||
let symbol_file = SymbolFile::load(&file_path).await?;
|
let symbol_file = SymbolFile::load(&file_path).await.ok();
|
||||||
|
let name = symbol_file
|
||||||
|
.as_ref()
|
||||||
|
.map(|f| f.name().to_string())
|
||||||
|
.or_else(|| {
|
||||||
|
file_path
|
||||||
|
.file_stem()
|
||||||
|
.map(|s| s.to_string_lossy().into_owned())
|
||||||
|
})
|
||||||
|
.unwrap_or_else(|| "game".to_string());
|
||||||
let mut call_stacks = HashMap::new();
|
let mut call_stacks = HashMap::new();
|
||||||
call_stacks.insert(
|
call_stacks.insert(
|
||||||
RESET_CODE,
|
RESET_CODE,
|
||||||
|
@ -25,15 +35,20 @@ impl ProgramState {
|
||||||
address: 0xfffffff0,
|
address: 0xfffffff0,
|
||||||
}],
|
}],
|
||||||
);
|
);
|
||||||
Ok(Self {
|
Self {
|
||||||
|
name,
|
||||||
symbol_file,
|
symbol_file,
|
||||||
call_stacks,
|
call_stacks,
|
||||||
context_stack: vec![RESET_CODE],
|
context_stack: vec![RESET_CODE],
|
||||||
})
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn symbol_file(&self) -> &SymbolFile {
|
pub fn name(&self) -> &str {
|
||||||
&self.symbol_file
|
&self.name
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn symbol_file(&self) -> Option<&SymbolFile> {
|
||||||
|
self.symbol_file.as_ref()
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn current_stack(&self) -> Option<(u16, &[StackFrame])> {
|
pub fn current_stack(&self) -> Option<(u16, &[StackFrame])> {
|
||||||
|
|
Loading…
Reference in New Issue