From 9e5433bcf8ba06fe60a595f043ee028ada9d5354 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Sun, 6 Oct 2024 15:23:50 +0800 Subject: [PATCH] Add name to threads This help identifying threads when debugging. The naming scheme is using 'class/function name + variable name'. Note that the length limitaion is 16 chars on linux. On Windows, the limit is 32767 chars. PR #21403. --- src/base/bittorrent/bencoderesumedatastorage.cpp | 1 + src/base/bittorrent/bencoderesumedatastorage.h | 1 - src/base/bittorrent/dbresumedatastorage.cpp | 1 - src/base/bittorrent/dbresumedatastorage.h | 4 ---- src/base/bittorrent/resumedatastorage.cpp | 3 +++ src/base/bittorrent/sessionimpl.cpp | 3 +++ src/base/bittorrent/sessionimpl.h | 1 - src/base/bittorrent/torrentcreationmanager.cpp | 3 +++ src/base/rss/rss_autodownloader.cpp | 1 + src/base/rss/rss_autodownloader.h | 1 - src/base/rss/rss_session.cpp | 1 + src/base/torrentfileswatcher.cpp | 1 + src/base/torrentfileswatcher.h | 2 -- src/gui/properties/propertieswidget.cpp | 1 - src/gui/torrentcontentwidget.cpp | 1 - src/gui/torrentcreatordialog.cpp | 1 + src/gui/uithemedialog.cpp | 4 ++-- src/gui/utils.cpp | 2 ++ src/webui/webapplication.cpp | 1 + 19 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/base/bittorrent/bencoderesumedatastorage.cpp b/src/base/bittorrent/bencoderesumedatastorage.cpp index 43dd414cd..670f36cc3 100644 --- a/src/base/bittorrent/bencoderesumedatastorage.cpp +++ b/src/base/bittorrent/bencoderesumedatastorage.cpp @@ -131,6 +131,7 @@ BitTorrent::BencodeResumeDataStorage::BencodeResumeDataStorage(const Path &path, m_asyncWorker->moveToThread(m_ioThread.get()); connect(m_ioThread.get(), &QThread::finished, m_asyncWorker, &QObject::deleteLater); + m_ioThread->setObjectName("BencodeResumeDataStorage m_ioThread"); m_ioThread->start(); } diff --git a/src/base/bittorrent/bencoderesumedatastorage.h b/src/base/bittorrent/bencoderesumedatastorage.h index 731a35859..38c10d865 100644 --- a/src/base/bittorrent/bencoderesumedatastorage.h +++ b/src/base/bittorrent/bencoderesumedatastorage.h @@ -37,7 +37,6 @@ #include "resumedatastorage.h" class QByteArray; -class QThread; namespace BitTorrent { diff --git a/src/base/bittorrent/dbresumedatastorage.cpp b/src/base/bittorrent/dbresumedatastorage.cpp index c42d68d12..faec89b0a 100644 --- a/src/base/bittorrent/dbresumedatastorage.cpp +++ b/src/base/bittorrent/dbresumedatastorage.cpp @@ -325,7 +325,6 @@ namespace BitTorrent BitTorrent::DBResumeDataStorage::DBResumeDataStorage(const Path &dbPath, QObject *parent) : ResumeDataStorage(dbPath, parent) - , m_ioThread {new QThread} { const bool needCreateDB = !dbPath.exists(); diff --git a/src/base/bittorrent/dbresumedatastorage.h b/src/base/bittorrent/dbresumedatastorage.h index 072813d1f..92f0e6ea1 100644 --- a/src/base/bittorrent/dbresumedatastorage.h +++ b/src/base/bittorrent/dbresumedatastorage.h @@ -34,8 +34,6 @@ #include "base/utils/thread.h" #include "resumedatastorage.h" -class QThread; - namespace BitTorrent { class DBResumeDataStorage final : public ResumeDataStorage @@ -61,8 +59,6 @@ namespace BitTorrent void updateDB(int fromVersion) const; void enableWALMode() const; - Utils::Thread::UniquePtr m_ioThread; - class Worker; Worker *m_asyncWorker = nullptr; diff --git a/src/base/bittorrent/resumedatastorage.cpp b/src/base/bittorrent/resumedatastorage.cpp index 771e7d706..9cb1f6f75 100644 --- a/src/base/bittorrent/resumedatastorage.cpp +++ b/src/base/bittorrent/resumedatastorage.cpp @@ -35,6 +35,8 @@ #include #include +#include "base/global.h" + const int TORRENTIDLIST_TYPEID = qRegisterMetaType>(); BitTorrent::ResumeDataStorage::ResumeDataStorage(const Path &path, QObject *parent) @@ -56,6 +58,7 @@ void BitTorrent::ResumeDataStorage::loadAll() const { doLoadAll(); }); + loadingThread->setObjectName("ResumeDataStorage::loadAll loadingThread"); connect(loadingThread, &QThread::finished, loadingThread, &QObject::deleteLater); loadingThread->start(); } diff --git a/src/base/bittorrent/sessionimpl.cpp b/src/base/bittorrent/sessionimpl.cpp index bde4b1853..2fb8c5816 100644 --- a/src/base/bittorrent/sessionimpl.cpp +++ b/src/base/bittorrent/sessionimpl.cpp @@ -536,6 +536,7 @@ SessionImpl::SessionImpl(QObject *parent) { // It is required to perform async access to libtorrent sequentially m_asyncWorker->setMaxThreadCount(1); + m_asyncWorker->setObjectName("SessionImpl m_asyncWorker"); if (port() < 0) m_port = Utils::Random::rand(1024, 65535); @@ -600,6 +601,7 @@ SessionImpl::SessionImpl(QObject *parent) connect(m_ioThread.get(), &QThread::finished, m_torrentContentRemover, &QObject::deleteLater); connect(m_torrentContentRemover, &TorrentContentRemover::jobFinished, this, &SessionImpl::torrentContentRemovingFinished); + m_ioThread->setObjectName("SessionImpl m_ioThread"); m_ioThread->start(); initMetrics(); @@ -659,6 +661,7 @@ SessionImpl::~SessionImpl() qDebug("Deleting libtorrent session..."); delete nativeSessionProxy; }); + sessionTerminateThread->setObjectName("~SessionImpl sessionTerminateThread"); connect(sessionTerminateThread, &QThread::finished, sessionTerminateThread, &QObject::deleteLater); sessionTerminateThread->start(); if (sessionTerminateThread->wait(shutdownDeadlineTimer)) diff --git a/src/base/bittorrent/sessionimpl.h b/src/base/bittorrent/sessionimpl.h index b1fe4efe0..d83bbb767 100644 --- a/src/base/bittorrent/sessionimpl.h +++ b/src/base/bittorrent/sessionimpl.h @@ -57,7 +57,6 @@ #include "trackerentrystatus.h" class QString; -class QThread; class QThreadPool; class QTimer; class QUrl; diff --git a/src/base/bittorrent/torrentcreationmanager.cpp b/src/base/bittorrent/torrentcreationmanager.cpp index 283a99780..9ff0b531d 100644 --- a/src/base/bittorrent/torrentcreationmanager.cpp +++ b/src/base/bittorrent/torrentcreationmanager.cpp @@ -62,7 +62,10 @@ BitTorrent::TorrentCreationManager::TorrentCreationManager(IApplication *app, QO , m_maxTasks {SETTINGS_KEY(u"MaxTasks"_s), 256} , m_numThreads {SETTINGS_KEY(u"NumThreads"_s), 1} , m_tasks {std::make_unique()} + , m_threadPool(this) { + m_threadPool.setObjectName("TorrentCreationManager m_threadPool"); + if (m_numThreads > 0) m_threadPool.setMaxThreadCount(m_numThreads); } diff --git a/src/base/rss/rss_autodownloader.cpp b/src/base/rss/rss_autodownloader.cpp index c00735559..a365a53ef 100644 --- a/src/base/rss/rss_autodownloader.cpp +++ b/src/base/rss/rss_autodownloader.cpp @@ -123,6 +123,7 @@ AutoDownloader::AutoDownloader(IApplication *app) .arg(fileName.toString(), errorString), Log::CRITICAL); }); + m_ioThread->setObjectName("RSS::AutoDownloader m_ioThread"); m_ioThread->start(); connect(app->addTorrentManager(), &AddTorrentManager::torrentAdded diff --git a/src/base/rss/rss_autodownloader.h b/src/base/rss/rss_autodownloader.h index c70bdbf94..e69877fb8 100644 --- a/src/base/rss/rss_autodownloader.h +++ b/src/base/rss/rss_autodownloader.h @@ -41,7 +41,6 @@ #include "base/settingvalue.h" #include "base/utils/thread.h" -class QThread; class QTimer; class Application; diff --git a/src/base/rss/rss_session.cpp b/src/base/rss/rss_session.cpp index 1aabc7ba3..e91d3d70c 100644 --- a/src/base/rss/rss_session.cpp +++ b/src/base/rss/rss_session.cpp @@ -90,6 +90,7 @@ Session::Session() m_itemsByPath.insert(u""_s, new Folder); // root folder + m_workingThread->setObjectName("RSS::Session m_workingThread"); m_workingThread->start(); load(); diff --git a/src/base/torrentfileswatcher.cpp b/src/base/torrentfileswatcher.cpp index 91f7ef7e7..5fa224d05 100644 --- a/src/base/torrentfileswatcher.cpp +++ b/src/base/torrentfileswatcher.cpp @@ -146,6 +146,7 @@ TorrentFilesWatcher::TorrentFilesWatcher(QObject *parent) m_asyncWorker->moveToThread(m_ioThread.get()); connect(m_ioThread.get(), &QThread::finished, m_asyncWorker, &QObject::deleteLater); + m_ioThread->setObjectName("TorrentFilesWatcher m_ioThread"); m_ioThread->start(); load(); diff --git a/src/base/torrentfileswatcher.h b/src/base/torrentfileswatcher.h index e26196086..9b2361575 100644 --- a/src/base/torrentfileswatcher.h +++ b/src/base/torrentfileswatcher.h @@ -36,8 +36,6 @@ #include "base/path.h" #include "base/utils/thread.h" -class QThread; - /* * Watches the configured directories for new .torrent files in order * to add torrents to BitTorrent session. Supports Network File System diff --git a/src/gui/properties/propertieswidget.cpp b/src/gui/properties/propertieswidget.cpp index 664a4cf44..d5c2b03a4 100644 --- a/src/gui/properties/propertieswidget.cpp +++ b/src/gui/properties/propertieswidget.cpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include "base/bittorrent/infohash.h" diff --git a/src/gui/torrentcontentwidget.cpp b/src/gui/torrentcontentwidget.cpp index 59c401871..ebafe0dfa 100644 --- a/src/gui/torrentcontentwidget.cpp +++ b/src/gui/torrentcontentwidget.cpp @@ -37,7 +37,6 @@ #include #include #include -#include #include #include "base/bittorrent/torrentcontenthandler.h" diff --git a/src/gui/torrentcreatordialog.cpp b/src/gui/torrentcreatordialog.cpp index d6b5bdf53..3e1c24f9c 100644 --- a/src/gui/torrentcreatordialog.cpp +++ b/src/gui/torrentcreatordialog.cpp @@ -109,6 +109,7 @@ TorrentCreatorDialog::TorrentCreatorDialog(QWidget *parent, const Path &defaultP updateInputPath(defaultPath); m_threadPool.setMaxThreadCount(1); + m_threadPool.setObjectName("TorrentCreatorDialog m_threadPool"); #ifdef QBT_USES_LIBTORRENT2 m_ui->checkOptimizeAlignment->hide(); diff --git a/src/gui/uithemedialog.cpp b/src/gui/uithemedialog.cpp index ff3980542..24ee381da 100644 --- a/src/gui/uithemedialog.cpp +++ b/src/gui/uithemedialog.cpp @@ -75,7 +75,7 @@ public: , m_defaultColor {defaultColor} , m_currentColor {currentColor} { - setObjectName(u"colorWidget"_s); + setObjectName("colorWidget"); setFrameShape(QFrame::Box); setFrameShadow(QFrame::Plain); setAlignment(Qt::AlignCenter); @@ -159,7 +159,7 @@ public: : QLabel(parent) , m_defaultPath {defaultPath} { - setObjectName(u"iconWidget"_s); + setObjectName("iconWidget"); setAlignment(Qt::AlignCenter); setCurrentPath(currentPath); diff --git a/src/gui/utils.cpp b/src/gui/utils.cpp index 91e8d3803..3b3a809cc 100644 --- a/src/gui/utils.cpp +++ b/src/gui/utils.cpp @@ -134,6 +134,7 @@ void Utils::Gui::openPath(const Path &path) ::CoUninitialize(); } }); + thread->setObjectName("Utils::Gui::openPath thread"); QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater); thread->start(); #else @@ -168,6 +169,7 @@ void Utils::Gui::openFolderSelect(const Path &path) ::CoUninitialize(); } }); + thread->setObjectName("Utils::Gui::openFolderSelect thread"); QObject::connect(thread, &QThread::finished, thread, &QObject::deleteLater); thread->start(); #elif defined(Q_OS_UNIX) && !defined(Q_OS_MACOS) diff --git a/src/webui/webapplication.cpp b/src/webui/webapplication.cpp index ddcf39176..d556e6cc3 100644 --- a/src/webui/webapplication.cpp +++ b/src/webui/webapplication.cpp @@ -184,6 +184,7 @@ WebApplication::WebApplication(IApplication *app, QObject *parent) m_freeDiskSpaceChecker->moveToThread(m_workerThread.get()); connect(m_workerThread.get(), &QThread::finished, m_freeDiskSpaceChecker, &QObject::deleteLater); + m_workerThread->setObjectName("WebApplication m_workerThread"); m_workerThread->start(); m_freeDiskSpaceCheckingTimer->setInterval(FREEDISKSPACE_CHECK_TIMEOUT);