Skip to content

Commit

Permalink
add show_logs for graphviz
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila authored and jpsamaroo committed Aug 21, 2024
1 parent 68710db commit 27c4100
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 5 deletions.
1 change: 1 addition & 0 deletions docs/src/logging-visualization.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ converted to a `Val` for dispatch purposes
(i.e. `render_logs(logs::Dict, :myrenderer)` -> `render_logs(logs, Val{:myrenderer}())`).

Built-in `IO` support exists for:
- `show_logs(io, logs, :graphviz)` to write a Graphviz dot graph of executed tasks and their dependencies
- `show_logs(io, logs, :chrome_trace)` to write a task execution timeline in the chrome-trace format (view in [perfetto web UI](https://ui.perfetto.dev/) or `about:tracing` in a chrome-based browser)

Built-in rendering support exists for:
Expand Down
43 changes: 38 additions & 5 deletions ext/GraphVizExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,30 @@ tab20_colors = [
]
_default_colors = tab20_colors

"""
Dagger.show_logs(io::IO, logs::Dict, ::Val{:graphviz}; disconnected=false,
color_by=:fn, times::Bool=true, times_digits::Integer=3)
Write a graph of the task dependencies and data dependencies in `logs` to dot format
Requires the following events enabled in `enable_logging!`: `taskdeps`, `tasknames`, `taskargs`, `taskargmoves`
Options:
- `disconnected`: If `true`, render disconnected vertices (tasks or arguments without upstream/downstream dependencies)
- `color_by`: How to color tasks; if `:fn`, then color by unique function name, if `:proc`, then color by unique processor
- `times`: If `true`, annotate each task with its start and finish times
- `times_digits`: Number of digits to display in the time annotations
- `colors`: A list of colors to use for coloring tasks
- `name_to_color`: A function that maps task names to colors
"""
function Dagger.show_logs(io::IO, logs::Dict, ::Val{:graphviz}; disconnected=false,
color_by=:fn, times::Bool=true, times_digits::Integer=3,
colors=_default_colors, name_to_color=_name_to_color)
dot = logs_to_dot(logs; disconnected, times, times_digits,
color_by, colors, name_to_color)
println(io, dot)
end

"""
Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,
color_by=:fn, layout_engine="dot",
Expand All @@ -50,14 +74,26 @@ Requires the `all_task_deps` event enabled in `enable_logging!`
Options:
- `disconnected`: If `true`, render disconnected vertices (tasks or arguments without upstream/downstream dependencies)
- `color_by`: How to color tasks; if `:fn`, then color by unique function name, if `:proc`, then color by unique processor
- `layout_engine`: The layout engine to use for GraphViz
- `layout_engine`: The layout engine to use for GraphViz rendering
- `times`: If `true`, annotate each task with its start and finish times
- `times_digits`: Number of digits to display in the time annotations
- `colors`: A list of colors to use for coloring tasks
- `name_to_color`: A function that maps task names to colors
"""
function Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,
color_by=:fn, layout_engine="dot",
times::Bool=true, times_digits::Integer=3,
colors=_default_colors, name_to_color=_name_to_color)
dot = logs_to_dot(logs; disconnected, times, times_digits,
color_by, colors, name_to_color)
gv = GraphViz.Graph(dot)
GraphViz.layout!(gv; engine=layout_engine)
return gv
end

function logs_to_dot(logs::Dict; disconnected=false, color_by=:fn,
times::Bool=true, times_digits::Integer=3,
colors=_default_colors, name_to_color=_name_to_color)
# Lookup all relevant task/argument dependencies and values in logs
g = SimpleDiGraph()

Expand Down Expand Up @@ -397,10 +433,7 @@ function Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,

# Generate the final graph
str *= "}\n"
gv = GraphViz.Graph(str)
GraphViz.layout!(gv; engine=layout_engine)

return gv
return str
end

end

0 comments on commit 27c4100

Please sign in to comment.