From e23925f2be9d64d1cb4b3d69664bfc60d6ae302a Mon Sep 17 00:00:00 2001 From: Delyan Angelov Date: Tue, 14 Jul 2020 18:45:44 +0300 Subject: [PATCH] pref: add -show-timings option --- cmd/tools/vself.v | 2 +- cmd/v/help/build.txt | 10 ++++++++++ vlib/v/builder/builder.v | 8 ++++++++ vlib/v/builder/c.v | 6 +++--- vlib/v/builder/cc.v | 1 + vlib/v/builder/js.v | 6 +++--- vlib/v/builder/x64.v | 7 ++++--- vlib/v/pref/pref.v | 4 ++++ 8 files changed, 34 insertions(+), 10 deletions(-) diff --git a/cmd/tools/vself.v b/cmd/tools/vself.v index 7f654fda98..11904f1599 100644 --- a/cmd/tools/vself.v +++ b/cmd/tools/vself.v @@ -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' } diff --git a/cmd/v/help/build.txt b/cmd/v/help/build.txt index d157400ca7..d3e0f22a4a 100644 --- a/cmd/v/help/build.txt +++ b/cmd/v/help/build.txt @@ -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: diff --git a/vlib/v/builder/builder.v b/vlib/v/builder/builder.v index 9023c549d4..15ba85b016 100644 --- a/vlib/v/builder/builder.v +++ b/vlib/v/builder/builder.v @@ -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) + } +} diff --git a/vlib/v/builder/c.v b/vlib/v/builder/c.v index f9698fd8df..825a3a8f99 100644 --- a/vlib/v/builder/c.v +++ b/vlib/v/builder/c.v @@ -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 diff --git a/vlib/v/builder/cc.v b/vlib/v/builder/cc.v index e83f35966d..58fecac6b6 100644 --- a/vlib/v/builder/cc.v +++ b/vlib/v/builder/cc.v @@ -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 { diff --git a/vlib/v/builder/js.v b/vlib/v/builder/js.v index 2ba4d587d8..3eeb63c3f8 100644 --- a/vlib/v/builder/js.v +++ b/vlib/v/builder/js.v @@ -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 } diff --git a/vlib/v/builder/x64.v b/vlib/v/builder/x64.v index 2c89c98584..5d4c8f2d96 100644 --- a/vlib/v/builder/x64.v +++ b/vlib/v/builder/x64.v @@ -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() { diff --git a/vlib/v/pref/pref.v b/vlib/v/pref/pref.v index 39c57bd96c..b2ce95bfe5 100644 --- a/vlib/v/pref/pref.v +++ b/vlib/v/pref/pref.v @@ -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 }