2011-12-06 07:50:25 +04:00
|
|
|
(function( $ ){
|
|
|
|
|
2012-01-25 23:14:02 +04:00
|
|
|
/**
|
2012-02-15 23:50:27 +04:00
|
|
|
* A utility class useful for developers to establish baseline performance
|
|
|
|
* metrics of rendering routines.
|
2012-01-25 23:14:02 +04:00
|
|
|
* @class
|
2012-02-15 23:50:27 +04:00
|
|
|
* @property {Boolean} midUpdate
|
|
|
|
* @property {Number} numUpdates
|
|
|
|
* @property {Number} lastBeginTime
|
|
|
|
* @property {Number} lastEndTime
|
|
|
|
* @property {Number} minUpdateTime
|
|
|
|
* @property {Number} avgUpdateTime
|
|
|
|
* @property {Number} maxUpdateTime
|
|
|
|
* @property {Number} minIdleTime
|
|
|
|
* @property {Number} avgIdleTime
|
|
|
|
* @property {Number} maxIdleTime
|
2012-01-25 23:14:02 +04:00
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
$.Profiler = function() {
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.midUpdate = false;
|
|
|
|
this.numUpdates = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.lastBeginTime = null;
|
|
|
|
this.lastEndTime = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.minUpdateTime = Infinity;
|
|
|
|
this.avgUpdateTime = 0;
|
|
|
|
this.maxUpdateTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.minIdleTime = Infinity;
|
|
|
|
this.avgIdleTime = 0;
|
|
|
|
this.maxIdleTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
$.Profiler.prototype = {
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
beginUpdate: function() {
|
2011-12-30 02:14:42 +04:00
|
|
|
if (this.midUpdate) {
|
2011-12-06 07:50:25 +04:00
|
|
|
this.endUpdate();
|
|
|
|
}
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.midUpdate = true;
|
|
|
|
this.lastBeginTime = new Date().getTime();
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if (this.numUpdates < 1) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return; // this is the first update
|
|
|
|
}
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
var time = this.lastBeginTime - this.lastEndTime;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.avgIdleTime = (this.avgIdleTime * (this.numUpdates - 1) + time) / this.numUpdates;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if (time < this.minIdleTime) {
|
|
|
|
this.minIdleTime = time;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-30 02:14:42 +04:00
|
|
|
if (time > this.maxIdleTime) {
|
|
|
|
this.maxIdleTime = time;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
endUpdate: function() {
|
2011-12-30 02:14:42 +04:00
|
|
|
if (!this.midUpdate) {
|
2011-12-06 07:50:25 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.lastEndTime = new Date().getTime();
|
|
|
|
this.midUpdate = false;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
var time = this.lastEndTime - this.lastBeginTime;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.numUpdates++;
|
|
|
|
this.avgUpdateTime = (this.avgUpdateTime * (this.numUpdates - 1) + time) / this.numUpdates;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
if (time < this.minUpdateTime) {
|
|
|
|
this.minUpdateTime = time;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
2011-12-30 02:14:42 +04:00
|
|
|
if (time > this.maxUpdateTime) {
|
|
|
|
this.maxUpdateTime = time;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2012-02-15 23:50:27 +04:00
|
|
|
/**
|
|
|
|
* @function
|
|
|
|
*/
|
2011-12-06 07:50:25 +04:00
|
|
|
clearProfile: function() {
|
2011-12-30 02:14:42 +04:00
|
|
|
this.midUpdate = false;
|
|
|
|
this.numUpdates = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.lastBeginTime = null;
|
|
|
|
this.lastEndTime = null;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.minUpdateTime = Infinity;
|
|
|
|
this.avgUpdateTime = 0;
|
|
|
|
this.maxUpdateTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
|
2011-12-30 02:14:42 +04:00
|
|
|
this.minIdleTime = Infinity;
|
|
|
|
this.avgIdleTime = 0;
|
|
|
|
this.maxIdleTime = 0;
|
2011-12-06 07:50:25 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
}( OpenSeadragon ));
|