Skip to content

Commit

Permalink
Respect configured sampling interval.
Browse files Browse the repository at this point in the history
  • Loading branch information
mstange committed May 5, 2024
1 parent 00ed010 commit 9633380
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 7 additions & 3 deletions samply/src/windows/profiler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,15 @@ pub fn start_recording(
let timebase = std::time::SystemTime::now();
let timebase = ReferenceTimestamp::from_system_time(timebase);

let interval_8khz = SamplingInterval::from_nanos(122100); // 8192Hz // only with the higher recording rate?
const MIN_INTERVAL_NANOS: u64 = 122100; // 8192 kHz
let interval_nanos: u64 = recording_props.interval.as_nanos() as u64;
let interval_nanos = interval_nanos.clamp(MIN_INTERVAL_NANOS, u64::MAX);
let sampling_interval = SamplingInterval::from_nanos(interval_nanos);

let profile = Profile::new(
&profile_creation_props.profile_name,
timebase,
interval_8khz, // recording_props.interval.into(),
sampling_interval,
);

let arch = profile_creation_props
Expand All @@ -70,7 +74,7 @@ pub fn start_recording(
// Start xperf.
let mut xperf =
Xperf::new(arch.to_string()).unwrap_or_else(|e| panic!("Couldn't find xperf: {e:?}"));
xperf.start_xperf(&recording_props.output_file);
xperf.start_xperf(&recording_props.output_file, sampling_interval);

let included_processes = match recording_mode {
RecordingMode::All => {
Expand Down
12 changes: 9 additions & 3 deletions samply/src/windows/xperf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

use std::path::{Path, PathBuf};

use fxprof_processed_profile::SamplingInterval;

pub struct Xperf {
arch: String,
xperf_path: PathBuf,
Expand Down Expand Up @@ -44,7 +46,7 @@ impl Xperf {
)
}

pub fn start_xperf(&mut self, output_file: &Path) {
pub fn start_xperf(&mut self, output_file: &Path, interval: SamplingInterval) {
if self.is_running() {
self.stop_xperf();
}
Expand All @@ -62,12 +64,16 @@ impl Xperf {
None
};

let mut xperf = runas::Command::new(&self.xperf_path);
const NANOS_PER_TICK: u64 = 100;
let interval_ticks = interval.nanos() / NANOS_PER_TICK;

xperf.arg("-on");
let mut xperf = runas::Command::new(&self.xperf_path);
xperf.arg("-SetProfInt");
xperf.arg(interval_ticks.to_string());

// Virtualised ARM64 Windows crashes out on PROFILE tracing, so this hidden
// hack argument lets things still continue to run for development of samply.
xperf.arg("-on");
if !self.virtualized_aarch64_hack {
xperf.arg("PROC_THREAD+LOADER+PROFILE+CSWITCH");
xperf.arg("-stackwalk");
Expand Down

0 comments on commit 9633380

Please sign in to comment.