diff --git a/src/libs/services/scanner/impl/ScanStepScanFiles.cpp b/src/libs/services/scanner/impl/ScanStepScanFiles.cpp index 2e2c7eb3..e52caa4f 100644 --- a/src/libs/services/scanner/impl/ScanStepScanFiles.cpp +++ b/src/libs/services/scanner/impl/ScanStepScanFiles.cpp @@ -244,7 +244,7 @@ namespace Scanner ScanStepScanFiles::MetadataScanQueue::MetadataScanQueue(MetaData::IParser& parser, std::size_t threadCount, bool& abort) : _metadataParser{ parser } - , _scanContextRunner{ _scanContext, threadCount } + , _scanContextRunner{ _scanContext, threadCount, "ScannerMetadata" } , _abort{ abort } {} diff --git a/src/libs/utils/impl/IOContextRunner.cpp b/src/libs/utils/impl/IOContextRunner.cpp index 77a88b9d..3814eb1a 100644 --- a/src/libs/utils/impl/IOContextRunner.cpp +++ b/src/libs/utils/impl/IOContextRunner.cpp @@ -22,16 +22,31 @@ #include #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 } , _work{ ioService } { LMS_LOG(UTILS, INFO, "Starting IO context with " << threadCount << " threads..."); + 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::get() }) + profiler->setThreadName(std::this_thread::get_id(), threadName); + } + try { _ioService.run(); @@ -45,8 +60,7 @@ IOContextRunner::IOContextRunner(boost::asio::io_service& ioService, std::size_t } } -void -IOContextRunner::stop() +void IOContextRunner::stop() { LMS_LOG(UTILS, DEBUG, "Stopping IO context..."); _work.reset(); diff --git a/src/libs/utils/include/utils/IOContextRunner.hpp b/src/libs/utils/include/utils/IOContextRunner.hpp index e538826f..1a1857a2 100644 --- a/src/libs/utils/include/utils/IOContextRunner.hpp +++ b/src/libs/utils/include/utils/IOContextRunner.hpp @@ -26,7 +26,7 @@ class IOContextRunner { 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(); void stop(); diff --git a/src/lms/main.cpp b/src/lms/main.cpp index c03c8a5a..ef20d249 100644 --- a/src/lms/main.cpp +++ b/src/lms/main.cpp @@ -277,7 +277,7 @@ int main(int argc, char* argv[]) Wt::WServer server{ argv[0] }; server.setServerConfiguration(wtServerArgs.size(), const_cast(&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 Database::Db database{ config->getPath("working-dir") / "lms.db", getThreadCount() * 2 };