Skip to content

Commit

Permalink
Merge pull request #128 from vvuk/vladv/fix-mac-sample
Browse files Browse the repository at this point in the history
Tag samples with time as close as possible to the time they were taken
  • Loading branch information
mstange authored Mar 27, 2024
2 parents 2f94ef1 + df24932 commit dc2dc85
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion samply/src/mac/thread_profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@ use framehop::FrameAddress;
use fxprof_processed_profile::{CpuDelta, Profile, ThreadHandle, Timestamp};
use mach::mach_types::thread_act_t;
use mach::port::mach_port_t;
use time::get_monotonic_timestamp;

use std::mem;

use crate::mac::time;
use crate::shared::recycling::ThreadRecycler;
use crate::shared::types::{StackFrame, StackMode};
use crate::shared::unresolved_samples::{UnresolvedSamples, UnresolvedStacks};
Expand Down Expand Up @@ -140,6 +142,10 @@ impl ThreadProfiler {
stack_scratch_buffer,
fold_recursive_prefix,
)?;
// make sure to use the time immediately after the stack is sampled so that any
// jitdump records emitted in the interval between samply starting to sample
// all tasks and actually stopping the thread are properly used
let sample_time_mono = get_monotonic_timestamp();

let frames = stack_scratch_buffer.iter().rev().map(|f| match f {
FrameAddress::InstructionPointer(address) => {
Expand All @@ -153,7 +159,7 @@ impl ThreadProfiler {
unresolved_samples.add_sample(
self.profile_thread,
now,
now_mono,
sample_time_mono,
stack,
cpu_delta,
1,
Expand Down

0 comments on commit dc2dc85

Please sign in to comment.