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
8 // http://www.apache.org/licenses/LICENSE-2.0
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");
14 goog
.provide('i18n.input.chrome.inputview.PerfTracker');
16 goog
.require('i18n.input.chrome.Statistics');
19 goog
.scope(function() {
24 * The tracker for the performance.
26 * @param {PerfTracker.TickName} htmlLoadedTickName .
29 i18n
.input
.chrome
.inputview
.PerfTracker = function(
32 * The time when this tracker starts.
36 this.startInMs_
= new Date().getTime();
38 this.tick(htmlLoadedTickName
,
39 window
['InputViewPageStartLoading'],
40 'Time elapsed before 0');
42 var PerfTracker
= i18n
.input
.chrome
.inputview
.PerfTracker
;
45 /** @private {boolean} */
46 PerfTracker
.prototype.stopped_
= false;
50 * The name of the tick.
54 PerfTracker
.TickName
= {
55 BACKGROUND_HTML_LOADED
: 'BackgroundHtmlLoaded',
56 NACL_LOADED
: 'NaclLoaded',
57 BACKGROUND_SETTINGS_FETCHED
: 'BackgroundSettingsFetched',
58 HTML_LOADED
: 'HtmlLoaded',
59 KEYBOARD_CREATED
: 'KeyboardCreated',
60 KEYBOARD_SHOWN
: 'KeyboardShown',
61 KEYSET_LOADED
: 'KeysetLoaded',
62 LAYOUT_LOADED
: 'LayoutLoaded'
67 * Resets this performance tracker.
69 PerfTracker
.prototype.restart = function() {
70 this.startInMs_
= new Date().getTime();
71 this.stopped_
= false;
76 * Stops the performance tracker.
78 PerfTracker
.prototype.stop = function() {
84 * Ticks with a custom message.
86 * @param {PerfTracker.TickName} tickName .
87 * @param {number=} opt_startInMs The timestamp used as start, if not
88 * specified, use this.startInMs_.
89 * @param {string=} opt_msg Extra log message to describe the logging in more
92 PerfTracker
.prototype.tick = function(tickName
, opt_startInMs
, opt_msg
) {
97 var startInMs
= opt_startInMs
|| this.startInMs_
;
98 var cost
= new Date().getTime() - startInMs
;
99 var msg
= tickName
+ ' - ' + cost
;
101 msg
+= ' - ' + opt_msg
;
104 i18n
.input
.chrome
.Statistics
.getInstance().recordLatency(
105 'InputMethod.VirtualKeyboard.InitLatency.' + tickName
, cost
);