From 1777bcc69cf8ab4c77e9576fe72333be5d42dfb5 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Fri, 23 Aug 2024 12:15:23 +0300 Subject: [PATCH] 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 --- cmd/tools/vrepeat.v | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/cmd/tools/vrepeat.v b/cmd/tools/vrepeat.v index 1731ca578b..601ac5f789 100644 --- a/cmd/tools/vrepeat.v +++ b/cmd/tools/vrepeat.v @@ -148,7 +148,7 @@ fn (mut context Context) expand_all_commands(commands []string) []string { for paramv in paramlist { mut new_substituted_commands := []string{} for cscmd in substituted_commands { - scmd := cscmd.replace(paramk, paramv) + scmd := cscmd.replace('{${paramk}}', paramv) new_substituted_commands << scmd } 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() { + if context.results.len == 0 { + eprintln('no results') + exit(5) + } base := context.results[0].atiming.average context.results.sort_with_compare(compare_by_average) 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() ! { mut fp := flag.new_flag_parser(os.args#[1..]) 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.arguments_description('CMD1 CMD2 ...') fp.skip_executable() @@ -377,14 +381,14 @@ fn (mut context Context) parse_options() ! { 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_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}') - 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.') + 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. `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.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 { - parts := p.split(':') + parts := p.split('=') 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 {