MCPcopy Create free account
hub / github.com/modelscope/ms-agent / append_stats

Function append_stats

ms_agent/utils/stats.py:63–84  ·  view source on GitHub ↗
(path: str, record: Dict[str, Any])

Source from the content-addressed store, hash-verified

61
62
63async def append_stats(path: str, record: Dict[str, Any]) -> None:
64 if not path:
65 return
66 lock = _get_lock(path)
67 async with lock:
68 os.makedirs(os.path.dirname(path) or '.', exist_ok=True)
69 data: list = []
70 if os.path.exists(path):
71 try:
72 with open(path, 'r', encoding='utf-8') as f:
73 data = json.load(f) or []
74 except Exception as exc:
75 logger.warning(
76 f'Failed to read stats file {path}, resetting: {exc}')
77 data = []
78 if not isinstance(data, list):
79 data = []
80
81 record.setdefault('created_at', datetime.utcnow().isoformat())
82 data.append(record)
83 with open(path, 'w', encoding='utf-8') as f:
84 json.dump(data, f, ensure_ascii=True, indent=2)
85
86
87def build_timing_record(

Callers 2

run_loopMethod · 0.90
_run_agentMethod · 0.90

Calls 3

_get_lockFunction · 0.85
loadMethod · 0.80
dumpMethod · 0.80

Tested by

no test coverage detected