Skip to content

Instantly share code, notes, and snippets.

@cho45

cho45/size.rb

Created Aug 29, 2019
Embed
What would you like to do?
#!/usr/bin/env ruby
require 'pp'
D = Struct.new(:sec, :size, :name)
target = ARGV.shift
sram = `arm-none-eabi-objdump -t '#{target}'`.chomp.split(/\n/).
select {|l| /\.(bss|data)|vectors/ =~ l }.
map {|l|
p l
sec, size0 = *l.split(/\t/)
size, name = *size0.split(/\s+/) if size0
D.new(sec, size.to_i(16), name)
}
total = sram.map {|i| i.size }.reduce {|r,i| r + i}
sram.sort_by {|i|
i.size
}.each { |i|
puts "% 3d%% % 10d %s" % [i.size.to_f / total * 100, i.size, i.name]
}
puts "total: %d bytes" % total
sram, flash = *`arm-none-eabi-size -A '#{target}'`.chomp.split(/\n/)[2..-2].
map {|l| l.split(/\s+/) }.
select {|(n,_,a)| n != '.heap' && a != "0" }.
group_by {|(name,size,address)| address.start_with?('5368') }.
values_at(true, false).
map {|s| s.inject(0) {|r,i| r + i[1].to_i} }
MAX_SRAM = 16 * 1024
MAX_FLASH = 128 * 1024
puts "sram: %d/%d (%d%%)" % [ sram, MAX_SRAM, sram.to_f / MAX_SRAM * 100 ]
puts "flash: %d/%d (%d%%)" % [ flash, MAX_FLASH, flash.to_f / MAX_FLASH * 100 ]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.