Skip to content

Commit

Permalink
simplify logging visualization dispatch (#60)
Browse files Browse the repository at this point in the history
  • Loading branch information
m-fila authored Oct 30, 2024
1 parent 241b353 commit a58ec7f
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 32 deletions.
22 changes: 8 additions & 14 deletions bin/schedule.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ using Dagger
using ArgParse
using FrameworkDemo

const logs_formats = ["graph", "trace", "gantt", "raw"]

function parse_args(raw_args)
s = ArgParseSettings()

Expand Down Expand Up @@ -58,9 +60,7 @@ end

function (@main)(raw_args)
args = parse_args(raw_args)

logging_required = !isnothing(args["logs-graph"]) || !isnothing(args["logs-trace"]) ||
!isnothing(args["logs-gantt"]) || !isnothing(args["logs-raw"])
logging_required = any(x -> !isnothing(args["logs-$x"]), logs_formats)

if logging_required
FrameworkDemo.enable_logging!()
Expand Down Expand Up @@ -88,17 +88,11 @@ function (@main)(raw_args)
fast = fast)
if logging_required
logs = FrameworkDemo.fetch_logs!()
if !isnothing(args["logs-graph"])
FrameworkDemo.save_logs_graphviz(logs, args["logs-graph"])
end
if !isnothing(args["logs-trace"])
FrameworkDemo.save_logs_chrome_trace(logs, args["logs-trace"])
end
if !isnothing(args["logs-gantt"])
FrameworkDemo.save_logs_gantt(logs, args["logs-gantt"])
end
if !isnothing(args["logs-raw"])
FrameworkDemo.save_logs_raw(logs, args["logs-raw"])
for format in logs_formats
path = args["logs-$format"]
if !isnothing(path)
FrameworkDemo.save_logs(logs, path, Symbol(format))
end
end
end

Expand Down
16 changes: 12 additions & 4 deletions src/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,15 @@ import DataFrames
import Plots
import JSON3

function save_logs_graphviz(logs, path::String)
function save_logs(logs, ::String, ::Val{T}) where {T}
throw(ArgumentError("Unsupported visualization mode: `$T`"))
end

function save_logs(logs, path::String, mode::Symbol)
return save_logs(logs, path, Val{mode}())
end

function save_logs(logs, path::String, ::Val{:graph})
if splitext(path)[2] == ".dot"
open(path, "w") do io
Dagger.show_logs(io, logs, :graphviz; color_by = :proc)
Expand All @@ -17,20 +25,20 @@ function save_logs_graphviz(logs, path::String)
end
end

function save_logs_chrome_trace(logs, path::String)
function save_logs(logs, path::String, ::Val{:trace})
open(path, "w") do io
Dagger.show_logs(io, logs, :chrome_trace)
@info "Written logs trace to $path"
end
end

function save_logs_gantt(logs, path::String)
function save_logs(logs, path::String, ::Val{:gantt})
plot = Dagger.render_logs(logs, :plots_gantt)
Plots.savefig(plot, path)
@info "Written logs gantt chart to $path"
end

function save_logs_raw(logs, path::String)
function save_logs(logs, path::String, ::Val{:raw})
if splitext(path)[2] == ".json"
open(path, "w") do io
JSON3.write(io, logs)
Expand Down
35 changes: 21 additions & 14 deletions test/visualization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,26 @@ using Graphs
using MetaGraphs

@testset "Visualization" begin
graph = joinpath(pkgdir(FrameworkDemo), "data/demo/datadeps/df.graphml") |>
FrameworkDemo.parse_graphml |> FrameworkDemo.mockup_dataflow |>
FrameworkDemo.get_execution_plan
@testset "Execution plan" begin
graph = joinpath(pkgdir(FrameworkDemo), "data/demo/datadeps/df.graphml") |>
FrameworkDemo.parse_graphml |> FrameworkDemo.mockup_dataflow |>
FrameworkDemo.get_execution_plan

@test nv(graph) == 7
@test ne(graph) == 7
has_edge(x::String, y::String) = Graphs.has_edge(graph, graph[x, :label],
graph[y, :label])
@test has_edge("ProducerA", "TransformerAB")
@test has_edge("ProducerBC", "TransformerAB")
@test has_edge("ProducerBC", "ConsumerBC")
@test has_edge("ProducerBC", "TransformerC")
@test has_edge("ProducerBC", "ConsumerCD")
@test has_edge("TransformerAB", "ConsumerE")
@test has_edge("TransformerAB", "ConsumerCD")
@test nv(graph) == 7
@test ne(graph) == 7
has_edge(x::String, y::String) = Graphs.has_edge(graph, graph[x, :label],
graph[y, :label])
@test has_edge("ProducerA", "TransformerAB")
@test has_edge("ProducerBC", "TransformerAB")
@test has_edge("ProducerBC", "ConsumerBC")
@test has_edge("ProducerBC", "TransformerC")
@test has_edge("ProducerBC", "ConsumerCD")
@test has_edge("TransformerAB", "ConsumerE")
@test has_edge("TransformerAB", "ConsumerCD")
end

@testset "Save logs" begin
@test_throws ArgumentError FrameworkDemo.save_logs(Dict{}(), tempname(),
:unsupported_format)
end
end

0 comments on commit a58ec7f

Please sign in to comment.