[Bf-blender-cvs] [e77e106] depsgraph_refactor: Depsgraph graphviz debugging: Replaced plain FILE pointer with an internal context struct.

Lukas Tönne noreply at git.blender.org
Mon Apr 14 13:52:16 CEST 2014


Commit: e77e1066357b5bd3b68ec3abd243288b3c35f125
Author: Lukas Tönne
Date:   Sun Apr 13 12:22:33 2014 +0200
https://developer.blender.org/rBe77e1066357b5bd3b68ec3abd243288b3c35f125

Depsgraph graphviz debugging: Replaced plain FILE pointer with an
internal context struct.

This allows passing along several options, flags, etc. without too many
parameters in all the functions, and possibly tweaking the common
fprintf calls.

===================================================================

M	source/blender/depsgraph/intern/depsgraph_debug.cpp

===================================================================

diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cpp b/source/blender/depsgraph/intern/depsgraph_debug.cpp
index 38f17db..d92b765 100644
--- a/source/blender/depsgraph/intern/depsgraph_debug.cpp
+++ b/source/blender/depsgraph/intern/depsgraph_debug.cpp
@@ -87,15 +87,6 @@ static const int deg_debug_node_type_color_map[][2] = {
     {-1,                         0}
 };
 
-static int deg_debug_node_type_color_index(eDepsNode_Type type)
-{
-	const int (*pair)[2];
-	for (pair = deg_debug_node_type_color_map; (*pair)[0] >= 0; ++pair)
-		if ((*pair)[0] == type)
-			return (*pair)[1];
-	return -1;
-}
-
 static const int deg_debug_relation_type_color_map[][2] = {
     {DEPSREL_TYPE_STANDARD,         0},
     {DEPSREL_TYPE_ROOT_TO_ACTIVE,   1},
@@ -112,52 +103,76 @@ static const int deg_debug_relation_type_color_map[][2] = {
     {-1,                            0}
 };
 
-static void deg_debug_graphviz_legend_color(FILE *f, const char *name, const char *color)
+static int deg_debug_node_type_color_index(eDepsNode_Type type)
+{
+	const int (*pair)[2];
+	for (pair = deg_debug_node_type_color_map; (*pair)[0] >= 0; ++pair)
+		if ((*pair)[0] == type)
+			return (*pair)[1];
+	return -1;
+}
+
+struct DebugContext {
+	FILE *file;
+	bool show_tags;
+};
+
+static void deg_debug_printf(const DebugContext &ctx, const char *fmt, ...)
 {
-	fprintf(f, "<TR>");
-	fprintf(f, "<TD>%s</TD>", name);
-	fprintf(f, "<TD BGCOLOR=\"%s\"></TD>", color);
-	fprintf(f, "</TR>" NL);
+	va_list args;
+	va_start(args, fmt);
+	
+	vfprintf(ctx.file, fmt, args);
+	
+	va_end(args);
+}
+
+static void deg_debug_graphviz_legend_color(const DebugContext &ctx, const char *name, const char *color)
+{
+	deg_debug_printf(ctx, "<TR>");
+	deg_debug_printf(ctx, "<TD>%s</TD>", name);
+	deg_debug_printf(ctx, "<TD BGCOLOR=\"%s\"></TD>", color);
+	deg_debug_printf(ctx, "</TR>" NL);
 }
 
 #if 0
-static void deg_debug_graphviz_legend_line(FILE *f, const char *name, const char *color, const char *style)
+static void deg_debug_graphviz_legend_line(const DebugContext &ctx, const char *name, const char *color, const char *style)
 {
 	/* XXX TODO */
-	fprintf(f, "" NL);
+	deg_debug_printf(ctx, "" NL);
 }
 
-static void deg_debug_graphviz_legend_cluster(FILE *f, const char *name, const char *color, const char *style)
+static void deg_debug_graphviz_legend_cluster(const DebugContext &ctx, const char *name, const char *color, const char *style)
 {
-	fprintf(f, "<TR>");
-	fprintf(f, "<TD>%s</TD>", name);
-	fprintf(f, "<TD CELLPADDING=\"4\"><TABLE BORDER=\"1\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">");
-	fprintf(f, "<TR><TD BGCOLOR=\"%s\"></TD></TR>", color);
-	fprintf(f, "</TABLE></TD>");
-	fprintf(f, "</TR>" NL);
+	deg_debug_printf(ctx, "<TR>");
+	deg_debug_printf(ctx, "<TD>%s</TD>", name);
+	deg_debug_printf(ctx, "<TD CELLPADDING=\"4\"><TABLE BORDER=\"1\" CELLBORDER=\"0\" CELLSPACING=\"0\" CELLPADDING=\"0\">");
+	deg_debug_printf(ctx, "<TR><TD BGCOLOR=\"%s\"></TD></TR>", color);
+	deg_debug_printf(ctx, "</TABLE></TD>");
+	deg_debug_printf(ctx, "</TR>" NL);
 }
 #endif
 
-static void deg_debug_graphviz_legend(FILE *f)
+static void deg_debug_graphviz_legend(const DebugContext &ctx)
 {
 	const int (*pair)[2];
 	
-	fprintf(f, "{" NL);
-	fprintf(f, "rank = sink;" NL);
-	fprintf(f, "Legend [shape=none, margin=0, label=<" NL);
-	fprintf(f, "  <TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">" NL);
-	fprintf(f, "<TR><TD COLSPAN=\"2\"><B>Legend</B></TD></TR>" NL);
+	deg_debug_printf(ctx, "{" NL);
+	deg_debug_printf(ctx, "rank = sink;" NL);
+	deg_debug_printf(ctx, "Legend [shape=none, margin=0, label=<" NL);
+	deg_debug_printf(ctx, "  <TABLE BORDER=\"0\" CELLBORDER=\"1\" CELLSPACING=\"0\" CELLPADDING=\"4\">" NL);
+	deg_debug_printf(ctx, "<TR><TD COLSPAN=\"2\"><B>Legend</B></TD></TR>" NL);
 	
 	for (pair = deg_debug_node_type_color_map; (*pair)[0] >= 0; ++pair) {
 		DepsNodeFactory *nti = DEG_get_node_factory((eDepsNode_Type)(*pair)[0]);
-		deg_debug_graphviz_legend_color(f, nti->tname().c_str(), deg_debug_colors_light[(*pair)[1] % deg_debug_max_colors]);
+		deg_debug_graphviz_legend_color(ctx, nti->tname().c_str(), deg_debug_colors_light[(*pair)[1] % deg_debug_max_colors]);
 	}
 	
-	fprintf(f, "</TABLE>" NL);
-	fprintf(f, ">" NL);
-	fprintf(f, ",fontname=\"%s\"", deg_debug_graphviz_fontname);
-	fprintf(f, "];" NL);
-	fprintf(f, "}" NL);
+	deg_debug_printf(ctx, "</TABLE>" NL);
+	deg_debug_printf(ctx, ">" NL);
+	deg_debug_printf(ctx, ",fontname=\"%s\"", deg_debug_graphviz_fontname);
+	deg_debug_printf(ctx, "];" NL);
+	deg_debug_printf(ctx, "}" NL);
 }
 
 static int deg_debug_relation_type_color_index(eDepsRelation_Type type)
@@ -169,83 +184,83 @@ static int deg_debug_relation_type_color_index(eDepsRelation_Type type)
 	return -1;
 }
 
-static void deg_debug_graphviz_node_type_color(FILE *f, const char *attr, eDepsNode_Type type)
+static void deg_debug_graphviz_node_type_color(const DebugContext &ctx, const char *attr, eDepsNode_Type type)
 {
 	const char *defaultcolor = "gainsboro";
 	int color = deg_debug_node_type_color_index(type);
 	
-	fprintf(f, "%s=", attr);
+	deg_debug_printf(ctx, "%s=", attr);
 	if (color < 0)
-		fprintf(f, "%s", defaultcolor);
+		deg_debug_printf(ctx, "%s", defaultcolor);
 	else
-		fprintf(f, "\"%s\"", deg_debug_colors_light[color % deg_debug_max_colors]);
+		deg_debug_printf(ctx, "\"%s\"", deg_debug_colors_light[color % deg_debug_max_colors]);
 }
 
-static void deg_debug_graphviz_relation_type_color(FILE *f, const char *attr, eDepsRelation_Type type)
+static void deg_debug_graphviz_relation_type_color(const DebugContext &ctx, const char *attr, eDepsRelation_Type type)
 {
 	const char *defaultcolor = "black";
 #if 0 /* disabled for now, edge colors are hardly distinguishable */
 	int color = deg_debug_relation_type_color_index(type);
 	
-	fprintf(f, "%s=", attr);
+	deg_debug_printf(ctx, "%s=", attr);
 	if (color < 0)
-		fprintf(f, "%s", defaultcolor);
+		deg_debug_printf(ctx, "%s", defaultcolor);
 	else
-		fprintf(f, "\"%s\"", deg_debug_colors_dark[color % deg_debug_max_colors]);
+		deg_debug_printf(ctx, "\"%s\"", deg_debug_colors_dark[color % deg_debug_max_colors]);
 #else
-	fprintf(f, "%s=%s", attr, defaultcolor);
+	deg_debug_printf(ctx, "%s=%s", attr, defaultcolor);
 #endif
 }
 
-static void deg_debug_graphviz_node_single(FILE *f, const void *p, const char *name, const char *style, eDepsNode_Type type)
+static void deg_debug_graphviz_node_single(const DebugContext &ctx, const void *p, const char *name, const char *style, eDepsNode_Type type)
 {
 	const char *shape = "box";
 	
-	fprintf(f, "// %s\n", name);
-	fprintf(f, "\"node_%p\"", p);
-	fprintf(f, "[");
-//	fprintf(f, "label=<<B>%s</B>>", name);
-	fprintf(f, "label=<%s>", name);
-	fprintf(f, ",fontname=\"%s\"", deg_debug_graphviz_fontname);
-	fprintf(f, ",shape=%s", shape);
-	fprintf(f, ",style=%s", style);
-	deg_debug_graphviz_node_type_color(f, ",fillcolor", type);
-	fprintf(f, "];" NL);
+	deg_debug_printf(ctx, "// %s\n", name);
+	deg_debug_printf(ctx, "\"node_%p\"", p);
+	deg_debug_printf(ctx, "[");
+//	deg_debug_printf(ctx, "label=<<B>%s</B>>", name);
+	deg_debug_printf(ctx, "label=<%s>", name);
+	deg_debug_printf(ctx, ",fontname=\"%s\"", deg_debug_graphviz_fontname);
+	deg_debug_printf(ctx, ",shape=%s", shape);
+	deg_debug_printf(ctx, ",style=%s", style);
+	deg_debug_graphviz_node_type_color(ctx, ",fillcolor", type);
+	deg_debug_printf(ctx, "];" NL);
 	
-	fprintf(f, NL);
+	deg_debug_printf(ctx, NL);
 }
 
-static void deg_debug_graphviz_node_cluster_begin(FILE *f, const void *p, const char *name, const char *style, eDepsNode_Type type)
+static void deg_debug_graphviz_node_cluster_begin(const DebugContext &ctx, const void *p, const char *name, const char *style, eDepsNode_Type type)
 {
-	fprintf(f, "// %s\n", name);
-	fprintf(f, "subgraph \"cluster_%p\" {" NL, p);
-//	fprintf(f, "label=<<B>%s</B>>;" NL, name);
-	fprintf(f, "label=<%s>;" NL, name);
-	fprintf(f, "fontname=\"%s\";" NL, deg_debug_graphviz_fontname);
-	fprintf(f, "style=%s;" NL, style);
-	deg_debug_graphviz_node_type_color(f, "fillcolor", type); fprintf(f, ";" NL);
+	deg_debug_printf(ctx, "// %s\n", name);
+	deg_debug_printf(ctx, "subgraph \"cluster_%p\" {" NL, p);
+//	deg_debug_printf(ctx, "label=<<B>%s</B>>;" NL, name);
+	deg_debug_printf(ctx, "label=<%s>;" NL, name);
+	deg_debug_printf(ctx, "fontname=\"%s\";" NL, deg_debug_graphviz_fontname);
+	deg_debug_printf(ctx, "style=%s;" NL, style);
+	deg_debug_graphviz_node_type_color(ctx, "fillcolor", type); deg_debug_printf(ctx, ";" NL);
 	
 	/* dummy node, so we can add edges between clusters */
-	fprintf(f, "\"node_%p\"", p);
-	fprintf(f, "[");
-	fprintf(f, "shape=%s", "point");
-	fprintf(f, ",style=%s", "invis");
-	fprintf(f, "];" NL);
+	deg_debug_printf(ctx, "\"node_%p\"", p);
+	deg_debug_printf(ctx, "[");
+	deg_debug_printf(ctx, "shape=%s", "point");
+	deg_debug_printf(ctx, ",style=%s", "invis");
+	deg_debug_printf(ctx, "];" NL);
 	
-	fprintf(f, NL);
+	deg_debug_printf(ctx, NL);
 }
 
-static void deg_debug_graphviz_node_cluster_end(FILE *f)
+static void deg_debug_graphviz_node_cluster_end(const DebugContext &ctx)
 {
-	fprintf(f, "}" NL);
+	deg_debug_printf(ctx, "}" NL);
 	
-	fprintf(f, NL);
+	deg_debug_printf(ctx, NL);
 }
 
-static void deg_debug_graphviz_graph_nodes(FILE *f, const Depsgraph *graph);
-static void deg_debug_graphviz_graph_relations(FILE *f, const Depsgraph *graph);
+static void deg_debug_graphviz_graph_nodes(const DebugContext &ctx, const Depsgraph *graph);
+static void deg_debug_graphviz_graph_relations(const DebugContext &ctx, const Depsgraph *graph);
 
-static void deg_debug_graphviz_node(FILE *f, const DepsNode *node)
+static void deg_debug_graphviz_node(const DebugContext &ctx, const DepsNode *node)
 {
 	const char *style;
 	switch (node->tclass) {
@@ -264,15 +279,15 @@ static void deg_debug_graphviz_node(FILE *f, const DepsNode *node)
 		case DEPSNODE_TYPE_ID_REF: {
 			const IDDepsNode *id_node = (const IDDepsNode *)node;
 			if (id_node->components.empty()) {
-				deg_debug_graphviz_node_single(f, node, node->name.c_str(), style, node->type);
+				deg_debug_graphviz_node_single(ctx, node, node->name.c_str(), style, node->type);
 			}
 			else {
-				deg_debug

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list