stat.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. // ======================================================================== //
  2. // Copyright 2009-2017 Intel Corporation //
  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. #pragma once
  17. #include "default.h"
  18. /* Makros to gather statistics */
  19. #ifdef EMBREE_STAT_COUNTERS
  20. # define STAT(x) x
  21. # define STAT3(s,x,y,z) \
  22. STAT(Stat::get().code .s+=x); \
  23. STAT(Stat::get().active.s+=y); \
  24. STAT(Stat::get().all .s+=z);
  25. # define STAT_USER(i,x) Stat::get().user[i]+=x;
  26. #else
  27. # define STAT(x)
  28. # define STAT3(s,x,y,z)
  29. # define STAT_USER(i,x)
  30. #endif
  31. namespace embree
  32. {
  33. /*! Gathers ray tracing statistics. We count 1) how often a code
  34. * location is reached, 2) how many SIMD lanes are active, 3) how
  35. * many SIMD lanes reach the code location */
  36. class Stat
  37. {
  38. public:
  39. static const size_t SIZE_HISTOGRAM = 64+1;
  40. /*! constructs stat counter class */
  41. Stat ();
  42. /*! destructs stat counter class */
  43. ~Stat ();
  44. class Counters
  45. {
  46. public:
  47. Counters () {
  48. clear();
  49. }
  50. void clear()
  51. {
  52. all.clear();
  53. active.clear();
  54. code.clear();
  55. for (auto& u : user) u.store(0);
  56. }
  57. public:
  58. /* per packet and per ray stastics */
  59. struct
  60. {
  61. void clear () {
  62. normal.clear();
  63. shadow.clear();
  64. }
  65. /* normal and shadow ray statistics */
  66. struct
  67. {
  68. void clear()
  69. {
  70. travs.store(0);
  71. trav_nodes.store(0);
  72. trav_leaves.store(0);
  73. trav_prims.store(0);
  74. trav_prim_hits.store(0);
  75. for (auto& v : trav_hit_boxes) v.store(0);
  76. trav_stack_pop.store(0);
  77. trav_stack_nodes.store(0);
  78. trav_xfm_nodes.store(0);
  79. }
  80. public:
  81. std::atomic<size_t> travs;
  82. std::atomic<size_t> trav_nodes;
  83. std::atomic<size_t> trav_leaves;
  84. std::atomic<size_t> trav_prims;
  85. std::atomic<size_t> trav_prim_hits;
  86. std::atomic<size_t> trav_hit_boxes[SIZE_HISTOGRAM+1];
  87. std::atomic<size_t> trav_stack_pop;
  88. std::atomic<size_t> trav_stack_nodes;
  89. std::atomic<size_t> trav_xfm_nodes;
  90. } normal, shadow;
  91. } all, active, code;
  92. std::atomic<size_t> user[10];
  93. };
  94. public:
  95. static __forceinline Counters& get() {
  96. return instance.cntrs;
  97. }
  98. static void clear() {
  99. instance.cntrs.clear();
  100. }
  101. static void print(std::ostream& cout);
  102. private:
  103. Counters cntrs;
  104. private:
  105. static Stat instance;
  106. };
  107. }