Development mbed library for MAX32630FTHR

Dependents:   blinky_max32630fthr

Committer:
switches
Date:
Fri Nov 11 20:59:50 2016 +0000
Revision:
0:5c4d7b2438d3
Initial commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
switches 0:5c4d7b2438d3 1 """
switches 0:5c4d7b2438d3 2 mbed SDK
switches 0:5c4d7b2438d3 3 Copyright (c) 2011-2013 ARM Limited
switches 0:5c4d7b2438d3 4
switches 0:5c4d7b2438d3 5 Licensed under the Apache License, Version 2.0 (the "License");
switches 0:5c4d7b2438d3 6 you may not use this file except in compliance with the License.
switches 0:5c4d7b2438d3 7 You may obtain a copy of the License at
switches 0:5c4d7b2438d3 8
switches 0:5c4d7b2438d3 9 http://www.apache.org/licenses/LICENSE-2.0
switches 0:5c4d7b2438d3 10
switches 0:5c4d7b2438d3 11 Unless required by applicable law or agreed to in writing, software
switches 0:5c4d7b2438d3 12 distributed under the License is distributed on an "AS IS" BASIS,
switches 0:5c4d7b2438d3 13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
switches 0:5c4d7b2438d3 14 See the License for the specific language governing permissions and
switches 0:5c4d7b2438d3 15 limitations under the License.
switches 0:5c4d7b2438d3 16 """
switches 0:5c4d7b2438d3 17 import sys
switches 0:5c4d7b2438d3 18 from os.path import join, abspath, dirname, exists, splitext
switches 0:5c4d7b2438d3 19 from subprocess import Popen, PIPE
switches 0:5c4d7b2438d3 20 import csv
switches 0:5c4d7b2438d3 21 from collections import defaultdict
switches 0:5c4d7b2438d3 22
switches 0:5c4d7b2438d3 23 ROOT = abspath(join(dirname(__file__), ".."))
switches 0:5c4d7b2438d3 24 sys.path.insert(0, ROOT)
switches 0:5c4d7b2438d3 25
switches 0:5c4d7b2438d3 26 from tools.paths import BUILD_DIR, TOOLS_DATA
switches 0:5c4d7b2438d3 27 from tools.settings import GCC_ARM_PATH
switches 0:5c4d7b2438d3 28 from tools.tests import TEST_MAP
switches 0:5c4d7b2438d3 29 from tools.build_api import build_mbed_libs, build_project
switches 0:5c4d7b2438d3 30
switches 0:5c4d7b2438d3 31 SIZE = join(GCC_ARM_PATH, 'arm-none-eabi-size')
switches 0:5c4d7b2438d3 32
switches 0:5c4d7b2438d3 33 def get_size(path):
switches 0:5c4d7b2438d3 34 out = Popen([SIZE, path], stdout=PIPE).communicate()[0]
switches 0:5c4d7b2438d3 35 return map(int, out.splitlines()[1].split()[:4])
switches 0:5c4d7b2438d3 36
switches 0:5c4d7b2438d3 37 def get_percentage(before, after):
switches 0:5c4d7b2438d3 38 if before == 0:
switches 0:5c4d7b2438d3 39 return 0 if after == 0 else 100.0
switches 0:5c4d7b2438d3 40 return float(after - before) / float(before) * 100.0
switches 0:5c4d7b2438d3 41
switches 0:5c4d7b2438d3 42 def human_size(val):
switches 0:5c4d7b2438d3 43 if val>1024:
switches 0:5c4d7b2438d3 44 return "%.0fKb" % (float(val)/1024.0)
switches 0:5c4d7b2438d3 45 return "%d" % val
switches 0:5c4d7b2438d3 46
switches 0:5c4d7b2438d3 47 def print_diff(name, before, after):
switches 0:5c4d7b2438d3 48 print "%s: (%s -> %s) %.2f%%" % (name, human_size(before) , human_size(after) , get_percentage(before , after))
switches 0:5c4d7b2438d3 49
switches 0:5c4d7b2438d3 50 BENCHMARKS = [
switches 0:5c4d7b2438d3 51 ("BENCHMARK_1", "CENV"),
switches 0:5c4d7b2438d3 52 ("BENCHMARK_2", "PRINTF"),
switches 0:5c4d7b2438d3 53 ("BENCHMARK_3", "FP"),
switches 0:5c4d7b2438d3 54 ("BENCHMARK_4", "MBED"),
switches 0:5c4d7b2438d3 55 ("BENCHMARK_5", "ALL"),
switches 0:5c4d7b2438d3 56 ]
switches 0:5c4d7b2438d3 57 BENCHMARK_DATA_PATH = join(TOOLS_DATA, 'benchmarks.csv')
switches 0:5c4d7b2438d3 58
switches 0:5c4d7b2438d3 59
switches 0:5c4d7b2438d3 60 def benchmarks():
switches 0:5c4d7b2438d3 61 # CSV Data
switches 0:5c4d7b2438d3 62 csv_data = csv.writer(open(BENCHMARK_DATA_PATH, 'wb'))
switches 0:5c4d7b2438d3 63 csv_data.writerow(['Toolchain', "Target", "Benchmark", "code", "data", "bss", "flash"])
switches 0:5c4d7b2438d3 64
switches 0:5c4d7b2438d3 65 # Build
switches 0:5c4d7b2438d3 66 for toolchain in ['ARM', 'uARM', 'GCC_CR', 'GCC_ARM']:
switches 0:5c4d7b2438d3 67 for mcu in ["LPC1768", "LPC11U24"]:
switches 0:5c4d7b2438d3 68 # Build Libraries
switches 0:5c4d7b2438d3 69 build_mbed_libs(mcu, toolchain)
switches 0:5c4d7b2438d3 70
switches 0:5c4d7b2438d3 71 # Build benchmarks
switches 0:5c4d7b2438d3 72 build_dir = join(BUILD_DIR, "benchmarks", mcu, toolchain)
switches 0:5c4d7b2438d3 73 for test_id, title in BENCHMARKS:
switches 0:5c4d7b2438d3 74 # Build Benchmark
switches 0:5c4d7b2438d3 75 try:
switches 0:5c4d7b2438d3 76 test = TEST_MAP[test_id]
switches 0:5c4d7b2438d3 77 path = build_project(test.source_dir, join(build_dir, test_id),
switches 0:5c4d7b2438d3 78 mcu, toolchain, test.dependencies)
switches 0:5c4d7b2438d3 79 base, ext = splitext(path)
switches 0:5c4d7b2438d3 80 # Check Size
switches 0:5c4d7b2438d3 81 code, data, bss, flash = get_size(base+'.elf')
switches 0:5c4d7b2438d3 82 csv_data.writerow([toolchain, mcu, title, code, data, bss, flash])
switches 0:5c4d7b2438d3 83 except Exception, e:
switches 0:5c4d7b2438d3 84 print "Unable to build %s for toolchain %s targeting %s" % (test_id, toolchain, mcu)
switches 0:5c4d7b2438d3 85 print e
switches 0:5c4d7b2438d3 86
switches 0:5c4d7b2438d3 87
switches 0:5c4d7b2438d3 88 def compare(t1, t2, target):
switches 0:5c4d7b2438d3 89 if not exists(BENCHMARK_DATA_PATH):
switches 0:5c4d7b2438d3 90 benchmarks()
switches 0:5c4d7b2438d3 91 else:
switches 0:5c4d7b2438d3 92 print "Loading: %s" % BENCHMARK_DATA_PATH
switches 0:5c4d7b2438d3 93
switches 0:5c4d7b2438d3 94 data = csv.reader(open(BENCHMARK_DATA_PATH, 'rb'))
switches 0:5c4d7b2438d3 95
switches 0:5c4d7b2438d3 96 benchmarks_data = defaultdict(dict)
switches 0:5c4d7b2438d3 97 for (toolchain, mcu, name, code, data, bss, flash) in data:
switches 0:5c4d7b2438d3 98 if target == mcu:
switches 0:5c4d7b2438d3 99 for t in [t1, t2]:
switches 0:5c4d7b2438d3 100 if toolchain == t:
switches 0:5c4d7b2438d3 101 benchmarks_data[name][t] = map(int, (code, data, bss, flash))
switches 0:5c4d7b2438d3 102
switches 0:5c4d7b2438d3 103 print "%s vs %s for %s" % (t1, t2, target)
switches 0:5c4d7b2438d3 104 for name, data in benchmarks_data.iteritems():
switches 0:5c4d7b2438d3 105 try:
switches 0:5c4d7b2438d3 106 # Check Size
switches 0:5c4d7b2438d3 107 code_a, data_a, bss_a, flash_a = data[t1]
switches 0:5c4d7b2438d3 108 code_u, data_u, bss_u, flash_u = data[t2]
switches 0:5c4d7b2438d3 109
switches 0:5c4d7b2438d3 110 print "\n=== %s ===" % name
switches 0:5c4d7b2438d3 111 print_diff("code", code_a , code_u)
switches 0:5c4d7b2438d3 112 print_diff("data", data_a , data_u)
switches 0:5c4d7b2438d3 113 print_diff("bss", bss_a , bss_u)
switches 0:5c4d7b2438d3 114 print_diff("flash", flash_a , flash_u)
switches 0:5c4d7b2438d3 115 except Exception, e:
switches 0:5c4d7b2438d3 116 print "No data for benchmark %s" % (name)
switches 0:5c4d7b2438d3 117 print e
switches 0:5c4d7b2438d3 118
switches 0:5c4d7b2438d3 119
switches 0:5c4d7b2438d3 120 if __name__ == '__main__':
switches 0:5c4d7b2438d3 121 compare("GCC_CR", "LPC1768")