stats.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. #ifndef __RENDER_STATS_H__
  17. #define __RENDER_STATS_H__
  18. #include "render/scene.h"
  19. #include "util/util_stats.h"
  20. #include "util/util_string.h"
  21. #include "util/util_vector.h"
  22. CCL_NAMESPACE_BEGIN
  23. /* Named statistics entry, which corresponds to a size. There is no real
  24. * semantic around the units of size, it just should be the same for all
  25. * entries.
  26. *
  27. * This is a generic entry foi all size-related statistics, which helps
  28. * avoiding duplicating code for things like sorting.
  29. */
  30. class NamedSizeEntry {
  31. public:
  32. NamedSizeEntry();
  33. NamedSizeEntry(const string &name, size_t size);
  34. string name;
  35. size_t size;
  36. };
  37. /* Container of named size entries. Used, for example, to store per-mesh memory
  38. * usage statistics. But also keeps track of overall memory usage of the
  39. * container.
  40. */
  41. class NamedSizeStats {
  42. public:
  43. NamedSizeStats();
  44. /* Add entry to the statistics. */
  45. void add_entry(const NamedSizeEntry &entry);
  46. /* Generate full human-readable report. */
  47. string full_report(int indent_level = 0);
  48. /* Total size of all entries. */
  49. size_t total_size;
  50. /* NOTE: Is fine to read directly, but for adding use add_entry(), which
  51. * makes sure all accumulating values are properly updated.
  52. */
  53. vector<NamedSizeEntry> entries;
  54. };
  55. class NamedNestedSampleStats {
  56. public:
  57. NamedNestedSampleStats();
  58. NamedNestedSampleStats(const string &name, uint64_t samples);
  59. NamedNestedSampleStats &add_entry(const string &name, uint64_t samples);
  60. /* Updates sum_samples recursively. */
  61. void update_sum();
  62. string full_report(int indent_level = 0, uint64_t total_samples = 0);
  63. string name;
  64. /* self_samples contains only the samples that this specific event got,
  65. * while sum_samples also includes the samples of all sub-entries. */
  66. uint64_t self_samples, sum_samples;
  67. vector<NamedNestedSampleStats> entries;
  68. };
  69. /* Named entry containing both a time-sample count for objects of a type and a
  70. * total count of processed items.
  71. * This allows to estimate the time spent per item. */
  72. class NamedSampleCountPair {
  73. public:
  74. NamedSampleCountPair(const ustring &name, uint64_t samples, uint64_t hits);
  75. ustring name;
  76. uint64_t samples;
  77. uint64_t hits;
  78. };
  79. /* Contains statistics about pairs of samples and counts as described above. */
  80. class NamedSampleCountStats {
  81. public:
  82. NamedSampleCountStats();
  83. string full_report(int indent_level = 0);
  84. void add(const ustring &name, uint64_t samples, uint64_t hits);
  85. typedef unordered_map<ustring, NamedSampleCountPair, ustringHash> entry_map;
  86. entry_map entries;
  87. };
  88. /* Statistics about mesh in the render database. */
  89. class MeshStats {
  90. public:
  91. MeshStats();
  92. /* Generate full human-readable report. */
  93. string full_report(int indent_level = 0);
  94. /* Input geometry statistics, this is what is coming as an input to render
  95. * from. say, Blender. This does not include runtime or engine specific
  96. * memory like BVH.
  97. */
  98. NamedSizeStats geometry;
  99. };
  100. /* Statistics about images held in memory. */
  101. class ImageStats {
  102. public:
  103. ImageStats();
  104. /* Generate full human-readable report. */
  105. string full_report(int indent_level = 0);
  106. NamedSizeStats textures;
  107. };
  108. /* Render process statistics. */
  109. class RenderStats {
  110. public:
  111. RenderStats();
  112. /* Return full report as string. */
  113. string full_report();
  114. /* Collect kernel sampling information from Stats. */
  115. void collect_profiling(Scene *scene, Profiler &prof);
  116. bool has_profiling;
  117. MeshStats mesh;
  118. ImageStats image;
  119. NamedNestedSampleStats kernel;
  120. NamedSampleCountStats shaders;
  121. NamedSampleCountStats objects;
  122. };
  123. CCL_NAMESPACE_END
  124. #endif /* __RENDER_STATS_H__ */