tools: Fix table size.

mesh
Pierre-Antoine Rouby 2023-05-03 11:28:49 +02:00
parent 500d97d7d3
commit 11906efb2c
1 changed files with 19 additions and 3 deletions

View File

@ -29,7 +29,19 @@ def display_timers():
global _timers global _timers
global _calls global _calls
print(f" +--{Style.BRIGHT}{Fore.BLUE}Timers{Style.RESET_ALL}------------------------------------------------------------------------------------------+") fmax = max(
map(
lambda f: len(f.__qualname__) + len(f.__module__),
_timers
)
)
head = " +--"
head += f"{Style.BRIGHT}{Fore.BLUE}Timers{Style.RESET_ALL}"
for t in range(fmax + 26):
head += "-"
head += "+"
print(head)
lst = sorted( lst = sorted(
map( map(
@ -42,10 +54,14 @@ def display_timers():
for func, time, calls in lst: for func, time, calls in lst:
name = (f"{Fore.BLUE}{func.__module__}{Style.RESET_ALL}" + name = (f"{Fore.BLUE}{func.__module__}{Style.RESET_ALL}" +
f".{Style.BRIGHT}{Fore.GREEN}{func.__qualname__:<{64 - len(func.__module__)}}{Style.RESET_ALL}") f".{Style.BRIGHT}{Fore.GREEN}{func.__qualname__:<{fmax - len(func.__module__)}}{Style.RESET_ALL}")
print(f" | {name} | {time:>10.6f} sec | {calls:>5} calls |") print(f" | {name} | {time:>10.6f} sec | {calls:>5} calls |")
print(" +--------------------------------------------------------------------------------------------------+") tail = " +--"
for t in range(fmax + 32):
tail += "-"
tail += "+"
print(tail)
def timer(func): def timer(func):
"""Function wrapper to register function runtime""" """Function wrapper to register function runtime"""