Skip to content

Commit a4d6a67

Browse files
authored
Merge pull request #570 from m-fila/chrome_trace_names
use user given task names in chrome trace
2 parents 1a317c3 + 07cdf63 commit a4d6a67

File tree

2 files changed

+28
-4
lines changed

2 files changed

+28
-4
lines changed

Diff for: ext/JSON3Ext.jl

+27-2
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ using Dagger
1010

1111
function logs_to_chrome_trace(logs::Dict)
1212
execution_logs = Dict{Int,Any}()
13+
tid_to_uid = Dict{Int,UInt}()
14+
uid_to_name = Dict{UInt,String}()
1315
add_unknown_procs_metadata = false
1416
Dagger.logs_event_pairs(logs) do w, start_idx, finish_idx
1517
category = logs[w][:core][start_idx].category
@@ -20,9 +22,9 @@ function logs_to_chrome_trace(logs::Dict)
2022
end
2123
t_start = logs[w][:core][start_idx].timestamp / 1e3 # us
2224
t_stop = logs[w][:core][finish_idx].timestamp / 1e3 # us
23-
proc = logs[w][:id][start_idx].processor
2425
execution_logs[tid][:ts] = t_start
2526
execution_logs[tid][:dur] = t_stop - t_start
27+
proc = logs[w][:id][start_idx].processor
2628
if proc isa Dagger.ThreadProc
2729
execution_logs[tid][:pid] = proc.owner
2830
execution_logs[tid][:tid] = proc.tid # thread id
@@ -37,14 +39,37 @@ function logs_to_chrome_trace(logs::Dict)
3739
if !haskey(execution_logs, tid)
3840
execution_logs[tid] = Dict{Symbol,Any}()
3941
end
42+
# auto name
4043
fname = logs[w][:taskfuncnames][start_idx]
4144
execution_logs[tid][:name] = fname
45+
# uid-tid mapping for user task name
46+
if haskey(logs[w], :taskuidtotid)
47+
uid_tid = logs[w][:taskuidtotid][start_idx]
48+
if uid_tid !== nothing
49+
uid, tid = uid_tid::Pair{UInt,Int}
50+
tid_to_uid[tid] = uid
51+
end
52+
end
53+
elseif category == :data_annotation
54+
# user task name
55+
id = logs[w][:id][start_idx]::NamedTuple
56+
name = String(id.name)
57+
obj = id.objectid::Dagger.LoggedMutableObject
58+
objid = obj.objid
59+
uid_to_name[objid] = name
4260
end
4361
end
4462
events = Vector{Dict{Symbol,Any}}()
45-
for (_, v) in execution_logs
63+
for (tid, v) in execution_logs
4664
v[:ph] = "X"
4765
v[:cat] = "compute"
66+
# replace auto name with user task name if present
67+
if haskey(tid_to_uid, tid)
68+
uid = tid_to_uid[tid]
69+
if haskey(uid_to_name, uid)
70+
v[:name] = uid_to_name[uid]
71+
end
72+
end
4873
push!(events, v)
4974
end
5075
if add_unknown_procs_metadata

Diff for: src/utils/logging.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ utilize for display purposes.
136136
function logs_annotate!(ctx::Context, arg, name::Union{String,Symbol})
137137
ismutable(arg) || throw(ArgumentError("Argument must be mutable to be annotated"))
138138
Dagger.TimespanLogging.timespan_start(ctx, :data_annotation, (;objectid=objectid_or_chunkid(arg), name), nothing)
139-
# TODO: Remove redundant log event
140-
Dagger.TimespanLogging.timespan_finish(ctx, :data_annotation, nothing, nothing)
139+
Dagger.TimespanLogging.timespan_finish(ctx, :data_annotation, (;objectid=objectid_or_chunkid(arg), name), nothing)
141140
end
142141
logs_annotate!(arg, name::Union{String,Symbol}) =
143142
logs_annotate!(Dagger.Sch.eager_context(), arg, name)

0 commit comments

Comments
 (0)