From 5a7cbe7ef77058eb59555e114758f44a9db45436 Mon Sep 17 00:00:00 2001 From: Alex Yusiuk <55661041+RRRadicalEdward@users.noreply.github.com> Date: Mon, 15 Apr 2024 11:19:18 +0300 Subject: [PATCH] feat: check if perf is installed (#317) --- src/lib.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib.rs b/src/lib.rs index 6ecbb8b..f6f030a 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -47,7 +47,16 @@ mod arch { verbose: bool, ignore_status: bool, ) -> Option { - let perf = env::var("PERF").unwrap_or_else(|_| "perf".to_string()); + let perf = if let Ok(path) = env::var("PERF") { + path + } else { + if Command::new("perf").arg("--help").status().is_err() { + eprintln!("perf is not installed or not present in $PATH"); + exit(1); + } + + String::from("perf") + }; let mut command = sudo_command(&perf, sudo); let args = custom_cmd.unwrap_or(format!("record -F {freq} --call-graph dwarf,16384 -g"));