stat.h 2.5 KB

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