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

Side by Side Diff: remoting/webapp/crd/js/log_to_server.js

Issue 953223002: Include time elapsed since start of a remoting session in each log entry. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Remove now unnecessary session duration logging. Created 5 years, 9 months 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 /** 5 /**
6 * @fileoverview 6 * @fileoverview
7 * Module for sending log entries to the server. 7 * Module for sending log entries to the server.
8 */ 8 */
9 9
10 'use strict'; 10 'use strict';
11 11
12 /** @suppress {duplicate} */ 12 /** @suppress {duplicate} */
13 var remoting = remoting || {}; 13 var remoting = remoting || {};
14 14
15 /** 15 /**
16 * @param {remoting.SignalStrategy} signalStrategy Signal strategy. 16 * @param {remoting.SignalStrategy} signalStrategy Signal strategy.
17 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection. 17 * @param {remoting.DesktopConnectedView.Mode} mode The mode of this connection.
18 * @constructor 18 * @constructor
19 */ 19 */
20 remoting.LogToServer = function(signalStrategy, mode) { 20 remoting.LogToServer = function(signalStrategy, mode) {
21 /** @private */ 21 /** @private */
22 this.statsAccumulator_ = new remoting.StatsAccumulator(); 22 this.statsAccumulator_ = new remoting.StatsAccumulator();
23 /** @private */ 23 /** @private */
24 this.sessionId_ = ''; 24 this.sessionId_ = '';
25 /** @private */ 25 /** @private */
26 this.sessionIdGenerationTime_ = 0; 26 this.sessionIdGenerationTime_ = 0;
27 /** @private */ 27 /** @private */
28 this.sessionStartTime_ = 0; 28 this.sessionStartTime_ = new Date().getTime();
29 /** @private */ 29 /** @private */
30 this.signalStrategy_ = signalStrategy; 30 this.signalStrategy_ = signalStrategy;
31 /** @private */ 31 /** @private */
32 this.mode_ = mode; 32 this.mode_ = mode;
33 /** @type {string} @private */ 33 /** @type {string} @private */
34 this.connectionType_ = ''; 34 this.connectionType_ = '';
35 35
36 this.setSessionId_(); 36 this.setSessionId_();
37 signalStrategy.sendConnectionSetupResults(this); 37 signalStrategy.sendConnectionSetupResults(this);
38 }; 38 };
(...skipping 14 matching lines...) Expand all
53 53
54 /** 54 /**
55 * Logs a client session state change. 55 * Logs a client session state change.
56 * 56 *
57 * @param {remoting.ClientSession.State} state 57 * @param {remoting.ClientSession.State} state
58 * @param {remoting.Error} connectionError 58 * @param {remoting.Error} connectionError
59 */ 59 */
60 remoting.LogToServer.prototype.logClientSessionStateChange = 60 remoting.LogToServer.prototype.logClientSessionStateChange =
61 function(state, connectionError) { 61 function(state, connectionError) {
62 this.maybeExpireSessionId_(); 62 this.maybeExpireSessionId_();
63 // Set the session start time if we haven't done so already.
64 if (remoting.LogToServer.isStartOfSession_(state)) {
65 if (this.sessionStartTime_ == 0) {
66 this.sessionStartTime_ = new Date().getTime();
67 }
68 }
69 // Log the session state change. 63 // Log the session state change.
70 var entry = remoting.ServerLogEntry.makeClientSessionStateChange( 64 var entry = remoting.ServerLogEntry.makeClientSessionStateChange(
71 state, connectionError, this.mode_); 65 state, connectionError, this.mode_);
72 entry.addHostFields(); 66 entry.addHostFields();
73 entry.addChromeVersionField(); 67 entry.addChromeVersionField();
74 entry.addWebappVersionField(); 68 entry.addWebappVersionField();
75 entry.addSessionIdField(this.sessionId_); 69 entry.addSessionIdField(this.sessionId_);
76 // Maybe clear the session start time, and log the session duration.
77 if (remoting.LogToServer.shouldAddDuration_(state) &&
78 (this.sessionStartTime_ != 0)) {
79 entry.addSessionDurationField(
80 (new Date().getTime() - this.sessionStartTime_) / 1000.0);
81 if (remoting.LogToServer.isEndOfSession_(state)) {
82 this.sessionStartTime_ = 0;
83 }
84 }
85 this.log_(entry); 70 this.log_(entry);
86 // Don't accumulate connection statistics across state changes. 71 // Don't accumulate connection statistics across state changes.
87 this.logAccumulatedStatistics_(); 72 this.logAccumulatedStatistics_();
88 this.statsAccumulator_.empty(); 73 this.statsAccumulator_.empty();
89 // Maybe clear the session ID. 74 // Maybe clear the session ID.
90 if (remoting.LogToServer.isEndOfSession_(state)) { 75 if (remoting.LogToServer.isEndOfSession_(state)) {
91 this.clearSessionId_(); 76 this.clearSessionId_();
92 } 77 }
93 }; 78 };
94 79
95 /** 80 /**
96 * Set the connection type (direct, stun relay). 81 * Set the connection type (direct, stun relay).
97 * 82 *
98 * @param {string} connectionType 83 * @param {string} connectionType
99 */ 84 */
100 remoting.LogToServer.prototype.setConnectionType = function(connectionType) { 85 remoting.LogToServer.prototype.setConnectionType = function(connectionType) {
101 this.connectionType_ = connectionType; 86 this.connectionType_ = connectionType;
102 }; 87 };
103 88
104 /** 89 /**
105 * @param {remoting.SignalStrategy.Type} strategyType 90 * @param {remoting.SignalStrategy.Type} strategyType
106 * @param {remoting.FallbackSignalStrategy.Progress} progress 91 * @param {remoting.FallbackSignalStrategy.Progress} progress
107 * @param {number} elapsedTimeInMs
108 */ 92 */
109 remoting.LogToServer.prototype.logSignalStrategyProgress = 93 remoting.LogToServer.prototype.logSignalStrategyProgress =
110 function(strategyType, progress, elapsedTimeInMs) { 94 function(strategyType, progress) {
111 this.maybeExpireSessionId_(); 95 this.maybeExpireSessionId_();
112 var entry = remoting.ServerLogEntry.makeSignalStrategyProgress( 96 var entry = remoting.ServerLogEntry.makeSignalStrategyProgress(
113 this.sessionId_, strategyType, progress, elapsedTimeInMs); 97 this.sessionId_, strategyType, progress);
114 this.log_(entry); 98 this.log_(entry);
115 }; 99 };
116 100
117 /** 101 /**
118 * Whether a session state is one of the states that occurs at the start of 102 * Whether a session state is one of the states that occurs at the start of
119 * a session. 103 * a session.
120 * 104 *
121 * @private 105 * @private
122 * @param {remoting.ClientSession.State} state 106 * @param {remoting.ClientSession.State} state
123 * @return {boolean} 107 * @return {boolean}
(...skipping 12 matching lines...) Expand all
136 * @param {remoting.ClientSession.State} state 120 * @param {remoting.ClientSession.State} state
137 * @return {boolean} 121 * @return {boolean}
138 */ 122 */
139 remoting.LogToServer.isEndOfSession_ = function(state) { 123 remoting.LogToServer.isEndOfSession_ = function(state) {
140 return ((state == remoting.ClientSession.State.CLOSED) || 124 return ((state == remoting.ClientSession.State.CLOSED) ||
141 (state == remoting.ClientSession.State.FAILED) || 125 (state == remoting.ClientSession.State.FAILED) ||
142 (state == remoting.ClientSession.State.CONNECTION_DROPPED) || 126 (state == remoting.ClientSession.State.CONNECTION_DROPPED) ||
143 (state == remoting.ClientSession.State.CONNECTION_CANCELED)); 127 (state == remoting.ClientSession.State.CONNECTION_CANCELED));
144 }; 128 };
145 129
146 /**
147 * Whether the duration should be added to the log entry for this state.
148 *
149 * @private
150 * @param {remoting.ClientSession.State} state
151 * @return {boolean}
152 */
153 remoting.LogToServer.shouldAddDuration_ = function(state) {
154 // Duration is added to log entries at the end of the session, as well as at
155 // some intermediate states where it is relevant (e.g. to determine how long
156 // it took for a session to become CONNECTED).
157 return (remoting.LogToServer.isEndOfSession_(state) ||
158 (state == remoting.ClientSession.State.CONNECTED));
159 };
160 130
161 /** 131 /**
162 * Logs connection statistics. 132 * Logs connection statistics.
163 * @param {Object<string, number>} stats The connection statistics 133 * @param {Object<string, number>} stats The connection statistics
164 */ 134 */
165 remoting.LogToServer.prototype.logStatistics = function(stats) { 135 remoting.LogToServer.prototype.logStatistics = function(stats) {
166 this.maybeExpireSessionId_(); 136 this.maybeExpireSessionId_();
167 // Store the statistics. 137 // Store the statistics.
168 this.statsAccumulator_.add(stats); 138 this.statsAccumulator_.add(stats);
169 // Send statistics to the server if they've been accumulating for at least 139 // Send statistics to the server if they've been accumulating for at least
(...skipping 26 matching lines...) Expand all
196 this.statsAccumulator_.empty(); 166 this.statsAccumulator_.empty();
197 }; 167 };
198 168
199 /** 169 /**
200 * Sends a log entry to the server. 170 * Sends a log entry to the server.
201 * 171 *
202 * @private 172 * @private
203 * @param {remoting.ServerLogEntry} entry 173 * @param {remoting.ServerLogEntry} entry
204 */ 174 */
205 remoting.LogToServer.prototype.log_ = function(entry) { 175 remoting.LogToServer.prototype.log_ = function(entry) {
176 // Log the time taken to get to this point from the time this session started.
177 var elapsedTimeInMs = new Date().getTime() - this.sessionStartTime_;
178 entry.addElapsedTimeMs(elapsedTimeInMs);
179
206 // Send the stanza to the debug log. 180 // Send the stanza to the debug log.
207 console.log('Enqueueing log entry:'); 181 console.log('Enqueueing log entry:');
208 entry.toDebugLog(1); 182 entry.toDebugLog(1);
209 183
210 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' + 184 var stanza = '<cli:iq to="' + remoting.settings.DIRECTORY_BOT_JID + '" ' +
211 'type="set" xmlns:cli="jabber:client">' + 185 'type="set" xmlns:cli="jabber:client">' +
212 '<gr:log xmlns:gr="google:remoting">' + 186 '<gr:log xmlns:gr="google:remoting">' +
213 entry.toStanza() + 187 entry.toStanza() +
214 '</gr:log>' + 188 '</gr:log>' +
215 '</cli:iq>'; 189 '</cli:iq>';
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 remoting.LogToServer.generateSessionId_ = function() { 244 remoting.LogToServer.generateSessionId_ = function() {
271 var idArray = []; 245 var idArray = [];
272 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) { 246 for (var i = 0; i < remoting.LogToServer.SESSION_ID_LEN_; i++) {
273 var index = 247 var index =
274 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length; 248 Math.random() * remoting.LogToServer.SESSION_ID_ALPHABET_.length;
275 idArray.push( 249 idArray.push(
276 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1)); 250 remoting.LogToServer.SESSION_ID_ALPHABET_.slice(index, index + 1));
277 } 251 }
278 return idArray.join(''); 252 return idArray.join('');
279 }; 253 };
OLDNEW
« no previous file with comments | « remoting/webapp/crd/js/fallback_signal_strategy.js ('k') | remoting/webapp/crd/js/server_log_entry.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698