Skip to content

Commit 62dbe1c

Browse files
authored
bencher: add solana cli version to markdown (#97)
1 parent a2714ca commit 62dbe1c

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

bencher/src/lib.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ use {
6464
solana_account::Account,
6565
solana_instruction::Instruction,
6666
solana_pubkey::Pubkey,
67-
std::path::PathBuf,
67+
std::{path::PathBuf, process::Command},
6868
};
6969

7070
/// A bench is a tuple of a name, an instruction, and a list of accounts.
@@ -113,6 +113,7 @@ impl<'a> MolluskComputeUnitBencher<'a> {
113113

114114
/// Execute the benches.
115115
pub fn execute(&mut self) {
116+
let solana_version = get_solana_version();
116117
let bench_results = std::mem::take(&mut self.benches)
117118
.into_iter()
118119
.map(|(name, instruction, accounts)| {
@@ -131,6 +132,15 @@ impl<'a> MolluskComputeUnitBencher<'a> {
131132
MolluskComputeUnitBenchResult::new(name, result)
132133
})
133134
.collect::<Vec<_>>();
134-
write_results(&self.out_dir, bench_results);
135+
write_results(&self.out_dir, &solana_version, bench_results);
136+
}
137+
}
138+
139+
fn get_solana_version() -> String {
140+
match Command::new("solana").arg("--version").output() {
141+
Ok(output) if output.status.success() => {
142+
String::from_utf8_lossy(&output.stdout).trim().to_string()
143+
}
144+
_ => "Unknown".to_string(),
135145
}
136146
}

bencher/src/result.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ impl<'a> MolluskComputeUnitBenchResult<'a> {
1919
}
2020
}
2121

22-
pub(crate) fn write_results(out_dir: &Path, results: Vec<MolluskComputeUnitBenchResult>) {
22+
pub(crate) fn write_results(
23+
out_dir: &Path,
24+
solana_version: &str,
25+
results: Vec<MolluskComputeUnitBenchResult>,
26+
) {
2327
let path = out_dir.join("compute_units.md");
2428

2529
// Load the existing bench content and parse the most recent table.
@@ -34,7 +38,7 @@ pub(crate) fn write_results(out_dir: &Path, results: Vec<MolluskComputeUnitBench
3438
.map(|content| parse_last_md_table(content));
3539

3640
// Prepare to write a new table.
37-
let mut md_table = md_header();
41+
let mut md_table = md_header(solana_version);
3842

3943
// Evaluate the results against the previous table, if any.
4044
// If there are changes, write a new table.
@@ -76,15 +80,17 @@ pub(crate) fn write_results(out_dir: &Path, results: Vec<MolluskComputeUnitBench
7680
}
7781
}
7882

79-
fn md_header() -> String {
83+
fn md_header(solana_version: &str) -> String {
8084
let now: DateTime<Utc> = Utc::now();
8185
format!(
8286
r#"#### Compute Units: {}
8387
88+
Solana CLI Version: {}
89+
8490
| Name | CUs | Delta |
8591
|------|------|-------|
8692
"#,
87-
now
93+
now, solana_version,
8894
)
8995
}
9096

0 commit comments

Comments
 (0)