From 349907b6459b639a937130f4de23e785cbf289d1 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Fri, 14 Apr 2017 13:00:47 -0700 Subject: [PATCH] Handle EINTR on reading file --- tools/profiling/microbenchmarks/bm_diff.py | 25 +++++++++++++++------- 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/tools/profiling/microbenchmarks/bm_diff.py b/tools/profiling/microbenchmarks/bm_diff.py index 3d4fa2a96a5..ba0c225f6cc 100755 --- a/tools/profiling/microbenchmarks/bm_diff.py +++ b/tools/profiling/microbenchmarks/bm_diff.py @@ -46,6 +46,7 @@ import itertools import speedup import random import shutil +import errno _INTERESTING = ( 'cpu_time', @@ -191,18 +192,26 @@ class Benchmark: return [self.final[f] if f in self.final else '' for f in flds] +def read_file(filename): + while True: + try: + with open(filename) as f: + return f.read() + except IOError, e: + if e.errno != errno.EINTR: + raise + +def read_json(filename): + return json.loads(read_file(filename)) + benchmarks = collections.defaultdict(Benchmark) for bm in args.benchmarks: for loop in range(0, args.loops): - with open('%s.counters.new.%d.json' % (bm, loop)) as f: - js_new_ctr = json.loads(f.read()) - with open('%s.opt.new.%d.json' % (bm, loop)) as f: - js_new_opt = json.loads(f.read()) - with open('%s.counters.old.%d.json' % (bm, loop)) as f: - js_old_ctr = json.loads(f.read()) - with open('%s.opt.old.%d.json' % (bm, loop)) as f: - js_old_opt = json.loads(f.read()) + js_new_ctr = read_json('%s.counters.new.%d.json' % (bm, loop)) + js_new_opt = read_json('%s.opt.new.%d.json' % (bm, loop)) + js_old_ctr = read_json('%s.counters.old.%d.json' % (bm, loop)) + js_old_opt = read_json('%s.opt.old.%d.json' % (bm, loop)) for row in bm_json.expand_json(js_new_ctr, js_new_opt): print row