def test_basic(self): def fib(n): if n == 1 or n == 0: return 1 return fib(n - 1) + fib(n - 2) t = VizTracer(verbose=0) for i in range(5, 10): t.start() fib(i) t.stop() t.parse() t.fork_save(output_file=str(i) + ".json") time.sleep(0.6) expected = {5: 15, 6: 25, 7: 41, 8: 67, 9: 109} pid = None for i in range(5, 10): path = str(i) + ".json" self.assertTrue(os.path.exists(path)) with open(path) as f: data = json.load(f) os.remove(path) self.assertEqual(len(data["traceEvents"]), expected[i]) if pid is None: pid = data["traceEvents"][0]["pid"] else: self.assertEqual(data["traceEvents"][0]["pid"], pid)
def wrapper(*args, **kwargs): tracer = VizTracer(**viztracer_kwargs) tracer.start() ret = func(*args, **kwargs) tracer.stop() if not os.path.exists(output_dir): os.mkdir(output_dir) file_name = os.path.join(output_dir, "result_{}_{}.json".format(func.__name__, int(100000 * time.time()))) tracer.fork_save(file_name) tracer.cleanup() return ret
def test_basic(self): def fib(n): if n == 1 or n == 0: return 1 return fib(n - 1) + fib(n - 2) t = VizTracer(verbose=0) processes = {} for i in range(5, 10): t.start() fib(i) t.stop() t.parse() processes[i] = t.fork_save(output_file=str(i) + ".json") expected = {5: 15, 6: 25, 7: 41, 8: 67, 9: 109} pid = None for i in range(5, 10): path = str(i) + ".json" processes[i].join() self.assertFileExists(path, timeout=10) with open(path) as f: data = json.load(f) os.remove(path) self.assertEventNumber(data, expected[i]) if pid is None: pid = data["traceEvents"][0]["pid"] else: self.assertEqual(data["traceEvents"][0]["pid"], pid)