Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Respect configured sampling interval. #174

Merged
merged 1 commit into from
May 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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