| 45 | |
| 46 | |
| 47 | def print_sizes(js_file): |
| 48 | if not os.path.isfile(js_file): |
| 49 | return error('Input JS file %s not found' % js_file) |
| 50 | if not js_file.endswith('.js'): |
| 51 | return error('Input file %s does not have a JS extension' % js_file) |
| 52 | |
| 53 | basename = js_file[:-3] |
| 54 | |
| 55 | # Find the JS file size |
| 56 | st = os.stat(js_file) |
| 57 | js_size = st.st_size |
| 58 | |
| 59 | # Find the rest of the sizes |
| 60 | wasm_file = basename + '.wasm' |
| 61 | if not os.path.isfile(wasm_file): |
| 62 | return error('Wasm file %s not found' % wasm_file) |
| 63 | |
| 64 | sizes = shared.check_call([LLVM_SIZE, '--format=sysv', wasm_file], |
| 65 | stdout=subprocess.PIPE).stdout |
| 66 | # llvm-size may emit some number of blank lines (after the total), ignore them |
| 67 | lines = [line for line in sizes.splitlines() if line] |
| 68 | |
| 69 | # Last line is the total. Add the JS size. |
| 70 | total = int(lines[-1].split()[-1]) |
| 71 | total += js_size |
| 72 | |
| 73 | for line in lines[:-1]: |
| 74 | print(line) |
| 75 | |
| 76 | print('JS\t\t%s\t0' % js_size) |
| 77 | print('Total\t\t%s' % total) |
| 78 | |
| 79 | |
| 80 | if __name__ == '__main__': |