From 142889e3a58bce2bcb404029d92e14be347f7d83 Mon Sep 17 00:00:00 2001 From: Ivan Savenko Date: Sun, 20 Aug 2023 23:09:17 +0300 Subject: [PATCH] Give all threads created by client human-readable name for debug --- client/CMT.cpp | 12 +++++++++--- client/CPlayerInterface.cpp | 3 +++ client/CServerHandler.cpp | 4 ++-- client/adventureMap/CInGameConsole.cpp | 2 ++ client/battle/BattleInterface.cpp | 2 ++ client/mainmenu/CMainMenu.cpp | 2 +- 6 files changed, 19 insertions(+), 6 deletions(-) diff --git a/client/CMT.cpp b/client/CMT.cpp index 1a06bb913..fcf9a0e80 100644 --- a/client/CMT.cpp +++ b/client/CMT.cpp @@ -27,11 +27,12 @@ #include "render/IScreenHandler.h" #include "render/Graphics.h" -#include "../lib/filesystem/Filesystem.h" +#include "../lib/CConfigHandler.h" #include "../lib/CGeneralTextHandler.h" +#include "../lib/CThreadHelper.h" #include "../lib/VCMIDirs.h" #include "../lib/VCMI_Lib.h" -#include "../lib/CConfigHandler.h" +#include "../lib/filesystem/Filesystem.h" #include "../lib/logging/CBasicLogConfigurator.h" @@ -297,7 +298,11 @@ int main(int argc, char * argv[]) #ifndef VCMI_NO_THREADED_LOAD //we can properly play intro only in the main thread, so we have to move loading to the separate thread - boost::thread loading(init); + boost::thread loading([]() + { + setThreadName("initialize"); + init(); + }); #else init(); #endif @@ -429,6 +434,7 @@ void playIntro() static void mainLoop() { + setThreadName("MainGUI"); inGuiThread.reset(new bool(true)); while(1) //main SDL events loop diff --git a/client/CPlayerInterface.cpp b/client/CPlayerInterface.cpp index 1e3e25275..d98f72fad 100644 --- a/client/CPlayerInterface.cpp +++ b/client/CPlayerInterface.cpp @@ -76,6 +76,7 @@ #include "../lib/UnlockGuard.h" #include "../lib/RoadHandler.h" #include "../lib/TerrainHandler.h" +#include "../lib/CThreadHelper.h" #include "CServerHandler.h" // FIXME: only needed for CGameState::mutex #include "../lib/gameState/CGameState.h" @@ -1933,6 +1934,8 @@ void CPlayerInterface::setMovementStatus(bool value) void CPlayerInterface::doMoveHero(const CGHeroInstance * h, CGPath path) { + setThreadName("doMoveHero"); + int i = 1; auto getObj = [&](int3 coord, bool ignoreHero) { diff --git a/client/CServerHandler.cpp b/client/CServerHandler.cpp index ea6c3fbae..2a992b9f0 100644 --- a/client/CServerHandler.cpp +++ b/client/CServerHandler.cpp @@ -817,7 +817,7 @@ public: void CServerHandler::threadHandleConnection() { - setThreadName("CServerHandler::threadHandleConnection"); + setThreadName("threadHandleConnection"); c->enterLobbyConnectionMode(); try @@ -898,7 +898,7 @@ void CServerHandler::visitForClient(CPackForClient & clientPack) void CServerHandler::threadRunServer() { #if !defined(VCMI_MOBILE) - setThreadName("CServerHandler::threadRunServer"); + setThreadName("threadRunServer"); const std::string logName = (VCMIDirs::get().userLogsPath() / "server_log.txt").string(); std::string comm = VCMIDirs::get().serverPath().string() + " --port=" + std::to_string(getHostPort()) diff --git a/client/adventureMap/CInGameConsole.cpp b/client/adventureMap/CInGameConsole.cpp index 3236a5bc2..8ab4aa479 100644 --- a/client/adventureMap/CInGameConsole.cpp +++ b/client/adventureMap/CInGameConsole.cpp @@ -27,6 +27,7 @@ #include "../../CCallback.h" #include "../../lib/CConfigHandler.h" +#include "../../lib/CThreadHelper.h" #include "../../lib/TextOperations.h" #include "../../lib/mapObjects/CArmedInstance.h" @@ -255,6 +256,7 @@ void CInGameConsole::endEnteringText(bool processEnteredText) //some commands like gosolo don't work when executed from GUI thread auto threadFunction = [=]() { + setThreadName("processCommand"); ClientCommandManager commandController; commandController.processCommand(txt.substr(1), true); }; diff --git a/client/battle/BattleInterface.cpp b/client/battle/BattleInterface.cpp index c21af7bf2..dc1ff5161 100644 --- a/client/battle/BattleInterface.cpp +++ b/client/battle/BattleInterface.cpp @@ -43,6 +43,7 @@ #include "../../lib/NetPacks.h" #include "../../lib/UnlockGuard.h" #include "../../lib/TerrainHandler.h" +#include "../../lib/CThreadHelper.h" BattleInterface::BattleInterface(const CCreatureSet *army1, const CCreatureSet *army2, const CGHeroInstance *hero1, const CGHeroInstance *hero2, @@ -731,6 +732,7 @@ void BattleInterface::requestAutofightingAIToTakeAction() // HOWEVER this thread won't atttempt to lock game state, potentially leading to races boost::thread aiThread([this, activeStack]() { + setThreadName("autofightingAI"); curInt->autofightingAI->activeStack(activeStack); }); aiThread.detach(); diff --git a/client/mainmenu/CMainMenu.cpp b/client/mainmenu/CMainMenu.cpp index ea2bdb93f..68cf793bf 100644 --- a/client/mainmenu/CMainMenu.cpp +++ b/client/mainmenu/CMainMenu.cpp @@ -567,7 +567,7 @@ void CSimpleJoinScreen::startConnectThread(const std::string & addr, ui16 port) void CSimpleJoinScreen::connectThread(const std::string & addr, ui16 port) { - setThreadName("CSimpleJoinScreen::connectThread"); + setThreadName("connectThread"); if(!addr.length()) CSH->startLocalServerAndConnect(); else