Created
August 29, 2019 23:33
-
-
Save cho45/216772b89d99f275381d511a24688ffd to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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