|
| 1 | +#!/usr/bin/python3 |
| 2 | + |
| 3 | +# Copyright 2020 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 | + |
| 7 | +import sys |
| 8 | +import re |
| 9 | +import subprocess |
| 10 | +from collections import Counter |
| 11 | +import argparse |
| 12 | +from prettytable import PrettyTable |
| 13 | + |
| 14 | +def Count(sub): |
| 15 | + couts = Counter() |
| 16 | + for line in sub.stdout: |
| 17 | + split = line.strip().decode('utf-8').split() |
| 18 | + if("0x" not in split[0]): |
| 19 | + continue |
| 20 | + if(len(split) >= 4): |
| 21 | + couts.update([split[2]]) |
| 22 | + cout = couts.items() |
| 23 | + cout = list(cout) |
| 24 | + cout.sort(key=lambda x: x[1], reverse=True) |
| 25 | + |
| 26 | + num = 0 |
| 27 | + for key, value in couts.items(): |
| 28 | + num += value |
| 29 | + |
| 30 | + return num, cout |
| 31 | + |
| 32 | +def ArgsInit(): |
| 33 | + parser = argparse.ArgumentParser() |
| 34 | + parser.add_argument('arch1', help="The path of an architecture executable d8.") |
| 35 | + parser.add_argument('arch2', help="The path of an architecture executable d8.") |
| 36 | + parser.add_argument('d8_object', nargs='+', help="The path to the target of d8 operation") |
| 37 | + args, unknown = parser.parse_known_args() |
| 38 | + return args, unknown |
| 39 | + |
| 40 | + |
| 41 | +def Compare(arch1, arch2): |
| 42 | + summary = PrettyTable(["Summary", arch1[2], arch2[2]]) |
| 43 | + summary.add_row(["count", arch1[0], arch2[0]]) |
| 44 | + print(summary) |
| 45 | + |
| 46 | + x = PrettyTable(["arch1_instr","arch1_ratio","arch1_count","arch2_instr","arch2_ratio","arch2_count"]) |
| 47 | + for n, v in zip(arch1[1], arch2[1]): |
| 48 | + row = [n[0], "{:.2%}".format(float(n[1]) / arch1[0]),n[1]] |
| 49 | + row.extend([v[0], "{:.2%}".format(float(v[1]) / arch2[0]), v[1]]) |
| 50 | + x.add_row(row) |
| 51 | + print(x) |
| 52 | + |
| 53 | +if __name__ == "__main__": |
| 54 | + args, run_args = ArgsInit() |
| 55 | + run_args.append("--trace-sim") |
| 56 | + run_args.insert(0, args.arch1) |
| 57 | + run_args.extend(args.d8_object) |
| 58 | + sub = subprocess.Popen( |
| 59 | + run_args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 60 | + risv = (Count(sub))+tuple(["arch1"]) |
| 61 | + |
| 62 | + run_args[0] = args.arch2 |
| 63 | + sub = subprocess.Popen( |
| 64 | + run_args, shell=False, stdout=subprocess.PIPE, stderr=subprocess.STDOUT) |
| 65 | + mips64el = (Count(sub))+tuple(["arhc2"]) |
| 66 | + Compare(risv, mips64el) |
| 67 | + pass |
0 commit comments