Commit 937cf472 authored by Pierre-Antoine Rouby's avatar Pierre-Antoine Rouby
Browse files

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

Showing with 10 additions and 8 deletions
+10 -8
......@@ -28,7 +28,7 @@ def display_timers():
global _timers
global _calls
print(f" +--{Fore.BLUE}Timers{Style.RESET_ALL}---------------------------------------------------------+")
print(f" +--{Style.BRIGHT}{Fore.BLUE}Timers{Style.RESET_ALL}------------------------------------------------------------------------------------------+")
lst = sorted(
map(
......@@ -40,9 +40,11 @@ def display_timers():
)
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):
"""Function wrapper to register function runtime"""
......@@ -59,12 +61,12 @@ def timer(func):
end_time = time.perf_counter()
run_time = end_time - start_time
if func.__qualname__ not in _timers:
_timers[func.__qualname__] = 0
_calls[func.__qualname__] = 0
if func not in _timers:
_timers[func] = 0
_calls[func] = 0
_timers[func.__qualname__] += run_time
_calls[func.__qualname__] += 1
_timers[func] += run_time
_calls[func] += 1
return value
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment