1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

vgit: avoid generics; enables compilation of the performance_compare & oldv tools.

This commit is contained in:
Delyan Angelov
2020-04-20 18:39:25 +03:00
parent dc8199709f
commit 7a03b18bfe
3 changed files with 34 additions and 34 deletions

View File

@@ -16,17 +16,13 @@ const (
struct Context {
cwd string // current working folder
mut:
v_repo_url string // the url of the vc repository. It can be a local folder path, which is useful to eliminate network operations...
vc_repo_url string // the url of the vc repository. It can be a local folder path, which is useful to eliminate network operations...
workdir string // the working folder (typically /tmp), where the tool will write
vgo vgit.VGitOptions
a string // the full path to the 'after' folder inside workdir
b string // the full path to the 'before' folder inside workdir
vc string // the full path to the vc folder inside workdir. It is used during bootstrapping v from the C source.
commit_before string // the git commit for the 'before' state
commit_after string // the git commit for the 'after' state
warmups int // how many times to execute a command before gathering stats
verbose bool // whether to print even more stuff
show_help bool // whether to show the usage screen
hyperfineopts string // use for additional CLI options that will be given to the hyperfine command
vflags string // other v options to pass to compared v commands
}
@@ -42,14 +38,14 @@ fn new_context() Context {
fn (c Context) compare_versions() {
// Input is validated at this point...
// Cleanup artifacts from previous runs of this tool:
scripting.chdir(c.workdir)
scripting.chdir(c.vgo.workdir)
scripting.run('rm -rf "$c.a" "$c.b" "$c.vc" ')
// clone the VC source *just once per comparison*, and reuse it:
scripting.run('git clone --quiet "$c.vc_repo_url" "$c.vc" ')
scripting.run('git clone --quiet "$c.vgo.vc_repo_url" "$c.vc" ')
println('Comparing V performance of commit $c.commit_before (before) vs commit $c.commit_after (after) ...')
c.prepare_v(c.b, c.commit_before)
c.prepare_v(c.a, c.commit_after)
scripting.chdir(c.workdir)
scripting.chdir(c.vgo.workdir)
if c.vflags.len > 0 {
os.setenv('VFLAGS', c.vflags, true)
@@ -95,12 +91,12 @@ fn (c &Context) prepare_v(cdir string, commit string) {
}
mut vgit_context := vgit.VGitContext{
cc: cc
workdir: c.workdir
commit_v: commit
path_v: cdir
path_vc: c.vc
v_repo_url: c.v_repo_url
vc_repo_url: c.vc_repo_url
workdir: c.vgo.workdir
v_repo_url: c.vgo.v_repo_url
vc_repo_url: c.vgo.vc_repo_url
}
vgit_context.compile_oldv_if_needed()
scripting.chdir(cdir)
@@ -164,10 +160,10 @@ fn (c Context) compare_v_performance(label string, commands []string) string {
hyperfine_commands_arguments << " \'cd ${c.a:-34s} ; ./$cmd \' ".replace_each(['@COMPILER@', source_location_a, '@DEBUG@', debug_option_a])
}
// /////////////////////////////////////////////////////////////////////////////
cmd_stats_file := os.real_path([c.workdir, 'v_performance_stats_${label}.json'].join(os.path_separator))
cmd_stats_file := os.real_path([c.vgo.workdir, 'v_performance_stats_${label}.json'].join(os.path_separator))
comparison_cmd := 'hyperfine $c.hyperfineopts ' + '--export-json ${cmd_stats_file} ' + '--time-unit millisecond ' + '--style full --warmup $c.warmups ' + hyperfine_commands_arguments.join(' ')
// /////////////////////////////////////////////////////////////////////////////
if c.verbose {
if c.vgo.verbose {
println(comparison_cmd)
}
os.system(comparison_cmd)
@@ -193,16 +189,16 @@ fn main() {
${flag.space}For example on linux, you may want to pass:
${flag.space}--hyperfine_options "--prepare \'sync; echo 3 | sudo tee /proc/sys/vm/drop_caches\'"
')
commits := vgit.add_common_tool_options(mut context, mut fp)
commits := vgit.add_common_tool_options(mut context.vgo, mut fp)
context.commit_before = commits[0]
if commits.len > 1 {
context.commit_after = commits[1]
}
context.b = vgit.normalized_workpath_for_commit(context.workdir, context.commit_before)
context.a = vgit.normalized_workpath_for_commit(context.workdir, context.commit_after)
context.vc = vgit.normalized_workpath_for_commit(context.workdir, 'vc')
if !os.is_dir(context.workdir) {
msg := 'Work folder: ' + context.workdir + ' , does not exist.'
context.b = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_before)
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)
exit(2)
}