1 /*
2  * This program is free software; you can redistribute it and/or
3  * modify it under the terms of the GNU General Public License
4  * as published by the Free Software Foundation; either version 2
5  * of the License, or (at your option) any later version.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * along with this program; if not, write to the Free Software Foundation,
14  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
15  *
16  * The Original Code is Copyright (C) 2013 Blender Foundation.
17  * All rights reserved.
18  */
19 
20 /** \file
21  * \ingroup depsgraph
22  */
23 
24 #include "intern/debug/deg_debug.h"
25 
26 #include "BLI_console.h"
27 #include "BLI_hash.h"
28 #include "BLI_string.h"
29 #include "BLI_utildefines.h"
30 
31 #include "PIL_time_utildefines.h"
32 
33 #include "BKE_global.h"
34 
35 namespace blender {
36 namespace deg {
37 
DepsgraphDebug()38 DepsgraphDebug::DepsgraphDebug()
39     : flags(G.debug), is_ever_evaluated(false), graph_evaluation_start_time_(0)
40 {
41 }
42 
do_time_debug() const43 bool DepsgraphDebug::do_time_debug() const
44 {
45   return ((G.debug & G_DEBUG_DEPSGRAPH_TIME) != 0);
46 }
47 
begin_graph_evaluation()48 void DepsgraphDebug::begin_graph_evaluation()
49 {
50   if (!do_time_debug()) {
51     return;
52   }
53 
54   const double current_time = PIL_check_seconds_timer();
55 
56   if (is_ever_evaluated) {
57     fps_samples_.add_sample(current_time - graph_evaluation_start_time_);
58   }
59 
60   graph_evaluation_start_time_ = current_time;
61 }
62 
end_graph_evaluation()63 void DepsgraphDebug::end_graph_evaluation()
64 {
65   if (!do_time_debug()) {
66     return;
67   }
68 
69   const double graph_eval_end_time = PIL_check_seconds_timer();
70   printf("Depsgraph updated in %f seconds.\n", graph_eval_end_time - graph_evaluation_start_time_);
71   printf("Depsgraph evaluation FPS: %f\n", 1.0f / fps_samples_.get_averaged());
72 
73   is_ever_evaluated = true;
74 }
75 
terminal_do_color(void)76 bool terminal_do_color(void)
77 {
78   return (G.debug & G_DEBUG_DEPSGRAPH_PRETTY) != 0;
79 }
80 
color_for_pointer(const void * pointer)81 string color_for_pointer(const void *pointer)
82 {
83   if (!terminal_do_color()) {
84     return "";
85   }
86   int r, g, b;
87   BLI_hash_pointer_to_color(pointer, &r, &g, &b);
88   char buffer[64];
89   BLI_snprintf(buffer, sizeof(buffer), TRUECOLOR_ANSI_COLOR_FORMAT, r, g, b);
90   return string(buffer);
91 }
92 
color_end(void)93 string color_end(void)
94 {
95   if (!terminal_do_color()) {
96     return "";
97   }
98   return string(TRUECOLOR_ANSI_COLOR_FINISH);
99 }
100 
101 }  // namespace deg
102 }  // namespace blender
103