40 #ifndef DOXYGEN_SHOULD_SKIP_THIS 46 # ifdef GUM_DEBUG_MODE 49 typedef std::map< std::string, int > DEBUG_MAP;
51 static std::mutex debug_mutex;
54 static DEBUG_MAP& __sizeof() {
56 static DEBUG_MAP* sizeOf =
new DEBUG_MAP();
61 static DEBUG_MAP& __creation() {
63 static DEBUG_MAP* creation =
new DEBUG_MAP();
67 static DEBUG_MAP& __deletion() {
69 static DEBUG_MAP* deletion =
new DEBUG_MAP();
73 std::string __getFile(
const char* f) {
75 return s.erase(0, s.rfind(
"/") + 1);
78 void __show_trace(
const char* zeKey,
83 # ifdef GUM_DEEP_TRACE_ON 84 std::cerr << std::setw(40) << std::setfill(
' ') << __getFile(zeFile) <<
"#" 85 << std::setfill(
'0') << std::setw(5) << std::dec << zeLine <<
" : " 86 << zeMsg <<
" <" << zeKey <<
"> [" << std::hex << zePtr <<
"]" 87 << std::dec << std::endl;
88 # endif // TRACE_CONSTRUCTION_ON 91 void __inc_creation(
const char* zeKey,
98 __show_trace(zeKey, zeFile, zeLine, zeMsg, zePtr);
99 __creation()[zeKey]++;
100 __sizeof()[zeKey] = zeSize;
101 debug_mutex.unlock();
105 void __dec_creation(
const char* zeKey,
111 __show_trace(zeKey, zeFile, zeLine, zeMsg, zePtr);
112 __creation()[zeKey]--;
113 debug_mutex.unlock();
116 void __inc_deletion(
const char* zeKey,
122 __show_trace(zeKey, zeFile, zeLine, zeMsg, zePtr);
123 __deletion()[zeKey]++;
124 debug_mutex.unlock();
127 void __dumpObjects() {
129 double total_size = 0.0;
132 int widthColLibelle = 50;
133 int widthColSizeOf = 5;
134 int widthColItemsNumber = 8;
136 std::cout << std::setfill(
'=') <<
"|" << std::setw(widthColLibelle + 2) <<
"" 137 <<
"|" << std::setw(widthColSizeOf + 4) <<
"" 138 <<
"|" << std::setw(widthColItemsNumber + 2) <<
"" 139 <<
"|" << std::setw(widthColItemsNumber + 2) <<
"" 141 std::cout << std::setfill(
' ') <<
"| " << std::left
142 << std::setw(widthColLibelle) <<
"Class Name" << std::right
143 <<
" | " << std::setw(widthColSizeOf) <<
"Size" 144 <<
" | " << std::setw(widthColItemsNumber) <<
"#Const" 145 <<
" | " << std::setw(widthColItemsNumber) <<
"#Dest" 146 <<
" |" << std::endl;
147 std::cout << std::setfill(
'-') <<
"|" << std::setw(widthColLibelle + 2) <<
"" 148 <<
"|" << std::setw(widthColSizeOf + 4) <<
"" 149 <<
"|" << std::setw(widthColItemsNumber + 2) <<
"" 150 <<
"|" << std::setw(widthColItemsNumber + 2) <<
"" 153 std::map< std::string, std::string > res;
155 for (DEBUG_MAP::const_iterator xx = __creation().begin();
156 xx != __creation().end();
158 std::stringstream stream;
159 int zeCreatedObjs = xx->second;
160 int zeDeletedObjts = -1;
161 int size = __sizeof()[xx->first];
163 stream << std::setfill(fillChar = (fillChar ==
'_') ?
' ' :
'_') <<
"| " 164 << std::setw(widthColLibelle) << std::left << xx->first <<
" | " 165 << std::right << std::setw(widthColSizeOf) << size <<
" o | " 166 << std::setw(widthColItemsNumber) << zeCreatedObjs <<
" | ";
168 if (size > 0) total_size += zeCreatedObjs * (size / 1024.0);
171 zeDeletedObjts = __deletion()[xx->first];
172 stream << std::setfill(fillChar) << std::setw(widthColItemsNumber)
174 }
catch (NotFound&) {
175 stream << std::setfill(fillChar) << std::setw(widthColItemsNumber)
182 if (zeCreatedObjs != zeDeletedObjts) {
183 nb_err += std::abs(zeDeletedObjts - zeCreatedObjs);
184 stream <<
"<--- failed";
187 res.insert(make_pair(xx->first, stream.str()));
192 for (DEBUG_MAP::const_iterator xx = __deletion().begin();
193 xx != __deletion().end();
196 __creation()[xx->first];
197 }
catch (NotFound&) {
198 std::stringstream stream;
199 fillChar = (fillChar ==
'_') ?
' ' :
'_';
200 stream << std::setfill(fillChar = (fillChar ==
'_') ?
' ' :
'_') <<
"| " 201 << std::setw(widthColLibelle) << std::left << xx->first +
" " 202 <<
" | " << std::right << std::setw(widthColSizeOf)
203 << __sizeof()[xx->first] <<
" o | " 204 << std::setw(widthColItemsNumber) <<
"?????" 205 <<
" | " << std::setw(widthColItemsNumber) << xx->second
207 res.insert(make_pair(xx->first, stream.str()));
209 nb_err += xx->second;
213 for (
const auto iter : res) {
214 std::cout << iter.second << std::endl;
217 std::cout << std::setfill(
'-');
219 std::cout <<
"|-" << std::setw(widthColLibelle) <<
"" 220 <<
"-|-" << std::setw(widthColSizeOf + 2) <<
"" 221 <<
"-|-" << std::setw(widthColItemsNumber) <<
"" 222 <<
"-|-" << std::setw(widthColItemsNumber) <<
"" 223 <<
"-|" << std::endl;
225 std::cout << std::setfill(
' ');
228 std::cout <<
"| " << std::setw(widthColLibelle) <<
"NO MEMORY LEAK !" 230 << std::setw(widthColSizeOf + widthColItemsNumber * 2 + 9) <<
"" 233 std::cout <<
"| " << std::setw(widthColLibelle) <<
"Memory leaks found " 236 << std::setw(widthColSizeOf + widthColItemsNumber * 2 - 6)
237 << nb_err <<
" object(s) " 241 std::cout <<
"| " << std::setw(widthColLibelle) <<
"total " 242 <<
" | " << std::fixed
243 << std::setw(widthColSizeOf + widthColItemsNumber * 2 - 4)
244 << std::setprecision(2) << total_size <<
" Ko " 247 std::cout << std::setfill(
'=') <<
"|" << std::setw(widthColLibelle + 2) <<
"" 248 <<
"|" << std::setw(widthColSizeOf + widthColItemsNumber * 2 + 10)
255 void __staticCorrections() {}
258 __staticCorrections();
260 __creation().clear();
261 __deletion().clear();
266 # endif // GUM_DEBUG_MODE 270 #endif // DOXYGEN_SHOULD_SKIP_THIS
void __atexit()
Used for debug purpose.
Copyright 2005-2019 Pierre-Henri WUILLEMIN et Christophe GONZALES (LIP6) {prenom.nom}_at_lip6.fr.
std::size_t Size
In aGrUM, hashed values are unsigned long int.