fix(benchmark): guard the POSIX-only resource import in skill_export (#7381)

skill_export.py imported the POSIX-only stdlib module `resource`
unconditionally at module level, so the benchmark entry point died with
ModuleNotFoundError on Windows before argument parsing. Mirror the
try/except ImportError guard already established by
checkpoint/checkpoint_bench_common.py, report "peak_rss_bytes": null when
the module is unavailable, and leave POSIX scaling unchanged (macOS
bytes, Linux KiB scaled to bytes).

Fixes #7380
This commit is contained in:
sun04222 2026-10-24 13:31:12 +08:00 committed by GitHub
parent d2f22e7ad8
commit 9a11f9aec7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -10,7 +10,6 @@ from __future__ import annotations
import json
import os
import resource
import shutil
import subprocess
import sys
@ -19,6 +18,11 @@ import threading
import time
from pathlib import Path
try:
import resource
except ImportError: # pragma: no cover - Windows only
resource = None # type: ignore[assignment]
from deerflow.skills import export
from deerflow.skills.storage.local_skill_storage import LocalSkillStorage
@ -112,7 +116,7 @@ def run(case):
elapsed = time.perf_counter() - start
finally:
export.tempfile.TemporaryFile = tracker.original
rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss
rss = resource.getrusage(resource.RUSAGE_SELF).ru_maxrss if resource is not None else None
print(
json.dumps(
{
@ -120,7 +124,7 @@ def run(case):
"outcome": outcome,
"wall_seconds": round(elapsed, 4),
"manifest_seconds": round(manifest_seconds, 4) if manifest_seconds is not None else None,
"peak_rss_bytes": rss if sys.platform == "darwin" else rss * 1024,
"peak_rss_bytes": (rss if sys.platform == "darwin" else rss * 1024) if rss is not None else None,
"peak_temp_files": tracker.peak_count,
"peak_temp_bytes": tracker.peak_bytes,
"remaining_temp_files": sum(not file.closed for file in tracker.files),