-
Notifications
You must be signed in to change notification settings - Fork 98
/
Copy pathcallstack_compression_test.ml
81 lines (77 loc) · 2.71 KB
/
callstack_compression_test.ml
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
open Core
open Magic_trace_lib
let compressed_test_string =
{|(
((new_symbols())(callstack()))
((new_symbols())(callstack()))
((new_symbols())(callstack()))
((new_symbols(((From_perf _start)0)))(callstack((0 0))))
((new_symbols((Untraced 1)))(callstack((1 0)(0 0))))
((new_symbols())(callstack((0 0))))
((new_symbols(((From_perf _dl_start)2)))(callstack((2 0)(0 0))))
((new_symbols())(callstack((1 1)(0 0))))
((new_symbols())(callstack((2 1))))
((new_symbols())(callstack((1 2))))
((new_symbols())(callstack((2 1))))
)|}
;;
let decompressed_test_string =
{|(
()
()
()
((From_perf _start))
(Untraced (From_perf _start))
((From_perf _start))
((From_perf _dl_start) (From_perf _start))
(Untraced (From_perf _start) (From_perf _start))
((From_perf _dl_start) (From_perf _start))
(Untraced (From_perf _start) (From_perf _start))
((From_perf _dl_start) (From_perf _start))
)|}
;;
let%expect_test "decompress" =
let compression_events =
[%of_sexp: Callstack_compression.compression_event list]
(Sexp.of_string compressed_test_string)
in
let state = Callstack_compression.init () in
List.iter compression_events ~f:(fun comp_event ->
let callstack = Callstack_compression.decompress_callstack state comp_event in
print_s [%sexp (callstack : Symbol.t list)]);
[%expect
{|
()
()
()
((From_perf _start))
(Untraced (From_perf _start))
((From_perf _start))
((From_perf _dl_start) (From_perf _start))
(Untraced (From_perf _start) (From_perf _start))
((From_perf _dl_start) (From_perf _start))
(Untraced (From_perf _start) (From_perf _start))
((From_perf _dl_start) (From_perf _start))|}]
;;
let%expect_test "compress" =
let compression_events =
[%of_sexp: Symbol.t list list] (Sexp.of_string decompressed_test_string)
in
let state = Callstack_compression.init () in
List.iter compression_events ~f:(fun callstack ->
let comp_event = Callstack_compression.compress_callstack state callstack in
print_s [%sexp (comp_event : Callstack_compression.compression_event)]);
[%expect
{|
((new_symbols ()) (callstack ()))
((new_symbols ()) (callstack ()))
((new_symbols ()) (callstack ()))
((new_symbols (((From_perf _start) 0))) (callstack ((0 0))))
((new_symbols ((Untraced 1))) (callstack ((1 0) (0 0))))
((new_symbols ()) (callstack ((0 0))))
((new_symbols (((From_perf _dl_start) 2))) (callstack ((2 0) (0 0))))
((new_symbols ()) (callstack ((1 1) (0 0))))
((new_symbols ()) (callstack ((2 1))))
((new_symbols ()) (callstack ((1 2))))
((new_symbols ()) (callstack ((2 1))))|}]
;;