v: add a TOTAL line, to the output of -show-timings, to minimise the need for external tools on windows (#21847)

This commit is contained in:
Delyan Angelov 2024-07-12 01:42:41 +03:00 committed by GitHub
parent d7550c5c02
commit f91f4d94ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 16 additions and 8 deletions

View file

@ -61,14 +61,19 @@ fn main() {
$if time_v ? { $if time_v ? {
timers_should_print = true timers_should_print = true
} }
mut timers := util.new_timers(should_print: timers_should_print, label: 'main') if '-show-timings' in os.args {
timers.start('v total') timers_should_print = true
defer { unbuffer_stdout()
timers.show('v total')
} }
mut timers := util.new_timers(should_print: timers_should_print, label: 'main')
timers.start('v start') timers.start('v start')
timers.show('v start') timers.show('v start')
timers.start('parse_CLI_args') timers.start('TOTAL')
// use at_exit here, instead of defer, since some code paths later do early exit(0) or exit(1), for showing errors, or after `v run`
at_exit(fn [mut timers] () {
timers.show('TOTAL')
})!
timers.start('v parsing CLI args')
args := os.args[1..] args := os.args[1..]
if args.len == 0 || args[0] in ['-', 'repl'] { if args.len == 0 || args[0] in ['-', 'repl'] {
@ -90,7 +95,7 @@ fn main() {
eprintln('-usecache is currently disabled on windows') eprintln('-usecache is currently disabled on windows')
exit(1) exit(1)
} }
timers.show('parse_CLI_args') timers.show('v parsing CLI args')
// Start calling the correct functions/external tools // Start calling the correct functions/external tools
// Note for future contributors: Please add new subcommands in the `match` block below. // Note for future contributors: Please add new subcommands in the `match` block below.
if command in external_tools { if command in external_tools {

View file

@ -71,7 +71,10 @@ pub fn (mut t Timers) measure(name string) i64 {
eprintln('> Available timers:') eprintln('> Available timers:')
eprintln('> ${timer_keys}') eprintln('> ${timer_keys}')
} }
ms := t.swatches[name].elapsed().microseconds() mut sw := t.swatches[name]
ms := sw.elapsed().microseconds()
sw.pause()
t.swatches[name] = sw
return ms return ms
} }
@ -112,8 +115,8 @@ pub fn (mut t Timers) message(name string) string {
} }
pub fn (mut t Timers) show(label string) { pub fn (mut t Timers) show(label string) {
formatted_message := t.message(label)
if t.should_print { if t.should_print {
formatted_message := t.message(label)
println(formatted_message) println(formatted_message)
} }
t.already_shown << label t.already_shown << label