My agentic slop goes here. Not intended for anyone else!
at main 2.4 kB view raw
1(** Cache statistics *) 2 3type t = { 4 total_size : int64; 5 entry_count : int; 6 expired_count : int; 7 pinned_count : int; 8 stale_count : int; 9 temporary_count : int; 10} 11 12let empty = { 13 total_size = 0L; 14 entry_count = 0; 15 expired_count = 0; 16 pinned_count = 0; 17 stale_count = 0; 18 temporary_count = 0; 19} 20 21let create ~total_size ~entry_count ~expired_count ~pinned_count ~stale_count ~temporary_count = 22 { total_size; entry_count; expired_count; pinned_count; stale_count; temporary_count } 23 24let of_entries entries = 25 List.fold_left (fun acc entry -> 26 let open Entry in 27 { total_size = Int64.add acc.total_size (size entry); 28 entry_count = acc.entry_count + 1; 29 expired_count = acc.expired_count + (if is_expired entry then 1 else 0); 30 pinned_count = acc.pinned_count + (if is_pinned entry then 1 else 0); 31 stale_count = acc.stale_count + (if is_stale entry then 1 else 0); 32 temporary_count = acc.temporary_count + (if is_temporary entry then 1 else 0); 33 } 34 ) empty entries 35 36let total_size t = t.total_size 37let entry_count t = t.entry_count 38let expired_count t = t.expired_count 39let pinned_count t = t.pinned_count 40let stale_count t = t.stale_count 41let temporary_count t = t.temporary_count 42 43let pp fmt t = 44 Format.fprintf fmt 45 "Stats{entries=%d, size=%Ld, expired=%d, pinned=%d, stale=%d, temporary=%d}" 46 t.entry_count 47 t.total_size 48 t.expired_count 49 t.pinned_count 50 t.stale_count 51 t.temporary_count 52 53(* Jsont support *) 54 55(* Helper codec for int64 *) 56let int64_jsont = 57 let kind = "Int64" in 58 let doc = "64-bit integer as number" in 59 let dec n = Int64.of_float n in 60 let enc i = Int64.to_float i in 61 Jsont.map ~kind ~doc ~dec ~enc Jsont.number 62 63let jsont = 64 let kind = "Stats" in 65 let doc = "Cache statistics" in 66 let make total_size entry_count expired_count pinned_count stale_count temporary_count = 67 { total_size; entry_count; expired_count; pinned_count; stale_count; temporary_count } 68 in 69 Jsont.Object.map ~kind ~doc make 70 |> Jsont.Object.mem "total_size" int64_jsont ~enc:total_size 71 |> Jsont.Object.mem "entry_count" Jsont.int ~enc:entry_count 72 |> Jsont.Object.mem "expired_count" Jsont.int ~enc:expired_count 73 |> Jsont.Object.mem "pinned_count" Jsont.int ~enc:pinned_count 74 |> Jsont.Object.mem "stale_count" Jsont.int ~enc:stale_count 75 |> Jsont.Object.mem "temporary_count" Jsont.int ~enc:temporary_count 76 |> Jsont.Object.finish