core: Print node types in traces
This makes it clearer when looking at output as to which types of node are involved in a particular graph.
This commit is contained in:
parent
bf619d0c9d
commit
0d289f982c
41
dag/graph.go
41
dag/graph.go
|
@ -177,6 +177,47 @@ func (g *Graph) Connect(edge Edge) {
|
||||||
s.Add(source)
|
s.Add(source)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// String outputs some human-friendly output for the graph structure.
|
||||||
|
func (g *Graph) StringWithNodeTypes() string {
|
||||||
|
var buf bytes.Buffer
|
||||||
|
|
||||||
|
// Build the list of node names and a mapping so that we can more
|
||||||
|
// easily alphabetize the output to remain deterministic.
|
||||||
|
vertices := g.Vertices()
|
||||||
|
names := make([]string, 0, len(vertices))
|
||||||
|
mapping := make(map[string]Vertex, len(vertices))
|
||||||
|
for _, v := range vertices {
|
||||||
|
name := VertexName(v)
|
||||||
|
names = append(names, name)
|
||||||
|
mapping[name] = v
|
||||||
|
}
|
||||||
|
sort.Strings(names)
|
||||||
|
|
||||||
|
// Write each node in order...
|
||||||
|
for _, name := range names {
|
||||||
|
v := mapping[name]
|
||||||
|
targets := g.downEdges[hashcode(v)]
|
||||||
|
|
||||||
|
buf.WriteString(fmt.Sprintf("%s - %T\n", name, v))
|
||||||
|
|
||||||
|
// Alphabetize dependencies
|
||||||
|
deps := make([]string, 0, targets.Len())
|
||||||
|
targetNodes := make([]Vertex, 0, targets.Len())
|
||||||
|
for _, target := range targets.List() {
|
||||||
|
deps = append(deps, VertexName(target))
|
||||||
|
targetNodes = append(targetNodes, target)
|
||||||
|
}
|
||||||
|
sort.Strings(deps)
|
||||||
|
|
||||||
|
// Write dependencies
|
||||||
|
for i, d := range deps {
|
||||||
|
buf.WriteString(fmt.Sprintf(" %s - %T\n", d, targetNodes[i]))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return buf.String()
|
||||||
|
}
|
||||||
|
|
||||||
// String outputs some human-friendly output for the graph structure.
|
// String outputs some human-friendly output for the graph structure.
|
||||||
func (g *Graph) String() string {
|
func (g *Graph) String() string {
|
||||||
var buf bytes.Buffer
|
var buf bytes.Buffer
|
||||||
|
|
|
@ -32,7 +32,7 @@ func (b *BasicGraphBuilder) Build(path []string) (*Graph, error) {
|
||||||
|
|
||||||
log.Printf(
|
log.Printf(
|
||||||
"[TRACE] Graph after step %T:\n\n%s",
|
"[TRACE] Graph after step %T:\n\n%s",
|
||||||
step, g.String())
|
step, g.StringWithNodeTypes())
|
||||||
}
|
}
|
||||||
|
|
||||||
// Validate the graph structure
|
// Validate the graph structure
|
||||||
|
|
Loading…
Reference in New Issue