]>
git.gir.st - tmk_keyboard.git/blob - tmk_core/tool/mbed/mbed-sdk/workspace_tools/size.py
3 Copyright (c) 2011-2013 ARM Limited
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
9 http://www.apache.org/licenses/LICENSE-2.0
11 Unless required by applicable law or agreed to in writing, software
12 distributed under the License is distributed on an "AS IS" BASIS,
13 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 See the License for the specific language governing permissions and
15 limitations under the License.
18 from os
.path
import join
, abspath
, dirname
, exists
, splitext
19 from subprocess
import Popen
, PIPE
21 from collections
import defaultdict
23 ROOT
= abspath(join(dirname(__file__
), ".."))
24 sys
.path
.insert(0, ROOT
)
26 from workspace_tools
.paths
import BUILD_DIR
, TOOLS_DATA
27 from workspace_tools
.settings
import GCC_ARM_PATH
28 from workspace_tools
.tests
import TEST_MAP
29 from workspace_tools
.build_api
import build_mbed_libs
, build_project
31 SIZE
= join(GCC_ARM_PATH
, 'arm-none-eabi-size')
34 out
= Popen([SIZE
, path
], stdout
=PIPE
).communicate()[0]
35 return map(int, out
.splitlines()[1].split()[:4])
37 def get_percentage(before
, after
):
39 return 0 if after
== 0 else 100.0
40 return float(after
- before
) / float(before
) * 100.0
44 return "%.0fKb" % (float(val
)/1024.0)
47 def print_diff(name
, before
, after
):
48 print "%s: (%s -> %s) %.2f%%" % (name
, human_size(before
) , human_size(after
) , get_percentage(before
, after
))
51 ("BENCHMARK_1", "CENV"),
52 ("BENCHMARK_2", "PRINTF"),
53 ("BENCHMARK_3", "FP"),
54 ("BENCHMARK_4", "MBED"),
55 ("BENCHMARK_5", "ALL"),
57 BENCHMARK_DATA_PATH
= join(TOOLS_DATA
, 'benchmarks.csv')
62 csv_data
= csv
.writer(open(BENCHMARK_DATA_PATH
, 'wb'))
63 csv_data
.writerow(['Toolchain', "Target", "Benchmark", "code", "data", "bss", "flash"])
66 for toolchain
in ['ARM', 'uARM', 'GCC_CR', 'GCC_CS', 'GCC_ARM']:
67 for mcu
in ["LPC1768", "LPC11U24"]:
69 build_mbed_libs(mcu
, toolchain
)
72 build_dir
= join(BUILD_DIR
, "benchmarks", mcu
, toolchain
)
73 for test_id
, title
in BENCHMARKS
:
76 test
= TEST_MAP
[test_id
]
77 path
= build_project(test
.source_dir
, join(build_dir
, test_id
),
78 mcu
, toolchain
, test
.dependencies
)
79 base
, ext
= splitext(path
)
81 code
, data
, bss
, flash
= get_size(base
+'.elf')
82 csv_data
.writerow([toolchain
, mcu
, title
, code
, data
, bss
, flash
])
84 print "Unable to build %s for toolchain %s targeting %s" % (test_id
, toolchain
, mcu
)
88 def compare(t1
, t2
, target
):
89 if not exists(BENCHMARK_DATA_PATH
):
92 print "Loading: %s" % BENCHMARK_DATA_PATH
94 data
= csv
.reader(open(BENCHMARK_DATA_PATH
, 'rb'))
96 benchmarks_data
= defaultdict(dict)
97 for (toolchain
, mcu
, name
, code
, data
, bss
, flash
) in data
:
101 benchmarks_data
[name
][t
] = map(int, (code
, data
, bss
, flash
))
103 print "%s vs %s for %s" % (t1
, t2
, target
)
104 for name
, data
in benchmarks_data
.iteritems():
107 code_a
, data_a
, bss_a
, flash_a
= data
[t1
]
108 code_u
, data_u
, bss_u
, flash_u
= data
[t2
]
110 print "\n=== %s ===" % name
111 print_diff("code", code_a
, code_u
)
112 print_diff("data", data_a
, data_u
)
113 print_diff("bss", bss_a
, bss_u
)
114 print_diff("flash", flash_a
, flash_u
)
116 print "No data for benchmark %s" % (name
)
120 if __name__
== '__main__':
121 compare("GCC_CR", "GCC_CS", "LPC1768")