From c85232ef1f4e7c878bcb8fbe1935ad9ecb27f934 Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Sat, 26 Aug 2023 10:40:16 +0300 Subject: [PATCH] tools: make performance_compare.v more robust and easier to use, by allowing `v run cmd/tools/performance_compare.v` too --- cmd/tools/modules/vgit/vgit.v | 15 +++++++-------- cmd/tools/performance_compare.v | 7 +++++-- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/cmd/tools/modules/vgit/vgit.v b/cmd/tools/modules/vgit/vgit.v index fbce0aa8c7..420caa8f05 100644 --- a/cmd/tools/modules/vgit/vgit.v +++ b/cmd/tools/modules/vgit/vgit.v @@ -4,7 +4,7 @@ import os import flag import scripting -pub fn check_v_commit_timestamp_before_self_rebuilding(v_timestamp int) { +pub fn check_v_commit_timestamp_before_self_rebuilding(v_timestamp u64) { if v_timestamp >= 1561805697 { return } @@ -29,9 +29,9 @@ pub fn validate_commit_exists(commit string) { } } -pub fn line_to_timestamp_and_commit(line string) (int, string) { +pub fn line_to_timestamp_and_commit(line string) (u64, string) { parts := line.split(' ') - return parts[0].int(), parts[1] + return parts[0].u64(), parts[1] } pub fn normalized_workpath_for_commit(workdir string, commit string) string { @@ -45,7 +45,7 @@ fn get_current_folder_commit_hash() string { return v_commithash } -pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string, string, int) { +pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string, string, u64) { scripting.chdir(cdir) // Building a historic v with the latest vc is not always possible ... // It is more likely, that the vc *at the time of the v commit*, @@ -132,7 +132,7 @@ pub mut: // these will be filled by vgitcontext.compile_oldv_if_needed() commit_v__hash string // the git commit of the v repo that should be prepared commit_vc_hash string // the git commit of the vc repo, corresponding to commit_v__hash - commit_v__ts int // unix timestamp, that corresponds to commit_v__hash; filled by prepare_vc_source + commit_v__ts u64 // unix timestamp, that corresponds to commit_v__hash; filled by prepare_vc_source vexename string // v or v.exe vexepath string // the full absolute path to the prepared v/v.exe vvlocation string // v.v or compiler/ or cmd/v, depending on v version @@ -214,7 +214,7 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() { pub struct VGitOptions { pub mut: - workdir string // the working folder (typically /tmp), where the tool will write + workdir string = os.temp_dir() // the working folder (typically /tmp), where the tool will write v_repo_url string // the url of the V repository. It can be a local folder path, if you want to eliminate network operations... vc_repo_url string // the url of the vc repository. It can be a local folder path, if you want to eliminate network operations... show_help bool // whether to show the usage screen @@ -222,8 +222,7 @@ pub mut: } pub fn add_common_tool_options(mut context VGitOptions, mut fp flag.FlagParser) []string { - tdir := os.temp_dir() - context.workdir = os.real_path(fp.string('workdir', `w`, context.workdir, 'A writable base folder. Default: ${tdir}')) + context.workdir = os.real_path(fp.string('workdir', `w`, context.workdir, 'A writable base folder. Default: ${context.workdir}')) context.v_repo_url = fp.string('vrepo', 0, context.v_repo_url, 'The url of the V repository. You can clone it locally too. See also --vcrepo below.') context.vc_repo_url = fp.string('vcrepo', 0, context.vc_repo_url, 'The url of the vc repository. You can clone it ${flag.space}beforehand, and then just give the local folder diff --git a/cmd/tools/performance_compare.v b/cmd/tools/performance_compare.v index dfe432416e..1552ef9f1a 100644 --- a/cmd/tools/performance_compare.v +++ b/cmd/tools/performance_compare.v @@ -92,6 +92,7 @@ fn (c &Context) prepare_v(cdir string, commit string) { } vgit_context.compile_oldv_if_needed() scripting.chdir(cdir) + scripting.run('${cdir}/v version') println('Making a v compiler in ${cdir}') scripting.run('./v -cc ${cc} -o v ${vgit_context.vvlocation}') println('Making a vprod compiler in ${cdir}') @@ -147,6 +148,7 @@ fn (c Context) compare_v_performance(label string, commands []string) string { } timestamp_a, _ := vgit.line_to_timestamp_and_commit(scripting.run('cd ${c.a}/ ; git rev-list -n1 --timestamp HEAD')) timestamp_b, _ := vgit.line_to_timestamp_and_commit(scripting.run('cd ${c.b}/ ; git rev-list -n1 --timestamp HEAD')) + // 1570877641 is 065ce39 2019-10-12 debug_option_a := if timestamp_a > 1570877641 { '-cg ' } else { '-debug ' } debug_option_b := if timestamp_b > 1570877641 { '-cg ' } else { '-debug ' } mut hyperfine_commands_arguments := []string{} @@ -185,6 +187,8 @@ fn (c Context) compare_v_performance(label string, commands []string) string { } fn main() { + // allow for `v run cmd/tools/performance_compare.v`, see oldv.v + os.setenv('VEXE', '', true) scripting.used_tools_must_exist(['cp', 'rm', 'strip', 'make', 'git', 'upx', 'cc', 'wc', 'tail', 'find', 'xargs', 'hyperfine']) mut context := new_context() @@ -209,8 +213,7 @@ ${flag.space}--hyperfine_options "--prepare \'sync; echo 3 | sudo tee /proc/sys/ context.a = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_after) context.vc = vgit.normalized_workpath_for_commit(context.vgo.workdir, 'vc') if !os.is_dir(context.vgo.workdir) { - msg := 'Work folder: ' + context.vgo.workdir + ' , does not exist.' - eprintln(msg) + eprintln('Work folder: `{context.vgo.workdir}` , does not exist. Use `--workdir /some/path` to set it.') exit(2) } context.compare_versions()