Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NEW profiler decorator #1110

Merged
merged 7 commits into from
Aug 18, 2020
Merged
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions conda_forge_tick/profiler.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import cProfile
import os
from functools import wraps
from datetime import datetime


# profiling decorator
def profiling():
def _profiling(f):
@wraps(f)
def __profiling(*rgs, **kwargs):
with cProfile.Profile() as prof:
prof.enable()

out_result = f(*rgs, **kwargs)
f(*rgs, **kwargs)

prof.disable()

# get current time
now = datetime.now()
current_time = now.strftime("%d-%m-%Y") + "_" + now.strftime("%H_%M_%S")
# process name -- aka profiler sub-folder
process_name = os.path.basename(__file__)
# check dir
os.makedirs(f"profiler/{process_name}", exist_ok=True)
# save stats into file
prof.dump_stats(f"profiler/{process_name}/{current_time}")

return out_result

return __profiling

return _profiling