Skip to content

Commit

Permalink
Add a testsuite option to snoop the compiler. [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
maleadt committed May 26, 2020
1 parent e9a7ae6 commit 555a5ef
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 4 deletions.
28 changes: 25 additions & 3 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@ if do_help
--list List all available tests.
--jobs=N Launch `N` process to perform tests.
Defaults to `Threads.nthreads()`.
--memcheck Run the tests under `cuda-memcheck`.""")
--memcheck Run the tests under `cuda-memcheck`.
--snoop=FILE Snoop on compiled methods and save to `FILE`.""")
exit(0)
end
_, jobs = extract_flag!(ARGS, "--jobs", Threads.nthreads())
do_memcheck, _ = extract_flag!(ARGS, "--memcheck")
do_snoop, snoop_path = extract_flag!(ARGS, "--snoop")

include("setup.jl") # make sure everything is precompiled

Expand Down Expand Up @@ -171,6 +173,12 @@ function addworker(X; kwargs...)
end
addworker(min(jobs, length(tests)))

# prepare to snoop on the compiler
if do_snoop
@info "Writing trace of compiled methods to '$snoop_path'"
snoop_io = open(snoop_path, "w")
end

# pretty print information about gc and mem usage
testgroupheader = "Test"
workerheader = "(Worker)"
Expand Down Expand Up @@ -285,18 +293,23 @@ try
push!(all_tasks, current_task())
while length(tests) > 0
test = popfirst!(tests)
running_tests[test] = now()
local resp
wrkr = p
dev = test=="initialization" ? nothing : pick.dev
snoop = do_snoop ? mktemp() : (nothing, nothing)

# run the test
running_tests[test] = now()
try
resp = remotecall_fetch(runtests, wrkr, test_runners[test], test, dev)
resp = remotecall_fetch(runtests, wrkr, test_runners[test], test, dev, snoop[1])
catch e
isa(e, InterruptException) && return
resp = Any[e]
end
delete!(running_tests, test)
push!(results, (test, resp))

# act on the results
if resp[1] isa Exception
print_testworker_errored(test, wrkr)

Expand All @@ -307,6 +320,15 @@ try
else
print_testworker_stats(test, wrkr, resp)
end

# aggregate the snooped compiler invocations
if do_snoop
for line in eachline(snoop[2])
println(snoop_io, line)
end
close(snoop[2])
rm(snoop[1])
end
end
if p != 1
# Free up memory =)
Expand Down
14 changes: 13 additions & 1 deletion test/setup.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,15 @@ const memcheck = haskey(ENV, "CUDA_MEMCHECK")

## entry point

function runtests(f, name, device=nothing)
function runtests(f, name, device=nothing, snoop=nothing)
old_print_setting = Test.TESTSET_PRINT_ENABLE[]
Test.TESTSET_PRINT_ENABLE[] = false

if snoop !== nothing
io = open(snoop, "w")
ccall(:jl_dump_compiles, Nothing, (Ptr{Nothing},), io.handle)
end

try
let id = myid()
wait(@spawnat 1 print_testworker_started(name, id))
Expand All @@ -30,6 +36,7 @@ function runtests(f, name, device=nothing)
ex = quote
Random.seed!(1)
CUDA.allowscalar(false)

if $device !== nothing
device!($device)
CUDA.@timed @testset $"$name" begin
Expand Down Expand Up @@ -64,6 +71,11 @@ function runtests(f, name, device=nothing)
end
vcat(collect(res_and_time_data), rss)
finally
if snoop !== nothing
ccall(:jl_dump_compiles, Nothing, (Ptr{Nothing},), C_NULL)
close(io)
end

Test.TESTSET_PRINT_ENABLE[] = old_print_setting
end
end
Expand Down

0 comments on commit 555a5ef

Please sign in to comment.