@@ -87,6 +87,7 @@ struct TestRecord <: AbstractTestRecord
8787 bytes:: UInt64
8888 gctime:: Float64
8989 rss:: UInt64
90+ total_time:: Float64
9091end
9192
9293function memory_usage (rec:: TestRecord )
@@ -106,6 +107,7 @@ struct TestIOContext
106107 stdout :: IO
107108 stderr :: IO
108109 color:: Bool
110+ debug_timing:: Bool
109111 lock:: ReentrantLock
110112 name_align:: Int
111113 elapsed_align:: Int
@@ -115,7 +117,7 @@ struct TestIOContext
115117 rss_align:: Int
116118end
117119
118- function test_IOContext (stdout :: IO , stderr :: IO , lock:: ReentrantLock , name_align:: Int )
120+ function test_IOContext (stdout :: IO , stderr :: IO , lock:: ReentrantLock , name_align:: Int , debug_timing :: Bool )
119121 elapsed_align = textwidth (" Time (s)" )
120122 gc_align = textwidth (" GC (s)" )
121123 percent_align = textwidth (" GC %" )
@@ -125,19 +127,26 @@ function test_IOContext(stdout::IO, stderr::IO, lock::ReentrantLock, name_align:
125127 color = get (stdout , :color , false )
126128
127129 return TestIOContext (
128- stdout , stderr , color, lock, name_align, elapsed_align, gc_align, percent_align,
130+ stdout , stderr , color, debug_timing, lock, name_align, elapsed_align, gc_align, percent_align,
129131 alloc_align, rss_align
130132 )
131133end
132134
133135function print_header (ctx:: TestIOContext , testgroupheader, workerheader)
134136 lock (ctx. lock)
135137 try
138+ # header top
136139 printstyled (ctx. stdout , " " ^ (ctx. name_align + textwidth (testgroupheader) - 3 ), " │ " )
137- printstyled (ctx. stdout , " │ ──────────────── CPU ──────────────── │\n " , color = :white )
140+ printstyled (ctx. stdout , " |" , color = :white )
141+ ctx. debug_timing && printstyled (ctx. stdout , " Init │" , color = :white )
142+ printstyled (ctx. stdout , " ──────────────── CPU ──────────────── │\n " , color = :white )
143+
144+ # header bottom
138145 printstyled (ctx. stdout , testgroupheader, color = :white )
139146 printstyled (ctx. stdout , lpad (workerheader, ctx. name_align - textwidth (testgroupheader) + 1 ), " │ " , color = :white )
140- printstyled (ctx. stdout , " Time (s) │ GC (s) │ GC % │ Alloc (MB) │ RSS (MB) │\n " , color = :white )
147+ printstyled (ctx. stdout , " Time (s) │" , color = :white )
148+ ctx. debug_timing && printstyled (ctx. stdout , " time (s) │" , color = :white )
149+ printstyled (ctx. stdout , " GC (s) │ GC % │ Alloc (MB) │ RSS (MB) │\n " , color = :white )
141150 flush (ctx. stdout )
142151 finally
143152 unlock (ctx. lock)
@@ -163,9 +172,15 @@ function print_test_finished(record::TestRecord, wrkr, test, ctx::TestIOContext)
163172 try
164173 printstyled (ctx. stdout , test, color = :white )
165174 printstyled (ctx. stdout , lpad (" ($wrkr )" , ctx. name_align - textwidth (test) + 1 , " " ), " │ " , color = :white )
166- time_str = @sprintf (" %7.2f" , record. time)
175+ time = record. time
176+ time_str = @sprintf (" %7.2f" , time)
167177 printstyled (ctx. stdout , lpad (time_str, ctx. elapsed_align, " " ), " │ " , color = :white )
168178
179+ if ctx. debug_timing
180+ init_time_str = @sprintf (" %7.2f" , record. total_time - time)
181+ printstyled (ctx. stdout , lpad (init_time_str, ctx. elapsed_align, " " ), " │ " , color = :white )
182+ end
183+
169184 gc_str = @sprintf (" %5.2f" , record. gctime)
170185 printstyled (ctx. stdout , lpad (gc_str, ctx. gc_align, " " ), " │ " , color = :white )
171186 percent_str = @sprintf (" %4.1f" , 100 * record. gctime / record. time)
@@ -191,8 +206,11 @@ function print_test_failed(record::TestRecord, wrkr, test, ctx::TestIOContext)
191206 lpad (" ($wrkr )" , ctx. name_align - textwidth (test) + 1 , " " ), " |"
192207 , color = :red
193208 )
194- time_str = @sprintf (" %7.2f" , record. time)
209+ time = record. time
210+ time_str = @sprintf (" %7.2f" , time)
195211 printstyled (ctx. stderr , lpad (time_str, ctx. elapsed_align + 1 , " " ), " │" , color = :red )
212+ init_time_str = @sprintf (" %7.2f" , record. total_time - time)
213+ printstyled (ctx. stdout , lpad (init_time_str, ctx. elapsed_align, " " ), " │ " , color = :red )
196214
197215 failed_str = " failed at $(now ()) \n "
198216 # 11 -> 3 from " | " 3x and 2 for each " " on either side
@@ -278,7 +296,7 @@ function Test.finish(ts::WorkerTestSet)
278296 return ts. wrapped_ts
279297end
280298
281- function runtest (f, name, init_code)
299+ function runtest (f, name, init_code, start_time )
282300 function inner ()
283301 # generate a temporary module to execute the tests in
284302 mod = @eval (Main, module $ (gensym (name)) end )
@@ -307,7 +325,7 @@ function runtest(f, name, init_code)
307325
308326 # process results
309327 rss = Sys. maxrss ()
310- record = TestRecord (data... , rss)
328+ record = TestRecord (data... , rss, time () - start_time )
311329
312330 GC. gc (true )
313331 return record
@@ -542,6 +560,7 @@ Fields are
542560
543561* `jobs::Union{Some{Int}, Nothing}`: the number of jobs
544562* `verbose::Union{Some{Nothing}, Nothing}`: whether verbose printing was enabled
563+ * `debug_timing::Union{Some{Nothing}, Nothing}`: whether debug timing printing was enabled
545564* `quickfail::Union{Some{Nothing}, Nothing}`: whether quick fail was enabled
546565* `list::Union{Some{Nothing}, Nothing}`: whether tests should be listed
547566* `custom::Dict{String,Any}`: a dictionary of custom arguments
@@ -550,6 +569,7 @@ Fields are
550569struct ParsedArgs
551570 jobs:: Union{Some{Int}, Nothing}
552571 verbose:: Union{Some{Nothing}, Nothing}
572+ debug_timing:: Union{Some{Nothing}, Nothing}
553573 quickfail:: Union{Some{Nothing}, Nothing}
554574 list:: Union{Some{Nothing}, Nothing}
555575
@@ -607,7 +627,8 @@ function parse_args(args; custom::Array{String} = String[])
607627 --list List all available tests.
608628 --verbose Print more information during testing.
609629 --quickfail Fail the entire run as soon as a single test errored.
610- --jobs=N Launch `N` processes to perform tests."""
630+ --jobs=N Launch `N` processes to perform tests.
631+ --debug-timing Print testset initialization timings."""
611632
612633 if ! isempty (custom)
613634 usage *= " \n\n Custom arguments:"
@@ -622,6 +643,7 @@ function parse_args(args; custom::Array{String} = String[])
622643
623644 jobs = extract_flag! (args, " --jobs" ; typ = Int)
624645 verbose = extract_flag! (args, " --verbose" )
646+ debug_timing = extract_flag! (args, " --debug-timing" )
625647 quickfail = extract_flag! (args, " --quickfail" )
626648 list = extract_flag! (args, " --list" )
627649
@@ -636,7 +658,7 @@ function parse_args(args; custom::Array{String} = String[])
636658 error (" Unknown test options `$(join (optlike_args, " " )) ` (try `--help` for usage instructions)" )
637659 end
638660
639- return ParsedArgs (jobs, verbose, quickfail, list, custom_args, args)
661+ return ParsedArgs (jobs, verbose, debug_timing, quickfail, list, custom_args, args)
640662end
641663
642664"""
@@ -836,7 +858,7 @@ function runtests(mod::Module, args::ParsedArgs;
836858 stderr . lock = print_lock
837859 end
838860
839- io_ctx = test_IOContext (stdout , stderr , print_lock, name_align)
861+ io_ctx = test_IOContext (stdout , stderr , print_lock, name_align, ! isnothing (args . debug_timing) )
840862 print_header (io_ctx, testgroupheader, workerheader)
841863
842864 status_lines_visible = Ref (0 )
@@ -1020,7 +1042,7 @@ function runtests(mod::Module, args::ParsedArgs;
10201042 result = try
10211043 Malt. remote_eval_wait (Main, wrkr. w, :(import ParallelTestRunner))
10221044 Malt. remote_call_fetch (invokelatest, wrkr. w, runtest,
1023- testsuite[test], test, init_code)
1045+ testsuite[test], test, init_code, test_t0 )
10241046 catch ex
10251047 if isa (ex, InterruptException)
10261048 # the worker got interrupted, signal other tasks to stop
0 commit comments