mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
Merge pull request #1633 from pandamicro/master
Use pstats instead of lstats
This commit is contained in:
@@ -23,19 +23,51 @@
|
||||
THE SOFTWARE.
|
||||
****************************************************************************/
|
||||
|
||||
var LStats = require('../../../external/lstats/lstats');
|
||||
var PStats = require('../../../external/pstats/pstats');
|
||||
var macro = require('../platform/CCMacro');
|
||||
|
||||
var _fps = document.createElement('div');
|
||||
_fps.id = 'fps';
|
||||
|
||||
let stats = new LStats(_fps, [
|
||||
'fps', 'ms', 'mem'
|
||||
]);
|
||||
let stats = PStats.new(_fps, {
|
||||
values: {
|
||||
frame: { desc: 'Frame time (ms)', min: 0, max: 50, average: 500 },
|
||||
fps: { desc: 'Framerate (FPS)', below: 30, average: 500 },
|
||||
draws: { desc: 'Draw call' },
|
||||
logic: { desc: 'Game Logic (ms)', min: 0, max: 50, average: 500, color: '#080' },
|
||||
render: { desc: 'Renderer (ms)', min: 0, max: 50, average: 500, color: '#f90' },
|
||||
memory: { desc: 'Memory', extension : 'memory.used', average: 2000, threshold: true }
|
||||
},
|
||||
extensions: [
|
||||
'memory'
|
||||
],
|
||||
css: '.pstats {left: ' + macro.DIRECTOR_STATS_POSITION.x + 'px; bottom: ' + macro.DIRECTOR_STATS_POSITION.y + 'px;}'
|
||||
});
|
||||
|
||||
let _showFPS = false;
|
||||
|
||||
function tick () {
|
||||
stats.tick();
|
||||
function beforeUpdate () {
|
||||
stats('frame').start();
|
||||
stats('logic').start();
|
||||
}
|
||||
|
||||
function afterVisit () {
|
||||
if (cc.director.isPaused()) {
|
||||
stats('frame').start();
|
||||
}
|
||||
else {
|
||||
stats('logic').end();
|
||||
}
|
||||
stats('render').start();
|
||||
}
|
||||
|
||||
function afterDraw () {
|
||||
stats('render').end();
|
||||
stats('draws').value = cc.g_NumberOfDraws;
|
||||
stats('memory').snapshot();
|
||||
stats('frame').end();
|
||||
stats('fps').frame();
|
||||
stats().tick();
|
||||
}
|
||||
|
||||
cc.profiler = module.exports = {
|
||||
@@ -48,7 +80,9 @@ cc.profiler = module.exports = {
|
||||
if (_fps.parentElement === document.body) {
|
||||
document.body.removeChild(_fps);
|
||||
}
|
||||
cc.director.off(cc.Director.EVENT_AFTER_VISIT, tick);
|
||||
cc.director.off(cc.Director.EVENT_BEFORE_UPDATE, beforeUpdate);
|
||||
cc.director.off(cc.Director.EVENT_AFTER_VISIT, afterVisit);
|
||||
cc.director.off(cc.Director.EVENT_AFTER_DRAW, afterDraw);
|
||||
_showFPS = false;
|
||||
}
|
||||
},
|
||||
@@ -58,7 +92,9 @@ cc.profiler = module.exports = {
|
||||
if (_fps.parentElement === null) {
|
||||
document.body.appendChild(_fps);
|
||||
}
|
||||
cc.director.on(cc.Director.EVENT_AFTER_VISIT, tick);
|
||||
cc.director.on(cc.Director.EVENT_BEFORE_UPDATE, beforeUpdate);
|
||||
cc.director.on(cc.Director.EVENT_AFTER_VISIT, afterVisit);
|
||||
cc.director.on(cc.Director.EVENT_AFTER_DRAW, afterDraw);
|
||||
_showFPS = true;
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
-1
@@ -1 +0,0 @@
|
||||
module.exports=function(){"use strict";function t(){if(typeof window.performance==="undefined"){window.performance={}}if(!window.performance.now){var t=Date.now();if(performance.timing&&performance.timing.navigationStart){t=performance.timing.navigationStart}window.performance.now=function i(){return Date.now()-t}}if(!window.performance.mark){window.performance.mark=function(){}}if(!window.performance.measure){window.performance.measure=function(){}}if(!window.performance.memory){window.performance.memory={usedJSHeapSize:0,totalJSHeapSize:0}}}t();var i=80;var e=38;var s=Math.round(window.devicePixelRatio||1);var a=i*s;var h=e*s;var l=3*s;var n=2*s;var r=3*s;var c=15*s;var _=74*s;var o=(e-18)*s;var f=function t(f,d,p,m){this._name=d;this._fg=p;this._bg=m;this._canvas=document.createElement("canvas");this._canvas.width=a;this._canvas.height=h;this._canvas.style.cssText="width:"+i+"px;height:"+e+"px";this._ctx=this._canvas.getContext("2d");this._ctx.font="bold "+9*s+"px Helvetica,Arial,sans-serif";this._ctx.textBaseline="top";this._ctx.fillStyle=m;this._ctx.fillRect(0,0,a,h);this._ctx.fillStyle=p;this._ctx.fillText(d,l,n);this._ctx.fillRect(r,c,_,o);this._ctx.fillStyle=m;this._ctx.globalAlpha=.9;this._ctx.fillRect(r,c,_,o);f.appendChild(this._canvas)};f.prototype.draw=function t(i,e){var h=Math.round(i*100)/100;this._ctx.fillStyle=this._bg;this._ctx.globalAlpha=1;this._ctx.fillRect(0,0,a,c);this._ctx.fillStyle=this._fg;this._ctx.fillText(h+" "+this._name,l,n);this._ctx.drawImage(this._canvas,r+s,c,_-s,o,r,c,_-s,o);this._ctx.fillRect(r+_-s,c,s,o);var f=Math.round((1-i/e)*o);this._ctx.fillStyle=this._bg;this._ctx.globalAlpha=.9;this._ctx.fillRect(r+_-s,c,s,f)};var d=function(t){function i(i,e,a,h){t.call(this,i,e,a,h);this._threshold=0;this._canvas2=document.createElement("canvas");this._canvas2.width=_;this._canvas2.height=o;this._canvas2.style.cssText="width:"+_/s+"px;height:"+o/s+"px";this._ctx2=this._canvas2.getContext("2d");this._ctx2.fillStyle=h;this._ctx.globalAlpha=.9;this._ctx2.fillRect(0,0,_,o)}if(t)i.__proto__=t;i.prototype=Object.create(t&&t.prototype);i.prototype.constructor=i;i.prototype.draw=function t(i,e){var h=Math.round(i*100)/100;this._ctx.fillStyle=this._bg;this._ctx.globalAlpha=1;this._ctx.fillRect(0,0,a,c);this._ctx.fillStyle=this._fg;this._ctx.fillText(h+" "+this._name,l,n);if(i>this._threshold){var f=(i-i%o)/o;var d=o*(f+1);var p=this._threshold;this._threshold=d;var m=p/d;this._ctx2.drawImage(this._canvas,r,c,_,o,0,0,_,o);this._ctx.fillStyle=this._fg;this._ctx.globalAlpha=1;this._ctx.fillRect(r,c,_,o);this._ctx.fillStyle=this._bg;this._ctx.globalAlpha=.9;this._ctx.fillRect(r,c,_,o);this._ctx.fillStyle=this._fg;this._ctx.globalAlpha=1;this._ctx.drawImage(this._canvas2,s,0,_-s,o,r,c+(1-m)*o,_-s,m*o)}else{this._ctx.drawImage(this._canvas,r+s,c,_-s,o,r,c,_-s,o)}var x=Math.round((1-i/this._threshold)*o);this._ctx.fillRect(r+_-s,c,s,o);if(e){this._ctx.fillStyle="#e00";this._ctx.globalAlpha=1;this._ctx.fillRect(r+_-s,c,s,x)}else{this._ctx.fillStyle=this._bg;this._ctx.globalAlpha=.9;this._ctx.fillRect(r+_-s,c,s,x)}};return i}(f);var p=function t(i,e){var s=this;if(e===void 0)e=["fps","ms","mb"];this._mode=0;this._enableFPS=e.indexOf("fps")!==-1;this._enableMS=e.indexOf("ms")!==-1;if(window.performance.memory&&window.performance.memory.totalJSHeapSize){this._enableMB=e.indexOf("mb")!==-1}this._framesMS=0;this._lastTimeMS=0;this._frames=0;this._lastTimeFPS=0;this._used=0;this._lastUsed=0;this._lastTimeMB=0;var a=document.createElement("div");a.style.cssText="position:fixed;top:5px;right:5px;cursor:pointer;opacity:0.9;z-index:9999";a.addEventListener("mousedown",function(t){t.preventDefault();t.stopPropagation();s._mode=++s._mode%a.children.length;for(var i=0;i<a.children.length;++i){a.children[i].style.display=i===s._mode?"block":"none"}});if(this._enableFPS){this._graphFPS=new f(a,"FPS","#0ff","#002")}if(this._enableMS){this._graphMS=new f(a,"MS","#f08","#201")}if(this._enableMB){this._graphMB=new d(a,"MB","#0f0","#020")}for(var h=0;h<a.children.length;++h){a.children[h].style.display=h===0?"block":"none"}i.appendChild(a)};p.prototype.tick=function t(){var i=window.performance.now();if(this._enableMS){++this._framesMS;var e=i-this._lastTimeMS;if(e>100){this._graphMS.draw(e/this._framesMS,50);this._framesMS=0;this._lastTimeMS=i}}if(this._enableFPS){++this._frames;var s=i-this._lastTimeFPS;if(s>1e3){this._graphFPS.draw(this._frames*1e3/s,100);this._frames=0;this._lastTimeFPS=i}}if(this._enableMB){var a=i-this._lastTimeMB;if(a>200){this._lastUsed=this._used;this._used=window.performance.memory.usedJSHeapSize;this._lastTimeMB=i;var h=this._used-this._lastUsed;this._graphMB.draw(this._used/1048576,h<0)}}};return p}();
|
||||
Vendored
+1
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user