33 typedef std::map<const std::type_info*, COUNT*> TypeCounter;
34 typedef std::map<const std::string*, COUNT*> StringCounter;
35 static bool s_trace_instances = ::getenv(
"DD4HEP_TRACE") != 0;
41 inline TypeCounter& types() {
42 return *(s_typCounts.get());
44 inline StringCounter& strings() {
45 return *(s_strCounts.get());
51 ~_Global() { s_global = 0; }
53 int on_exit_destructors() {
54 static bool first =
true;
55 if ( first && s_global == 0 && s_trace_instances ) {
57 ::printf(
"Static out of order destructors occurred. Reference count table is unreliable.....\n");
71 if (0 == s_thisCount.
value()) {
72 StringCounter::iterator i;
73 TypeCounter::iterator j;
75 for (i = s_strCounts->begin(); i != s_strCounts->end(); ++i)
77 for (j = s_typCounts->begin(); j != s_typCounts->end(); ++j)
86 return s_trace_instances;
91 s_trace_instances = value;
96 Counter* cnt = s_trace_instances ? types()[&typ] : &s_nullCount;
97 return (0 != cnt) ? cnt : types()[&typ] =
new Counter();
102 Counter* cnt = s_trace_instances ? strings()[&typ] : &s_nullCount;
103 return (0 != cnt) ? cnt : strings()[&typ] =
new Counter();
106 #define COUNTER_LOCK std::lock_guard<std::mutex> _counter_lock(s_globalObj.lock);
115 on_exit_destructors();
125 on_exit_destructors();
135 on_exit_destructors();
145 on_exit_destructors();
150 bool need_footer =
false;
151 if ((typ &
STRING) && s_strCounts.get()) {
152 if ( !s_strCounts->empty() ) {
153 std::cout <<
"+--------------------------------------------------------------------------+" << std::endl;
154 std::cout <<
"| I n s t a n c e c o u n t e r s b y N A M E |" << std::endl;
155 std::cout <<
"+----------+---------+---------+-------------------------------------------+" << std::endl;
156 std::cout <<
"| Total | Max | Leaking | Type identifier |" << std::endl;
157 std::cout <<
"+----------+---------+---------+-------------------------------------------+" << std::endl;
158 long tot_instances=0, max_instances=0, now_instances=0;
159 for (
const auto& i : *s_strCounts ) {
160 std::cout <<
"|" << std::setw(10) << i.second->total()
161 <<
"|" << std::setw(9) << i.second->maximum()
162 <<
"|" << std::setw(9) << i.second->value()
163 <<
"|" << i.first->substr(0,80) << std::endl;
164 tot_instances += i.second->total();
165 max_instances += i.second->maximum();
166 now_instances += i.second->value();
168 std::cout <<
"+----------+---------+---------+-------------------------------------------+" << std::endl;
169 std::cout <<
"|" << std::setw(10) << tot_instances
170 <<
"|" << std::setw(9) << max_instances
171 <<
"|" << std::setw(9) << now_instances
172 <<
"|" <<
"Grand total (Sum of all counters)" << std::endl;
176 if ((typ &
TYPEINFO) && s_typCounts.get()) {
177 if ( !s_typCounts->empty() ) {
178 std::cout <<
"+--------------------------------------------------------------------------+" << std::endl;
179 std::cout <<
"| I n s t a n c e c o u n t e r s b y T Y P E I N F O |" << std::endl;
180 std::cout <<
"+----------+---------+---------+-------------------------------------------+" << std::endl;
181 std::cout <<
"| Total | Max | Leaking | Type identifier |" << std::endl;
182 std::cout <<
"+----------+---------+---------+-------------------------------------------+" << std::endl;
183 long tot_instances=0, max_instances=0, now_instances=0;
184 for (
const auto& i : *s_typCounts ) {
185 std::string nam = typeName(*(i.first));
186 if ( nam.length() > 80 ) nam = nam.substr(0,80)+
" ...";
187 std::cout <<
"|" << std::setw(10) << i.second->total()
188 <<
"|" << std::setw(9) << i.second->maximum()
189 <<
"|" << std::setw(9) << i.second->value()
190 <<
"|" << nam << std::endl;
191 tot_instances += i.second->total();
192 max_instances += i.second->maximum();
193 now_instances += i.second->value();
195 std::cout <<
"+----------+---------+---------+-------------------------------------------+" << std::endl;
196 std::cout <<
"|" << std::setw(10) << tot_instances
197 <<
"|" << std::setw(9) << max_instances
198 <<
"|" << std::setw(9) << now_instances
199 <<
"|" <<
"Grand total (Sum of all counters)" << std::endl;
204 std::cout <<
"+----------+-------+-------------------------------------------+" << std::endl;