OLD | NEW |
(Empty) | |
| 1 // Copyright 2014 The ChromeOS IME Authors. All Rights Reserved. |
| 2 // limitations under the License. |
| 3 // See the License for the specific language governing permissions and |
| 4 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 5 // distributed under the License is distributed on an "AS-IS" BASIS, |
| 6 // Unless required by applicable law or agreed to in writing, software |
| 7 // |
| 8 // http://www.apache.org/licenses/LICENSE-2.0 |
| 9 // |
| 10 // You may obtain a copy of the License at |
| 11 // you may not use this file except in compliance with the License. |
| 12 // Licensed under the Apache License, Version 2.0 (the "License"); |
| 13 // |
| 14 goog.provide('i18n.input.chrome.inputview.PerfTracker'); |
| 15 |
| 16 goog.require('i18n.input.chrome.Statistics'); |
| 17 |
| 18 |
| 19 goog.scope(function() { |
| 20 |
| 21 |
| 22 |
| 23 /** |
| 24 * The tracker for the performance. |
| 25 * |
| 26 * @param {PerfTracker.TickName} htmlLoadedTickName . |
| 27 * @constructor |
| 28 */ |
| 29 i18n.input.chrome.inputview.PerfTracker = function( |
| 30 htmlLoadedTickName) { |
| 31 /** |
| 32 * The time when this tracker starts. |
| 33 * |
| 34 * @private {number} |
| 35 */ |
| 36 this.startInMs_ = new Date().getTime(); |
| 37 |
| 38 this.tick(htmlLoadedTickName, |
| 39 window['InputViewPageStartLoading']); |
| 40 }; |
| 41 var PerfTracker = i18n.input.chrome.inputview.PerfTracker; |
| 42 |
| 43 |
| 44 /** @private {boolean} */ |
| 45 PerfTracker.prototype.stopped_ = false; |
| 46 |
| 47 |
| 48 /** |
| 49 * The name of the tick. |
| 50 * |
| 51 * @enum {string} |
| 52 */ |
| 53 PerfTracker.TickName = { |
| 54 BACKGROUND_HTML_LOADED: 'BackgroundHtmlLoaded', |
| 55 NACL_LOADED: 'NaclLoaded', |
| 56 BACKGROUND_SETTINGS_FETCHED: 'BackgroundSettingsFetched', |
| 57 HTML_LOADED: 'HtmlLoaded', |
| 58 KEYBOARD_CREATED: 'KeyboardCreated', |
| 59 KEYBOARD_SHOWN: 'KeyboardShown', |
| 60 KEYSET_LOADED: 'KeysetLoaded', |
| 61 LAYOUT_LOADED: 'LayoutLoaded' |
| 62 }; |
| 63 |
| 64 |
| 65 /** |
| 66 * Resets this performance tracker. |
| 67 */ |
| 68 PerfTracker.prototype.restart = function() { |
| 69 this.startInMs_ = new Date().getTime(); |
| 70 this.stopped_ = false; |
| 71 }; |
| 72 |
| 73 |
| 74 /** |
| 75 * Stops the performance tracker. |
| 76 */ |
| 77 PerfTracker.prototype.stop = function() { |
| 78 this.stopped_ = true; |
| 79 }; |
| 80 |
| 81 |
| 82 /** |
| 83 * Ticks with a custom message. |
| 84 * |
| 85 * @param {PerfTracker.TickName} tickName . |
| 86 * @param {number=} opt_startInMs The timestamp used as start, if not |
| 87 * specified, use this.startInMs_. |
| 88 */ |
| 89 PerfTracker.prototype.tick = function(tickName, opt_startInMs) { |
| 90 if (this.stopped_) { |
| 91 return; |
| 92 } |
| 93 |
| 94 var startInMs = opt_startInMs || this.startInMs_; |
| 95 var cost = new Date().getTime() - startInMs; |
| 96 console.log(tickName + ' - ' + cost); |
| 97 i18n.input.chrome.Statistics.getInstance().recordLatency( |
| 98 'InputMethod.VirtualKeyboard.InitLatency.' + tickName, cost); |
| 99 }; |
| 100 |
| 101 }); // goog.scope |
| 102 |
OLD | NEW |