Created
August 22, 2024 01:50
-
-
Save cart/722756ba3da0e983d207633e0a48a8ab to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use serde::{Deserialize, Serialize}; | |
use std::{collections::HashMap, fs::read_to_string}; | |
#[derive(Serialize, Deserialize, Debug)] | |
struct BloatOutput { | |
#[serde(alias = "file-size")] | |
file_size: usize, | |
#[serde(alias = "text-section-size")] | |
text_section_size: usize, | |
functions: Vec<Function>, | |
} | |
#[derive(Serialize, Deserialize, Debug)] | |
struct Function { | |
#[serde(alias = "crate")] | |
crate_name: Option<String>, | |
name: String, | |
size: usize, | |
} | |
fn main() { | |
let output = read_to_string("out.json").unwrap(); | |
let p: BloatOutput = serde_json::from_str(&output).unwrap(); | |
let mut combined = HashMap::<String, usize>::default(); | |
for func in p.functions { | |
let count = combined.entry(func.name.clone()).or_default(); | |
*count += func.size; | |
} | |
let mut values = combined.into_iter().collect::<Vec<_>>(); | |
values.sort_by_key(|(_, size)| *size); | |
let values = values | |
.into_iter() | |
.map(|(name, size)| (name, size, 100.0 * size as f32 / p.text_section_size as f32)) | |
.collect::<Vec<_>>(); | |
println!("{:#?}", values); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
It might be useful to turn this into a script using the nightly/experimental cargo-script functionality.