@awayfl/avm2
Version:
Virtual machine for executing AS3 code
80 lines (79 loc) • 2.45 kB
JavaScript
var Stat = /** @class */ (function () {
function Stat() {
}
Stat.begin = function (name) {
var now = performance.now();
this._currentTask = {
name: name,
start: now,
droped: false,
};
if (this._firstCompilerRun < 0) {
this._firstCompilerRun = now;
}
};
Stat.drop = function () {
if (!this._currentTask) {
return;
}
this._currentTask.droped = true;
this.end();
};
Stat.end = function () {
if (!this._currentTask) {
return;
}
var now = performance.now();
var start = this._currentTask.start;
var delta = now - start;
var sr = this.statRecords;
if (now - this._lastCompilerStop < this.TASK_DELAY) {
this._taskBathTime += delta;
}
else {
this._taskBathTime = 0;
}
sr.runs++;
sr.drops += +this._currentTask.droped;
sr.totalCompileTime += delta;
sr.minCompileTime = sr.minCompileTime > delta ? delta : sr.minCompileTime;
sr.maxCompileTime = sr.minCompileTime < delta ? delta : sr.minCompileTime;
sr.overhead = 100 * sr.totalCompileTime / (this._lastCompilerStop - this._firstCompilerRun);
sr.maxCompilerBatchTime =
this._taskBathTime > sr.maxCompilerBatchTime
? this._taskBathTime
: sr.maxCompilerBatchTime;
this._lastCompilerStop = now;
this._currentTask = null;
};
Stat.reset = function () {
Object.assign(this.statRecords, {
compiled: 0,
droped: 0,
minCompileTime: Number.MAX_VALUE,
maxCompileTime: -Number.MAX_VALUE,
totalCompileTime: -0,
maxCompilerTaskTime: -Number.MAX_VALUE,
overhead: 0
});
this._currentTask = null;
this._taskBathTime = 0;
};
Stat.TASK_DELAY = 10; // max delta between tasks
Stat.statRecords = {
runs: 0,
drops: 0,
minCompileTime: Number.MAX_VALUE,
maxCompileTime: -Number.MAX_VALUE,
totalCompileTime: -0,
maxCompilerBatchTime: -Number.MAX_VALUE,
overhead: 0
};
Stat._firstCompilerRun = -1;
Stat._lastCompilerStop = -1;
Stat._taskBathTime = 0;
return Stat;
}());
export { Stat };
//@ts-ignore
window.AWAY_COMPILER_STAT = Stat;