Skip to content

Commit 74919c0

Browse files
committed
feat(walltime): auto-install samply via upstream installer script
1 parent 0e6e4ea commit 74919c0

2 files changed

Lines changed: 94 additions & 0 deletions

File tree

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
//! Samply profiler integration.
22
3+
mod setup;
4+
35
use crate::executor::ExecutorConfig;
6+
use crate::executor::ToolStatus;
47
use crate::executor::helpers::command::CommandBuilder;
58
use crate::executor::shared::fifo::FifoBenchmarkData;
69
use crate::executor::wall_time::profiler::Profiler;
710
use crate::prelude::*;
11+
use crate::system::SystemInfo;
812
use async_trait::async_trait;
913
use runner_shared::artifacts::ArtifactExt;
1014
use runner_shared::artifacts::ExecutionTimestamps;
1115
use runner_shared::metadata::WalltimeMetadata;
16+
use setup::{get_samply_status, install_samply};
1217
use std::path::Path;
1318
use std::path::PathBuf;
1419

@@ -32,6 +37,18 @@ impl SamplyProfiler {
3237

3338
#[async_trait(?Send)]
3439
impl Profiler for SamplyProfiler {
40+
fn tool_status(&self) -> Option<ToolStatus> {
41+
Some(get_samply_status())
42+
}
43+
44+
async fn setup(
45+
&self,
46+
_system_info: &SystemInfo,
47+
_setup_cache_dir: Option<&Path>,
48+
) -> anyhow::Result<()> {
49+
install_samply().await
50+
}
51+
3552
async fn wrap(
3653
&mut self,
3754
mut cmd_builder: CommandBuilder,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
use crate::binary_installer::ensure_binary_installed;
2+
use crate::executor::{ToolInstallStatus, ToolStatus};
3+
use crate::prelude::*;
4+
use std::process::Command;
5+
6+
pub const SAMPLY_COMMAND: &str = "samply";
7+
pub const SAMPLY_VERSION: &str = "0.13.1";
8+
9+
pub fn get_samply_status() -> ToolStatus {
10+
let tool_name = SAMPLY_COMMAND.to_string();
11+
12+
let is_available = Command::new("which")
13+
.arg(SAMPLY_COMMAND)
14+
.output()
15+
.is_ok_and(|output| output.status.success());
16+
if !is_available {
17+
return ToolStatus {
18+
tool_name,
19+
status: ToolInstallStatus::NotInstalled,
20+
};
21+
}
22+
23+
let Ok(version_output) = Command::new(SAMPLY_COMMAND).arg("--version").output() else {
24+
return ToolStatus {
25+
tool_name,
26+
status: ToolInstallStatus::NotInstalled,
27+
};
28+
};
29+
30+
if !version_output.status.success() {
31+
return ToolStatus {
32+
tool_name,
33+
status: ToolInstallStatus::NotInstalled,
34+
};
35+
}
36+
37+
let version = String::from_utf8_lossy(&version_output.stdout)
38+
.trim()
39+
.to_string();
40+
41+
let expected = semver::Version::parse(SAMPLY_VERSION).unwrap();
42+
if let Some(version_str) = version.split_once(' ').map(|(_, v)| v.trim()) {
43+
if let Ok(installed) = semver::Version::parse(version_str) {
44+
if installed < expected {
45+
return ToolStatus {
46+
tool_name,
47+
status: ToolInstallStatus::IncorrectVersion {
48+
version,
49+
message: format!("version too old, expecting {SAMPLY_VERSION} or higher"),
50+
},
51+
};
52+
}
53+
return ToolStatus {
54+
tool_name,
55+
status: ToolInstallStatus::Installed { version },
56+
};
57+
}
58+
}
59+
60+
ToolStatus {
61+
tool_name,
62+
status: ToolInstallStatus::IncorrectVersion {
63+
version,
64+
message: "could not parse version".to_string(),
65+
},
66+
}
67+
}
68+
69+
pub async fn install_samply() -> Result<()> {
70+
let get_samply_installer_url = || {
71+
format!(
72+
"https://github.com/mstange/samply/releases/download/samply-v{SAMPLY_VERSION}/samply-installer.sh"
73+
)
74+
};
75+
76+
ensure_binary_installed(SAMPLY_COMMAND, SAMPLY_VERSION, get_samply_installer_url).await
77+
}

0 commit comments

Comments
 (0)