Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
yappi.set_tag_callback(tag_cbk2)
burn_io(0.1)
yappi.stop()
traces = yappi.get_func_stats()
t1 = '''
..p/yappi/tests/utils.py:134 burn_io 2 0.000000 0.208146 0.104073
'''
self.assert_traces_almost_equal(t1, traces)
tagged_traces = yappi.get_func_stats(filter={'tag': 2})
t1 = '''
..p/yappi/tests/utils.py:134 burn_io 1 0.000000 0.105063 0.105063
'''
self.assert_traces_almost_equal(t1, tagged_traces)
yappi.clear_stats()
def setUp(self):
# reset everything back to default
yappi.stop()
yappi.clear_stats()
yappi.set_clock_type('cpu') # reset to default clock type
yappi.set_context_id_callback(None)
yappi.set_context_name_callback(None)
yappi.set_tag_callback(None)
def test_no_stats_different_clock_type_load(self):
def a():
pass
yappi.start()
a()
yappi.stop()
yappi.get_func_stats().save("tests/ystats1.ys")
yappi.clear_stats()
yappi.set_clock_type("WALL")
yappi.start()
yappi.stop()
stats = yappi.get_func_stats().add("tests/ystats1.ys")
fsa = utils.find_stat_by_name(stats, 'a')
self.assertTrue(fsa is not None)
yappi.set_tag_callback(tag_cbk2)
burn_cpu(0.1)
yappi.stop()
traces = yappi.get_func_stats()
t1 = '''
../yappi/tests/utils.py:125 burn_cpu 2 0.000000 0.200156 0.100078
'''
self.assert_traces_almost_equal(t1, traces)
tagged_traces = yappi.get_func_stats(filter={'tag': 1})
t1 = '''
../yappi/tests/utils.py:125 burn_cpu 1 0.000000 0.100062 0.100062
'''
self.assert_traces_almost_equal(t1, tagged_traces)
yappi.clear_stats()
# test wall
yappi.set_clock_type("wall")
yappi.set_tag_callback(tag_cbk)
yappi.start()
burn_io(0.1)
yappi.set_tag_callback(tag_cbk2)
burn_io(0.1)
yappi.stop()
traces = yappi.get_func_stats()
t1 = '''
..p/yappi/tests/utils.py:134 burn_io 2 0.000000 0.208146 0.104073
'''
self.assert_traces_almost_equal(t1, traces)
tagged_traces = yappi.get_func_stats(filter={'tag': 2})
def a():
pass
def b():
pass
yappi.start()
t = threading.Thread(target=a)
t.start()
t.join()
t = threading.Thread(target=b)
t.start()
t.join()
yappi.get_func_stats().save("tests/ystats1.ys")
yappi.clear_stats()
_yappi._set_test_timings(timings)
self.assertEqual(len(yappi.get_func_stats()), 0)
self.assertEqual(len(yappi.get_thread_stats()), 1)
t = threading.Thread(target=a)
t.start()
t.join()
self.assertEqual(_yappi._get_start_flags()["profile_builtins"], 0)
self.assertEqual(_yappi._get_start_flags()["profile_multithread"], 1)
yappi.get_func_stats().save("tests/ystats2.ys")
stats = yappi.YFuncStats([
"tests/ystats1.ys",
"tests/ystats2.ys",
])
fsa = utils.find_stat_by_name(stats, "a")
asyncio.get_event_loop().run_until_complete(a())
asyncio.get_event_loop().run_until_complete(a())
yappi.stop()
r1 = '''
..p/yappi/tests/test_asyncio.py:43 a 2 0.000118 1.604049 0.802024
async_sleep 6 0.000000 0.603239 0.100540
../yappi/tests/utils.py:126 burn_cpu 2 0.576313 0.600026 0.300013
..p/yappi/tests/utils.py:135 burn_io 4 0.000025 0.400666 0.100166
time.sleep 4 0.400641 0.400641 0.100160
'''
stats = yappi.get_func_stats()
self.assert_traces_almost_equal(r1, stats)
yappi.clear_stats()
yappi.set_clock_type("cpu")
yappi.start(builtins=True)
asyncio.get_event_loop().run_until_complete(a())
asyncio.get_event_loop().run_until_complete(a())
yappi.stop()
stats = yappi.get_func_stats()
r1 = '''
..p/yappi/tests/test_asyncio.py:43 a 2 0.000117 0.601170 0.300585
../yappi/tests/utils.py:126 burn_cpu 2 0.000000 0.600047 0.300024
async_sleep 6 0.000159 0.000801 0.000134
time.sleep 4 0.000169 0.000169 0.000042
'''
self.assert_traces_almost_equal(r1, stats)
def clear_stats(self):
yappi.clear_stats()
return '<a href="stats">stats</a>'
def _startProfiling():
logger.info("Activating new profiler")
yappi.clear_stats()
yappi.start()
_updateMenuStatus()
def __exit__(self,*args):
import yappi
yappi.stop()
yappi.print_stats()
yappi.clear_stats()