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
type time = Measure.time
type datum = {
scenario : string;
section : string;
label : string;
ticks : Z.t;
time : time;
}
let make_datum scenario section label ticks time =
{scenario; section; label; ticks; time}
type benchmark = {
verbose : bool;
totals : bool;
irmin : bool;
current_scenario : string;
current_section : string;
data : datum list;
total_time : time;
total_tick : Z.t;
}
let empty_benchmark ?(verbose = false) ?(totals = true) ?(irmin = true) () =
{
verbose;
totals;
irmin;
current_scenario = "";
current_section = "";
data = [];
total_time = Measure.zero;
total_tick = Z.zero;
}
let init_scenario scenario benchmark =
{
benchmark with
current_scenario = scenario;
current_section = "Booting " ^ scenario;
}
let switch_section current_section benchmark = {benchmark with current_section}
let verbose_datum name ticks time =
Printf.printf
"%s finished in %s ticks %f s\n%!"
name
(Z.to_string ticks)
(Measure.to_seconds time)
let add_datum name ticks time benchmark =
if benchmark.verbose then verbose_datum name ticks time ;
if (not benchmark.totals) && benchmark.current_section = name then benchmark
else if (not benchmark.irmin) && ticks = Z.zero then benchmark
else
let datum =
make_datum
benchmark.current_scenario
benchmark.current_section
name
ticks
time
in
{benchmark with data = datum :: benchmark.data}
let add_final_info total_time total_tick benchmark =
if benchmark.totals then
let datum =
make_datum
benchmark.current_scenario
"all steps"
"total"
total_tick
total_time
in
{benchmark with data = datum :: benchmark.data}
else benchmark
let add_tickless_datum label time benchmark =
add_datum label Z.zero time benchmark
module Csv = struct
let pp_line oc scenario section label ticks time =
Printf.fprintf
oc
"\"%s\" , \"%s\" , \"%s\" , %s , %f \n%!"
scenario
section
label
(Z.to_string ticks)
(Measure.to_seconds time)
let pp_datum oc {scenario; section; label; ticks; time} =
if section != label then pp_line oc scenario section label ticks time
else pp_line oc scenario section "all phases" ticks time
let pp_benchmark oc benchmark =
List.iter (pp_datum oc) (List.rev benchmark.data) ;
close_out oc
end
let cycle_infos benchmark =
let folder (cycles, acc_ticks, acc_time) datum =
match datum.label with
| "Padding" -> ((acc_ticks, acc_time) :: cycles, Z.zero, 0.0)
| "Decoding" | "Linking" | "Initialising" | "Evaluating" ->
( cycles,
Z.add acc_ticks datum.ticks,
acc_time +. Measure.to_seconds datum.time )
| _ -> (cycles, acc_ticks, acc_time)
in
let cycles, _, _ =
List.fold_left folder ([], Z.zero, 0.0) (List.rev benchmark.data)
in
List.rev cycles
let pp_analysis fmt benchmark =
let cycles = cycle_infos benchmark in
Format.fprintf fmt "Ran for %d kernel_run calls:" (List.length cycles) ;
let pp_cycle (ticks, time) =
Format.fprintf fmt "\n%s ticks in %f seconds" (Z.to_string ticks) time
in
List.iter pp_cycle cycles