1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
open! Core
module Source = struct
type t = Memtrace.Trace.Allocation_source.t =
| Minor
| Major
| External
[@@deriving sexp_of]
end
type 'loc t =
| Alloc of
{ obj_id : Obj_id.t
; source : Source.t
; single_allocation_size : Byte_units.t
; nsamples : int
; size : Byte_units.t
; backtrace_buffer : 'loc array
; backtrace_length : int
; common_prefix : int
}
| Promote of Obj_id.t
| Collect of Obj_id.t
| End
module As_sexp = struct
type 'loc t =
| Alloc of
{ obj_id : Obj_id.t
; source : Source.t
; single_allocation_size : Byte_units.t
; nsamples : int
; size : Byte_units.t
; backtrace : 'loc array
; common_prefix : int
}
| Promote of { obj_id : Obj_id.t }
| Collect of { obj_id : Obj_id.t }
| End
[@@deriving sexp_of]
end
let as_sexp : 'loc t -> 'loc As_sexp.t = function
| Alloc
{ obj_id
; source
; single_allocation_size
; nsamples
; size
; backtrace_buffer
; backtrace_length
; common_prefix
} ->
let backtrace = Array.sub backtrace_buffer ~pos:0 ~len:backtrace_length in
Alloc
{ obj_id; source; single_allocation_size; nsamples; size; backtrace; common_prefix }
| Promote obj_id -> Promote { obj_id }
| Collect obj_id -> Collect { obj_id }
| End -> End
;;
let sexp_of_t sexp_of_loc t = As_sexp.sexp_of_t sexp_of_loc (t |> as_sexp)