Skip to content

Commit

Permalink
Allow printing task backtraces via profiling peek mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
Drvi committed Oct 8, 2024
1 parent 9c63250 commit f90cdbb
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
7 changes: 6 additions & 1 deletion base/Base.jl
Original file line number Diff line number Diff line change
Expand Up @@ -590,7 +590,8 @@ end
if is_primary_base_module

# Profiling helper
# triggers printing the report and (optionally) saving a heap snapshot after a SIGINFO/SIGUSR1 profile request
# triggers printing the report and (optionally) saving a heap snapshot/printing task backtraces
# after a SIGINFO/SIGUSR1 profile request
# Needs to be in Base because Profile is no longer loaded on boot
const PROFILE_PRINT_COND = Ref{Base.AsyncCondition}()
function profile_printing_listener()
Expand All @@ -601,6 +602,10 @@ function profile_printing_listener()
profile = @something(profile, require(PkgId(UUID("9abbd945-dff8-562f-b5e8-e1ebf5ef1b79"), "Profile")))

invokelatest(profile.peek_report[])
if Base.get_bool_env("JULIA_PROFILE_PEEK_TASK_BACKTRACES", false) === true
println(stderr, "Printing Julia task backtraces...")
ccall(:jl_print_task_backtraces, Cvoid, ())
end
if Base.get_bool_env("JULIA_PROFILE_PEEK_HEAP_SNAPSHOT", false) === true
println(stderr, "Saving heap snapshot...")
fname = invokelatest(profile.take_heap_snapshot)
Expand Down
5 changes: 5 additions & 0 deletions doc/src/manual/environment-variables.md
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,11 @@ Enable debug logging for a file or module, see [`Logging`](@ref man-logging) for
Enable collecting of a heap snapshot during execution via the profiling peek mechanism.
See [Triggered During Execution](@ref).

### [`JULIA_PROFILE_PEEK_TASK_BACKTRACES`](@id JULIA_PROFILE_PEEK_TASK_BACKTRACES)

Enable printing of task backtraces via the profiling peek mechanism.
See [Triggered During Execution](@ref).

### [`JULIA_TIMING_SUBSYSTEMS`](@id JULIA_TIMING_SUBSYSTEMS)

Allows you to enable or disable zones for a specific Julia run.
Expand Down
4 changes: 2 additions & 2 deletions stdlib/Profile/docs/src/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ First, a single stack trace at the instant that the signal was thrown is shown,
followed by the profile report at the next yield point, which may be at task completion for code without yield points
e.g. tight loops.

Optionally set environment variable [`JULIA_PROFILE_PEEK_HEAP_SNAPSHOT`](@ref JULIA_PROFILE_PEEK_HEAP_SNAPSHOT) to `1` to also automatically collect a
[heap snapshot](@ref Heap-Snapshots).
Optionally set environment variable [`JULIA_PROFILE_PEEK_HEAP_SNAPSHOT`](@ref JULIA_PROFILE_PEEK_HEAP_SNAPSHOT) or [`JULIA_PROFILE_PEEK_TASK_BACKTRACES`](@ref JULIA_PROFILE_PEEK_TASK_BACKTRACES) to `1` to also automatically collect a
[heap snapshot](@ref Heap-Snapshots) or print task backtraces, respectively.

```julia-repl
julia> foo()
Expand Down

0 comments on commit f90cdbb

Please sign in to comment.