Skip to content

Commit c85232e

Browse files
committed
tools: make performance_compare.v more robust and easier to use, by allowing v run cmd/tools/performance_compare.v too
1 parent 806f071 commit c85232e

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

cmd/tools/modules/vgit/vgit.v

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import os
44
import flag
55
import scripting
66

7-
pub fn check_v_commit_timestamp_before_self_rebuilding(v_timestamp int) {
7+
pub fn check_v_commit_timestamp_before_self_rebuilding(v_timestamp u64) {
88
if v_timestamp >= 1561805697 {
99
return
1010
}
@@ -29,9 +29,9 @@ pub fn validate_commit_exists(commit string) {
2929
}
3030
}
3131

32-
pub fn line_to_timestamp_and_commit(line string) (int, string) {
32+
pub fn line_to_timestamp_and_commit(line string) (u64, string) {
3333
parts := line.split(' ')
34-
return parts[0].int(), parts[1]
34+
return parts[0].u64(), parts[1]
3535
}
3636

3737
pub fn normalized_workpath_for_commit(workdir string, commit string) string {
@@ -45,7 +45,7 @@ fn get_current_folder_commit_hash() string {
4545
return v_commithash
4646
}
4747

48-
pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string, string, int) {
48+
pub fn prepare_vc_source(vcdir string, cdir string, commit string) (string, string, u64) {
4949
scripting.chdir(cdir)
5050
// Building a historic v with the latest vc is not always possible ...
5151
// It is more likely, that the vc *at the time of the v commit*,
@@ -132,7 +132,7 @@ pub mut:
132132
// these will be filled by vgitcontext.compile_oldv_if_needed()
133133
commit_v__hash string // the git commit of the v repo that should be prepared
134134
commit_vc_hash string // the git commit of the vc repo, corresponding to commit_v__hash
135-
commit_v__ts int // unix timestamp, that corresponds to commit_v__hash; filled by prepare_vc_source
135+
commit_v__ts u64 // unix timestamp, that corresponds to commit_v__hash; filled by prepare_vc_source
136136
vexename string // v or v.exe
137137
vexepath string // the full absolute path to the prepared v/v.exe
138138
vvlocation string // v.v or compiler/ or cmd/v, depending on v version
@@ -214,16 +214,15 @@ pub fn (mut vgit_context VGitContext) compile_oldv_if_needed() {
214214

215215
pub struct VGitOptions {
216216
pub mut:
217-
workdir string // the working folder (typically /tmp), where the tool will write
217+
workdir string = os.temp_dir() // the working folder (typically /tmp), where the tool will write
218218
v_repo_url string // the url of the V repository. It can be a local folder path, if you want to eliminate network operations...
219219
vc_repo_url string // the url of the vc repository. It can be a local folder path, if you want to eliminate network operations...
220220
show_help bool // whether to show the usage screen
221221
verbose bool // should the tool be much more verbose
222222
}
223223

224224
pub fn add_common_tool_options(mut context VGitOptions, mut fp flag.FlagParser) []string {
225-
tdir := os.temp_dir()
226-
context.workdir = os.real_path(fp.string('workdir', `w`, context.workdir, 'A writable base folder. Default: ${tdir}'))
225+
context.workdir = os.real_path(fp.string('workdir', `w`, context.workdir, 'A writable base folder. Default: ${context.workdir}'))
227226
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.')
228227
context.vc_repo_url = fp.string('vcrepo', 0, context.vc_repo_url, 'The url of the vc repository. You can clone it
229228
${flag.space}beforehand, and then just give the local folder

cmd/tools/performance_compare.v

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ fn (c &Context) prepare_v(cdir string, commit string) {
9292
}
9393
vgit_context.compile_oldv_if_needed()
9494
scripting.chdir(cdir)
95+
scripting.run('${cdir}/v version')
9596
println('Making a v compiler in ${cdir}')
9697
scripting.run('./v -cc ${cc} -o v ${vgit_context.vvlocation}')
9798
println('Making a vprod compiler in ${cdir}')
@@ -147,6 +148,7 @@ fn (c Context) compare_v_performance(label string, commands []string) string {
147148
}
148149
timestamp_a, _ := vgit.line_to_timestamp_and_commit(scripting.run('cd ${c.a}/ ; git rev-list -n1 --timestamp HEAD'))
149150
timestamp_b, _ := vgit.line_to_timestamp_and_commit(scripting.run('cd ${c.b}/ ; git rev-list -n1 --timestamp HEAD'))
151+
// 1570877641 is 065ce39 2019-10-12
150152
debug_option_a := if timestamp_a > 1570877641 { '-cg ' } else { '-debug ' }
151153
debug_option_b := if timestamp_b > 1570877641 { '-cg ' } else { '-debug ' }
152154
mut hyperfine_commands_arguments := []string{}
@@ -185,6 +187,8 @@ fn (c Context) compare_v_performance(label string, commands []string) string {
185187
}
186188

187189
fn main() {
190+
// allow for `v run cmd/tools/performance_compare.v`, see oldv.v
191+
os.setenv('VEXE', '', true)
188192
scripting.used_tools_must_exist(['cp', 'rm', 'strip', 'make', 'git', 'upx', 'cc', 'wc', 'tail',
189193
'find', 'xargs', 'hyperfine'])
190194
mut context := new_context()
@@ -209,8 +213,7 @@ ${flag.space}--hyperfine_options "--prepare \'sync; echo 3 | sudo tee /proc/sys/
209213
context.a = vgit.normalized_workpath_for_commit(context.vgo.workdir, context.commit_after)
210214
context.vc = vgit.normalized_workpath_for_commit(context.vgo.workdir, 'vc')
211215
if !os.is_dir(context.vgo.workdir) {
212-
msg := 'Work folder: ' + context.vgo.workdir + ' , does not exist.'
213-
eprintln(msg)
216+
eprintln('Work folder: `{context.vgo.workdir}` , does not exist. Use `--workdir /some/path` to set it.')
214217
exit(2)
215218
}
216219
context.compare_versions()

0 commit comments

Comments
 (0)