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

source code of qtquick3d/src/3rdparty/embree/kernels/common/stat.cpp