mirror of
https://github.com/vlang/v.git
synced 2025-09-13 14:32:26 +03:00
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:
parent
d7550c5c02
commit
f91f4d94ea
2 changed files with 16 additions and 8 deletions
17
cmd/v/v.v
17
cmd/v/v.v
|
@ -61,14 +61,19 @@ fn main() {
|
|||
$if time_v ? {
|
||||
timers_should_print = true
|
||||
}
|
||||
mut timers := util.new_timers(should_print: timers_should_print, label: 'main')
|
||||
timers.start('v total')
|
||||
defer {
|
||||
timers.show('v total')
|
||||
if '-show-timings' in os.args {
|
||||
timers_should_print = true
|
||||
unbuffer_stdout()
|
||||
}
|
||||
mut timers := util.new_timers(should_print: timers_should_print, label: 'main')
|
||||
timers.start('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..]
|
||||
|
||||
if args.len == 0 || args[0] in ['-', 'repl'] {
|
||||
|
@ -90,7 +95,7 @@ fn main() {
|
|||
eprintln('-usecache is currently disabled on windows')
|
||||
exit(1)
|
||||
}
|
||||
timers.show('parse_CLI_args')
|
||||
timers.show('v parsing CLI args')
|
||||
// Start calling the correct functions/external tools
|
||||
// Note for future contributors: Please add new subcommands in the `match` block below.
|
||||
if command in external_tools {
|
||||
|
|
|
@ -71,7 +71,10 @@ pub fn (mut t Timers) measure(name string) i64 {
|
|||
eprintln('> Available timers:')
|
||||
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
|
||||
}
|
||||
|
||||
|
@ -112,8 +115,8 @@ pub fn (mut t Timers) message(name string) string {
|
|||
}
|
||||
|
||||
pub fn (mut t Timers) show(label string) {
|
||||
formatted_message := t.message(label)
|
||||
if t.should_print {
|
||||
formatted_message := t.message(label)
|
||||
println(formatted_message)
|
||||
}
|
||||
t.already_shown << label
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue