diff --git a/build b/build index 8c0474e..d7765fe 100644 --- a/build +++ b/build @@ -1 +1 @@ -69 \ No newline at end of file +70 \ No newline at end of file diff --git a/src/DeviceStatusReceiver.cpp b/src/DeviceStatusReceiver.cpp index b32af69..d272fb9 100644 --- a/src/DeviceStatusReceiver.cpp +++ b/src/DeviceStatusReceiver.cpp @@ -23,6 +23,7 @@ namespace OpenWifi { } void DeviceStatusReceiver::run() { + Utils::SetThreadName("dev-status"); Poco::AutoPtr Note(Queue_.waitDequeueNotification()); while(Note && Running_) { auto Msg = dynamic_cast(Note.get()); diff --git a/src/HealthReceiver.cpp b/src/HealthReceiver.cpp index d1a00ad..19dc01e 100644 --- a/src/HealthReceiver.cpp +++ b/src/HealthReceiver.cpp @@ -23,6 +23,7 @@ namespace OpenWifi { } void HealthReceiver::run() { + Utils::SetThreadName("dev-health"); Poco::AutoPtr Note(Queue_.waitDequeueNotification()); while(Note && Running_) { auto Msg = dynamic_cast(Note.get()); diff --git a/src/StateReceiver.cpp b/src/StateReceiver.cpp index b09283b..4cbf74d 100644 --- a/src/StateReceiver.cpp +++ b/src/StateReceiver.cpp @@ -25,6 +25,7 @@ namespace OpenWifi { void StateReceiver::run() { Poco::AutoPtr Note(Queue_.waitDequeueNotification()); + Utils::SetThreadName("dev-state"); while(Note && Running_) { auto Msg = dynamic_cast(Note.get()); if(Msg!= nullptr) { diff --git a/src/StorageService.cpp b/src/StorageService.cpp index 726cc0a..8b40cfe 100644 --- a/src/StorageService.cpp +++ b/src/StorageService.cpp @@ -66,6 +66,7 @@ namespace OpenWifi { } void Storage::run() { + Utils::SetThreadName("strg-updtr"); Running_ = true ; bool FirstRun=true; long Retry = 2000; diff --git a/src/VenueCoordinator.cpp b/src/VenueCoordinator.cpp index 3989b74..5d7af7c 100644 --- a/src/VenueCoordinator.cpp +++ b/src/VenueCoordinator.cpp @@ -34,6 +34,7 @@ namespace OpenWifi { } void VenueCoordinator::run() { + Utils::SetThreadName("venue-coord"); Running_=true; while(Running_) { Poco::Thread::trySleep(20000); diff --git a/src/VenueWatcher.cpp b/src/VenueWatcher.cpp index 007d262..e6751ad 100644 --- a/src/VenueWatcher.cpp +++ b/src/VenueWatcher.cpp @@ -34,6 +34,7 @@ namespace OpenWifi { } void VenueWatcher::run() { + Utils::SetThreadName("venue-watch"); Running_ = true; Poco::AutoPtr Msg(Queue_.waitDequeueNotification()); while(Msg && Running_) { diff --git a/src/framework/MicroService.h b/src/framework/MicroService.h index 9169c10..8447a5e 100644 --- a/src/framework/MicroService.h +++ b/src/framework/MicroService.h @@ -643,6 +643,27 @@ namespace OpenWifi::RESTAPI_utils { namespace OpenWifi::Utils { + inline void SetThreadName(const char *name) { +#ifdef __linux__ + Poco::Thread::current()->setName(name); + pthread_setname_np(pthread_self(), name); +#endif +#ifdef __APPLE__ + Poco::Thread::current()->setName(name); + pthread_setname_np(name); +#endif + } + + inline void SetThreadName(Poco::Thread &thr, const char *name) { +#ifdef __linux__ + thr.setName(name); + pthread_setname_np(thr.tid(), name); +#endif +#ifdef __APPLE__ + thr.setName(name); +#endif + } + enum MediaTypeEncodings { PLAIN, BINARY, @@ -1316,7 +1337,7 @@ namespace OpenWifi { inline void Start(); inline void Stop(); private: - std::atomic_bool Running_ = false; + mutable std::atomic_bool Running_ = false; Poco::Thread Thread_; }; @@ -1847,7 +1868,8 @@ namespace OpenWifi { Request = &RequestIn; Response = &ResponseIn; - Poco::Thread::current()->setName("WebServerThread_" + std::to_string(TransactionId_)); + std::string th_name = "restsvr_" + std::to_string(TransactionId_); + Utils::SetThreadName(th_name.c_str()); if(Request->getContentLength()>0) { if(Request->getContentType().find("application/json")!=std::string::npos) { @@ -2579,7 +2601,7 @@ namespace OpenWifi { private: std::recursive_mutex Mutex_; Poco::Thread Worker_; - std::atomic_bool Running_=false; + mutable std::atomic_bool Running_=false; Poco::NotificationQueue Queue_; }; @@ -2605,7 +2627,7 @@ namespace OpenWifi { private: std::recursive_mutex Mutex_; Poco::Thread Worker_; - std::atomic_bool Running_=false; + mutable std::atomic_bool Running_=false; }; class KafkaDispatcher : public Poco::Runnable { @@ -2662,6 +2684,7 @@ namespace OpenWifi { inline void run() override { Poco::AutoPtr Note(Queue_.waitDequeueNotification()); + Utils::SetThreadName("kafka-dispatch"); while(Note && Running_) { auto Msg = dynamic_cast(Note.get()); if(Msg!= nullptr) { @@ -2687,7 +2710,7 @@ namespace OpenWifi { std::recursive_mutex Mutex_; Types::NotifyTable Notifiers_; Poco::Thread Worker_; - std::atomic_bool Running_=false; + mutable std::atomic_bool Running_=false; uint64_t FunctionId_=1; Poco::NotificationQueue Queue_; }; @@ -2882,6 +2905,7 @@ namespace OpenWifi { void handleRequest(Poco::Net::HTTPServerRequest& Request, Poco::Net::HTTPServerResponse& Response) override { + Utils::SetThreadName("alb-request"); try { if((id_ % 100) == 0) { Logger_.debug(fmt::format("ALB-REQUEST({}): ALB Request {}.", @@ -2950,7 +2974,7 @@ namespace OpenWifi { std::unique_ptr Server_; std::unique_ptr Socket_; int Port_ = 0; - std::atomic_bool Running_=false; + mutable std::atomic_bool Running_=false; }; inline auto ALBHealthCheckServer() { return ALBHealthCheckServer::instance(); } @@ -2982,7 +3006,7 @@ namespace OpenWifi { inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) { RESTAPIHandler::BindingMap Bindings; - Poco::Thread::current()->setName(fmt::format("RESTAPI_ExtServer_{}",Id)); + Utils::SetThreadName(fmt::format("rest_ext_{}",Id).c_str()); return RESTAPI_ExtRouter(Path, Bindings, Logger(), Server_, Id); } @@ -3006,7 +3030,7 @@ namespace OpenWifi { inline Poco::Net::HTTPRequestHandler *createRequestHandler(const Poco::Net::HTTPServerRequest &Request) override { try { Poco::URI uri(Request.getURI()); - Poco::Thread::current()->setName(fmt::format("ExtWebServer_{}",TransactionId_)); + Utils::SetThreadName(fmt::format("rest_ext_{}",TransactionId_).c_str()); return RESTAPI_ExtServer()->CallServer(uri.getPath(), TransactionId_++); } catch (...) { @@ -3115,7 +3139,7 @@ namespace OpenWifi { inline Poco::Net::HTTPRequestHandler *CallServer(const std::string &Path, uint64_t Id) { RESTAPIHandler::BindingMap Bindings; - Poco::Thread::current()->setName(fmt::format("RESTAPI_IntServer_{}",Id)); + Utils::SetThreadName(fmt::format("rest_int_{}",Id).c_str()); return RESTAPI_IntRouter(Path, Bindings, Logger(), Server_, Id); } private: @@ -3524,7 +3548,9 @@ namespace OpenWifi { void DaemonPostInitialization(Poco::Util::Application &self); inline void MicroService::initialize(Poco::Util::Application &self) { - // add the default services + // Utils::SetThreadName("microservice"); + + // add the default services LoadConfigurationFile(); InitializeLoggingSystem(); @@ -3919,6 +3945,7 @@ namespace OpenWifi { inline int MicroService::main([[maybe_unused]] const ArgVec &args) { + // Utils::SetThreadName("main"); MyErrorHandler ErrorHandler(*this); Poco::ErrorHandler::set(&ErrorHandler); @@ -4034,6 +4061,7 @@ namespace OpenWifi { inline void BusEventManager::run() { Running_ = true; + Utils::SetThreadName("BusEventManager"); auto Msg = MicroService::instance().MakeSystemEventMessage(KafkaTopics::ServiceEvents::EVENT_JOIN); KafkaManager()->PostMessage(KafkaTopics::SERVICE_EVENTS,MicroService::instance().PrivateEndPoint(),Msg, false); while(Running_) { @@ -4119,6 +4147,8 @@ namespace OpenWifi { } inline void KafkaProducer::run() { + + Utils::SetThreadName("KafkaProducer"); cppkafka::Configuration Config({ { "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") }, { "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") } @@ -4157,6 +4187,8 @@ namespace OpenWifi { } inline void KafkaConsumer::run() { + Utils::SetThreadName("KafkaConsumer"); + cppkafka::Configuration Config({ { "client.id", MicroService::instance().ConfigGetString("openwifi.kafka.client.id") }, { "metadata.broker.list", MicroService::instance().ConfigGetString("openwifi.kafka.brokerlist") }, @@ -4815,7 +4847,7 @@ namespace OpenWifi { [[nodiscard]] bool SendToUser(const std::string &userName, const std::string &Payload); void SendToAll(const std::string &Payload); private: - std::atomic_bool Running_ = false; + mutable std::atomic_bool Running_ = false; Poco::Thread Thr_; // std::unique_ptr ReactorPool_; Poco::Net::SocketReactor Reactor_; @@ -4912,6 +4944,7 @@ namespace OpenWifi { inline void WebSocketClientServer::run() { Running_ = true ; + Utils::SetThreadName("ws:clnt-svr"); while(Running_) { Poco::Thread::trySleep(2000);