Skip to content

Commit

Permalink
utils/Dot_output: tentative graph reduction
Browse files Browse the repository at this point in the history
  • Loading branch information
pveber committed Jan 8, 2019
1 parent f7aa79f commit 019bac3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
31 changes: 28 additions & 3 deletions lib/utils/dot_output.ml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,30 @@ module G = struct
add_edge_e acc e
)

let is_path (W.Any w) =
match w with
| Plugin _ -> true
| Shell _ -> true
| Input _ -> true
| Select _ -> true
| Pure _ -> false
| App _ -> false
| Eval_path _ -> false
| Both _ -> false
| List _ -> false
| Spawn _ -> false
| List_nth _ -> false
| Glob _ -> false


let reduce_to_paths g =
let foreach_vertex v acc =
if is_path v then acc else (
let f p acc = fold_succ (fun s acc -> add_edge acc p s) g p acc in
fold_pred f g v (remove_vertex g v)
)
in
fold_vertex foreach_vertex g g
end


Expand Down Expand Up @@ -147,12 +171,13 @@ let dot_output ?db oc g ~needed =
*
* let create path = new logger path *)

let workflow_to_channel ?db oc w =
let workflow_to_channel ?db ?(reduce = false) oc w =
let dep_graph = G.of_workflow (Bistro.Private.reveal w) in
let dep_graph = if reduce then G.reduce_to_paths dep_graph else dep_graph in
dot_output ~needed:S.empty ?db oc dep_graph

let workflow_to_file ?db fn w =
Out_channel.with_file fn ~f:(fun oc -> workflow_to_channel ?db oc w)
let workflow_to_file ?db ?reduce fn w =
Out_channel.with_file fn ~f:(fun oc -> workflow_to_channel ?db ?reduce oc w)

let gc_state_to_channel ?condensed ?db oc gcs =
let dep_graph = G.of_gc_state ?condensed gcs in
Expand Down
2 changes: 2 additions & 0 deletions lib/utils/dot_output.mli
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ open Bistro_engine

val workflow_to_channel :
?db:Db.t ->
?reduce:bool ->
out_channel ->
_ workflow ->
unit

val workflow_to_file :
?db:Db.t ->
?reduce:bool ->
string ->
_ workflow ->
unit
Expand Down

0 comments on commit 019bac3

Please sign in to comment.