-
Notifications
You must be signed in to change notification settings - Fork 62
/
map-file-stats.js
56 lines (48 loc) · 1.34 KB
/
map-file-stats.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
let fs = require("fs")
let sums = {
TOTAL: 0,
"RAM.TOTAL": 0
}
let inprog = false
let inram = false
for (let line of fs.readFileSync(process.argv[2], "utf8").split(/\r?\n/)) {
if (/\*fill\*/.test(line)) continue
if (/^r[oa]m\s/.test(line)) continue
let m = /^ \.(\w+)/.exec(line)
if (m) {
if (m[1] == "text" || m[1] == "binmeta" || m[1] == "rodata" || m[1] == "data")
inprog = true
else
inprog = false
if (m[1] == "data" || m[1] == "bss")
inram = true
else
inram = false
}
if (!inprog && !inram) continue
m = /\s+(0x00[a-f0-9]+)\s+(0x[a-f0-9]+)\s+(.*)/.exec(line)
if (!m) continue
let addr = parseInt(m[1])
let size = parseInt(m[2])
if (!addr || !size) continue
let name = m[3]
if (/load address/.test(name)) continue
name = name.replace(/.*\/lib/, "lib")
.replace("CMakeFiles/CIRCUIT_PLAYGROUND.dir/", "")
// .replace(/\(.*/, "") // can remove
.replace(/pxtapp\/.*/, "pxtapp")
.replace(/libcodal-.*/, "codal")
let pref = inram ? "RAM." : ""
// if (inram&&size > 500) console.log(line)
name = pref + name
//console.log(name, size, line)
if (!sums[name]) sums[name] = 0
sums[name] += size
sums[pref + "TOTAL"] += size
}
let kk = Object.keys(sums)
kk.sort((a, b) => sums[b] - sums[a])
for (let k of kk) {
if (!/RAM/.test(k))
console.log(`${sums[k]}\t${k}`)
}