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