Added some thread names

This commit is contained in:
emeric
2024-03-09 22:23:02 +01:00
parent 65d95060b0
commit 9c8844d866
4 changed files with 21 additions and 7 deletions
@@ -244,7 +244,7 @@ namespace Scanner
ScanStepScanFiles::MetadataScanQueue::MetadataScanQueue(MetaData::IParser& parser, std::size_t threadCount, bool& abort) ScanStepScanFiles::MetadataScanQueue::MetadataScanQueue(MetaData::IParser& parser, std::size_t threadCount, bool& abort)
: _metadataParser{ parser } : _metadataParser{ parser }
, _scanContextRunner{ _scanContext, threadCount } , _scanContextRunner{ _scanContext, threadCount, "ScannerMetadata" }
, _abort{ abort } , _abort{ abort }
{} {}
+18 -4
View File
@@ -22,16 +22,31 @@
#include <cstdlib> #include <cstdlib>
#include "utils/ILogger.hpp" #include "utils/ILogger.hpp"
#include "utils/IProfiler.hpp"
IOContextRunner::IOContextRunner(boost::asio::io_service& ioService, std::size_t threadCount) IOContextRunner::IOContextRunner(boost::asio::io_service& ioService, std::size_t threadCount, std::string_view name)
: _ioService{ ioService } : _ioService{ ioService }
, _work{ ioService } , _work{ ioService }
{ {
LMS_LOG(UTILS, INFO, "Starting IO context with " << threadCount << " threads..."); LMS_LOG(UTILS, INFO, "Starting IO context with " << threadCount << " threads...");
for (std::size_t i{}; i < threadCount; ++i) for (std::size_t i{}; i < threadCount; ++i)
{ {
_threads.emplace_back([&] std::string threadName{ name };
if (!threadName.empty())
{
threadName += "Thread_";
threadName += std::to_string(i);
}
_threads.emplace_back([this, threadName]
{ {
if (!threadName.empty())
{
if (auto * profiler{ Service<profiling::IProfiler>::get() })
profiler->setThreadName(std::this_thread::get_id(), threadName);
}
try try
{ {
_ioService.run(); _ioService.run();
@@ -45,8 +60,7 @@ IOContextRunner::IOContextRunner(boost::asio::io_service& ioService, std::size_t
} }
} }
void void IOContextRunner::stop()
IOContextRunner::stop()
{ {
LMS_LOG(UTILS, DEBUG, "Stopping IO context..."); LMS_LOG(UTILS, DEBUG, "Stopping IO context...");
_work.reset(); _work.reset();
@@ -26,7 +26,7 @@
class IOContextRunner class IOContextRunner
{ {
public: public:
IOContextRunner(boost::asio::io_service& ioService, std::size_t threadCount); IOContextRunner(boost::asio::io_service& ioService, std::size_t threadCount, std::string_view name);
~IOContextRunner(); ~IOContextRunner();
void stop(); void stop();
+1 -1
View File
@@ -277,7 +277,7 @@ int main(int argc, char* argv[])
Wt::WServer server{ argv[0] }; Wt::WServer server{ argv[0] };
server.setServerConfiguration(wtServerArgs.size(), const_cast<char**>(&wtArgv[0])); server.setServerConfiguration(wtServerArgs.size(), const_cast<char**>(&wtArgv[0]));
IOContextRunner ioContextRunner{ ioContext, getThreadCount() }; IOContextRunner ioContextRunner{ ioContext, getThreadCount(), "Misc" };
// Connection pool size must be twice the number of threads: we have at least 2 io pools with getThreadCount() each and they all may access the database // Connection pool size must be twice the number of threads: we have at least 2 io pools with getThreadCount() each and they all may access the database
Database::Db database{ config->getPath("working-dir") / "lms.db", getThreadCount() * 2 }; Database::Db database{ config->getPath("working-dir") / "lms.db", getThreadCount() * 2 };