Skip to content

Commit 4a29811

Browse files
Add -a, --all flag to garbage command
And extend tests accordingly Relates to AlexEne#109
1 parent 8990caf commit 4a29811

6 files changed

Lines changed: 74 additions & 1 deletion

File tree

opt/definitions.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,6 +514,10 @@ pub struct Garbage {
514514
/// The maximum number of items to display.
515515
#[structopt(short = "n", default_value = "10")]
516516
max_items: u32,
517+
518+
/// Display all items. Overrides -n <max_items>
519+
#[structopt(short = "a", long = "all")]
520+
all_items: bool,
517521
}
518522

519523
impl Default for Garbage {
@@ -527,6 +531,7 @@ impl Default for Garbage {
527531
output_format: Default::default(),
528532

529533
max_items: 10,
534+
all_items: false,
530535
}
531536
}
532537
}
@@ -540,11 +545,12 @@ impl Garbage {
540545

541546
/// The maximum number of items to display.
542547
pub fn max_items(&self) -> u32 {
543-
self.max_items
548+
if self.all_items { u32::MAX } else { self.max_items }
544549
}
545550

546551
/// Set the maximum number of items to display.
547552
pub fn set_max_items(&mut self, max: u32) {
548553
self.max_items = max;
554+
self.all_items = false;
549555
}
550556
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
Bytes │ Size % │ Garbage Item
2+
───────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
3+
1034 ┊ 36.71% ┊ data[3]
4+
136 ┊ 4.83% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6
5+
76 ┊ 2.70% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::new_cell_for_free_list::h8f071b7bce0301ba
6+
25 ┊ 0.89% ┊ data[1]
7+
25 ┊ 0.89% ┊ data[2]
8+
12 ┊ 0.43% ┊ elem[0]
9+
6 ┊ 0.21% ┊ type[0]
10+
6 ┊ 0.21% ┊ type[1]
11+
6 ┊ 0.21% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099
12+
5 ┊ 0.18% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355
13+
4 ┊ 0.14% ┊ table[0]
14+
4 ┊ 0.14% ┊ __wasm_nullptr
15+
3 ┊ 0.11% ┊ type[2]
16+
3 ┊ 0.11% ┊ core::ptr::drop_in_place::h8e9fdc2437d43666
17+
3 ┊ 0.11% ┊ core::ptr::drop_in_place::h4e5cdfd7b9310648.18
18+
1 ┊ 0.04% ┊ func[0]
19+
1 ┊ 0.04% ┊ func[1]
20+
1 ┊ 0.04% ┊ func[4]
21+
1 ┊ 0.04% ┊ func[5]
22+
1 ┊ 0.04% ┊ func[6]
23+
1 ┊ 0.04% ┊ func[7]
24+
1 ┊ 0.04% ┊ func[10]
25+
1355 ┊ 48.10% ┊ Σ [22 Total Rows]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"name":"data[3]","bytes":1034,"size_percent":36.7057152999645},{"name":"<wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6","bytes":136,"size_percent":4.827831025914093},{"name":"<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::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":"<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099","bytes":6,"size_percent":0.21299254526091588},{"name":"<wee_alloc::size_classes::SizeClassAllocPolicy<'a> 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}]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Bytes │ Size % │ Garbage Item
2+
───────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
3+
1034 ┊ 36.71% ┊ data[3]
4+
136 ┊ 4.83% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6
5+
76 ┊ 2.70% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::new_cell_for_free_list::h8f071b7bce0301ba
6+
25 ┊ 0.89% ┊ data[1]
7+
25 ┊ 0.89% ┊ data[2]
8+
12 ┊ 0.43% ┊ elem[0]
9+
6 ┊ 0.21% ┊ type[0]
10+
6 ┊ 0.21% ┊ type[1]
11+
6 ┊ 0.21% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099
12+
5 ┊ 0.18% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355
13+
24 ┊ 0.85% ┊ ... and 12 more
14+
1355 ┊ 48.10% ┊ Σ [22 Total Rows]
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
[{"name":"data[3]","bytes":1034,"size_percent":36.7057152999645},{"name":"<wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6","bytes":136,"size_percent":4.827831025914093},{"name":"<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::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":"<wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099","bytes":6,"size_percent":0.21299254526091588},{"name":"<wee_alloc::size_classes::SizeClassAllocPolicy<'a> 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}]

twiggy/tests/tests.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -429,6 +429,32 @@ test!(
429429
"2"
430430
);
431431

432+
test!(garbage_wee_alloc_top_10, "garbage", "./fixtures/wee_alloc.wasm");
433+
434+
test!(
435+
garbage_wee_alloc_all,
436+
"garbage",
437+
"./fixtures/wee_alloc.wasm",
438+
"-a"
439+
);
440+
441+
test!(
442+
garbage_wee_alloc_top_10_json,
443+
"garbage",
444+
"./fixtures/wee_alloc.wasm",
445+
"-f",
446+
"json"
447+
);
448+
449+
test!(
450+
garbage_wee_alloc_all_json,
451+
"garbage",
452+
"./fixtures/wee_alloc.wasm",
453+
"-f",
454+
"json",
455+
"-a"
456+
);
457+
432458
test!(
433459
monos_json,
434460
"monos",

0 commit comments

Comments
 (0)