[Libreoffice-commits] online.git: net/ServerSocket.hpp net/Socket.cpp net/Socket.hpp wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

Ashod Nakashian ashod.nakashian at collabora.co.uk
Mon Mar 13 04:20:17 UTC 2017


 net/ServerSocket.hpp   |    2 +-
 net/Socket.cpp         |   23 ++++++++++++-----------
 net/Socket.hpp         |    6 +++---
 wsd/DocumentBroker.cpp |   36 ++++++++++++++++++------------------
 wsd/DocumentBroker.hpp |    2 +-
 wsd/LOOLWSD.cpp        |   33 +++++++++++++++++++--------------
 6 files changed, 54 insertions(+), 48 deletions(-)

New commits:
commit 04bbb75200e5097429b119f2773f115a542cf823
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date:   Sun Mar 12 19:03:45 2017 -0400

    wsd: dump state to generic ostream for flexiblity and to log
    
    Change-Id: I4670ee2e90b7809ebc66a2b324a44334b3dbba2b
    Reviewed-on: https://gerrit.libreoffice.org/35119
    Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
    Tested-by: Ashod Nakashian <ashnakash at gmail.com>

diff --git a/net/ServerSocket.hpp b/net/ServerSocket.hpp
index 8f98dc6..29381c1 100644
--- a/net/ServerSocket.hpp
+++ b/net/ServerSocket.hpp
@@ -83,7 +83,7 @@ public:
         return POLLIN;
     }
 
-    void dumpState() override;
+    void dumpState(std::ostream& os) override;
 
     HandleResult handlePoll(const Poco::Timestamp &/* now */, int events) override
     {
diff --git a/net/Socket.cpp b/net/Socket.cpp
index b64f904..48bc696 100644
--- a/net/Socket.cpp
+++ b/net/Socket.cpp
@@ -85,9 +85,9 @@ void SocketPoll::wakeupWorld()
         wakeup(fd);
 }
 
-void ServerSocket::dumpState()
+void ServerSocket::dumpState(std::ostream& os)
 {
-    std::cerr << "\t" << getFD() << "\t<accept>\n";
+    os << "\t" << getFD() << "\t<accept>\n";
 }
 
 namespace {
@@ -121,24 +121,25 @@ void dump_hex (const char *legend, const char *prefix, std::vector<char> buffer)
 
 } // namespace
 
-void StreamSocket::dumpState()
+void StreamSocket::dumpState(std::ostream& os)
 {
-    std::cerr << "\t" << getFD() << "\t" << getPollEvents() << "\t"
-              << _inBuffer.size() << "\t" << _outBuffer.size() << "\t"
-              << "\n";
+    os << "\t" << getFD() << "\t" << getPollEvents() << "\t"
+       << _inBuffer.size() << "\t" << _outBuffer.size() << "\t"
+       << "\n";
     if (_inBuffer.size() > 0)
         dump_hex("\t\tinBuffer:\n", "\t\t", _inBuffer);
     if (_outBuffer.size() > 0)
         dump_hex("\t\toutBuffer:\n", "\t\t", _inBuffer);
 }
 
-void SocketPoll::dumpState()
+void SocketPoll::dumpState(std::ostream& os)
 {
-    std::cerr << " Poll [" << _pollSockets.size() << "] - wakeup r: "
-              << _wakeup[0] << " w: " << _wakeup[1] << "\n";
-    std::cerr << "\tfd\tevents\trsize\twsize\n";
+    // FIXME: NOT thread-safe! _pollSockets is modified from the polling thread!
+    os << " Poll [" << _pollSockets.size() << "] - wakeup r: "
+       << _wakeup[0] << " w: " << _wakeup[1] << "\n";
+    os << "\tfd\tevents\trsize\twsize\n";
     for (auto &i : _pollSockets)
-        i->dumpState();
+        i->dumpState(os);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/net/Socket.hpp b/net/Socket.hpp
index 7071acd..6929938 100644
--- a/net/Socket.hpp
+++ b/net/Socket.hpp
@@ -175,7 +175,7 @@ public:
         return rc;
     }
 
-    virtual void dumpState() {}
+    virtual void dumpState(std::ostream&) {}
 
     /// Set the thread-id we're bound to
     void setThreadOwner(const std::thread::id &id)
@@ -414,7 +414,7 @@ public:
         wakeup();
     }
 
-    void dumpState();
+    void dumpState(std::ostream& os);
 
     /// Removes a socket from this poller.
     /// NB. this must be called from the socket poll that
@@ -762,7 +762,7 @@ protected:
         return ::write(getFD(), buf, len);
     }
 
-    void dumpState() override;
+    void dumpState(std::ostream& os) override;
 
     /// Get the Write Lock.
     std::unique_lock<std::mutex> getWriteLock() { return std::unique_lock<std::mutex>(_writeMutex); }
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index aacdfae..9e2087f 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1292,31 +1292,31 @@ void DocumentBroker::updateLastActivityTime()
     Admin::instance().updateLastActivityTime(_docKey);
 }
 
-void DocumentBroker::dumpState()
+void DocumentBroker::dumpState(std::ostream& os)
 {
     std::unique_lock<std::mutex> lock(_mutex);
 
-    std::cerr << " Broker: " << _filename;
+    os << " Broker: " << _filename;
     if (_markToDestroy)
-        std::cerr << " *** Marked to destroy ***\n";
+        os << " *** Marked to destroy ***";
     else
-        std::cerr << " has live sessions\n";
+        os << " has live sessions";
     if (_isLoaded)
-        std::cerr << "  loaded in: " << _loadDuration.count() << "ms\n";
+        os << "\n  loaded in: " << _loadDuration.count() << "ms";
     else
-        std::cerr << "  still loading...\n";
-    std::cerr << "  modified?: " << _isModified << "\n";
-    std::cerr << "  jail id: " << _jailId << "\n";
-    std::cerr << "  public uri: " << _uriPublic.toString() << "\n";
-    std::cerr << "  jailed uri: " << _uriJailed.toString() << "\n";
-    std::cerr << "  doc key: " << _docKey << "\n";
-    std::cerr << "  num sessions: " << getSessionsCount() << "\n";
-    std::cerr << "  new sessions: " << _newSessions.size() << "\n";
-    std::cerr << "  last editable?: " << _lastEditableSession << "\n";
-    std::cerr << "  cursor " << _cursorPosX << ", " << _cursorPosY
-              << "( " << _cursorWidth << "," << _cursorHeight << ")\n";
-
-    _poll->dumpState();
+        os << "\n  still loading...";
+    os << "\n  modified?: " << _isModified;
+    os << "\n  jail id: " << _jailId;
+    os << "\n  public uri: " << _uriPublic.toString();
+    os << "\n  jailed uri: " << _uriJailed.toString();
+    os << "\n  doc key: " << _docKey;
+    os << "\n  num sessions: " << getSessionsCount();
+    os << "\n  new sessions: " << _newSessions.size();
+    os << "\n  last editable?: " << _lastEditableSession;
+    os << "\n  cursor " << _cursorPosX << ", " << _cursorPosY
+      << "( " << _cursorWidth << "," << _cursorHeight << ")\n";
+
+    _poll->dumpState(os);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 2a9c152..9836872 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -253,7 +253,7 @@ public:
         return _sessions.size();
     }
 
-    void dumpState();
+    void dumpState(std::ostream& os);
 
     std::string getJailRoot() const;
 
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 8444f07..b8a2b9d 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -2361,30 +2361,30 @@ public:
         SocketPoll::wakeupWorld();
     }
 
-    void dumpState()
+    void dumpState(std::ostream& os)
     {
-        std::cerr << "LOOLWSDServer:\n"
-                  << "   Ports: server " << ClientPortNumber
-                  <<          " prisoner " << MasterPortNumber << "\n"
-                  << "  stop: " << _stop << "\n"
-                  << "  TerminationFlag: " << TerminationFlag << "\n"
-                  << "  isShuttingDown: " << ShutdownRequestFlag << "\n"
-                  << "  NewChildren: " << NewChildren.size() << "\n"
-                  << "  OutstandingForks: " << OutstandingForks << "\n";
+        os << "LOOLWSDServer:\n"
+           << "   Ports: server " << ClientPortNumber
+           <<          " prisoner " << MasterPortNumber << "\n"
+           << "  stop: " << _stop << "\n"
+           << "  TerminationFlag: " << TerminationFlag << "\n"
+           << "  isShuttingDown: " << ShutdownRequestFlag << "\n"
+           << "  NewChildren: " << NewChildren.size() << "\n"
+           << "  OutstandingForks: " << OutstandingForks << "\n";
 
         std::cerr << "Server poll:\n";
-        _acceptPoll.dumpState();
+        _acceptPoll.dumpState(os);
 
         std::cerr << "Web Server poll:\n";
-        WebServerPoll.dumpState();
+        WebServerPoll.dumpState(os);
 
         std::cerr << "Prisoner poll:\n";
-        PrisonerPoll.dumpState();
+        PrisonerPoll.dumpState(os);
 
         std::cerr << "Document Broker polls "
                   << "[ " << DocBrokers.size() << " ]:\n";
         for (auto &i : DocBrokers)
-            i.second->dumpState();
+            i.second->dumpState(os);
     }
 
 private:
@@ -2735,7 +2735,12 @@ void alertAllUsers(const std::string& msg)
 
 void dump_state()
 {
-    srv.dumpState();
+    std::ostringstream oss;
+    srv.dumpState(oss);
+
+    const std::string msg = oss.str();
+    std::cerr << msg << std::endl;
+    LOG_TRC(msg);
 }
 
 POCO_SERVER_MAIN(LOOLWSD)


More information about the Libreoffice-commits mailing list