Track time in main and time disabled
This commit is contained in:
parent
109091c087
commit
2e5af76dbb
@ -11,11 +11,13 @@ pub struct AnalyzeData {
|
||||
pub packets: u64,
|
||||
pub cycles: u64,
|
||||
pub time: Duration,
|
||||
pub time_outside_hypervisor: Duration,
|
||||
pub time_main: Duration,
|
||||
pub time_disabled: Duration,
|
||||
}
|
||||
|
||||
#[derive(Debug)]
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
enum Scope {
|
||||
Disabled,
|
||||
Main,
|
||||
PreRun,
|
||||
PostRun,
|
||||
@ -42,8 +44,11 @@ pub fn analyze_dump(path: impl AsRef<Path>) -> Result<AnalyzeData, Box<dyn Error
|
||||
Ok(Packet::Cyc(cyc)) => {
|
||||
segments.last_mut().unwrap().1 += cyc.value();
|
||||
}
|
||||
Ok(Packet::Vmcs(_)) => {
|
||||
// last_packet_vmcs = true;
|
||||
Ok(Packet::TipPge(_)) => {
|
||||
segments.push((Scope::Main, 0));
|
||||
}
|
||||
Ok(Packet::TipPgd(_)) => {
|
||||
segments.push((Scope::Disabled, 0));
|
||||
}
|
||||
Ok(Packet::Ptw(ptwrite)) => {
|
||||
if ptwrite.payload() == 42 {
|
||||
@ -61,18 +66,27 @@ pub fn analyze_dump(path: impl AsRef<Path>) -> Result<AnalyzeData, Box<dyn Error
|
||||
}
|
||||
}
|
||||
// dbg!(&segments);
|
||||
let cycles_main: u64 = segments
|
||||
.iter()
|
||||
.filter(|(scope, _)| matches!(scope, Scope::Main))
|
||||
.map(|(_, cycles)| cycles)
|
||||
.sum();
|
||||
let cycles_total = segments.iter().map(|(_, cycles)| cycles).sum();
|
||||
let total_seconds = cycles_total as f64 / 2_700_000_000.0;
|
||||
let total_seconds_no_hypervisor = cycles_main as f64 / 2_700_000_000.0;
|
||||
|
||||
let main_duration = duration_in_mode(&segments, Scope::Main);
|
||||
let disabled_duration = duration_in_mode(&segments, Scope::Disabled);
|
||||
|
||||
Ok(AnalyzeData {
|
||||
packets: total,
|
||||
cycles: cycles_total,
|
||||
time: Duration::from_secs_f64(total_seconds),
|
||||
time_outside_hypervisor: Duration::from_secs_f64(total_seconds_no_hypervisor),
|
||||
time_main: main_duration,
|
||||
time_disabled: disabled_duration
|
||||
})
|
||||
}
|
||||
|
||||
fn duration_in_mode(segments: &[(Scope, u64)], scope: Scope) -> Duration {
|
||||
let total_cycles = segments
|
||||
.into_iter()
|
||||
.filter(|(it, _)| *it == scope)
|
||||
.map(|(_, cycles)| *cycles)
|
||||
.sum::<u64>();
|
||||
let total_seconds = total_cycles as f64 / 2_700_000_000.0;
|
||||
Duration::from_secs_f64(total_seconds)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user