common/Util.cpp |   12 ++++++------
 net/Socket.cpp  |    2 ++
 net/Socket.hpp  |   21 ++++++++++++++-------
 3 files changed, 22 insertions(+), 13 deletions(-)

New commits:
commit e0822f851647b17fca3043c8f17e52ebe8090aa2
Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk>
Date:   Sun Apr 2 17:38:05 2017 -0400

    wsd: better thread affinity logging
    
    Change-Id: I9e4bc3fe864aa409dc4874a9d6fc4ab22bfea592
    Reviewed-on: https://gerrit.libreoffice.org/36029
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/common/Util.cpp b/common/Util.cpp
index 8e9552b6..3260d130 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -265,13 +265,13 @@ namespace Util
         strncpy(ThreadName, s.c_str(), 31);
         ThreadName[31] = '\0';
         if (prctl(PR_SET_NAME, reinterpret_cast<unsigned long>(s.c_str()), 0, 
0, 0) != 0)
-        {
-            LOG_SYS("Cannot set thread name to " << s << ".");
-        }
+            LOG_SYS("Cannot set thread name of " << getThreadId() << " (0x" <<
+                    std::hex << std::this_thread::get_id() <<
+                    std::dec << ") to [" << s << "].");
         else
-        {
-            LOG_INF("Thread " << std::hex << std::this_thread::get_id() << 
std::dec << " is now called " << s);
-        }
+            LOG_INF("Thread " << getThreadId() << " (0x" <<
+                    std::hex << std::this_thread::get_id() <<
+                    std::dec << ") is now called [" << s << "].");
     }
 
     const char *getThreadName()
diff --git a/net/Socket.cpp b/net/Socket.cpp
index 39906bf7..2b9899f8 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -57,6 +57,8 @@ SocketPoll::SocketPoll(const std::string& threadName)
     }
 
     _owner = std::this_thread::get_id();
+    LOG_DBG("Thread affinity of " << _name << " set to 0x" <<
+            std::hex << _owner << "." << std::dec);
 }
 
 SocketPoll::~SocketPoll()
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 4d723d99..94d4cc34 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -185,7 +185,12 @@ public:
     void setThreadOwner(const std::thread::id &id)
     {
 #if ENABLE_DEBUG
-       _owner = id;
+        if (id != _owner)
+        {
+            LOG_DBG("#" << _fd << " Thread affinity set to 0x" << std::hex <<
+                    id << " (was 0x" << _owner << ")." << std::dec);
+            _owner = id;
+        }
 #else
        (void)id;
 #endif
@@ -196,8 +201,10 @@ public:
 #if ENABLE_DEBUG
         const bool sameThread = std::this_thread::get_id() == _owner;
         if (!sameThread)
-            LOG_WRN("#" << _fd << " invoked from foreign thread. Expected: " <<
-                    std::hex << _owner << std::dec);
+            LOG_WRN("#" << _fd << " Invoked from foreign thread. Expected: 0x" 
<< std::hex <<
+                    _owner << " but called from 0x" << 
std::this_thread::get_id() << " (" <<
+                    std::dec << Util::getThreadId() << ").");
+
         if (hard)
             return sameThread;
         else
@@ -224,12 +231,12 @@ protected:
         _sendBufferSize = DefaultSendBufferSize;
 #if ENABLE_DEBUG
         _owner = std::this_thread::get_id();
+        LOG_DBG("#" << _fd << " Thread affinity set to 0x" << std::hex << 
_owner << "." << std::dec);
 
         const int oldSize = getSocketBufferSize();
         setSocketBufferSize(0);
         LOG_TRC("#" << _fd << ": Buffer size: " << getSendBufferSize() << " 
(was " << oldSize << ")");
 #endif
-
     }
 
 private:
@@ -291,9 +298,9 @@ public:
     bool isCorrectThread() const
     {
         if (std::this_thread::get_id() != _owner)
-            LOG_WRN("Incorrect thread affinity. Expected: 0x" << std::hex << 
_owner <<
-                    " but called from " << std::this_thread::get_id() << 
std::dec <<
-                    ", stop: " << _stop);
+            LOG_WRN("Incorrect thread affinity for " << _name << ". Expected: 
0x" << std::hex <<
+                    _owner << " (" << std::dec << Util::getThreadId() << ") 
but called from 0x" <<
+                    std::hex << std::this_thread::get_id() << std::dec << ", 
stop: " << _stop);
 
         return _stop || std::this_thread::get_id() == _owner;
     }
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to