Skip to content

Commit

Permalink
Merge pull request #300 from mstange/dont-move-reference-timestamp
Browse files Browse the repository at this point in the history
Make sure the reference timestamp stays constant.
  • Loading branch information
mstange authored Jul 15, 2024
2 parents 21b3bf6 + eec0857 commit 0ab7c71
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions samply/src/windows/profile_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ pub struct ProfileContext {
stack_sample_count: usize,
event_count: usize,

seen_header: bool,
timestamp_converter: TimestampConverter,
event_timestamps_are_qpc: bool,

Expand Down Expand Up @@ -582,6 +583,7 @@ impl ProfileContext {
sample_count: 0,
stack_sample_count: 0,
event_count: 0,
seen_header: false,
// Dummy, will be replaced once we see the header
timestamp_converter: TimestampConverter {
reference_raw: 0,
Expand Down Expand Up @@ -692,10 +694,27 @@ impl ProfileContext {
self.event_timestamps_are_qpc = true;
}

self.timestamp_converter = TimestampConverter {
reference_raw: timestamp_raw,
raw_to_ns_factor: 1000 * 1000 * 1000 / perf_freq,
};
if !self.seen_header {
// Initialize our reference timestamp to the timestamp from the
// first trace's header.
self.timestamp_converter = TimestampConverter {
reference_raw: timestamp_raw,
raw_to_ns_factor: 1000 * 1000 * 1000 / perf_freq,
};
self.seen_header = true;
} else {
// The header we're processing is the header of the user trace.
// Make sure the timestamps in the two traces are comparable.
assert!(
self.timestamp_converter.reference_raw <= timestamp_raw,
"The first trace should have started first"
);
assert_eq!(
self.timestamp_converter.raw_to_ns_factor,
1000 * 1000 * 1000 / perf_freq,
"The two traces have incompatible timestamps"
);
}
}

pub fn handle_collection_start(&mut self, interval_raw: u32) {
Expand Down

0 comments on commit 0ab7c71

Please sign in to comment.