38 mStringFilter = aStringFilter;
43 mLabelWordWrapper = aStringFilter;
49 dotFile.open(aOutFilePath.c_str());
51 unsigned int evaluationIndex = 0;
52 if (dotFile.is_open())
54 dotFile <<
"digraph GraphAnalyzer {" << endl;
55 dotFile <<
"\trankdir = \"LR\";" << endl;
56 dotFile <<
"\tnode[fontname=Helvetica];" << endl;
57 dotFile <<
"\t//ratio=fill; size=\"17,11\";" << endl;
58 dotFile << GetLegend() << endl;
59 for (std::list< Vertex* >::const_iterator it = mGraph.
GetVertices().begin();
63 std::string nodeName(GenerateNodeName((*it)->GetName()));
64 std::string nodeLabel(GenerateNodeLabel(nodeName, evaluationIndex++));
68 std::string exposureStyleOverride;
72 exposureStyleOverride =
"peripheries=2, ";
76 exposureStyleOverride =
"";
80 if ((*it)->GetFutureInEdges().size() > 0 && (*it)->GetFutureInEdges() == (*it)->GetOutEdges())
82 dotFile <<
"\t\"" << nodeName <<
"\" [label=\"" << nodeLabel <<
"\",style=filled, shape=box, " << exposureStyleOverride <<
"color=orange];" << endl;
85 else if ((*it)->GetOutEdges().size() == 0)
87 dotFile <<
"\t\"" << nodeName <<
"\" [label=\"" << nodeLabel <<
"\",style=filled, shape=box, " << exposureStyleOverride <<
"color=limegreen];" << endl;
90 else if ((*it)->GetInEdges().size() == 0)
92 dotFile <<
"\t\"" << nodeName <<
"\" [label=\"" << nodeLabel <<
"\",style=filled, shape=box, " << exposureStyleOverride <<
"color=lightblue];" << endl;
96 dotFile <<
"\t\"" << nodeName <<
"\" [label=\"" << nodeLabel <<
"\",style=filled, shape=box, " << exposureStyleOverride <<
"color=red];" << endl;
101 dotFile <<
"\t\"" << nodeName <<
"\" [label=\"" << nodeLabel <<
"\", color=blue];" << endl;
104 for (std::list<Vertex*>::const_iterator outIt = (*it)->GetOutEdges().begin();
105 outIt != (*it)->GetOutEdges().end();
108 dotFile <<
"\t\t\"" << nodeName <<
"\" -> \"" << GenerateNodeName((*outIt)->GetName()) <<
"\";" << endl;
111 for (std::list<Vertex*>::const_iterator outIt = (*it)->GetFutureOutEdges().begin();
112 outIt != (*it)->GetFutureOutEdges().end();
115 dotFile <<
"\t\t\"" << nodeName <<
"\" -> \"" << GenerateNodeName((*outIt)->GetName()) <<
"\" [style=dotted, color=red, constraint=false];" << endl;
119 dotFile <<
"}" << endl;
123 DG_LOG(
"GraphViz DOT file created at: %s", aOutFilePath.c_str());
130 for (std::list<Vertex*>::const_iterator vertexIt = mGraph.
GetVertices().begin();
134 DG_LOG(
"Vertex %s", GenerateNodeName((*vertexIt)->GetName()).c_str());
136 DG_LOG(
"--- VERTICES END ---");
141 for (std::list< Vertex* >::const_iterator it = mGraph.
GetVertices().begin();
147 if ((*it)->GetInEdges().size() > 1)
152 DG_LOG(
"Topic %s has two inputs and is public", (*it)->GetName());
161 std::string GraphAnalyzer::GenerateNodeName(
const char* aCompilerName)
const 163 std::string retString = std::string(aCompilerName);
166 retString = mStringFilter(retString);
172 std::string GraphAnalyzer::GenerateNodeLabel(
const std::string& aNodeName,
int aEvaluationIndex)
const 174 std::string nodeLabel(aNodeName);
176 if (mLabelWordWrapper)
178 nodeLabel = mLabelWordWrapper(nodeLabel);
181 std::ostringstream nodeLabelStream;
182 nodeLabelStream << aEvaluationIndex <<
":" << nodeLabel;
184 return nodeLabelStream.str();
187 std::string GraphAnalyzer::GetLegend()
const 189 std::string legend =
"\n" 191 "node [shape=plaintext]\n" 192 "subgraph cluster_02\n" 194 "label = \"Legend\";\n" 195 "\"Input Topic\" [label=\"[i] Input Topic\",style=filled, shape=box, color=lightblue];\n" 196 "\"Normal Topic\" [label=\"[i] Normal Topic\",style=filled, shape=box, color=red];\n" 197 "\"Public Topic\" [label=\"[i] Public Topic\",style=filled, shape=box, color=grey, peripheries=2];\n" 198 "\"Output Topic\" [label=\"[i] Output Topic\",style=filled, shape=box, color=limegreen];\n" 199 "\"Timeout Topic\" [label=\"[i] Timeout Topic\",style=filled, shape=box, color=orange];\n" 200 "\"Detector\" [label=\"[i] Detector\", shape=ellipse, color=blue];\n" 201 "\"hidden1\" [label=\"\"]\n" 202 "\"hidden2\" [label=\"\"]\n" 203 "\"Publish() dependency\" -> \"hidden1\";\n" 204 "\"FuturePublish() dependency\" -> \"hidden2\" [style=dotted, color=red];\n" const VertexPtrContainer & GetVertices() const
Implements a graph of Topics & Detectors with Input/Output APIs.
std::string WrapOnCommonEndings(const std::string &aNodeName)
Adds a \n to the input name before common suffixes.
virtual TopicStateIdType GetId() const =0
void DG_LOG(const char *aLogString,...)
void SetLabelWordWrapper(std::string(*aStringFilter)(const std::string &))
Sets a filter to insert at specific points.
GraphAnalyzer(const Graph &aGraph)
bool HasPublicConflict() const
Prints whether two detectors post to the same public Topic.
void GenerateDotFile(const std::string &aOutFilePath) const
Print to aOutFilePath a graphviz visualization of the graph.
Provide interface for a topic.
void SetStringFilter(std::string(*aStringFilter)(const std::string &))
Sets a filter to produce readable names from mangle C++ ones.
std::string GetMinimalName(const std::string &aMangledString)
Returns a readable name with redundant prefixes/suffixes removed.
void PrintVertexes() const
Prints to stdout the names of all vertices in the current order.