@@ -97,6 +97,7 @@ struct TestRecord <: AbstractTestRecord
9797 bytes:: UInt64
9898 gctime:: Float64
9999 rss:: UInt64
100+ total_time:: Float64
100101end
101102
102103function memory_usage (rec:: TestRecord )
@@ -116,6 +117,7 @@ struct TestIOContext
116117 stdout :: IO
117118 stderr :: IO
118119 color:: Bool
120+ debug_timing:: Bool
119121 lock:: ReentrantLock
120122 name_align:: Int
121123 elapsed_align:: Int
@@ -125,7 +127,7 @@ struct TestIOContext
125127 rss_align:: Int
126128end
127129
128- function test_IOContext (stdout :: IO , stderr :: IO , lock:: ReentrantLock , name_align:: Int )
130+ function test_IOContext (stdout :: IO , stderr :: IO , lock:: ReentrantLock , name_align:: Int , debug_timing :: Bool )
129131 elapsed_align = textwidth (" Time (s)" )
130132 gc_align = textwidth (" GC (s)" )
131133 percent_align = textwidth (" GC %" )
@@ -135,19 +137,26 @@ function test_IOContext(stdout::IO, stderr::IO, lock::ReentrantLock, name_align:
135137 color = get (stdout , :color , false )
136138
137139 return TestIOContext (
138- stdout , stderr , color, lock, name_align, elapsed_align, gc_align, percent_align,
140+ stdout , stderr , color, debug_timing, lock, name_align, elapsed_align, gc_align, percent_align,
139141 alloc_align, rss_align
140142 )
141143end
142144
143145function print_header (ctx:: TestIOContext , testgroupheader, workerheader)
144146 lock (ctx. lock)
145147 try
148+ # header top
146149 printstyled (ctx. stdout , " " ^ (ctx. name_align + textwidth (testgroupheader) - 3 ), " │ " )
147- printstyled (ctx. stdout , " │ ──────────────── CPU ──────────────── │\n " , color = :white )
150+ printstyled (ctx. stdout , " |" , color = :white )
151+ ctx. debug_timing && printstyled (ctx. stdout , " Init │" , color = :white )
152+ printstyled (ctx. stdout , " ──────────────── CPU ──────────────── │\n " , color = :white )
153+
154+ # header bottom
148155 printstyled (ctx. stdout , testgroupheader, color = :white )
149156 printstyled (ctx. stdout , lpad (workerheader, ctx. name_align - textwidth (testgroupheader) + 1 ), " │ " , color = :white )
150- printstyled (ctx. stdout , " Time (s) │ GC (s) │ GC % │ Alloc (MB) │ RSS (MB) │\n " , color = :white )
157+ printstyled (ctx. stdout , " Time (s) │" , color = :white )
158+ ctx. debug_timing && printstyled (ctx. stdout , " time (s) │" , color = :white )
159+ printstyled (ctx. stdout , " GC (s) │ GC % │ Alloc (MB) │ RSS (MB) │\n " , color = :white )
151160 flush (ctx. stdout )
152161 finally
153162 unlock (ctx. lock)
@@ -173,9 +182,15 @@ function print_test_finished(record::TestRecord, wrkr, test, ctx::TestIOContext)
173182 try
174183 printstyled (ctx. stdout , test, color = :white )
175184 printstyled (ctx. stdout , lpad (" ($wrkr )" , ctx. name_align - textwidth (test) + 1 , " " ), " │ " , color = :white )
176- time_str = @sprintf (" %7.2f" , record. time)
185+ time = record. time
186+ time_str = @sprintf (" %7.2f" , time)
177187 printstyled (ctx. stdout , lpad (time_str, ctx. elapsed_align, " " ), " │ " , color = :white )
178188
189+ if ctx. debug_timing
190+ init_time_str = @sprintf (" %7.2f" , record. total_time - time)
191+ printstyled (ctx. stdout , lpad (init_time_str, ctx. elapsed_align, " " ), " │ " , color = :white )
192+ end
193+
179194 gc_str = @sprintf (" %5.2f" , record. gctime)
180195 printstyled (ctx. stdout , lpad (gc_str, ctx. gc_align, " " ), " │ " , color = :white )
181196 percent_str = @sprintf (" %4.1f" , 100 * record. gctime / record. time)
@@ -201,8 +216,11 @@ function print_test_failed(record::TestRecord, wrkr, test, ctx::TestIOContext)
201216 lpad (" ($wrkr )" , ctx. name_align - textwidth (test) + 1 , " " ), " |"
202217 , color = :red
203218 )
204- time_str = @sprintf (" %7.2f" , record. time)
219+ time = record. time
220+ time_str = @sprintf (" %7.2f" , time)
205221 printstyled (ctx. stderr , lpad (time_str, ctx. elapsed_align + 1 , " " ), " │" , color = :red )
222+ init_time_str = @sprintf (" %7.2f" , record. total_time - time)
223+ printstyled (ctx. stdout , lpad (init_time_str, ctx. elapsed_align, " " ), " │ " , color = :red )
206224
207225 failed_str = " failed at $(now ()) \n "
208226 # 11 -> 3 from " | " 3x and 2 for each " " on either side
@@ -288,7 +306,7 @@ function Test.finish(ts::WorkerTestSet)
288306 return ts. wrapped_ts
289307end
290308
291- function runtest (f, name, init_code)
309+ function runtest (f, name, init_code, start_time )
292310 function inner ()
293311 # generate a temporary module to execute the tests in
294312 mod = @eval (Main, module $ (gensym (name)) end )
@@ -317,7 +335,7 @@ function runtest(f, name, init_code)
317335
318336 # process results
319337 rss = Sys. maxrss ()
320- record = TestRecord (data... , rss)
338+ record = TestRecord (data... , rss, time () - start_time )
321339
322340 GC. gc (true )
323341 return record
@@ -552,6 +570,7 @@ Fields are
552570
553571* `jobs::Union{Some{Int}, Nothing}`: the number of jobs
554572* `verbose::Union{Some{Nothing}, Nothing}`: whether verbose printing was enabled
573+ * `debug_timing::Union{Some{Nothing}, Nothing}`: whether debug timing printing was enabled
555574* `quickfail::Union{Some{Nothing}, Nothing}`: whether quick fail was enabled
556575* `list::Union{Some{Nothing}, Nothing}`: whether tests should be listed
557576* `custom::Dict{String,Any}`: a dictionary of custom arguments
@@ -560,6 +579,7 @@ Fields are
560579struct ParsedArgs
561580 jobs:: Union{Some{Int}, Nothing}
562581 verbose:: Union{Some{Nothing}, Nothing}
582+ debug_timing:: Union{Some{Nothing}, Nothing}
563583 quickfail:: Union{Some{Nothing}, Nothing}
564584 list:: Union{Some{Nothing}, Nothing}
565585
@@ -617,7 +637,8 @@ function parse_args(args; custom::Array{String} = String[])
617637 --list List all available tests.
618638 --verbose Print more information during testing.
619639 --quickfail Fail the entire run as soon as a single test errored.
620- --jobs=N Launch `N` processes to perform tests."""
640+ --jobs=N Launch `N` processes to perform tests.
641+ --debug-timing Print testset initialization timings."""
621642
622643 if ! isempty (custom)
623644 usage *= " \n\n Custom arguments:"
@@ -632,6 +653,7 @@ function parse_args(args; custom::Array{String} = String[])
632653
633654 jobs = extract_flag! (args, " --jobs" ; typ = Int)
634655 verbose = extract_flag! (args, " --verbose" )
656+ debug_timing = extract_flag! (args, " --debug-timing" )
635657 quickfail = extract_flag! (args, " --quickfail" )
636658 list = extract_flag! (args, " --list" )
637659
@@ -646,7 +668,7 @@ function parse_args(args; custom::Array{String} = String[])
646668 error (" Unknown test options `$(join (optlike_args, " " )) ` (try `--help` for usage instructions)" )
647669 end
648670
649- return ParsedArgs (jobs, verbose, quickfail, list, custom_args, args)
671+ return ParsedArgs (jobs, verbose, debug_timing, quickfail, list, custom_args, args)
650672end
651673
652674"""
@@ -844,7 +866,7 @@ function runtests(mod::Module, args::ParsedArgs;
844866 stderr . lock = print_lock
845867 end
846868
847- io_ctx = test_IOContext (stdout , stderr , print_lock, name_align)
869+ io_ctx = test_IOContext (stdout , stderr , print_lock, name_align, ! isnothing (args . debug_timing) )
848870 print_header (io_ctx, testgroupheader, workerheader)
849871
850872 status_lines_visible = Ref (0 )
@@ -1028,7 +1050,7 @@ function runtests(mod::Module, args::ParsedArgs;
10281050 result = try
10291051 Malt. remote_eval_wait (Main, wrkr. w, :(import ParallelTestRunner))
10301052 Malt. remote_call_fetch (invokelatest, wrkr. w, runtest,
1031- testsuite[test], test, init_code)
1053+ testsuite[test], test, init_code, test_t0 )
10321054 catch ex
10331055 if isa (ex, InterruptException)
10341056 # the worker got interrupted, signal other tasks to stop
0 commit comments