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

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
« no previous file with comments | « remoting/webapp/me2mom/debug_log.js ('k') | remoting/webapp/me2mom/server_log_entry.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..48f21b2b9e14e880e38863b99f15080047089069 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.
@@ -49,13 +52,50 @@ remoting.LogToServer.prototype.setEnabled = function(enabled) {
*/
remoting.LogToServer.prototype.logClientSessionStateChange =
function(state, connectionError) {
- var entry = remoting.ServerLogEntry.prototype.makeClientSessionStateChange(
+ var entry = remoting.ServerLogEntry.makeClientSessionStateChange(
state, connectionError);
entry.addHostFields();
entry.addChromeVersionField();
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.makeStats(this.statsAccumulator);
+ if (entry) {
+ entry.addHostFields();
+ entry.addChromeVersionField();
+ entry.addWebappVersionField();
+ entry.addIdField(this.getId());
+ this.log(entry);
+ }
+ this.statsAccumulator.empty();
};
/**
@@ -68,20 +108,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.log('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);
};
« no previous file with comments | « remoting/webapp/me2mom/debug_log.js ('k') | remoting/webapp/me2mom/server_log_entry.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698