HTRACE-123. Fix graphviz functionality in the htrace command (cmccabe)
diff --git a/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go b/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go
index 290984e..ef7b43f 100644
--- a/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go
+++ b/htrace-core/src/go/src/org/apache/htrace/htrace/cmd.go
@@ -70,14 +70,14 @@
loadFile := app.Command("loadFile", "Write whitespace-separated JSON spans from a file to the server.")
loadFilePath := loadFile.Arg("path",
"A file containing whitespace-separated span JSON.").Required().String()
- dumpAll := app.Command("dumpAll", "Dump all spans from the htraced daemon.")
- dumpAllOutPath := dumpAll.Flag("path", "The path to dump the trace spans to.").Default("-").String()
- dumpAllLim := dumpAll.Flag("lim", "The number of spans to transfer from the server at once.").
- Default("100").Int()
loadJson := app.Command("load", "Write JSON spans from the command-line to the server.")
loadJsonArg := loadJson.Arg("json", "A JSON span to write to the server.").Required().String()
+ dumpAll := app.Command("dumpAll", "Dump all spans from the htraced daemon.")
+ dumpAllOutPath := dumpAll.Arg("path", "The path to dump the trace spans to.").Default("-").String()
+ dumpAllLim := dumpAll.Flag("lim", "The number of spans to transfer from the server at once.").
+ Default("100").Int()
graph := app.Command("graph", "Visualize span JSON as a graph.")
- graphJsonFile := graph.Flag("input", "The JSON file to load").Required().String()
+ graphJsonFile := graph.Arg("input", "The JSON file to load").Required().String()
graphDotFile := graph.Flag("output",
"The path to write a GraphViz dotfile to. This file can be used as input to "+
"GraphViz, in order to generate a pretty picture. See graphviz.org for more "+
diff --git a/htrace-core/src/go/src/org/apache/htrace/htrace/graph.go b/htrace-core/src/go/src/org/apache/htrace/htrace/graph.go
index 36951de..dabf2df 100644
--- a/htrace-core/src/go/src/org/apache/htrace/htrace/graph.go
+++ b/htrace-core/src/go/src/org/apache/htrace/htrace/graph.go
@@ -52,6 +52,10 @@
if err != nil {
return err
}
+ err = writer.Flush()
+ if err != nil {
+ return err
+ }
err = file.Close()
file = nil
return err
@@ -107,6 +111,6 @@
}
}
}
- w.Printf("}")
+ w.Printf("}\n")
return w.Error()
}
diff --git a/htrace-core/src/go/src/org/apache/htrace/htrace/graph_test.go b/htrace-core/src/go/src/org/apache/htrace/htrace/graph_test.go
index 3003b3f..8698a98 100644
--- a/htrace-core/src/go/src/org/apache/htrace/htrace/graph_test.go
+++ b/htrace-core/src/go/src/org/apache/htrace/htrace/graph_test.go
@@ -76,7 +76,8 @@
"e2c7273efb280a8c" [label="ClientNamenodeProtocol#getBlockLocations"];
"6af3cc058e5d829d" -> "75d16cc5b2c07d8a";
"75d16cc5b2c07d8a" -> "e2c7273efb280a8c";
-}`
+}
+`
if w.String() != EXPECTED_STR {
t.Fatalf("Expected to get:\n%s\nGot:\n%s\n", EXPECTED_STR, w.String())
}