Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3625)

Unified Diff: remoting/webapp/me2mom/log_to_server.js

Issue 8865005: The chromoting client logs connection statistics to the server. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Review. Created 9 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: remoting/webapp/me2mom/log_to_server.js
diff --git a/remoting/webapp/me2mom/log_to_server.js b/remoting/webapp/me2mom/log_to_server.js
index 017bc1afe21c0ce4816f1a8d4fcb05803e871f53..349b77a43d5c75042c6d995c4ea1ef6e54ff8c35 100644
--- a/remoting/webapp/me2mom/log_to_server.js
+++ b/remoting/webapp/me2mom/log_to_server.js
@@ -16,7 +16,10 @@ var remoting = remoting || {};
* @constructor
*/
remoting.LogToServer = function() {
- /** @type Array.<string> */ this.pendingEntries = [];
+ /** @type Array.<string> */
+ this.pendingEntries = [];
+ /** @type {remoting.StatsAccumulator} */
+ this.statsAccumulator = new remoting.StatsAccumulator();
};
// Local storage keys.
@@ -56,6 +59,44 @@ remoting.LogToServer.prototype.logClientSessionStateChange =
entry.addWebappVersionField();
entry.addIdField(this.getId());
this.log(entry);
+ // Don't accumulate connection statistics across state changes.
+ this.logAccumulatedStatistics();
+ this.statsAccumulator.empty();
+};
+
+/**
+ * Logs connection statistics.
+ * @param {Object.<string, number>} stats the connection statistics
+ */
+remoting.LogToServer.prototype.logStatistics = function(stats) {
+ // Store the statistics.
+ this.statsAccumulator.add(stats);
+ // Send statistics to the server if they've been accumulating for at least
+ // 60 seconds.
+ if (this.statsAccumulator.getTimeSinceFirstValue() >= 60 * 1000) {
+ this.logAccumulatedStatistics();
+ }
+};
+
+/**
+ * Moves connection statistics from the accumulator to the log server.
+ *
+ * If all the statistics are zero, then the accumulator is still emptied,
+ * but the statistics are not sent to the log server.
+ *
+ * @private
+ */
+remoting.LogToServer.prototype.logAccumulatedStatistics = function() {
+ var entry = remoting.ServerLogEntry.prototype.makeStats(
+ this.statsAccumulator);
Jamie 2011/12/09 19:47:56 Directly invoking a method on the prototype seems
simonmorris 2011/12/09 21:12:12 This was just because I didn't have the convention
+ if (entry) {
+ entry.addHostFields();
+ entry.addChromeVersionField();
+ entry.addWebappVersionField();
+ entry.addIdField(this.getId());
+ this.log(entry);
+ }
+ this.statsAccumulator.empty();
};
/**
@@ -68,20 +109,25 @@ remoting.LogToServer.prototype.log = function(entry) {
if (!this.isEnabled()) {
return;
}
- // Store a stanza for the entry
+ // Send the stanza to the debug log.
+ remoting.debug.logIndent(0, 'Enqueueing log entry:');
+ entry.toDebugLog(1);
+ // Store a stanza for the entry.
this.pendingEntries.push(entry.toStanza());
// Stop if there's no connection to the server.
if (!remoting.wcs) {
return;
}
// Send all pending entries to the server.
+ remoting.debug.log('Sending ' + this.pendingEntries.length + ' log ' +
+ ((this.pendingEntries.length == 1) ? 'entry' : 'entries') +
+ ' to the server.');
var stanza = '<cli:iq to="remoting@bot.talk.google.com" type="set" ' +
'xmlns:cli="jabber:client"><gr:log xmlns:gr="google:remoting">';
while (this.pendingEntries.length > 0) {
stanza += /** @type string */ this.pendingEntries.shift();
}
stanza += '</gr:log></cli:iq>';
- remoting.debug.logIq(true, stanza);
remoting.wcs.sendIq(stanza);
};
@@ -132,3 +178,14 @@ remoting.LogToServer.prototype.generateId = function() {
}
return idArray.join('');
};
+
+/**
+ * Sends a message describing a log entry to the debug log.
+ *
+ * @private
+ * @param {remoting.ServerLogEntry} entry
+ */
+remoting.LogToServer.prototype.logToConsole = function(entry) {
+ remoting.debug.logIndent(0, 'Queueing log entry:');
+ entry.toDebugLog(1)
+};
Jamie 2011/12/09 19:47:56 This function looks like it's unused.
simonmorris 2011/12/09 21:12:12 Done.

Powered by Google App Engine
This is Rietveld 408576698