def test_include_exclude_exception(self): tracer = _VizTracer(exclude_files=["./src/"], include_files=["./"]) with self.assertRaises(Exception): tracer.start() tracer = _VizTracer(exclude_files=["./src/"]) tracer.include_files = ["./"] with self.assertRaises(Exception): tracer.start() tracer.exclude_files = None tracer.start() tracer.stop()
def test_max_stack_depth(self): tracer = _VizTracer(tracer="c", max_stack_depth=3) tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 7) tracer = _VizTracer(tracer="python", max_stack_depth=3) tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 10)
def test_novdb(self): tracer = _VizTracer(novdb=False) tracer.start() fib(5) tracer.stop() tracer.parse() self.assertTrue("caller_lineno" in tracer.data["traceEvents"][0]) tracer = _VizTracer(novdb=True) tracer.start() fib(5) tracer.stop() tracer.parse() self.assertFalse("caller_lineno" in tracer.data["traceEvents"][0])
def test_novdb(self): tracer = _VizTracer(vdb=True) tracer.start() fib(5) tracer.stop() tracer.parse() events = [e for e in tracer.data["traceEvents"] if e["ph"] != "M"] self.assertTrue("caller_lineno" in events[0]) tracer = _VizTracer(vdb=False) tracer.start() fib(5) tracer.stop() tracer.parse() events = [e for e in tracer.data["traceEvents"] if e["ph"] != "M"] self.assertFalse("caller_lineno" in events[0])
def test_log_function_args(self): tracer = _VizTracer(log_function_args=True) tracer.start() fib(5) tracer.stop() tracer.parse() self.assertTrue("args" in tracer.data["traceEvents"][0] and "func_args" in tracer.data["traceEvents"][0]["args"])
def test_wrap(self): tracer = _VizTracer(tracer_entries=10) tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 10)
def test_exclude_files(self): tracer = _VizTracer(exclude_files=["./src/"]) tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 177) tracer.exclude_files = [os.path.abspath("./")] tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 0) tracer.exclude_files = ["./"] tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 0) tracer.exclude_files = [] tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 177)
def test_json(self): t = _VizTracer() t.start() fib(10) t.stop() t.parse() t.generate_json()
def test_c_load(self): tracer = _VizTracer(tracer="c") tracer.start() fib(5) tracer.stop() tracer.parse() with open("result.html", "w") as f: f.write(tracer.generate_report())
def test_c_cleanup(self): tracer = _VizTracer() tracer.start() fib(5) tracer.stop() tracer.cleanup() tracer.clear() tracer.cleanup()
def test_log_func_args(self): tracer = _VizTracer(log_func_args=True) tracer.start() fib(5) tracer.stop() tracer.parse() events = [e for e in tracer.data["traceEvents"] if e["ph"] != "M"] self.assertTrue("args" in events[0] and "func_args" in events[0]["args"])
def test_ignore_frozen(self): tracer = _VizTracer(ignore_frozen=True) tracer.start() import random # noqa: F401 lst = [] lst.append(1) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 1)
def test_ignore_non_file(self): tracer = _VizTracer(ignore_non_file=True) tracer.start() import random lst = [] lst.append(1) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 1)
def test_min_duration(self): tracer = _VizTracer(min_duration=10) tracer.start() a = [] for _ in range(3): a.append(1) time.sleep(0.001) tracer.stop() tracer.parse() self.assertEventNumber(tracer.data, 1)
def test_double_parse(self): tracer = _VizTracer() tracer.start() fib(10) tracer.stop() tracer.parse() result1 = tracer.generate_report() tracer.parse() result2 = tracer.generate_report() self.assertEqual(result1, result2)
def test_construct(self): def fib(n): if n == 1 or n == 0: return 1 return fib(n-1) + fib(n-2) t = _VizTracer() t.start() fib(5) t.stop() entries = t.parse() self.assertEqual(entries, 15)
def test_builtin_func(self): import random def fun(n): for _ in range(n): random.randrange(n) t = _VizTracer(ignore_c_function=True) t.start() fun(10) t.stop() entries = t.parse() self.assertEqual(entries, 21)
def test_construct(self): def fib(n): if n == 1 or n == 0: return 1 return fib(n - 1) + fib(n - 2) t = _VizTracer() t.start() fib(5) t.stop() t.parse() self.assertEventNumber(t.data, 15)
def test_builtin_func(self): import random def fun(n): for _ in range(n): random.randrange(n) t = _VizTracer(ignore_c_function=True) t.start() fun(10) t.stop() t.parse() self.assertEventNumber(t.data, 21)
def test_builtin_func(self): def fun(n): import random for _ in range(n): random.randrange(n) t = _VizTracer() t.start() fun(10) t.stop() entries = t.parse() self.assertEqual(entries, 32)
def test_exclude_files(self): tracer = _VizTracer(tracer="c", exclude_files=["./src/"]) tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 176) tracer.exclude_files = ["./"] tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 0)
def test_c_run_after_clear(self): tracer = _VizTracer() tracer.start() fib(5) tracer.stop() entries1 = tracer.parse() report1 = tracer.generate_report() tracer.start() fib(5) tracer.stop() entries2 = tracer.parse() report2 = tracer.generate_report() self.assertEqual(entries1, entries2) self.assertNotEqual(report1, report2)
def test_log_gc(self): import gc tracer = _VizTracer(log_gc=True) self.assertTrue(tracer.log_gc) tracer.start() gc.collect() tracer.stop() tracer.parse() self.assertEqual(len(tracer.data["traceEvents"]), 3) tracer.log_gc = False tracer.start() gc.collect() tracer.stop() tracer.parse() self.assertEqual(len(tracer.data["traceEvents"]), 1)
def test_log_return_value(self): tracer = _VizTracer() tracer.start() fib(5) tracer.stop() tracer.parse() self.assertFalse("args" in tracer.data["traceEvents"][0]) tracer.log_return_value = True tracer.start() fib(5) tracer.stop() tracer.parse() self.assertTrue("args" in tracer.data["traceEvents"][0] and \ "return_value" in tracer.data["traceEvents"][0]["args"])
def test_include_files(self): tracer = _VizTracer(tracer="c", include_files=["./src/"]) tracer.start() fib(10) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 0) tracer.include_files = ["./"] tracer.start() fib(10) tracer.stop() entries = tracer.parse() with open("result.html", "w") as f: f.write(tracer.generate_report()) self.assertEqual(entries, 177)
def test_ignore_c_function(self): tracer = _VizTracer() tracer.start() lst = [] lst.append(1) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 1) tracer.ignore_c_function = True tracer.start() lst = [] lst.append(1) tracer.stop() entries = tracer.parse() self.assertEqual(entries, 0)
def test_log_func_retval(self): tracer = _VizTracer() tracer.start() fib(5) tracer.stop() tracer.parse() events = [e for e in tracer.data["traceEvents"] if e["ph"] != "M"] self.assertFalse("args" in events[0]) tracer.log_func_retval = True tracer.start() fib(5) tracer.stop() tracer.parse() events = [e for e in tracer.data["traceEvents"] if e["ph"] != "M"] self.assertTrue("args" in events[0] and "return_value" in events[0]["args"])
def test_log_gc(self): import gc tracer = _VizTracer(log_gc=True) # do collect first to get rid of the garbage tracer gc.collect() self.assertTrue(tracer.log_gc) tracer.start() gc.collect() tracer.stop() tracer.parse() self.assertEventNumber(tracer.data, 3) tracer.log_gc = False tracer.start() gc.collect() tracer.stop() tracer.parse() self.assertEventNumber(tracer.data, 1)
def test_c_load(self): tracer = _VizTracer() tracer.start() fib(5) tracer.stop() tracer.parse()