58#ifndef DOXYGEN_SHOULD_SKIP_THIS
67 using DEBUG_MAP = std::map< std::string, int >;
69 static std::mutex& _debug_mutex_() {
71 static std::mutex debug_mutex;
76 static DEBUG_MAP& _sizeof_() {
78 static DEBUG_MAP sizeOf;
83 static DEBUG_MAP& _creation_() {
85 static DEBUG_MAP creation;
89 static DEBUG_MAP& _deletion_() {
91 static DEBUG_MAP deletion;
95 std::string _getFile_(
const char* f) {
97 return s.erase(0, s.rfind(
'/') + 1);
100 void _show_trace_(
const char* zeKey,
105# ifdef GUM_DEEP_TRACE_ON
106 std::cerr << std::setw(40) << std::setfill(
' ') << _getFile_(zeFile) <<
"#"
107 << std::setfill(
'0') << std::setw(5) << std::dec << zeLine <<
" : " << zeMsg <<
" <"
108 << zeKey <<
"> [" << std::hex << zePtr <<
"]" << std::dec << std::endl;
112 void _inc_creation_(
const char* zeKey,
118 static DEBUG_MAP& creation = _creation_();
119 static DEBUG_MAP& size = _sizeof_();
120 std::unique_lock lck{_debug_mutex_()};
122 _show_trace_(zeKey, zeFile, zeLine, zeMsg, zePtr);
124 size[zeKey] = zeSize;
128 void _dec_creation_(
const char* zeKey,
133 static DEBUG_MAP& creation = _creation_();
134 std::unique_lock lck{_debug_mutex_()};
136 _show_trace_(zeKey, zeFile, zeLine, zeMsg, zePtr);
140 void _inc_deletion_(
const char* zeKey,
145 static DEBUG_MAP& deletion = _deletion_();
146 std::unique_lock lck{_debug_mutex_()};
148 _show_trace_(zeKey, zeFile, zeLine, zeMsg, zePtr);
152 void _dumpObjects_() {
153 DEBUG_MAP& creation = _creation_();
154 DEBUG_MAP& deletion = _deletion_();
155 DEBUG_MAP& sizeOf = _sizeof_();
158 double total_size = 0.0;
161 int widthColLibelle = 50;
162 int widthColSizeOf = 5;
163 int widthColItemsNumber = 8;
165 std::cout << std::setfill(
'=') <<
"|" << std::setw(widthColLibelle + 2) <<
""
166 <<
"|" << std::setw(widthColSizeOf + 4) <<
""
167 <<
"|" << std::setw(widthColItemsNumber + 2) <<
""
168 <<
"|" << std::setw(widthColItemsNumber + 2) <<
""
170 std::cout << std::setfill(
' ') <<
"| " << std::left << std::setw(widthColLibelle)
171 <<
"Class Name" << std::right <<
" | " << std::setw(widthColSizeOf) <<
"Size"
172 <<
" | " << std::setw(widthColItemsNumber) <<
"#Const"
173 <<
" | " << std::setw(widthColItemsNumber) <<
"#Dest"
174 <<
" |" << std::endl;
175 std::cout << std::setfill(
'-') <<
"|" << std::setw(widthColLibelle + 2) <<
""
176 <<
"|" << std::setw(widthColSizeOf + 4) <<
""
177 <<
"|" << std::setw(widthColItemsNumber + 2) <<
""
178 <<
"|" << std::setw(widthColItemsNumber + 2) <<
""
181 std::map< std::string, std::string > res;
183 for (DEBUG_MAP::const_iterator xx = creation.begin(); xx != creation.end(); ++xx) {
184 std::stringstream stream;
185 int zeCreatedObjs = xx->second;
186 int zeDeletedObjts = -1;
187 int size = sizeOf[xx->first];
189 stream << std::setfill(fillChar = (fillChar ==
'_') ?
' ' :
'_') <<
"| "
190 << std::setw(widthColLibelle) << std::left << xx->first <<
" | " << std::right
191 << std::setw(widthColSizeOf) << size <<
" o | " << std::setw(widthColItemsNumber)
192 << zeCreatedObjs <<
" | ";
194 if (size > 0) total_size += zeCreatedObjs * (size / 1024.0);
197 zeDeletedObjts = deletion[xx->first];
198 stream << std::setfill(fillChar) << std::setw(widthColItemsNumber) << zeDeletedObjts;
199 }
catch (NotFound
const&) {
200 stream << std::setfill(fillChar) << std::setw(widthColItemsNumber) <<
"?????";
205 if (zeCreatedObjs != zeDeletedObjts) {
206 nb_err += std::abs(zeDeletedObjts - zeCreatedObjs);
207 stream <<
"<--- failed";
210 res.insert(make_pair(xx->first, stream.str()));
214 for (DEBUG_MAP::const_iterator xx = deletion.begin(); xx != deletion.end(); ++xx) {
217 }
catch (NotFound
const&) {
218 std::stringstream stream;
219 fillChar = (fillChar ==
'_') ?
' ' :
'_';
220 stream << std::setfill(fillChar = (fillChar ==
'_') ?
' ' :
'_') <<
"| "
221 << std::setw(widthColLibelle) << std::left << xx->first +
" " <<
" | "
222 << std::right << std::setw(widthColSizeOf) << sizeOf[xx->first] <<
" o | "
223 << std::setw(widthColItemsNumber) <<
"?????"
224 <<
" | " << std::setw(widthColItemsNumber) << xx->second <<
" |<--- failed";
225 res.insert(make_pair(xx->first, stream.str()));
227 nb_err += xx->second;
231 for (
const auto& [fisrt, second]: res)
232 std::cout << second << std::endl;
235 std::cout << std::setfill(
'-');
237 std::cout <<
"|-" << std::setw(widthColLibelle) <<
""
238 <<
"-|-" << std::setw(widthColSizeOf + 2) <<
""
239 <<
"-|-" << std::setw(widthColItemsNumber) <<
""
240 <<
"-|-" << std::setw(widthColItemsNumber) <<
""
241 <<
"-|" << std::endl;
243 std::cout << std::setfill(
' ');
246 std::cout <<
"| " << std::setw(widthColLibelle) <<
"NO MEMORY LEAK !"
247 <<
" | " << std::setw(widthColSizeOf + widthColItemsNumber * 2 + 9) <<
""
250 std::cout <<
"| " << std::setw(widthColLibelle) <<
"Memory leaks found "
252 <<
" | " << std::setw(widthColSizeOf + widthColItemsNumber * 2 - 6) << nb_err
257 std::cout <<
"| " << std::setw(widthColLibelle) <<
"total "
258 <<
" | " << std::fixed << std::setw(widthColSizeOf + widthColItemsNumber * 2 - 4)
259 << std::setprecision(2) << total_size <<
" Ko "
262 std::cout << std::setfill(
'=') <<
"|" << std::setw(widthColLibelle + 2) <<
""
263 <<
"|" << std::setw(widthColSizeOf + widthColItemsNumber * 2 + 10) <<
""
269 void _staticCorrections_() {
271 _inc_deletion_(
"HashTable",
"GraphElements.cpp", 40,
"destructor of",
nullptr);
272 _inc_deletion_(
"Set",
"GraphElements.cpp", 40,
"destructor of",
nullptr);
276 _staticCorrections_();
278 _creation_().clear();
279 _deletion_().clear();
std::size_t Size
In aGrUM, hashed values are unsigned long int.
void _atexit_()
Used for debug purpose.
Internal namespace for aGrUM debugging tools.
gum is the global namespace for all aGrUM entities