@@ -28,9 +28,11 @@ void printUsage()
2828{
2929 SWSS_LOG_ENTER ();
3030
31- std::cout << " Usage: saidump [-t] [-h]" << std::endl;
31+ std::cout << " Usage: saidump [-t] [-g] [- h]" << std::endl;
3232 std::cout << " -t --tempView:" << std::endl;
3333 std::cout << " Dump temp view" << std::endl;
34+ std::cout << " -g --dumpGraph:" << std::endl;
35+ std::cout << " Dump current graph" << std::endl;
3436 std::cout << " -h --help:" << std::endl;
3537 std::cout << " Print out this message" << std::endl;
3638}
@@ -160,7 +162,10 @@ void print_attributes(size_t indent, const TableMap& map)
160162 }
161163}
162164
163- #define SAI_OBJECT_TYPE_PREFIX_LEN 16
165+ // colors are in HSV
166+ #define GV_ARROW_COLOR " 0.650 0.700 0.700"
167+ #define GV_ROOT_COLOR " 0.650 0.200 1.000"
168+ #define GV_NODE_COLOR " 0.650 0.500 1.000"
164169
165170void dumpGraph (const TableDump& td)
166171{
@@ -170,8 +175,8 @@ void dumpGraph(const TableDump& td)
170175 std::map<sai_object_type_t ,const sai_object_type_info_t *> typemap;
171176
172177 std::cout << " digraph \" SAI Object Dependency Graph\" {" << std::endl;
173- std::cout << " size= \" 30,12\" ; ratio = fill;" << std::endl;
174- std::cout << " node [style= filled];" << std::endl;
178+ std::cout << " size = \" 30,12\" ; ratio = fill;" << std::endl;
179+ std::cout << " node [ style = filled ];" << std::endl;
175180
176181 // build object type map first
177182
@@ -202,6 +207,8 @@ void dumpGraph(const TableDump& td)
202207 std::set<sai_object_type_t > ref;
203208 std::set<sai_object_type_t > attrref;
204209
210+ #define SAI_OBJECT_TYPE_PREFIX_LEN (sizeof (" SAI_OBJECT_TYPE_" ) - 1 )
211+
205212 for (const auto & key: td)
206213 {
207214 sai_object_meta_key_t meta_key;
@@ -231,7 +238,7 @@ void dumpGraph(const TableDump& td)
231238
232239 ss << std::string (member_info->objecttypename + SAI_OBJECT_TYPE_PREFIX_LEN) << " -> "
233240 << std::string (info->objecttypename + SAI_OBJECT_TYPE_PREFIX_LEN)
234- << " [color=\" 0.650 0.700 0.700 \" , style = dashed, penwidth=2 ]" ;
241+ << " [ color=\" " << GV_ARROW_COLOR << " \" , style = dashed, penwidth = 2 ]" ;
235242
236243 std::string link = ss.str ();
237244
@@ -261,7 +268,7 @@ void dumpGraph(const TableDump& td)
261268
262269 sai_deserialize_attr_value (field.second , *meta, attr, false );
263270
264- sai_object_list_t list = {0 , NULL };
271+ sai_object_list_t list = { 0 , NULL };
265272
266273 switch (meta->attrvaluetype )
267274 {
@@ -322,7 +329,7 @@ void dumpGraph(const TableDump& td)
322329
323330 ss << std::string (attr_oid_info->objecttypename + SAI_OBJECT_TYPE_PREFIX_LEN) << " -> "
324331 << std::string (info->objecttypename + SAI_OBJECT_TYPE_PREFIX_LEN)
325- << " [color= \" 0.650 0.700 0.700 \" ]" ;
332+ << " [ color = \" " << GV_ARROW_COLOR << " \" ]" ;
326333
327334 std::string link = ss.str ();
328335
@@ -347,36 +354,44 @@ void dumpGraph(const TableDump& td)
347354
348355 if (info->isnonobjectid )
349356 {
350- std::cout << name << " [color=plum, shape = rect];\n " ;
357+ /* non object id leafs */
358+
359+ std::cout << name << " [ color = plum, shape = rect ];\n " ;
351360 continue ;
352361 }
353362
354363 if (ref.find (ot) != ref.end () && attrref.find (ot) != attrref.end ())
355364 {
356- std::cout << name << " [color=\" 0.650 0.500 1.000\" ];\n " ;
365+ /* middle nodes */
366+
367+ std::cout << name << " [ color =\" " << GV_NODE_COLOR << " \" ];\n " ;
357368 continue ;
358369 }
359370
360371 if (ref.find (ot) != ref.end () && attrref.find (ot) == attrref.end ())
361372 {
362- std::cout << name << " [color=\" 0.355 0.563 1.000\" , shape = rect];\n " ;
373+ /* leafs */
374+
375+ std::cout << name << " [ color = palegreen, shape = rect ];\n " ;
363376 continue ;
364377 }
365378
366379 if (ref.find (ot) == ref.end () && attrref.find (ot) != attrref.end ())
367380 {
368- std::cout << name << " [color=\" 0.650 0.200 1.000\" ];\n " ;
381+ /* roots */
382+
383+ std::cout << name << " [ color = \" " << GV_ROOT_COLOR << " \" ];\n " ;
369384 continue ;
370385 }
371386
372387 /* objects which are there but not referenced nowhere for example STP */
373388
374- std::cout << name << " [color= \" 0.650 0.200 1.000 \" shape= rect];\n " ;
389+ std::cout << name << " [ color = \" " << GV_ROOT_COLOR << " \" , shape = rect ];\n " ;
375390 }
376391
377- std::cout << " SWITCH -> PORT[ dir= \" none\" , color= \" red\" , peripheries = 2, penwidth=2.0 , style = dashed ];" <<std::endl;
378- std::cout << " SWITCH [color= orange, shape = parallelogram, peripheries = 2];" <<std::endl;
379- std::cout << " PORT [color= gold, shape = diamond, peripheries=2 ];" << std::endl;
392+ std::cout << " SWITCH -> PORT [ dir = none, color = red, peripheries = 2, penwidth = 2 , style = dashed ];" << std::endl;
393+ std::cout << " SWITCH [ color = orange, fillcolor = orange, shape = parallelogram, peripheries = 2 ];" << std::endl;
394+ std::cout << " PORT [ color = gold, shape = diamond, peripheries = 2 ];" << std::endl;
380395 std::cout << " }" << std::endl;
381396}
382397
0 commit comments