feat(convert): integrate process metrics into JSON and SQLite converters
- add process_metrics function to record peak RSS and CPU time - update JSON converter to include metrics in completion marker - modify SQLite converter to utilize new metrics for performance tracking - enhance storage size updates with locking mechanism for concurrent access
This commit is contained in:
@@ -10,6 +10,7 @@ import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
import psutil
|
||||
import yaml
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -57,3 +58,22 @@ def write_marker(out_root: Path, task_id: str, entries: dict) -> Path:
|
||||
def load_lab_config(out_root: Path) -> dict:
|
||||
with open(out_root / "config" / "lab_config.yaml", encoding="utf-8") as fh:
|
||||
return yaml.safe_load(fh)
|
||||
|
||||
|
||||
def process_metrics() -> dict:
|
||||
"""Peak RSS and CPU time of the current process.
|
||||
|
||||
Every converter records its own build cost in its marker so the task 10
|
||||
hardware-sizing model can extrapolate per-format RAM/CPU needs, not just
|
||||
disk. peak_wset exists on Windows; the rss fallback covers Linux, where
|
||||
the value is the current (not peak) RSS - good enough for streaming
|
||||
converters whose RSS is flat by design.
|
||||
"""
|
||||
proc = psutil.Process()
|
||||
mem = proc.memory_info()
|
||||
peak = getattr(mem, "peak_wset", 0) or mem.rss
|
||||
cpu = proc.cpu_times()
|
||||
return {
|
||||
"proc_peak_rss_mb": round(peak / 1048576, 1),
|
||||
"proc_cpu_seconds": round(cpu.user + cpu.system, 1),
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user