Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'source/blender/depsgraph/intern/debug')
-rw-r--r--source/blender/depsgraph/intern/debug/deg_debug.cc40
-rw-r--r--source/blender/depsgraph/intern/debug/deg_debug.h33
-rw-r--r--source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc6
-rw-r--r--source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc2
-rw-r--r--source/blender/depsgraph/intern/debug/deg_time_average.h71
5 files changed, 149 insertions, 3 deletions
diff --git a/source/blender/depsgraph/intern/debug/deg_debug.cc b/source/blender/depsgraph/intern/debug/deg_debug.cc
index b811f11f721..74a042989db 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug.cc
@@ -28,10 +28,50 @@
#include "BLI_hash.h"
#include "BLI_string.h"
+#include "PIL_time_utildefines.h"
+
#include "BKE_global.h"
namespace DEG {
+DepsgraphDebug::DepsgraphDebug()
+ : flags(G.debug), is_ever_evaluated(false), graph_evaluation_start_time_(0)
+{
+}
+
+bool DepsgraphDebug::do_time_debug() const
+{
+ return ((G.debug & G_DEBUG_DEPSGRAPH_TIME) != 0);
+}
+
+void DepsgraphDebug::begin_graph_evaluation()
+{
+ if (!do_time_debug()) {
+ return;
+ }
+
+ const double current_time = PIL_check_seconds_timer();
+
+ if (is_ever_evaluated) {
+ fps_samples_.add_sample(current_time - graph_evaluation_start_time_);
+ }
+
+ graph_evaluation_start_time_ = current_time;
+}
+
+void DepsgraphDebug::end_graph_evaluation()
+{
+ if (!do_time_debug()) {
+ return;
+ }
+
+ const double graph_eval_end_time = PIL_check_seconds_timer();
+ printf("Depsgraph updated in %f seconds.\n", graph_eval_end_time - graph_evaluation_start_time_);
+ printf("Depsgraph evaluation FPS: %f\n", 1.0f / fps_samples_.get_averaged());
+
+ is_ever_evaluated = true;
+}
+
bool terminal_do_color(void)
{
return (G.debug & G_DEBUG_DEPSGRAPH_PRETTY) != 0;
diff --git a/source/blender/depsgraph/intern/debug/deg_debug.h b/source/blender/depsgraph/intern/debug/deg_debug.h
index 3e4da644641..21a802828dc 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug.h
+++ b/source/blender/depsgraph/intern/debug/deg_debug.h
@@ -24,6 +24,7 @@
#pragma once
#include "intern/depsgraph_type.h"
+#include "intern/debug/deg_time_average.h"
#include "BKE_global.h"
@@ -31,6 +32,38 @@
namespace DEG {
+class DepsgraphDebug {
+ public:
+ DepsgraphDebug();
+
+ bool do_time_debug() const;
+
+ void begin_graph_evaluation();
+ void end_graph_evaluation();
+
+ /* NOTE: Corresponds to G_DEBUG_DEPSGRAPH_* flags. */
+ int flags;
+
+ /* Name of this dependency graph (is used for debug prints, helping to distinguish graphs
+ * created for different view layer). */
+ string name;
+
+ /* Is true when dependency graph was evaluated at least once.
+ * This is NOT an indication that depsgraph is at its evaluated state. */
+ bool is_ever_evaluated;
+
+ protected:
+ /* Maximum number of counters used to calculate frame rate of depsgraph update. */
+ static const constexpr int MAX_FPS_COUNTERS = 64;
+
+ /* Point in time when last graph evaluation began.
+ * Is initialized from begin_graph_evaluation() when time debug is enabled.
+ */
+ double graph_evaluation_start_time_;
+
+ AveragedTimeSampler<MAX_FPS_COUNTERS> fps_samples_;
+};
+
#define DEG_DEBUG_PRINTF(depsgraph, type, ...) \
do { \
if (DEG_debug_flags_get(depsgraph) & G_DEBUG_DEPSGRAPH_##type) { \
diff --git a/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc b/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
index ee3959a0861..b2f2359a954 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_relations_graphviz.cc
@@ -36,6 +36,8 @@ extern "C" {
#include "DEG_depsgraph_debug.h"
#include "intern/depsgraph.h"
+#include "intern/depsgraph_relation.h"
+
#include "intern/node/deg_node_component.h"
#include "intern/node/deg_node_id.h"
#include "intern/node/deg_node_operation.h"
@@ -553,7 +555,7 @@ static void deg_debug_graphviz_graph_nodes(const DebugContext &ctx, const Depsgr
deg_debug_graphviz_node(ctx, node);
}
TimeSourceNode *time_source = graph->find_time_source();
- if (time_source != NULL) {
+ if (time_source != nullptr) {
deg_debug_graphviz_node(ctx, time_source);
}
}
@@ -570,7 +572,7 @@ static void deg_debug_graphviz_graph_relations(const DebugContext &ctx, const De
}
TimeSourceNode *time_source = graph->find_time_source();
- if (time_source != NULL) {
+ if (time_source != nullptr) {
deg_debug_graphviz_node_relations(ctx, time_source);
}
}
diff --git a/source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc b/source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc
index 4a668e817fe..c37188bc3ca 100644
--- a/source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc
+++ b/source/blender/depsgraph/intern/debug/deg_debug_stats_gnuplot.cc
@@ -156,7 +156,7 @@ void DEG_debug_stats_gnuplot(const Depsgraph *depsgraph,
const char *label,
const char *output_filename)
{
- if (depsgraph == NULL) {
+ if (depsgraph == nullptr) {
return;
}
DEG::DebugContext ctx;
diff --git a/source/blender/depsgraph/intern/debug/deg_time_average.h b/source/blender/depsgraph/intern/debug/deg_time_average.h
new file mode 100644
index 00000000000..9794e9a88c3
--- /dev/null
+++ b/source/blender/depsgraph/intern/debug/deg_time_average.h
@@ -0,0 +1,71 @@
+/*
+ * 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.
+ */
+
+/** \file
+ * \ingroup depsgraph
+ */
+
+#pragma once
+
+namespace DEG {
+
+// Utility class which takes care of calculating average of time series, such as
+// FPS counters.
+template<int MaxSamples> class AveragedTimeSampler {
+ public:
+ AveragedTimeSampler() : num_samples_(0), next_sample_index_(0)
+ {
+ }
+
+ void add_sample(double value)
+ {
+ samples_[next_sample_index_] = value;
+
+ // Move to the next index, keeping wrapping at the end of array into account.
+ ++next_sample_index_;
+ if (next_sample_index_ == MaxSamples) {
+ next_sample_index_ = 0;
+ }
+
+ // Update number of stored samples.
+ if (num_samples_ != MaxSamples) {
+ ++num_samples_;
+ }
+ }
+
+ double get_averaged() const
+ {
+ double sum = 0.0;
+ for (int i = 0; i < num_samples_; ++i) {
+ sum += samples_[i];
+ }
+ return sum / num_samples_;
+ }
+
+ protected:
+ double samples_[MaxSamples];
+
+ // Number of samples which are actually stored in the array.
+ int num_samples_;
+
+ // Index in the samples_ array under which next sample will be stored.
+ int next_sample_index_;
+};
+
+} // namespace DEG