Skip to content

Commit

Permalink
Add log_file to Context for easy plan UI
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsamaroo committed Oct 29, 2020
1 parent f2d3c53 commit 9bba6c7
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 10 deletions.
13 changes: 12 additions & 1 deletion src/compute.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,18 @@ function compute(ctx::Context, d::Thunk; options=nothing)
PLUGINS[:scheduler] = get_type(PLUGIN_CONFIGS[:scheduler])
end
scheduler = PLUGINS[:scheduler]
(scheduler).compute_dag(ctx, d; options=options)
res = (scheduler).compute_dag(ctx, d; options=options)
if ctx.log_file !== nothing
if ctx.log_sink !== LocalEventLog
logs = get_logs!(ctx.log_sink)
open(ctx.log_file, "w") do io
Dagger.show_plan(io, logs, d)
end
else
@warn "Context log_sink not set to LocalEventLog, skipping"
end
end
res
end

function debug_compute(ctx::Context, args...; profile=false, options=nothing)
Expand Down
22 changes: 13 additions & 9 deletions src/processor.jl
Original file line number Diff line number Diff line change
Expand Up @@ -235,10 +235,11 @@ default_enabled(proc::ThreadProc) = true
"A context represents a set of processors to use for an operation."
mutable struct Context
procs::Vector{Processor}
proc_lock::ReentrantLock
log_sink::Any
log_file::Union{String,Nothing}
profile::Bool
options
proc_lock::ReentrantLock
end

"""
Expand All @@ -253,16 +254,19 @@ number of threads.
It is also possible to create a Context from a vector of [`OSProc`](@ref),
or equivalently the underlying process ids can also be passed directly
as a `Vector{Int}`.
Special fields include:
- 'log_sink': A log sink object to use, if any.
- `log_file::Union{String,Nothing}`: Path to logfile. If specified, at
scheduler termination logs will be collected, combined with input thunks, and
written out in DOT format to this location.
- `profile::Bool`: Whether or not to perform profiling with Profile stdlib.
"""
function Context(xs)
Context(xs, NoOpLog(), false, nothing) # By default don't log events
end
Context(xs, log_sink, profile, options) = Context(xs, log_sink, profile, options, ReentrantLock())
Context(procs::Vector{P}=Processor[OSProc(w) for w in workers()];
proc_lock=ReentrantLock(), log_sink=NoOpLog(), log_file=nothing,
profile=false, options=nothing) where {P<:Processor} =
Context(procs, proc_lock, log_sink, log_file, profile, options)
Context(xs::Vector{Int}) = Context(map(OSProc, xs))
function Context()
procs = [OSProc(w) for w in workers()]
Context(procs)
end
procs(ctx::Context) = lock(ctx) do
copy(ctx.procs)
end
Expand Down
1 change: 1 addition & 0 deletions src/ui/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ function write_dag(io, logs::Vector, t=nothing)
c = write_node(io, arg, c, name)
push!(nodes, name)
end
arg_c += 1
end
argnodemap[id] = nodes
end
Expand Down
14 changes: 14 additions & 0 deletions test/ui.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,18 @@ end
logs = Dagger.get_logs!(log)
plan = Dagger.show_plan(logs, j)
end

@testset "Automatic Plan Rendering" begin
x = compute(rand(Blocks(2,2),4,4))
mktemp() do path, io
ctx = Context(;log_sink=Dagger.LocalEventLog(),log_file=path)
compute(ctx, x * x)
plan = String(read(io))
@test occursin("digraph {", plan)
@test occursin("Comm:", plan)
@test occursin("Move:", plan)
@test occursin("Compute:", plan)
@test endswith(plan, "}\n")
end
end
end

0 comments on commit 9bba6c7

Please sign in to comment.