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:
parent
f299473697
commit
6b1eda3e12
@ -15,15 +15,14 @@
|
|||||||
/* globals requirejs, __non_webpack_require__ */
|
/* globals requirejs, __non_webpack_require__ */
|
||||||
|
|
||||||
import {
|
import {
|
||||||
assert, createPromiseCapability, getVerbosityLevel, info,
|
assert, createPromiseCapability, getVerbosityLevel, info, InvalidPDFException,
|
||||||
InvalidPDFException, isArrayBuffer, isSameOrigin, loadJpegStream,
|
isArrayBuffer, isSameOrigin, loadJpegStream, MessageHandler,
|
||||||
MessageHandler, MissingPDFException, NativeImageDecoding, PageViewport,
|
MissingPDFException, NativeImageDecoding, PageViewport, PasswordException,
|
||||||
PasswordException, StatTimer, stringToBytes, UnexpectedResponseException,
|
stringToBytes, UnexpectedResponseException, UnknownErrorException, Util, warn
|
||||||
UnknownErrorException, Util, warn
|
|
||||||
} from '../shared/util';
|
} from '../shared/util';
|
||||||
import {
|
import {
|
||||||
DOMCanvasFactory, DOMCMapReaderFactory, getDefaultSetting,
|
DOMCanvasFactory, DOMCMapReaderFactory, getDefaultSetting,
|
||||||
RenderingCancelledException
|
RenderingCancelledException, StatTimer
|
||||||
} from './dom_utils';
|
} from './dom_utils';
|
||||||
import { FontFaceObject, FontLoader } from './font_loader';
|
import { FontFaceObject, FontLoader } from './font_loader';
|
||||||
import { CanvasGraphics } from './canvas';
|
import { CanvasGraphics } from './canvas';
|
||||||
|
@ -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 {
|
export {
|
||||||
CustomStyle,
|
CustomStyle,
|
||||||
RenderingCancelledException,
|
RenderingCancelledException,
|
||||||
@ -474,4 +534,5 @@ export {
|
|||||||
DOMCMapReaderFactory,
|
DOMCMapReaderFactory,
|
||||||
DOMSVGFactory,
|
DOMSVGFactory,
|
||||||
SimpleXMLParser,
|
SimpleXMLParser,
|
||||||
|
StatTimer,
|
||||||
};
|
};
|
||||||
|
@ -73,4 +73,4 @@ exports.RenderingCancelledException =
|
|||||||
pdfjsDisplayDOMUtils.RenderingCancelledException;
|
pdfjsDisplayDOMUtils.RenderingCancelledException;
|
||||||
exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
|
exports.getFilenameFromUrl = pdfjsDisplayDOMUtils.getFilenameFromUrl;
|
||||||
exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
|
exports.addLinkAttributes = pdfjsDisplayDOMUtils.addLinkAttributes;
|
||||||
exports.StatTimer = pdfjsSharedUtil.StatTimer;
|
exports.StatTimer = pdfjsDisplayDOMUtils.StatTimer;
|
||||||
|
@ -1118,66 +1118,6 @@ function createPromiseCapability() {
|
|||||||
return capability;
|
return capability;
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
|
||||||
})();
|
|
||||||
|
|
||||||
var createBlob = function createBlob(data, contentType) {
|
var createBlob = function createBlob(data, contentType) {
|
||||||
if (typeof Blob !== 'undefined') {
|
if (typeof Blob !== 'undefined') {
|
||||||
return new Blob([data], { type: contentType, });
|
return new Blob([data], { type: contentType, });
|
||||||
@ -1668,7 +1608,6 @@ export {
|
|||||||
PageViewport,
|
PageViewport,
|
||||||
PasswordException,
|
PasswordException,
|
||||||
PasswordResponses,
|
PasswordResponses,
|
||||||
StatTimer,
|
|
||||||
StreamType,
|
StreamType,
|
||||||
TextRenderingMode,
|
TextRenderingMode,
|
||||||
UnexpectedResponseException,
|
UnexpectedResponseException,
|
||||||
|
Loading…
Reference in New Issue
Block a user