65 pthread_mutex_init( &
__mutex,
nullptr );
72#ifdef H2CORE_HAVE_DEBUG
82#ifdef H2CORE_HAVE_DEBUG
85 out <<
"level must be Debug or higher"<< std::endl;
87 out <<
"\033[35mlog level must be \033[31mDebug\033[35m or higher\033[0m"<< std::endl;
92 if ( map ==
nullptr ) {
99 object_map_t::iterator it = map->begin();
100 while ( it != map->end() ) {
101 if ( it->second.constructed || it->second.destructed ) {
102 o <<
"\t[ " << std::setw( 30 ) << ( *it ).first <<
" ]\t" << std::setw( 6 ) << ( *it ).second.constructed <<
"\t" << std::setw( 6 ) << ( *it ).second.destructed
103 <<
"\t" << std::setw( 6 ) << ( *it ).second.constructed - ( *it ).second.destructed << std::endl;
107 pthread_mutex_unlock( &
__mutex );
109 out << std::endl <<
"\033[35m";
111 out <<
"Objects map :" << std::setw( 30 ) <<
"class\t" <<
"constr destr alive" << std::endl << o.str() <<
"Total : " << std::setw( 6 ) <<
__objects_count <<
" objects.";
115 out << std::endl << std::endl;
118 out <<
"Base::write_objects_map_to :: not compiled with H2CORE_HAVE_DEBUG flag set" << std::endl;
120 out <<
"\033[35mBase::write_objects_map_to :: \033[31mnot compiled with H2CORE_HAVE_DEBUG flag set\033[0m" << std::endl;
126#ifdef H2CORE_HAVE_DEBUG
129 if (!strcmp(ii.first,
"Object")) {
130 return ii.second->constructed - ii.second->destructed;
135 ERRORLOG(
"This function is only supported in debug builds of Hydrogen." );
147 mapCopy.insert( std::pair<const char*, obj_cpt_t>( ii.first, copy ) );
161 auto it = mapSnapshot.find( ii.first );
162 if ( it != mapSnapshot.end() ) {
163 diff.
constructed = ii.second->constructed - it->second.constructed;
164 diff.
destructed = ii.second->destructed - it->second.destructed;
165 mapDiff.insert( std::pair<const char*, obj_cpt_t>( ii.first, diff ) );
173 return QString(
"[%1] instances alive: %2" )
187 QString sResult(
"Start clocking" );
188 if ( ! sMsg.isEmpty() ) {
189 sResult = QString(
"%1: %2" ).arg( sMsg ).arg( sResult );
192 return std::move( sResult );
203 sResult =
"Start clocking";
205 sResult = QString(
"elapsed [%1]ms" )
212 if ( ! sMsg.isEmpty() ) {
213 sResult = QString(
"%1: %2" ).arg( sMsg ).arg( sResult );
216 return std::move( sResult );
220 return os <<
object.toQString(
"",
true ).toLocal8Bit().data() << std::endl;
224 return os <<
object->toQString(
"",
true ).toLocal8Bit().data() << std::endl;
230 qWarning() <<
"Base::registerClass: " << name <<
" null counters!";
239 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)
static Logger * logger()
return the logger instance
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.
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.
void log(unsigned level, const QString &class_name, const char *func_name, const QString &msg)
the log function
bool should_log(unsigned lvl) const
return true if the level is set in the bitmask
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
an objects class map item type
std::atomic< int > constructed