Skip to content

Commit 4713c26

Browse files
committed
fixup! feat(walltime): bundle samply via library crate
1 parent e40e632 commit 4713c26

3 files changed

Lines changed: 16 additions & 9 deletions

File tree

src/executor/wall_time/profiler/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,14 @@ pub mod samply;
1010

1111
const WALLTIME_METADATA_CURRENT_VERSION: u64 = 1;
1212

13+
/// Sampling rate (Hz) shared by all walltime profilers. A prime number to
14+
/// avoid synchronization with periodic tasks.
15+
pub(super) const SAMPLING_RATE_HZ: u32 = 997;
16+
17+
/// Warning shown when walltime profiling ran but no benchmarks were detected.
18+
pub(super) const NO_BENCHMARKS_DETECTED_WARNING: &str = "Walltime profiling is enabled, but failed to detect benchmarks. \
19+
If you wish to disable this warning, set CODSPEED_PROFILER_ENABLED=false";
20+
1321
use crate::executor::ExecutorConfig;
1422
use crate::executor::ToolStatus;
1523
use crate::executor::helpers::command::CommandBuilder;

src/executor/wall_time/profiler/perf/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ use crate::executor::helpers::env::suppress_go_perf_unwinding_warning;
1010
use crate::executor::helpers::harvest_perf_maps_for_pids::harvest_perf_maps_for_pids;
1111
use crate::executor::helpers::run_with_sudo::wrap_with_sudo;
1212
use crate::executor::shared::fifo::FifoBenchmarkData;
13+
use crate::executor::wall_time::profiler::NO_BENCHMARKS_DETECTED_WARNING;
1314
use crate::executor::wall_time::profiler::Profiler;
15+
use crate::executor::wall_time::profiler::SAMPLING_RATE_HZ;
1416
use crate::executor::wall_time::profiler::WALLTIME_METADATA_CURRENT_VERSION;
1517
use crate::executor::wall_time::profiler::linux_sysctl::ensure_linux_profiling_sysctls;
1618
use crate::executor::wall_time::profiler::perf::perf_executable::get_working_perf_executable;
@@ -146,7 +148,7 @@ impl Profiler for PerfProfiler {
146148
// Required for matching the markers and URIs to the samples.
147149
"-k",
148150
"CLOCK_MONOTONIC",
149-
"--freq=997", // Use a prime number to avoid synchronization with periodic tasks
151+
&format!("--freq={SAMPLING_RATE_HZ}"),
150152
"--delay=-1",
151153
"-g",
152154
"--user-callchains",
@@ -219,9 +221,7 @@ impl Profiler for PerfProfiler {
219221
if let Err(BenchmarkDataSaveError::MissingIntegration) =
220222
bench_data.save_to(profile_folder, perf_file_path).await
221223
{
222-
warn!(
223-
"Perf is enabled, but failed to detect benchmarks. If you wish to disable this warning, set CODSPEED_PROFILER_ENABLED=false"
224-
);
224+
warn!("{NO_BENCHMARKS_DETECTED_WARNING}");
225225
return Ok(());
226226
}
227227

src/executor/wall_time/profiler/samply/mod.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,11 @@ use runner_shared::metadata::WalltimeMetadata;
1414
use std::path::Path;
1515
use std::path::PathBuf;
1616

17+
use super::NO_BENCHMARKS_DETECTED_WARNING;
18+
use super::SAMPLING_RATE_HZ;
1719
use super::WALLTIME_METADATA_CURRENT_VERSION;
1820

1921
const SAMPLY_OUTPUT_FILE_NAME: &str = "samply-profile.json.gz";
20-
const SAMPLY_RATE_HZ: &str = "997";
2122

2223
pub struct SamplyProfiler {
2324
/// Set by [`Profiler::wrap_command`]. Currently unused after `wrap_command`
@@ -62,7 +63,7 @@ impl Profiler for SamplyProfiler {
6263
"--no-open",
6364
"--save-only",
6465
"--rate",
65-
SAMPLY_RATE_HZ,
66+
&SAMPLING_RATE_HZ.to_string(),
6667
]);
6768
samply_builder.arg("-o");
6869
samply_builder.arg(&output_path);
@@ -80,9 +81,7 @@ impl Profiler for SamplyProfiler {
8081
profile_folder: &Path,
8182
) -> anyhow::Result<()> {
8283
let Some(integration) = fifo_data.integration.clone() else {
83-
warn!(
84-
"Walltime profiling is enabled, but failed to detect benchmarks. If you wish to disable this warning, set CODSPEED_PROFILER_ENABLED=false"
85-
);
84+
warn!("{NO_BENCHMARKS_DETECTED_WARNING}");
8685
return Ok(());
8786
};
8887

0 commit comments

Comments
 (0)