[Bf-blender-cvs] [da4efaeb87b] master: Depsgraph: Support colored addresses in debug prints

Sergey Sharybin noreply at git.blender.org
Fri Mar 16 12:25:11 CET 2018


Commit: da4efaeb87b74f73bd5b640eb70132521a1db5cb
Author: Sergey Sharybin
Date:   Fri Mar 16 12:24:08 2018 +0100
Branches: master
https://developer.blender.org/rBda4efaeb87b74f73bd5b640eb70132521a1db5cb

Depsgraph: Support colored addresses in debug prints

Enabled with --debug-depsgraph-pretty, only works with ANSI terminals.

Thanks Bastien for review!

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

M	source/blender/blenkernel/BKE_global.h
M	source/blender/depsgraph/intern/depsgraph.cc
M	source/blender/depsgraph/intern/depsgraph_intern.h
M	source/blender/python/intern/bpy_app.c
M	source/creator/creator_args.c

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

diff --git a/source/blender/blenkernel/BKE_global.h b/source/blender/blenkernel/BKE_global.h
index fc614d0272a..832b4164613 100644
--- a/source/blender/blenkernel/BKE_global.h
+++ b/source/blender/blenkernel/BKE_global.h
@@ -127,14 +127,15 @@ enum {
 	G_DEBUG_DEPSGRAPH_TAG        = (1 << 10),  /* depsgraph tagging messages */
 	G_DEBUG_DEPSGRAPH_TIME       = (1 << 11),  /* depsgraph timing statistics and messages */
 	G_DEBUG_DEPSGRAPH_NO_THREADS = (1 << 12),  /* single threaded depsgraph */
+	G_DEBUG_DEPSGRAPH_PRETTY     = (1 << 13),  /* use pretty colors in depsgraph messages */
 	G_DEBUG_DEPSGRAPH = (G_DEBUG_DEPSGRAPH_BUILD |
 	                     G_DEBUG_DEPSGRAPH_EVAL |
 	                     G_DEBUG_DEPSGRAPH_TAG |
 	                     G_DEBUG_DEPSGRAPH_TIME),
-	G_DEBUG_SIMDATA =   (1 << 13), /* sim debug data display */
-	G_DEBUG_GPU_MEM =   (1 << 14), /* gpu memory in status bar */
-	G_DEBUG_GPU =       (1 << 15), /* gpu debug */
-	G_DEBUG_IO = (1 << 16),   /* IO Debugging (for Collada, ...)*/
+	G_DEBUG_SIMDATA =   (1 << 14), /* sim debug data display */
+	G_DEBUG_GPU_MEM =   (1 << 15), /* gpu memory in status bar */
+	G_DEBUG_GPU =       (1 << 16), /* gpu debug */
+	G_DEBUG_IO = (1 << 17),   /* IO Debugging (for Collada, ...)*/
 };
 
 #define G_DEBUG_ALL  (G_DEBUG | G_DEBUG_FFMPEG | G_DEBUG_PYTHON | G_DEBUG_EVENTS | G_DEBUG_WM | G_DEBUG_JOBS | \
diff --git a/source/blender/depsgraph/intern/depsgraph.cc b/source/blender/depsgraph/intern/depsgraph.cc
index f8e12ef45c3..66ddaa6b0d5 100644
--- a/source/blender/depsgraph/intern/depsgraph.cc
+++ b/source/blender/depsgraph/intern/depsgraph.cc
@@ -35,6 +35,8 @@
 #include "MEM_guardedalloc.h"
 
 #include "BLI_utildefines.h"
+#include "BLI_console.h"
+#include "BLI_hash.h"
 #include "BLI_ghash.h"
 #include "BLI_listbase.h"
 
@@ -458,6 +460,31 @@ void deg_editors_scene_update(Main *bmain, Scene *scene, bool updated)
 	}
 }
 
+bool deg_terminal_do_color(void)
+{
+	return (G.debug & G_DEBUG_DEPSGRAPH_PRETTY) != 0;
+}
+
+string deg_color_for_pointer(const void *pointer)
+{
+	if (!deg_terminal_do_color()) {
+		return "";
+	}
+	int r, g, b;
+	BLI_hash_pointer_to_color(pointer, &r, &g, &b);
+	char buffer[64];
+	BLI_snprintf(buffer, sizeof(buffer), TRUECOLOR_ANSI_COLOR_FORMAT, r, g, b);
+	return string(buffer);
+}
+
+string deg_color_end(void)
+{
+	if (!deg_terminal_do_color()) {
+		return "";
+	}
+	return string(TRUECOLOR_ANSI_COLOR_FINISH);
+}
+
 }  // namespace DEG
 
 /* **************** */
@@ -495,6 +522,8 @@ void DEG_editors_update_pre(Main *bmain, Scene *scene, bool time)
 	}
 }
 
+/* Evaluation and debug */
+
 void DEG_debug_print_eval(const char *function_name,
                           const char *object_name,
                           const void *object_address)
@@ -502,7 +531,12 @@ void DEG_debug_print_eval(const char *function_name,
 	if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
 		return;
 	}
-	printf("%s on %s (%p)\n", function_name, object_name, object_address);
+	printf("%s on %s %s(%p)%s\n",
+	       function_name,
+	       object_name,
+	       DEG::deg_color_for_pointer(object_address).c_str(),
+	       object_address,
+	       DEG::deg_color_end().c_str());
 }
 
 void DEG_debug_print_eval_subdata(const char *function_name,
@@ -515,11 +549,17 @@ void DEG_debug_print_eval_subdata(const char *function_name,
 	if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
 		return;
 	}
-	printf("%s on %s (%p) %s %s (%p)\n",
+	printf("%s on %s %s(%p)%s %s %s %s(%p)%s\n",
 	       function_name,
-	       object_name, object_address,
+	       object_name,
+	       DEG::deg_color_for_pointer(object_address).c_str(),
+	       object_address,
+	       DEG::deg_color_end().c_str(),
 	       subdata_comment,
-	       subdata_name, subdata_address);
+	       subdata_name,
+	       DEG::deg_color_for_pointer(subdata_address).c_str(),
+	       subdata_address,
+	       DEG::deg_color_end().c_str());
 }
 
 void DEG_debug_print_eval_subdata_index(const char *function_name,
@@ -533,11 +573,18 @@ void DEG_debug_print_eval_subdata_index(const char *function_name,
 	if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
 		return;
 	}
-	printf("%s on %s (%p) %s %s[%d] (%p)\n",
+	printf("%s on %s %s(%p)^%s %s %s[%d] %s(%p)%s\n",
 	       function_name,
-	       object_name, object_address,
+	       object_name,
+	       DEG::deg_color_for_pointer(object_address).c_str(),
+	       object_address,
+	       DEG::deg_color_end().c_str(),
 	       subdata_comment,
-	       subdata_name, subdata_index, subdata_address);
+	       subdata_name,
+	       subdata_index,
+	       DEG::deg_color_for_pointer(subdata_address).c_str(),
+	       subdata_address,
+	       DEG::deg_color_end().c_str());
 }
 
 void DEG_debug_print_eval_time(const char *function_name,
@@ -548,6 +595,11 @@ void DEG_debug_print_eval_time(const char *function_name,
 	if ((G.debug & G_DEBUG_DEPSGRAPH_EVAL) == 0) {
 		return;
 	}
-	printf("%s on %s (%p) at time %f\n",
-	       function_name, object_name, object_address, time);
+	printf("%s on %s %s(%p)%s at time %f\n",
+	       function_name,
+	       object_name,
+	       DEG::deg_color_for_pointer(object_address).c_str(),
+	       object_address,
+	       DEG::deg_color_end().c_str(),
+	       time);
 }
diff --git a/source/blender/depsgraph/intern/depsgraph_intern.h b/source/blender/depsgraph/intern/depsgraph_intern.h
index 2ac97c53db7..89432e17f87 100644
--- a/source/blender/depsgraph/intern/depsgraph_intern.h
+++ b/source/blender/depsgraph/intern/depsgraph_intern.h
@@ -116,4 +116,8 @@ void deg_editors_scene_update(struct Main *bmain, struct Scene *scene, bool upda
 		} \
 	} while (0)
 
+bool deg_terminal_do_color(void);
+string deg_color_for_pointer(const void *pointer);
+string deg_color_end(void);
+
 }  // namespace DEG
diff --git a/source/blender/python/intern/bpy_app.c b/source/blender/python/intern/bpy_app.c
index ec77dc07ba7..1e2ce372727 100644
--- a/source/blender/python/intern/bpy_app.c
+++ b/source/blender/python/intern/bpy_app.c
@@ -361,6 +361,7 @@ static PyGetSetDef bpy_app_getsets[] = {
 	{(char *)"debug_depsgraph_eval", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_DEPSGRAPH_EVAL},
 	{(char *)"debug_depsgraph_tag", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_DEPSGRAPH_TAG},
 	{(char *)"debug_depsgraph_time", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_DEPSGRAPH_TIME},
+	{(char *)"debug_depsgraph_pretty", bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_DEPSGRAPH_PRETTY},
 	{(char *)"debug_simdata",   bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_SIMDATA},
 	{(char *)"debug_gpumem",    bpy_app_debug_get, bpy_app_debug_set, (char *)bpy_app_debug_doc, (void *)G_DEBUG_GPU_MEM},
 
diff --git a/source/creator/creator_args.c b/source/creator/creator_args.c
index 04a8ae8c28f..25f8d732c58 100644
--- a/source/creator/creator_args.c
+++ b/source/creator/creator_args.c
@@ -761,6 +761,8 @@ static const char arg_handle_debug_mode_generic_set_doc_depsgraph_eval[] =
 "\n\tEnable debug messages from dependency graph related on evaluation.";
 static const char arg_handle_debug_mode_generic_set_doc_depsgraph_no_threads[] =
 "\n\tSwitch dependency graph to a single threaded evaluation.";
+static const char arg_handle_debug_mode_generic_set_doc_depsgraph_pretty[] =
+"\n\tEnable colors for dependency graph debug messages.";
 static const char arg_handle_debug_mode_generic_set_doc_gpumem[] =
 "\n\tEnable GPU memory stats in status bar.";
 
@@ -1878,6 +1880,8 @@ void main_args_setup(bContext *C, bArgs *ba, SYS_SystemHandle *syshandle)
 	            CB_EX(arg_handle_debug_mode_generic_set, depsgraph_time), (void *)G_DEBUG_DEPSGRAPH_TIME);
 	BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph-no-threads",
 	            CB_EX(arg_handle_debug_mode_generic_set, depsgraph_no_threads), (void *)G_DEBUG_DEPSGRAPH_NO_THREADS);
+	BLI_argsAdd(ba, 1, NULL, "--debug-depsgraph-pretty",
+	            CB_EX(arg_handle_debug_mode_generic_set, depsgraph_pretty), (void *)G_DEBUG_DEPSGRAPH_PRETTY);
 	BLI_argsAdd(ba, 1, NULL, "--debug-gpumem",
 	            CB_EX(arg_handle_debug_mode_generic_set, gpumem), (void *)G_DEBUG_GPU_MEM);



More information about the Bf-blender-cvs mailing list