Cleanup: Naming of depsgraph
[blender.git] / source / blender / makesrna / intern / rna_depsgraph.c
1 /*
2  * ***** BEGIN GPL LICENSE BLOCK *****
3  *
4  * This program is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU General Public License
6  * as published by the Free Software Foundation; either version 2
7  * of the License, or (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software Foundation,
16  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18  * Contributor(s): Blender Foundation (2014).
19  *
20  * ***** END GPL LICENSE BLOCK *****
21  */
22
23 /** \file blender/makesrna/intern/rna_depsgraph.c
24  *  \ingroup RNA
25  */
26
27 #include <stdlib.h>
28
29 #include "BLI_utildefines.h"
30 #include "BLI_path_util.h"
31
32 #include "RNA_define.h"
33 #include "RNA_enum_types.h"
34
35 #include "rna_internal.h"
36
37 #include "DEG_depsgraph.h"
38
39 #include "BKE_depsgraph.h"
40
41 #define STATS_MAX_SIZE 16384
42
43 #ifdef RNA_RUNTIME
44
45 #include "DEG_depsgraph_build.h"
46 #include "DEG_depsgraph_debug.h"
47
48 static void rna_Depsgraph_debug_relations_graphviz(Depsgraph *depsgraph,
49                                                    const char *filename)
50 {
51         FILE *f = fopen(filename, "w");
52         if (f == NULL) {
53                 return;
54         }
55         DEG_debug_relations_graphviz(depsgraph, f, "Depsgraph");
56         fclose(f);
57 }
58
59 static void rna_Depsgraph_debug_stats_gnuplot(Depsgraph *depsgraph,
60                                               const char *filename,
61                                               const char *output_filename)
62 {
63         FILE *f = fopen(filename, "w");
64         if (f == NULL) {
65                 return;
66         }
67         DEG_debug_stats_gnuplot(depsgraph, f, "Timing Statistics", output_filename);
68         fclose(f);
69 }
70
71 static void rna_Depsgraph_debug_tag_update(Depsgraph *depsgraph)
72 {
73         DEG_graph_tag_relations_update(depsgraph);
74 }
75
76 static void rna_Depsgraph_debug_stats(Depsgraph *depsgraph, char *result)
77 {
78         size_t outer, ops, rels;
79         DEG_stats_simple(depsgraph, &outer, &ops, &rels);
80         BLI_snprintf(result, STATS_MAX_SIZE,
81                     "Approx %lu Operations, %lu Relations, %lu Outer Nodes",
82                     ops, rels, outer);
83 }
84
85 #else
86
87 static void rna_def_depsgraph(BlenderRNA *brna)
88 {
89         StructRNA *srna;
90         FunctionRNA *func;
91         PropertyRNA *parm;
92
93         srna = RNA_def_struct(brna, "Depsgraph", NULL);
94         RNA_def_struct_ui_text(srna, "Dependency Graph", "");
95
96         func = RNA_def_function(srna, "debug_relations_graphviz", "rna_Depsgraph_debug_relations_graphviz");
97         parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
98                                         "File in which to store graphviz debug output");
99         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
100
101         func = RNA_def_function(srna, "debug_stats_gnuplot", "rna_Depsgraph_debug_stats_gnuplot");
102         parm = RNA_def_string_file_path(func, "filename", NULL, FILE_MAX, "File Name",
103                                         "File in which to store graphviz debug output");
104         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
105         parm = RNA_def_string_file_path(func, "output_filename", NULL, FILE_MAX, "Output File Name",
106                                         "File name where gnuplot script will save the result");
107         RNA_def_parameter_flags(parm, 0, PARM_REQUIRED);
108
109         func = RNA_def_function(srna, "debug_tag_update", "rna_Depsgraph_debug_tag_update");
110
111         func = RNA_def_function(srna, "debug_stats", "rna_Depsgraph_debug_stats");
112         RNA_def_function_ui_description(func, "Report the number of elements in the Dependency Graph");
113         /* weak!, no way to return dynamic string type */
114         parm = RNA_def_string(func, "result", NULL, STATS_MAX_SIZE, "result", "");
115         RNA_def_parameter_flags(parm, PROP_THICK_WRAP, 0); /* needed for string return value */
116         RNA_def_function_output(func, parm);
117 }
118
119 void RNA_def_depsgraph(BlenderRNA *brna)
120 {
121         rna_def_depsgraph(brna);
122 }
123
124 #endif