Skip to content

Commit e7d69bb

Browse files
committed
logging/viz: Add docstrings
1 parent f9a9198 commit e7d69bb

File tree

4 files changed

+87
-11
lines changed

4 files changed

+87
-11
lines changed

ext/GraphVizExt.jl

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,23 @@ function pretty_time(t; digits=3)
2323
"$(r(t)) ns"
2424
end
2525
end
26+
27+
"""
28+
Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,
29+
color_by=:fn, layout_engine="dot",
30+
times::Bool=true, times_digits::Integer=3)
31+
32+
Render a graph of the task dependencies and data dependencies in `logs` using GraphViz.
33+
34+
Requires the following events enabled in `enable_logging!`: `taskdeps`, `tasknames`, `taskargs`, `taskargmoves`
35+
36+
Options:
37+
- `disconnected`: If `true`, render disconnected vertices (tasks or arguments without upstream/downstream dependencies)
38+
- `color_by`: How to color tasks; if `:fn`, then color by unique function name, if `:proc`, then color by unique processor
39+
- `layout_engine`: The layout engine to use for GraphViz
40+
- `times`: If `true`, annotate each task with its start and finish times
41+
- `times_digits`: Number of digits to display in the time annotations
42+
"""
2643
function Dagger.render_logs(logs::Dict, ::Val{:graphviz}; disconnected=false,
2744
color_by=:fn, layout_engine="dot",
2845
times::Bool=true, times_digits::Integer=3)

ext/PlotsExt.jl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,11 @@ end
6767

6868
# Implementation adapted from:
6969
# https://discourse.julialang.org/t/how-to-make-a-gantt-plot-with-plots-jl/95165/7
70+
"""
71+
Dagger.render_logs(logs::Dict, ::Val{:plots_gantt}; kwargs...)
72+
73+
Render a Gantt chart of task execution in `logs` using Plots. `kwargs` are passed to `plot` directly.
74+
"""
7075
function Dagger.render_logs(logs::Dict, ::Val{:plots_gantt}; kwargs...)
7176
df = logs_to_df(logs)
7277

src/utils/logging.jl

Lines changed: 34 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,19 @@
11
# Logging utilities
22

3+
"""
4+
enable_logging!(;kwargs...)
5+
6+
Enables logging globally for all workers. Certain core events are always enabled by this call, but additional ones may be specified via `kwargs`.
7+
8+
Extra events:
9+
- `metrics::Bool`: Enables various utilization and allocation metrics
10+
- `timeline::Bool`: Enables raw "timeline" values, which are event-specific; not recommended except for debugging
11+
- `tasknames::Bool`: Enables generating unique task names for each task
12+
- `taskdeps::Bool`: Enables reporting of upstream task dependencies (as task IDs) for each task argument
13+
- `taskargs::Bool`: Enables reporting of upstream non-task dependencies (as `objectid` hash) for each task argument
14+
- `taskargmoves::Bool`: Enables reporting of copies of upstream dependencies (as original and copy `objectid` hashes) for each task argument
15+
- `profile::Bool`: Enables profiling of task execution; not currently recommended, as it adds significant overhead
16+
"""
317
function enable_logging!(;metrics::Bool=true,
418
timeline::Bool=false,
519
tasknames::Bool=true,
@@ -37,13 +51,30 @@ function enable_logging!(;metrics::Bool=true,
3751
ml[:psat] = Dagger.Events.ProcessorSaturation()
3852
end
3953
Dagger.Sch.eager_context().log_sink = ml
54+
return
4055
end
56+
57+
"""
58+
disable_logging!()
59+
60+
Disables logging previously enabled with `enable_logging!`.
61+
"""
4162
function disable_logging!()
4263
Dagger.Sch.eager_context().log_sink = TimespanLogging.NoOpLog()
64+
return
4365
end
44-
function fetch_logs!()
45-
return TimespanLogging.get_logs!(Dagger.Sch.eager_context())
46-
end
66+
67+
"""
68+
fetch_logs!() -> Dict{Int, Dict{Symbol, Vector}}
69+
70+
Fetches and returns the currently-accumulated logs for each worker. Each entry
71+
of the outer `Dict` is keyed on worker ID, so `logs[1]` are the logs for worker
72+
`1`.
73+
74+
Consider using `show_logs` or `render_logs` to generate a renderable display of
75+
these logs.
76+
"""
77+
fetch_logs!() = TimespanLogging.get_logs!(Dagger.Sch.eager_context())
4778

4879
function logs_event_pairs(f, logs::Dict)
4980
running_events = Dict{Tuple,Int}()

src/visualization.jl

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,34 @@
11
# Printable representation
22

3-
show_logs(io::IO, t, vizmode::Symbol; options...) =
4-
show_logs(io, t, Val{vizmode}(); options...)
3+
"""
4+
show_logs(io::IO, logs, vizmode::Symbol; options...)
5+
show_logs(io::IO, t, logs, vizmode::Symbol; options...)
6+
7+
Displays the logs of a task `t` and/or logs object `logs` using the visualization mode `vizmode`, which is written to the given IO stream `io`. `options` are specific to the visualization mode.
8+
9+
---
10+
11+
show_logs(logs, vizmode::Symbol; options...)
12+
show_logs(t, logs, vizmode::Symbol; options...)
13+
14+
Returns a string representation of the logs of a task `t` and/or logs object `logs` using the visualization mode `vizmode`. `options` are specific to the visualization mode.
15+
"""
16+
function show_logs end
17+
18+
show_logs(io::IO, logs, vizmode::Symbol; options...) =
19+
show_logs(io, logs, Val{vizmode}(); options...)
520
show_logs(io::IO, t, logs, vizmode::Symbol; options...) =
621
show_logs(io, t, Val{vizmode}(); options...)
722
show_logs(io::IO, ::T, ::Val{vizmode}; options...) where {T,vizmode} =
823
throw(ArgumentError("show_logs: Task/logs type `$T` not supported for visualization mode `$(repr(vizmode))`"))
924
show_logs(io::IO, ::T, ::Logs, ::Val{vizmode}; options...) where {T,Logs,vizmode} =
1025
throw(ArgumentError("show_logs: Task type `$T` and logs type `$Logs` not supported for visualization mode `$(repr(vizmode))`"))
1126

12-
show_logs(t, vizmode::Symbol; options...) =
13-
show_logs(t, Val{vizmode}(); options...)
27+
show_logs(logs, vizmode::Symbol; options...) =
28+
show_logs(logs, Val{vizmode}(); options...)
1429
show_logs(t, logs, vizmode::Symbol; options...) =
1530
show_logs(t, logs, Val{vizmode}(); options...)
16-
function show_logs(t, ::Val{vizmode}; options...) where vizmode
31+
function show_logs(logs, ::Val{vizmode}; options...) where vizmode
1732
iob = IOBuffer()
1833
show_logs(iob, t, Val{vizmode}(); options...)
1934
return String(take!(iob))
@@ -26,10 +41,18 @@ end
2641

2742
# Displayable representation
2843

29-
render_logs(t, vizmode::Symbol; options...) =
30-
render_logs(t, Val{vizmode}(); options...)
44+
"""
45+
render_logs(logs, vizmode::Symbol; options...)
46+
render_logs(t, logs, vizmode::Symbol; options...)
47+
48+
Returns a displayable representation of the logs of a task `t` and/or logs object `logs` using the visualization mode `vizmode`. `options` are specific to the visualization mode.
49+
"""
50+
function render_logs end
51+
52+
render_logs(logs, vizmode::Symbol; options...) =
53+
render_logs(logs, Val{vizmode}(); options...)
3154
render_logs(t, logs, vizmode::Symbol; options...) =
32-
render_logs(t, Val{vizmode}(); options...)
55+
render_logs(t, logs, Val{vizmode}(); options...)
3356
render_logs(::T, ::Val{vizmode}; options...) where {T,vizmode} =
3457
throw(ArgumentError("render_logs: Task/logs type `$T` not supported for visualization mode `$(repr(vizmode))`"))
3558
render_logs(::T, ::Logs, ::Val{vizmode}; options...) where {T,Logs,vizmode} =

0 commit comments

Comments
 (0)