Committer:
borlanic
Date:
Fri Mar 30 14:07:05 2018 +0000
Revision:
4:75df35ef4fb6
Parent:
0:380207fcb5c1
commentar

Who changed what in which revision?

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