@@ -22,16 +22,20 @@ fn get_report_running_period_ms() time.Duration {
2222// It was extracted by the original non customiseable output implementation directly in cmd/tools/modules/testing/common.v
2323pub struct NormalReporter {
2424mut :
25+ vroot string
2526 runtime time.Duration
2627 comptime time.Duration
2728 nfiles int
2829 njobs int
2930 //
3031 running shared map [string ]LogMessage
3132 compiling shared map [string ]LogMessage
33+ rtimes shared []TaskDuration
34+ ctimes shared []TaskDuration
3235}
3336
3437pub fn (mut r NormalReporter) session_start (message string , mut ts TestSession) {
38+ r.vroot = ts.vroot.replace ('\\ ' , '/' ) + '/'
3539 header (message)
3640 r.nfiles = ts.files.len
3741 r.njobs = runtime.nr_jobs ()
@@ -74,7 +78,56 @@ fn (r &NormalReporter) report_current_running_and_compiling_status_periodically(
7478 }
7579}
7680
81+ fn (r &NormalReporter) show_longest (label string , limit int , kind TaskKind) {
82+ if limit < = 0 {
83+ return
84+ }
85+ println ('> Longest ${limit} by ${label} :' )
86+ mut tasks := []TaskDuration{cap: r.nfiles}
87+ match kind {
88+ .comptime {
89+ rlock r.ctimes {
90+ tasks << r.ctimes
91+ }
92+ }
93+ .runtime {
94+ rlock r.rtimes {
95+ tasks << r.rtimes
96+ }
97+ }
98+ .totaltime {
99+ mut tall := []TaskDuration{}
100+ rlock r.rtimes {
101+ tall << r.rtimes
102+ }
103+ rlock r.ctimes {
104+ tall << r.ctimes
105+ }
106+ mut mall := map [string ]TaskDuration{}
107+ for task in tall {
108+ if current := mall[task.path] {
109+ mall[task.path].duration = current.duration + task.duration
110+ continue
111+ }
112+ mall[task.path] = task
113+ }
114+ tasks = mall.values ()
115+ }
116+ }
117+ tasks.sort (a.duration > b.duration)
118+ for tidx, task in tasks {
119+ npath := task.path.replace ('\\ ' , '/' ).replace (r.vroot, '' )
120+ println (' ${tidx + 1:3} | ${task.duration:10s} | ${npath} ' )
121+ if tidx + 1 > = limit {
122+ break
123+ }
124+ }
125+ }
126+
77127pub fn (r &NormalReporter) session_stop (message string , mut ts TestSession) {
128+ r.show_longest ('compilation time' , show_longest_by_comptime, .comptime)
129+ r.show_longest ('run time' , show_longest_by_runtime, .runtime)
130+ r.show_longest ('total time' , show_longest_by_totaltime, .totaltime)
78131 println ('${ts.benchmark.total_message(message)} Comptime: ${r.comptime.microseconds() / 1000} ms. Runtime: ${r.runtime.microseconds() / 1000} ms.' )
79132}
80133
@@ -89,11 +142,17 @@ pub fn (mut r NormalReporter) report(index int, message LogMessage) {
89142 }
90143 if message.kind == .compile_end {
91144 r.comptime + = message.took
145+ lock r.ctimes {
146+ r.ctimes << TaskDuration{message.file, message.took}
147+ }
92148 lock r.compiling {
93149 r.compiling.delete (message.file)
94150 }
95151 }
96152 if message.kind == .cmd_end {
153+ lock r.rtimes {
154+ r.rtimes << TaskDuration{message.file, message.took}
155+ }
97156 r.runtime + = message.took
98157 }
99158 if message.kind == .cmd_begin {
@@ -161,3 +220,15 @@ pub fn (r NormalReporter) list_of_failed_commands(failed_cmds []string) {
161220 }
162221 }
163222}
223+
224+ enum TaskKind {
225+ comptime
226+ runtime
227+ totaltime
228+ }
229+
230+ struct TaskDuration {
231+ mut :
232+ path string
233+ duration time.Duration
234+ }
0 commit comments