MCPcopy Create free account
hub / github.com/1jehuang/jcode / load_samples

Function load_samples

scripts/analyze_runtime_memory_log.py:201–239  ·  view source on GitHub ↗
(paths: Iterable[Path])

Source from the content-addressed store, hash-verified

199
200
201def load_samples(paths: Iterable[Path]) -> list[Sample]:
202 samples: list[Sample] = []
203 for path in paths:
204 try:
205 lines = path.read_text().splitlines()
206 except FileNotFoundError:
207 continue
208 for idx, line in enumerate(lines, start=1):
209 line = line.strip()
210 if not line:
211 continue
212 try:
213 raw = json.loads(line)
214 except json.JSONDecodeError:
215 continue
216 trigger = raw.get("trigger") or {}
217 source = str(raw.get("source") or "")
218 kind = infer_kind(raw, source)
219 target = infer_target(raw, path)
220 instance_id = infer_instance_id(raw, target)
221 trigger_category, trigger_reason = infer_trigger(raw, kind, source, trigger)
222 samples.append(
223 Sample(
224 path=path,
225 line_no=idx,
226 raw=raw,
227 timestamp_ms=int(raw.get("timestamp_ms") or 0),
228 kind=kind,
229 target=target,
230 instance_id=instance_id,
231 source=source,
232 trigger_category=trigger_category,
233 trigger_reason=trigger_reason,
234 sessions=raw.get("sessions") if isinstance(raw.get("sessions"), dict) else None,
235 totals=raw.get("totals") if isinstance(raw.get("totals"), dict) else None,
236 )
237 )
238 samples.sort(key=lambda sample: (sample.timestamp_ms, str(sample.path), sample.line_no))
239 return samples
240
241
242def infer_instance_id(raw: dict[str, Any], target: str) -> str:

Callers 1

mainFunction · 0.85

Calls 6

infer_kindFunction · 0.85
infer_targetFunction · 0.85
infer_instance_idFunction · 0.85
infer_triggerFunction · 0.85
SampleClass · 0.85
getMethod · 0.45

Tested by

no test coverage detected