pub fn lookup_thread(metrics: &PayloadMetrics, worker_tid: i32) -> ThreadLookupExpand description
Extract the allocated_bytes / deallocated_bytes values for
worker_tid from snapshot 0 in the flat metric list produced by
walk_json_leaves over the probe’s JSON output.
ThreadResult is externally-tagged so the probe emits
{"pid":P,"snapshots":[{"timestamp_unix_sec":T,"threads":[{"Ok":{"tid":T,"allocated_bytes":A,"deallocated_bytes":D,...}}, {"Err":{"tid":T,"error":...,"error_kind":...}}, ...]}, ...]}
which walk_json_leaves flattens per array index into contiguous
keys snapshots.0.threads.0.Ok.tid, snapshots.0.threads.1.Err.tid,
… with no gaps. Each index carries exactly one variant wrapper.
The scan stops at the first index where neither .Ok.tid nor
.Err.tid exists (the natural array terminator) and returns
ThreadLookup::TidAbsent. If the cap is reached without hitting
the terminator AND without matching worker_tid, returns
ThreadLookup::ExceedsCap. If the matching tid is on the Err
arm (no allocated_bytes sibling), returns
ThreadLookup::MissingAllocatedBytes.