def inner(*args, **kwargs): res = f(*args, **kwargs) if sys.stdout.isatty(): if 'name' in res.get('meta', {}): name = res['meta']['name'] else: name = sys.argv[0] display_stats(name, res['times']) else: print(json.dumps(res, indent=4))
def run_benchmarks(benchmarks, max_time=None, output_dir=None, includes=None, excludes=None, continue_on_error=False, python_executable=None, env=None): if output_dir and not os.path.exists(output_dir): os.makedirs(output_dir) for benchmark_dir in benchmarks: name = os.path.basename(benchmark_dir) if name in excludes: continue if includes and name not in includes: continue if not output_dir: stderr = sys.stderr else: stderr = open(os.path.join(output_dir, "%s.stderr.log" % name), "wb") data = None try: data = run_benchmark(os.path.join(benchmark_dir, "benchmark.py"), env=None, max_time=max_time, python_executable=python_executable, stderr=stderr) if output_dir: stderr.close() with open(os.path.join(output_dir, "%s.json" % name), "wb") as f: json.dump(data, f, indent=4) display_stats(name, data['times']) del data except RuntimeError as exc: logging.error("%s failed to complete: %s", name, exc) if not continue_on_error: raise