name all the threads

This commit is contained in:
HifiExperiments 2021-02-13 20:17:28 -08:00
parent c869554d46
commit 30c4779eeb
19 changed files with 85 additions and 25 deletions

1
.gitignore vendored
View file

@ -111,3 +111,4 @@ tools/unity-avatar-exporter
server-console/package-lock.json server-console/package-lock.json
vcpkg/ vcpkg/
/tools/nitpick/compiledResources /tools/nitpick/compiledResources
qt/

View file

@ -33,6 +33,7 @@
#include <Trace.h> #include <Trace.h>
#include <StatTracker.h> #include <StatTracker.h>
#include <ThreadHelpers.h>
#include "AssignmentClientLogging.h" #include "AssignmentClientLogging.h"
#include "AssignmentFactory.h" #include "AssignmentFactory.h"
@ -235,10 +236,13 @@ void AssignmentClient::handleCreateAssignmentPacket(QSharedPointer<ReceivedMessa
qCDebug(assignment_client) << "Destination IP for assignment is" << nodeList->getDomainHandler().getIP().toString(); qCDebug(assignment_client) << "Destination IP for assignment is" << nodeList->getDomainHandler().getIP().toString();
// start the deployed assignment // start the deployed assignment
QThread* workerThread = new QThread; QThread* workerThread = new QThread();
workerThread->setObjectName("ThreadedAssignment Worker"); workerThread->setObjectName("ThreadedAssignment Worker");
connect(workerThread, &QThread::started, _currentAssignment.data(), &ThreadedAssignment::run); connect(workerThread, &QThread::started, _currentAssignment.data(), [this] {
setThreadName("ThreadedAssignment Worker");
_currentAssignment->run();
});
// Once the ThreadedAssignment says it is finished - we ask it to deleteLater // Once the ThreadedAssignment says it is finished - we ask it to deleteLater
// This is a queued connection so that it is put into the event loop to be processed by the worker // This is a queued connection so that it is put into the event loop to be processed by the worker

View file

@ -11,9 +11,13 @@
#include "AudioMixerSlavePool.h" #include "AudioMixerSlavePool.h"
#include <QObject>
#include <assert.h> #include <assert.h>
#include <algorithm> #include <algorithm>
#include <ThreadHelpers.h>
void AudioMixerSlaveThread::run() { void AudioMixerSlaveThread::run() {
while (true) { while (true) {
wait(); wait();
@ -157,6 +161,7 @@ void AudioMixerSlavePool::resize(int numThreads) {
// start new slaves // start new slaves
for (int i = 0; i < numThreads - _numThreads; ++i) { for (int i = 0; i < numThreads - _numThreads; ++i) {
auto slave = new AudioMixerSlaveThread(*this, _workerSharedData); auto slave = new AudioMixerSlaveThread(*this, _workerSharedData);
QObject::connect(slave, &QThread::started, [] { setThreadName("AudioMixerSlaveThread"); });
slave->start(); slave->start();
_slaves.emplace_back(slave); _slaves.emplace_back(slave);
} }

View file

@ -34,6 +34,7 @@
#include <QtCore/QDir> #include <QtCore/QDir>
#include <OctreeDataUtils.h> #include <OctreeDataUtils.h>
#include <ThreadHelpers.h>
Q_LOGGING_CATEGORY(octree_server, "hifi.octree-server") Q_LOGGING_CATEGORY(octree_server, "hifi.octree-server")
@ -1192,7 +1193,10 @@ void OctreeServer::domainSettingsRequestComplete() {
_persistAsFileType); _persistAsFileType);
_persistManager->moveToThread(&_persistThread); _persistManager->moveToThread(&_persistThread);
connect(&_persistThread, &QThread::finished, _persistManager, &QObject::deleteLater); connect(&_persistThread, &QThread::finished, _persistManager, &QObject::deleteLater);
connect(&_persistThread, &QThread::started, _persistManager, &OctreePersistThread::start); connect(&_persistThread, &QThread::started, _persistManager, [this] {
setThreadName("OctreePersistThread");
_persistManager->start();
});
connect(_persistManager, &OctreePersistThread::loadCompleted, this, [this]() { connect(_persistManager, &OctreePersistThread::loadCompleted, this, [this]() {
beginRunning(); beginRunning();
}); });

View file

@ -60,6 +60,7 @@
#include <Gzip.h> #include <Gzip.h>
#include <OctreeDataUtils.h> #include <OctreeDataUtils.h>
#include <ThreadHelpers.h>
using namespace std::chrono; using namespace std::chrono;
@ -830,9 +831,11 @@ void DomainServer::setupNodeListAndAssignments() {
// set a custom packetVersionMatch as the verify packet operator for the udt::Socket // set a custom packetVersionMatch as the verify packet operator for the udt::Socket
nodeList->setPacketFilterOperator(&DomainServer::isPacketVerified); nodeList->setPacketFilterOperator(&DomainServer::isPacketVerified);
_assetClientThread.setObjectName("AssetClient Thread"); QString name = "AssetClient Thread";
_assetClientThread.setObjectName(name);
auto assetClient = DependencyManager::set<AssetClient>(); auto assetClient = DependencyManager::set<AssetClient>();
assetClient->moveToThread(&_assetClientThread); assetClient->moveToThread(&_assetClientThread);
connect(&_assetClientThread, &QThread::started, [name] { setThreadName(name.toStdString()); });
_assetClientThread.start(); _assetClientThread.start();
// add whatever static assignments that have been parsed to the queue // add whatever static assignments that have been parsed to the queue
addStaticAssignmentsToQueue(); addStaticAssignmentsToQueue();

View file

@ -254,6 +254,7 @@
#include "AboutUtil.h" #include "AboutUtil.h"
#include "ExternalResource.h" #include "ExternalResource.h"
#include <ThreadHelpers.h>
#if defined(Q_OS_WIN) #if defined(Q_OS_WIN)
#include <VersionHelpers.h> #include <VersionHelpers.h>
@ -1168,6 +1169,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer& startupTimer, bo
if (!DISABLE_WATCHDOG) { if (!DISABLE_WATCHDOG) {
auto deadlockWatchdogThread = new DeadlockWatchdogThread(); auto deadlockWatchdogThread = new DeadlockWatchdogThread();
deadlockWatchdogThread->setMainThreadID(QThread::currentThreadId()); deadlockWatchdogThread->setMainThreadID(QThread::currentThreadId());
connect(deadlockWatchdogThread, &QThread::started, [] { setThreadName("DeadlockWatchdogThread"); });
deadlockWatchdogThread->start(); deadlockWatchdogThread->start();
// Pause the deadlock watchdog when we sleep, or it might // Pause the deadlock watchdog when we sleep, or it might
@ -5206,6 +5208,7 @@ void getCpuUsage(vec3& systemAndUser) {
void setupCpuMonitorThread() { void setupCpuMonitorThread() {
initCpuUsage(); initCpuUsage();
auto cpuMonitorThread = QThread::currentThread(); auto cpuMonitorThread = QThread::currentThread();
setThreadName("CPU Monitor Thread");
QTimer* timer = new QTimer(); QTimer* timer = new QTimer();
timer->setInterval(50); timer->setInterval(50);

View file

@ -15,6 +15,7 @@
#include <SharedUtil.h> #include <SharedUtil.h>
#include <shared/QtHelpers.h> #include <shared/QtHelpers.h>
#include <ThreadHelpers.h>
#include "AudioConstants.h" #include "AudioConstants.h"
#include "AudioInjector.h" #include "AudioInjector.h"
@ -54,11 +55,14 @@ AudioInjectorManager::~AudioInjectorManager() {
} }
void AudioInjectorManager::createThread() { void AudioInjectorManager::createThread() {
_thread = new QThread; _thread = new QThread();
_thread->setObjectName("Audio Injector Thread"); _thread->setObjectName("Audio Injector Thread");
// when the thread is started, have it call our run to handle injection of audio // when the thread is started, have it call our run to handle injection of audio
connect(_thread, &QThread::started, this, &AudioInjectorManager::run, Qt::DirectConnection); connect(_thread, &QThread::started, this, [this] {
setThreadName("AudioInjectorManager");
run();
}, Qt::DirectConnection);
moveToThread(_thread); moveToThread(_thread);

View file

@ -50,6 +50,7 @@
#include "CompositorHelper.h" #include "CompositorHelper.h"
#include "Logging.h" #include "Logging.h"
#include "RefreshRateController.h" #include "RefreshRateController.h"
#include <ThreadHelpers.h>
using namespace shader::gpu::program; using namespace shader::gpu::program;
@ -285,6 +286,7 @@ bool OpenGLDisplayPlugin::activate() {
widget->context()->doneCurrent(); widget->context()->doneCurrent();
presentThread->setContext(widget->context()); presentThread->setContext(widget->context());
connect(presentThread.data(), &QThread::started, [] { setThreadName("OpenGL Present Thread"); });
// Start execution // Start execution
presentThread->start(); presentThread->start();
} }

View file

@ -8,8 +8,10 @@
#include "GLTexture.h" #include "GLTexture.h"
#include <QObject>
#include <QtCore/QThread> #include <QtCore/QThread>
#include <NumericalConstants.h> #include <NumericalConstants.h>
#include <ThreadHelpers.h>
#include "GLBackend.h" #include "GLBackend.h"
@ -64,7 +66,7 @@ public:
protected: protected:
class TextureBufferThread : public QThread { class TextureBufferThread : public QThread {
public: public:
TextureBufferThread(GLTextureTransferEngineDefault& parent) : _parent(parent) { start(); } TextureBufferThread(GLTextureTransferEngineDefault& parent) : _parent(parent) {}
protected: protected:
void run() override { void run() override {
@ -302,6 +304,8 @@ void GLTextureTransferEngineDefault::processTransferQueues() {
#if THREADED_TEXTURE_BUFFERING #if THREADED_TEXTURE_BUFFERING
if (!_transferThread) { if (!_transferThread) {
_transferThread = new TextureBufferThread(*this); _transferThread = new TextureBufferThread(*this);
QObject::connect(_transferThread, &QThread::started, [] { setThreadName("TextureBufferThread"); });
_transferThread->start();
} }
#endif #endif

View file

@ -19,6 +19,7 @@
#include <QFileInfo> #include <QFileInfo>
#include <SharedUtil.h> #include <SharedUtil.h>
#include <ThreadHelpers.h>
#include "AssetResourceRequest.h" #include "AssetResourceRequest.h"
#include "FileResourceRequest.h" #include "FileResourceRequest.h"
@ -28,12 +29,16 @@
#include "NetworkingConstants.h" #include "NetworkingConstants.h"
ResourceManager::ResourceManager(bool atpSupportEnabled) : _atpSupportEnabled(atpSupportEnabled) { ResourceManager::ResourceManager(bool atpSupportEnabled) : _atpSupportEnabled(atpSupportEnabled) {
_thread.setObjectName("Resource Manager Thread"); QString name = "Resource Manager Thread";
_thread.setObjectName(name);
if (_atpSupportEnabled) { if (_atpSupportEnabled) {
auto assetClient = DependencyManager::set<AssetClient>(); auto assetClient = DependencyManager::set<AssetClient>();
assetClient->moveToThread(&_thread); assetClient->moveToThread(&_thread);
QObject::connect(&_thread, &QThread::started, assetClient.data(), &AssetClient::initCaching); QObject::connect(&_thread, &QThread::started, assetClient.data(), [assetClient, name] {
setThreadName(name.toStdString());
assetClient->initCaching();
});
} }
_thread.start(); _thread.start();

View file

@ -31,6 +31,7 @@
#include "Socket.h" #include "Socket.h"
#include <Trace.h> #include <Trace.h>
#include <Profile.h> #include <Profile.h>
#include <ThreadHelpers.h>
#include "../NetworkLogging.h" #include "../NetworkLogging.h"
@ -67,24 +68,26 @@ const microseconds SendQueue::MINIMUM_ESTIMATED_TIMEOUT = milliseconds(10);
std::unique_ptr<SendQueue> SendQueue::create(Socket* socket, HifiSockAddr destination, SequenceNumber currentSequenceNumber, std::unique_ptr<SendQueue> SendQueue::create(Socket* socket, HifiSockAddr destination, SequenceNumber currentSequenceNumber,
MessageNumber currentMessageNumber, bool hasReceivedHandshakeACK) { MessageNumber currentMessageNumber, bool hasReceivedHandshakeACK) {
Q_ASSERT_X(socket, "SendQueue::create", "Must be called with a valid Socket*"); Q_ASSERT_X(socket, "SendQueue::create", "Must be called with a valid Socket*");
auto queue = std::unique_ptr<SendQueue>(new SendQueue(socket, destination, currentSequenceNumber, auto queue = std::unique_ptr<SendQueue>(new SendQueue(socket, destination, currentSequenceNumber,
currentMessageNumber, hasReceivedHandshakeACK)); currentMessageNumber, hasReceivedHandshakeACK));
// Setup queue private thread // Setup queue private thread
QThread* thread = new QThread; QThread* thread = new QThread();
thread->setObjectName("Networking: SendQueue " + destination.objectName()); // Name thread for easier debug QString name = "Networking: SendQueue " + destination.objectName();
thread->setObjectName(name); // Name thread for easier debug
connect(thread, &QThread::started, [name] { setThreadName(name.toStdString()); });
connect(thread, &QThread::started, queue.get(), &SendQueue::run); connect(thread, &QThread::started, queue.get(), &SendQueue::run);
connect(queue.get(), &QObject::destroyed, thread, &QThread::quit); // Thread auto cleanup connect(queue.get(), &QObject::destroyed, thread, &QThread::quit); // Thread auto cleanup
connect(thread, &QThread::finished, thread, &QThread::deleteLater); // Thread auto cleanup connect(thread, &QThread::finished, thread, &QThread::deleteLater); // Thread auto cleanup
// Move queue to private thread and start it // Move queue to private thread and start it
queue->moveToThread(thread); queue->moveToThread(thread);
thread->start(); thread->start();
return queue; return queue;
} }

View file

@ -29,6 +29,7 @@
#include "RenderControl.h" #include "RenderControl.h"
#include "RenderEventHandler.h" #include "RenderEventHandler.h"
#include "TextureCache.h" #include "TextureCache.h"
#include <ThreadHelpers.h>
// Time between receiving a request to render the offscreen UI actually triggering // Time between receiving a request to render the offscreen UI actually triggering
// the render. Could possibly be increased depending on the framerate we expect to // the render. Could possibly be increased depending on the framerate we expect to
@ -162,7 +163,9 @@ void SharedObject::setRootItem(QQuickItem* rootItem) {
// Create the render thread // Create the render thread
_renderThread = new QThread(); _renderThread = new QThread();
_renderThread->setObjectName(objectName()); QString name = objectName();
_renderThread->setObjectName(name);
QObject::connect(_renderThread, &QThread::started, [name] { setThreadName("QML SharedObject " + name.toStdString()); });
_renderThread->start(); _renderThread->start();
// Create event handler for the render thread // Create event handler for the render thread

View file

@ -87,7 +87,7 @@
#include "SettingHandle.h" #include "SettingHandle.h"
#include <AddressManager.h> #include <AddressManager.h>
#include <NetworkingConstants.h> #include <NetworkingConstants.h>
#include <ThreadHelpers.h>
const QString ScriptEngine::_SETTINGS_ENABLE_EXTENDED_EXCEPTIONS { const QString ScriptEngine::_SETTINGS_ENABLE_EXTENDED_EXCEPTIONS {
"com.highfidelity.experimental.enableExtendedJSExceptions" "com.highfidelity.experimental.enableExtendedJSExceptions"
@ -429,13 +429,17 @@ void ScriptEngine::runInThread() {
// The thread interface cannot live on itself, and we want to move this into the thread, so // The thread interface cannot live on itself, and we want to move this into the thread, so
// the thread cannot have this as a parent. // the thread cannot have this as a parent.
QThread* workerThread = new QThread(); QThread* workerThread = new QThread();
workerThread->setObjectName(QString("js:") + getFilename().replace("about:","")); QString name = QString("js:") + getFilename().replace("about:","");
workerThread->setObjectName(name);
moveToThread(workerThread); moveToThread(workerThread);
// NOTE: If you connect any essential signals for proper shutdown or cleanup of // NOTE: If you connect any essential signals for proper shutdown or cleanup of
// the script engine, make sure to add code to "reconnect" them to the // the script engine, make sure to add code to "reconnect" them to the
// disconnectNonEssentialSignals() method // disconnectNonEssentialSignals() method
connect(workerThread, &QThread::started, this, &ScriptEngine::run); connect(workerThread, &QThread::started, this, [this, name] {
setThreadName(name.toStdString());
run();
});
connect(this, &QObject::destroyed, workerThread, &QThread::quit); connect(this, &QObject::destroyed, workerThread, &QThread::quit);
connect(workerThread, &QThread::finished, workerThread, &QObject::deleteLater); connect(workerThread, &QThread::finished, workerThread, &QObject::deleteLater);

View file

@ -14,6 +14,8 @@
#include <QDebug> #include <QDebug>
#include <QtCore/QCoreApplication> #include <QtCore/QCoreApplication>
#include "ThreadHelpers.h"
GenericThread::GenericThread() : GenericThread::GenericThread() :
_stopThread(false), _stopThread(false),
_isThreaded(false) // assume non-threaded, must call initialize() _isThreaded(false) // assume non-threaded, must call initialize()
@ -36,8 +38,11 @@ void GenericThread::initialize(bool isThreaded, QThread::Priority priority) {
// match the thread name to our object name // match the thread name to our object name
_thread->setObjectName(objectName()); _thread->setObjectName(objectName());
connect(_thread, &QThread::started, this, &GenericThread::started); connect(_thread, &QThread::started, this, [this] {
connect(_thread, &QThread::started, this, &GenericThread::threadRoutine); setThreadName("Generic thread " + objectName().toStdString());
started();
threadRoutine();
});
connect(_thread, &QThread::finished, this, &GenericThread::finished); connect(_thread, &QThread::finished, this, &GenericThread::finished);
moveToThread(_thread); moveToThread(_thread);

View file

@ -21,6 +21,7 @@
#include "SettingManager.h" #include "SettingManager.h"
#include "SharedLogging.h" #include "SharedLogging.h"
#include "SharedUtil.h" #include "SharedUtil.h"
#include "ThreadHelpers.h"
namespace Setting { namespace Setting {
// This should only run as a post-routine in the QCoreApplication destructor // This should only run as a post-routine in the QCoreApplication destructor
@ -53,7 +54,10 @@ namespace Setting {
thread->setObjectName("Settings Thread"); thread->setObjectName("Settings Thread");
// Setup setting periodical save timer // Setup setting periodical save timer
QObject::connect(thread, &QThread::started, globalManager.data(), &Manager::startTimer); QObject::connect(thread, &QThread::started, globalManager.data(), [globalManager] {
setThreadName("Settings Save Thread");
globalManager->startTimer();
});
QObject::connect(thread, &QThread::finished, globalManager.data(), &Manager::stopTimer); QObject::connect(thread, &QThread::finished, globalManager.data(), &Manager::stopTimer);
// Setup manager threading affinity // Setup manager threading affinity

View file

@ -32,6 +32,8 @@ void withLock(QMutex& lock, F function) {
function(); function();
} }
void setThreadName(const std::string& name);
void moveToNewNamedThread(QObject* object, const QString& name, void moveToNewNamedThread(QObject* object, const QString& name,
std::function<void(QThread*)> preStartCallback, std::function<void(QThread*)> preStartCallback,
std::function<void()> startCallback, std::function<void()> startCallback,

View file

@ -595,7 +595,7 @@ void TabletProxy::gotoMenuScreen(const QString& submenu) {
} }
void TabletProxy::loadQMLOnTopImpl(const QVariant& path, bool localSafeContext) { void TabletProxy::loadQMLOnTopImpl(const QVariant& path, bool localSafeContext) {
if (QThread::currentThread() != thread()) { if (QThread::currentThread() != thread()) {
qCWarning(uiLogging) << __FUNCTION__ << "may not be called directly by scripts"; qCWarning(uiLogging) << __FUNCTION__ << "may not be called directly by scripts";
return; return;
} }

View file

@ -31,6 +31,7 @@
#include <display-plugins/CompositorHelper.h> #include <display-plugins/CompositorHelper.h>
#include <ui-plugins/PluginContainer.h> #include <ui-plugins/PluginContainer.h>
#include <gl/OffscreenGLCanvas.h> #include <gl/OffscreenGLCanvas.h>
#include <ThreadHelpers.h>
#include "OpenVrHelpers.h" #include "OpenVrHelpers.h"
@ -494,6 +495,7 @@ bool OpenVrDisplayPlugin::internalActivate() {
_submitCanvas->doneCurrent(); _submitCanvas->doneCurrent();
}); });
} }
connect(_submitThread.get(), &QThread::started, [] { setThreadName("OpenVR Submit Thread"); });
_submitCanvas->moveToThread(_submitThread.get()); _submitCanvas->moveToThread(_submitThread.get());
} }

View file

@ -49,6 +49,7 @@
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
#include <ui-plugins/PluginContainer.h> #include <ui-plugins/PluginContainer.h>
#include <plugins/DisplayPlugin.h> #include <plugins/DisplayPlugin.h>
#include <ThreadHelpers.h>
#include <controllers/UserInputMapper.h> #include <controllers/UserInputMapper.h>
#include <plugins/InputConfiguration.h> #include <plugins/InputConfiguration.h>
@ -403,6 +404,7 @@ bool ViveControllerManager::activate() {
if (_viveProEye) { if (_viveProEye) {
_viveProEyeReadThread = std::make_shared<ViveProEyeReadThread>(); _viveProEyeReadThread = std::make_shared<ViveProEyeReadThread>();
connect(_viveProEyeReadThread.get(), &QThread::started, [] { setThreadName("ViveProEyeReadThread"); });
_viveProEyeReadThread->start(QThread::HighPriority); _viveProEyeReadThread->start(QThread::HighPriority);
} }
} }