Source file trace_stat_summary_cb.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
module Summary = Trace_stat_summary
module Utils = Trace_stat_summary_utils
type metrics = (string * float list) list [@@deriving repr]
let metrics_t = Irmin.Type.(Json.assoc (list float))
type result = { name : string; metrics : metrics } [@@deriving repr]
type t = { results : (result[@nobuiltin]) list } [@@deriving repr]
(** As of may 2021, outputing "nan" strings in place of numbers crashes the CB.
Let's just filter those out since this is functionally identical. *)
let filter_nans_out results =
List.map
(fun { name; metrics } ->
let metrics =
List.map
(fun (name, l) ->
(name, match l with [ v ] when Float.is_nan v -> [] | l -> l))
metrics
in
{ name; metrics })
results
let create_raw_results0 s : result list =
let open Summary in
[
{
name = "Trace Replay - main metrics";
metrics =
[
("CPU time elapsed (s)", [ s.elapsed_cpu ]);
( "TZ-transactions per sec",
[
(Utils.approx_transaction_count_of_block_count s.block_count
|> float_of_int)
/. s.elapsed_cpu;
] );
( "TZ-operations per sec",
[
(Utils.approx_operation_count_of_block_count s.block_count
|> float_of_int)
/. s.elapsed_cpu;
] );
( "Context.set per sec",
[
fst (Span.Map.find `Add s.span).cumu_count.max_value
/. s.elapsed_cpu;
] );
( "tail latency (s)",
[ fst (Span.Map.find `Commit s.span).duration.max_value ] );
];
};
{
name = "Trace Replay - resource usage - disk IO (total)";
metrics =
[
( "IOPS (op/s)",
[ s.index.nb_both.value_after_commit.diff /. s.elapsed_cpu ] );
( "throughput (MB/s)",
[
s.index.bytes_both.value_after_commit.diff /. s.elapsed_cpu /. 1e6;
] );
("total (MB)", [ s.index.bytes_both.value_after_commit.diff /. 1e6 ]);
];
};
{
name = "Trace Replay - resource usage - disk IO (read)";
metrics =
[
( "IOPS (op/s)",
[ s.index.nb_reads.value_after_commit.diff /. s.elapsed_cpu ] );
( "throughput (MB/s)",
[
s.index.bytes_read.value_after_commit.diff /. s.elapsed_cpu /. 1e6;
] );
("total (MB)", [ s.index.bytes_read.value_after_commit.diff /. 1e6 ]);
];
};
{
name = "Trace Replay - resource usage - disk IO (write)";
metrics =
[
( "IOPS (op/s)",
[ s.index.nb_writes.value_after_commit.diff /. s.elapsed_cpu ] );
( "throughput (MB/s)",
[
s.index.bytes_written.value_after_commit.diff
/. s.elapsed_cpu
/. 1e6;
] );
( "total (MB)",
[ s.index.bytes_written.value_after_commit.diff /. 1e6 ] );
];
};
{
name = "Trace Replay - resource usage - misc.";
metrics =
[
( "max memory usage (GB)",
[ List.fold_left max 0. s.gc.major_heap_top_bytes /. 1e9 ] );
("mean CPU usage", [ s.elapsed_cpu /. s.elapsed_wall ]);
];
};
]
let create_raw_results1 s : result list =
let a =
let name = "Trace Replay - Context Phases Length" in
let open Trace_stat_summary in
let metrics =
[ `Block; `Buildup; `Commit ]
|> List.map @@ fun k ->
let vs = Span.(Map.find k s.span).duration in
( Printf.sprintf "%s (ms)" (Span.Key.to_string k),
[
vs.mean *. 1000.
;
] )
in
{ name; metrics }
in
let b =
let name = "Trace Replay - Context Buildup Lengths" in
let open Trace_stat_summary in
let metrics =
[ `Add; `Remove; `Find; `Mem; `Mem_tree; `Copy; `Unseen ]
|> List.map @@ fun k ->
let vs = Span.(Map.find k s.span).duration in
( Printf.sprintf "%s (\xc2\xb5s)" (Span.Key.to_string k),
[
vs.mean *. 1e6 ;
] )
in
{ name; metrics }
in
[ a; b ]
let create_raw_results2 s : result list =
let name = "Trace Replay - irmin-pack Global Stats" in
let metrics =
let open Summary in
[
("finds", s.pack.finds.total);
("finds.from_staging", s.pack.finds.from_staging);
("finds.from_lru", s.pack.finds.from_lru);
("finds.from_pack_direct", s.pack.finds.from_pack_direct);
("finds.from_pack_indexed", s.pack.finds.from_pack_indexed);
("finds.missing", s.pack.finds.missing);
("finds.cache_miss", s.pack.finds.cache_miss);
("appended_hashes", s.pack.appended_hashes);
("appended_offsets", s.pack.appended_offsets);
("inode_add", s.pack.inode_add);
("inode_remove", s.pack.inode_remove);
("inode_of_seq", s.pack.inode_of_seq);
("inode_of_raw", s.pack.inode_of_raw);
("inode_rec_add", s.pack.inode_rec_add);
("inode_rec_remove", s.pack.inode_rec_remove);
("inode_to_binv", s.pack.inode_to_binv);
("inode_decode_bin", s.pack.inode_decode_bin);
("inode_encode_bin", s.pack.inode_encode_bin);
]
|> List.map @@ fun (name, lbs) -> (name, [ lbs.value_after_commit.diff ])
in
[ { name; metrics } ]
let create_raw_results3 s : result list =
let name = "Trace Replay - irmin.tree Global Stats" in
let open Trace_stat_summary in
let metrics =
[
("contents_hash", s.tree.contents_hash);
("contents_find", s.tree.contents_find);
("contents_add", s.tree.contents_add);
("node_hash", s.tree.node_hash);
("node_mem", s.tree.node_mem);
("node_add", s.tree.node_add);
("node_find", s.tree.node_find);
("node_val_v", s.tree.node_val_v);
("node_val_find", s.tree.node_val_find);
("node_val_list", s.tree.node_val_list);
]
|> List.map @@ fun (name, lbs) -> (name, [ lbs.value_after_commit.diff ])
in
[ { name; metrics } ]
let create_raw_results4 s : result list =
let name = "Trace Replay - index Stats" in
let open Trace_stat_summary in
let metrics =
[
( "cumu data MB",
[ fst s.index.cumu_data_bytes.value_after_commit.max_value *. 1e-6 ] );
("merge count", [ s.index.nb_merge.value_after_commit.diff ]);
]
in
[ { name; metrics } ]
let create_raw_results5 s : result list =
let name = "Trace Replay - GC Stats" in
let open Trace_stat_summary in
let metrics =
[
("minor words allocated", s.gc.minor_words);
("major words allocated", s.gc.major_words);
("minor collections", s.gc.minor_collections);
("major collections", s.gc.major_collections);
("promoted words", s.gc.promoted_words);
("compactions", s.gc.compactions);
]
|> List.map @@ fun (name, lbs) -> (name, [ lbs.value_after_commit.diff ])
in
let metrics' =
[
( "avg major heap MB after commit",
[ s.gc.major_heap_bytes.value_after_commit.mean /. 1e6 ] );
]
in
[ { name; metrics = metrics @ metrics' } ]
let of_summary s =
{
results =
create_raw_results0 s
@ create_raw_results1 s
@ create_raw_results2 s
@ create_raw_results3 s
@ create_raw_results4 s
@ create_raw_results5 s
|> filter_nans_out;
}