1 /* 2 * Copyright 2011-2018 Blender Foundation 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 #ifndef __RENDER_STATS_H__ 18 #define __RENDER_STATS_H__ 19 20 #include "render/scene.h" 21 22 #include "util/util_stats.h" 23 #include "util/util_string.h" 24 #include "util/util_vector.h" 25 26 CCL_NAMESPACE_BEGIN 27 28 /* Named statistics entry, which corresponds to a size. There is no real 29 * semantic around the units of size, it just should be the same for all 30 * entries. 31 * 32 * This is a generic entry for all size-related statistics, which helps 33 * avoiding duplicating code for things like sorting. 34 */ 35 class NamedSizeEntry { 36 public: 37 NamedSizeEntry(); 38 NamedSizeEntry(const string &name, size_t size); 39 40 string name; 41 size_t size; 42 }; 43 44 class NamedTimeEntry { 45 public: 46 NamedTimeEntry(); 47 NamedTimeEntry(const string &name, double time); 48 49 string name; 50 double time; 51 }; 52 53 /* Container of named size entries. Used, for example, to store per-mesh memory 54 * usage statistics. But also keeps track of overall memory usage of the 55 * container. 56 */ 57 class NamedSizeStats { 58 public: 59 NamedSizeStats(); 60 61 /* Add entry to the statistics. */ 62 void add_entry(const NamedSizeEntry &entry); 63 64 /* Generate full human-readable report. */ 65 string full_report(int indent_level = 0); 66 67 /* Total size of all entries. */ 68 size_t total_size; 69 70 /* NOTE: Is fine to read directly, but for adding use add_entry(), which 71 * makes sure all accumulating values are properly updated. 72 */ 73 vector<NamedSizeEntry> entries; 74 }; 75 76 class NamedTimeStats { 77 public: 78 NamedTimeStats(); 79 80 /* Add entry to the statistics. */ add_entry(const NamedTimeEntry & entry)81 void add_entry(const NamedTimeEntry &entry) 82 { 83 total_time += entry.time; 84 entries.push_back(entry); 85 } 86 87 /* Generate full human-readable report. */ 88 string full_report(int indent_level = 0); 89 90 /* Total time of all entries. */ 91 double total_time; 92 93 /* NOTE: Is fine to read directly, but for adding use add_entry(), which 94 * makes sure all accumulating values are properly updated. 95 */ 96 vector<NamedTimeEntry> entries; 97 clear()98 void clear() 99 { 100 total_time = 0.0; 101 entries.clear(); 102 } 103 }; 104 105 class NamedNestedSampleStats { 106 public: 107 NamedNestedSampleStats(); 108 NamedNestedSampleStats(const string &name, uint64_t samples); 109 110 NamedNestedSampleStats &add_entry(const string &name, uint64_t samples); 111 112 /* Updates sum_samples recursively. */ 113 void update_sum(); 114 115 string full_report(int indent_level = 0, uint64_t total_samples = 0); 116 117 string name; 118 119 /* self_samples contains only the samples that this specific event got, 120 * while sum_samples also includes the samples of all sub-entries. */ 121 uint64_t self_samples, sum_samples; 122 123 vector<NamedNestedSampleStats> entries; 124 }; 125 126 /* Named entry containing both a time-sample count for objects of a type and a 127 * total count of processed items. 128 * This allows to estimate the time spent per item. */ 129 class NamedSampleCountPair { 130 public: 131 NamedSampleCountPair(const ustring &name, uint64_t samples, uint64_t hits); 132 133 ustring name; 134 uint64_t samples; 135 uint64_t hits; 136 }; 137 138 /* Contains statistics about pairs of samples and counts as described above. */ 139 class NamedSampleCountStats { 140 public: 141 NamedSampleCountStats(); 142 143 string full_report(int indent_level = 0); 144 void add(const ustring &name, uint64_t samples, uint64_t hits); 145 146 typedef unordered_map<ustring, NamedSampleCountPair, ustringHash> entry_map; 147 entry_map entries; 148 }; 149 150 /* Statistics about mesh in the render database. */ 151 class MeshStats { 152 public: 153 MeshStats(); 154 155 /* Generate full human-readable report. */ 156 string full_report(int indent_level = 0); 157 158 /* Input geometry statistics, this is what is coming as an input to render 159 * from. say, Blender. This does not include runtime or engine specific 160 * memory like BVH. 161 */ 162 NamedSizeStats geometry; 163 }; 164 165 /* Statistics about images held in memory. */ 166 class ImageStats { 167 public: 168 ImageStats(); 169 170 /* Generate full human-readable report. */ 171 string full_report(int indent_level = 0); 172 173 NamedSizeStats textures; 174 }; 175 176 /* Render process statistics. */ 177 class RenderStats { 178 public: 179 RenderStats(); 180 181 /* Return full report as string. */ 182 string full_report(); 183 184 /* Collect kernel sampling information from Stats. */ 185 void collect_profiling(Scene *scene, Profiler &prof); 186 187 bool has_profiling; 188 189 MeshStats mesh; 190 ImageStats image; 191 NamedNestedSampleStats kernel; 192 NamedSampleCountStats shaders; 193 NamedSampleCountStats objects; 194 }; 195 196 class UpdateTimeStats { 197 public: 198 /* Generate full human-readable report. */ 199 string full_report(int indent_level = 0); 200 201 NamedTimeStats times; 202 }; 203 204 class SceneUpdateStats { 205 public: 206 SceneUpdateStats(); 207 208 UpdateTimeStats geometry; 209 UpdateTimeStats image; 210 UpdateTimeStats light; 211 UpdateTimeStats object; 212 UpdateTimeStats background; 213 UpdateTimeStats bake; 214 UpdateTimeStats camera; 215 UpdateTimeStats film; 216 UpdateTimeStats integrator; 217 UpdateTimeStats osl; 218 UpdateTimeStats particles; 219 UpdateTimeStats scene; 220 UpdateTimeStats svm; 221 UpdateTimeStats tables; 222 223 string full_report(); 224 225 void clear(); 226 }; 227 228 CCL_NAMESPACE_END 229 230 #endif /* __RENDER_STATS_H__ */ 231