From 65f9f09e68170244eca06d4fb68fddeeca460717 Mon Sep 17 00:00:00 2001 From: Jon Gjengset Date: Sat, 20 Jun 2020 14:50:17 -0400 Subject: [PATCH] Mark all Option types non_exhaustive This is a breaking change. See also https://github.com/rust-lang/rust/issues/70564#issuecomment-647031324 for why this change is a little sad. --- CHANGELOG.md | 12 +- Cargo.toml | 2 + azure-pipelines.yml | 30 ++-- benches/flamegraph.rs | 2 +- src/bin/collapse-dtrace.rs | 11 +- src/bin/collapse-guess.rs | 9 +- src/bin/collapse-perf.rs | 21 ++- src/bin/collapse-sample.rs | 9 +- src/bin/collapse-vtune.rs | 9 +- src/bin/flamegraph.rs | 55 ++++--- src/collapse/common.rs | 3 + src/collapse/dtrace.rs | 1 + src/collapse/guess.rs | 1 + src/collapse/perf.rs | 1 + src/collapse/sample.rs | 1 + src/collapse/vtune.rs | 1 + src/flamegraph/mod.rs | 1 + tests/collapse-dtrace.rs | 28 ++-- tests/collapse-sample.rs | 6 +- tests/collapse-vtune.rs | 6 +- tests/flamegraph.rs | 288 +++++++++++++++---------------------- 21 files changed, 223 insertions(+), 274 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6a25a911..3a0d35b4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,10 +6,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] ### Added -- Flame chart mode. Flame charts put the passage of time on the x-axis instead of the alphabet. [#125](https://github.com/jonhoo/inferno/pull/125) + + - Flame chart mode. Flame charts put the passage of time on the x-axis instead of the alphabet. [#125](https://github.com/jonhoo/inferno/pull/125) + - `cargo hack` to check that all features compile. [#181](https://github.com/jonhoo/inferno/pull/181) ### Changed + - All `Options` are now marked as `#[non_exhaustive]` so that we can + add options without making that a breaking change. This also makes + feature-dependent fields (like `func_nameattr` on `flamegraph`) okay. + Unfortunately, it also means that function record update syntax won't + work any more (`Options { ..., ..Default::default() }`). See + https://github.com/rust-lang/rust/issues/70564#issuecomment-647031324 + for details. [#181](https://github.com/jonhoo/inferno/pull/181) + ### Removed ## [0.9.9] - 2020-06-03 diff --git a/Cargo.toml b/Cargo.toml index 77b9a478..ca9abe16 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -96,7 +96,9 @@ required-features = ["cli"] [[bench]] name = "collapse" harness = false +required-features = ["multithreaded"] [[bench]] name = "flamegraph" harness = false +required-features = ["multithreaded"] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index 3610ca5a..5dc8d1dd 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -1,13 +1,25 @@ jobs: - - template: default.yml@templates - parameters: - codecov_token: $(CODECOV_TOKEN_SECRET) - minrust: 1.40.0 - env: - RUST_BACKTRACE: 1 - setup: - - checkout: self - submodules: recursive + - template: default.yml@templates + parameters: + codecov_token: $(CODECOV_TOKEN_SECRET) + minrust: 1.40.0 + env: + RUST_BACKTRACE: 1 + setup: + - checkout: self + submodules: recursive + - job: features + displayName: "Check feature combinations" + pool: + vmImage: ubuntu-latest + steps: + - template: install-rust.yml@templates + parameters: + rust: stable + - script: cargo install cargo-hack + displayName: install cargo-hack + - script: cargo hack + displayName: cargo hack --feature-powerset check --all-targets resources: repositories: diff --git a/benches/flamegraph.rs b/benches/flamegraph.rs index 7a5804c7..180c9bd6 100644 --- a/benches/flamegraph.rs +++ b/benches/flamegraph.rs @@ -42,5 +42,5 @@ macro_rules! flamegraph_benchmarks { flamegraph_benchmarks! { flamegraph: ("tests/data/collapse-perf/results/example-perf-stacks-collapsed.txt", - Options { reverse_stack_order: true, ..Default::default() }) + { let mut opt = Options::default(); opt.reverse_stack_order = true; opt }) } diff --git a/src/bin/collapse-dtrace.rs b/src/bin/collapse-dtrace.rs index 292b7a25..76493ee2 100644 --- a/src/bin/collapse-dtrace.rs +++ b/src/bin/collapse-dtrace.rs @@ -60,13 +60,10 @@ struct Opt { impl Opt { fn into_parts(self) -> (Option, Options) { - ( - self.infile, - Options { - includeoffset: self.includeoffset, - nthreads: self.nthreads, - }, - ) + let mut options = Options::default(); + options.includeoffset = self.includeoffset; + options.nthreads = self.nthreads; + (self.infile, options) } } diff --git a/src/bin/collapse-guess.rs b/src/bin/collapse-guess.rs index eddbfdd0..889d2690 100644 --- a/src/bin/collapse-guess.rs +++ b/src/bin/collapse-guess.rs @@ -53,12 +53,9 @@ struct Opt { impl Opt { fn into_parts(self) -> (Option, Options) { - ( - self.infile, - Options { - nthreads: self.nthreads, - }, - ) + let mut options = Options::default(); + options.nthreads = self.nthreads; + (self.infile, options) } } diff --git a/src/bin/collapse-perf.rs b/src/bin/collapse-perf.rs index ae2bfc5b..41b9d2c2 100644 --- a/src/bin/collapse-perf.rs +++ b/src/bin/collapse-perf.rs @@ -84,18 +84,15 @@ struct Opt { impl Opt { fn into_parts(self) -> (Option, Options) { - ( - self.infile, - Options { - include_pid: self.pid, - include_tid: self.tid, - include_addrs: self.addrs, - annotate_jit: self.jit || self.all, - annotate_kernel: self.kernel || self.all, - event_filter: self.event_filter, - nthreads: self.nthreads, - }, - ) + let mut options = Options::default(); + options.include_pid = self.pid; + options.include_tid = self.tid; + options.include_addrs = self.addrs; + options.annotate_jit = self.jit || self.all; + options.annotate_kernel = self.kernel || self.all; + options.event_filter = self.event_filter; + options.nthreads = self.nthreads; + (self.infile, options) } } diff --git a/src/bin/collapse-sample.rs b/src/bin/collapse-sample.rs index 52e6d4b6..41c941b6 100644 --- a/src/bin/collapse-sample.rs +++ b/src/bin/collapse-sample.rs @@ -40,12 +40,9 @@ struct Opt { impl Opt { fn into_parts(self) -> (Option, Options) { - ( - self.infile, - Options { - no_modules: self.no_modules, - }, - ) + let mut options = Options::default(); + options.no_modules = self.no_modules; + (self.infile, options) } } diff --git a/src/bin/collapse-vtune.rs b/src/bin/collapse-vtune.rs index 19979985..629b5651 100644 --- a/src/bin/collapse-vtune.rs +++ b/src/bin/collapse-vtune.rs @@ -42,12 +42,9 @@ struct Opt { impl Opt { fn into_parts(self) -> (Option, Options) { - ( - self.infile, - Options { - no_modules: self.no_modules, - }, - ) + let mut options = Options::default(); + options.no_modules = self.no_modules; + (self.infile, options) } } diff --git a/src/bin/flamegraph.rs b/src/bin/flamegraph.rs index b1607cd7..5640f157 100644 --- a/src/bin/flamegraph.rs +++ b/src/bin/flamegraph.rs @@ -387,36 +387,31 @@ mod tests { ]; let opt = Opt::from_iter_safe(args).unwrap(); let (infiles, options) = opt.into_parts(); - let expected_options = Options { - colors: Palette::from_str("purple").unwrap(), - search_color: color::SearchColor::from_str("#203040").unwrap(), - title: "Test Title".to_string(), - image_width: Some(100), - frame_height: 500, - min_width: 90.1, - font_type: "Helvetica".to_string(), - font_size: 13, - font_width: 10.5, - text_truncate_direction: TextTruncateDirection::Right, - count_name: "test count name".to_string(), - name_type: "test name type".to_string(), - factor: 0.1, - notes: "Test notes".to_string(), - subtitle: Some("Test Subtitle".to_string()), - bgcolors: Some(color::BackgroundColor::Blue), - hash: true, - palette_map: Default::default(), - #[cfg(feature = "nameattr")] - func_frameattrs: Default::default(), - direction: Direction::Inverted, - negate_differentials: true, - pretty_xml: true, - no_sort: false, - reverse_stack_order: true, - no_javascript: true, - color_diffusion: false, - flame_chart: false, - }; + let mut expected_options = Options::default(); + expected_options.colors = Palette::from_str("purple").unwrap(); + expected_options.search_color = color::SearchColor::from_str("#203040").unwrap(); + expected_options.title = "Test Title".to_string(); + expected_options.image_width = Some(100); + expected_options.frame_height = 500; + expected_options.min_width = 90.1; + expected_options.font_type = "Helvetica".to_string(); + expected_options.font_size = 13; + expected_options.font_width = 10.5; + expected_options.text_truncate_direction = TextTruncateDirection::Right; + expected_options.count_name = "test count name".to_string(); + expected_options.name_type = "test name type".to_string(); + expected_options.factor = 0.1; + expected_options.notes = "Test notes".to_string(); + expected_options.subtitle = Some("Test Subtitle".to_string()); + expected_options.bgcolors = Some(color::BackgroundColor::Blue); + expected_options.hash = true; + expected_options.direction = Direction::Inverted; + expected_options.negate_differentials = true; + expected_options.pretty_xml = true; + expected_options.no_sort = false; + expected_options.reverse_stack_order = true; + expected_options.no_javascript = true; + expected_options.color_diffusion = false; assert_eq!(options, expected_options); assert_eq!(infiles.len(), 2, "expected 2 input files"); diff --git a/src/collapse/common.rs b/src/collapse/common.rs index eaf98bd2..46d74d43 100644 --- a/src/collapse/common.rs +++ b/src/collapse/common.rs @@ -1,6 +1,8 @@ use std::borrow::Cow; use std::io; +#[cfg(feature = "multithreaded")] use std::mem; +#[cfg(feature = "multithreaded")] use std::sync::Arc; use ahash::AHashMap; @@ -33,6 +35,7 @@ pub(crate) const DEFAULT_NSTACKS_PER_JOB: usize = 100; /// A guess at the number of bytes contained in any given stack of any given format. /// Used to calculate the initial capacity of the vector used for sending input /// data across threads. +#[cfg(feature = "multithreaded")] const NBYTES_PER_STACK_GUESS: usize = 1024; const RUST_HASH_LENGTH: usize = 17; diff --git a/src/collapse/dtrace.rs b/src/collapse/dtrace.rs index a132fcc8..55b1cc58 100644 --- a/src/collapse/dtrace.rs +++ b/src/collapse/dtrace.rs @@ -8,6 +8,7 @@ use crate::collapse::common::{self, CollapsePrivate, Occurrences}; /// `dtrace` folder configuration options. #[derive(Clone, Debug)] +#[non_exhaustive] pub struct Options { /// Include function offset (except leafs). /// diff --git a/src/collapse/guess.rs b/src/collapse/guess.rs index 332d6fda..10cf6838 100644 --- a/src/collapse/guess.rs +++ b/src/collapse/guess.rs @@ -9,6 +9,7 @@ const LINES_PER_ITERATION: usize = 10; /// Folder configuration options. #[derive(Clone, Debug)] +#[non_exhaustive] pub struct Options { /// The number of threads to use. /// diff --git a/src/collapse/perf.rs b/src/collapse/perf.rs index f8634f6c..02c1a918 100644 --- a/src/collapse/perf.rs +++ b/src/collapse/perf.rs @@ -24,6 +24,7 @@ mod logging { /// `perf` folder configuration options. #[derive(Clone, Debug)] +#[non_exhaustive] pub struct Options { /// Annotate JIT functions with a `_[j]` suffix. /// diff --git a/src/collapse/sample.rs b/src/collapse/sample.rs index 79c232f7..68fd10d6 100644 --- a/src/collapse/sample.rs +++ b/src/collapse/sample.rs @@ -30,6 +30,7 @@ static END_LINE: &str = "Total number in stack"; /// `sample` folder configuration options. #[derive(Clone, Debug)] +#[non_exhaustive] pub struct Options { /// Don't include modules with function names. /// diff --git a/src/collapse/vtune.rs b/src/collapse/vtune.rs index 0841680a..c90ac4cb 100644 --- a/src/collapse/vtune.rs +++ b/src/collapse/vtune.rs @@ -10,6 +10,7 @@ static HEADER: &str = "Function Stack,CPU Time:Self,Module"; /// `vtune` folder configuration options. #[derive(Clone, Debug)] +#[non_exhaustive] pub struct Options { /// Don't include modules with function names. /// diff --git a/src/flamegraph/mod.rs b/src/flamegraph/mod.rs index 75b496f5..165df125 100644 --- a/src/flamegraph/mod.rs +++ b/src/flamegraph/mod.rs @@ -92,6 +92,7 @@ pub mod defaults { /// Configure the flame graph. #[derive(Debug, PartialEq)] +#[non_exhaustive] pub struct Options<'a> { /// The color palette to use when plotting. pub colors: color::Palette, diff --git a/tests/collapse-dtrace.rs b/tests/collapse-dtrace.rs index 72c87900..7fab4ac4 100644 --- a/tests/collapse-dtrace.rs +++ b/tests/collapse-dtrace.rs @@ -46,15 +46,11 @@ fn collapse_dtrace_compare_to_upstream() { fn collapse_dtrace_compare_to_upstream_with_offsets() { let test_file = "./flamegraph/example-dtrace-stacks.txt"; let result_file = "./tests/data/collapse-dtrace/results/dtrace-example-offsets.txt"; - test_collapse_dtrace( - test_file, - result_file, - Options { - includeoffset: true, - ..Default::default() - }, - ) - .unwrap() + + let mut options = Options::default(); + options.includeoffset = true; + + test_collapse_dtrace(test_file, result_file, options).unwrap() } #[test] @@ -80,15 +76,11 @@ fn collapse_dtrace_compare_to_flamegraph_bug() { // https://github.com/brendangregg/FlameGraph/issues/202 let test_file = "./tests/data/collapse-dtrace/flamegraph-bug.txt"; let result_file = "./tests/data/collapse-dtrace/results/flamegraph-bug.txt"; - test_collapse_dtrace( - test_file, - result_file, - Options { - includeoffset: true, - ..Default::default() - }, - ) - .unwrap() + + let mut options = Options::default(); + options.includeoffset = true; + + test_collapse_dtrace(test_file, result_file, options).unwrap() } #[test] diff --git a/tests/collapse-sample.rs b/tests/collapse-sample.rs index 7b7e4983..73c3ab79 100644 --- a/tests/collapse-sample.rs +++ b/tests/collapse-sample.rs @@ -43,7 +43,11 @@ fn collapse_sample_default() { fn collapse_sample_no_modules() { let test_file = "./tests/data/collapse-sample/sample.txt"; let result_file = "./tests/data/collapse-sample/results/sample-no-modules.txt"; - test_collapse_sample(test_file, result_file, Options { no_modules: true }).unwrap() + + let mut options = Options::default(); + options.no_modules = true; + + test_collapse_sample(test_file, result_file, options).unwrap() } #[test] diff --git a/tests/collapse-vtune.rs b/tests/collapse-vtune.rs index 956d4a32..64aaaf21 100644 --- a/tests/collapse-vtune.rs +++ b/tests/collapse-vtune.rs @@ -43,7 +43,11 @@ fn collapse_vtune_default() { fn collapse_vtune_no_modules() { let test_file = "./tests/data/collapse-vtune/vtune.csv"; let result_file = "./tests/data/collapse-vtune/results/vtune-no-modules.txt"; - test_collapse_vtune(test_file, result_file, Options { no_modules: true }).unwrap() + + let mut options = Options::default(); + options.no_modules = true; + + test_collapse_vtune(test_file, result_file, options).unwrap() } #[test] diff --git a/tests/flamegraph.rs b/tests/flamegraph.rs index d8d9421f..13a00f20 100644 --- a/tests/flamegraph.rs +++ b/tests/flamegraph.rs @@ -126,12 +126,10 @@ fn flamegraph_colors_java() { let input_file = "./flamegraph/test/results/perf-java-stacks-01-collapsed-all.txt"; let expected_result_file = "./tests/data/flamegraph/colors/java.svg"; - let options = flamegraph::Options { - colors: Palette::from_str("java").unwrap(), - bgcolors: Some(BackgroundColor::from_str("blue").unwrap()), - hash: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.colors = Palette::from_str("java").unwrap(); + options.bgcolors = Some(BackgroundColor::from_str("blue").unwrap()); + options.hash = true; test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -141,12 +139,10 @@ fn flamegraph_colors_js() { let input_file = "./flamegraph/test/results/perf-js-stacks-01-collapsed-all.txt"; let expected_result_file = "./tests/data/flamegraph/colors/js.svg"; - let options = flamegraph::Options { - colors: Palette::from_str("js").unwrap(), - bgcolors: Some(BackgroundColor::from_str("green").unwrap()), - hash: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.colors = Palette::from_str("js").unwrap(); + options.bgcolors = Some(BackgroundColor::from_str("green").unwrap()); + options.hash = true; test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -164,10 +160,8 @@ fn flamegraph_differential_negated() { let input_file = "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/differential/diff-negated.svg"; - let options = Options { - negate_differentials: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.negate_differentials = true; test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -175,10 +169,8 @@ fn flamegraph_differential_negated() { fn flamegraph_collor_diffusion() { let input_file = "./flamegraph/test/results/perf-vertx-stacks-01-collapsed-all.txt"; let expected_result_file = "./tests/data/flamegraph/options/colordiffusion.svg"; - let options = Options { - color_diffusion: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.color_diffusion = true; test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -186,11 +178,9 @@ fn flamegraph_collor_diffusion() { fn flamegraph_factor() { let input_file = "./flamegraph/test/results/perf-vertx-stacks-01-collapsed-all.txt"; let expected_result_file = "./tests/data/flamegraph/factor/factor-2.5.svg"; - let options = Options { - factor: 2.5, - hash: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.factor = 2.5; + options.hash = true; test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -201,12 +191,10 @@ fn flamegraph_nameattr() { let expected_result_file = "./tests/data/flamegraph/nameattr/nameattr.svg"; let nameattr_file = "./tests/data/flamegraph/nameattr/nameattr.txt"; - let options = flamegraph::Options { - hash: true, - func_frameattrs: flamegraph::FuncFrameAttrsMap::from_file(&PathBuf::from(nameattr_file)) - .unwrap(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.hash = true; + options.func_frameattrs = + flamegraph::FuncFrameAttrsMap::from_file(&PathBuf::from(nameattr_file)).unwrap(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -218,12 +206,10 @@ fn flamegraph_nameattr_empty_line() { let expected_result_file = "./tests/data/flamegraph/nameattr/nameattr.svg"; let nameattr_file = "./tests/data/flamegraph/nameattr/nameattr_empty_first_line.txt"; - let options = flamegraph::Options { - hash: true, - func_frameattrs: flamegraph::FuncFrameAttrsMap::from_file(&PathBuf::from(nameattr_file)) - .unwrap(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.hash = true; + options.func_frameattrs = + flamegraph::FuncFrameAttrsMap::from_file(&PathBuf::from(nameattr_file)).unwrap(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -235,12 +221,10 @@ fn flamegraph_nameattr_empty_attribute() { let expected_result_file = "./tests/data/flamegraph/nameattr/nameattr.svg"; let nameattr_file = "./tests/data/flamegraph/nameattr/nameattr_empty_attribute.txt"; - let options = flamegraph::Options { - hash: true, - func_frameattrs: flamegraph::FuncFrameAttrsMap::from_file(&PathBuf::from(nameattr_file)) - .unwrap(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.hash = true; + options.func_frameattrs = + flamegraph::FuncFrameAttrsMap::from_file(&PathBuf::from(nameattr_file)).unwrap(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -252,12 +236,10 @@ fn flamegraph_nameattr_duplicate_attributes() { let expected_result_file = "./tests/data/flamegraph/nameattr/nameattr_duplicate_attributes.svg"; let nameattr_file = "./tests/data/flamegraph/nameattr/nameattr_duplicate_attributes.txt"; - let options = flamegraph::Options { - hash: true, - func_frameattrs: flamegraph::FuncFrameAttrsMap::from_file(&PathBuf::from(nameattr_file)) - .unwrap(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.hash = true; + options.func_frameattrs = + flamegraph::FuncFrameAttrsMap::from_file(&PathBuf::from(nameattr_file)).unwrap(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -376,10 +358,8 @@ fn flamegraph_palette_map() { let palette_file = "./tests/data/flamegraph/palette-map/palette.map"; let mut palette_map = load_palette_map_file(palette_file); - let options = flamegraph::Options { - palette_map: Some(&mut palette_map), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.palette_map = Some(&mut palette_map); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -458,10 +438,8 @@ fn flamegraph_unsorted_multiple_input_files() { ]; let expected_result_file = "./tests/data/flamegraph/perf-vertx-stacks/perf-vertx-stacks-01-collapsed-all.svg"; - let options = Options { - hash: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.hash = true; test_flamegraph_multiple_files(input_files, expected_result_file, options).unwrap(); } @@ -470,10 +448,8 @@ fn flamegraph_should_prune_narrow_blocks() { let input_file = "./tests/data/flamegraph/narrow-blocks/narrow-blocks.txt"; let expected_result_file = "./tests/data/flamegraph/narrow-blocks/narrow-blocks.svg"; - let options = flamegraph::Options { - hash: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.hash = true; test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -483,12 +459,10 @@ fn flamegraph_inverted() { let input_file = "./flamegraph/test/results/perf-vertx-stacks-01-collapsed-all.txt"; let expected_result_file = "./tests/data/flamegraph/inverted/inverted.svg"; - let options = flamegraph::Options { - hash: true, - title: "Icicle Graph".to_string(), - direction: Direction::Inverted, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.hash = true; + options.title = "Icicle Graph".to_string(); + options.direction = Direction::Inverted; test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -498,10 +472,8 @@ fn flamegraph_grey_frames() { let input_file = "./tests/data/flamegraph/grey-frames/grey-frames.txt"; let expected_result_file = "./tests/data/flamegraph/grey-frames/grey-frames.svg"; - let options = flamegraph::Options { - hash: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.hash = true; test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -514,10 +486,8 @@ fn flamegraph_example_perf_stacks() { let palette_file = "./tests/data/flamegraph/example-perf-stacks/palette.map"; let mut palette_map = load_palette_map_file(palette_file); - let options = flamegraph::Options { - palette_map: Some(&mut palette_map), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.palette_map = Some(&mut palette_map); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -539,10 +509,8 @@ fn flamegraph_title_simple() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/title_simple.svg"; - let options = flamegraph::Options { - title: "Test Graph".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.title = "Test Graph".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -553,10 +521,8 @@ fn flamegraph_title_with_symbols() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/title_with_symbols.svg"; - let options = flamegraph::Options { - title: "Test <& ' \"".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.title = "Test <& ' \"".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -567,10 +533,8 @@ fn flamegraph_subtitle_simple() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/subtitle_simple.svg"; - let options = flamegraph::Options { - subtitle: Some("Test Subtitle".to_owned()), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.subtitle = Some("Test Subtitle".to_owned()); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -581,10 +545,8 @@ fn flamegraph_subtitle_with_symbols() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/subtitle_with_symbols.svg"; - let options = flamegraph::Options { - subtitle: Some("Test Subtitle <& ' \"".to_owned()), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.subtitle = Some("Test Subtitle <& ' \"".to_owned()); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -595,10 +557,8 @@ fn flamegraph_notes_simple() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/notes_simple.svg"; - let options = flamegraph::Options { - notes: "Test Notes".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.notes = "Test Notes".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -609,10 +569,8 @@ fn flamegraph_notes_with_symbols() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/notes_with_symbols.svg"; - let options = flamegraph::Options { - notes: "Test Notes <& ' \"".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.notes = "Test Notes <& ' \"".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -623,10 +581,8 @@ fn flamegraph_count_name_simple() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/count_name_simple.svg"; - let options = flamegraph::Options { - count_name: "test-samples".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.count_name = "test-samples".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -637,10 +593,8 @@ fn flamegraph_count_name_with_symbols() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/count_name_with_symbols.svg"; - let options = flamegraph::Options { - count_name: "test-samples <& ' \"".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.count_name = "test-samples <& ' \"".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -651,10 +605,8 @@ fn flamegraph_name_type_simple() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/name_type_simple.svg"; - let options = flamegraph::Options { - name_type: "Tfunction:".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.name_type = "Tfunction:".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -665,10 +617,8 @@ fn flamegraph_name_type_with_quote() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/name_type_with_quote.svg"; - let options = flamegraph::Options { - name_type: "Test: '".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.name_type = "Test: '".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -679,10 +629,8 @@ fn flamegraph_name_type_with_backslash() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/name_type_with_backslash.svg"; - let options = flamegraph::Options { - name_type: "Test: \\".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.name_type = "Test: \\".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -693,10 +641,8 @@ fn flamegraph_font_type_simple() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/font_type_simple.svg"; - let options = flamegraph::Options { - font_type: "Andale Mono".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.font_type = "Andale Mono".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -707,10 +653,8 @@ fn flamegraph_font_type_with_quote() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/font_type_with_quote.svg"; - let options = flamegraph::Options { - font_type: "Andale Mono\"".to_owned(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.font_type = "Andale Mono\"".to_owned(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -721,10 +665,8 @@ fn search_color_non_default() { "./tests/data/flamegraph/differential/perf-cycles-instructions-01-collapsed-all-diff.txt"; let expected_result_file = "./tests/data/flamegraph/options/search_color.svg"; - let options = flamegraph::Options { - search_color: "#7d7d7d".parse().unwrap(), - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.search_color = "#7d7d7d".parse().unwrap(); test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -734,10 +676,10 @@ fn flamegraph_sorted_input_file() { let input_file = "./flamegraph/test/results/perf-vertx-stacks-01-collapsed-all.txt"; let expected_result_file = "./tests/data/flamegraph/perf-vertx-stacks/perf-vertx-stacks-01-collapsed-all.svg"; - let options = Options { - hash: true, - ..Default::default() - }; + + let mut options = flamegraph::Options::default(); + options.hash = true; + test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -747,10 +689,10 @@ fn flamegraph_unsorted_input_file() { "./tests/data/flamegraph/unsorted-input/perf-vertx-stacks-01-collapsed-all-unsorted.txt"; let expected_result_file = "./tests/data/flamegraph/perf-vertx-stacks/perf-vertx-stacks-01-collapsed-all.svg"; - let options = Options { - hash: true, - ..Default::default() - }; + + let mut options = flamegraph::Options::default(); + options.hash = true; + test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -760,10 +702,10 @@ fn flamegraph_no_sort_should_return_error_on_unsorted_input() { "./tests/data/flamegraph/unsorted-input/perf-vertx-stacks-01-collapsed-all-unsorted.txt"; let expected_result_file = "./tests/data/flamegraph/perf-vertx-stacks/perf-vertx-stacks-01-collapsed-all.svg"; - let options = Options { - no_sort: true, - ..Default::default() - }; + + let mut options = flamegraph::Options::default(); + options.no_sort = true; + assert!(test_flamegraph(input_file, expected_result_file, options).is_err()); } @@ -773,11 +715,11 @@ fn flamegraph_reversed_stack_ordering() { "./tests/data/flamegraph/unsorted-input/perf-vertx-stacks-01-collapsed-all-unsorted.txt"; let expected_result_file = "./tests/data/flamegraph/perf-vertx-stacks/perf-vertx-stacks-01-collapsed-all-reversed-stacks.svg"; - let options = Options { - hash: true, - reverse_stack_order: true, - ..Default::default() - }; + + let mut options = flamegraph::Options::default(); + options.hash = true; + options.reverse_stack_order = true; + test_flamegraph(input_file, expected_result_file, options).unwrap(); } @@ -785,21 +727,20 @@ fn flamegraph_reversed_stack_ordering() { fn flamegraph_reversed_stack_ordering_with_fractional_samples() { let input_file = "./tests/data/flamegraph/fractional-samples/fractional.txt"; let expected_result_file = "./tests/data/flamegraph/fractional-samples/fractional-reversed.svg"; - let options = Options { - hash: true, - reverse_stack_order: true, - ..Default::default() - }; + + let mut options = flamegraph::Options::default(); + options.hash = true; + options.reverse_stack_order = true; + test_flamegraph(input_file, expected_result_file, options).unwrap(); } #[test] fn flamegraph_should_warn_about_no_sort_when_reversing_stack_ordering() { - let options = Options { - no_sort: true, - reverse_stack_order: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.no_sort = true; + options.reverse_stack_order = true; + test_flamegraph_logs_with_options( "./flamegraph/test/results/perf-funcab-cmd-01-collapsed-all.txt", |captured_logs| { @@ -819,10 +760,9 @@ fn flamegraph_should_warn_about_no_sort_when_reversing_stack_ordering() { #[test] fn flamegraph_should_warn_about_bad_input_lines_with_reversed_stack_ordering() { - let options = Options { - reverse_stack_order: true, - ..Default::default() - }; + let mut options = flamegraph::Options::default(); + options.reverse_stack_order = true; + test_flamegraph_logs_with_options( "./tests/data/flamegraph/bad-lines/bad-lines.txt", |captured_logs| { @@ -901,15 +841,13 @@ fn flamegraph_colors_truncate_right() { let input_file = "./flamegraph/test/results/perf-java-stacks-01-collapsed-all.txt"; let expected_result_file = "./tests/data/flamegraph/options/truncate-right.svg"; - let options = flamegraph::Options { - colors: Palette::from_str("java").unwrap(), - text_truncate_direction: TextTruncateDirection::Right, - bgcolors: Some(BackgroundColor::from_str("blue").unwrap()), - hash: true, - ..Default::default() - }; + let mut opts = flamegraph::Options::default(); + opts.colors = Palette::from_str("java").unwrap(); + opts.text_truncate_direction = TextTruncateDirection::Right; + opts.bgcolors = Some(BackgroundColor::from_str("blue").unwrap()); + opts.hash = true; - test_flamegraph(input_file, expected_result_file, options).unwrap(); + test_flamegraph(input_file, expected_result_file, opts).unwrap(); } #[test] @@ -917,11 +855,9 @@ fn flamegraph_flamechart() { let input_file = "./tests/data/flamegraph/flamechart/flames.txt"; let expected_result_file = "./tests/data/flamegraph/flamechart/flame.svg"; - let options = flamegraph::Options { - title: flamegraph::defaults::CHART_TITLE.to_owned(), - flame_chart: true, - ..Default::default() - }; + let mut opts = flamegraph::Options::default(); + opts.title = flamegraph::defaults::CHART_TITLE.to_owned(); + opts.flame_chart = true; - test_flamegraph(input_file, expected_result_file, options).unwrap(); + test_flamegraph(input_file, expected_result_file, opts).unwrap(); }