Better format for timing log

Calculating the duration when reporting timings often suffered floating
point round-offs that harmed the legibility of the log. For example,
rendering a diff might have logged the following.

  Diff Syntax Render: 71.60000000000036

With this change, the value is rounded and units are added, so the same
log message appears like the following.

  Diff Syntax Render: 72ms

Change-Id: Ib52349ea796734189efe2b88c1c072bf1bd981cf
This commit is contained in:
Wyatt Allen
2017-09-13 09:53:47 -07:00
parent 8e4c17c0d0
commit 4f1e607a9d
2 changed files with 4 additions and 4 deletions

View File

@@ -198,7 +198,7 @@
*/
timeEnd(name) {
const baseTime = this._baselines[name] || 0;
const time = this.now() - baseTime;
const time = Math.round(this.now() - baseTime) + 'ms';
this.reporter(TIMING.TYPE, TIMING.CATEGORY, name, time);
delete this._baselines[name];
},

View File

@@ -85,10 +85,10 @@ limitations under the License.
nowStub.returns(3.123);
element.timeEnd('foo');
assert.isTrue(element.reporter.calledWithExactly(
'timing-report', 'UI Latency', 'foo', 3.123
'timing-report', 'UI Latency', 'foo', '3ms'
));
assert.isTrue(element.reporter.calledWithExactly(
'timing-report', 'UI Latency', 'bar', 1
'timing-report', 'UI Latency', 'bar', '1ms'
));
});
@@ -104,7 +104,7 @@ limitations under the License.
sandbox.stub(element, 'now').returns(42);
element.pluginsLoaded();
assert.isTrue(element.defaultReporter.calledWithExactly(
'timing-report', 'UI Latency', 'PluginsLoaded', 42
'timing-report', 'UI Latency', 'PluginsLoaded', '42ms'
));
});