difftreelog
fix only build benchmarker for x86_64-linux
in: master
3 files changed
xtask/Cargo.tomldiffbeforeafterboth--- a/xtask/Cargo.toml
+++ b/xtask/Cargo.toml
@@ -18,5 +18,5 @@
xshell.workspace = true
clap = { workspace = true, features = ["derive"] }
-[target.'cfg(target_os = "linux")'.dependencies]
+[target.'cfg(all(target_arch = "x86_64", target_os = "linux"))'.dependencies]
nix.workspace = true
xtask/src/bench.rsdiffbeforeafterboth--- a/xtask/src/bench.rs
+++ b/xtask/src/bench.rs
@@ -1,3 +1,5 @@
+#![allow(clippy::cast_precision_loss)]
+
use std::{
ffi::OsString,
mem,
xtask/src/main.rsdiffbeforeafterboth1use anyhow::Result;2#[cfg(not(target_os = "linux"))]3use anyhow::bail;4use clap::Parser;5use xshell::{Shell, cmd};67#[cfg(target_os = "linux")]8mod bench;9mod sourcegen;1011#[derive(Parser)]12enum Opts {13 /// Generate files for rowan parser14 Sourcegen,15 /// Profile file execution16 Profile {17 #[arg(long, default_value = "true")]18 hyperfine: bool,19 #[arg(long)]20 callgrind: bool,21 #[arg(long)]22 cachegrind: bool,23 #[arg(long, default_value = env!("TARGET_PLATFORM"))]24 target: String,25 args: Vec<String>,26 },27 /// Run all lints enforced by this repo28 Lint {29 /// Also fix found issues when possible.30 #[arg(long)]31 fix: bool,32 },33 /// Build and run test file from `bindings/c`34 TestCBindings {35 #[arg(long, default_value = env!("TARGET_PLATFORM"))]36 target: String,37 /// Which bindings file to build and run38 #[arg(long, default_value = "libjsonnet_test_file")]39 test_file: String,40 args: Vec<String>,41 },42 /// Benchmark a command: repeated runs, reports time + RSS stats (Linux only)43 Bench {44 #[arg(long, default_value_t = 10)]45 runs: u32,46 #[arg(long, default_value_t = 1)]47 warmup: u32,48 /// Show command output49 #[arg(long, short = 'q')]50 output: bool,51 #[arg(trailing_var_arg = true, required = true)]52 args: Vec<String>,53 },54}5556fn main() -> Result<()> {57 let sh = Shell::new()?;58 match Opts::parse() {59 Opts::Sourcegen => sourcegen::generate_ungrammar(),60 Opts::Profile {61 hyperfine,62 callgrind,63 cachegrind,64 args,65 target,66 } => {67 let out = sh.create_temp_dir()?;6869 cmd!(sh, "cargo build --target={target} --profile releasedebug").run()?;70 let built = format!("./target/{target}/releasedebug/jrsonnet");71 let bench_cmd = format!("{built} {}", args.join(" "));72 if hyperfine {73 cmd!(sh, "hyperfine {bench_cmd}").run()?;74 }75 if callgrind {76 let args = args.clone();77 let mut callgrind_out = out.path().to_owned();78 callgrind_out.push("callgrind.out.1");79 cmd!(sh, "valgrind --tool=callgrind --dump-instr=yes --collect-jumps=yes --callgrind-out-file={callgrind_out} {built} {args...}").run()?;80 cmd!(sh, "kcachegrind {callgrind_out}").run()?;81 }82 if cachegrind {83 let mut cachegrind_out = out.path().to_owned();84 cachegrind_out.push("cachegrind.out.1");85 cmd!(86 sh,87 "valgrind --tool=cachegrind --cachegrind-out-file={cachegrind_out} {built} {args...}"88 )89 .run()?;90 cmd!(sh, "kcachegrind {cachegrind_out}").run()?;91 }9293 Ok(())94 }95 Opts::Lint { fix } => {96 let fmt_check = if fix { None } else { Some("--check") };97 cmd!(sh, "cargo fmt {fmt_check...}").run()?;98 Ok(())99 }100 Opts::TestCBindings {101 target,102 test_file,103 args,104 } => {105 cmd!(106 sh,107 "cargo build -p libjsonnet --target={target} --release --no-default-features --features=interop-common,interop-threading"108 )109 .run()?;110 let built = format!("./target/{target}/release/libjsonnet.a");111 let c_bindings = "./bindings/c/";112 cmd!(sh, "cp {built} {c_bindings}").run()?;113 sh.change_dir(c_bindings);114115 // TODO: Pass target to gcc?116 cmd!(sh, "gcc -c {test_file}.c").run()?;117 cmd!(sh, "gcc -o {test_file} -lc -lm {test_file}.o libjsonnet.a").run()?;118 let sh = Shell::new()?;119120 cmd!(sh, "{c_bindings}{test_file} {args...}").run()?;121122 Ok(())123 }124 #[cfg(target_os = "linux")]125 Opts::Bench {126 runs,127 warmup,128 output,129 args,130 } => bench::bench_cmd(&args, runs, warmup, output),131 }132}