1#!/usr/bin/env python3 2# vim:fenc=utf-8:ts=2:sw=2:softtabstop=2:expandtab: 3# Copyright 2022 the V8 project authors. All rights reserved. 4# Use of this source code is governed by a BSD-style license that can be 5# found in the LICENSE file. 6 7import sys 8import re 9 10liftoff_regex = re.compile('^Compiled function .* using Liftoff, ' 11 '.*bodysize ([0-9]+) codesize ([0-9]+)$') 12turbofan_regex = re.compile('^Compiled function .* using TurboFan, ' 13 '.*bodysize ([0-9]+) codesize ([0-9]+) ') 14wasm2js_regex = re.compile('^Compiled WasmToJS wrapper .* ' 15 'codesize ([0-9]+)$') 16 17 18def main(): 19 print('Reading --trace-wasm-compilation-times lines from stdin...') 20 liftoff_values = [] 21 turbofan_values = [] 22 wasm2js_values = [] 23 for line in sys.stdin: 24 match(line, liftoff_regex, liftoff_values) 25 match(line, turbofan_regex, turbofan_values) 26 match_wasm2js(line, wasm2js_values) 27 28 evaluate('Liftoff', liftoff_values) 29 evaluate('TurboFan', turbofan_values) 30 evaluate_wasm2js(wasm2js_values) 31 32 33def match(line, regex, array): 34 m = regex.match(line) 35 if m: 36 array.append([int(m.group(1)), int(m.group(2))]) 37 38 39def match_wasm2js(line, array): 40 m = wasm2js_regex.match(line) 41 if m: 42 array.append(int(m.group(1))) 43 44 45def evaluate(name, values): 46 n = len(values) 47 if n == 0: 48 print(f'No values for {name}') 49 return 50 51 print(f'Computing base and factor for {name} based on {n} values') 52 sum_xy = sum(x * y for [x, y] in values) 53 sum_x = sum(x for [x, y] in values) 54 sum_y = sum(y for [x, y] in values) 55 sum_xx = sum(x * x for [x, y] in values) 56 57 factor = (n * sum_xy - sum_x * sum_y) / (n * sum_xx - sum_x * sum_x) 58 base = (sum_y - factor * sum_x) / n 59 60 print(f'--> [{name}] Trend line: base: {base:.2f}, factor {factor:.2f}') 61 62 min_y = min(y for [x, y] in values) 63 64 simple_factor = (sum_y - n * min_y) / sum_x 65 print(f'--> [{name}] Simple analysis: Min {min_y}, ' 66 f'factor {simple_factor:.2f}') 67 68 69def evaluate_wasm2js(values): 70 n = len(values) 71 if n == 0: 72 print('No wasm2js wrappers') 73 return 74 75 print(f'--> [Wasm2js wrappers] {n} compiled, size min {min(values)}, ' 76 f'max {max(values)}, avg {(sum(values) / n):.2f}') 77 78 79main() 80