pref: add -show-timings option

pull/5829/head
Delyan Angelov 2020-07-14 18:45:44 +03:00
parent 06f5279f77
commit e23925f2be
8 changed files with 34 additions and 10 deletions

View File

@ -26,7 +26,7 @@ fn main() {
exit(1)
}
if result.output.len > 0 {
println(result.output)
println(result.output.trim_space())
}
v_file := if os.user_os() == 'windows' { 'v.exe' } else { 'v' }

View File

@ -110,6 +110,16 @@ The build flags are shared by the build and run commands:
to detect whether or not to use ANSI colors may not work in all cases.
These options allow you to override the default detection.
-check-syntax
Only scan and parse the files, but then stop. Useful for very quick syntax checks.
-show-timings
Print a summary about how long each compiler stage took, for example:
PARSE: 152ms
CHECK: 62ms
C GEN: 103ms
C tcc: 95ms
For C-specific build flags, use `v help build-c`.
See also:

View File

@ -303,3 +303,11 @@ fn (b &Builder) print_warnings_and_errors() {
fn verror(s string) {
util.verror('builder error', s)
}
pub fn (mut b Builder) timing_message(msg string) {
if b.pref.show_timings {
println(msg)
} else {
b.info(msg)
}
}

View File

@ -12,7 +12,7 @@ pub fn (mut b Builder) gen_c(v_files []string) string {
b.parse_imports()
t1 := time.ticks()
parse_time := t1 - t0
b.info('PARSE: ${parse_time}ms')
b.timing_message('PARSE: ${parse_time}ms')
if b.pref.only_check_syntax {
return ''
}
@ -21,14 +21,14 @@ pub fn (mut b Builder) gen_c(v_files []string) string {
b.checker.check_files(b.parsed_files)
t2 := time.ticks()
check_time := t2 - t1
b.info('CHECK: ${check_time}ms')
b.timing_message('CHECK: ${check_time}ms')
b.print_warnings_and_errors()
// println('starting cgen...')
// TODO: move gen.cgen() to c.gen()
res := gen.cgen(b.parsed_files, b.table, b.pref)
t3 := time.ticks()
gen_time := t3 - t2
b.info('C GEN: ${gen_time}ms')
b.timing_message('C GEN: ${gen_time}ms')
// println('cgen done')
// println(res)
return res

View File

@ -478,6 +478,7 @@ fn (mut v Builder) cc() {
println('$ccompiler took $diff ms')
println('=========\n')
}
v.timing_message('C ${ccompiler:3}: ${diff}ms')
// Link it if we are cross compiling and need an executable
/*
if v.os == .linux && !linux_host && v.pref.build_mode != .build {

View File

@ -13,16 +13,16 @@ pub fn (mut b Builder) gen_js(v_files []string) string {
b.parse_imports()
t1 := time.ticks()
parse_time := t1 - t0
b.info('PARSE: ${parse_time}ms')
b.timing_message('PARSE: ${parse_time}ms')
b.checker.check_files(b.parsed_files)
t2 := time.ticks()
check_time := t2 - t1
b.info('CHECK: ${check_time}ms')
b.timing_message('CHECK: ${check_time}ms')
b.print_warnings_and_errors()
res := js.gen(b.parsed_files, b.table, b.pref)
t3 := time.ticks()
gen_time := t3 - t2
b.info('JS GEN: ${gen_time}ms')
b.timing_message('JS GEN: ${gen_time}ms')
return res
}

View File

@ -16,15 +16,16 @@ pub fn (mut b Builder) build_x64(v_files []string, out_file string) {
b.parse_imports()
t1 := time.ticks()
parse_time := t1 - t0
b.info('PARSE: ${parse_time}ms')
b.timing_message('PARSE: ${parse_time}ms')
b.checker.check_files(b.parsed_files)
t2 := time.ticks()
check_time := t2 - t1
b.info('CHECK: ${check_time}ms')
b.timing_message('CHECK: ${check_time}ms')
x64.gen(b.parsed_files, out_file, b.pref)
t3 := time.ticks()
gen_time := t3 - t2
b.info('x64 GEN: ${gen_time}ms')
b.timing_message('x64 GEN: ${gen_time}ms')
}
pub fn (mut b Builder) compile_x64() {

View File

@ -117,6 +117,7 @@ pub mut:
is_vweb bool // skip _ var warning in templates
only_check_syntax bool // when true, just parse the files, then stop, before running checker
experimental bool // enable experimental features
show_timings bool // show how much time each compiler stage took
}
pub fn parse_args(args []string) (&Preferences, string) {
@ -128,6 +129,9 @@ pub fn parse_args(args []string) (&Preferences, string) {
arg := args[i]
current_args := args[i..]
match arg {
'-show-timings' {
res.show_timings = true
}
'-check-syntax' {
res.only_check_syntax = true
}