Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -a, --all flag to garbage command #118

Merged
merged 1 commit into from
Aug 13, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion opt/definitions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 <max_items>
#[structopt(short = "a", long = "all")]
all_items: bool,
}

impl Default for Garbage {
Expand All @@ -527,6 +531,7 @@ impl Default for Garbage {
output_format: Default::default(),

max_items: 10,
all_items: false,
}
}
}
Expand All @@ -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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch here 😸

}
}
25 changes: 25 additions & 0 deletions twiggy/tests/expectations/garbage_wee_alloc_all
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
Bytes │ Size % │ Garbage Item
───────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1034 ┊ 36.71% ┊ data[3]
136 ┊ 4.83% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6
76 ┊ 2.70% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::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% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099
5 ┊ 0.18% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> 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]
1 change: 1 addition & 0 deletions twiggy/tests/expectations/garbage_wee_alloc_all_json
Original file line number Diff line number Diff line change
@@ -0,0 +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}]
14 changes: 14 additions & 0 deletions twiggy/tests/expectations/garbage_wee_alloc_top_10
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Bytes │ Size % │ Garbage Item
───────┼────────┼─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
1034 ┊ 36.71% ┊ data[3]
136 ┊ 4.83% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::new_cell_for_free_list::h3987e3054b8224e6
76 ┊ 2.70% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::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% ┊ <wee_alloc::LargeAllocPolicy as wee_alloc::AllocPolicy>::min_cell_size::hc7cee2a550987099
5 ┊ 0.18% ┊ <wee_alloc::size_classes::SizeClassAllocPolicy<'a> as wee_alloc::AllocPolicy>::min_cell_size::h6f746be886573355
24 ┊ 0.85% ┊ ... and 12 more
1355 ┊ 48.10% ┊ Σ [22 Total Rows]
1 change: 1 addition & 0 deletions twiggy/tests/expectations/garbage_wee_alloc_top_10_json
Original file line number Diff line number Diff line change
@@ -0,0 +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}]
26 changes: 26 additions & 0 deletions twiggy/tests/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"
);

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job adding these tests as well!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing is the most important ;)

test!(
monos_json,
"monos",
Expand Down