From c50057a14526a10681e6ed84c7daf015a12c40be Mon Sep 17 00:00:00 2001 From: Nilstrieb <48135649+Nilstrieb@users.noreply.github.com> Date: Sun, 2 Jul 2023 13:37:50 +0200 Subject: [PATCH] run instruction --- README.md | 11 +++++++++++ src/main.rs | 8 +++++++- 2 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..05f5eba --- /dev/null +++ b/README.md @@ -0,0 +1,11 @@ +# Rust binary size analyzer + +How to use: + +`cd client && npm i && npm run dev` + +In a separate shell: + +`cargo run --release BINARY_PATH > client/groups.json` + +Note: The symbol parsing code is extremely cursed. This may lead to very wonky results. \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index f5db249..6387560 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,8 @@ fn main() -> Result<()> { .nth(1) .unwrap_or("./target/debug/my-binary-is-thicc-af".into()); + let limit = 10; + let data = std::fs::read(&path).wrap_err_with(|| format!("error opening `{path}`"))?; let object = object::File::parse(data.as_slice()).context("could not parse object file")?; @@ -54,7 +56,11 @@ fn main() -> Result<()> { let mut root_groups = Groups(HashMap::new()); for (sym, size) in symbol_sizes { - let components = symbol_components(sym).with_context(|| sym.to_string())?; + let mut components = symbol_components(sym).with_context(|| sym.to_string())?; + + if components.len() > limit { + components.truncate(limit); + } add_to_group(&mut root_groups, components, size); }