diff --git a/lang/funcs/dage/dage.go b/lang/funcs/dage/dage.go index df231a1b..5f588ac5 100644 --- a/lang/funcs/dage/dage.go +++ b/lang/funcs/dage/dage.go @@ -504,6 +504,14 @@ func (obj *Engine) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge { return fe } +// Graph returns a copy of the contained graph. +func (obj *Engine) Graph() *pgraph.Graph { + //obj.graphMutex.Lock() // XXX: should this be a RLock? + //defer obj.graphMutex.Unlock() // XXX: should this be an RUnlock? + + return obj.graph.Copy() +} + // Lock must be used before modifying the running graph. Make sure to Unlock // when done. // XXX: should Lock take a context if we want to bail mid-way? diff --git a/lang/funcs/dage/txn.go b/lang/funcs/dage/txn.go index 41a669cc..07ecd61a 100644 --- a/lang/funcs/dage/txn.go +++ b/lang/funcs/dage/txn.go @@ -510,7 +510,7 @@ func (obj *graphTxn) commit() error { //gv := &pgraph.Graphviz{ // Filename: fmt.Sprintf("/tmp/txn-graphviz-%d.dot", d), // Graphs: map[*pgraph.Graph]*pgraph.GraphvizOpts{ - // engine.graph: nil, + // obj.Graph(): nil, // }, //} //if err := gv.Exec(); err != nil { diff --git a/lang/funcs/dage/txn_test.go b/lang/funcs/dage/txn_test.go index d615eead..e406c177 100644 --- a/lang/funcs/dage/txn_test.go +++ b/lang/funcs/dage/txn_test.go @@ -115,6 +115,10 @@ func (obj *testGraphAPI) FindEdge(f1, f2 interfaces.Func) *interfaces.FuncEdge { return fe } +func (obj *testGraphAPI) Graph() *pgraph.Graph { + return obj.graph.Copy() +} + type testNullFunc struct { name string } diff --git a/lang/interfaces/func.go b/lang/interfaces/func.go index f0ec2a6b..781d839c 100644 --- a/lang/interfaces/func.go +++ b/lang/interfaces/func.go @@ -262,6 +262,9 @@ type GraphAPI interface { HasVertex(Func) bool FindEdge(Func, Func) *FuncEdge LookupEdge(*FuncEdge) (Func, Func, bool) + + // Graph returns a copy of the current graph. + Graph() *pgraph.Graph } // Txn is the interface that the engine graph API makes available so that