Backup 1

Committer:
borlanic
Date:
Tue Apr 24 11:45:18 2018 +0000
Revision:
0:02dd72d1d465
BaBoRo_test2 - backup 1

Who changed what in which revision?

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