OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 * A class of server log entries. | 7 * A class of server log entries. |
8 */ | 8 */ |
9 | 9 |
10 'use strict'; | 10 'use strict'; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
87 case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL: | 87 case remoting.ClientSession.ConnectionError.INCOMPATIBLE_PROTOCOL: |
88 return 'incompatible-protocol'; | 88 return 'incompatible-protocol'; |
89 case remoting.ClientSession.ConnectionError.NETWORK_FAILURE: | 89 case remoting.ClientSession.ConnectionError.NETWORK_FAILURE: |
90 return 'network-failure'; | 90 return 'network-failure'; |
91 default: | 91 default: |
92 return 'unknown-' + connectionError; | 92 return 'unknown-' + connectionError; |
93 } | 93 } |
94 } | 94 } |
95 | 95 |
96 /** @private */ | 96 /** @private */ |
97 remoting.ServerLogEntry.prototype.VALUE_EVENT_NAME_CONNECTION_STATISTICS_ = | |
98 "connection-statistics"; | |
99 /** @private */ | |
100 remoting.ServerLogEntry.prototype.KEY_VIDEO_BANDWIDTH_ = "video-bandwidth"; | |
101 /** @private */ | |
102 remoting.ServerLogEntry.prototype.KEY_CAPTURE_LATENCY_ = "capture-latency"; | |
103 /** @private */ | |
104 remoting.ServerLogEntry.prototype.KEY_ENCODE_LATENCY_ = "encode-latency"; | |
105 /** @private */ | |
106 remoting.ServerLogEntry.prototype.KEY_DECODE_LATENCY_ = "decode-latency"; | |
107 /** @private */ | |
108 remoting.ServerLogEntry.prototype.KEY_RENDER_LATENCY_ = "render-latency"; | |
109 /** @private */ | |
110 remoting.ServerLogEntry.prototype.KEY_ROUNDTRIP_LATENCY_ = "roundtrip-latency"; | |
Jamie
2011/12/09 19:47:56
Why not reuse the keys from ClientSession?
simonmorris
2011/12/09 21:12:12
Because I want to be able to look down the list of
| |
111 | |
112 /** @private */ | |
97 remoting.ServerLogEntry.prototype.KEY_OS_NAME_ = 'os-name'; | 113 remoting.ServerLogEntry.prototype.KEY_OS_NAME_ = 'os-name'; |
98 /** @private */ | 114 /** @private */ |
99 remoting.ServerLogEntry.prototype.VALUE_OS_NAME_WINDOWS_ = 'Windows'; | 115 remoting.ServerLogEntry.prototype.VALUE_OS_NAME_WINDOWS_ = 'Windows'; |
100 /** @private */ | 116 /** @private */ |
101 remoting.ServerLogEntry.prototype.VALUE_OS_NAME_LINUX_ = 'Linux'; | 117 remoting.ServerLogEntry.prototype.VALUE_OS_NAME_LINUX_ = 'Linux'; |
102 /** @private */ | 118 /** @private */ |
103 remoting.ServerLogEntry.prototype.VALUE_OS_NAME_MAC_ = 'Mac'; | 119 remoting.ServerLogEntry.prototype.VALUE_OS_NAME_MAC_ = 'Mac'; |
104 /** @private */ | 120 /** @private */ |
105 remoting.ServerLogEntry.prototype.VALUE_OS_NAME_CHROMEOS_ = 'ChromeOS'; | 121 remoting.ServerLogEntry.prototype.VALUE_OS_NAME_CHROMEOS_ = 'ChromeOS'; |
106 | 122 |
(...skipping 28 matching lines...) Expand all Loading... | |
135 remoting.ServerLogEntry.prototype.toStanza = function() { | 151 remoting.ServerLogEntry.prototype.toStanza = function() { |
136 var stanza = '<gr:entry '; | 152 var stanza = '<gr:entry '; |
137 for (var key in this.dict) { | 153 for (var key in this.dict) { |
138 stanza += escape(key) + '="' + escape(this.dict[key]) + '" '; | 154 stanza += escape(key) + '="' + escape(this.dict[key]) + '" '; |
139 } | 155 } |
140 stanza += '/>'; | 156 stanza += '/>'; |
141 return stanza; | 157 return stanza; |
142 }; | 158 }; |
143 | 159 |
144 /** | 160 /** |
161 * Prints this object on the debug log. | |
162 * | |
163 * @param {number} indentLevel the indentation level of each field | |
164 */ | |
165 remoting.ServerLogEntry.prototype.toDebugLog = function(indentLevel) { | |
166 for (var key in this.dict) { | |
167 remoting.debug.logIndent(indentLevel, key + ': ' + this.dict[key]); | |
168 } | |
Jamie
2011/12/09 19:47:56
It might be better to log these on a single line,
simonmorris
2011/12/09 21:12:12
Done.
| |
169 }; | |
170 | |
171 /** | |
145 * Makes a log entry for a change of client session state. | 172 * Makes a log entry for a change of client session state. |
146 * | 173 * |
147 * @param {remoting.ClientSession.State} state | 174 * @param {remoting.ClientSession.State} state |
148 * @param {remoting.ClientSession.ConnectionError} connectionError | 175 * @param {remoting.ClientSession.ConnectionError} connectionError |
149 * @return {remoting.ServerLogEntry} | 176 * @return {remoting.ServerLogEntry} |
150 */ | 177 */ |
151 remoting.ServerLogEntry.prototype.makeClientSessionStateChange = | 178 remoting.ServerLogEntry.prototype.makeClientSessionStateChange = |
152 function(state, connectionError) { | 179 function(state, connectionError) { |
153 var entry = new remoting.ServerLogEntry(); | 180 var entry = new remoting.ServerLogEntry(); |
154 entry.set(this.KEY_ROLE_, this.VALUE_ROLE_CLIENT_); | 181 entry.set(this.KEY_ROLE_, this.VALUE_ROLE_CLIENT_); |
155 entry.set(this.KEY_EVENT_NAME_, this.VALUE_EVENT_NAME_SESSION_STATE_); | 182 entry.set(this.KEY_EVENT_NAME_, this.VALUE_EVENT_NAME_SESSION_STATE_); |
156 entry.set(this.KEY_SESSION_STATE_, this.getValueForSessionState(state)); | 183 entry.set(this.KEY_SESSION_STATE_, this.getValueForSessionState(state)); |
157 if (connectionError != remoting.ClientSession.ConnectionError.NONE) { | 184 if (connectionError != remoting.ClientSession.ConnectionError.NONE) { |
158 entry.set(this.KEY_CONNECTION_ERROR_, | 185 entry.set(this.KEY_CONNECTION_ERROR_, |
159 this.getValueForConnectionError(connectionError)); | 186 this.getValueForConnectionError(connectionError)); |
160 } | 187 } |
161 return entry; | 188 return entry; |
162 }; | 189 }; |
163 | 190 |
164 /** | 191 /** |
192 * Makes a log entry for a set of connection statistics. | |
193 * Returns null if all the statistics were zero. | |
194 * | |
195 * @param {remoting.StatsAccumulator} statsAccumulator | |
196 * @return {?remoting.ServerLogEntry} | |
197 */ | |
198 remoting.ServerLogEntry.prototype.makeStats = function(statsAccumulator) { | |
Jamie
2011/12/09 19:47:56
I don't think this (or the previous method) belong
simonmorris
2011/12/09 21:12:12
Done.
| |
199 var entry = new remoting.ServerLogEntry(); | |
200 entry.set(this.KEY_ROLE_, this.VALUE_ROLE_CLIENT_); | |
201 entry.set(this.KEY_EVENT_NAME_, this.VALUE_EVENT_NAME_CONNECTION_STATISTICS_); | |
202 var nonZero = false; | |
203 nonZero |= entry.addStatsField( | |
204 this.KEY_VIDEO_BANDWIDTH_, | |
205 remoting.ClientSession.STATS_KEY_VIDEO_BANDWIDTH, statsAccumulator); | |
206 nonZero |= entry.addStatsField( | |
207 this.KEY_CAPTURE_LATENCY_, | |
208 remoting.ClientSession.STATS_KEY_CAPTURE_LATENCY, statsAccumulator); | |
209 nonZero |= entry.addStatsField( | |
210 this.KEY_ENCODE_LATENCY_, | |
211 remoting.ClientSession.STATS_KEY_ENCODE_LATENCY, statsAccumulator); | |
212 nonZero |= entry.addStatsField( | |
213 this.KEY_DECODE_LATENCY_, | |
214 remoting.ClientSession.STATS_KEY_DECODE_LATENCY, statsAccumulator); | |
215 nonZero |= entry.addStatsField( | |
216 this.KEY_RENDER_LATENCY_, | |
217 remoting.ClientSession.STATS_KEY_RENDER_LATENCY, statsAccumulator); | |
218 nonZero |= entry.addStatsField( | |
219 this.KEY_ROUNDTRIP_LATENCY_, | |
220 remoting.ClientSession.STATS_KEY_ROUNDTRIP_LATENCY, statsAccumulator); | |
221 if (nonZero) { | |
222 return entry; | |
223 } | |
224 return null; | |
225 }; | |
226 | |
227 /** | |
228 * Adds one connection statistic to a log entry. | |
229 * | |
230 * @private | |
231 * @param {string} entryKey | |
232 * @param {string} statsKey | |
233 * @param {remoting.StatsAccumulator} statsAccumulator | |
234 * @return {boolean} whether the statistic is non-zero | |
235 */ | |
236 remoting.ServerLogEntry.prototype.addStatsField = function( | |
237 entryKey, statsKey, statsAccumulator) { | |
238 var val = statsAccumulator.calcMean(statsKey); | |
239 this.set(entryKey, val.toString()); | |
240 return (val != 0); | |
241 }; | |
242 | |
243 /** | |
165 * Adds an ID field to this log entry. | 244 * Adds an ID field to this log entry. |
166 * | 245 * |
167 * @param {string} id | 246 * @param {string} id |
168 */ | 247 */ |
169 remoting.ServerLogEntry.prototype.addIdField = function(id) { | 248 remoting.ServerLogEntry.prototype.addIdField = function(id) { |
170 this.set(this.KEY_ID_, id); | 249 this.set(this.KEY_ID_, id); |
171 } | 250 } |
172 | 251 |
173 /** | 252 /** |
174 * Adds fields describing the host to this log entry. | 253 * Adds fields describing the host to this log entry. |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
284 } | 363 } |
285 return null; | 364 return null; |
286 }; | 365 }; |
287 | 366 |
288 /** | 367 /** |
289 * Adds a field specifying the webapp version to this log entry. | 368 * Adds a field specifying the webapp version to this log entry. |
290 */ | 369 */ |
291 remoting.ServerLogEntry.prototype.addWebappVersionField = function() { | 370 remoting.ServerLogEntry.prototype.addWebappVersionField = function() { |
292 this.set(this.KEY_WEBAPP_VERSION_, chrome.app.getDetails().version); | 371 this.set(this.KEY_WEBAPP_VERSION_, chrome.app.getDetails().version); |
293 }; | 372 }; |
OLD | NEW |