Skip to content

Commit

Permalink
add namespace size aggregation to rust-size script
Browse files Browse the repository at this point in the history
  • Loading branch information
mmoskal committed Nov 8, 2024
1 parent 529c7b1 commit e9ddf73
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion scripts/rust-size.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ function main(binname) {
}
const nmout = nm.stdout.toString()
const bycat = {}
const bynamespace = {}
for (const line of nmout.split("\n")) {
// format: 0000000000077ea0 l F .text 000000000000003e core::ptr::drop_in_place<toktrie::Splice>

const m = /^\s*([0-9a-f]+)\s[\sa-zA-Z]+(\.\S+)\s+([0-9a-f]+)\s+(.*)$/.exec(line)
const m = /^\s*([0-9a-f]+)\s[\sa-zA-Z]+(\.\S+)\s+([0-9a-f]+)\s+(.*)$/.exec(line)
if (!m) {
console.log("skipping", line)
continue
Expand All @@ -26,9 +27,21 @@ function main(binname) {

if (!bycat[category]) bycat[category] = 0
bycat[category] += size

if (size) {
const namespace = name.replace(/(::|\.).*/, "")
if (!bynamespace[namespace]) bynamespace[namespace] = 0
bynamespace[namespace] += size
}
}

console.log(bycat)

const namespaceKeys = Object.keys(bynamespace)
namespaceKeys.sort((a, b) => bynamespace[a] - bynamespace[b])
for (const ns of namespaceKeys) {
console.log(ns, bynamespace[ns])
}
}

main(process.argv[2])
Expand Down

0 comments on commit e9ddf73

Please sign in to comment.