mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
v.util.timers: improve tracing by supporting -d trace_timers_creation
This commit is contained in:
parent
2754368873
commit
229d2fb667
@ -50,7 +50,7 @@ fn main() {
|
||||
$if time_v ? {
|
||||
timers_should_print = true
|
||||
}
|
||||
mut timers := util.new_timers(timers_should_print)
|
||||
mut timers := util.new_timers(should_print: timers_should_print, label: 'main')
|
||||
timers.start('v total')
|
||||
defer {
|
||||
timers.show('v total')
|
||||
|
@ -101,7 +101,7 @@ mut:
|
||||
vweb_gen_types []ast.Type // vweb route checks
|
||||
prevent_sum_type_unwrapping_once bool // needed for assign new values to sum type, stopping unwrapping then
|
||||
loop_label string // set when inside a labelled for loop
|
||||
timers &util.Timers = util.new_timers(false)
|
||||
timers &util.Timers = util.get_timers()
|
||||
comptime_fields_type map[string]ast.Type
|
||||
fn_scope &ast.Scope = voidptr(0)
|
||||
main_fn_decl_node ast.FnDecl
|
||||
@ -123,7 +123,7 @@ pub fn new_checker(table &ast.Table, pref &pref.Preferences) &Checker {
|
||||
return &Checker{
|
||||
table: table
|
||||
pref: pref
|
||||
timers: util.new_timers(timers_should_print)
|
||||
timers: util.new_timers(should_print: timers_should_print, label: 'checker')
|
||||
match_exhaustive_cutoff_limit: pref.checker_match_exhaustive_cutoff_limit
|
||||
}
|
||||
}
|
||||
|
@ -175,7 +175,7 @@ mut:
|
||||
returned_var_name string // to detect that a var doesn't need to be freed since it's being returned
|
||||
branch_parent_pos int // used in BranchStmt (continue/break) for autofree stop position
|
||||
infix_left_var_name string // a && if expr
|
||||
timers &util.Timers = util.new_timers(false)
|
||||
timers &util.Timers = util.get_timers()
|
||||
force_main_console bool // true when [console] used on fn main()
|
||||
as_cast_type_names map[string]string // table for type name lookup in runtime (for __as_cast)
|
||||
obf_table map[string]string
|
||||
@ -240,7 +240,7 @@ pub fn gen(files []&ast.File, table &ast.Table, pref &pref.Preferences) string {
|
||||
indent: -1
|
||||
module_built: module_built
|
||||
timers_should_print: timers_should_print
|
||||
timers: util.new_timers(timers_should_print)
|
||||
timers: util.new_timers(should_print: timers_should_print, label: 'global_cgen')
|
||||
inner_loop: &ast.EmptyStmt{}
|
||||
field_data_type: ast.Type(table.find_type_idx('FieldData'))
|
||||
init: strings.new_builder(100)
|
||||
@ -525,7 +525,10 @@ fn cgen_process_one_file_cb(p &pool.PoolProcessor, idx int, wid int) &Gen {
|
||||
fn_decl: 0
|
||||
indent: -1
|
||||
module_built: global_g.module_built
|
||||
timers: util.new_timers(global_g.timers_should_print)
|
||||
timers: util.new_timers(
|
||||
should_print: global_g.timers_should_print
|
||||
label: 'cgen_process_one_file_cb idx: $idx, wid: $wid'
|
||||
)
|
||||
inner_loop: &ast.EmptyStmt{}
|
||||
field_data_type: ast.Type(global_g.table.find_type_idx('FieldData'))
|
||||
array_sort_fn: global_g.array_sort_fn
|
||||
|
@ -360,7 +360,7 @@ fn (mut q Queue) run() {
|
||||
}
|
||||
*/
|
||||
pub fn parse_files(paths []string, table &ast.Table, pref &pref.Preferences) []&ast.File {
|
||||
mut timers := util.new_timers(false)
|
||||
mut timers := util.new_timers(should_print: false, label: 'parse_files: $paths')
|
||||
$if time_parsing ? {
|
||||
timers.should_print = true
|
||||
}
|
||||
|
@ -1,12 +1,16 @@
|
||||
// Copyright (c) 2019-2021 Alexander Medvednikov. All rights reserved.
|
||||
// Use of this source code is governed by an MIT license
|
||||
// that can be found in the LICENSE file.
|
||||
[has_globals]
|
||||
module util
|
||||
|
||||
import time
|
||||
|
||||
__global g_timers = new_timers(should_print: false, label: 'g_timers')
|
||||
|
||||
[heap]
|
||||
pub struct Timers {
|
||||
label string
|
||||
pub mut:
|
||||
swatches map[string]time.StopWatch
|
||||
should_print bool
|
||||
@ -14,18 +18,26 @@ pub mut:
|
||||
already_shown []string
|
||||
}
|
||||
|
||||
pub fn new_timers(should_print bool) &Timers {
|
||||
[params]
|
||||
pub struct TimerParams {
|
||||
should_print bool
|
||||
label string
|
||||
}
|
||||
|
||||
pub fn new_timers(params TimerParams) &Timers {
|
||||
$if trace_timers_creation ? {
|
||||
eprintln('>>>> new_timers, should_print: $params.should_print | label: $params.label')
|
||||
}
|
||||
return &Timers{
|
||||
label: params.label
|
||||
swatches: map[string]time.StopWatch{}
|
||||
should_print: should_print
|
||||
should_print: params.should_print
|
||||
already_shown: []string{cap: 100}
|
||||
}
|
||||
}
|
||||
|
||||
const timers = new_timers(false)
|
||||
|
||||
pub fn get_timers() &Timers {
|
||||
return util.timers
|
||||
return g_timers
|
||||
}
|
||||
|
||||
pub fn timing_start(label string) {
|
||||
@ -34,18 +46,15 @@ pub fn timing_start(label string) {
|
||||
}
|
||||
|
||||
pub fn timing_measure(label string) {
|
||||
mut t := get_timers()
|
||||
t.show(label)
|
||||
g_timers.show(label)
|
||||
}
|
||||
|
||||
pub fn timing_measure_cumulative(label string) {
|
||||
mut t := get_timers()
|
||||
t.measure_cumulative(label)
|
||||
g_timers.measure_cumulative(label)
|
||||
}
|
||||
|
||||
pub fn timing_set_should_print(should_print bool) {
|
||||
mut t := util.timers
|
||||
t.should_print = should_print
|
||||
g_timers.should_print = should_print
|
||||
}
|
||||
|
||||
pub fn (mut t Timers) start(name string) {
|
||||
|
Loading…
Reference in New Issue
Block a user