My OCaml is 5.3 and I want to know what occupies heap in a certain time (location in the code is known). I tried to use memtrace, but it is not exactly what is needed because it traces what has been allocation from point to point. I could have some intuition what allocated most, but it is not exactly the thing.
There is a thing called memtrace_viewer, but it is difficult to compile (I did not succeed).
The built-in tool memtrace_hotspots is kind of useful, bit I’m not sure it gives accurate results. For example, if I will compute sum of toplevel percent values, should it be 100%? And should if my memtrace rate if 1.0?
Hotspots output
Trace for ... [19343]:
367061949 samples of 2.7 GB allocations
0.4 GB (13.3%) at Stdlib__Format.output_acc (format.ml:1395:32-48, 1395:32-48, 1395:32-48)
0.1 GB ( 4.2%) at Backend__InferAnalyze.source_file_should_be_analyzed (src/backend/InferAnalyze.ml:80:37-69)
including:
15.0 MB via Absint__ProcnameDispatcher.Call.contramap_arg_payload.map_args (20% of this)
0.1 GB ( 4.0%) at Pulselib__PulseBaseAddressAttributes.check_valid (src/pulse/PulseBaseAddressAttributes.ml:174:2-65, 180:6-24)
0.1 GB ( 4.0%) at Stdlib__Map.Make.bal (map.ml:119:12-67)
99.4 MB ( 3.5%) at IR__FuncArg.map_payload (src/IR/FuncArg.ml:25:49-91)
85.4 MB ( 3.1%) at Stdlib__Set.Make.bal (set.ml:128:12-62, 128:12-62, 128:12-62...)
85.0 MB ( 3.0%) at Base__List.map (src/list.ml:433:15-45, 433:15-45)
68.5 MB ( 2.4%) at IR__QualifiedCppName.extract_last_exn (src/IR/QualifiedCppName.ml:53:6-18)
including:
21.5 MB via Absint__ProcnameDispatcher.templ_begin.on_templated_name (27% of this)
21.5 MB via Absint__ProcnameDispatcher.templ_end.(fun).on_templated_name (27% of this)
18.6 MB via Absint__ProcnameDispatcher.name_cons.on_qual_name (33% of this)
58.0 MB ( 2.1%) at Absint__ProcnameDispatcher.templated_name_of_csharp (src/absint/ProcnameDispatcher.ml:95:2-17)
including:
19.3 MB via Absint__ProcnameDispatcher.Call.args_begin.(fun).on_csharp (33% of this)
55.6 MB ( 2.0%) at IStdlib__RecencyMap.Make.to_seq.(fun) (src/istd/RecencyMap.ml:154:20-97, 154:20-97)
41.0 MB ( 1.5%) at Base__Container.fold_until.(fun) (src/container.ml:30:14-191, 32:23-145, 30:14-191...)
38.9 MB ( 1.4%) at IR__SourceFiles.get_all (src/IR/SourceFiles.ml:108:5-282, 109:13-92, 109:13-92...)
38.7 MB ( 1.4%) at Stdlib__Buffer.create (buffer.ml:43:9-23, 43:9-23, 44:1-71...)
34.5 MB ( 1.2%) at Stdlib__Set.Make.add (set.ml:133:21-49, 133:21-49)
32.8 MB ( 1.2%) at Pulselib__PulseAbductiveDomain.Internal.GraphVisit.visit_address.(fun) (src/pulse/PulseAbductiveDomain.ml:1452:50-792, 1461:71-95)
31.4 MB ( 1.1%) at CamlinternalFormat.make_printf.(fun) (camlinternalFormat.ml:1544:4-67, 1544:46-60, 1544:29-62...)
28.1 MB ( 1.0%) at Stdlib__Format.enqueue_string_as (format.ml:459:24-78, 459:40-49)
26.0 MB ( 0.9%) at Stdlib__Map.Make.add (map.ml:127:14-50, 131:41-63, 127:14-50...)
25.1 MB ( 0.9%) at Stdlib__Map.Make.create (map.ml:87:10-65)
24.6 MB ( 0.9%) at Pulselib__PulseFormulaTerm.fold_subst_variables.(fun) (src/pulse/PulseFormulaTerm.ml:503:44-123, 448:76-84)
23.6 MB ( 0.8%) at Stdlib__Seq.append (seq.ml:33:22-48, 33:22-48)
22.8 MB ( 0.8%) at CamlinternalFormat.make_padding.(fun) (camlinternalFormat.ml:1672:4-98, 1673:20-50)
21.8 MB ( 0.8%) at Stdlib__Map.Make.singleton (map.ml:89:28-59, 89:28-59, 89:28-59)
20.8 MB ( 0.7%) at Stdlib__List.to_seq.aux (list.ml:603:19-41, 603:19-41)
20.3 MB ( 0.7%) at Stdlib__Map.Make.find_opt (map.ml:224:24-30, 224:24-30, 224:24-30)
19.9 MB ( 0.7%) at Pulselib__PulseValueOrigin.addr_hist (src/pulse/PulseValueOrigin.ml:60:6-18)
18.3 MB ( 0.7%) at Stdlib__Queue.peek_opt (queue.ml:66:24-36)
18.1 MB ( 0.6%) at Stdlib__Set.Make.create (set.ml:93:10-60)
17.8 MB ( 0.6%) at Base__With_return.with_return.return (src/with_return.ml:12:13-160, 15:32-42)
17.7 MB ( 0.6%) at Base__With_return.with_return (src/with_return.ml:10:16-27, 11:17-25)
17.6 MB ( 0.6%) at Stdlib__Format.pp_make_formatter (format.ml:969:2-912, 962:4-72, 966:13-53)
17.1 MB ( 0.6%) at Pulselib__ZSafe.protect (src/pulse/ZSafe.ml:10:27-32, 10:22-32)
17.0 MB ( 0.6%) at Stdlib__Queue.add (queue.ml:41:18-55)
16.9 MB ( 0.6%) at Core__Std_internal.compare_option.(fun) (core/src/std_internal.ml:186:21-23)