This commit is contained in:
2026-01-19 00:29:24 +03:00
parent 9d250fde9c
commit a174e0d5ab
8 changed files with 20 additions and 19 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ from argenta.app import StaticDividingLine
from .handlers import router from .handlers import router
app = App(initial_message="metrics", prompt=">>> ", dividing_line=StaticDividingLine('~', length=70)) app = App(initial_message="metrics", prompt=">>> ", dividing_line=None)
orchestrator = Orchestrator() orchestrator = Orchestrator()
+2 -2
View File
@@ -154,10 +154,10 @@ class Benchmarks:
benchmark_results=benchmark_results benchmark_results=benchmark_results
) )
def run_benchmarks_grouped_by_type(self) -> list[BenchmarkGroupResult]: def run_benchmarks_grouped_by_type(self, iterations: int = 100, is_gc_disabled: bool = False) -> list[BenchmarkGroupResult]:
results: list[BenchmarkGroupResult] = [] results: list[BenchmarkGroupResult] = []
for type_, benchmarks in self._benchmarks_grouped_by_type.items(): for type_, benchmarks in self._benchmarks_grouped_by_type.items():
results.append(self.run_benchmarks_by_type(type_)) results.append(self.run_benchmarks_by_type(type_, iterations, is_gc_disabled))
return results return results
def get_benchmarks_by_type(self, type_: str) -> list[Benchmark]: def get_benchmarks_by_type(self, type_: str) -> list[Benchmark]:
+10 -3
View File
@@ -1,5 +1,6 @@
from rich.console import Console from rich.console import Console
from argenta.command import Flag, PossibleValues
from argenta.command.models import Command from argenta.command.models import Command
from argenta.response import Response from argenta.response import Response
from argenta.router import Router from argenta.router import Router
@@ -12,13 +13,19 @@ console = Console()
router = Router(title="Metrics commands:") router = Router(title="Metrics commands:")
@router.command(Command("all-print", description="Print all benchmarks results")) @router.command(
Command(
"all-print",
description="Print all benchmarks results",
flags=Flag('without-gc', possible_values=PossibleValues.NEITHER)
)
)
def all_print_handler(_: Response) -> None: def all_print_handler(_: Response) -> None:
report_generator = ReportGenerator(get_system_info()) report_generator = ReportGenerator(get_system_info())
console.print(report_generator.generate_system_info_header()) console.print(report_generator.generate_system_info_header())
console.print(report_generator.generate_system_info_table()) console.print(report_generator.generate_system_info_table())
return is_gc_disabled = _.input_flags.get_flag_by_name("without-gc")
type_grouped_benchmarks: list[BenchmarkGroupResult] = registered_benchmarks.run_benchmarks_grouped_by_type() type_grouped_benchmarks: list[BenchmarkGroupResult] = registered_benchmarks.run_benchmarks_grouped_by_type(is_gc_disabled=is_gc_disabled)
for benchmark_group_result in type_grouped_benchmarks: for benchmark_group_result in type_grouped_benchmarks:
console.print(report_generator.generate_benchmark_table_header(benchmark_group_result)) console.print(report_generator.generate_benchmark_table_header(benchmark_group_result))
console.print(report_generator.generate_benchmark_report_table(benchmark_group_result)) console.print(report_generator.generate_benchmark_report_table(benchmark_group_result))
+1 -2
View File
@@ -36,6 +36,7 @@ class ReportGenerator:
def generate_benchmark_table_header(benchmark_group_result: BenchmarkGroupResult) -> Panel: def generate_benchmark_table_header(benchmark_group_result: BenchmarkGroupResult) -> Panel:
header_text = Text(f"TYPE: {benchmark_group_result.type_.upper()} ; " header_text = Text(f"TYPE: {benchmark_group_result.type_.upper()} ; "
f"ITERATIONS: {benchmark_group_result.iterations} ; " f"ITERATIONS: {benchmark_group_result.iterations} ; "
f"GC {"DISABLED" if benchmark_group_result.is_gc_disabled else "ENABLED"} ; "
f"ALL TIME IN MS", f"ALL TIME IN MS",
style="bold magenta") style="bold magenta")
return Panel(header_text, expand=False, border_style="magenta") return Panel(header_text, expand=False, border_style="magenta")
@@ -55,8 +56,6 @@ class ReportGenerator:
table.add_row("CPU Physical Cores", str(self.system_info.cpu_info.physical_cores)) table.add_row("CPU Physical Cores", str(self.system_info.cpu_info.physical_cores))
table.add_row("CPU Logical Cores", str(self.system_info.cpu_info.logical_cores)) table.add_row("CPU Logical Cores", str(self.system_info.cpu_info.logical_cores))
table.add_row("CPU Max Frequency", str(self.system_info.cpu_info.max_frequency) + ' GHz') table.add_row("CPU Max Frequency", str(self.system_info.cpu_info.max_frequency) + ' GHz')
table.add_row("CPU Min Frequency", str(self.system_info.cpu_info.min_frequency) + ' GHz')
table.add_row("CPU Current Frequency", str(self.system_info.cpu_info.current_frequency) + ' GHz')
table.add_row("Total RAM", str(self.system_info.memory_info.total_ram) + ' GB') table.add_row("Total RAM", str(self.system_info.memory_info.total_ram) + ' GB')
table.add_row("Used RAM", str(self.system_info.memory_info.used_ram) + ' GB') table.add_row("Used RAM", str(self.system_info.memory_info.used_ram) + ' GB')
table.add_row("Available RAM", str(self.system_info.memory_info.available_ram) + ' GB') table.add_row("Available RAM", str(self.system_info.memory_info.available_ram) + ' GB')
-6
View File
@@ -30,8 +30,6 @@ class CPUInfo:
physical_cores: int physical_cores: int
logical_cores: int logical_cores: int
max_frequency: float max_frequency: float
min_frequency: float
current_frequency: float
@dataclass(frozen=True, slots=True) @dataclass(frozen=True, slots=True)
class MemoryInfo: class MemoryInfo:
@@ -93,8 +91,6 @@ def get_cpu_info() -> CPUInfo:
cpu_logical_cores = psutil.cpu_count(logical=True) cpu_logical_cores = psutil.cpu_count(logical=True)
cpu_freq = psutil.cpu_freq() or "N/A" cpu_freq = psutil.cpu_freq() or "N/A"
cpu_current_frequency = cpu_freq.current
cpu_min_frequency = cpu_freq.min
cpu_max_frequency = cpu_freq.max cpu_max_frequency = cpu_freq.max
return CPUInfo( return CPUInfo(
@@ -102,8 +98,6 @@ def get_cpu_info() -> CPUInfo:
architecture=cpu_architecture, architecture=cpu_architecture,
physical_cores=cpu_physical_cores, physical_cores=cpu_physical_cores,
logical_cores=cpu_logical_cores, logical_cores=cpu_logical_cores,
current_frequency=cpu_current_frequency,
min_frequency=cpu_min_frequency,
max_frequency=cpu_max_frequency max_frequency=cpu_max_frequency
) )
+1 -1
View File
@@ -4,7 +4,7 @@ from argenta.app import DynamicDividingLine
from .routers import router from .routers import router
app: App = App(prompt='>>> ', dividing_line=DynamicDividingLine('~')) app: App = App(prompt='>>> ', dividing_line=None)
orchestrator: Orchestrator = Orchestrator() orchestrator: Orchestrator = Orchestrator()
def main() -> None: def main() -> None:
+4 -3
View File
@@ -42,7 +42,7 @@ class BaseApp:
farewell_message: str, farewell_message: str,
exit_command: Command, exit_command: Command,
system_router_title: str, system_router_title: str,
dividing_line: StaticDividingLine | DynamicDividingLine, dividing_line: StaticDividingLine | DynamicDividingLine | None,
repeat_command_groups_printing: bool, repeat_command_groups_printing: bool,
override_system_messages: bool, override_system_messages: bool,
autocompleter: AutoCompleter, autocompleter: AutoCompleter,
@@ -198,7 +198,8 @@ class BaseApp:
is_override=self._override_system_messages is_override=self._override_system_messages
) )
) )
elif self._dividing_line is None:
print('\n' + text.strip("\n") + '\n')
else: else:
raise NotImplementedError raise NotImplementedError
@@ -408,7 +409,7 @@ class App(BaseApp):
farewell_message: str = "\nSee you\n", farewell_message: str = "\nSee you\n",
exit_command: Command = DEFAULT_EXIT_COMMAND, exit_command: Command = DEFAULT_EXIT_COMMAND,
system_router_title: str = "System points:", system_router_title: str = "System points:",
dividing_line: AVAILABLE_DIVIDING_LINES = DEFAULT_DIVIDING_LINE, dividing_line: AVAILABLE_DIVIDING_LINES | None = DEFAULT_DIVIDING_LINE,
repeat_command_groups_printing: bool = False, repeat_command_groups_printing: bool = False,
override_system_messages: bool = False, override_system_messages: bool = False,
autocompleter: AutoCompleter = DEFAULT_AUTOCOMPLETER, autocompleter: AutoCompleter = DEFAULT_AUTOCOMPLETER,
+1 -1
View File
@@ -361,7 +361,7 @@ def test_set_exit_command_handler_stores_handler() -> None:
def test_setup_default_view_formats_prompt() -> None: def test_setup_default_view_formats_prompt() -> None:
app = App(prompt='>>') app = App(prompt='>>')
assert app._prompt == '[italic dim bold]>>' assert app._prompt == '[italic dim bold]>>[/italic dim bold]'
def test_setup_default_view_sets_default_unknown_command_handler() -> None: def test_setup_default_view_sets_default_unknown_command_handler() -> None: