Includes library modifications to allow access to AIN_4 (AIN_0 / 5)

Committer:
bryantaylor
Date:
Tue Sep 20 21:26:12 2016 +0000
Revision:
0:eafc3fd41f75
hackathon

Who changed what in which revision?

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