-
Notifications
You must be signed in to change notification settings - Fork 10
/
nmsize
24 lines (21 loc) · 578 Bytes
/
nmsize
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env ruby
# from https://stackoverflow.com/a/2922525
syms = []
total = 0
IO.popen("nm --demangle -S #{ARGV.join(' ')}").each_line { |line|
addr, size, scope, name = line.split(' ', 4)
next unless addr and size and scope and name
name.chomp!
addr = addr.to_i(16)
size = size.to_i(16)
total += size
syms << [size, name]
}
syms.sort! { |a,b| b[0] <=> a[0] }
cumulative = 0.0
syms.each { |sym|
size = sym[0]
cumulative += size
printf "%5.1f%% %6s %s\n", cumulative / total * 100, size.to_s, sym[1]
}
printf "%5.1f%% %6s %s\n", 100, total, "TOTAL"