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.
This commit is contained in:
Chocobo1
2024-10-06 15:23:50 +08:00
committed by GitHub
parent 3fb5d7764c
commit 9e5433bcf8
19 changed files with 19 additions and 14 deletions

View File

@@ -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();
}

View File

@@ -37,7 +37,6 @@
#include "resumedatastorage.h"
class QByteArray;
class QThread;
namespace BitTorrent
{

View File

@@ -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();

View File

@@ -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;

View File

@@ -35,6 +35,8 @@
#include <QMutexLocker>
#include <QThread>
#include "base/global.h"
const int TORRENTIDLIST_TYPEID = qRegisterMetaType<QList<BitTorrent::TorrentID>>();
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();
}

View File

@@ -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))

View File

@@ -57,7 +57,6 @@
#include "trackerentrystatus.h"
class QString;
class QThread;
class QThreadPool;
class QTimer;
class QUrl;

View File

@@ -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<TaskSet>()}
, m_threadPool(this)
{
m_threadPool.setObjectName("TorrentCreationManager m_threadPool");
if (m_numThreads > 0)
m_threadPool.setMaxThreadCount(m_numThreads);
}

View File

@@ -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

View File

@@ -41,7 +41,6 @@
#include "base/settingvalue.h"
#include "base/utils/thread.h"
class QThread;
class QTimer;
class Application;

View File

@@ -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();

View File

@@ -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();

View File

@@ -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