mirror of
https://github.com/koloideal/Argenta.git
synced 2026-06-10 18:15:28 +03:00
ruff format
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
from .diagram_generator import DiagramGenerator
|
||||
from .release_generator import ReleaseGenerator
|
||||
from .report_table_generator import ReportTableGenerator
|
||||
from .system_info_reader import get_system_info
|
||||
from .release_generator import ReleaseGenerator
|
||||
|
||||
__all__ = ["DiagramGenerator", "ReportTableGenerator", "get_system_info", "ReleaseGenerator"]
|
||||
|
||||
@@ -12,8 +12,8 @@ class DiagramGenerator:
|
||||
def __init__(self, output_dir: Path | str) -> None:
|
||||
self.output_dir: Path = Path(output_dir) if isinstance(output_dir, str) else output_dir
|
||||
|
||||
matplotlib.use('Agg')
|
||||
plt.style.use('seaborn-v0_8-whitegrid')
|
||||
matplotlib.use("Agg")
|
||||
plt.style.use("seaborn-v0_8-whitegrid")
|
||||
|
||||
def generate_comparison_diagram(self, benchmark_group: BenchmarkGroupResult) -> Path:
|
||||
results = benchmark_group.benchmark_results
|
||||
@@ -27,7 +27,7 @@ class DiagramGenerator:
|
||||
max_value = max(
|
||||
max(avg_times) if avg_times else 0,
|
||||
max(median_times) if median_times else 0,
|
||||
max(std_devs) if std_devs else 0
|
||||
max(std_devs) if std_devs else 0,
|
||||
)
|
||||
y_limit = max_value / 0.85 if max_value > 0 else 1.0
|
||||
|
||||
@@ -41,34 +41,77 @@ class DiagramGenerator:
|
||||
x_median = [x + bar_width for x in x_positions]
|
||||
|
||||
fig, ax = plt.subplots(figsize=(16, 8))
|
||||
fig.patch.set_facecolor('white')
|
||||
fig.patch.set_facecolor("white")
|
||||
|
||||
bars_std = ax.bar(x_std_dev, std_devs, bar_width, label='Std Deviation',
|
||||
color='#2ecc71', alpha=0.9, edgecolor='#27ae60', linewidth=1.5)
|
||||
bars_avg = ax.bar(x_avg, avg_times, bar_width, label='Average Time',
|
||||
color='#3498db', alpha=0.9, edgecolor='#2980b9', linewidth=1.5)
|
||||
bars_median = ax.bar(x_median, median_times, bar_width, label='Median Time',
|
||||
color='#e74c3c', alpha=0.9, edgecolor='#c0392b', linewidth=1.5)
|
||||
bars_std = ax.bar(
|
||||
x_std_dev,
|
||||
std_devs,
|
||||
bar_width,
|
||||
label="Std Deviation",
|
||||
color="#2ecc71",
|
||||
alpha=0.9,
|
||||
edgecolor="#27ae60",
|
||||
linewidth=1.5,
|
||||
)
|
||||
bars_avg = ax.bar(
|
||||
x_avg,
|
||||
avg_times,
|
||||
bar_width,
|
||||
label="Average Time",
|
||||
color="#3498db",
|
||||
alpha=0.9,
|
||||
edgecolor="#2980b9",
|
||||
linewidth=1.5,
|
||||
)
|
||||
bars_median = ax.bar(
|
||||
x_median,
|
||||
median_times,
|
||||
bar_width,
|
||||
label="Median Time",
|
||||
color="#e74c3c",
|
||||
alpha=0.9,
|
||||
edgecolor="#c0392b",
|
||||
linewidth=1.5,
|
||||
)
|
||||
|
||||
for bar_group in [bars_std, bars_avg, bars_median]:
|
||||
for bar in bar_group:
|
||||
height = bar.get_height()
|
||||
ax.text(
|
||||
bar.get_x() + bar.get_width() / 2.,
|
||||
bar.get_x() + bar.get_width() / 2.0,
|
||||
height,
|
||||
f'{height:.3f}',
|
||||
ha='center', va='bottom', fontsize=9, fontweight='bold'
|
||||
f"{height:.3f}",
|
||||
ha="center",
|
||||
va="bottom",
|
||||
fontsize=9,
|
||||
fontweight="bold",
|
||||
)
|
||||
|
||||
ax.set_ylabel('Time (ms)', fontsize=14, fontweight='bold', labelpad=10)
|
||||
ax.set_ylabel("Time (ms)", fontsize=14, fontweight="bold", labelpad=10)
|
||||
|
||||
title_text = f'{benchmark_group.type_.replace("_", " ").title()}'
|
||||
metadata_text = f'Iterations: {benchmark_group.iterations} | GC: {"Disabled" if benchmark_group.is_gc_disabled else "Enabled"}'
|
||||
title_text = f"{benchmark_group.type_.replace('_', ' ').title()}"
|
||||
metadata_text = f"Iterations: {benchmark_group.iterations} | GC: {'Disabled' if benchmark_group.is_gc_disabled else 'Enabled'}"
|
||||
|
||||
ax.text(0.5, 1.08, title_text, transform=ax.transAxes,
|
||||
fontsize=18, fontweight='bold', ha='center', color='#2c3e50')
|
||||
ax.text(0.5, 1.03, metadata_text, transform=ax.transAxes,
|
||||
fontsize=12, ha='center', color='#7f8c8d', style='italic')
|
||||
ax.text(
|
||||
0.5,
|
||||
1.08,
|
||||
title_text,
|
||||
transform=ax.transAxes,
|
||||
fontsize=18,
|
||||
fontweight="bold",
|
||||
ha="center",
|
||||
color="#2c3e50",
|
||||
)
|
||||
ax.text(
|
||||
0.5,
|
||||
1.03,
|
||||
metadata_text,
|
||||
transform=ax.transAxes,
|
||||
fontsize=12,
|
||||
ha="center",
|
||||
color="#7f8c8d",
|
||||
style="italic",
|
||||
)
|
||||
|
||||
ax.set_xticks(x_positions)
|
||||
ax.set_xticklabels([])
|
||||
@@ -79,23 +122,32 @@ class DiagramGenerator:
|
||||
text_x_pos,
|
||||
y_limit * 0.02,
|
||||
desc,
|
||||
rotation=90, va='bottom', ha='right', fontsize=10,
|
||||
color='#2c3e50'
|
||||
rotation=90,
|
||||
va="bottom",
|
||||
ha="right",
|
||||
fontsize=10,
|
||||
color="#2c3e50",
|
||||
)
|
||||
|
||||
ax.set_ylim(0, y_limit)
|
||||
|
||||
legend = ax.legend(loc='upper left', fontsize=12, framealpha=0.95,
|
||||
edgecolor='#34495e', fancybox=True, shadow=True)
|
||||
legend.get_frame().set_facecolor('#ecf0f1')
|
||||
legend = ax.legend(
|
||||
loc="upper left",
|
||||
fontsize=12,
|
||||
framealpha=0.95,
|
||||
edgecolor="#34495e",
|
||||
fancybox=True,
|
||||
shadow=True,
|
||||
)
|
||||
legend.get_frame().set_facecolor("#ecf0f1")
|
||||
|
||||
ax.grid(axis='y', alpha=0.4, linestyle='--', linewidth=0.8)
|
||||
ax.grid(axis="y", alpha=0.4, linestyle="--", linewidth=0.8)
|
||||
ax.set_axisbelow(True)
|
||||
|
||||
ax.spines['top'].set_visible(False)
|
||||
ax.spines['right'].set_visible(False)
|
||||
ax.spines['left'].set_color('#7f8c8d')
|
||||
ax.spines['bottom'].set_color('#7f8c8d')
|
||||
ax.spines["top"].set_visible(False)
|
||||
ax.spines["right"].set_visible(False)
|
||||
ax.spines["left"].set_color("#7f8c8d")
|
||||
ax.spines["bottom"].set_color("#7f8c8d")
|
||||
|
||||
plt.tight_layout()
|
||||
|
||||
@@ -104,7 +156,7 @@ class DiagramGenerator:
|
||||
|
||||
self.output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
plt.savefig(output_path, dpi=200, bbox_inches='tight', facecolor='white')
|
||||
plt.savefig(output_path, dpi=200, bbox_inches="tight", facecolor="white")
|
||||
plt.close(fig)
|
||||
|
||||
return output_path
|
||||
|
||||
@@ -12,20 +12,20 @@ class ReleaseGenerator:
|
||||
def __init__(self, lib_version: str) -> None:
|
||||
self.lib_version = lib_version
|
||||
self.output_dir = Path("metrics/reports/releases") / lib_version
|
||||
|
||||
|
||||
def generate_release(self, benchmark_groups: list[BenchmarkGroupResult]) -> Path:
|
||||
if self.output_dir.exists():
|
||||
shutil.rmtree(self.output_dir)
|
||||
|
||||
|
||||
self.output_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
|
||||
for benchmark_group in benchmark_groups:
|
||||
type_dir = self.output_dir / benchmark_group.type_
|
||||
type_dir.mkdir(exist_ok=True)
|
||||
|
||||
|
||||
diagram_generator = DiagramGenerator(type_dir)
|
||||
diagram_generator.generate_comparison_diagram(benchmark_group)
|
||||
|
||||
|
||||
json_data = {
|
||||
"type": benchmark_group.type_,
|
||||
"iterations": benchmark_group.iterations,
|
||||
@@ -36,14 +36,14 @@ class ReleaseGenerator:
|
||||
"description": br.description,
|
||||
"avg_time": br.avg_time,
|
||||
"median_time": br.median_time,
|
||||
"std_dev": br.std_dev
|
||||
"std_dev": br.std_dev,
|
||||
}
|
||||
for br in benchmark_group.benchmark_results
|
||||
]
|
||||
],
|
||||
}
|
||||
|
||||
|
||||
json_path = type_dir / f"{benchmark_group.type_}.json"
|
||||
with open(json_path, 'w', encoding='utf-8') as f:
|
||||
with open(json_path, "w", encoding="utf-8") as f:
|
||||
json.dump(json_data, f, indent=2, ensure_ascii=False)
|
||||
|
||||
|
||||
return self.output_dir
|
||||
|
||||
@@ -3,7 +3,7 @@ from rich.table import Table
|
||||
from rich.text import Text
|
||||
|
||||
from ..benchmarks.core.models import BenchmarkGroupResult
|
||||
from metrics.services.system_info_reader import SystemInfo
|
||||
from .system_info_reader import SystemInfo
|
||||
|
||||
|
||||
class ReportTableGenerator:
|
||||
@@ -12,11 +12,15 @@ class ReportTableGenerator:
|
||||
self._cached_benchmark_tables: dict[int, Table] = {}
|
||||
self._cached_system_info_table: Table | None = None
|
||||
|
||||
def generate_benchmark_report_table(self, benchmark_group_result: BenchmarkGroupResult) -> Table:
|
||||
def generate_benchmark_report_table(
|
||||
self, benchmark_group_result: BenchmarkGroupResult
|
||||
) -> Table:
|
||||
if cached_result := self._cached_benchmark_tables.get(id(benchmark_group_result)):
|
||||
return cached_result
|
||||
|
||||
table = Table(show_header=True, header_style="bold cyan", border_style="blue", show_lines=True)
|
||||
table = Table(
|
||||
show_header=True, header_style="bold cyan", border_style="blue", show_lines=True
|
||||
)
|
||||
table.add_column("Description", style="dim")
|
||||
table.add_column("Avg Time", justify="right", style="bold yellow")
|
||||
table.add_column("Median Time", justify="right", style="bold yellow")
|
||||
@@ -34,18 +38,22 @@ class ReportTableGenerator:
|
||||
|
||||
@staticmethod
|
||||
def generate_benchmark_table_header(benchmark_group_result: BenchmarkGroupResult) -> Panel:
|
||||
header_text = Text(f"TYPE: {benchmark_group_result.type_.upper()} ; "
|
||||
f"ITERATIONS: {benchmark_group_result.iterations} ; "
|
||||
f"GC {"DISABLED" if benchmark_group_result.is_gc_disabled else "ENABLED"} ; "
|
||||
f"ALL TIME IN MS",
|
||||
style="bold magenta")
|
||||
header_text = Text(
|
||||
f"TYPE: {benchmark_group_result.type_.upper()} ; "
|
||||
f"ITERATIONS: {benchmark_group_result.iterations} ; "
|
||||
f"GC {'DISABLED' if benchmark_group_result.is_gc_disabled else 'ENABLED'} ; "
|
||||
f"ALL TIME IN MS",
|
||||
style="bold magenta",
|
||||
)
|
||||
return Panel(header_text, expand=False, border_style="magenta")
|
||||
|
||||
def generate_system_info_table(self) -> Table:
|
||||
if self._cached_system_info_table is not None:
|
||||
return self._cached_system_info_table
|
||||
|
||||
table = Table(show_header=True, header_style="bold cyan", border_style="blue", show_lines=True)
|
||||
table = Table(
|
||||
show_header=True, header_style="bold cyan", border_style="blue", show_lines=True
|
||||
)
|
||||
table.add_column("Parameter", style="green")
|
||||
table.add_column("Value", style="yellow")
|
||||
|
||||
@@ -55,10 +63,10 @@ class ReportTableGenerator:
|
||||
table.add_row("CPU", self.system_info.cpu_info.name)
|
||||
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 Max Frequency", str(self.system_info.cpu_info.max_frequency) + ' GHz')
|
||||
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("Available RAM", str(self.system_info.memory_info.available_ram) + ' GB')
|
||||
table.add_row("CPU Max Frequency", str(self.system_info.cpu_info.max_frequency) + " GHz")
|
||||
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("Available RAM", str(self.system_info.memory_info.available_ram) + " GB")
|
||||
table.add_row("Python Version", self.system_info.python_info.version)
|
||||
table.add_row("Python Implementation", self.system_info.python_info.implementation)
|
||||
table.add_row("Python Compiler", self.system_info.python_info.compiler)
|
||||
@@ -69,4 +77,4 @@ class ReportTableGenerator:
|
||||
@staticmethod
|
||||
def generate_system_info_header() -> Panel:
|
||||
header_text = Text("SYSTEM INFO", style="bold magenta")
|
||||
return Panel(header_text, expand=False, border_style="magenta")
|
||||
return Panel(header_text, expand=False, border_style="magenta")
|
||||
|
||||
@@ -1,28 +1,19 @@
|
||||
__all__ = [
|
||||
"SystemInfo",
|
||||
"get_system_info"
|
||||
]
|
||||
__all__ = ["SystemInfo", "get_system_info"]
|
||||
|
||||
from dataclasses import dataclass
|
||||
import platform
|
||||
import sys
|
||||
from dataclasses import dataclass
|
||||
|
||||
import cpuinfo
|
||||
import psutil
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class SystemInfo:
|
||||
os_info: OSInfo
|
||||
cpu_info: CPUInfo
|
||||
memory_info: MemoryInfo
|
||||
python_info: PythonInfo
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class OSInfo:
|
||||
name: str
|
||||
kernel_version: str
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class CPUInfo:
|
||||
name: str
|
||||
@@ -31,11 +22,13 @@ class CPUInfo:
|
||||
logical_cores: int
|
||||
max_frequency: float
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class MemoryInfo:
|
||||
total_ram: float # in GB
|
||||
used_ram: float # in GB
|
||||
available_ram: float # in GB
|
||||
total_ram: float # in GB
|
||||
used_ram: float # in GB
|
||||
available_ram: float # in GB
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class PythonInfo:
|
||||
@@ -44,18 +37,6 @@ class PythonInfo:
|
||||
compiler: str
|
||||
|
||||
|
||||
def get_system_info() -> SystemInfo:
|
||||
os_info = get_os_info()
|
||||
cpu_info = get_cpu_info()
|
||||
memory_info = get_memory_info()
|
||||
python_info = get_python_info()
|
||||
return SystemInfo(
|
||||
os_info=os_info,
|
||||
cpu_info=cpu_info,
|
||||
memory_info=memory_info,
|
||||
python_info=python_info,
|
||||
)
|
||||
|
||||
def get_os_info() -> OSInfo:
|
||||
system = platform.system()
|
||||
|
||||
@@ -73,22 +54,17 @@ def get_os_info() -> OSInfo:
|
||||
kernel_version=kernel_version,
|
||||
)
|
||||
elif system == "Darwin":
|
||||
return OSInfo(
|
||||
kernel_version=platform.release(),
|
||||
name=f"macOS {platform.mac_ver()[0]}"
|
||||
)
|
||||
return OSInfo(kernel_version=platform.release(), name=f"macOS {platform.mac_ver()[0]}")
|
||||
else:
|
||||
return OSInfo(
|
||||
kernel_version=platform.release(),
|
||||
name=platform.system()
|
||||
)
|
||||
return OSInfo(kernel_version=platform.release(), name=platform.system())
|
||||
|
||||
|
||||
def get_cpu_info() -> CPUInfo:
|
||||
cpu_info = cpuinfo.get_cpu_info()
|
||||
cpu_name = cpu_info["brand_raw"]
|
||||
cpu_architecture = cpu_info["arch"]
|
||||
cpu_physical_cores = psutil.cpu_count(logical=False)
|
||||
cpu_logical_cores = psutil.cpu_count(logical=True)
|
||||
cpu_physical_cores = psutil.cpu_count(logical=False) or 0
|
||||
cpu_logical_cores = psutil.cpu_count(logical=True) or 0
|
||||
|
||||
cpu_freq = psutil.cpu_freq()
|
||||
cpu_max_frequency = cpu_freq.max
|
||||
@@ -98,9 +74,10 @@ def get_cpu_info() -> CPUInfo:
|
||||
architecture=cpu_architecture,
|
||||
physical_cores=cpu_physical_cores,
|
||||
logical_cores=cpu_logical_cores,
|
||||
max_frequency=cpu_max_frequency
|
||||
max_frequency=cpu_max_frequency,
|
||||
)
|
||||
|
||||
|
||||
def get_memory_info() -> MemoryInfo:
|
||||
mem = psutil.virtual_memory()
|
||||
total_ram = round(mem.total / (1024**3), 2)
|
||||
@@ -113,14 +90,32 @@ def get_memory_info() -> MemoryInfo:
|
||||
available_ram=available_ram,
|
||||
)
|
||||
|
||||
|
||||
def get_python_info() -> PythonInfo:
|
||||
python_version = platform.python_version()
|
||||
python_implementation = platform.python_implementation()
|
||||
python_compiler = platform.python_compiler()
|
||||
return PythonInfo(
|
||||
version=python_version,
|
||||
implementation=python_implementation,
|
||||
compiler=python_compiler
|
||||
version=python_version, implementation=python_implementation, compiler=python_compiler
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True, slots=True)
|
||||
class SystemInfo:
|
||||
os_info: OSInfo
|
||||
cpu_info: CPUInfo
|
||||
memory_info: MemoryInfo
|
||||
python_info: PythonInfo
|
||||
|
||||
|
||||
def get_system_info() -> SystemInfo:
|
||||
os_info = get_os_info()
|
||||
cpu_info = get_cpu_info()
|
||||
memory_info = get_memory_info()
|
||||
python_info = get_python_info()
|
||||
return SystemInfo(
|
||||
os_info=os_info,
|
||||
cpu_info=cpu_info,
|
||||
memory_info=memory_info,
|
||||
python_info=python_info,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user