Skip to content

Commit aeab95e

Browse files
rleshchinskiyRoman Leshchinskiy
andauthored
Add heap stats to -dgc-timings (oxcaml#1174)
This adds a bunch of heap stats from https://v2.ocaml.org/api/Gc.html to `-dgc-timings`. These will be consumed and stored by our build stats pipeline. Co-authored-by: Roman Leshchinskiy <rleshchinskiy@janestreet.com>
1 parent d2b0692 commit aeab95e

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

driver/optmaindriver.ml

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,11 +162,30 @@ let main unix argv ppf ~flambda2 =
162162
if !Flambda_backend_flags.gc_timings then begin
163163
let minor = Gc_timings.gc_minor_ns () in
164164
let major = Gc_timings.gc_major_ns () in
165+
let stats = Gc.quick_stat () in
165166
let secs x = x *. 1e-9 in
166167
let precision = !Clflags.timings_precision in
168+
let w2b n = n * (Sys.word_size / 8) in
169+
let fw2b x = w2b (Float.to_int x) in
167170
Format.fprintf Format.std_formatter "%0.*fs gc\n" precision (secs (minor +. major));
168171
Format.fprintf Format.std_formatter " %0.*fs minor\n" precision (secs minor);
169-
Format.fprintf Format.std_formatter " %0.*fs major\n" precision (secs major)
172+
Format.fprintf Format.std_formatter " %0.*fs major\n" precision (secs major);
173+
Format.fprintf Format.std_formatter "- heap\n";
174+
(* Having minor + major + promoted = total alloc make more sense for
175+
hierarchical stats. *)
176+
Format.fprintf Format.std_formatter " %ib alloc\n"
177+
(fw2b stats.minor_words + (fw2b stats.major_words - fw2b stats.promoted_words));
178+
Format.fprintf Format.std_formatter " %ib minor\n"
179+
(fw2b stats.minor_words - fw2b stats.promoted_words);
180+
Format.fprintf Format.std_formatter " %ib major\n"
181+
(fw2b stats.major_words - fw2b stats.promoted_words);
182+
Format.fprintf Format.std_formatter " %ib promoted\n"
183+
(fw2b stats.promoted_words);
184+
Format.fprintf Format.std_formatter " %ib top\n" (w2b stats.top_heap_words);
185+
Format.fprintf Format.std_formatter " %i collections\n"
186+
(stats.minor_collections + stats.major_collections);
187+
Format.fprintf Format.std_formatter " %i minor\n" stats.minor_collections;
188+
Format.fprintf Format.std_formatter " %i major\n" stats.major_collections;
170189
end;
171190
Profile.print Format.std_formatter !Clflags.profile_columns ~timings_precision:!Clflags.timings_precision;
172191
0

0 commit comments

Comments
 (0)