mirror of
https://github.com/ynput/ayon-core.git
synced 2026-01-01 08:24:53 +01:00
rename folder
This commit is contained in:
parent
483c930a68
commit
8432e94615
1511 changed files with 0 additions and 0 deletions
29
openpype/lib/profiling.py
Normal file
29
openpype/lib/profiling.py
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
"""Provide profiling decorator."""
|
||||
import os
|
||||
import cProfile
|
||||
|
||||
|
||||
def do_profile(fn, to_file=None):
|
||||
"""Wraps function in profiler run and print stat after it is done.
|
||||
|
||||
Args:
|
||||
to_file (str, optional): If specified, dumps stats into the file
|
||||
instead of printing.
|
||||
|
||||
"""
|
||||
if to_file:
|
||||
to_file = to_file.format(pid=os.getpid())
|
||||
|
||||
def profiled(*args, **kwargs):
|
||||
profiler = cProfile.Profile()
|
||||
try:
|
||||
profiler.enable()
|
||||
res = fn(*args, **kwargs)
|
||||
profiler.disable()
|
||||
return res
|
||||
finally:
|
||||
if to_file:
|
||||
profiler.dump_stats(to_file)
|
||||
else:
|
||||
profiler.print_stats()
|
||||
Loading…
Add table
Add a link
Reference in a new issue