From 128c77252ad2f2b6f13f2045b95d2bcfbb7cb63f Mon Sep 17 00:00:00 2001 From: Casper Verhaar Date: Wed, 6 Oct 2021 10:19:53 +0200 Subject: [PATCH 1/3] Bump MSRV to 1.52.0 --- azure-pipelines.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 1f3c3781..f7b496e8 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -2,7 +2,7 @@ jobs: - template: default.yml@templates parameters: codecov_token: $(CODECOV_TOKEN_SECRET) - minrust: 1.46.0 + minrust: 1.52.0 env: RUST_BACKTRACE: 1 setup: From 6b6d93c2c61c04676dad836e0f0104071f46f587 Mon Sep 17 00:00:00 2001 From: Casper Verhaar Date: Wed, 6 Oct 2021 10:36:26 +0200 Subject: [PATCH 2/3] Fix `clippy` warnings --- src/collapse/vtune.rs | 4 ++-- src/flamegraph/attrs.rs | 8 ++++---- src/flamegraph/color/palettes.rs | 6 +----- 3 files changed, 7 insertions(+), 11 deletions(-) diff --git a/src/collapse/vtune.rs b/src/collapse/vtune.rs index 6a01188c..9b7e76bc 100644 --- a/src/collapse/vtune.rs +++ b/src/collapse/vtune.rs @@ -122,9 +122,9 @@ impl From for Folder { impl Folder { fn line_parts<'a>(&self, line: &'a str) -> Option<(&'a str, &'a str, &'a str)> { - let mut line = if line.starts_with('"') { + let mut line = if let Some(line) = line.strip_prefix('"') { // The function name will be in quotes if it contains spaces. - line[1..].splitn(2, "\",") + line.splitn(2, "\",") } else { // We split on a string because we need to match the type of the other if branch. #[allow(clippy::single_char_pattern)] diff --git a/src/flamegraph/attrs.rs b/src/flamegraph/attrs.rs index 5091d143..bb074ca4 100644 --- a/src/flamegraph/attrs.rs +++ b/src/flamegraph/attrs.rs @@ -1,6 +1,6 @@ use std::fs::File; use std::io::{self, BufRead, BufReader}; -use std::path::PathBuf; +use std::path::Path; use ahash::AHashMap; use indexmap::map::Entry; @@ -27,7 +27,7 @@ impl FuncFrameAttrsMap { /// /// Each line should consist of a function name, a tab (`\t`), and then a sequence of /// tab-separated `name=value` pairs. - pub fn from_file(path: &PathBuf) -> io::Result { + pub fn from_file(path: &Path) -> io::Result { let file = BufReader::new(File::open(path)?); FuncFrameAttrsMap::from_reader(file) } @@ -158,8 +158,8 @@ impl<'a> Iterator for AttrIter<'a> { warn!("no value after \"=\" for extra attribute {}", name); } - let (value, rest) = if rest.starts_with('"') { - if let Some(eq) = rest[1..].find('"') { + let (value, rest) = if let Some(stripped_rest) = rest.strip_prefix('"') { + if let Some(eq) = stripped_rest.find('"') { (&rest[1..=eq], &rest[eq + 1..]) } else { warn!("no end quote found for extra attribute {}", name); diff --git a/src/flamegraph/color/palettes.rs b/src/flamegraph/color/palettes.rs index 20f9f5ef..31263116 100644 --- a/src/flamegraph/color/palettes.rs +++ b/src/flamegraph/color/palettes.rs @@ -22,11 +22,7 @@ pub(super) mod java { } } - let java_prefix = if name.starts_with('L') { - &name[1..] - } else { - name - }; + let java_prefix = name.strip_prefix('L').unwrap_or(name); if name.contains("::") || name.starts_with("-[") || name.starts_with("+[") { // C++ or Objective C From a9e612cd8964ff1ecd48b24adb3a4d505b15f4b9 Mon Sep 17 00:00:00 2001 From: Casper Verhaar Date: Wed, 6 Oct 2021 11:48:32 +0200 Subject: [PATCH 3/3] Fix more `clippy` warnings This fixes warnings emitted using Rust 1.55.0, which were not yet warnings in 1.52.0. --- src/bin/flamegraph.rs | 2 +- src/collapse/perf.rs | 6 ++---- src/flamegraph/mod.rs | 16 ++++++++-------- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/bin/flamegraph.rs b/src/bin/flamegraph.rs index 129a825b..4c443662 100644 --- a/src/bin/flamegraph.rs +++ b/src/bin/flamegraph.rs @@ -261,7 +261,7 @@ impl<'a> Opt { #[cfg(feature = "nameattr")] fn set_func_frameattrs(&self, options: &mut Options) { if let Some(file) = &self.nameattr { - match FuncFrameAttrsMap::from_file(&file) { + match FuncFrameAttrsMap::from_file(file) { Ok(m) => { options.func_frameattrs = m; } diff --git a/src/collapse/perf.rs b/src/collapse/perf.rs index a52d24d1..16fe6f52 100644 --- a/src/collapse/perf.rs +++ b/src/collapse/perf.rs @@ -586,15 +586,13 @@ fn with_module_fallback(module: &str, func: &str, pc: &str, include_addrs: bool) // output string is a bit longer than rawfunc but not much let mut res = String::with_capacity(func.len() + 12); + res.push('['); + res.push_str(func); if include_addrs { - res.push('['); - res.push_str(func); res.push_str(" <"); res.push_str(pc); res.push_str(">]"); } else { - res.push('['); - res.push_str(func); res.push(']'); } diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 69024cae..3c438fb4 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -456,7 +456,7 @@ where error!("No stack counts found"); // emit an error message SVG, for tools automating flamegraph use let imageheight = opt.font_size * 5; - svg::write_header(&mut svg, imageheight, &opt)?; + svg::write_header(&mut svg, imageheight, opt)?; svg::write_str( &mut svg, &mut buffer, @@ -493,7 +493,7 @@ where // draw canvas, and embed interactive JavaScript program let imageheight = ((depthmax + 1) * opt.frame_height) + opt.ypad1() + opt.ypad2(); - svg::write_header(&mut svg, imageheight, &opt)?; + svg::write_header(&mut svg, imageheight, opt)?; let (bgcolor1, bgcolor2) = color::bgcolor_for(opt.bgcolors, opt.colors); let style_options = StyleOptions { @@ -502,7 +502,7 @@ where bgcolor2, }; - svg::write_prelude(&mut svg, &style_options, &opt)?; + svg::write_prelude(&mut svg, &style_options, opt)?; // Used when picking color parameters at random, when no option determines how to pick these // parameters. We instanciate it here because it may be called once for each iteration in the @@ -573,7 +573,7 @@ where write!(buffer, "all ({} {}, 100%)", samples_txt, opt.count_name) } else { let pct = (100 * samples) as f64 / (timemax as f64 * opt.factor); - let function = deannotate(&frame.location.function); + let function = deannotate(frame.location.function); match frame.delta { None => write!( buffer, @@ -634,7 +634,7 @@ where let colors = opt.colors; let hash = opt.hash; let deterministic = opt.deterministic; - palette_map.find_color_for(&frame.location.function, |name| { + palette_map.find_color_for(frame.location.function, |name| { color::color(colors, hash, deterministic, name, &mut thread_rng) }) } else { @@ -653,7 +653,7 @@ where .trunc() as usize; let text: svg::TextArgument<'_> = if fitchars >= 3 { // room for one char plus two dots - let f = deannotate(&frame.location.function); + let f = deannotate(frame.location.function); // TODO: use Unicode grapheme clusters instead if f.len() < fitchars { @@ -718,11 +718,11 @@ fn write_container_start<'a, W: Write>( let mut has_href = false; if let Some(frame_attributes) = frame_attributes { if frame_attributes.attrs.contains_key("xlink:href") { - write_container_attributes(cache_a, &frame_attributes); + write_container_attributes(cache_a, frame_attributes); svg.write_event(&cache_a)?; has_href = true; } else { - write_container_attributes(cache_g, &frame_attributes); + write_container_attributes(cache_g, frame_attributes); svg.write_event(&cache_g)?; } if let Some(ref t) = frame_attributes.title {