Skip to content

Commit

Permalink
Merge pull request #193 from Firobe/lenient-stat-parsing
Browse files Browse the repository at this point in the history
stats: /proc/pid/status parsing more flexible
  • Loading branch information
hannesm authored Oct 7, 2024
2 parents 060c6e3 + 0e1b5bc commit 9fcb19e
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions stats/albatross_stats_pure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,9 @@ let read_proc_status pid =
List.map (String.split_on_char ':') lines |>
List.fold_left (fun acc x -> match acc, x with
| Some acc, k :: v ->
(* strip leading tab character *)
let v = String.concat ":" v in
if String.length v > 1 then
let v = String.sub v 1 (String.length v - 1) in
Some ((k, v) :: acc)
else
None
(* strip leading tab character and further possible whitespace *)
let v = String.concat ":" v |> String.trim in
Some ((k, v) :: acc)
| _ -> None) (Some []) |>
Option.to_result ~none:(`Msg "failed to parse /proc/<pid>/status")
with _ -> Error (`Msg (Fmt.str "error reading file /proc/%d/status" pid))
Expand Down

0 comments on commit 9fcb19e

Please sign in to comment.