nkjnm

Dependencies:   MAX44000 nexpaq_mdk

Fork of LED_Demo by Maxim nexpaq

Committer:
nitsshukla
Date:
Fri Nov 04 12:06:04 2016 +0000
Revision:
7:3a65ef12ba31
Parent:
1:55a6170b404f
kghj;

Who changed what in which revision?

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