Move StatTimer from src/shared/util.js to src/display/dom_utils.js

Since the `StatTimer` is not used in the worker, duplicating this code on both the main and worker sides seem completely unnecessary.
This commit is contained in:
Jonas Jenwald 2017-12-06 13:51:04 +01:00
parent f299473697
commit 6b1eda3e12
4 changed files with 67 additions and 68 deletions

View file

@ -461,6 +461,66 @@ function isExternalLinkTargetSet() {
}
}
var StatTimer = (function StatTimerClosure() {
function rpad(str, pad, length) {
while (str.length < length) {
str += pad;
}
return str;
}
function StatTimer() {
this.started = Object.create(null);
this.times = [];
this.enabled = true;
}
StatTimer.prototype = {
time: function StatTimer_time(name) {
if (!this.enabled) {
return;
}
if (name in this.started) {
warn('Timer is already running for ' + name);
}
this.started[name] = Date.now();
},
timeEnd: function StatTimer_timeEnd(name) {
if (!this.enabled) {
return;
}
if (!(name in this.started)) {
warn('Timer has not been started for ' + name);
}
this.times.push({
'name': name,
'start': this.started[name],
'end': Date.now(),
});
// Remove timer from started so it can be called again.
delete this.started[name];
},
toString: function StatTimer_toString() {
var i, ii;
var times = this.times;
var out = '';
// Find the longest name for padding purposes.
var longest = 0;
for (i = 0, ii = times.length; i < ii; ++i) {
var name = times[i]['name'];
if (name.length > longest) {
longest = name.length;
}
}
for (i = 0, ii = times.length; i < ii; ++i) {
var span = times[i];
var duration = span.end - span.start;
out += rpad(span['name'], ' ', longest) + ' ' + duration + 'ms\n';
}
return out;
},
};
return StatTimer;
})();
export {
CustomStyle,
RenderingCancelledException,
@ -474,4 +534,5 @@ export {
DOMCMapReaderFactory,
DOMSVGFactory,
SimpleXMLParser,
StatTimer,
};