From 0d7165e605e2bd60f3aae43a75fcc693f729dc5b Mon Sep 17 00:00:00 2001 From: Lucas Kent Date: Thu, 25 Jan 2024 21:09:16 +1100 Subject: [PATCH] Remove inferno dependency (#1434) --- Cargo.lock | 63 ----------- shotover-proxy/Cargo.toml | 1 - shotover-proxy/benches/windsock/profilers.rs | 26 +---- .../windsock/profilers/perf_flamegraph.rs | 107 ------------------ 4 files changed, 1 insertion(+), 196 deletions(-) delete mode 100644 shotover-proxy/benches/windsock/profilers/perf_flamegraph.rs diff --git a/Cargo.lock b/Cargo.lock index fc84fe546..7781b83fb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -59,7 +59,6 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "77c3a9648d43b9cd48db467b3f87fdd6e146bcc88ab0180006cef2179fe11d01" dependencies = [ "cfg-if", - "getrandom 0.2.12", "once_cell", "version_check", "zerocopy", @@ -167,12 +166,6 @@ version = "0.3.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "6b4930d2cb77ce62f89ee5d5289b4ac049559b1c45539271f5ed4fdc7db34545" -[[package]] -name = "arrayvec" -version = "0.7.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "96d30a06541fbafbc7f82ed10c06164cfbd2c401138f6addd8404629c4b16711" - [[package]] name = "async-compression" version = "0.4.6" @@ -2424,27 +2417,6 @@ dependencies = [ "serde", ] -[[package]] -name = "inferno" -version = "0.11.19" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "321f0f839cd44a4686e9504b0a62b4d69a50b62072144c71c68f5873c167b8d9" -dependencies = [ - "ahash", - "crossbeam-channel", - "crossbeam-utils", - "dashmap", - "indexmap 2.1.0", - "is-terminal", - "itoa", - "log", - "num-format", - "once_cell", - "quick-xml", - "rgb", - "str_stack", -] - [[package]] name = "inout" version = "0.1.3" @@ -2921,16 +2893,6 @@ dependencies = [ "serde", ] -[[package]] -name = "num-format" -version = "0.4.4" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a652d9771a63711fd3c3deb670acfbe5c30a4072e664d7a3bf5a9e1056ac72c3" -dependencies = [ - "arrayvec", - "itoa", -] - [[package]] name = "num-integer" version = "0.1.45" @@ -3457,15 +3419,6 @@ dependencies = [ "winapi", ] -[[package]] -name = "quick-xml" -version = "0.26.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7f50b1c63b38611e7d4d7f68b82d3ad0cc71a2ad2e7f61fc10f1328d917c93cd" -dependencies = [ - "memchr", -] - [[package]] name = "quote" version = "1.0.35" @@ -3812,15 +3765,6 @@ dependencies = [ "subtle", ] -[[package]] -name = "rgb" -version = "0.8.37" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "05aaa8004b64fd573fc9d002f4e632d51ad4f026c2b5ba95fcb6c2f32c2c47d8" -dependencies = [ - "bytemuck", -] - [[package]] name = "ring" version = "0.17.7" @@ -4525,7 +4469,6 @@ dependencies = [ "hex", "hex-literal", "hyper", - "inferno", "itertools 0.12.0", "nix", "opensearch", @@ -4693,12 +4636,6 @@ version = "1.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "a2eb9349b6444b326872e140eb1cf5e7c522154d69e7a0ffb0fb81c06b37543f" -[[package]] -name = "str_stack" -version = "0.1.0" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9091b6114800a5f2141aee1d1b9d6ca3592ac062dc5decb3764ec5895a47b4eb" - [[package]] name = "string" version = "0.3.0" diff --git a/shotover-proxy/Cargo.toml b/shotover-proxy/Cargo.toml index b8b741879..b99b56064 100644 --- a/shotover-proxy/Cargo.toml +++ b/shotover-proxy/Cargo.toml @@ -54,7 +54,6 @@ cql-ws = { git = "https://github.com/shotover/cql-ws" } opensearch = "2.1.0" serde_json = "1.0.103" time = { version = "0.3.25" } -inferno = { version = "0.11.15", default-features = false, features = ["multithreaded", "nameattr"] } hyper.workspace = true shell-quote.workspace = true diff --git a/shotover-proxy/benches/windsock/profilers.rs b/shotover-proxy/benches/windsock/profilers.rs index d30ab6d5c..e63306f8b 100644 --- a/shotover-proxy/benches/windsock/profilers.rs +++ b/shotover-proxy/benches/windsock/profilers.rs @@ -2,25 +2,21 @@ use self::{samply::Samply, shotover_metrics::ShotoverMetrics}; use crate::common::Shotover; use anyhow::Result; use aws_throwaway::Ec2Instance; -use perf_flamegraph::Perf; use std::{collections::HashMap, path::PathBuf}; use test_helpers::shotover_process::BinProcess; use tokio::sync::mpsc::UnboundedReceiver; use windsock::Profiling; -mod perf_flamegraph; mod samply; mod sar; mod shotover_metrics; pub struct ProfilerRunner { bench_name: String, - run_flamegraph: bool, run_samply: bool, run_shotover_metrics: bool, run_sys_monitor: bool, results_path: PathBuf, - perf: Option, shotover_metrics: Option, samply: Option, sys_monitor: Option>>, @@ -28,9 +24,6 @@ pub struct ProfilerRunner { impl ProfilerRunner { pub fn new(bench_name: String, profiling: Profiling) -> Self { - let run_flamegraph = profiling - .profilers_to_use - .contains(&"flamegraph".to_owned()); let run_samply = profiling.profilers_to_use.contains(&"samply".to_owned()); let run_sys_monitor = profiling .profilers_to_use @@ -41,12 +34,10 @@ impl ProfilerRunner { ProfilerRunner { bench_name, - run_flamegraph, run_sys_monitor, run_samply, run_shotover_metrics, results_path: profiling.results_path, - perf: None, shotover_metrics: None, samply: None, sys_monitor: None, @@ -54,18 +45,6 @@ impl ProfilerRunner { } pub async fn run(&mut self, shotover: &Option) { - self.perf = if self.run_flamegraph { - if let Some(shotover) = &shotover { - Some(Perf::new( - self.results_path.clone(), - shotover.child().id().unwrap(), - )) - } else { - panic!("flamegraph not supported when benching without shotover") - } - } else { - None - }; self.shotover_metrics = if self.run_shotover_metrics { if shotover.is_some() { Some(ShotoverMetrics::new(self.bench_name.clone(), "localhost")) @@ -92,7 +71,7 @@ impl ProfilerRunner { } pub fn shotover_profile(&self) -> Option<&'static str> { - if self.run_flamegraph || self.run_samply { + if self.run_samply { Some("profiling") } else { None @@ -102,9 +81,6 @@ impl ProfilerRunner { impl Drop for ProfilerRunner { fn drop(&mut self) { - if let Some(perf) = self.perf.take() { - perf.flamegraph(); - } if let Some(samply) = self.samply.take() { samply.wait(); } diff --git a/shotover-proxy/benches/windsock/profilers/perf_flamegraph.rs b/shotover-proxy/benches/windsock/profilers/perf_flamegraph.rs deleted file mode 100644 index 76cf1c202..000000000 --- a/shotover-proxy/benches/windsock/profilers/perf_flamegraph.rs +++ /dev/null @@ -1,107 +0,0 @@ -use inferno::collapse::perf::{Folder, Options as CollapseOptions}; -use inferno::collapse::Collapse; -use inferno::flamegraph::{from_reader, Options}; -use std::fs::File; -use std::io::{BufReader, BufWriter}; -use std::path::PathBuf; -use std::process::{Child, Command}; - -pub struct Perf { - child: Child, - path: PathBuf, - perf_file: PathBuf, -} - -impl Perf { - /// Begin recording perf data to perf.data - pub fn new(path: PathBuf, pid: u32) -> Perf { - let perf_file = path.join("perf.data"); - // remove perf.data if it exists to avoid generating perf.data.old clutter - std::fs::remove_file(&perf_file).ok(); - - // Run `sudo ls` so that we can get sudo to stop asking for password for a while. - // It also lets us block until the user has entered the password, otherwise the rest of the test would continue before `perf` has started. - // TODO: It would be more robust to get a single root prompt and then keep feeding commands into it. - // But that would require a bunch of work so its out of scope for now. - test_helpers::run_command("sudo", &["ls"]).unwrap(); - - let mut command = Command::new("sudo"); - command.args([ - "perf", - "record", - "-F", - "997", - "--call-graph", - "dwarf,16384", - "-g", - "-o", - perf_file.to_str().unwrap(), - "-p", - &pid.to_string(), - ]); - - Perf { - child: command.spawn().unwrap(), - path, - perf_file, - } - } - - /// Blocks until the recorded process has terminated - /// Generates a flamegraph at flamegraph.svg - pub fn flamegraph(mut self) { - self.child.wait().unwrap(); - - test_helpers::run_command( - "sudo", - &[ - "chown", - &std::env::var("USER").unwrap(), - self.perf_file.to_str().unwrap(), - ], - ) - .unwrap(); - - let output = Command::new("perf") - .args([ - "script", - "-i", - self.perf_file.to_str().unwrap(), - // --inline (the default) is so slow on CI that it times out after 5h 😭 - //https://bugzilla.kernel.org/show_bug.cgi?id=202677 - if std::env::var("CI").is_ok() { - "--no-inline" - } else { - "--inline" - }, - ]) - .output() - .unwrap(); - if !output.status.success() { - panic!( - "unable to run 'perf script': ({}) {}", - output.status, - std::str::from_utf8(&output.stderr).unwrap() - ); - } - let output = output.stdout; - - let perf_reader = BufReader::new(&*output); - let mut collapsed = vec![]; - let collapsed_writer = BufWriter::new(&mut collapsed); - - Folder::from(CollapseOptions::default()) - .collapse(perf_reader, collapsed_writer) - .unwrap(); - - let collapsed_reader = BufReader::new(&*collapsed); - - let flamegraph_file = self.path.join("flamegraph.svg"); - println!("writing flamegraph to {flamegraph_file:?}"); - let flamegraph_writer = BufWriter::new(File::create(flamegraph_file).unwrap()); - - let mut options = Options::default(); - options.title = self.path.file_name().unwrap().to_str().unwrap().to_owned(); - from_reader(&mut options, collapsed_reader, flamegraph_writer).unwrap(); - } -}