16 """ Computes the diff between two qps runs and outputs significant results """
20 import multiprocessing
30 os.path.join(os.path.dirname(sys.argv[0]),
'..',
'microbenchmarks',
35 os.path.join(os.path.dirname(sys.argv[0]),
'..',
'..',
'run_tests',
41 argp = argparse.ArgumentParser(description=
'Perform diff on QPS Driver')
42 argp.add_argument(
'-d',
45 help=
'Commit or branch to compare the current one to')
51 help=
'Number of loops for each benchmark. More loops cuts down on noise'
53 argp.add_argument(
'-j',
56 default=multiprocessing.cpu_count(),
57 help=
'Number of CPUs to use')
58 args = argp.parse_args()
59 assert args.diff_base,
"diff_base must be set"
64 return [
'make',
'-j',
'%d' % jobs,
'qps_json_driver',
'qps_worker']
68 shutil.rmtree(
'qps_diff_%s' % name, ignore_errors=
True)
69 subprocess.check_call([
'git',
'submodule',
'update'])
72 except subprocess.CalledProcessError
as e:
73 subprocess.check_call([
'make',
'clean'])
75 os.rename(
'bins',
'qps_diff_%s' % name)
80 'qps_diff_%s/opt/qps_json_driver' % name,
'--scenarios_json', scenario,
81 '--json_file_out', fname
85 def run(name, scenarios, loops):
87 for i
in range(0, loops):
88 fname =
"%s.%s.%d.json" % (sn, name, i)
89 subprocess.check_call(
_run_cmd(name, scenarios[sn], fname))
94 with open(fname)
as f:
95 return json.loads(f.read())[
'qps']
97 print((
"IOError occurred reading file: %s" % fname))
99 except ValueError
as e:
100 print((
"ValueError occurred reading file: %s" % fname))
109 return (ary[(n - 1) / 2] + ary[(n - 1) / 2 + 1]) / 2.0
114 def diff(scenarios, loops, old, new):
122 for i
in range(loops):
123 old_data[sn].append(
_load_qps(
"%s.%s.%d.json" % (sn, old, i)))
124 new_data[sn].append(
_load_qps(
"%s.%s.%d.json" % (sn, new, i)))
127 headers = [
'Benchmark',
'qps']
131 print((
'%s: %s=%r %s=%r mdn_diff=%r' %
132 (sn, new, new_data[sn], old, old_data[sn], mdn_diff)))
134 if abs(s) > 3
and mdn_diff > 0.5:
135 rows.append([sn,
'%+d%%' % s])
138 return tabulate.tabulate(rows, headers=headers, floatfmt=
'+.2f')
144 build(
'new', args.jobs)
147 where_am_i = subprocess.check_output(
148 [
'git',
'rev-parse',
'--abbrev-ref',
'HEAD']).
decode().strip()
149 subprocess.check_call([
'git',
'checkout', args.diff_base])
151 build(
'old', args.jobs)
153 subprocess.check_call([
'git',
'checkout', where_am_i])
154 subprocess.check_call([
'git',
'submodule',
'update'])
156 run(
'new', qps_scenarios._SCENARIOS, args.loops)
157 run(
'old', qps_scenarios._SCENARIOS, args.loops)
159 diff_output =
diff(qps_scenarios._SCENARIOS, args.loops,
'old',
'new')
162 text =
'[qps] Performance differences noted:\n%s' % diff_output
164 text =
'[qps] No significant performance differences'
166 check_on_pr.check_on_pr(
'QPS',
'```\n%s\n```' % text)
169 if __name__ ==
'__main__':