-
Notifications
You must be signed in to change notification settings - Fork 6
Feat: add the exec subcommand to run an arbitrary rust binary #165
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
Merged
GuillaumeLagrange
merged 12 commits into
main
from
cod-1723-run-an-hello-world-rust-binary-in-the-runner-in-walltime
Dec 16, 2025
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
43caeb6
refactor: move executor and instruments modules out of `run` module
GuillaumeLagrange 195afc1
feat: add exec-harness binary
GuillaumeLagrange 2e61f04
feat: add exec subcommand and refactor run subcommand
GuillaumeLagrange 9b16923
fix: stop filtering out zero sized symbol
GuillaumeLagrange 2d6a9bc
fix: use correct name for unwind_data trait declaration
GuillaumeLagrange dd83962
refactor: create a dedicated execution_context that holds runtime inf…
GuillaumeLagrange fbdebd5
feat: use the projects upload enpdoint in exec command
GuillaumeLagrange 4c8c413
feat: parse perf file for memmap events instead of relying on /proc/p…
GuillaumeLagrange 99b1c98
chore: make the exec command work outside of git repos
GuillaumeLagrange 6d6358e
fix: stop ignoring samples
GuillaumeLagrange 65aad65
fix: prevent nextest from running valgrind and memcheck concurrently
GuillaumeLagrange 1dd86c6
fix: fix plan test in CI
GuillaumeLagrange File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| # Valgrind and memtrack tests must never run concurrently, even across multiple processes, else valgrind crashes. | ||
| # We have a semaphore setup in the test code, but it's not sufficient since nextest runs tests in multiple processes. | ||
| [test-groups] | ||
| bpf-instrumentation = { max-threads = 1 } | ||
|
|
||
| [[profile.default.overrides]] | ||
| filter = 'test(~executor::tests::valgrind) | test(~executor::tests::memory)' | ||
| test-group = 'bpf-instrumentation' |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,2 @@ | ||
| testdata/perf_map/* filter=lfs diff=lfs merge=lfs -text | ||
| src/run/runner/wall_time/perf/snapshots/*.snap filter=lfs diff=lfs merge=lfs -text | ||
| *.snap filter=lfs diff=lfs merge=lfs -text |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,2 @@ | ||
| /target | ||
| .DS_Store | ||
| samples |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| [package] | ||
| name = "exec-harness" | ||
| version = "4.4.2-beta.1" | ||
| edition = "2024" | ||
|
|
||
| [dependencies] | ||
| anyhow = { workspace = true } | ||
| codspeed = "4.1.0" | ||
| clap = { workspace = true } | ||
| serde_json = { workspace = true } | ||
| serde = { workspace = true } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| use crate::walltime::WalltimeResults; | ||
| use anyhow::Context; | ||
| use anyhow::Result; | ||
| use anyhow::bail; | ||
| use clap::Parser; | ||
| use codspeed::instrument_hooks::InstrumentHooks; | ||
| use codspeed::walltime_results::WalltimeBenchmark; | ||
| use std::path::PathBuf; | ||
| use std::process; | ||
|
|
||
| mod walltime; | ||
|
|
||
| #[derive(Parser, Debug)] | ||
| #[command(name = "exec-harness")] | ||
| #[command(about = "CodSpeed exec harness - wraps commands with performance instrumentation")] | ||
| struct Args { | ||
| /// Optional benchmark name (defaults to command filename) | ||
| #[arg(long)] | ||
| name: Option<String>, | ||
|
|
||
| /// The command and arguments to execute | ||
| command: Vec<String>, | ||
| } | ||
|
|
||
| fn main() -> Result<()> { | ||
| let args = Args::parse(); | ||
|
|
||
| if args.command.is_empty() { | ||
| bail!("Error: No command provided"); | ||
| } | ||
|
|
||
| // Derive benchmark name from command if not provided | ||
| let bench_name = args.name.unwrap_or_else(|| { | ||
GuillaumeLagrange marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| // Extract filename from command path | ||
| let cmd = &args.command[0]; | ||
| std::path::Path::new(cmd).to_string_lossy().into_owned() | ||
| }); | ||
|
|
||
| // TODO: Better URI generation | ||
| let bench_uri = format!("standalone_run::{bench_name}"); | ||
|
|
||
| let hooks = InstrumentHooks::instance(); | ||
|
|
||
| // TODO: Stop impersonating codspeed-rust 🥸 | ||
| hooks | ||
| .set_integration("codspeed-rust", env!("CARGO_PKG_VERSION")) | ||
| .unwrap(); | ||
|
|
||
| const NUM_ITERATIONS: usize = 1; | ||
| let mut times_per_round_ns = Vec::with_capacity(NUM_ITERATIONS); | ||
|
|
||
| hooks.start_benchmark().unwrap(); | ||
| for _ in 0..NUM_ITERATIONS { | ||
| // Spawn the command | ||
| let mut child = process::Command::new(&args.command[0]) | ||
| .args(&args.command[1..]) | ||
| .spawn() | ||
| .context("Failed to spawn command")?; | ||
|
|
||
| // Start monotonic timer for this iteration | ||
| let bench_start = InstrumentHooks::current_timestamp(); | ||
|
|
||
| // Wait for the process to complete | ||
| let status = child.wait().context("Failed to wait for command")?; | ||
|
|
||
| // Measure elapsed time | ||
| let bench_end = InstrumentHooks::current_timestamp(); | ||
| hooks.add_benchmark_timestamps(bench_start, bench_end); | ||
|
|
||
| // Exit immediately if any iteration fails | ||
| if !status.success() { | ||
| bail!("Command failed with exit code: {:?}", status.code()); | ||
| } | ||
|
|
||
| // Calculate and store the elapsed time in nanoseconds | ||
| let elapsed_ns = (bench_end - bench_start) as u128; | ||
| times_per_round_ns.push(elapsed_ns); | ||
| } | ||
|
|
||
| hooks.stop_benchmark().unwrap(); | ||
| hooks.set_executed_benchmark(&bench_uri).unwrap(); | ||
|
|
||
| // Collect walltime results | ||
| let max_time_ns = times_per_round_ns.iter().copied().max(); | ||
| let walltime_benchmark = WalltimeBenchmark::from_runtime_data( | ||
| bench_name.clone(), | ||
| bench_uri.clone(), | ||
| vec![1; NUM_ITERATIONS], | ||
| times_per_round_ns, | ||
| max_time_ns, | ||
| ); | ||
|
|
||
| let walltime_results = WalltimeResults::from_benchmarks(vec![walltime_benchmark]) | ||
| .expect("Failed to create walltime results"); | ||
|
|
||
| walltime_results | ||
| .save_to_file( | ||
| std::env::var("CODSPEED_PROFILE_FOLDER") | ||
| .map(PathBuf::from) | ||
| .unwrap_or_else(|_| std::env::current_dir().unwrap().join(".codspeed")), | ||
| ) | ||
| .expect("Failed to save walltime results"); | ||
|
|
||
| Ok(()) | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,63 @@ | ||
| use anyhow::Context; | ||
| use anyhow::Result; | ||
| use codspeed::walltime_results::WalltimeBenchmark; | ||
| use serde::Deserialize; | ||
| use serde::Serialize; | ||
| use std::path::Path; | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| struct Instrument { | ||
| #[serde(rename = "type")] | ||
| type_: String, | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| struct Creator { | ||
| name: String, | ||
| version: String, | ||
| pid: u32, | ||
| } | ||
|
|
||
| #[derive(Debug, Serialize, Deserialize)] | ||
| pub struct WalltimeResults { | ||
| creator: Creator, | ||
| instrument: Instrument, | ||
| benchmarks: Vec<WalltimeBenchmark>, | ||
| } | ||
|
|
||
| impl WalltimeResults { | ||
| pub fn from_benchmarks(benchmarks: Vec<WalltimeBenchmark>) -> Result<Self> { | ||
| Ok(WalltimeResults { | ||
| instrument: Instrument { | ||
| type_: "walltime".to_string(), | ||
| }, | ||
| creator: Creator { | ||
| // TODO: Stop impersonating codspeed-rust 🥸 | ||
| name: "codspeed-rust".to_string(), | ||
GuillaumeLagrange marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| version: env!("CARGO_PKG_VERSION").to_string(), | ||
| pid: std::process::id(), | ||
| }, | ||
| benchmarks, | ||
| }) | ||
| } | ||
|
|
||
| pub fn save_to_file<P: AsRef<Path>>(&self, profile_folder: P) -> Result<()> { | ||
| let results_path = { | ||
| let results_dir = profile_folder.as_ref().join("results"); | ||
| std::fs::create_dir_all(&results_dir).with_context(|| { | ||
| format!( | ||
| "Failed to create results directory: {}", | ||
| results_dir.display() | ||
| ) | ||
| })?; | ||
|
|
||
| results_dir.join(format!("{}.json", self.creator.pid)) | ||
| }; | ||
|
|
||
| let file = std::fs::File::create(&results_path) | ||
| .with_context(|| format!("Failed to create file: {}", results_path.display()))?; | ||
| serde_json::to_writer_pretty(file, &self) | ||
| .with_context(|| format!("Failed to write JSON to file: {}", results_path.display()))?; | ||
| Ok(()) | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.