|
14 | 14 |
|
15 | 15 | from ..model.batch import Batch, LemmaResult |
16 | 16 | from ..model.tamarin_recipe import TamarinRecipe |
17 | | -from ..utils.system_resources import resolve_resource_value |
| 17 | +from ..utils.system_resources import ( |
| 18 | + get_human_readable_volume_size, |
| 19 | + resolve_resource_value, |
| 20 | +) |
18 | 21 |
|
19 | 22 | if TYPE_CHECKING: |
20 | 23 | from ..model.executable_task import ExecutableTask |
@@ -306,11 +309,11 @@ def task_execution_summary(self, batch: Batch) -> None: |
306 | 309 | ) |
307 | 310 | runtime_table.add_row( |
308 | 311 | "Total peak memory used", |
309 | | - f"{self._format_memory(batch.execution_metadata.total_memory)}", |
| 312 | + f"{get_human_readable_volume_size(batch.execution_metadata.total_memory, 'MB')}", |
310 | 313 | ) |
311 | 314 | runtime_table.add_row( |
312 | 315 | "Max peak memory used", |
313 | | - f"{self._format_memory(batch.execution_metadata.max_memory)}", |
| 316 | + f"{get_human_readable_volume_size(batch.execution_metadata.max_memory, 'MB')}", |
314 | 317 | ) |
315 | 318 | runtime_table.add_row( |
316 | 319 | "Freshly executed tasks", |
@@ -387,8 +390,8 @@ def task_execution_summary(self, batch: Batch) -> None: |
387 | 390 | duration_display = self._format_duration( |
388 | 391 | rich_executable.task_execution_metadata.exec_duration_monotonic |
389 | 392 | ) |
390 | | - memory_display = self._format_memory( |
391 | | - rich_executable.task_execution_metadata.peak_memory |
| 393 | + memory_display = get_human_readable_volume_size( |
| 394 | + rich_executable.task_execution_metadata.peak_memory, "MB" |
392 | 395 | ) |
393 | 396 |
|
394 | 397 | cache_display = ( |
@@ -627,48 +630,6 @@ def _format_duration(self, seconds: float) -> str: |
627 | 630 | minutes = int((seconds % 3600) // 60) |
628 | 631 | return f"{hours}h {minutes}m" |
629 | 632 |
|
630 | | - def _format_memory(self, memory_mb: float) -> str: |
631 | | - """ |
632 | | - Format memory usage in human-readable format. |
633 | | - Automatically switches between MB and GB based on size. |
634 | | -
|
635 | | - Args: |
636 | | - memory_mb: Memory usage in megabytes |
637 | | -
|
638 | | - Returns: |
639 | | - Formatted memory string (e.g., "256 MB" or "1.5 GB") |
640 | | - """ |
641 | | - if memory_mb < 1024: |
642 | | - return f"{memory_mb:.1f} MB" |
643 | | - else: |
644 | | - memory_gb = memory_mb / 1024 |
645 | | - return f"{memory_gb:.1f} GB" |
646 | | - |
647 | | - def _format_bytes(self, size_bytes: int) -> str: |
648 | | - """ |
649 | | - Format bytes in human-readable format. |
650 | | -
|
651 | | - Args: |
652 | | - size_bytes: Size in bytes |
653 | | -
|
654 | | - Returns: |
655 | | - Formatted size string (e.g., "256 bytes", "1.5 kB", "2.0 MB", "1.2 GB") |
656 | | - """ |
657 | | - if size_bytes == 0: |
658 | | - return "0 bytes" |
659 | | - |
660 | | - volume = float(size_bytes) |
661 | | - unit = "bytes" |
662 | | - for unit in ["bytes", "kB", "MB", "GB"]: |
663 | | - if volume < 1024 or unit == "GB": |
664 | | - break |
665 | | - volume /= 1024 |
666 | | - |
667 | | - if unit == "bytes": |
668 | | - return f"{int(volume)} {unit}" |
669 | | - else: |
670 | | - return f"{volume:.1f} {unit}" |
671 | | - |
672 | 633 | def check_report( |
673 | 634 | self, |
674 | 635 | recipe: TamarinRecipe, |
|
0 commit comments