Skip to content

Commit

Permalink
Simplify the new tests for measuring compilation time.
Browse files Browse the repository at this point in the history
  • Loading branch information
NHDaly committed Jul 31, 2021
1 parent 4eece51 commit 926f1a3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 4 deletions.
4 changes: 2 additions & 2 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ function gc_alloc_count(diff::GC_Diff)
diff.malloc + diff.realloc + diff.poolalloc + diff.bigalloc
end

# cumulative total time spent on compilation
# cumulative total time spent on compilation, in nanoseconds
cumulative_compile_time_ns_before() = ccall(:jl_cumulative_compile_time_ns_before, UInt64, ())
cumulative_compile_time_ns_after() = ccall(:jl_cumulative_compile_time_ns_after, UInt64, ())
# cumulative total time this thread has spent on compilation since process start.
# cumulative total time the process has spent on compilation while measurement was enabled.
cumulative_compile_time_ns() = ccall(:jl_cumulative_compile_time_ns, UInt64, ())

# total time spend in garbage collection, in nanoseconds
Expand Down
2 changes: 2 additions & 0 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ void jl_jit_globals(std::map<void *, GlobalVariable*> &globals)
extern "C" JL_DLLEXPORT
uint64_t jl_cumulative_compile_time_ns_before()
{
// Increment the flag to allow reentrant callers to `@time`.
jl_atomic_fetch_add(&jl_measure_compile_time, 1);
return jl_atomic_load(&jl_cumulative_compile_time);
}
extern "C" JL_DLLEXPORT
uint64_t jl_cumulative_compile_time_ns_after()
{
// Decrement the flag when done measuring, allowing other callers to continue measuring.
jl_atomic_fetch_add(&jl_measure_compile_time, -1);
return jl_atomic_load(&jl_cumulative_compile_time);
}
Expand Down
7 changes: 5 additions & 2 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,8 @@ function timev_macro_scope()
end
@test timev_macro_scope() == 1

before = Base.cumulative_compile_time_ns_before();

# exercise concurrent calls to `@time` for reentrant compilation time measurement.
t1 = @async @time begin
sleep(2)
Expand All @@ -274,8 +276,9 @@ t2 = @async begin
@time 2 + 2
end

# Test that the total compilation time across all threads is including at least this thread.
@test Base.process_cumulative_compile_time_ns() >= Base.cumulative_compile_time_ns()
after = Base.cumulative_compile_time_ns_after();
@test after >= before;
@test Base.cumulative_compile_time_ns() >= after;

# interactive utilities

Expand Down

0 comments on commit 926f1a3

Please sign in to comment.