Logging, runtime tracing, and the obs performance profiler for OCaml
0

Configure Feed

Select the types of activity you want to include in your feed.

obs: extract obs report summary render helpers

+49 -37
+49 -37
bin/obs/cmd_common.ml
··· 55 55 ]) 56 56 findings 57 57 58 + let summary_ctx ~isatty = 59 + Tty.Display.ctx ~ppf:Fmt.stdout 60 + ~now:(fun () -> 0.) 61 + ~dimensions:(fun () -> (100, 24)) 62 + ~is_tty:isatty () 63 + 64 + let render_table ~ctx ~theme cols rows = 65 + Fmt.pr "%a@." (Tty.Table.pp ~ctx) (Tty.Table.of_string_rows ~theme cols rows) 66 + 67 + let render_verdict ~theme (r : Report.t) = 68 + Fmt.pr "%a@." Tty.Panel.pp 69 + (Tty.Panel.v ~theme ~title:(Tty.Span.text "obs") (Tty.Span.text r.verdict)) 70 + 71 + let render_budget ~ctx ~theme ~unattributed bd = 72 + render_table ~ctx ~theme 73 + Tty.Table. 74 + [ 75 + column "budget"; 76 + column ~align:`Right "time"; 77 + column ~align:`Right "%wall"; 78 + ] 79 + (budget_rows ~unattributed bd) 80 + 81 + let render_findings ~ctx ~theme findings = 82 + if findings = [] then 83 + Fmt.pr "findings: none above the floor; run looks balanced@." 84 + else 85 + render_table ~ctx ~theme 86 + Tty.Table. 87 + [ 88 + column "#"; 89 + column "kind"; 90 + column ~align:`Right "payoff"; 91 + column ~max_width:54 ~overflow:`Truncate "fix"; 92 + ] 93 + (findings_rows findings) 94 + 95 + let render_critical_path_ceiling (r : Report.t) = 96 + if r.critical_path <> [] && r.budget.wall > 0. then 97 + let cp = cp_total r in 98 + Fmt.pr "ceiling: at most %s (%s) reclaimable -- the critical path@." 99 + (dur cp) 100 + (pct (cp /. r.budget.wall)) 101 + 58 102 (* The triage as a retro green Matrix-themed set of tables: a verdict panel, the 59 103 wall-clock budget, and the ranked findings. Colour follows the formatter's 60 104 style renderer, so a pipe or [--json] stays plain. *) ··· 62 106 let theme = Tty.Theme.matrix in 63 107 let isatty = Unix.isatty Unix.stdout in 64 108 Fmt.set_style_renderer Fmt.stdout (if isatty then `Ansi_tty else `None); 65 - let ctx = 66 - Tty.Display.ctx ~ppf:Fmt.stdout 67 - ~now:(fun () -> 0.) 68 - ~dimensions:(fun () -> (100, 24)) 69 - ~is_tty:isatty () 70 - in 71 - let table cols rows = 72 - Fmt.pr "%a@." (Tty.Table.pp ~ctx) 73 - (Tty.Table.of_string_rows ~theme cols rows) 74 - in 109 + let ctx = summary_ctx ~isatty in 75 110 let bd = r.Report.budget in 76 111 let unattributed = r.no_evidence || r.allocation_only in 77 - Fmt.pr "%a@." Tty.Panel.pp 78 - (Tty.Panel.v ~theme ~title:(Tty.Span.text "obs") (Tty.Span.text r.verdict)); 79 - table 80 - Tty.Table. 81 - [ 82 - column "budget"; 83 - column ~align:`Right "time"; 84 - column ~align:`Right "%wall"; 85 - ] 86 - (budget_rows ~unattributed bd); 112 + render_verdict ~theme r; 113 + render_budget ~ctx ~theme ~unattributed bd; 87 114 if not unattributed then begin 88 - if r.findings = [] then 89 - Fmt.pr "findings: none above the floor; run looks balanced@." 90 - else 91 - table 92 - Tty.Table. 93 - [ 94 - column "#"; 95 - column "kind"; 96 - column ~align:`Right "payoff"; 97 - column ~max_width:54 ~overflow:`Truncate "fix"; 98 - ] 99 - (findings_rows r.findings); 100 - if r.critical_path <> [] && bd.wall > 0. then 101 - let cp = cp_total r in 102 - Fmt.pr "ceiling: at most %s (%s) reclaimable -- the critical path@." 103 - (dur cp) 104 - (pct (cp /. bd.wall)) 115 + render_findings ~ctx ~theme r.findings; 116 + render_critical_path_ceiling r 105 117 end 106 118 107 119 let render_summary _opts report =