[Libreoffice-commits] online.git: common/Session.hpp kit/ChildSession.hpp kit/ForKit.cpp kit/Kit.cpp

Michael Meeks (via logerrit) logerrit at kemper.freedesktop.org
Sat Jul 18 16:21:35 UTC 2020


 common/Session.hpp   |    9 +++++-
 kit/ChildSession.hpp |    7 ++++
 kit/ForKit.cpp       |    2 -
 kit/Kit.cpp          |   75 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 4 files changed, 89 insertions(+), 4 deletions(-)

New commits:
commit ca5d5943e45b2a23a634d6825a220026b4fb5495
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue Jul 14 15:20:05 2020 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Sat Jul 18 18:21:14 2020 +0200

    Kit: add initial state dumping on USR1.
    
    Change-Id: I8225f686e8678c08e505490df056904fc813d2fe
    Reviewed-on: https://gerrit.libreoffice.org/c/online/+/98927
    Tested-by: Jenkins
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice at gmail.com>
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/common/Session.hpp b/common/Session.hpp
index 02a11fa23..64e5e1502 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -53,12 +53,19 @@ public:
     }
     std::shared_ptr<T> findByCanonicalId(int id)
     {
-        for (auto &it : *this) {
+        for (const auto &it : *this) {
             if (it.second->getCanonicalViewId() == id)
                 return it.second;
         }
         return std::shared_ptr<T>();
     }
+    void dumpState(std::ostream& oss)
+    {
+        for (const auto &it : *this) {
+            oss << "\tsession '" << it.first << "'\n";
+            it.second->dumpState(oss);
+        }
+    }
 };
 
 /// Base class of a WebSocket session.
diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp
index 48edf98b2..3b6226d8f 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -315,6 +315,13 @@ private:
         return ret;
     }
 
+public:
+    void dumpState(std::ostream& oss) override
+    {
+        Session::dumpState(oss);
+        // TODO: the rest ...
+    }
+
 private:
     const std::string _jailId;
     DocumentManagerInterface* _docManager;
diff --git a/kit/ForKit.cpp b/kit/ForKit.cpp
index 9daa93576..9afa62b4e 100644
--- a/kit/ForKit.cpp
+++ b/kit/ForKit.cpp
@@ -69,7 +69,6 @@ std::string MasterLocation;
 
 extern "C" { void dump_forkit_state(void); /* easy for gdb */ }
 
-#if !MOBILEAPP
 void dump_forkit_state()
 {
     std::ostringstream oss;
@@ -92,7 +91,6 @@ void dump_forkit_state()
     fprintf(stderr, "%s", msg.c_str());
     LOG_TRC(msg);
 }
-#endif
 
 class ServerWSHandler;
 
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index 37016d420..7c8f426d0 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -105,6 +105,8 @@ using Poco::Path;
 using namespace LOOLProtocol;
 using std::size_t;
 
+extern "C" { void dump_kit_state(void); /* easy for gdb */ }
+
 // We only host a single document in our lifetime.
 class Document;
 #ifndef BUILDING_TESTS
@@ -1549,6 +1551,43 @@ private:
         sendTextFrame(msg);
     }
 
+public:
+    void dumpState(std::ostream& oss)
+    {
+        oss << "Kit Document:\n"
+            << "\n\tstop: " << _stop
+            << "\n\tisLoading: " << _stop
+            << "\n\tjailId: " << _jailId
+            << "\n\tdocKey: " << _docKey
+            << "\n\tdocId: " << _docId
+            << "\n\turl: " << _url
+            << "\n\tobfuscatedFileId: " << _obfuscatedFileId
+            << "\n\tjailedUrl: " << _jailedUrl
+            << "\n\trenderOpts: " << _renderOpts
+            << "\n\thaveDocPassword: " << _haveDocPassword // not the pwd itself
+            << "\n\tisDocPasswordProtected: " << _isDocPasswordProtected
+            << "\n\tdocPasswordType: " << (int)_docPasswordType
+            << "\n\teditorId: " << _editorId
+            << "\n\teditorChangeWarning: " << _editorChangeWarning
+            << "\n";
+
+        // dumpState:
+        // TODO: _websocketHandler - but this is an odd one.
+        // TODO: std::shared_ptr<TileQueue> _tileQueue;
+        // TODO: PngCache _pngCache;
+        // TODO: std::map<int, std::unique_ptr<CallbackDescriptor>> _viewIdToCallbackDescr;
+        // ThreadPool _pngPool;
+
+        _sessions.dumpState(oss);
+
+        // TODO: std::map<int, std::chrono::steady_clock::time_point> _lastUpdatedAt;
+        // TODO: std::map<int, int> _speedCount;
+
+        /// For showing disconnected user info in the doc repair dialog.
+        // TODO: std::map<int, UserInfo> _sessionUserInfo;
+        // TODO: std::chrono::steady_clock::time_point _lastMemStatsTime;
+    }
+
 private:
     std::shared_ptr<lok::Office> _loKit;
     const std::string _jailId;
@@ -1619,24 +1658,45 @@ class KitSocketPoll final : public SocketPoll
     std::chrono::steady_clock::time_point _pollEnd;
     std::shared_ptr<Document> _document;
 
+    static KitSocketPoll *mainPoll;
+
     KitSocketPoll() :
         SocketPoll("kit")
     {
 #ifdef IOS
         terminationFlag = false;
 #endif
+        mainPoll = this;
     }
 
 public:
     ~KitSocketPoll()
     {
         // Just to make it easier to set a breakpoint
+        mainPoll = nullptr;
+    }
+
+    static void dumpGlobalState(std::ostream &oss)
+    {
+        if (mainPoll)
+        {
+            if (!mainPoll->_document)
+                oss << "KitSocketPoll: no doc\n";
+            else
+            {
+                mainPoll->_document->dumpState(oss);
+                mainPoll->dumpState(oss);
+            }
+        }
+        else
+            oss << "KitSocketPoll: none\n";
     }
 
     static std::shared_ptr<KitSocketPoll> create()
     {
         KitSocketPoll *p = new KitSocketPoll();
         auto result = std::shared_ptr<KitSocketPoll>(p);
+
 #ifdef IOS
         std::unique_lock<std::mutex> lock(KSPollsMutex);
         KSPolls.push_back(result);
@@ -1647,6 +1707,8 @@ public:
     // process pending message-queue events.
     void drainQueue(const std::chrono::steady_clock::time_point &now)
     {
+        SigUtil::checkDumpGlobalState(dump_kit_state);
+
         if (_document)
             _document->drainQueue(now);
     }
@@ -1671,7 +1733,6 @@ public:
         int maxExtraEvents = 15;
         int eventsSignalled = 0;
 
-
         if (timeoutMicroS < 0)
         {
             // Flush at most 1 + maxExtraEvents, or return when nothing left.
@@ -1729,6 +1790,8 @@ public:
 #endif
 };
 
+KitSocketPoll *KitSocketPoll::mainPoll = nullptr;
+
 #ifdef IOS
 
 std::mutex KitSocketPoll::KSPollsMutex;
@@ -2460,4 +2523,14 @@ std::string anonymizeUsername(const std::string& username)
 
 #endif // !MOBILEAPP
 
+void dump_kit_state()
+{
+    std::ostringstream oss;
+    KitSocketPoll::dumpGlobalState(oss);
+
+    const std::string msg = oss.str();
+    fprintf(stderr, "%s", msg.c_str());
+    LOG_TRC(msg);
+}
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list