Skip to content

Commit 27c4100

Browse files
m-filajpsamaroo
authored andcommitted
add show_logs for graphviz
1 parent 68710db commit 27c4100

File tree

2 files changed

+39
-5
lines changed

2 files changed

+39
-5
lines changed

docs/src/logging-visualization.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ converted to a `Val` for dispatch purposes
1818
(i.e. `render_logs(logs::Dict, :myrenderer)` -> `render_logs(logs, Val{:myrenderer}())`).
1919

2020
Built-in `IO` support exists for:
21+
- `show_logs(io, logs, :graphviz)` to write a Graphviz dot graph of executed tasks and their dependencies
2122
- `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)
2223

2324
Built-in rendering support exists for:

ext/GraphVizExt.jl

Lines changed: 38 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ tab20_colors = [
3838
]
3939
_default_colors = tab20_colors
4040

41+
"""
42+
Dagger.show_logs(io::IO, logs::Dict, ::Val{:graphviz}; disconnected=false,
43+
color_by=:fn, times::Bool=true, times_digits::Integer=3)
44+
45+
Write a graph of the task dependencies and data dependencies in `logs` to dot format
46+
47+
Requires the following events enabled in `enable_logging!`: `taskdeps`, `tasknames`, `taskargs`, `taskargmoves`
48+
49+
Options:
50+
- `disconnected`: If `true`, render disconnected vertices (tasks or arguments without upstream/downstream dependencies)
51+
- `color_by`: How to color tasks; if `:fn`, then color by unique function name, if `:proc`, then color by unique processor
52+
- `times`: If `true`, annotate each task with its start and finish times
53+
- `times_digits`: Number of digits to display in the time annotations
54+
- `colors`: A list of colors to use for coloring tasks
55+
- `name_to_color`: A function that maps task names to colors
56+
"""
57+
function Dagger.show_logs(io::IO, logs::Dict, ::Val{:graphviz}; disconnected=false,
58+
color_by=:fn, times::Bool=true, times_digits::Integer=3,
59+
colors=_default_colors, name_to_color=_name_to_color)
60+
dot = logs_to_dot(logs; disconnected, times, times_digits,
61+
color_by, colors, name_to_color)
62+
println(io, dot)
63+
end
64+
4165
"""
4266
Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,
4367
color_by=:fn, layout_engine="dot",
@@ -50,14 +74,26 @@ Requires the `all_task_deps` event enabled in `enable_logging!`
5074
Options:
5175
- `disconnected`: If `true`, render disconnected vertices (tasks or arguments without upstream/downstream dependencies)
5276
- `color_by`: How to color tasks; if `:fn`, then color by unique function name, if `:proc`, then color by unique processor
53-
- `layout_engine`: The layout engine to use for GraphViz
77+
- `layout_engine`: The layout engine to use for GraphViz rendering
5478
- `times`: If `true`, annotate each task with its start and finish times
5579
- `times_digits`: Number of digits to display in the time annotations
80+
- `colors`: A list of colors to use for coloring tasks
81+
- `name_to_color`: A function that maps task names to colors
5682
"""
5783
function Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,
5884
color_by=:fn, layout_engine="dot",
5985
times::Bool=true, times_digits::Integer=3,
6086
colors=_default_colors, name_to_color=_name_to_color)
87+
dot = logs_to_dot(logs; disconnected, times, times_digits,
88+
color_by, colors, name_to_color)
89+
gv = GraphViz.Graph(dot)
90+
GraphViz.layout!(gv; engine=layout_engine)
91+
return gv
92+
end
93+
94+
function logs_to_dot(logs::Dict; disconnected=false, color_by=:fn,
95+
times::Bool=true, times_digits::Integer=3,
96+
colors=_default_colors, name_to_color=_name_to_color)
6197
# Lookup all relevant task/argument dependencies and values in logs
6298
g = SimpleDiGraph()
6399

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

398434
# Generate the final graph
399435
str *= "}\n"
400-
gv = GraphViz.Graph(str)
401-
GraphViz.layout!(gv; engine=layout_engine)
402-
403-
return gv
436+
return str
404437
end
405438

406439
end

0 commit comments

Comments
 (0)