37 #ifndef DOXYGEN_SHOULD_SKIP_THIS 43 # ifdef GUM_DEBUG_MODE 46 typedef std::map< std::string, int > DEBUG_MAP;
48 static std::mutex debug_mutex;
51 static DEBUG_MAP& __sizeof() {
53 static DEBUG_MAP* sizeOf =
new DEBUG_MAP();
58 static DEBUG_MAP& __creation() {
60 static DEBUG_MAP* creation =
new DEBUG_MAP();
64 static DEBUG_MAP& __deletion() {
66 static DEBUG_MAP* deletion =
new DEBUG_MAP();
70 std::string __getFile(
const char* f) {
72 return s.erase(0, s.rfind(
"/") + 1);
75 void __show_trace(
const char* zeKey,
80 # ifdef GUM_DEEP_TRACE_ON 81 std::cerr << std::setw(40) << std::setfill(
' ') << __getFile(zeFile) <<
"#" 82 << std::setfill(
'0') << std::setw(5) << std::dec << zeLine <<
" : " 83 << zeMsg <<
" <" << zeKey <<
"> [" << std::hex << zePtr <<
"]" 84 << std::dec << std::endl;
85 # endif // TRACE_CONSTRUCTION_ON 88 void __inc_creation(
const char* zeKey,
95 __show_trace(zeKey, zeFile, zeLine, zeMsg, zePtr);
96 __creation()[zeKey]++;
97 __sizeof()[zeKey] = zeSize;
102 void __dec_creation(
const char* zeKey,
108 __show_trace(zeKey, zeFile, zeLine, zeMsg, zePtr);
109 __creation()[zeKey]--;
110 debug_mutex.unlock();
113 void __inc_deletion(
const char* zeKey,
119 __show_trace(zeKey, zeFile, zeLine, zeMsg, zePtr);
120 __deletion()[zeKey]++;
121 debug_mutex.unlock();
124 void __dumpObjects() {
126 double total_size = 0.0;
129 int widthColLibelle = 50;
130 int widthColSizeOf = 5;
131 int widthColItemsNumber = 8;
133 std::cout << std::setfill(
'=') <<
"|" << std::setw(widthColLibelle + 2) <<
"" 134 <<
"|" << std::setw(widthColSizeOf + 4) <<
"" 135 <<
"|" << std::setw(widthColItemsNumber + 2) <<
"" 136 <<
"|" << std::setw(widthColItemsNumber + 2) <<
"" 138 std::cout << std::setfill(
' ') <<
"| " << std::left
139 << std::setw(widthColLibelle) <<
"Class Name" << std::right
140 <<
" | " << std::setw(widthColSizeOf) <<
"Size" 141 <<
" | " << std::setw(widthColItemsNumber) <<
"#Const" 142 <<
" | " << std::setw(widthColItemsNumber) <<
"#Dest" 143 <<
" |" << std::endl;
144 std::cout << std::setfill(
'-') <<
"|" << std::setw(widthColLibelle + 2) <<
"" 145 <<
"|" << std::setw(widthColSizeOf + 4) <<
"" 146 <<
"|" << std::setw(widthColItemsNumber + 2) <<
"" 147 <<
"|" << std::setw(widthColItemsNumber + 2) <<
"" 150 std::map< std::string, std::string > res;
152 for (DEBUG_MAP::const_iterator xx = __creation().begin();
153 xx != __creation().end();
155 std::stringstream stream;
156 int zeCreatedObjs = xx->second;
157 int zeDeletedObjts = -1;
158 int size = __sizeof()[xx->first];
160 stream << std::setfill(fillChar = (fillChar ==
'_') ?
' ' :
'_') <<
"| " 161 << std::setw(widthColLibelle) << std::left << xx->first <<
" | " 162 << std::right << std::setw(widthColSizeOf) << size <<
" o | " 163 << std::setw(widthColItemsNumber) << zeCreatedObjs <<
" | ";
165 if (size > 0) total_size += zeCreatedObjs * (size / 1024.0);
168 zeDeletedObjts = __deletion()[xx->first];
169 stream << std::setfill(fillChar) << std::setw(widthColItemsNumber)
171 }
catch (NotFound&) {
172 stream << std::setfill(fillChar) << std::setw(widthColItemsNumber)
179 if (zeCreatedObjs != zeDeletedObjts) {
180 nb_err += std::abs(zeDeletedObjts - zeCreatedObjs);
181 stream <<
"<--- failed";
184 res.insert(make_pair(xx->first, stream.str()));
189 for (DEBUG_MAP::const_iterator xx = __deletion().begin();
190 xx != __deletion().end();
193 __creation()[xx->first];
194 }
catch (NotFound&) {
195 std::stringstream stream;
196 fillChar = (fillChar ==
'_') ?
' ' :
'_';
197 stream << std::setfill(fillChar = (fillChar ==
'_') ?
' ' :
'_') <<
"| " 198 << std::setw(widthColLibelle) << std::left << xx->first +
" " 199 <<
" | " << std::right << std::setw(widthColSizeOf)
200 << __sizeof()[xx->first] <<
" o | " 201 << std::setw(widthColItemsNumber) <<
"?????" 202 <<
" | " << std::setw(widthColItemsNumber) << xx->second
204 res.insert(make_pair(xx->first, stream.str()));
206 nb_err += xx->second;
210 for (
const auto iter : res) {
211 std::cout << iter.second << std::endl;
214 std::cout << std::setfill(
'-');
216 std::cout <<
"|-" << std::setw(widthColLibelle) <<
"" 217 <<
"-|-" << std::setw(widthColSizeOf + 2) <<
"" 218 <<
"-|-" << std::setw(widthColItemsNumber) <<
"" 219 <<
"-|-" << std::setw(widthColItemsNumber) <<
"" 220 <<
"-|" << std::endl;
222 std::cout << std::setfill(
' ');
225 std::cout <<
"| " << std::setw(widthColLibelle) <<
"NO MEMORY LEAK !" 227 << std::setw(widthColSizeOf + widthColItemsNumber * 2 + 9) <<
"" 230 std::cout <<
"| " << std::setw(widthColLibelle) <<
"Memory leaks found " 233 << std::setw(widthColSizeOf + widthColItemsNumber * 2 - 6)
234 << nb_err <<
" object(s) " 238 std::cout <<
"| " << std::setw(widthColLibelle) <<
"total " 239 <<
" | " << std::fixed
240 << std::setw(widthColSizeOf + widthColItemsNumber * 2 - 4)
241 << std::setprecision(2) << total_size <<
" Ko " 244 std::cout << std::setfill(
'=') <<
"|" << std::setw(widthColLibelle + 2) <<
"" 245 <<
"|" << std::setw(widthColSizeOf + widthColItemsNumber * 2 + 10)
252 void __staticCorrections() {}
255 __staticCorrections();
257 __creation().clear();
258 __deletion().clear();
263 # endif // GUM_DEBUG_MODE 267 #endif // DOXYGEN_SHOULD_SKIP_THIS
void __atexit()
Used for debug purpose.
gum is the global namespace for all aGrUM entities
std::size_t Size
In aGrUM, hashed values are unsigned long int.