From 27323834658d87f686c2f7cf23153b3e1420f56b Mon Sep 17 00:00:00 2001 From: David Venhoff Date: Fri, 12 Sep 2025 11:04:02 +0200 Subject: [PATCH] Adjust tsc calculation Since we only want to record the time when benchmarking --- pt-dump-decoder/src/lib.rs | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/pt-dump-decoder/src/lib.rs b/pt-dump-decoder/src/lib.rs index 9c51e51..3f719f7 100644 --- a/pt-dump-decoder/src/lib.rs +++ b/pt-dump-decoder/src/lib.rs @@ -49,8 +49,10 @@ pub fn analyze_dump( let f_bus = cpuid!(0x16).ecx as f64 * 1_000_000.0; let mut current_cbr = 0u8; - let mut first_tsc = None::; - let mut last_tsc = 0; + // Records the first tsc after the ptwrite (42) message + let mut first_tsc_main = None::; + // Records the first tsc after the ptwrite (43) message + let mut first_tsc_post_run = None::; let mut seen_cbrs = HashMap::::new(); @@ -68,10 +70,15 @@ pub fn analyze_dump( segments.last_mut().unwrap().1 += duration; } Ok(Packet::Tsc(tsc)) => { - if first_tsc.is_none() { - first_tsc = Some(tsc.tsc()); + if let [.., (Scope::Main, _)] = segments.as_slice() + && first_tsc_main.is_none() + { + first_tsc_main = Some(tsc.tsc()); + } else if let [.., (Scope::PostRun, _)] = segments.as_slice() + && first_tsc_post_run.is_none() + { + first_tsc_post_run = Some(tsc.tsc()); } - last_tsc = tsc.tsc(); } Ok(Packet::Cbr(cbr)) => { current_cbr = cbr.ratio(); @@ -104,7 +111,7 @@ pub fn analyze_dump( .unwrap() .tsc_frequency() .unwrap(); - let total_seconds_tsc = (last_tsc - first_tsc.unwrap()) as f64 / f_tsc as f64; + let total_seconds_tsc = (first_tsc_post_run.unwrap() - first_tsc_main.unwrap()) as f64 / f_tsc as f64; Ok(AnalyzeData { packets: total,