stat.cpp 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #include "stat.h"
  17. namespace embree
  18. {
  19. Stat Stat::instance;
  20. Stat::Stat () {
  21. }
  22. Stat::~Stat ()
  23. {
  24. #ifdef EMBREE_STAT_COUNTERS
  25. Stat::print(std::cout);
  26. #endif
  27. }
  28. void Stat::print(std::ostream& cout)
  29. {
  30. Counters& cntrs = instance.cntrs;
  31. /* print absolute numbers */
  32. cout << "--------- ABSOLUTE ---------" << std::endl;
  33. cout << " #normal_travs = " << float(cntrs.code.normal.travs )*1E-6 << "M" << std::endl;
  34. cout << " #nodes = " << float(cntrs.code.normal.trav_nodes )*1E-6 << "M" << std::endl;
  35. cout << " #nodes_xfm = " << float(cntrs.code.normal.trav_xfm_nodes )*1E-6 << "M" << std::endl;
  36. cout << " #leaves = " << float(cntrs.code.normal.trav_leaves )*1E-6 << "M" << std::endl;
  37. cout << " #prims = " << float(cntrs.code.normal.trav_prims )*1E-6 << "M" << std::endl;
  38. cout << " #prim_hits = " << float(cntrs.code.normal.trav_prim_hits )*1E-6 << "M" << std::endl;
  39. cout << " #stack nodes = " << float(cntrs.code.normal.trav_stack_nodes )*1E-6 << "M" << std::endl;
  40. cout << " #stack pop = " << float(cntrs.code.normal.trav_stack_pop )*1E-6 << "M" << std::endl;
  41. size_t normal_box_hits = 0;
  42. size_t weighted_box_hits = 0;
  43. for (size_t i=0;i<SIZE_HISTOGRAM;i++) {
  44. normal_box_hits += cntrs.code.normal.trav_hit_boxes[i];
  45. weighted_box_hits += cntrs.code.normal.trav_hit_boxes[i]*i;
  46. }
  47. cout << " #hit_boxes = " << normal_box_hits << " (total) distribution: ";
  48. float average = 0.0f;
  49. for (size_t i=0;i<SIZE_HISTOGRAM;i++)
  50. {
  51. float value = 100.0f * cntrs.code.normal.trav_hit_boxes[i] / normal_box_hits;
  52. cout << "[" << i << "] " << value << " ";
  53. average += (float)i*cntrs.code.normal.trav_hit_boxes[i] / normal_box_hits;
  54. }
  55. cout << " average = " << average << std::endl;
  56. for (size_t i=0;i<SIZE_HISTOGRAM;i++) cout << "[" << i << "] " << 100.0f * cntrs.code.normal.trav_hit_boxes[i]*i / weighted_box_hits << " ";
  57. cout << std::endl;
  58. if (cntrs.code.shadow.travs) {
  59. cout << " #shadow_travs = " << float(cntrs.code.shadow.travs )*1E-6 << "M" << std::endl;
  60. cout << " #nodes = " << float(cntrs.code.shadow.trav_nodes )*1E-6 << "M" << std::endl;
  61. cout << " #nodes_xfm = " << float(cntrs.code.shadow.trav_xfm_nodes)*1E-6 << "M" << std::endl;
  62. cout << " #leaves = " << float(cntrs.code.shadow.trav_leaves )*1E-6 << "M" << std::endl;
  63. cout << " #prims = " << float(cntrs.code.shadow.trav_prims )*1E-6 << "M" << std::endl;
  64. cout << " #prim_hits = " << float(cntrs.code.shadow.trav_prim_hits)*1E-6 << "M" << std::endl;
  65. cout << " #stack nodes = " << float(cntrs.code.shadow.trav_stack_nodes )*1E-6 << "M" << std::endl;
  66. cout << " #stack pop = " << float(cntrs.code.shadow.trav_stack_pop )*1E-6 << "M" << std::endl;
  67. size_t shadow_box_hits = 0;
  68. size_t weighted_shadow_box_hits = 0;
  69. for (size_t i=0;i<SIZE_HISTOGRAM;i++) {
  70. shadow_box_hits += cntrs.code.shadow.trav_hit_boxes[i];
  71. weighted_shadow_box_hits += cntrs.code.shadow.trav_hit_boxes[i]*i;
  72. }
  73. cout << " #hit_boxes = ";
  74. for (size_t i=0;i<SIZE_HISTOGRAM;i++) cout << "[" << i << "] " << 100.0f * cntrs.code.shadow.trav_hit_boxes[i] / shadow_box_hits << " ";
  75. cout << std::endl;
  76. for (size_t i=0;i<SIZE_HISTOGRAM;i++) cout << "[" << i << "] " << 100.0f * cntrs.code.shadow.trav_hit_boxes[i]*i / weighted_shadow_box_hits << " ";
  77. cout << std::endl;
  78. }
  79. cout << std::endl;
  80. /* print per traversal numbers */
  81. cout << "--------- PER TRAVERSAL ---------" << std::endl;
  82. float active_normal_travs = float(cntrs.active.normal.travs )/float(cntrs.all.normal.travs );
  83. float active_normal_trav_nodes = float(cntrs.active.normal.trav_nodes )/float(cntrs.all.normal.trav_nodes );
  84. float active_normal_trav_xfm_nodes = float(cntrs.active.normal.trav_xfm_nodes )/float(cntrs.all.normal.trav_xfm_nodes );
  85. float active_normal_trav_leaves = float(cntrs.active.normal.trav_leaves)/float(cntrs.all.normal.trav_leaves);
  86. float active_normal_trav_prims = float(cntrs.active.normal.trav_prims )/float(cntrs.all.normal.trav_prims );
  87. float active_normal_trav_prim_hits = float(cntrs.active.normal.trav_prim_hits )/float(cntrs.all.normal.trav_prim_hits );
  88. float active_normal_trav_stack_pop = float(cntrs.active.normal.trav_stack_pop )/float(cntrs.all.normal.trav_stack_pop );
  89. cout << " #normal_travs = " << float(cntrs.all.normal.travs )/float(cntrs.all.normal.travs) << ", " << 100.0f*active_normal_travs << "% active" << std::endl;
  90. cout << " #nodes = " << float(cntrs.all.normal.trav_nodes )/float(cntrs.all.normal.travs) << ", " << 100.0f*active_normal_trav_nodes << "% active" << std::endl;
  91. cout << " #node_xfm = " << float(cntrs.all.normal.trav_xfm_nodes )/float(cntrs.all.normal.travs) << ", " << 100.0f*active_normal_trav_xfm_nodes << "% active" << std::endl;
  92. cout << " #leaves = " << float(cntrs.all.normal.trav_leaves)/float(cntrs.all.normal.travs) << ", " << 100.0f*active_normal_trav_leaves << "% active" << std::endl;
  93. cout << " #prims = " << float(cntrs.all.normal.trav_prims )/float(cntrs.all.normal.travs) << ", " << 100.0f*active_normal_trav_prims << "% active" << std::endl;
  94. cout << " #prim_hits = " << float(cntrs.all.normal.trav_prim_hits )/float(cntrs.all.normal.travs) << ", " << 100.0f*active_normal_trav_prim_hits << "% active" << std::endl;
  95. cout << " #stack_pop = " << float(cntrs.all.normal.trav_stack_pop )/float(cntrs.all.normal.travs) << ", " << 100.0f*active_normal_trav_stack_pop << "% active" << std::endl;
  96. if (cntrs.all.shadow.travs) {
  97. float active_shadow_travs = float(cntrs.active.shadow.travs )/float(cntrs.all.shadow.travs );
  98. float active_shadow_trav_nodes = float(cntrs.active.shadow.trav_nodes )/float(cntrs.all.shadow.trav_nodes );
  99. float active_shadow_trav_xfm_nodes = float(cntrs.active.shadow.trav_xfm_nodes )/float(cntrs.all.shadow.trav_xfm_nodes );
  100. float active_shadow_trav_leaves = float(cntrs.active.shadow.trav_leaves)/float(cntrs.all.shadow.trav_leaves);
  101. float active_shadow_trav_prims = float(cntrs.active.shadow.trav_prims )/float(cntrs.all.shadow.trav_prims );
  102. float active_shadow_trav_prim_hits = float(cntrs.active.shadow.trav_prim_hits )/float(cntrs.all.shadow.trav_prim_hits );
  103. cout << " #shadow_travs = " << float(cntrs.all.shadow.travs )/float(cntrs.all.shadow.travs) << ", " << 100.0f*active_shadow_travs << "% active" << std::endl;
  104. cout << " #nodes = " << float(cntrs.all.shadow.trav_nodes )/float(cntrs.all.shadow.travs) << ", " << 100.0f*active_shadow_trav_nodes << "% active" << std::endl;
  105. cout << " #nodes_xfm = " << float(cntrs.all.shadow.trav_xfm_nodes )/float(cntrs.all.shadow.travs) << ", " << 100.0f*active_shadow_trav_xfm_nodes << "% active" << std::endl;
  106. cout << " #leaves = " << float(cntrs.all.shadow.trav_leaves)/float(cntrs.all.shadow.travs) << ", " << 100.0f*active_shadow_trav_leaves << "% active" << std::endl;
  107. cout << " #prims = " << float(cntrs.all.shadow.trav_prims )/float(cntrs.all.shadow.travs) << ", " << 100.0f*active_shadow_trav_prims << "% active" << std::endl;
  108. cout << " #prim_hits = " << float(cntrs.all.shadow.trav_prim_hits )/float(cntrs.all.shadow.travs) << ", " << 100.0f*active_shadow_trav_prim_hits << "% active" << std::endl;
  109. }
  110. cout << std::endl;
  111. /* print user counters for performance tuning */
  112. cout << "--------- USER ---------" << std::endl;
  113. for (size_t i=0; i<10; i++)
  114. cout << "#user" << i << " = " << float(cntrs.user[i])/float(cntrs.all.normal.travs+cntrs.all.shadow.travs) << " per traversal" << std::endl;
  115. cout << "#user5/user3 " << 100.0f*float(cntrs.user[5])/float(cntrs.user[3]) << "%" << std::endl;
  116. cout << "#user6/user3 " << 100.0f*float(cntrs.user[6])/float(cntrs.user[3]) << "%" << std::endl;
  117. cout << "#user7/user3 " << 100.0f*float(cntrs.user[7])/float(cntrs.user[3]) << "%" << std::endl;
  118. cout << std::endl;
  119. }
  120. }