From f0596bf6605b6ad2de12c94c1af47b6fbac241a8 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 16 Mar 2018 12:11:55 +0100 Subject: Hash: Add utility function to convert address to rgb values Some magic hashing, will become handy to make debug messages easier to follow. --- source/blender/blenlib/BLI_hash.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/source/blender/blenlib/BLI_hash.h b/source/blender/blenlib/BLI_hash.h index fa79481e25c..9ca7898d6b8 100644 --- a/source/blender/blenlib/BLI_hash.h +++ b/source/blender/blenlib/BLI_hash.h @@ -68,4 +68,16 @@ BLI_INLINE float BLI_hash_int_01(unsigned int k) return (float)BLI_hash_int(k) * (1.0f / (float)0xFFFFFFFF); } +BLI_INLINE void BLI_hash_pointer_to_color(const void *ptr, int *r, int *g, int *b) +{ + size_t val = (size_t)ptr; + const size_t hash_a = BLI_hash_int(val & 0x0000ffff); + const size_t hash_b = BLI_hash_int((val & 0xffff0000) >> 32); + const size_t hash = + hash_a ^ (hash_b + 0x9e3779b9 + (hash_a << 6) + (hash_a >> 2)); + *r = (hash & 0xff0000) >> 16; + *g = (hash & 0x00ff00) >> 8; + *b = hash & 0x0000ff; +} + #endif // __BLI_HASH_H__ -- cgit v1.2.3 From 295d8510afcbf2c7315d3bcbe53db583505d18f6 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 16 Mar 2018 12:16:29 +0100 Subject: Add Truecolor ANSI console constants They are used to start and end colored output in console. Use with care, it is up to you to check that console actually supports Truecolor ANSII. In thew future we can extend this to other consoles and platforms. --- source/blender/blenlib/BLI_console.h | 42 +++++++++++++++++++++++++++++++++++ source/blender/blenlib/CMakeLists.txt | 1 + 2 files changed, 43 insertions(+) create mode 100644 source/blender/blenlib/BLI_console.h diff --git a/source/blender/blenlib/BLI_console.h b/source/blender/blenlib/BLI_console.h new file mode 100644 index 00000000000..bf433f78f70 --- /dev/null +++ b/source/blender/blenlib/BLI_console.h @@ -0,0 +1,42 @@ +/* + * ***** BEGIN GPL LICENSE BLOCK ***** + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + * + * The Original Code is Copyright (C) 2018 Blender Foundation. + * All rights reserved. + * + * Contributor(s): Srrgey Sharybin. + * + * ***** END GPL LICENSE BLOCK ***** + */ + +#ifndef __BLI_CONSOLE_H__ +#define __BLI_CONSOLE_H__ + +/** \file BLI_console.h + * \ingroup bli + * \brief Set of utility functions and constants to work with consoles. + */ + +/* Format string where one could BLI_snprintf() R, G and B values + * and get proper marker to start colored output in the console. + */ +#define TRUECOLOR_ANSI_COLOR_FORMAT "\x1b[38;2;%d;%d;%dm" + +/* Marker which indicates that colored output is finished. */ +#define TRUECOLOR_ANSI_COLOR_FINISH "\x1b[0m" + +#endif /* __BLI_CONSOLE_H__ */ diff --git a/source/blender/blenlib/CMakeLists.txt b/source/blender/blenlib/CMakeLists.txt index d137de58e17..33a8379def5 100644 --- a/source/blender/blenlib/CMakeLists.txt +++ b/source/blender/blenlib/CMakeLists.txt @@ -138,6 +138,7 @@ set(SRC BLI_compiler_attrs.h BLI_compiler_compat.h BLI_compiler_typecheck.h + BLI_console.h BLI_convexhull_2d.h BLI_dial_2d.h BLI_dlrbTree.h -- cgit v1.2.3 From da4efaeb87b74f73bd5b640eb70132521a1db5cb Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Fri, 16 Mar 2018 12:24:08 +0100 Subject: Depsgraph: Support colored addresses in debug prints Enabled with --debug-depsgraph-pretty, only works with ANSI terminals. Thanks Bastien for review! --- source/blender/blenkernel/BKE_global.h | 9 +-- source/blender/depsgraph/intern/depsgraph.cc | 70 +++++++++++++++++++--- source/blender/depsgraph/intern/depsgraph_intern.h | 4 ++ source/blender/python/intern/bpy_app.c | 1 + source/creator/creator_args.c | 4 ++ 5 files changed, 75 insertions(+), 13 deletions(-) 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); -- cgit v1.2.3