tools: improve the help screen for v repeat -h, add detailed example for using -t and -p to produce a matrix of 24 permutation runs

This commit is contained in:
Delyan Angelov 2024-08-23 12:15:23 +03:00
parent 7baee04727
commit 1777bcc69c
No known key found for this signature in database
GPG key ID: 66886C0F12D595ED

View file

@ -148,7 +148,7 @@ fn (mut context Context) expand_all_commands(commands []string) []string {
for paramv in paramlist { for paramv in paramlist {
mut new_substituted_commands := []string{} mut new_substituted_commands := []string{}
for cscmd in substituted_commands { for cscmd in substituted_commands {
scmd := cscmd.replace(paramk, paramv) scmd := cscmd.replace('{${paramk}}', paramv)
new_substituted_commands << scmd new_substituted_commands << scmd
} }
for sc in new_substituted_commands { for sc in new_substituted_commands {
@ -297,6 +297,10 @@ fn compare_by_average(a &CmdResult, b &CmdResult) int {
} }
fn (mut context Context) show_diff_summary() { fn (mut context Context) show_diff_summary() {
if context.results.len == 0 {
eprintln('no results')
exit(5)
}
base := context.results[0].atiming.average base := context.results[0].atiming.average
context.results.sort_with_compare(compare_by_average) context.results.sort_with_compare(compare_by_average)
mut first_cmd_percentage := f64(100.0) mut first_cmd_percentage := f64(100.0)
@ -362,7 +366,7 @@ fn (mut context Context) show_summary_title(line string) {
fn (mut context Context) parse_options() ! { fn (mut context Context) parse_options() ! {
mut fp := flag.new_flag_parser(os.args#[1..]) mut fp := flag.new_flag_parser(os.args#[1..])
fp.application(os.file_name(os.executable())) fp.application(os.file_name(os.executable()))
fp.version('0.0.2') fp.version('0.0.3')
fp.description('Repeat command(s) and collect statistics.\nNote: quote each command (argument), when it contains spaces.') fp.description('Repeat command(s) and collect statistics.\nNote: quote each command (argument), when it contains spaces.')
fp.arguments_description('CMD1 CMD2 ...') fp.arguments_description('CMD1 CMD2 ...')
fp.skip_executable() fp.skip_executable()
@ -377,14 +381,14 @@ fn (mut context Context) parse_options() ! {
context.verbose = fp.bool('verbose', `v`, false, 'Be more verbose.') context.verbose = fp.bool('verbose', `v`, false, 'Be more verbose.')
context.fail_on_maxtime = fp.int('max_time', `m`, max_time, 'Fail with exit code 2, when first cmd takes above M milliseconds (regression). Default: ${max_time}') context.fail_on_maxtime = fp.int('max_time', `m`, max_time, 'Fail with exit code 2, when first cmd takes above M milliseconds (regression). Default: ${max_time}')
context.fail_on_regress_percent = fp.int('fail_percent', `f`, max_fail_percent, 'Fail with exit code 3, when first cmd is X% slower than the rest (regression). Default: ${max_fail_percent}') context.fail_on_regress_percent = fp.int('fail_percent', `f`, max_fail_percent, 'Fail with exit code 3, when first cmd is X% slower than the rest (regression). Default: ${max_fail_percent}')
context.cmd_template = fp.string('template', `t`, '{T}', 'Command template. {T} will be substituted with the current command. Default: {T}') context.cmd_template = fp.string('template', `t`, '{T}', 'Command template. {T} will be substituted with the current command. Default: {T}. \n Here is an example, that will produce and run 24 permutations = (3 for opt) x (2 for source) x (4 = v names):\n v repeat -p opt=-check-syntax,-check,"-o x.c" -p source=examples/hello_world.v,examples/hanoi.v --template "./{T} {opt} {source}" vold vnew vold_prod vnew_prod')
cmd_params := fp.string_multi('parameter', `p`, 'A parameter substitution list. `{p}=val1,val2,val2` means that {p} in the template, will be substituted with each of val1, val2, val3.') cmd_params := fp.string_multi('parameter', `p`, 'A parameter substitution list. `pp=val1,val2,val2` means that {pp} in the template, will be substituted with *each* of val1, val2, val3.')
context.nmins = fp.int('nmins', `i`, 0, 'Ignore the BOTTOM X results (minimum execution time). Makes the results more robust to performance flukes. Default: 0') context.nmins = fp.int('nmins', `i`, 0, 'Ignore the BOTTOM X results (minimum execution time). Makes the results more robust to performance flukes. Default: 0')
context.nmaxs = fp.int('nmaxs', `a`, 0, 'Ignore the TOP X results (maximum execution time). Makes the results more robust to performance flukes. Default: 0') context.nmaxs = fp.int('nmaxs', `a`, 0, 'Ignore the TOP X results (maximum execution time). Makes the results more robust to performance flukes. Default: 0')
for p in cmd_params { for p in cmd_params {
parts := p.split(':') parts := p.split('=')
if parts.len > 1 { if parts.len > 1 {
context.cmd_params[parts[0]] = parts[1].split(',') context.cmd_params[parts[0].trim('{}')] = parts[1].split(',')
} }
} }
if context.show_help { if context.show_help {