2020-11-06 17:23:14 +00:00
|
|
|
# piker: trading gear for hackers
|
|
|
|
# Copyright (C) 2018-present Tyler Goodlet (in stewardship of piker0)
|
|
|
|
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 of the License, or
|
|
|
|
# (at your option) any later version.
|
|
|
|
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <https://www.gnu.org/licenses/>.
|
2020-10-26 14:54:46 +00:00
|
|
|
|
|
|
|
"""
|
|
|
|
Profiling wrappers for internal libs.
|
2020-12-29 15:15:38 +00:00
|
|
|
|
2020-10-26 14:54:46 +00:00
|
|
|
"""
|
|
|
|
import time
|
|
|
|
from functools import wraps
|
|
|
|
|
2022-03-09 16:08:49 +00:00
|
|
|
# NOTE: you can pass a flag to enable this:
|
|
|
|
# ``piker chart <args> --profile``.
|
|
|
|
_pg_profile: bool = False
|
2022-04-05 13:18:19 +00:00
|
|
|
ms_slower_then: float = 0
|
2020-12-29 15:15:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
def pg_profile_enabled() -> bool:
|
|
|
|
global _pg_profile
|
|
|
|
return _pg_profile
|
|
|
|
|
2020-10-26 14:54:46 +00:00
|
|
|
|
|
|
|
def timeit(fn):
|
|
|
|
@wraps(fn)
|
|
|
|
def wrapper(*args, **kwargs):
|
|
|
|
t = time.time()
|
|
|
|
res = fn(*args, **kwargs)
|
|
|
|
print(
|
|
|
|
'%s.%s: %.4f sec'
|
|
|
|
% (fn.__module__, fn.__qualname__, time.time() - t)
|
|
|
|
)
|
|
|
|
return res
|
|
|
|
|
|
|
|
return wrapper
|