Skip to content

Commit 132057c

Browse files
Profile.print: de-focus sleeping frames as gray (#57312)
1 parent b682f49 commit 132057c

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

stdlib/Profile/src/Profile.jl

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -980,13 +980,14 @@ mutable struct StackFrameTree{T} # where T <: Union{UInt64, StackFrame}
980980
flat_count::Int # number of times this frame was in the flattened representation (unlike count, this'll sum to 100% of parent)
981981
max_recur::Int # maximum number of times this frame was the *top* of the recursion in the stack
982982
count_recur::Int # sum of the number of times this frame was the *top* of the recursion in a stack (divide by count to get an average)
983+
sleeping::Bool # whether this frame was in a sleeping state
983984
down::Dict{T, StackFrameTree{T}}
984985
# construction workers:
985986
recur::Int
986987
builder_key::Vector{UInt64}
987988
builder_value::Vector{StackFrameTree{T}}
988989
up::StackFrameTree{T}
989-
StackFrameTree{T}() where {T} = new(UNKNOWN, 0, 0, 0, 0, 0, Dict{T, StackFrameTree{T}}(), 0, UInt64[], StackFrameTree{T}[])
990+
StackFrameTree{T}() where {T} = new(UNKNOWN, 0, 0, 0, 0, 0, true, Dict{T, StackFrameTree{T}}(), 0, UInt64[], StackFrameTree{T}[])
990991
end
991992

992993

@@ -1027,6 +1028,10 @@ function tree_format(frames::Vector{<:StackFrameTree}, level::Int, cols::Int, ma
10271028
base = string(base, "+", nextra, " ")
10281029
end
10291030
strcount = rpad(string(frame.count), ndigcounts, " ")
1031+
if frame.sleeping
1032+
stroverhead = styled"{gray:$(stroverhead)}"
1033+
strcount = styled"{gray:$(strcount)}"
1034+
end
10301035
if li != UNKNOWN
10311036
if li.line == li.pointer
10321037
strs[i] = string(stroverhead, "", base, strcount, " ",
@@ -1039,6 +1044,7 @@ function tree_format(frames::Vector{<:StackFrameTree}, level::Int, cols::Int, ma
10391044
else
10401045
fname = string(li.func)
10411046
end
1047+
frame.sleeping && (fname = styled"{gray:$(fname)}")
10421048
path, pkgname, filename = short_path(li.file, filenamemap)
10431049
if showpointer
10441050
fname = string(
@@ -1082,15 +1088,15 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI
10821088
skip = false
10831089
nsleeping = 0
10841090
is_task_profile = false
1091+
is_sleeping = true
10851092
for i in startframe:-1:1
10861093
(startframe - 1) >= i >= (startframe - (nmeta + 1)) && continue # skip metadata (it's read ahead below) and extra block end NULL IP
10871094
ip = all[i]
10881095
if is_block_end(all, i)
10891096
# read metadata
10901097
thread_sleeping_state = all[i - META_OFFSET_SLEEPSTATE] - 1 # subtract 1 as state is incremented to avoid being equal to 0
1091-
if thread_sleeping_state == 2
1092-
is_task_profile = true
1093-
end
1098+
is_sleeping = thread_sleeping_state == 1
1099+
is_task_profile = thread_sleeping_state == 2
10941100
# cpu_cycle_clock = all[i - META_OFFSET_CPUCYCLECLOCK]
10951101
taskid = all[i - META_OFFSET_TASKID]
10961102
threadid = all[i - META_OFFSET_THREADID]
@@ -1145,6 +1151,7 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI
11451151
parent = build[j]
11461152
parent.recur += 1
11471153
parent.count_recur += 1
1154+
parent.sleeping &= is_sleeping
11481155
found = true
11491156
break
11501157
end
@@ -1164,6 +1171,7 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI
11641171
while this !== parent && (recur === :off || this.recur == 0)
11651172
this.count += 1
11661173
this.recur = 1
1174+
this.sleeping &= is_sleeping
11671175
this = this.up
11681176
end
11691177
end
@@ -1185,6 +1193,7 @@ function tree!(root::StackFrameTree{T}, all::Vector{UInt64}, lidict::Union{LineI
11851193
this.up = parent
11861194
this.count += 1
11871195
this.recur = 1
1196+
this.sleeping &= is_sleeping
11881197
end
11891198
parent = this
11901199
end

0 commit comments

Comments
 (0)