Skip to content

Instantly share code, notes, and snippets.

@cho45
Created August 29, 2019 23:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cho45/216772b89d99f275381d511a24688ffd to your computer and use it in GitHub Desktop.
Save cho45/216772b89d99f275381d511a24688ffd to your computer and use it in GitHub Desktop.
#!/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