Skip to content

Commit 9649af3

Browse files
committed
tools: improve v test by updating VTEST_REPORT_RUNNING_PERIOD_MS to 5 minutes by default, and adding stats for the currently compiling tests too
1 parent 6534616 commit 9649af3

1 file changed

Lines changed: 37 additions & 9 deletions

File tree

‎cmd/tools/modules/testing/output_normal.v‎

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
module testing
22

3+
import os
34
import time
45
import term
5-
import os
6+
import strings
7+
import runtime
68

79
pub const empty = term.header(' ', ' ')
810

@@ -12,7 +14,7 @@ pub const empty = term.header(' ', ' ')
1214
pub const report_running_period_ms = get_report_running_period_ms()
1315

1416
fn get_report_running_period_ms() time.Duration {
15-
return os.getenv_opt('VTEST_REPORT_RUNNING_PERIOD_MS') or { '60000' }.int() * time.millisecond
17+
return os.getenv_opt('VTEST_REPORT_RUNNING_PERIOD_MS') or { '300_000' }.int() * time.millisecond // 5 minutes by default
1618
}
1719

1820
// NormalReporter implements the interface testing.Reporter.
@@ -22,35 +24,53 @@ pub struct NormalReporter {
2224
mut:
2325
runtime time.Duration
2426
comptime time.Duration
25-
running shared map[string]LogMessage
2627
nfiles int
28+
njobs int
29+
//
30+
running shared map[string]LogMessage
31+
compiling shared map[string]LogMessage
2732
}
2833

2934
pub fn (mut r NormalReporter) session_start(message string, mut ts TestSession) {
3035
header(message)
3136
r.nfiles = ts.files.len
32-
spawn r.report_current_running_status_periodically()
37+
r.njobs = runtime.nr_jobs()
38+
spawn r.report_current_running_and_compiling_status_periodically()
3339
}
3440

35-
fn (r &NormalReporter) report_current_running_status_periodically() {
41+
fn (r &NormalReporter) report_current_running_and_compiling_status_periodically() {
3642
if report_running_period_ms == 0 {
3743
return
3844
}
3945
mut start_t := time.now()
4046
mut pi := 0
47+
mut ccompiling := map[string]LogMessage{}
4148
mut crunning := map[string]LogMessage{}
49+
mut sb := strings.new_builder(1024)
4250
for {
4351
pi++
4452
time.sleep(report_running_period_ms)
4553
t := time.now()
54+
rlock r.compiling {
55+
ccompiling = r.compiling.clone()
56+
}
4657
rlock r.running {
4758
crunning = r.running.clone()
4859
}
49-
keys := crunning.keys()
50-
eprintln(' >>>>> ${t.format_ss_micro()} | period ${pi:2} | started: ${t - start_t:10} ago | total files: ${r.nfiles:5} | vjobs: ${' | running ${keys.len} _test.v files'}')
51-
for ik, k in keys {
52-
eprintln(' >>>>> ${ik + 1:4}/${keys.len:-4}, T: ${crunning[k].flow_id:3}, started: ${t - crunning[k].when:10} ago, `${k}`')
60+
ckeys := ccompiling.keys()
61+
rkeys := crunning.keys()
62+
sb.writeln('')
63+
sb.writeln(' >>>>> ${t.format_ss_micro()} | period ${pi:2} | started: ${t - start_t:10} ago | vjobs: ${r.njobs} | _test.v files: ${r.nfiles:5} | C: ${ckeys.len:3} | R: ${rkeys.len:3}')
64+
for ik, k in ckeys {
65+
cval := ccompiling[k]
66+
sb.writeln(' >>>>> compiling ${ik + 1:2}/${ckeys.len:-2}, T: ${cval.flow_id:2}, started: ${t - cval.when:10} ago, `${k}`')
67+
}
68+
for ik, k in rkeys {
69+
cval := crunning[k]
70+
sb.writeln(' >>>>> running ${ik + 1:2}/${rkeys.len:-2}, T: ${cval.flow_id:2}, started: ${t - cval.when:10} ago, `${k}`')
5371
}
72+
sb.writeln('')
73+
eprint(sb.str()) // write everything at once, to minimise the chance of interference with the normal output of `v test`
5474
}
5575
}
5676

@@ -62,8 +82,16 @@ pub fn (r &NormalReporter) session_stop(message string, mut ts TestSession) {
6282
// in the normal one, it currently does nothing
6383
pub fn (mut r NormalReporter) report(index int, message LogMessage) {
6484
// eprintln('> ${@METHOD} index: $index | message: $message')
85+
if message.kind == .compile_begin {
86+
lock r.compiling {
87+
r.compiling[message.file] = message
88+
}
89+
}
6590
if message.kind == .compile_end {
6691
r.comptime += message.took
92+
lock r.compiling {
93+
r.compiling.delete(message.file)
94+
}
6795
}
6896
if message.kind == .cmd_end {
6997
r.runtime += message.took

0 commit comments

Comments
 (0)