Skip to content

Commit

Permalink
tools: make performance_compare.v more robust and easier to use, by a…
Browse files Browse the repository at this point in the history
…llowing `v run cmd/tools/performance_compare.v` too
  • Loading branch information
spytheman committed Aug 26, 2023
1 parent 806f071 commit c85232e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
15 changes: 7 additions & 8 deletions cmd/tools/modules/vgit/vgit.v
Expand Up @@ -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
}
Expand All @@ -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 {
Expand All @@ -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*,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -214,16 +214,15 @@ 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
verbose bool // should the tool be much more verbose
}

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
Expand Down
7 changes: 5 additions & 2 deletions cmd/tools/performance_compare.v
Expand Up @@ -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}')
Expand Down Expand Up @@ -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{}
Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand Down

0 comments on commit c85232e

Please sign in to comment.