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
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
type t = {path : string; name : string; color : Log.Color.t}
type regression_method =
| Lasso of {positive : bool}
| Ridge of {positive : bool}
| NNLS
type tag =
| Proto of Protocol.t
| Interpreter
| Translator
| Sapling
| Encoding
| Io
| Misc
| Builtin
| Global_constants
| Cache
| Carbonated_map
| Tickets
| Big_map
| Skip_list
| Sc_rollup
| Shell
| Apply
| Example
| Micheline
| Dal
type michelson_term_kind = Data | Code
type list_mode = All | Any | Exactly
let create ?(path = Constant.tezos_snoop) ?(color = Log.Color.FG.blue) () =
{path; name = "snoop"; color}
let spawn_command snoop command =
Process.spawn ~name:snoop.name ~color:snoop.color snoop.path command
let benchmark_command ~bench_name ~bench_num ~save_to ~nsamples ?seed
?config_file ?csv_dump () =
let command =
[
"benchmark";
bench_name;
"and";
"save";
"to";
save_to;
"--bench-num";
string_of_int bench_num;
"--nsamples";
string_of_int nsamples;
]
in
let seed =
match seed with None -> [] | Some seed -> ["--seed"; string_of_int seed]
in
let config_file =
match config_file with
| None -> []
| Some config_file -> ["--config-file"; config_file]
in
let csv_dump =
match csv_dump with None -> [] | Some csv -> ["--dump-csv"; csv]
in
command @ seed @ config_file @ csv_dump
let spawn_benchmark ~bench_name ~bench_num ~nsamples ~save_to ?seed ?config_file
?csv_dump snoop =
spawn_command
snoop
(benchmark_command
~bench_name
~bench_num
~save_to
~nsamples
?seed
?config_file
?csv_dump
())
let benchmark ~bench_name ~bench_num ~nsamples ~save_to ?seed ?config_file
?csv_dump snoop =
spawn_benchmark
~bench_name
~bench_num
~nsamples
~save_to
?seed
?config_file
?csv_dump
snoop
|> Process.check
let infer_command ~local_model_name ~workload_data ~regression_method ~dump_csv
~solution ?report ?graph () =
let regression_method =
match regression_method with
| Lasso {positive} ->
if positive then ["lasso"; "--lasso-positive"] else ["lasso"]
| Ridge {positive} ->
if positive then ["ridge"; "--ridge-positive"] else ["ridge"]
| NNLS -> ["nnls"]
in
let report =
match report with
| None -> []
| Some report_file -> ["--report"; report_file]
in
let graph =
match graph with
| None -> []
| Some graph_file -> ["--dot-file"; graph_file]
in
[
"infer";
"parameters";
"for";
"model";
local_model_name;
"on";
"data";
workload_data;
"using";
]
@ regression_method
@ ["--dump-csv"; dump_csv; "--save-solution"; solution]
@ report @ graph
let spawn_infer_parameters ~local_model_name ~workload_data ~regression_method
~dump_csv ~solution ?report ?graph snoop =
spawn_command
snoop
(infer_command
~local_model_name
~workload_data
~regression_method
~dump_csv
~solution
?report
?graph
())
let infer_parameters ~local_model_name ~workload_data ~regression_method
~dump_csv ~solution ?report ?graph snoop =
spawn_infer_parameters
~local_model_name
~workload_data
~regression_method
~dump_csv
~solution
?report
?graph
snoop
|> Process.check
let sapling_generate_command ~tx_count ~max_inputs ~max_outputs ~file
?(protocol = Protocol.Alpha) ?max_nullifiers ?max_additional_commitments
?seed () =
let max_nullifiers =
match max_nullifiers with
| None -> []
| Some max_nf -> ["--max-nullifiers"; string_of_int max_nf]
in
let max_additional_commitments =
match max_additional_commitments with
| None -> []
| Some max_ac -> ["--max-additional-commitments"; string_of_int max_ac]
in
let seed =
match seed with None -> [] | Some seed -> ["--seed"; string_of_int seed]
in
let proto_tag = Protocol.tag protocol in
[
proto_tag;
"sapling";
"generate";
string_of_int tx_count;
"transactions";
"in";
file;
"--max-inputs";
string_of_int max_inputs;
"--max-outputs";
string_of_int max_outputs;
]
@ max_nullifiers @ max_additional_commitments @ seed
let spawn_sapling_generate ?protocol ~tx_count ~max_inputs ~max_outputs ~file
?max_nullifiers ?max_additional_commitments ?seed snoop =
spawn_command
snoop
(sapling_generate_command
~tx_count
~max_inputs
~max_outputs
~file
?protocol
?max_nullifiers
?max_additional_commitments
?seed
())
let sapling_generate ?protocol ~tx_count ~max_inputs ~max_outputs ~file
?max_nullifiers ?max_additional_commitments ?seed snoop =
spawn_sapling_generate
~tx_count
~max_inputs
~max_outputs
~file
?protocol
?max_nullifiers
?max_additional_commitments
?seed
snoop
|> Process.check
let string_of_kind kind = match kind with Data -> "data" | Code -> "code"
let michelson_generate_command ?(protocol = Protocol.Alpha) ~terms_count ~kind
~file ?min_size ?max_size ?burn_in ?seed () =
let seed =
match seed with None -> [] | Some seed -> ["--seed"; string_of_int seed]
in
let min_size =
match min_size with
| None -> []
| Some sz -> ["--min-size"; string_of_int sz]
in
let max_size =
match max_size with
| None -> []
| Some sz -> ["--max-size"; string_of_int sz]
in
let burn_in =
match burn_in with
| None -> []
| Some burn_in -> ["--burn-in"; string_of_int burn_in]
in
let proto_tag = Protocol.tag protocol in
[
proto_tag;
"michelson";
"generate";
string_of_int terms_count;
"terms";
"of";
"kind";
string_of_kind kind;
"in";
file;
]
@ seed @ min_size @ max_size @ burn_in
let spawn_michelson_generate ?protocol ~terms_count ~kind ~file ?min_size
?max_size ?burn_in ?seed snoop =
spawn_command
snoop
(michelson_generate_command
?protocol
~terms_count
~kind
~file
?min_size
?max_size
?burn_in
?seed
())
let michelson_generate ?protocol ~terms_count ~kind ~file ?min_size ?max_size
?burn_in ?seed snoop =
spawn_michelson_generate
?protocol
~terms_count
~kind
~file
?min_size
?max_size
?burn_in
?seed
snoop
|> Process.check
let michelson_concat_command ?(protocol = Protocol.Alpha) ~file1 ~file2 ~target
() =
let proto_tag = Protocol.tag protocol in
[
proto_tag;
"michelson";
"concat";
"files";
file1;
"and";
file2;
"into";
target;
]
let spawn_michelson_concat ?protocol ~file1 ~file2 ~target snoop =
spawn_command
snoop
(michelson_concat_command ?protocol ~file1 ~file2 ~target ())
let michelson_concat ?protocol ~file1 ~file2 ~target snoop =
spawn_michelson_concat ?protocol ~file1 ~file2 ~target snoop |> Process.check
let string_of_tag (tag : tag) =
match tag with
| Proto proto -> Protocol.tag proto
| Interpreter -> "interpreter"
| Translator -> "translator"
| Sapling -> "sapling"
| Encoding -> "encoding"
| Io -> "io"
| Misc -> "misc"
| Builtin -> "builtin"
| Global_constants -> "global_constants"
| Cache -> "cache"
| Carbonated_map -> "carbonated_map"
| Tickets -> "tickets"
| Big_map -> "big_map"
| Skip_list -> "skip_list"
| Sc_rollup -> "sc_rollup"
| Shell -> "shell"
| Apply -> "apply"
| Example -> "example"
| Micheline -> "micheline"
| Dal -> "dal"
let list_benchmarks_command mode tags =
let tags = List.map string_of_tag tags in
match mode with
| All -> ["list"; "benchmarks"; "with"; "tags"; "all"; "of"] @ tags
| Any -> ["list"; "benchmarks"; "with"; "tags"; "any"; "of"] @ tags
| Exactly -> ["list"; "benchmarks"; "with"; "tags"; "exactly"] @ tags
let spawn_list_benchmarks ~mode ~tags snoop =
spawn_command snoop (list_benchmarks_command mode tags)
let list_benchmarks ~mode ~tags snoop =
let process = spawn_list_benchmarks ~mode ~tags snoop in
let* output = Process.check_and_read_stdout process in
let lines = String.split_on_char '\n' output in
Lwt_list.filter_map_s
(function
| "" -> return None
| line -> (
match line =~* rex "(.*):.*" with
| None -> Test.fail "Can't parse benchmark out of \"%s\"" line
| Some s -> return (Some s)))
lines
let empty_config ~(file : string) snoop =
let command = ["config"; "generate"; "empty"; "in"; file] in
spawn_command snoop command |> Process.check
let write_config ~(benchmark : string) ~(bench_config : string) ~(file : string)
snoop =
let command =
["config"; "edit"; file; "for"; benchmark; "-f"; bench_config]
in
let* () =
if not (Sys.file_exists file) then empty_config ~file snoop
else Lwt.return_unit
in
spawn_command snoop command |> Process.check
let generate_code_using_solution ~solution ?save_to ?fixed_point snoop =
let command =
[
"generate";
"code";
"using";
"solution";
solution;
"for";
"inferred";
"models";
]
@ (match fixed_point with None -> [] | Some fn -> ["--fixed-point"; fn])
@ match save_to with None -> [] | Some file -> ["--save-to"; file]
in
let process = spawn_command snoop command in
let* output = Process.check_and_read_stdout process in
match save_to with None -> Lwt.return output | _ -> Lwt.return ""
let check_definitions ~files snoop =
let open Process in
let command ~files = ["check"; "definitions"; "of"] @ files in
let spawn ~files snoop = spawn_command snoop (command ~files) in
let process = spawn ~files snoop in
Lwt.catch
(fun () -> check process)
(fun exn ->
Log.error "Cost function definitions have some issues" ;
raise exn)