Skip to content

Commit 281cd93

Browse files
committed
Write jit addresses to perf map
1 parent c9cc594 commit 281cd93

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

src/jit/jit_memory.rs

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,13 +94,58 @@ pub struct JitLiveRanges {
9494
pub vram_arm7: HeapMemU8<{ (vram::ARM7_SIZE / JIT_LIVE_RANGE_PAGE_SIZE / 8) as usize }>,
9595
}
9696

97+
#[cfg(target_os = "linux")]
98+
struct JitPerfMapRecord {
99+
perf_map_path: std::path::PathBuf,
100+
perf_map: std::fs::File,
101+
}
102+
103+
#[cfg(target_os = "linux")]
104+
impl JitPerfMapRecord {
105+
fn new() -> Self {
106+
let perf_map_path = std::path::PathBuf::from(format!("/tmp/perf-{}.map", std::process::id()));
107+
JitPerfMapRecord {
108+
perf_map_path: perf_map_path.clone(),
109+
perf_map: std::fs::File::create(perf_map_path).unwrap(),
110+
}
111+
}
112+
113+
fn record(&mut self, jit_start: usize, jit_size: usize, guest_pc: u32, cpu_type: CpuType) {
114+
if crate::IS_DEBUG {
115+
use std::io::Write;
116+
writeln!(self.perf_map, "{jit_start:x} {jit_size:x} {cpu_type:?}_{guest_pc:x}").unwrap();
117+
}
118+
}
119+
120+
fn reset(&mut self) {
121+
if crate::IS_DEBUG {
122+
self.perf_map = std::fs::File::create(&self.perf_map_path).unwrap()
123+
}
124+
}
125+
}
126+
127+
#[cfg(target_os = "vita")]
128+
struct JitPerfMapRecord;
129+
130+
#[cfg(target_os = "vita")]
131+
impl JitPerfMapRecord {
132+
fn new() -> Self {
133+
JitPerfMapRecord
134+
}
135+
136+
fn record(&mut self, jit_start: usize, jit_size: usize, guest_pc: u32, cpu_type: CpuType) {}
137+
138+
fn reset(&mut self) {}
139+
}
140+
97141
pub struct JitMemory {
98142
mem: Mmap,
99143
mem_common_end: usize,
100144
mem_start: usize,
101145
jit_entries: JitEntries,
102146
jit_live_ranges: JitLiveRanges,
103147
pub jit_memory_map: JitMemoryMap,
148+
jit_perf_map_record: JitPerfMapRecord,
104149
}
105150

106151
impl JitMemory {
@@ -115,11 +160,14 @@ impl JitMemory {
115160
jit_entries,
116161
jit_live_ranges,
117162
jit_memory_map,
163+
jit_perf_map_record: JitPerfMapRecord::new(),
118164
}
119165
}
120166

121167
fn reset_blocks(&mut self) {
122168
debug_println!("Jit memory reset");
169+
self.jit_perf_map_record.reset();
170+
123171
self.mem_start = self.mem_common_end;
124172

125173
self.jit_entries.reset();
@@ -216,6 +264,8 @@ impl JitMemory {
216264
guest_pc
217265
);
218266

267+
self.jit_perf_map_record.record(jit_entry_addr as usize, aligned_size, guest_pc, CPU);
268+
219269
(jit_entry_addr, flushed)
220270
}};
221271
}

0 commit comments

Comments
 (0)