tools: Update timers display format (add module name).

mesh
Pierre-Antoine Rouby 2023-04-25 11:56:52 +02:00
parent 0b06c9be80
commit 937cf47256
1 changed files with 10 additions and 8 deletions

View File

@ -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