Skip to content

Commit

Permalink
Add cumulative_compile_time_ns() to return the cumulative compile tim…
Browse files Browse the repository at this point in the history
…e for a thread without stopping measurement.

```julia
julia> Base.cumulative_compile_time_ns_before()  # enable constantly measuring compilation time
0x0000000000000000

julia> @time @eval module M ; f(x) = 2+x; end
  0.006730 seconds (919 allocations: 55.212 KiB, 57.20% compilation time)
Main.M

julia> Base.cumulative_compile_time_ns()
0x00000000075246b3

julia> @time 2+2
  0.000000 seconds
4

julia> Base.cumulative_compile_time_ns()
0x0000000007fe4a46

julia> @time @eval M.f(2)
  0.003538 seconds (750 allocations: 46.247 KiB, 94.64% compilation time)
4

julia> Base.cumulative_compile_time_ns()
0x000000000831619e
```
  • Loading branch information
NHDaly committed Jul 30, 2021
1 parent d0ad20e commit a5a5111
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 0 deletions.
2 changes: 2 additions & 0 deletions base/timing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ end
# cumulative total time spent on compilation
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_compile_time_ns() = ccall(:jl_cumulative_compile_time_ns, UInt64, ())

# total time spend in garbage collection, in nanoseconds
gc_time_ns() = ccall(:jl_gc_total_hrtime, UInt64, ())
Expand Down
6 changes: 6 additions & 0 deletions src/jitlayers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ uint64_t jl_cumulative_compile_time_ns_after()
return jl_cumulative_compile_time[tid];
}

extern "C" JL_DLLEXPORT
uint64_t jl_cumulative_compile_time_ns() {
int tid = jl_threadid();
return jl_cumulative_compile_time[tid];
}

// this generates llvm code for the lambda info
// and adds the result to the jitlayers
// (and the shadow module),
Expand Down
13 changes: 13 additions & 0 deletions test/misc.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,19 @@ function timev_macro_scope()
end
@test timev_macro_scope() == 1


t1 = @async @time begin
sleep(2)
@eval module M ; f(x,y) = x+y ; end
@eval M.f(2,3)
end

t2 = @async begin
sleep(1)
@time 2 + 2
end


# interactive utilities

struct ambigconvert; end # inject a problematic `convert` method to ensure it still works
Expand Down

0 comments on commit a5a5111

Please sign in to comment.