mirror of
https://github.com/cocos/cocos4.git
synced 2026-12-02 08:42:43 +08:00
28527bdc10
* remove es6 class * refine code * refine code
52 lines
1.0 KiB
JavaScript
52 lines
1.0 KiB
JavaScript
const Counter = require('./counter');
|
|
|
|
let PerfCounter = cc.Class({
|
|
extends: Counter,
|
|
|
|
ctor (id, opts, now) {
|
|
// DISABLE
|
|
// this._idstart = `${id}_start`;
|
|
// this._idend = `${id}_end`;
|
|
|
|
this._time = now;
|
|
},
|
|
|
|
start(now) {
|
|
this._time = now;
|
|
|
|
// DISABLE: long time running will cause performance drop down
|
|
// window.performance.mark(this._idstart);
|
|
},
|
|
|
|
end(now) {
|
|
this._value = now - this._time;
|
|
|
|
// DISABLE: long time running will cause performance drop down
|
|
// window.performance.mark(this._idend);
|
|
// window.performance.measure(this._id, this._idstart, this._idend);
|
|
|
|
this._average(this._value);
|
|
},
|
|
|
|
tick() {
|
|
this.end();
|
|
this.start();
|
|
},
|
|
|
|
frame(now) {
|
|
let t = now;
|
|
let e = t - this._time;
|
|
this._total++;
|
|
let avg = this._opts.average || 1000;
|
|
|
|
if (e > avg) {
|
|
this._value = this._total * 1000 / e;
|
|
this._total = 0;
|
|
this._time = t;
|
|
this._average(this._value);
|
|
}
|
|
}
|
|
});
|
|
|
|
module.exports = PerfCounter;
|