BBR 1 Ebene

Committer:
borlanic
Date:
Mon May 14 11:29:06 2018 +0000
Revision:
0:fbdae7e6d805
BBR

Who changed what in which revision?

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