[Libreoffice-commits] online.git: loleaflet/dist loleaflet/src loolwsd/AdminModel.cpp loolwsd/AdminModel.hpp
Pranav Kant
pranavk at collabora.com
Fri Apr 1 08:04:21 UTC 2016
loleaflet/dist/admin/admin.html | 1
loleaflet/src/admin/AdminSocketAnalytics.js | 2 -
loleaflet/src/admin/AdminSocketOverview.js | 35 ++++++++++++++++++++++++----
loleaflet/src/admin/Util.js | 33 +++++++++++++++++++++++++-
loolwsd/AdminModel.cpp | 4 ++-
loolwsd/AdminModel.hpp | 2 +
6 files changed, 69 insertions(+), 8 deletions(-)
New commits:
commit 28cf20b0913dc3ad95a4e695e7f94f95080a5bdd
Author: Pranav Kant <pranavk at collabora.com>
Date: Fri Apr 1 13:20:14 2016 +0530
bccu#1640: Add elapsed time field to admin console
Time increment is handled on client-side, server only sends the
elapsed time during first page-load.
Change-Id: I73e98fd95ca9f391b625a8dcfc7e3490878c6a40
diff --git a/loleaflet/dist/admin/admin.html b/loleaflet/dist/admin/admin.html
index 4fc7567..5663b80 100644
--- a/loleaflet/dist/admin/admin.html
+++ b/loleaflet/dist/admin/admin.html
@@ -101,6 +101,7 @@
<th>Document</th>
<th>Number of views</th>
<th>Memory consumed</th>
+ <th>Elapsed time</th>
</tr>
</thead>
<tbody id="doclist">
diff --git a/loleaflet/src/admin/AdminSocketAnalytics.js b/loleaflet/src/admin/AdminSocketAnalytics.js
index fa25324..4f93626 100644
--- a/loleaflet/src/admin/AdminSocketAnalytics.js
+++ b/loleaflet/src/admin/AdminSocketAnalytics.js
@@ -92,7 +92,7 @@ var AdminSocketAnalytics = AdminSocketBase.extend({
this._d3yAxis = d3.svg.axis()
.scale(this._yScale)
.tickFormat(function (d) {
- return Util.humanize(d);
+ return Util.humanizeMem(d);
})
.orient('left');
diff --git a/loleaflet/src/admin/AdminSocketOverview.js b/loleaflet/src/admin/AdminSocketOverview.js
index afced98..5bcb54e 100644
--- a/loleaflet/src/admin/AdminSocketOverview.js
+++ b/loleaflet/src/admin/AdminSocketOverview.js
@@ -10,6 +10,8 @@ var AdminSocketOverview = AdminSocketBase.extend({
_basicStatsIntervalId: 0,
+ _docElapsedTimeIntervalId: 0,
+
_getBasicStats: function() {
this.socket.send('total_mem');
this.socket.send('active_docs_count');
@@ -27,6 +29,15 @@ var AdminSocketOverview = AdminSocketBase.extend({
return socketOverview._getBasicStats();
}, 5000);
+ this._docElapsedTimeIntervalId =
+ setInterval(function() {
+ $('td.elapsed_time').each(function() {
+ var newSecs = parseInt($(this).val()) + 1;
+ $(this).val(newSecs);
+ $(this).html(Util.humanizeSecs(newSecs));
+ });
+ }, 1000);
+
// Allow table rows to have a context menu for terminating sessions
$('body').on('contextmenu', 'table tr', function(ev) {
$('#rowContextMenu').css({
@@ -67,9 +78,9 @@ var AdminSocketOverview = AdminSocketBase.extend({
var tableContainer = document.getElementById('doclist');
var rowContainer;
- var pidEle, urlEle, viewsEle, memEle, docEle;
+ var pidEle, urlEle, viewsEle, memEle, sDocTimeEle, docEle;
var nViews, nTotalViews;
- var docProps, sPid, sUrl, sViews, sMem;
+ var docProps, sPid, sUrl, sViews, sMem, sDocTime;
if (textMsg.startsWith('documents')) {
var documents = textMsg.substring('documents'.length);
documents = documents.trim().split('\n');
@@ -82,6 +93,7 @@ var AdminSocketOverview = AdminSocketBase.extend({
sUrl = docProps[1];
sViews = docProps[2];
sMem = docProps[3];
+ sDocTime = docProps[4];
if (sUrl === '0') {
continue;
}
@@ -103,8 +115,14 @@ var AdminSocketOverview = AdminSocketBase.extend({
rowContainer.appendChild(viewsEle);
memEle = document.createElement('td');
- memEle.innerHTML = Util.humanize(parseInt(sMem));
+ memEle.innerHTML = Util.humanizeMem(parseInt(sMem));
rowContainer.appendChild(memEle);
+
+ sDocTimeEle = document.createElement('td');
+ sDocTimeEle.className = 'elapsed_time';
+ sDocTimeEle.value = parseInt(sDocTime);
+ sDocTimeEle.innerHTML = Util.humanizeSecs(sDocTime);
+ rowContainer.appendChild(sDocTimeEle);
}
}
else if (textMsg.startsWith('addview')) {
@@ -154,9 +172,15 @@ var AdminSocketOverview = AdminSocketBase.extend({
rowContainer.appendChild(viewsEle);
memEle = document.createElement('td');
- memEle.innerHTML = Util.humanize(parseInt(sMem));
+ memEle.innerHTML = Util.humanizeMem(parseInt(sMem));
rowContainer.appendChild(memEle);
+ sDocTimeEle = document.createElement('td');
+ sDocTimeEle.className = 'elapsed_time';
+ sDocTimeEle.value = 0;
+ sDocTimeEle.innerHTML = Util.humanizeSecs(0);
+ rowContainer.appendChild(sDocTimeEle);
+
var totalUsersEle = document.getElementById('active_docs_count');
totalUsersEle.innerHTML = parseInt(totalUsersEle.innerHTML) + 1;
}
@@ -169,7 +193,7 @@ var AdminSocketOverview = AdminSocketBase.extend({
var nData = parseInt(textMsg[1]);
if (sCommand === 'total_mem') {
- nData = Util.humanize(nData);
+ nData = Util.humanizeMem(nData);
}
document.getElementById(sCommand).innerHTML = nData;
}
@@ -186,5 +210,6 @@ var AdminSocketOverview = AdminSocketBase.extend({
onSocketClose: function() {
clearInterval(this._basicStatsIntervalId);
+ clearInterval(this._docElapsedTimeIntervalId);
}
});
diff --git a/loleaflet/src/admin/Util.js b/loleaflet/src/admin/Util.js
index 61db108..dd0cac1 100644
--- a/loleaflet/src/admin/Util.js
+++ b/loleaflet/src/admin/Util.js
@@ -8,7 +8,7 @@ var Util = Base.extend({
}, { // class itnerface
- humanize: function humanFileSize(kbytes) {
+ humanizeMem: function (kbytes) {
var unit = 1000;
var units = ['kB', 'MB', 'GB', 'TB'];
for (var i = 0; Math.abs(kbytes) >= unit && i < units.length; i++) {
@@ -16,5 +16,36 @@ var Util = Base.extend({
}
return kbytes.toFixed(1) + ' ' + units[i];
+ },
+
+ humanizeSecs: function(secs) {
+ var mins = 0;
+ var hrs = 0;
+ var res = '';
+
+ secs = parseInt(secs);
+ if (isNaN(secs))
+ return res;
+
+ if (secs >= 60) {
+ mins = Math.floor(secs / 60);
+ secs = secs - mins * 60;
+ }
+ if (mins >= 60) {
+ hrs = Math.floor(mins / 60);
+ mins = mins - hrs * 60;
+ }
+
+ if (hrs) {
+ res = hrs + ':' + mins + ' hrs';
+ } else if (mins) {
+ res = mins + ':' + secs + ' mins';
+ } else if (secs) {
+ res = secs + ' s';
+ } else {
+ res = '';
+ }
+
+ return res;
}
});
diff --git a/loolwsd/AdminModel.cpp b/loolwsd/AdminModel.cpp
index 644fa9c..7498fc9 100644
--- a/loolwsd/AdminModel.cpp
+++ b/loolwsd/AdminModel.cpp
@@ -348,11 +348,13 @@ std::string AdminModel::getDocuments()
std::string sUrl = it.second.getUrl();
std::string sViews = std::to_string(it.second.getActiveViews());
std::string sMem = std::to_string(Util::getMemoryUsage(it.second.getPid()));
+ std::string sElapsed = std::to_string(it.second.getElapsedTime());
oss << sPid << " "
<< sUrl << " "
<< sViews << " "
- << sMem << " \n ";
+ << sMem << " "
+ << sElapsed << " \n ";
}
return oss.str();
diff --git a/loolwsd/AdminModel.hpp b/loolwsd/AdminModel.hpp
index 444689b..7f7bf76 100644
--- a/loolwsd/AdminModel.hpp
+++ b/loolwsd/AdminModel.hpp
@@ -62,6 +62,8 @@ public:
bool isExpired() const { return _end != 0 && std::time(nullptr) >= _end; }
+ std::time_t getElapsedTime() const { return std::time(nullptr) - _start; }
+
void addView(int nSessionId);
void removeView(int nSessionId);
More information about the Libreoffice-commits
mailing list