#include <LeaLeakChecker.h>
Public Types | |
| typedef std::map< std::string, LeaClassMonitor * >::iterator | MapItr |
| typedef std::map< std::string, LeaClassMonitor * >::const_iterator | MapConstItr |
Public Member Functions | |
| virtual | ~LeaLeakChecker () |
| LeaClassMonitor * | GetExistingMonitor (const Char_t *name) const |
| UInt_t | GetNumActive (const Char_t *name=0) const |
| UInt_t | GetNumCreated (const Char_t *name=0) const |
| std::ostream & | Print (std::ostream &os) |
| Bool_t | Add (const Char_t *name, const void *addr) |
| LeaClassMonitor * | GetMonitor (const Char_t *name) |
| void | Reset (const Char_t *name=0) |
| Bool_t | Remove (const Char_t *name, const void *addr) |
Static Public Member Functions | |
| static LeaLeakChecker * | Instance () |
Private Member Functions | |
| LeaLeakChecker () | |
Private Attributes | |
| std::map< std::string, LeaClassMonitor * > | fMonitors |
Static Private Attributes | |
| static LeaLeakChecker * | fgInstance = 0 |
Friends | |
| struct | Cleaner |
Classes | |
| struct | Cleaner |
Definition at line 33 of file LeaLeakChecker.h.
| typedef std::map<std::string,LeaClassMonitor*>::const_iterator LeaLeakChecker::MapConstItr |
Definition at line 39 of file LeaLeakChecker.h.
| typedef std::map<std::string,LeaClassMonitor*>::iterator LeaLeakChecker::MapItr |
Definition at line 38 of file LeaLeakChecker.h.
| LeaLeakChecker::~LeaLeakChecker | ( | ) | [virtual] |
Definition at line 318 of file LeaLeakChecker.cxx.
References fgInstance, and fMonitors.
00318 { 00319 00320 00321 // Purpose: Destructor. 00322 00323 // Arguments: 00324 // None. 00325 00326 // Return: n/a 00327 00328 // Contact: N. West 00329 00330 // Specification:- 00331 // ============= 00332 00333 // o Destroy LeaLeakChecker. 00334 00335 // Program Notes:- 00336 // ============= 00337 00338 // None. 00339 00340 cout << "LeakChecker shutting down ..." << endl; 00341 for ( MapItr itr = fMonitors.begin(); 00342 itr != fMonitors.end(); 00343 itr++) { 00344 LeaClassMonitor* mon = (*itr).second; 00345 delete mon; 00346 } 00347 cout << "LeakChecker shutdown complete." << endl; 00348 LeaLeakChecker::fgInstance = 0; 00349 00350 }
| LeaLeakChecker::LeaLeakChecker | ( | ) | [private] |
Definition at line 290 of file LeaLeakChecker.cxx.
References Msg::kDebug, and MSG.
Referenced by Instance().
00290 { 00291 00292 00293 // Purpose: Default constructor. 00294 00295 // Arguments: 00296 // None. 00297 00298 // Return: n/a 00299 00300 // Contact: N. West 00301 00302 // Specification:- 00303 // ============= 00304 00305 // o Create LeaLeakChecker. 00306 00307 // Program Notes:- 00308 // ============= 00309 00310 // None. 00311 00312 MSG("Lea", Msg::kDebug) << "Creating LeaLeakChecker at " 00313 << reinterpret_cast<void*>(this) << endl; 00314 00315 }
| Bool_t LeaLeakChecker::Add | ( | const Char_t * | name, | |
| const void * | addr | |||
| ) |
Definition at line 45 of file LeaLeakChecker.cxx.
00045 { 00046 00047 00048 // Purpose: Add named object to class monitor. 00049 00050 // Arguments: 00051 // name in String containing class name (can be file name). 00052 // addr in Address of object. 00053 00054 // Return: kTRUE always (reserved for future use). 00055 00056 // Contact: N. West 00057 00058 // Specification:- 00059 // ============= 00060 00061 // o Get monitor for class and record object creation. 00062 00063 // Program Notes:- 00064 // ============= 00065 00066 // None. 00067 00068 return GetMonitor(name)->Add(addr); 00069 00070 }
| LeaClassMonitor * LeaLeakChecker::GetExistingMonitor | ( | const Char_t * | name | ) | const |
Definition at line 75 of file LeaLeakChecker.cxx.
References fMonitors.
Referenced by GetNumActive(), GetNumCreated(), and Reset().
00076 { 00077 00078 00079 // Purpose: Return monitor for this existing class. 00080 00081 // Arguments: 00082 // name in class name. 00083 00084 // Return: Class Monitor addr, or 0 if none. 00085 00086 // Contact: N. West 00087 00088 // Specification:- 00089 // ============= 00090 00091 // o Return the LeaClassMonitor for this class if any. 00092 00093 // Program Notes:- 00094 // ============= 00095 00096 // None. 00097 00098 00099 std::string className = name; 00100 00101 // Locate the associated class monitor. 00102 MapConstItr element = fMonitors.find(className); 00103 return ( element != fMonitors.end() ) ? (*element).second : 0; 00104 00105 }
| LeaClassMonitor * LeaLeakChecker::GetMonitor | ( | const Char_t * | name | ) |
Definition at line 108 of file LeaLeakChecker.cxx.
References fMonitors, Msg::kDebug, MSG, and LeaClassMonitor::SetName().
Referenced by Remove().
00108 { 00109 00110 00111 // Purpose: Return monitor for this class, creating if necessary 00112 00113 // Arguments: 00114 // name in class name or file name. 00115 00116 // Return: Class Monitor add. 00117 00118 // Contact: N. West 00119 00120 // Specification:- 00121 // ============= 00122 00123 // o Determine the class name if necessary from the file name. 00124 00125 // o Return, creating if necessary and required, the LeaClassMonitor 00126 // for this class. 00127 00128 // Program Notes:- 00129 // ============= 00130 00131 // None. 00132 00133 // Determine the class name from the file name by removing 00134 // leading directory and any trailing extension. 00135 00136 std::string className = name; 00137 if ( className.find(".") < className.size() ) { 00138 UInt_t locSlash = className.rfind("/"); 00139 if ( locSlash < className.size() ) className.erase(0,locSlash+1); 00140 className.erase(className.find("."),className.size()); 00141 } 00142 00143 00144 // Locate the associated class monitor and set its name if new. 00145 LeaClassMonitor* mon = fMonitors[className]; 00146 if ( ! mon ) { 00147 mon = new LeaClassMonitor; 00148 fMonitors[className] = mon; 00149 mon->SetName(className.c_str()); 00150 } 00151 00152 MSG("Lea", Msg::kDebug) << "ClassMonitor: " 00153 << className.c_str() << " found at " 00154 << reinterpret_cast<void*> (mon) 00155 << " set size " << fMonitors.size() << endl; 00156 00157 return mon; 00158 00159 00160 }
| UInt_t LeaLeakChecker::GetNumActive | ( | const Char_t * | name = 0 |
) | const |
Definition at line 164 of file LeaLeakChecker.cxx.
References fMonitors, GetExistingMonitor(), and LeaClassMonitor::GetNumActive().
Referenced by NavValidate::RunAllTests(), and LeaValidate::Test_1().
00164 { 00165 00166 00167 // Purpose: Return the number of active objects of one or all 00168 // classes. 00169 00170 // Arguments: 00171 // name in Class name string or 0 (default) all classes. 00172 00173 // Return: Return the number of active objects of one or all 00174 // classes. 00175 00176 // Contact: N. West 00177 00178 // Specification:- 00179 // ============= 00180 00181 // o Return the number of active objects of one or all classes. 00182 00183 // Program Notes:- 00184 // ============= 00185 00186 // None. 00187 00188 // If name supplied, just use, but don't create, it. 00189 00190 if ( name ) { 00191 LeaClassMonitor* mon = GetExistingMonitor(name); 00192 return mon ? mon->GetNumActive() : 0; 00193 } 00194 00195 // No name supplied, use all classs 00196 00197 UInt_t num = 0; 00198 for ( MapConstItr itr = fMonitors.begin(); 00199 itr != fMonitors.end(); 00200 itr++) num += (*itr).second->GetNumActive(); 00201 return num; 00202 00203 }
| UInt_t LeaLeakChecker::GetNumCreated | ( | const Char_t * | name = 0 |
) | const |
Definition at line 206 of file LeaLeakChecker.cxx.
References fMonitors, GetExistingMonitor(), and LeaClassMonitor::GetNumCreated().
Referenced by NavValidate::RunAllTests(), and LeaValidate::Test_1().
00206 { 00207 00208 00209 // Purpose: Return the number of created objects of one or all 00210 // classes. 00211 00212 // Arguments: 00213 // name in Class name string or 0 (default) all classes. 00214 00215 // Return: Return the number of created objects of one or all 00216 // classes. 00217 00218 // Contact: N. West 00219 00220 // Specification:- 00221 // ============= 00222 00223 // o Return the number of created objects of one or all classes. 00224 00225 // Program Notes:- 00226 // ============= 00227 00228 // None. 00229 00230 // If name supplied, just use, but don't create, it. 00231 00232 if ( name ) { 00233 LeaClassMonitor* mon = GetExistingMonitor(name); 00234 return mon ? mon->GetNumCreated() : 0; 00235 } 00236 00237 // No name supplied, use all classs 00238 00239 UInt_t num = 0; 00240 for ( MapConstItr itr = fMonitors.begin(); 00241 itr != fMonitors.end(); 00242 itr++) num += (*itr).second->GetNumCreated(); 00243 return num; 00244 00245 }
| LeaLeakChecker * LeaLeakChecker::Instance | ( | ) | [static] |
Definition at line 248 of file LeaLeakChecker.cxx.
References LeaLeakChecker::Cleaner::ClassIsUsed(), fgInstance, Msg::kWarning, LeaLeakChecker(), and MSG.
Referenced by DbmModule::CheckMemory(), NavValidate::RunAllTests(), and LeaValidate::Test_1().
00248 { 00249 00250 00251 // Purpose: Return a pointer to the sole instance of the LeaLeakChecker. 00252 00253 // Arguments: 00254 // None 00255 00256 // Return: A pointer to the LeaLeakChecker. 00257 00258 // Contact: N. West 00259 00260 // Specification:- 00261 // ============= 00262 00263 // o Return a pointer to the sole instance of the LeaLeakChecker. 00264 00265 // Program Notes:- 00266 // ============= 00267 00268 // None. 00269 00270 if ( ! fgInstance ) { 00271 00272 // Helper class to handle delete 00273 static LeaLeakChecker::Cleaner c; 00274 c.ClassIsUsed(); 00275 00276 fgInstance = new LeaLeakChecker(); 00277 00278 MSG("Lea",Msg::kWarning) << "\n\n\n" 00279 << " WARNING: The LeakChecker package has been activated.\n" 00280 << " ******* This can seriously degrade performance and should\n" 00281 << " only be used for development and never production !!!\n\n\n"; 00282 00283 } 00284 00285 return fgInstance; 00286 00287 }
| std::ostream& LeaLeakChecker::Print | ( | std::ostream & | os | ) |
Referenced by operator<<().
| Bool_t LeaLeakChecker::Remove | ( | const Char_t * | name, | |
| const void * | addr | |||
| ) |
Definition at line 434 of file LeaLeakChecker.cxx.
References GetMonitor(), and LeaClassMonitor::Remove().
00434 { 00435 00436 00437 // Purpose: Remove named object to class monitor. 00438 00439 // Arguments: 00440 // name in String containing class name (can be file name). 00441 // addr in Address of object. 00442 00443 // Return: kTRUE always (reserved for future use). 00444 00445 // Contact: N. West 00446 00447 // Specification:- 00448 // ============= 00449 00450 // o Get monitor for class and record object destruction. 00451 00452 // Program Notes:- 00453 // ============= 00454 00455 // None. 00456 00457 return GetMonitor(name)->Remove(addr); 00458 00459 }
| void LeaLeakChecker::Reset | ( | const Char_t * | name = 0 |
) |
Definition at line 395 of file LeaLeakChecker.cxx.
References fMonitors, GetExistingMonitor(), and LeaClassMonitor::Reset().
Referenced by NavValidate::RunAllTests(), and LeaValidate::Test_1().
00395 { 00396 00397 00398 // Purpose: Clear the number of objects of one or all classes. 00399 00400 // Arguments: 00401 // name in Class name string or 0 (default) all classes. 00402 00403 // Return: None. 00404 00405 // Contact: N. West 00406 00407 // Specification:- 00408 // ============= 00409 00410 // o Reseet the number of objects of one or all classes. 00411 00412 // Program Notes:- 00413 // ============= 00414 00415 // None. 00416 00417 // If name supplied, just use, but don't create, it. 00418 00419 if ( name ) { 00420 LeaClassMonitor* mon = GetExistingMonitor(name); 00421 if ( mon ) mon->Reset(); 00422 } 00423 00424 // No name supplied, use all classs 00425 00426 for ( MapConstItr itr = fMonitors.begin(); 00427 itr != fMonitors.end(); 00428 itr++) (*itr).second->Reset(); 00429 00430 }
friend struct Cleaner [friend] |
Definition at line 70 of file LeaLeakChecker.h.
LeaLeakChecker * LeaLeakChecker::fgInstance = 0 [static, private] |
Definition at line 78 of file LeaLeakChecker.h.
Referenced by Instance(), LeaLeakChecker::Cleaner::~Cleaner(), and ~LeaLeakChecker().
std::map<std::string,LeaClassMonitor*> LeaLeakChecker::fMonitors [private] |
Definition at line 76 of file LeaLeakChecker.h.
Referenced by GetExistingMonitor(), GetMonitor(), GetNumActive(), GetNumCreated(), Reset(), and ~LeaLeakChecker().
1.4.7