diff options
Diffstat (limited to 'grpc/tools/profiling/microbenchmarks/bm_diff/bm_diff.py')
-rwxr-xr-x | grpc/tools/profiling/microbenchmarks/bm_diff/bm_diff.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/grpc/tools/profiling/microbenchmarks/bm_diff/bm_diff.py b/grpc/tools/profiling/microbenchmarks/bm_diff/bm_diff.py index 846682d9..01b622d8 100755 --- a/grpc/tools/profiling/microbenchmarks/bm_diff/bm_diff.py +++ b/grpc/tools/profiling/microbenchmarks/bm_diff/bm_diff.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2.7 +#!/usr/bin/env python3 # # Copyright 2017 gRPC authors. # @@ -15,20 +15,19 @@ # limitations under the License. """ Computes the diff between two bm runs and outputs significant results """ -import bm_constants -import bm_speedup - -import sys +import argparse +import collections +import json import os +import subprocess +import sys sys.path.append(os.path.join(os.path.dirname(sys.argv[0]), '..')) -import bm_json -import json +import bm_constants +import bm_json +import bm_speedup import tabulate -import argparse -import collections -import subprocess verbose = False @@ -38,9 +37,9 @@ def _median(ary): ary = sorted(ary) n = len(ary) if n % 2 == 0: - return (ary[(n - 1) / 2] + ary[(n - 1) / 2 + 1]) / 2.0 + return (ary[(n - 1) // 2] + ary[(n - 1) // 2 + 1]) / 2.0 else: - return ary[n / 2] + return ary[n // 2] def _args(): @@ -82,14 +81,16 @@ def _args(): help='Print details of before/after') args = argp.parse_args() global verbose - if args.verbose: verbose = True + if args.verbose: + verbose = True assert args.new assert args.old return args def _maybe_print(str): - if verbose: print str + if verbose: + print(str) class Benchmark: @@ -110,7 +111,8 @@ class Benchmark: for f in sorted(track): new = self.samples[True][f] old = self.samples[False][f] - if not new or not old: continue + if not new or not old: + continue mdn_diff = abs(_median(new) - _median(old)) _maybe_print('%s: %s=%r %s=%r mdn_diff=%r' % (f, new_name, new, old_name, old, mdn_diff)) @@ -133,14 +135,14 @@ def _read_json(filename, badjson_files, nonexistant_files): with open(filename) as f: r = f.read() return json.loads(r) - except IOError, e: + except IOError as e: if stripped in nonexistant_files: nonexistant_files[stripped] += 1 else: nonexistant_files[stripped] = 1 return None - except ValueError, e: - print r + except ValueError as e: + print(r) if stripped in badjson_files: badjson_files[stripped] += 1 else: @@ -163,6 +165,7 @@ def diff(bms, loops, regex, track, old, new, counters): 'bm_diff_%s/opt/%s' % (old, bm), '--benchmark_list_tests', '--benchmark_filter=%s' % regex ]).splitlines(): + line = line.decode('UTF-8') stripped_line = line.strip().replace("/", "_").replace( "<", "_").replace(">", "_").replace(", ", "_") js_new_opt = _read_json( @@ -204,7 +207,8 @@ def diff(bms, loops, regex, track, old, new, counters): headers = ['Benchmark'] + fields rows = [] for name in sorted(benchmarks.keys()): - if benchmarks[name].skip(): continue + if benchmarks[name].skip(): + continue rows.append([name] + benchmarks[name].row(fields)) note = None if len(badjson_files): |