| 323 | } |
| 324 | |
| 325 | export function readProcesses(raw: unknown): ProcessReport { |
| 326 | const record = isRecord(raw) ? raw : {}; |
| 327 | const list = Array.isArray(record['processes']) ? record['processes'].filter(isRecord) : []; |
| 328 | return { |
| 329 | selfPid: optionalNumber(record['self_pid']) ?? -1, |
| 330 | selfRssMb: optionalNumber(record['self_rss_mb']) ?? 0, |
| 331 | telemetry: { |
| 332 | cpuUnit: record['cpu_unit'] === 'percent' || record['cpu_unit'] === 'seconds' ? record['cpu_unit'] : 'unknown', |
| 333 | memoryKind: memoryKind(record['memory_kind']), |
| 334 | selfMemoryKind: memoryKind(record['self_memory_kind']), |
| 335 | selfMemoryMb: measurement(record['self_rss_mb'], record['self_memory_available']), |
| 336 | }, |
| 337 | processes: list.map((entry) => ({ |
| 338 | pid: optionalNumber(entry['pid']) ?? -1, |
| 339 | cpu: optionalNumber(entry['cpu']) ?? 0, |
| 340 | rssMb: optionalNumber(entry['rss_mb']) ?? 0, |
| 341 | elapsed: entry['cpu_available'] === false ? '' : text(entry['elapsed']), |
| 342 | command: text(entry['command']), |
| 343 | isSelf: entry['is_self'] === true, |
| 344 | telemetry: { |
| 345 | cpu: measurement(entry['cpu'], entry['cpu_available']), |
| 346 | memoryMb: measurement(entry['rss_mb'], entry['memory_available']), |
| 347 | }, |
| 348 | })), |
| 349 | }; |
| 350 | } |
| 351 | |
| 352 | // ------------------------------------------------------------ the form ---- |
| 353 | |