From 7cbbb1d933147e9de7f0f97ee54e8bcca0620c19 Mon Sep 17 00:00:00 2001 From: Klaus Basan Date: Thu, 23 Aug 2018 01:47:47 +0200 Subject: [PATCH] Improved thread info (for debugging) --- src/blackcore/db/backgrounddataupdater.cpp | 6 ++++-- src/blackcore/db/databasereader.cpp | 4 ++-- src/blackmisc/threadutils.cpp | 14 ++++++++++++++ src/blackmisc/threadutils.h | 6 ++++++ 4 files changed, 26 insertions(+), 4 deletions(-) diff --git a/src/blackcore/db/backgrounddataupdater.cpp b/src/blackcore/db/backgrounddataupdater.cpp index a99b38e58..9cd56aad6 100644 --- a/src/blackcore/db/backgrounddataupdater.cpp +++ b/src/blackcore/db/backgrounddataupdater.cpp @@ -173,11 +173,13 @@ namespace BlackCore if (!latestDbTs.isValid()) { return; } if (latestDbTs <= latestCacheTs) { - this->addHistory(CLogMessage(this).info("Background updater, no auto sync with DB, entity '%1', DB ts: %2 cache ts: %3") << entityStr << latestDbTs.toString(Qt::ISODate) << latestCacheTsStr); + this->addHistory(CLogMessage(this).info("Background updater (%1), no auto synchronization with DB, entity '%2', DB ts: %3 cache ts: %4") + << CThreadUtils::currentThreadInfo() << entityStr << latestDbTs.toString(Qt::ISODate) << latestCacheTsStr); return; } - this->addHistory(CLogMessage(this).info("Background updater triggering read of '%1' since '%2'") << entityStr << latestCacheTsStr); + this->addHistory(CLogMessage(this).info("Background updater (%1) triggering read of '%2' since '%3'") + << CThreadUtils::currentThreadInfo() << entityStr << latestCacheTsStr); sApp->getWebDataServices()->triggerLoadingDirectlyFromDb(entity, latestCacheTs); } diff --git a/src/blackcore/db/databasereader.cpp b/src/blackcore/db/databasereader.cpp index 6cfedc114..ceb1bbcb3 100644 --- a/src/blackcore/db/databasereader.cpp +++ b/src/blackcore/db/databasereader.cpp @@ -668,9 +668,9 @@ namespace BlackCore void CDatabaseReader::logParseMessage(const QString &entity, int size, int msElapsed, const CDatabaseReader::JsonDatastoreResponse &response) const { - CLogMessage(this).info("Parsed %1 %2 in %3ms, thread '%4' | '%5'") + CLogMessage(this).info("Parsed %1 %2 in %3ms, thread %4 | '%5'") << size << entity << msElapsed - << QThread::currentThread()->objectName() << response.toQString(); + << CThreadUtils::currentThreadInfo() << response.toQString(); } QString CDatabaseReader::fileNameForMode(CEntityFlags::Entity entity, CDbFlags::DataRetrievalModeFlag mode) diff --git a/src/blackmisc/threadutils.cpp b/src/blackmisc/threadutils.cpp index 3b65d9919..e5fc31c2a 100644 --- a/src/blackmisc/threadutils.cpp +++ b/src/blackmisc/threadutils.cpp @@ -61,4 +61,18 @@ namespace BlackMisc static const QString unknown("unknown"); return unknown; } + + const QString CThreadUtils::threadToString(const void *t) + { + static const QString s("0x%1"); + return s.arg(reinterpret_cast(t), 0, 16); + } + + const QString CThreadUtils::currentThreadInfo() + { + static const QString info("thread: %1 name: '%2' priority: '%3'"); + const QThread *t = QThread::currentThread(); + if (!t) { return QString("no thread"); } + return info.arg(threadToString(t), t->objectName(), priorityToString(t->priority())); + } } // ns diff --git a/src/blackmisc/threadutils.h b/src/blackmisc/threadutils.h index 30aa9bb04..9857ba141 100644 --- a/src/blackmisc/threadutils.h +++ b/src/blackmisc/threadutils.h @@ -40,6 +40,12 @@ namespace BlackMisc //! Priority to string static const QString &priorityToString(QThread::Priority priority); + + //! Thread to int string info + static const QString threadToString(const void *t); + + //! Info about current thread + static const QString currentThreadInfo(); }; } // ns