blob: e864a50019e455b5f43bd626a031be4a21298f1c (
plain)
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
|
(* TEST
flags = "-g -w -5"
* flat-float-array
reference = "${test_source_directory}/callstacks.flat-float-array.reference"
* skip
reason = "port stat-mem-prof : https://github.com/ocaml/ocaml/pull/8634"
** native
** bytecode
* no-flat-float-array
reference = "${test_source_directory}/callstacks.no-flat-float-array.reference"
* skip
reason = "port stat-mem-prof : https://github.com/ocaml/ocaml/pull/8634"
** native
** bytecode
*)
open Gc.Memprof
let alloc_list_literal () =
ignore (Sys.opaque_identity [Sys.opaque_identity 1])
let alloc_pair () =
ignore (Sys.opaque_identity (Sys.opaque_identity 1, Sys.opaque_identity 2))
type record = { a : int; b : int }
let alloc_record () =
ignore (Sys.opaque_identity
{a = Sys.opaque_identity 1; b = Sys.opaque_identity 2})
let alloc_some () =
ignore (Sys.opaque_identity (Some (Sys.opaque_identity 2)))
let alloc_array_literal () =
ignore (Sys.opaque_identity [|Sys.opaque_identity 1|])
let alloc_float_array_literal () =
ignore (Sys.opaque_identity
[|Sys.opaque_identity 1.; Sys.opaque_identity 2.|])
let[@inline never] do_alloc_unknown_array_literal x =
Sys.opaque_identity [|x|]
let alloc_unknown_array_literal () =
ignore (Sys.opaque_identity (do_alloc_unknown_array_literal 1.))
let alloc_small_array () =
ignore (Sys.opaque_identity (Array.make 10 (Sys.opaque_identity 1)))
let alloc_large_array () =
ignore (Sys.opaque_identity (Array.make 100000 (Sys.opaque_identity 1)))
let alloc_closure () =
let x = Sys.opaque_identity 1 in
ignore (Sys.opaque_identity (fun () -> x))
let floatarray = [| 1.; 2. |]
let[@inline never] get0 a = a.(0)
let getfloatfield () =
ignore (Sys.opaque_identity (get0 floatarray))
let marshalled =
Marshal.to_string [Sys.opaque_identity 1] []
let alloc_unmarshal () =
ignore (Sys.opaque_identity
((Marshal.from_string [@inlined never]) (Sys.opaque_identity marshalled) 0))
let alloc_ref () =
ignore (Sys.opaque_identity (ref (Sys.opaque_identity 1)))
let fl = 1.
let[@inline never] prod_floats a b = a *. b
let alloc_boxedfloat () =
ignore (Sys.opaque_identity (prod_floats fl fl))
let allocators =
[alloc_list_literal; alloc_pair; alloc_record; alloc_some;
alloc_array_literal; alloc_float_array_literal; alloc_unknown_array_literal;
alloc_small_array; alloc_large_array; alloc_closure;
getfloatfield; alloc_unmarshal; alloc_ref; alloc_boxedfloat]
let test alloc =
Printf.printf "-----------\n%!";
let callstack = ref None in
start ~callstack_size:10 ~sampling_rate:1.
{ null_tracker with
alloc_minor = (fun info ->
callstack := Some info.callstack;
None
);
alloc_major = (fun info ->
callstack := Some info.callstack;
None
);
};
alloc ();
stop ();
match !callstack with
| None -> Printf.printf "No callstack\n%!";
| Some cs -> Printexc.print_raw_backtrace stdout cs
let () =
List.iter test allocators
|