diff --git a/base/Base.jl b/base/Base.jl index 24f07dfef6de7f..06192aea8147d4 100644 --- a/base/Base.jl +++ b/base/Base.jl @@ -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() @@ -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) diff --git a/doc/src/manual/environment-variables.md b/doc/src/manual/environment-variables.md index 2fc1dcbb2f32bc..105624222be4bf 100644 --- a/doc/src/manual/environment-variables.md +++ b/doc/src/manual/environment-variables.md @@ -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. diff --git a/stdlib/Profile/docs/src/index.md b/stdlib/Profile/docs/src/index.md index 1fbab0ea534d8f..2721036ce86861 100644 --- a/stdlib/Profile/docs/src/index.md +++ b/stdlib/Profile/docs/src/index.md @@ -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()