Skip to content

use user given task names in chrome trace #570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Aug 29, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 27 additions & 2 deletions ext/JSON3Ext.jl
Original file line number Diff line number Diff line change
@@ -10,6 +10,8 @@ using Dagger

function logs_to_chrome_trace(logs::Dict)
execution_logs = Dict{Int,Any}()
tid_to_uid = Dict{Int,UInt}()
uid_to_name = Dict{UInt,String}()
add_unknown_procs_metadata = false
Dagger.logs_event_pairs(logs) do w, start_idx, finish_idx
category = logs[w][:core][start_idx].category
@@ -20,9 +22,9 @@ function logs_to_chrome_trace(logs::Dict)
end
t_start = logs[w][:core][start_idx].timestamp / 1e3 # us
t_stop = logs[w][:core][finish_idx].timestamp / 1e3 # us
proc = logs[w][:id][start_idx].processor
execution_logs[tid][:ts] = t_start
execution_logs[tid][:dur] = t_stop - t_start
proc = logs[w][:id][start_idx].processor
if proc isa Dagger.ThreadProc
execution_logs[tid][:pid] = proc.owner
execution_logs[tid][:tid] = proc.tid # thread id
@@ -37,14 +39,37 @@ function logs_to_chrome_trace(logs::Dict)
if !haskey(execution_logs, tid)
execution_logs[tid] = Dict{Symbol,Any}()
end
# auto name
fname = logs[w][:taskfuncnames][start_idx]
execution_logs[tid][:name] = fname
# uid-tid mapping for user task name
if haskey(logs[w], :taskuidtotid)
uid_tid = logs[w][:taskuidtotid][start_idx]
if uid_tid !== nothing
uid, tid = uid_tid::Pair{UInt,Int}
tid_to_uid[tid] = uid
end
end
elseif category == :data_annotation
# user task name
id = logs[w][:id][start_idx]::NamedTuple
name = String(id.name)
obj = id.objectid::Dagger.LoggedMutableObject
objid = obj.objid
uid_to_name[objid] = name
end
end
events = Vector{Dict{Symbol,Any}}()
for (_, v) in execution_logs
for (tid, v) in execution_logs
v[:ph] = "X"
v[:cat] = "compute"
# replace auto name with user task name if present
if haskey(tid_to_uid, tid)
uid = tid_to_uid[tid]
if haskey(uid_to_name, uid)
v[:name] = uid_to_name[uid]
end
end
push!(events, v)
end
if add_unknown_procs_metadata
3 changes: 1 addition & 2 deletions src/utils/logging.jl
Original file line number Diff line number Diff line change
@@ -136,8 +136,7 @@ utilize for display purposes.
function logs_annotate!(ctx::Context, arg, name::Union{String,Symbol})
ismutable(arg) || throw(ArgumentError("Argument must be mutable to be annotated"))
Dagger.TimespanLogging.timespan_start(ctx, :data_annotation, (;objectid=objectid_or_chunkid(arg), name), nothing)
# TODO: Remove redundant log event
Dagger.TimespanLogging.timespan_finish(ctx, :data_annotation, nothing, nothing)
Dagger.TimespanLogging.timespan_finish(ctx, :data_annotation, (;objectid=objectid_or_chunkid(arg), name), nothing)
end
logs_annotate!(arg, name::Union{String,Symbol}) =
logs_annotate!(Dagger.Sch.eager_context(), arg, name)