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 * Module to support logging debug messages. | 7 * Module to support logging debug messages. |
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 * @constructor | 16 * @constructor |
17 * @param {Element} logElement The HTML div to which to add log messages. | 17 * @param {Element} logElement The HTML div to which to add log messages. |
18 * @param {Element} statsElement The HTML div to which to update stats. | |
Jamie
2011/10/27 20:41:36
I've extended DebugLog to manage the stats panel a
garykac
2011/10/27 22:32:39
OK
| |
18 */ | 19 */ |
19 remoting.DebugLog = function(logElement) { | 20 remoting.DebugLog = function(logElement, statsElement) { |
20 this.debugLog = logElement; | 21 this.logElement = logElement; |
22 this.statsElement = statsElement; | |
21 }; | 23 }; |
22 | 24 |
23 /** Maximum number of lines to record in the debug log. Only the most | 25 /** |
24 * recent <n> lines are displayed. */ | 26 * Maximum number of lines to record in the debug log. Only the most |
27 * recent <n> lines are displayed. | |
28 */ | |
25 remoting.DebugLog.prototype.MAX_DEBUG_LOG_SIZE = 1000; | 29 remoting.DebugLog.prototype.MAX_DEBUG_LOG_SIZE = 1000; |
26 | 30 |
27 /** | 31 /** |
28 * Add the given message to the debug log. | 32 * Add the given message to the debug log. |
29 * | 33 * |
30 * @param {string} message The debug info to add to the log. | 34 * @param {string} message The debug info to add to the log. |
31 */ | 35 */ |
32 remoting.DebugLog.prototype.log = function(message) { | 36 remoting.DebugLog.prototype.log = function(message) { |
33 // Remove lines from top if we've hit our max log size. | 37 // Remove lines from top if we've hit our max log size. |
34 if (this.debugLog.childNodes.length == this.MAX_DEBUG_LOG_SIZE) { | 38 if (this.logElement.childNodes.length == this.MAX_DEBUG_LOG_SIZE) { |
35 this.debugLog.removeChild(this.debugLog.firstChild); | 39 this.logElement.removeChild(this.logElement.firstChild); |
36 } | 40 } |
37 | 41 |
38 // Add the new <p> to the end of the debug log. | 42 // Add the new <p> to the end of the debug log. |
39 var p = document.createElement('p'); | 43 var p = document.createElement('p'); |
40 p.appendChild(document.createTextNode(message)); | 44 p.appendChild(document.createTextNode(message)); |
41 this.debugLog.appendChild(p); | 45 this.logElement.appendChild(p); |
42 | 46 |
43 // Scroll to bottom of div | 47 // Scroll to bottom of div |
44 this.debugLog.scrollTop = this.debugLog.scrollHeight; | 48 this.logElement.scrollTop = this.logElement.scrollHeight; |
45 }; | 49 }; |
46 | 50 |
51 /** | |
52 * Show or hide the debug log. | |
53 */ | |
54 remoting.DebugLog.prototype.toggle = function() { | |
55 var debugLog = /** @type {Element} */ this.logElement.parentNode; | |
56 if (debugLog.hidden) { | |
57 debugLog.hidden = false; | |
58 } else { | |
59 debugLog.hidden = true; | |
60 } | |
61 }; | |
62 | |
63 /** | |
64 * Update the statistics panel. | |
65 * @param {Object.<string, number>} stats The connection statistics. | |
66 */ | |
67 remoting.DebugLog.prototype.updateStatistics = function(stats) { | |
68 var units = ''; | |
69 var videoBandwidth = stats['video_bandwidth']; | |
70 if (videoBandwidth < 1024) { | |
71 units = 'Bps'; | |
72 } else if (videoBandwidth < 1048576) { | |
73 units = 'KiBps'; | |
74 videoBandwidth = videoBandwidth / 1024; | |
75 } else if (videoBandwidth < 1073741824) { | |
76 units = 'MiBps'; | |
77 videoBandwidth = videoBandwidth / 1048576; | |
78 } else { | |
79 units = 'GiBps'; | |
80 videoBandwidth = videoBandwidth / 1073741824; | |
81 } | |
82 | |
83 var statistics = document.getElementById('statistics'); | |
84 this.statsElement.innerText = | |
85 'Bandwidth: ' + videoBandwidth.toFixed(2) + units + | |
86 ', Frame Rate: ' + | |
87 (stats['video_frame_rate'] ? | |
88 stats['video_frame_rate'].toFixed(2) + ' fps' : 'n/a') + | |
89 ', Capture: ' + stats['capture_latency'].toFixed(2) + 'ms' + | |
90 ', Encode: ' + stats['encode_latency'].toFixed(2) + 'ms' + | |
91 ', Decode: ' + stats['decode_latency'].toFixed(2) + 'ms' + | |
92 ', Render: ' + stats['render_latency'].toFixed(2) + 'ms' + | |
93 ', Latency: ' + stats['roundtrip_latency'].toFixed(2) + 'ms'; | |
94 }; | |
95 | |
96 /** | |
97 * Check for the debug toggle hot-key. | |
98 * | |
99 * @param {Event} event The keyboard event. | |
100 * @return {void} Nothing. | |
101 */ | |
102 remoting.DebugLog.onKeydown = function(event) { | |
103 if (String.fromCharCode(event.which) == 'D') { | |
104 remoting.debug.toggle(); | |
105 } | |
106 } | |
107 | |
47 /** @type {remoting.DebugLog} */ | 108 /** @type {remoting.DebugLog} */ |
48 remoting.debug = null; | 109 remoting.debug = null; |
OLD | NEW |