diff --git a/opt/definitions.rs b/opt/definitions.rs index 6c37f2db..ee34ed4a 100644 --- a/opt/definitions.rs +++ b/opt/definitions.rs @@ -514,6 +514,10 @@ pub struct Garbage { /// The maximum number of items to display. #[structopt(short = "n", default_value = "10")] max_items: u32, + + /// Display all items. Overrides -n + #[structopt(short = "a", long = "all")] + all_items: bool, } impl Default for Garbage { @@ -527,6 +531,7 @@ impl Default for Garbage { output_format: Default::default(), max_items: 10, + all_items: false, } } } @@ -540,11 +545,12 @@ impl Garbage { /// The maximum number of items to display. pub fn max_items(&self) -> u32 { - self.max_items + if self.all_items { u32::MAX } else { self.max_items } } /// Set the maximum number of items to display. pub fn set_max_items(&mut self, max: u32) { self.max_items = max; + self.all_items = false; } } diff --git a/twiggy/tests/expectations/garbage_wee_alloc_all b/twiggy/tests/expectations/garbage_wee_alloc_all new file mode 100644 index 00000000..1ee50b83 --- /dev/null +++ b/twiggy/tests/expectations/garbage_wee_alloc_all @@ -0,0 +1,25 @@ + Bytes │ Size % │ Garbage Item +───────┼────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + 1034 ┊ 36.71% ┊ data[3] + 136 ┊ 4.83% ┊ as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6 + 76 ┊ 2.70% ┊ ::new_cell_for_free_list::h8f071b7bce0301ba + 25 ┊ 0.89% ┊ data[1] + 25 ┊ 0.89% ┊ data[2] + 12 ┊ 0.43% ┊ elem[0] + 6 ┊ 0.21% ┊ type[0] + 6 ┊ 0.21% ┊ type[1] + 6 ┊ 0.21% ┊ ::min_cell_size::hc7cee2a550987099 + 5 ┊ 0.18% ┊ as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355 + 4 ┊ 0.14% ┊ table[0] + 4 ┊ 0.14% ┊ __wasm_nullptr + 3 ┊ 0.11% ┊ type[2] + 3 ┊ 0.11% ┊ core::ptr::drop_in_place::h8e9fdc2437d43666 + 3 ┊ 0.11% ┊ core::ptr::drop_in_place::h4e5cdfd7b9310648.18 + 1 ┊ 0.04% ┊ func[0] + 1 ┊ 0.04% ┊ func[1] + 1 ┊ 0.04% ┊ func[4] + 1 ┊ 0.04% ┊ func[5] + 1 ┊ 0.04% ┊ func[6] + 1 ┊ 0.04% ┊ func[7] + 1 ┊ 0.04% ┊ func[10] + 1355 ┊ 48.10% ┊ Σ [22 Total Rows] diff --git a/twiggy/tests/expectations/garbage_wee_alloc_all_json b/twiggy/tests/expectations/garbage_wee_alloc_all_json new file mode 100644 index 00000000..82333c2b --- /dev/null +++ b/twiggy/tests/expectations/garbage_wee_alloc_all_json @@ -0,0 +1 @@ +[{"name":"data[3]","bytes":1034,"size_percent":36.7057152999645},{"name":" as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6","bytes":136,"size_percent":4.827831025914093},{"name":"::new_cell_for_free_list::h8f071b7bce0301ba","bytes":76,"size_percent":2.697905573304934},{"name":"data[1]","bytes":25,"size_percent":0.8874689385871495},{"name":"data[2]","bytes":25,"size_percent":0.8874689385871495},{"name":"elem[0]","bytes":12,"size_percent":0.42598509052183176},{"name":"type[0]","bytes":6,"size_percent":0.21299254526091588},{"name":"type[1]","bytes":6,"size_percent":0.21299254526091588},{"name":"::min_cell_size::hc7cee2a550987099","bytes":6,"size_percent":0.21299254526091588},{"name":" as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355","bytes":5,"size_percent":0.1774937877174299},{"name":"table[0]","bytes":4,"size_percent":0.1419950301739439},{"name":"__wasm_nullptr","bytes":4,"size_percent":0.1419950301739439},{"name":"type[2]","bytes":3,"size_percent":0.10649627263045794},{"name":"core::ptr::drop_in_place::h8e9fdc2437d43666","bytes":3,"size_percent":0.10649627263045794},{"name":"core::ptr::drop_in_place::h4e5cdfd7b9310648.18","bytes":3,"size_percent":0.10649627263045794},{"name":"func[0]","bytes":1,"size_percent":0.03549875754348598},{"name":"func[1]","bytes":1,"size_percent":0.03549875754348598},{"name":"func[4]","bytes":1,"size_percent":0.03549875754348598},{"name":"func[5]","bytes":1,"size_percent":0.03549875754348598},{"name":"func[6]","bytes":1,"size_percent":0.03549875754348598},{"name":"func[7]","bytes":1,"size_percent":0.03549875754348598},{"name":"func[10]","bytes":1,"size_percent":0.03549875754348598},{"name":"Σ [22 Total Rows]","bytes":1355,"size_percent":48.1008164714235}] diff --git a/twiggy/tests/expectations/garbage_wee_alloc_top_10 b/twiggy/tests/expectations/garbage_wee_alloc_top_10 new file mode 100644 index 00000000..14375778 --- /dev/null +++ b/twiggy/tests/expectations/garbage_wee_alloc_top_10 @@ -0,0 +1,14 @@ + Bytes │ Size % │ Garbage Item +───────┼────────┼───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── + 1034 ┊ 36.71% ┊ data[3] + 136 ┊ 4.83% ┊ as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6 + 76 ┊ 2.70% ┊ ::new_cell_for_free_list::h8f071b7bce0301ba + 25 ┊ 0.89% ┊ data[1] + 25 ┊ 0.89% ┊ data[2] + 12 ┊ 0.43% ┊ elem[0] + 6 ┊ 0.21% ┊ type[0] + 6 ┊ 0.21% ┊ type[1] + 6 ┊ 0.21% ┊ ::min_cell_size::hc7cee2a550987099 + 5 ┊ 0.18% ┊ as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355 + 24 ┊ 0.85% ┊ ... and 12 more + 1355 ┊ 48.10% ┊ Σ [22 Total Rows] diff --git a/twiggy/tests/expectations/garbage_wee_alloc_top_10_json b/twiggy/tests/expectations/garbage_wee_alloc_top_10_json new file mode 100644 index 00000000..34c06145 --- /dev/null +++ b/twiggy/tests/expectations/garbage_wee_alloc_top_10_json @@ -0,0 +1 @@ +[{"name":"data[3]","bytes":1034,"size_percent":36.7057152999645},{"name":" as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6","bytes":136,"size_percent":4.827831025914093},{"name":"::new_cell_for_free_list::h8f071b7bce0301ba","bytes":76,"size_percent":2.697905573304934},{"name":"data[1]","bytes":25,"size_percent":0.8874689385871495},{"name":"data[2]","bytes":25,"size_percent":0.8874689385871495},{"name":"elem[0]","bytes":12,"size_percent":0.42598509052183176},{"name":"type[0]","bytes":6,"size_percent":0.21299254526091588},{"name":"type[1]","bytes":6,"size_percent":0.21299254526091588},{"name":"::min_cell_size::hc7cee2a550987099","bytes":6,"size_percent":0.21299254526091588},{"name":" as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355","bytes":5,"size_percent":0.1774937877174299},{"name":"... and 12 more","bytes":24,"size_percent":0.8519701810436635},{"name":"Σ [22 Total Rows]","bytes":1355,"size_percent":48.1008164714235}] diff --git a/twiggy/tests/tests.rs b/twiggy/tests/tests.rs index 9dc458e3..3556b7bf 100644 --- a/twiggy/tests/tests.rs +++ b/twiggy/tests/tests.rs @@ -429,6 +429,32 @@ test!( "2" ); +test!(garbage_wee_alloc_top_10, "garbage", "./fixtures/wee_alloc.wasm"); + +test!( + garbage_wee_alloc_all, + "garbage", + "./fixtures/wee_alloc.wasm", + "-a" +); + +test!( + garbage_wee_alloc_top_10_json, + "garbage", + "./fixtures/wee_alloc.wasm", + "-f", + "json" +); + +test!( + garbage_wee_alloc_all_json, + "garbage", + "./fixtures/wee_alloc.wasm", + "-f", + "json", + "-a" +); + test!( monos_json, "monos",