From b6560d9fc16d74409c001bffc37a85ba1d224475 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Tue, 24 Oct 2017 16:00:50 +0200 Subject: Depsgraph: Remove bunch of debug code Was never actually used and implementation seems to be slow: we shouldn't be doing per-node evaluation hash lookups, adds too much overhead. We can instead store statistics in the node itself, and maybe even group them somehow. Ideally such a statistics should be user-friendly so riggers and animators can see exactly what's happening. --- source/blender/depsgraph/CMakeLists.txt | 2 - source/blender/depsgraph/DEG_depsgraph_debug.h | 36 +-- source/blender/depsgraph/intern/depsgraph_debug.cc | 21 -- source/blender/depsgraph/intern/eval/deg_eval.cc | 5 - .../depsgraph/intern/eval/deg_eval_debug.cc | 250 --------------------- .../blender/depsgraph/intern/eval/deg_eval_debug.h | 79 ------- 6 files changed, 1 insertion(+), 392 deletions(-) delete mode 100644 source/blender/depsgraph/intern/eval/deg_eval_debug.cc delete mode 100644 source/blender/depsgraph/intern/eval/deg_eval_debug.h (limited to 'source') diff --git a/source/blender/depsgraph/CMakeLists.txt b/source/blender/depsgraph/CMakeLists.txt index b4509c7a61a..eae3e402850 100644 --- a/source/blender/depsgraph/CMakeLists.txt +++ b/source/blender/depsgraph/CMakeLists.txt @@ -56,7 +56,6 @@ set(SRC intern/debug/deg_debug_graphviz.cc intern/eval/deg_eval.cc intern/eval/deg_eval_copy_on_write.cc - intern/eval/deg_eval_debug.cc intern/eval/deg_eval_flush.cc intern/nodes/deg_node.cc intern/nodes/deg_node_component.cc @@ -82,7 +81,6 @@ set(SRC intern/builder/deg_builder_transitive.h intern/eval/deg_eval.h intern/eval/deg_eval_copy_on_write.h - intern/eval/deg_eval_debug.h intern/eval/deg_eval_flush.h intern/nodes/deg_node.h intern/nodes/deg_node_component.h diff --git a/source/blender/depsgraph/DEG_depsgraph_debug.h b/source/blender/depsgraph/DEG_depsgraph_debug.h index 0d19b8e1e97..63ebe21d073 100644 --- a/source/blender/depsgraph/DEG_depsgraph_debug.h +++ b/source/blender/depsgraph/DEG_depsgraph_debug.h @@ -39,45 +39,11 @@ extern "C" { #endif -struct GHash; -struct ID; - struct Depsgraph; -/* ************************************************ */ -/* Statistics */ - -typedef struct DepsgraphStatsTimes { - float duration_last; -} DepsgraphStatsTimes; - -typedef struct DepsgraphStatsComponent { - struct DepsgraphStatsComponent *next, *prev; - - char name[64]; - DepsgraphStatsTimes times; -} DepsgraphStatsComponent; - -typedef struct DepsgraphStatsID { - struct ID *id; - - DepsgraphStatsTimes times; - ListBase components; -} DepsgraphStatsID; - -typedef struct DepsgraphStats { - struct GHash *id_stats; -} DepsgraphStats; - -struct DepsgraphStats *DEG_stats(void); - -void DEG_stats_verify(void); - -struct DepsgraphStatsID *DEG_stats_id(struct ID *id); - /* ------------------------------------------------ */ -void DEG_stats_simple(const struct Depsgraph *graph, +void DEG_stats_simple(const struct Depsgraph *graph, size_t *r_outer, size_t *r_operations, size_t *r_relations); diff --git a/source/blender/depsgraph/intern/depsgraph_debug.cc b/source/blender/depsgraph/intern/depsgraph_debug.cc index 453bd2aa75f..8db8eb32b34 100644 --- a/source/blender/depsgraph/intern/depsgraph_debug.cc +++ b/source/blender/depsgraph/intern/depsgraph_debug.cc @@ -41,30 +41,9 @@ extern "C" { #include "DEG_depsgraph_debug.h" #include "DEG_depsgraph_build.h" -#include "intern/eval/deg_eval_debug.h" #include "intern/depsgraph_intern.h" #include "util/deg_util_foreach.h" -/* ************************************************ */ - -DepsgraphStats *DEG_stats(void) -{ - return DEG::DepsgraphDebug::stats; -} - -void DEG_stats_verify() -{ - DEG::DepsgraphDebug::verify_stats(); -} - -DepsgraphStatsID *DEG_stats_id(ID *id) -{ - if (!DEG::DepsgraphDebug::stats) { - return NULL; - } - return DEG::DepsgraphDebug::get_id_stats(id, false); -} - bool DEG_debug_compare(const struct Depsgraph *graph1, const struct Depsgraph *graph2) { diff --git a/source/blender/depsgraph/intern/eval/deg_eval.cc b/source/blender/depsgraph/intern/eval/deg_eval.cc index 510e0e6ebbc..f5b11785441 100644 --- a/source/blender/depsgraph/intern/eval/deg_eval.cc +++ b/source/blender/depsgraph/intern/eval/deg_eval.cc @@ -45,7 +45,6 @@ #include "atomic_ops.h" -#include "intern/eval/deg_eval_debug.h" #include "intern/eval/deg_eval_flush.h" #include "intern/nodes/deg_node.h" #include "intern/nodes/deg_node_component.h" @@ -315,15 +314,11 @@ void deg_evaluate_on_refresh(EvaluationContext *eval_ctx, } #endif - DepsgraphDebug::eval_begin(eval_ctx); - schedule_graph(task_pool, graph); BLI_task_pool_work_and_wait(task_pool); BLI_task_pool_free(task_pool); - DepsgraphDebug::eval_end(eval_ctx); - /* Clear any uncleared tags - just in case. */ deg_graph_clear_tags(graph); diff --git a/source/blender/depsgraph/intern/eval/deg_eval_debug.cc b/source/blender/depsgraph/intern/eval/deg_eval_debug.cc deleted file mode 100644 index e195fdd8ec8..00000000000 --- a/source/blender/depsgraph/intern/eval/deg_eval_debug.cc +++ /dev/null @@ -1,250 +0,0 @@ -/* - * ***** 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) 2014 Blender Foundation. - * All rights reserved. - * - * Original Author: Lukas Toenne - * Contributor(s): None Yet - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/depsgraph/intern/eval/deg_eval_debug.cc - * \ingroup depsgraph - * - * Implementation of tools for debugging the depsgraph - */ - -#include "intern/eval/deg_eval_debug.h" - -#include /* required for STREQ later on. */ - -#include "BLI_listbase.h" -#include "BLI_ghash.h" - -extern "C" { -#include "WM_api.h" -#include "WM_types.h" -} /* extern "C" */ - -#include "DEG_depsgraph_debug.h" - -#include "intern/nodes/deg_node.h" -#include "intern/nodes/deg_node_component.h" -#include "intern/nodes/deg_node_operation.h" -#include "intern/depsgraph_intern.h" - -namespace DEG { - -DepsgraphStats *DepsgraphDebug::stats = NULL; - -static string get_component_name(eDepsNode_Type type, const char *name = "") -{ - DepsNodeFactory *factory = deg_get_node_factory(type); - if (name[0] != '\0') { - return string(factory->tname()); - } - else { - return string(factory->tname()) + " | " + name; - } -} - -static void times_clear(DepsgraphStatsTimes ×) -{ - times.duration_last = 0.0f; -} - -static void times_add(DepsgraphStatsTimes ×, float time) -{ - times.duration_last += time; -} - -void DepsgraphDebug::eval_begin(const EvaluationContext *UNUSED(eval_ctx)) -{ - /* TODO(sergey): Stats are currently globally disabled. */ - /* verify_stats(); */ - reset_stats(); -} - -void DepsgraphDebug::eval_end(const EvaluationContext *UNUSED(eval_ctx)) -{ - WM_main_add_notifier(NC_SPACE | ND_SPACE_INFO_REPORT, NULL); -} - -void DepsgraphDebug::eval_step(const EvaluationContext *UNUSED(eval_ctx), - const char *message) -{ -#ifdef DEG_DEBUG_BUILD - if (deg_debug_eval_cb) - deg_debug_eval_cb(deg_debug_eval_userdata, message); -#else - (void)message; /* Ignored. */ -#endif -} - -void DepsgraphDebug::task_started(Depsgraph *graph, - const OperationDepsNode *node) -{ - if (stats) { - BLI_spin_lock(&graph->lock); - - ComponentDepsNode *comp = node->owner; - ID *id = comp->owner->id_orig; - - DepsgraphStatsID *id_stats = get_id_stats(id, true); - times_clear(id_stats->times); - - /* XXX TODO use something like: if (id->flag & ID_DEG_DETAILS) {...} */ - if (0) { - /* XXX component name usage needs cleanup! currently mixes identifier - * and description strings! - */ - DepsgraphStatsComponent *comp_stats = - get_component_stats(id, get_component_name(comp->type, - comp->name).c_str(), - true); - times_clear(comp_stats->times); - } - - BLI_spin_unlock(&graph->lock); - } -} - -void DepsgraphDebug::task_completed(Depsgraph *graph, - const OperationDepsNode *node, - double time) -{ - if (stats) { - BLI_spin_lock(&graph->lock); - - ComponentDepsNode *comp = node->owner; - ID *id = comp->owner->id_orig; - - DepsgraphStatsID *id_stats = get_id_stats(id, true); - times_add(id_stats->times, time); - - /* XXX TODO use something like: if (id->flag & ID_DEG_DETAILS) {...} */ - if (0) { - /* XXX component name usage needs cleanup! currently mixes identifier - * and description strings! - */ - DepsgraphStatsComponent *comp_stats = - get_component_stats(id, - get_component_name(comp->type, - comp->name).c_str(), - true); - times_add(comp_stats->times, time); - } - - BLI_spin_unlock(&graph->lock); - } -} - -/* ********** */ -/* Statistics */ - - -/* GHash callback */ -static void deg_id_stats_free(void *val) -{ - DepsgraphStatsID *id_stats = (DepsgraphStatsID *)val; - - if (id_stats) { - BLI_freelistN(&id_stats->components); - MEM_freeN(id_stats); - } -} - -void DepsgraphDebug::stats_init() -{ - if (!stats) { - stats = (DepsgraphStats *)MEM_callocN(sizeof(DepsgraphStats), - "Depsgraph Stats"); - stats->id_stats = BLI_ghash_new(BLI_ghashutil_ptrhash, - BLI_ghashutil_ptrcmp, - "Depsgraph ID Stats Hash"); - } -} - -void DepsgraphDebug::stats_free() -{ - if (stats) { - BLI_ghash_free(stats->id_stats, NULL, deg_id_stats_free); - MEM_freeN(stats); - stats = NULL; - } -} - -void DepsgraphDebug::verify_stats() -{ - stats_init(); -} - -void DepsgraphDebug::reset_stats() -{ - if (!stats) { - return; - } - - /* XXX this doesn't work, will immediately clear all info, - * since most depsgraph updates have none or very few updates to handle. - * - * Could consider clearing only zero-user ID blocks here - */ -// BLI_ghash_clear(stats->id_stats, NULL, deg_id_stats_free); -} - -DepsgraphStatsID *DepsgraphDebug::get_id_stats(ID *id, bool create) -{ - DepsgraphStatsID *id_stats = (DepsgraphStatsID *)BLI_ghash_lookup(stats->id_stats, id); - - if (!id_stats && create) { - id_stats = (DepsgraphStatsID *)MEM_callocN(sizeof(DepsgraphStatsID), - "Depsgraph ID Stats"); - id_stats->id = id; - - BLI_ghash_insert(stats->id_stats, id, id_stats); - } - - return id_stats; -} - -DepsgraphStatsComponent *DepsgraphDebug::get_component_stats( - DepsgraphStatsID *id_stats, - const char *name, - bool create) -{ - DepsgraphStatsComponent *comp_stats; - for (comp_stats = (DepsgraphStatsComponent *)id_stats->components.first; - comp_stats != NULL; - comp_stats = comp_stats->next) - { - if (STREQ(comp_stats->name, name)) { - break; - } - } - if (!comp_stats && create) { - comp_stats = (DepsgraphStatsComponent *)MEM_callocN(sizeof(DepsgraphStatsComponent), - "Depsgraph Component Stats"); - BLI_strncpy(comp_stats->name, name, sizeof(comp_stats->name)); - BLI_addtail(&id_stats->components, comp_stats); - } - return comp_stats; -} - -} // namespace DEG diff --git a/source/blender/depsgraph/intern/eval/deg_eval_debug.h b/source/blender/depsgraph/intern/eval/deg_eval_debug.h deleted file mode 100644 index 0bbe88cc9ca..00000000000 --- a/source/blender/depsgraph/intern/eval/deg_eval_debug.h +++ /dev/null @@ -1,79 +0,0 @@ -/* - * ***** 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) 2013 Blender Foundation. - * All rights reserved. - * - * Original Author: Joshua Leung - * Contributor(s): None Yet - * - * ***** END GPL LICENSE BLOCK ***** - */ - -/** \file blender/depsgraph/intern/eval/deg_eval_debug.h - * \ingroup depsgraph - */ - -#pragma once - -#include "intern/depsgraph_types.h" - -struct ID; -struct EvaluationContext; - -struct DepsgraphStats; -struct DepsgraphStatsID; -struct DepsgraphStatsComponent; - -namespace DEG { - -struct Depsgraph; -struct DepsgraphSettings; -struct OperationDepsNode; - -struct DepsgraphDebug { - static DepsgraphStats *stats; - - static void stats_init(); - static void stats_free(); - - static void verify_stats(); - static void reset_stats(); - - static void eval_begin(const EvaluationContext *eval_ctx); - static void eval_end(const EvaluationContext *eval_ctx); - static void eval_step(const EvaluationContext *eval_ctx, - const char *message); - - static void task_started(Depsgraph *graph, const OperationDepsNode *node); - static void task_completed(Depsgraph *graph, - const OperationDepsNode *node, - double time); - - static DepsgraphStatsID *get_id_stats(ID *id, bool create); - static DepsgraphStatsComponent *get_component_stats(DepsgraphStatsID *id_stats, - const char *name, - bool create); - static DepsgraphStatsComponent *get_component_stats(ID *id, - const char *name, - bool create) - { - return get_component_stats(get_id_stats(id, create), name, create); - } -}; - -} // namespace DEG -- cgit v1.2.3