mirror of https://gitlab.com/pamhyr/pamhyr2
tools: Update timers display format (add module name).
parent
0b06c9be80
commit
937cf47256
18
src/tools.py
18
src/tools.py
|
|
@ -28,7 +28,7 @@ def display_timers():
|
||||||
global _timers
|
global _timers
|
||||||
global _calls
|
global _calls
|
||||||
|
|
||||||
print(f" +--{Fore.BLUE}Timers{Style.RESET_ALL}---------------------------------------------------------+")
|
print(f" +--{Style.BRIGHT}{Fore.BLUE}Timers{Style.RESET_ALL}------------------------------------------------------------------------------------------+")
|
||||||
|
|
||||||
lst = sorted(
|
lst = sorted(
|
||||||
map(
|
map(
|
||||||
|
|
@ -40,9 +40,11 @@ def display_timers():
|
||||||
)
|
)
|
||||||
|
|
||||||
for func, time, calls in lst:
|
for func, time, calls in lst:
|
||||||
print(f" | {Fore.GREEN}{func:<32}{Style.RESET_ALL} | {time:>10.6f} sec | {calls:>5} calls |")
|
name = (f"{Fore.BLUE}{func.__module__}{Style.RESET_ALL}" +
|
||||||
|
f".{Style.BRIGHT}{Fore.GREEN}{func.__qualname__:<{64 - len(func.__module__)}}{Style.RESET_ALL}")
|
||||||
|
print(f" | {name} | {time:>10.6f} sec | {calls:>5} calls |")
|
||||||
|
|
||||||
print(" +-----------------------------------------------------------------+")
|
print(" +--------------------------------------------------------------------------------------------------+")
|
||||||
|
|
||||||
def timer(func):
|
def timer(func):
|
||||||
"""Function wrapper to register function runtime"""
|
"""Function wrapper to register function runtime"""
|
||||||
|
|
@ -59,12 +61,12 @@ def timer(func):
|
||||||
end_time = time.perf_counter()
|
end_time = time.perf_counter()
|
||||||
run_time = end_time - start_time
|
run_time = end_time - start_time
|
||||||
|
|
||||||
if func.__qualname__ not in _timers:
|
if func not in _timers:
|
||||||
_timers[func.__qualname__] = 0
|
_timers[func] = 0
|
||||||
_calls[func.__qualname__] = 0
|
_calls[func] = 0
|
||||||
|
|
||||||
_timers[func.__qualname__] += run_time
|
_timers[func] += run_time
|
||||||
_calls[func.__qualname__] += 1
|
_calls[func] += 1
|
||||||
|
|
||||||
return value
|
return value
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue