dbt-selly/dbt-env/lib/python3.8/site-packages/dbt/profiler.py

20 lines
424 B
Python
Raw Normal View History

2022-03-22 15:13:27 +00:00
from contextlib import contextmanager
from cProfile import Profile
from pstats import Stats
@contextmanager
def profiler(enable, outfile):
try:
if enable:
profiler = Profile()
profiler.enable()
yield
finally:
if enable:
profiler.disable()
stats = Stats(profiler)
stats.sort_stats('tottime')
stats.dump_stats(outfile)