Track total time using tsc packets and total internal time with cycles.
Something is still wrong though, the tsc time is somehow less than the cyc time
This commit is contained in:
parent
2e5af76dbb
commit
10ca8f89f6
@ -10,14 +10,13 @@ use std::time::Duration;
|
||||
pub struct AnalyzeData {
|
||||
pub packets: u64,
|
||||
pub cycles: u64,
|
||||
pub time: Duration,
|
||||
pub time_tsc: Duration,
|
||||
pub time_cyc: Duration,
|
||||
pub time_main: Duration,
|
||||
pub time_disabled: Duration,
|
||||
}
|
||||
|
||||
#[derive(Debug, Eq, PartialEq)]
|
||||
enum Scope {
|
||||
Disabled,
|
||||
Main,
|
||||
PreRun,
|
||||
PostRun,
|
||||
@ -38,17 +37,20 @@ pub fn analyze_dump(path: impl AsRef<Path>) -> Result<AnalyzeData, Box<dyn Error
|
||||
let mut segments = vec![(Scope::PreRun, 0u64)];
|
||||
let mut total = 0u64;
|
||||
|
||||
let mut first_tsc = None::<u64>;
|
||||
let mut last_tsc = 0;
|
||||
|
||||
for packet in decoder {
|
||||
total += 1;
|
||||
match packet {
|
||||
Ok(Packet::Cyc(cyc)) => {
|
||||
segments.last_mut().unwrap().1 += cyc.value();
|
||||
}
|
||||
Ok(Packet::TipPge(_)) => {
|
||||
segments.push((Scope::Main, 0));
|
||||
Ok(Packet::Tsc(tsc)) => {
|
||||
if first_tsc.is_none() {
|
||||
first_tsc = Some(tsc.tsc());
|
||||
}
|
||||
Ok(Packet::TipPgd(_)) => {
|
||||
segments.push((Scope::Disabled, 0));
|
||||
last_tsc = tsc.tsc();
|
||||
}
|
||||
Ok(Packet::Ptw(ptwrite)) => {
|
||||
if ptwrite.payload() == 42 {
|
||||
@ -61,6 +63,9 @@ pub fn analyze_dump(path: impl AsRef<Path>) -> Result<AnalyzeData, Box<dyn Error
|
||||
println!("GOT PTWRITE!!!!!: {ptwrite:?}");
|
||||
}
|
||||
}
|
||||
Ok(Packet::Ovf(overflow)) => {
|
||||
panic!("Got overflow packet: {overflow:?}, index {total}");
|
||||
}
|
||||
Ok(_) => {}
|
||||
Err(error) => println!("Got error: {error:?}"),
|
||||
}
|
||||
@ -69,15 +74,16 @@ pub fn analyze_dump(path: impl AsRef<Path>) -> Result<AnalyzeData, Box<dyn Error
|
||||
let cycles_total = segments.iter().map(|(_, cycles)| cycles).sum();
|
||||
let total_seconds = cycles_total as f64 / 2_700_000_000.0;
|
||||
|
||||
let total_seconds_tsc = (last_tsc - first_tsc.unwrap()) 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_cyc: Duration::from_secs_f64(total_seconds),
|
||||
time_main: main_duration,
|
||||
time_disabled: disabled_duration
|
||||
time_tsc: Duration::from_secs_f64(total_seconds_tsc)
|
||||
})
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user