[Libreoffice-commits] online.git: 2 commits - common/Util.cpp loleaflet/src wsd/Admin.cpp wsd/Admin.hpp wsd/AdminModel.cpp wsd/AdminModel.hpp wsd/DocumentBroker.cpp wsd/protocol.txt

Michael Meeks michael.meeks at collabora.com
Tue Feb 7 18:55:58 UTC 2017


 common/Util.cpp                            |    4 ++--
 loleaflet/src/admin/AdminSocketOverview.js |   19 +++++++++++++++++--
 wsd/Admin.cpp                              |   16 ++++++++--------
 wsd/Admin.hpp                              |    2 +-
 wsd/AdminModel.cpp                         |   22 ++++++++++++++++------
 wsd/AdminModel.hpp                         |   14 +++++++-------
 wsd/DocumentBroker.cpp                     |    6 +++---
 wsd/protocol.txt                           |    6 ++++++
 8 files changed, 60 insertions(+), 29 deletions(-)

New commits:
commit e662b3457a3ab466651d50d5b88a99d863318d31
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Feb 7 18:52:01 2017 +0000

    AdminConsole: add new propchange notification, and update memory live.

diff --git a/loleaflet/src/admin/AdminSocketOverview.js b/loleaflet/src/admin/AdminSocketOverview.js
index 3bfdafe..4f6e081 100644
--- a/loleaflet/src/admin/AdminSocketOverview.js
+++ b/loleaflet/src/admin/AdminSocketOverview.js
@@ -23,7 +23,7 @@ var AdminSocketOverview = AdminSocketBase.extend({
 		this.base.call(this);
 
 		this.socket.send('documents');
-		this.socket.send('subscribe adddoc rmdoc resetidle');
+		this.socket.send('subscribe adddoc rmdoc resetidle propchange');
 
 		this._getBasicStats();
 		var socketOverview = this;
@@ -113,7 +113,8 @@ var AdminSocketOverview = AdminSocketBase.extend({
 									    .text(sViews);
 				$rowContainer.append($views);
 
-				$mem = $(document.createElement('td')).text(Util.humanizeMem(parseInt(sMem)));
+				$mem = $(document.createElement('td')).attr('id', 'docmem' + sPid)
+						.text(Util.humanizeMem(parseInt(sMem)));
 				$rowContainer.append($mem);
 
 				$docTime = $(document.createElement('td')).addClass('elapsed_time')
@@ -218,6 +219,20 @@ var AdminSocketOverview = AdminSocketBase.extend({
 				nTotalViews = parseInt($a.text());
 				$a.text(nTotalViews - 1);
 			}
+		} else if (textMsg.startsWith('propchange')) {
+			textMsg = textMsg.substring('propchange'.length);
+			docProps = textMsg.trim().split(' ');
+			sPid = docProps[0];
+			sProp = docProps[1];
+			sValue = docProps[2];
+
+			$doc = $('#doc' + sPid);
+			if ($doc.length !== 0) {
+				if (sProp == 'mem') {
+					$mem = $('#docmem' + sPid);
+					$mem.text(Util.humanizeMem(parseInt(sValue)));
+				}
+			}
 		}
 	},
 
diff --git a/wsd/AdminModel.cpp b/wsd/AdminModel.cpp
index 48d791e..f06573c 100644
--- a/wsd/AdminModel.cpp
+++ b/wsd/AdminModel.cpp
@@ -399,11 +399,23 @@ void AdminModel::updateLastActivityTime(const std::string& docKey)
     }
 }
 
+bool Document::updateMemoryDirty(int dirty)
+{
+    if (_memoryDirty == dirty)
+        return false;
+    _memoryDirty = dirty;
+    return true;
+}
+
 void AdminModel::updateMemoryDirty(const std::string& docKey, int dirty)
 {
     auto docIt = _documents.find(docKey);
-    if (docIt != _documents.end())
-        docIt->second.updateMemoryDirty(dirty);
+    if (docIt != _documents.end() &&
+        docIt->second.updateMemoryDirty(dirty))
+    {
+        notify("propchange " + std::to_string(docIt->second.getPid()) +
+               " mem " + std::to_string(dirty));
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/AdminModel.hpp b/wsd/AdminModel.hpp
index 1b9432e..8bfb719 100644
--- a/wsd/AdminModel.hpp
+++ b/wsd/AdminModel.hpp
@@ -74,7 +74,7 @@ public:
     const std::map<std::string, View>& getViews() const { return _views; }
 
     void updateLastActivityTime() { _lastActivity = std::time(nullptr); }
-    void updateMemoryDirty(int dirty) { _memoryDirty = dirty; }
+    bool updateMemoryDirty(int dirty);
     int getMemoryDirty() const { return _memoryDirty; }
 
 private:
diff --git a/wsd/protocol.txt b/wsd/protocol.txt
index 79705e9..ba3a191 100644
--- a/wsd/protocol.txt
+++ b/wsd/protocol.txt
@@ -546,6 +546,12 @@ section). Others are just response messages to some client command.
     <memory consumed> in kilobytes sent from admin -> client after every
     mem_stats_interval (see `set` command for list of settings)
 
+[*] propchange <pid> <property> <new-value>
+
+    Notifies of a property change on a pid's property. Properties can
+    include:
+       "mem" <memory consumed> - in kilobytes of the process.
+
 [*] resetidle <pid>
 
     <pid> process id hosting the document
commit 9ec0466c57d55dc3280e39426070216f290a87a4
Author: Michael Meeks <michael.meeks at collabora.com>
Date:   Tue Feb 7 14:39:56 2017 +0000

    Admin - measure dirty memory of kits, and RSS of forkit.
    
    Gives a more accurate real memory consumption for each process.

diff --git a/common/Util.cpp b/common/Util.cpp
index 1fc1adc..a17698c 100644
--- a/common/Util.cpp
+++ b/common/Util.cpp
@@ -151,8 +151,8 @@ namespace Util
             while (fgets(line, sizeof (line), file))
             {
                 const char *value;
-                if ((value = startsWith(line, "Private_Dirty:")) ||
-                    (value = startsWith(line, "Shared_Dirty:")))
+                // Shared_Dirty is accounted for by forkit's RSS
+                if (value = startsWith(line, "Private_Dirty:"))
                 {
                     numDirtyKb += atoi(value);
                 }
diff --git a/wsd/Admin.cpp b/wsd/Admin.cpp
index 73b75a8..d5b2277 100644
--- a/wsd/Admin.cpp
+++ b/wsd/Admin.cpp
@@ -371,14 +371,14 @@ unsigned Admin::getTotalMemoryUsage()
 {
     Util::assertIsLocked(_modelMutex);
 
-    // PSS would be wrong for forkit since we will have one or
-    // more prespawned kits that will share their pages with forkit,
-    // but we don't count the kits unless and until a document is loaded.
-    // So RSS is a decent approximation (albeit slightly on the high side).
+    // To simplify and clarify this; since load, link and pre-init all
+    // inside the forkit - we should account all of our fixed cost of
+    // memory to the forkit; and then count only dirty pages in the clients
+    // since we know that they share everything else with the forkit.
     const size_t forkitRssKb = Util::getMemoryUsageRSS(_forKitPid);
     const size_t wsdPssKb = Util::getMemoryUsagePSS(Poco::Process::id());
-    const size_t kitsPssKb = _model.getKitsMemoryUsage();
-    const size_t totalMem = wsdPssKb + forkitRssKb + kitsPssKb;
+    const size_t kitsDirtyKb = _model.getKitsMemoryUsage();
+    const size_t totalMem = wsdPssKb + forkitRssKb + kitsDirtyKb;
 
     return totalMem;
 }
@@ -404,10 +404,10 @@ void Admin::updateLastActivityTime(const std::string& docKey)
     _model.updateLastActivityTime(docKey);
 }
 
-void Admin::updateMemoryPss(const std::string& docKey, int pss)
+void Admin::updateMemoryDirty(const std::string& docKey, int dirty)
 {
     std::unique_lock<std::mutex> modelLock(_modelMutex);
-    _model.updateMemoryPss(docKey, pss);
+    _model.updateMemoryDirty(docKey, dirty);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/Admin.hpp b/wsd/Admin.hpp
index 6e7ef58..33f0617 100644
--- a/wsd/Admin.hpp
+++ b/wsd/Admin.hpp
@@ -97,7 +97,7 @@ public:
     std::unique_lock<std::mutex> getLock() { return std::unique_lock<std::mutex>(_modelMutex); }
 
     void updateLastActivityTime(const std::string& docKey);
-    void updateMemoryPss(const std::string& docKey, int pss);
+    void updateMemoryDirty(const std::string& docKey, int dirty);
 
 private:
     Admin();
diff --git a/wsd/AdminModel.cpp b/wsd/AdminModel.cpp
index 87a8336..48d791e 100644
--- a/wsd/AdminModel.cpp
+++ b/wsd/AdminModel.cpp
@@ -137,7 +137,7 @@ unsigned AdminModel::getKitsMemoryUsage()
     {
         if (!it.second.isExpired())
         {
-            const auto bytes = it.second.getMemoryPss();
+            const auto bytes = it.second.getMemoryDirty();
             if (bytes > 0)
             {
                 totalMem += bytes;
@@ -280,7 +280,7 @@ void AdminModel::addDocument(const std::string& docKey, Poco::Process::PID pid,
     }
     else
     {
-        oss << _documents.begin()->second.getMemoryPss();
+        oss << _documents.begin()->second.getMemoryDirty();
     }
 
     notify(oss.str());
@@ -377,7 +377,7 @@ std::string AdminModel::getDocuments() const
             oss << it.second.getPid() << ' '
                 << encodedFilename << ' '
                 << it.second.getActiveViews() << ' '
-                << it.second.getMemoryPss() << ' '
+                << it.second.getMemoryDirty() << ' '
                 << it.second.getElapsedTime() << ' '
                 << it.second.getIdleTime() << " \n ";
         }
@@ -399,13 +399,11 @@ void AdminModel::updateLastActivityTime(const std::string& docKey)
     }
 }
 
-void AdminModel::updateMemoryPss(const std::string& docKey, int pss)
+void AdminModel::updateMemoryDirty(const std::string& docKey, int dirty)
 {
     auto docIt = _documents.find(docKey);
     if (docIt != _documents.end())
-    {
-        docIt->second.updateMemoryPss(pss);
-    }
+        docIt->second.updateMemoryDirty(dirty);
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/wsd/AdminModel.hpp b/wsd/AdminModel.hpp
index 0e46ca5..1b9432e 100644
--- a/wsd/AdminModel.hpp
+++ b/wsd/AdminModel.hpp
@@ -49,7 +49,7 @@ public:
         : _docKey(docKey),
           _pid(pid),
           _filename(filename),
-          _memoryPss(0),
+          _memoryDirty(0),
           _start(std::time(nullptr)),
           _lastActivity(_start)
     {
@@ -74,8 +74,8 @@ public:
     const std::map<std::string, View>& getViews() const { return _views; }
 
     void updateLastActivityTime() { _lastActivity = std::time(nullptr); }
-    void updateMemoryPss(int pss) { _memoryPss = pss; }
-    int getMemoryPss() const { return _memoryPss; }
+    void updateMemoryDirty(int dirty) { _memoryDirty = dirty; }
+    int getMemoryDirty() const { return _memoryDirty; }
 
 private:
     const std::string _docKey;
@@ -86,8 +86,8 @@ private:
     unsigned _activeViews = 0;
     /// Hosted filename
     std::string _filename;
-    /// The PSS of the document's Kit process.
-    int _memoryPss;
+    /// The dirty (ie. un-shared) memory of the document's Kit process.
+    int _memoryDirty;
 
     std::time_t _start;
     std::time_t _lastActivity;
@@ -178,7 +178,7 @@ public:
     void removeDocument(const std::string& docKey);
 
     void updateLastActivityTime(const std::string& docKey);
-    void updateMemoryPss(const std::string& docKey, int pss);
+    void updateMemoryDirty(const std::string& docKey, int dirty);
 
 private:
     std::string getMemStats();
@@ -193,7 +193,7 @@ private:
     std::map<int, Subscriber> _subscribers;
     std::map<std::string, Document> _documents;
 
-    /// The last N total memory PSS.
+    /// The last N total memory Dirty size.
     std::list<unsigned> _memStats;
     unsigned _memStatsSize = 100;
 
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index f37152c..2cda4a0 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -759,10 +759,10 @@ bool DocumentBroker::handleInput(const std::vector<char>& payload)
         }
         else if (command == "procmemstats:")
         {
-            int pss;
-            if (message->getTokenInteger("pss", pss))
+            int dirty;
+            if (message->getTokenInteger("dirty", dirty))
             {
-                Admin::instance().updateMemoryPss(_docKey, pss);
+                Admin::instance().updateMemoryDirty(_docKey, dirty);
             }
         }
         else


More information about the Libreoffice-commits mailing list