Skip to content

Commit 9ef02e4

Browse files
KristofferCtopolarityKristoffer Carlssonpchintalapudi
authored
transition @zone in Core.Compiler to directly use jl_timing (JuliaLang#58213)
This builds on the prior work from Kristoffer and Prem to implement a Julia-side `@zone` macro that interacts with the JL_TIMING system to provide profiling events to Tracy, VTune, and/or the TIMING_COUNTS back-end. This implementation includes some extra tricks to make sure that the timing block is stack-allocated, which can be important for performance if we start to use `@zone` for high-frequency events. Co-authored-by: Cody Tapscott <[email protected]> Co-authored-by: Kristoffer Carlsson <[email protected]> Co-authored-by: Prem Chintalapudi <[email protected]>
1 parent da6873d commit 9ef02e4

File tree

5 files changed

+39
-115
lines changed

5 files changed

+39
-115
lines changed

src/Compiler.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ function is_return_type(Core.@nospecialize(f))
120120
return false
121121
end
122122

123-
include("profiling.jl")
123+
include("timing.jl")
124124
include("sort.jl")
125125

126126
# We don't include some.jl, but this definition is still useful.

src/profiling.jl

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/profiling/ittapi.jl

Lines changed: 0 additions & 18 deletions
This file was deleted.

src/profiling/tracy.jl

Lines changed: 0 additions & 63 deletions
This file was deleted.

src/timing.jl

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
if ccall(:jl_timing_enabled, Cint, ()) != 0
2+
function getzonedexpr(name::Union{Symbol, String}, ex::Expr, func::Symbol, file::Symbol, line::Integer, color::Integer)
3+
event = RefValue{Ptr{Cvoid}}(C_NULL)
4+
name = QuoteNode(Symbol(name))
5+
func = QuoteNode(func)
6+
file = QuoteNode(file)
7+
8+
# XXX: This buffer must be large enough to store any jl_timing_block_t (runtime-checked)
9+
buffer = (0, 0, 0, 0, 0, 0, 0)
10+
buffer_size = Core.sizeof(buffer)
11+
return quote
12+
if $event[] === C_NULL
13+
$event[] = ccall(:_jl_timing_event_create, Ptr{Cvoid},
14+
(Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Ptr{UInt8}, Cint, Cint),
15+
:CORE_COMPILER, $name, $func, $file, $line, $color)
16+
end
17+
timing_block = RefValue($buffer)
18+
block_ptr = pointer_from_objref(timing_block)
19+
$(Expr(:gc_preserve, quote
20+
ccall(:_jl_timing_block_init, Cvoid, (Ptr{Cvoid}, Csize_t, Ptr{Cvoid}), block_ptr, $buffer_size, $event[])
21+
ccall(:_jl_timing_block_start, Cvoid, (Ptr{Cvoid},), block_ptr)
22+
$(Expr(:tryfinally,
23+
:($(Expr(:escape, ex))),
24+
quote
25+
ccall(:_jl_timing_block_end, Cvoid, (Ptr{Cvoid},), block_ptr)
26+
end
27+
))
28+
end, :timing_block))
29+
end
30+
end
31+
macro zone(name, ex::Expr)
32+
return getzonedexpr(name, ex, :unknown_julia_function, __source__.file, __source__.line, 0)
33+
end
34+
else
35+
macro zone(name, ex::Expr)
36+
return esc(ex)
37+
end
38+
end

0 commit comments

Comments
 (0)