mirror of
https://github.com/Noratrieb/my-binary-is-thicc-af.git
synced 2026-01-14 11:45:05 +01:00
use fxhash
This commit is contained in:
parent
c50057a145
commit
076080f31d
3 changed files with 16 additions and 6 deletions
7
Cargo.lock
generated
7
Cargo.lock
generated
|
|
@ -83,6 +83,7 @@ dependencies = [
|
||||||
"eyre",
|
"eyre",
|
||||||
"object",
|
"object",
|
||||||
"rustc-demangle",
|
"rustc-demangle",
|
||||||
|
"rustc-hash",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
]
|
]
|
||||||
|
|
@ -128,6 +129,12 @@ version = "0.1.23"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "rustc-hash"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "ruzstd"
|
name = "ruzstd"
|
||||||
version = "0.3.1"
|
version = "0.3.1"
|
||||||
|
|
|
||||||
|
|
@ -9,5 +9,9 @@ edition = "2021"
|
||||||
eyre = "0.6.8"
|
eyre = "0.6.8"
|
||||||
object = "0.31.1"
|
object = "0.31.1"
|
||||||
rustc-demangle = { version = "0.1.23", features = ["std"] }
|
rustc-demangle = { version = "0.1.23", features = ["std"] }
|
||||||
|
rustc-hash = "1.1.0"
|
||||||
serde = { version = "1.0.164", features = ["derive"] }
|
serde = { version = "1.0.164", features = ["derive"] }
|
||||||
serde_json = "1.0.99"
|
serde_json = "1.0.99"
|
||||||
|
|
||||||
|
[profile.release]
|
||||||
|
debug = 1
|
||||||
|
|
|
||||||
11
src/main.rs
11
src/main.rs
|
|
@ -1,8 +1,7 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
use eyre::{eyre, Context, ContextCompat, Result};
|
use eyre::{eyre, Context, ContextCompat, Result};
|
||||||
use object::{Object, ObjectSection, ObjectSymbol};
|
use object::{Object, ObjectSection, ObjectSymbol};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
|
use rustc_hash::FxHashMap;
|
||||||
|
|
||||||
#[derive(serde::Serialize)]
|
#[derive(serde::Serialize)]
|
||||||
struct SerGroup {
|
struct SerGroup {
|
||||||
|
|
@ -17,7 +16,7 @@ fn main() -> Result<()> {
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.unwrap_or("./target/debug/my-binary-is-thicc-af".into());
|
.unwrap_or("./target/debug/my-binary-is-thicc-af".into());
|
||||||
|
|
||||||
let limit = 10;
|
let limit = 100;
|
||||||
|
|
||||||
let data = std::fs::read(&path).wrap_err_with(|| format!("error opening `{path}`"))?;
|
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")?;
|
let object = object::File::parse(data.as_slice()).context("could not parse object file")?;
|
||||||
|
|
@ -53,7 +52,7 @@ fn main() -> Result<()> {
|
||||||
symbol_sizes.sort_by_key(|&(_, size)| size);
|
symbol_sizes.sort_by_key(|&(_, size)| size);
|
||||||
symbol_sizes.reverse();
|
symbol_sizes.reverse();
|
||||||
|
|
||||||
let mut root_groups = Groups(HashMap::new());
|
let mut root_groups = Groups(FxHashMap::default());
|
||||||
|
|
||||||
for (sym, size) in symbol_sizes {
|
for (sym, size) in symbol_sizes {
|
||||||
let mut components = symbol_components(sym).with_context(|| sym.to_string())?;
|
let mut components = symbol_components(sym).with_context(|| sym.to_string())?;
|
||||||
|
|
@ -78,7 +77,7 @@ fn main() -> Result<()> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Groups(HashMap<String, Group>);
|
struct Groups(FxHashMap<String, Group>);
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
struct Group {
|
struct Group {
|
||||||
|
|
@ -120,7 +119,7 @@ fn add_to_group(mut cur_groups: &mut Groups, components: Vec<String>, sym_size:
|
||||||
for head in components {
|
for head in components {
|
||||||
let grp = cur_groups.0.entry(head).or_insert(Group {
|
let grp = cur_groups.0.entry(head).or_insert(Group {
|
||||||
weight: sym_size, // NOTE: This is a dummy value for everything but the innermost nesting.
|
weight: sym_size, // NOTE: This is a dummy value for everything but the innermost nesting.
|
||||||
children: Groups(HashMap::new()),
|
children: Groups(FxHashMap::default()),
|
||||||
});
|
});
|
||||||
cur_groups = &mut grp.children;
|
cur_groups = &mut grp.children;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue