67 if (
__logger ==
nullptr && pLogger !=
nullptr ) {
73 pthread_mutex_init( &
__mutex,
nullptr );
80#ifdef H2CORE_HAVE_DEBUG
84 __logger->log(
Logger::Error,
"set_count",
"Object",
"not compiled with H2CORE_HAVE_DEBUG flag set" );
90#ifdef H2CORE_HAVE_DEBUG
93 out <<
"level must be Debug or higher" << std::endl;
95 out <<
"\033[35mlog level must be \033[31mDebug\033[35m or higher\033[0m"<< std::endl;
101 if ( map ==
nullptr ) {
106 std::ostringstream o;
107 pthread_mutex_lock( &
__mutex );
108 object_map_t::iterator it = map->begin();
109 while ( it != map->end() ) {
110 if ( it->second.constructed || it->second.destructed ) {
111 o <<
"\t[ " << std::setw( 30 ) << ( *it ).first <<
" ]\t" << std::setw( 6 ) << ( *it ).second.constructed <<
"\t" << std::setw( 6 ) << ( *it ).second.destructed
112 <<
"\t" << std::setw( 6 ) << ( *it ).second.constructed - ( *it ).second.destructed << std::endl;
116 pthread_mutex_unlock( &
__mutex );
123 out <<
"Objects map :" << std::setw( 30 ) <<
"class\t" <<
"constr destr alive" << std::endl << o.str() <<
"Total : " << std::setw( 6 ) <<
__objects_count <<
" objects.";
128 out << std::endl << std::endl;
132 out <<
"Base::write_objects_map_to :: not compiled with H2CORE_HAVE_DEBUG flag set" << std::endl;
134 out <<
"\033[35mBase::write_objects_map_to :: \033[31mnot compiled with H2CORE_HAVE_DEBUG flag set\033[0m" << std::endl;
140#ifdef H2CORE_HAVE_DEBUG
143 if (!strcmp(ii.first,
"Object")) {
144 return ii.second->constructed - ii.second->destructed;
149 ERRORLOG(
"This function is only supported in debug builds of Hydrogen." );
161 mapCopy.insert( std::pair<const char*, obj_cpt_t>( ii.first, copy ) );
175 auto it = mapSnapshot.find( ii.first );
176 if ( it != mapSnapshot.end() ) {
177 diff.
constructed = ii.second->constructed - it->second.constructed;
178 diff.
destructed = ii.second->destructed - it->second.destructed;
179 mapDiff.insert( std::pair<const char*, obj_cpt_t>( ii.first, diff ) );
187 return QString(
"[%1] instances alive: %2" )
196#ifdef HAVE_EXECINFO_H
197 const int nMaxFrames = 128;
198 void *frames[ nMaxFrames ];
199 int nFrames = backtrace( frames, nMaxFrames );
200 char **symbols = backtrace_symbols( frames, nFrames );
201 for (
int i = 0; i < nFrames; i++ ) {
202 DEBUGLOG( QString(
"%1").arg( symbols[i] ) );
205 DEBUGLOG(
"Compiled without backtrace support" );
215 QString sResult(
"Start clocking" );
216 if ( ! sMsg.isEmpty() ) {
217 sResult = QString(
"%1: %2" ).arg( sMsg ).arg( sResult );
220 return std::move( sResult );
231 sResult =
"Start clocking";
233 sResult = QString(
"elapsed [%1]ms" )
240 if ( ! sMsg.isEmpty() ) {
241 sResult = QString(
"%1: %2" ).arg( sMsg ).arg( sResult );
244 return std::move( sResult );
248 return os <<
object.toQString(
"",
true ).toLocal8Bit().data() << std::endl;
252 return os <<
object->toQString(
"",
true ).toLocal8Bit().data() << std::endl;
258 qWarning() <<
"Base::registerClass: " << name <<
" null counters!";
267 qWarning() <<
"Base::registerClass: " << name <<
" already registered";
int gettimeofday(struct timeval *tv, struct timezone *tz)
static std::atomic< int > __objects_count
total objects count
static void registerClass(const char *name, const atomic_obj_cpt_t *counters)
virtual QString toQString(const QString &sPrefix="", bool bShort=true) const
Formatted string version for debugging purposes.
static QString base_clock_in(const QString &sMsg)
static object_map_t getObjectMap()
static pthread_mutex_t __mutex
yeah this has to be thread safe
static bool count_active()
static QString base_clock(const QString &sMsg)
Measures the current time and stores it in __last_clock.
static int getAliveObjectCount()
void Print(bool bShort=true) const
Prints content of toQString() via DEBUGLOG.
void logBacktrace() const
Print the current stack at point into the debug log.
static bool __count
should we count class instances
static void set_count(bool flag)
enable/disable class instances counting
static int bootstrap(Logger *logger, bool count=false)
must be called before any Object instantiation !
static timeval __last_clock
static object_internal_map_t __objects_map
objects classes and instances count structure
static QString sPrintIndention
String used to format the debugging string output of some core classes.
static void write_objects_map_to(std::ostream &out, object_map_t *map=nullptr)
output the full objects map to a given ostream
virtual const char * class_name() const
static void printObjectMapDiff(object_map_t map)
Creates the difference between a snapshot of the object map and its current state and prints it to st...
Class for writing logs to the console.
bool getLogColors() const
std::map< const char *, const atomic_obj_cpt_t * > object_internal_map_t
std::ostream & operator<<(std::ostream &os, const Base &object)
std::map< const char *, obj_cpt_t > object_map_t
the objects class map types
atomic_obj_cpt_t Object< T >::counters
an objects class map item type