mirror of
https://github.com/vlang/v.git
synced 2025-09-09 07:15:50 -04:00
tools: make performance_compare.v more robust and easier to use, by allowing v run cmd/tools/performance_compare.v
too
This commit is contained in:
parent
806f071a11
commit
c85232ef1f
@ -4,7 +4,7 @@ import os
|
|||||||
import flag
|
import flag
|
||||||
import scripting
|
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 {
|
if v_timestamp >= 1561805697 {
|
||||||
return
|
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(' ')
|
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 {
|
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
|
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)
|
scripting.chdir(cdir)
|
||||||
// Building a historic v with the latest vc is not always possible ...
|
// 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*,
|
// 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()
|
// 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_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_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
|
vexename string // v or v.exe
|
||||||
vexepath string // the full absolute path to the prepared v/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
|
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 struct VGitOptions {
|
||||||
pub mut:
|
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...
|
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...
|
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
|
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 {
|
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: ${context.workdir}'))
|
||||||
context.workdir = os.real_path(fp.string('workdir', `w`, context.workdir, 'A writable base folder. Default: ${tdir}'))
|
|
||||||
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.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
|
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
|
${flag.space}beforehand, and then just give the local folder
|
||||||
|
@ -92,6 +92,7 @@ fn (c &Context) prepare_v(cdir string, commit string) {
|
|||||||
}
|
}
|
||||||
vgit_context.compile_oldv_if_needed()
|
vgit_context.compile_oldv_if_needed()
|
||||||
scripting.chdir(cdir)
|
scripting.chdir(cdir)
|
||||||
|
scripting.run('${cdir}/v version')
|
||||||
println('Making a v compiler in ${cdir}')
|
println('Making a v compiler in ${cdir}')
|
||||||
scripting.run('./v -cc ${cc} -o v ${vgit_context.vvlocation}')
|
scripting.run('./v -cc ${cc} -o v ${vgit_context.vvlocation}')
|
||||||
println('Making a vprod compiler in ${cdir}')
|
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_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'))
|
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_a := if timestamp_a > 1570877641 { '-cg ' } else { '-debug ' }
|
||||||
debug_option_b := if timestamp_b > 1570877641 { '-cg ' } else { '-debug ' }
|
debug_option_b := if timestamp_b > 1570877641 { '-cg ' } else { '-debug ' }
|
||||||
mut hyperfine_commands_arguments := []string{}
|
mut hyperfine_commands_arguments := []string{}
|
||||||
@ -185,6 +187,8 @@ fn (c Context) compare_v_performance(label string, commands []string) string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn main() {
|
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',
|
scripting.used_tools_must_exist(['cp', 'rm', 'strip', 'make', 'git', 'upx', 'cc', 'wc', 'tail',
|
||||||
'find', 'xargs', 'hyperfine'])
|
'find', 'xargs', 'hyperfine'])
|
||||||
mut context := new_context()
|
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.a = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_after)
|
||||||
context.vc = vgit.normalized_workpath_for_commit(context.vgo.workdir, 'vc')
|
context.vc = vgit.normalized_workpath_for_commit(context.vgo.workdir, 'vc')
|
||||||
if !os.is_dir(context.vgo.workdir) {
|
if !os.is_dir(context.vgo.workdir) {
|
||||||
msg := 'Work folder: ' + context.vgo.workdir + ' , does not exist.'
|
eprintln('Work folder: `{context.vgo.workdir}` , does not exist. Use `--workdir /some/path` to set it.')
|
||||||
eprintln(msg)
|
|
||||||
exit(2)
|
exit(2)
|
||||||
}
|
}
|
||||||
context.compare_versions()
|
context.compare_versions()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user