Depsgraph: Support colored addresses in debug prints
Enabled with --debug-depsgraph-pretty, only works with ANSI terminals. Thanks Bastien for review!
This commit is contained in:
@@ -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 | \
|
||||
|
@@ -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);
|
||||
}
|
||||
|
@@ -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
|
||||
|
@@ -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},
|
||||
|
||||
|
@@ -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);
|
||||
|
||||
|
Reference in New Issue
Block a user