mirror of
https://github.com/cocos/cocos4.git
synced 2026-11-21 16:12:40 +08:00
2 lines
13 KiB
JavaScript
2 lines
13 KiB
JavaScript
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 e(){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}}}var e=Math.round(window.devicePixelRatio||1);var i=function t(e,i){this._color=i||"#666";this._canvas=document.createElement("canvas");this._ctx=this._canvas.getContext("2d");this._canvas.className="pstats-canvas";e.appendChild(this._canvas)};i.prototype.init=function t(i,a){var n=i*e;var s=a*e;this._canvas.width=n;this._canvas.height=s;this._canvas.style.width=i+"px";this._canvas.style.height=a+"px";this._ctx.globalAlpha=1;this._ctx.fillStyle="#444";this._ctx.fillRect(0,0,n,s)};var a=Math.round(window.devicePixelRatio||1);var n=function(t){function e(e,i){t.call(this,e,i);this._current=0;this._max=0}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.draw=function t(e,i){var n=this._canvas.width;var s=this._canvas.height;this._current+=(e-this._current)*.1;this._max*=.99;if(this._current>this._max){this._max=this._current}var o=Math.round((1-this._current/this._max)*s);this._ctx.globalAlpha=1;this._ctx.drawImage(this._canvas,a,0,n-a,s,0,0,n-a,s);if(i){this._ctx.fillStyle="#444";this._ctx.fillRect(n-a,0,a,s);this._ctx.fillStyle="#b70000";this._ctx.fillRect(n-a,o,a,s-o);this._ctx.globalAlpha=.5;this._ctx.fillStyle="#fff";this._ctx.fillRect(n-a,o,a,a)}else{this._ctx.fillStyle="#444";this._ctx.fillRect(n-a,0,a,s);this._ctx.fillStyle=this._color;this._ctx.fillRect(n-a,o,a,s-o);this._ctx.globalAlpha=.5;this._ctx.fillStyle="#fff";this._ctx.fillRect(n-a,o,a,a)}};return e}(i);var s=Math.round(window.devicePixelRatio||1);var o=function(t){function e(e,i){t.call(this,e,i);this._threshold=0;this._canvas2=document.createElement("canvas");this._ctx2=this._canvas2.getContext("2d")}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.init=function e(i,a){t.prototype.init.call(this,i,a);var n=i*s;var o=a*s;this._canvas2.width=n;this._canvas2.height=o;this._canvas2.style.width=i+"px";this._canvas2.style.height=a+"px";this._ctx2.globalAlpha=1;this._ctx2.fillStyle="#444";this._ctx2.fillRect(0,0,n,o)};e.prototype.draw=function t(e,i){var a=this._canvas.width;var n=this._canvas.height;this._ctx.globalAlpha=1;this._ctx2.globalAlpha=1;if(e>this._threshold){var o=(e-e%n)/n;var r=n*(o+1);var l=this._threshold;this._threshold=r;var c=l/r;this._ctx2.drawImage(this._canvas,0,0);this._ctx.fillStyle="#444";this._ctx.fillRect(0,0,a,n);this._ctx.drawImage(this._canvas2,s,0,a-s,n,0,Math.round((1-c)*n),a-s,n)}else{this._ctx.drawImage(this._canvas,s,0,a-s,n,0,0,a-s,n)}var h=Math.round(n*(1-e/this._threshold));if(i){this._ctx.fillStyle="#444";this._ctx.fillRect(a-s,0,s,n);this._ctx.fillStyle="#b70000";this._ctx.fillRect(a-s,h,s,n-h);this._ctx.globalAlpha=.5;this._ctx.fillStyle="#fff";this._ctx.fillRect(a-s,h,s,s)}else{this._ctx.fillStyle="#444";this._ctx.fillRect(a-s,0,s,n);this._ctx.fillStyle=this._color;this._ctx.fillRect(a-s,h,s,n-h);this._ctx.globalAlpha=.5;this._ctx.fillStyle="#fff";this._ctx.fillRect(a-s,h,s,s)}};return e}(i);var r=Math.round(window.devicePixelRatio||1);var l=function(t){function e(e,i,a,n){t.call(this,e,i);this._min=a;this._max=n}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.draw=function t(e,i){var a=this._canvas.width;var n=this._canvas.height;var s=(e-this._min)/(this._max-this._min);var o=Math.round((1-s)*n);this._ctx.globalAlpha=1;this._ctx.drawImage(this._canvas,r,0,a-r,n,0,0,a-r,n);if(i){this._ctx.fillStyle="#444";this._ctx.fillRect(a-r,0,r,n);this._ctx.fillStyle="#b70000";this._ctx.fillRect(a-r,o,r,n-o);this._ctx.globalAlpha=.5;this._ctx.fillStyle="#fff";this._ctx.fillRect(a-r,o,r,r)}else{this._ctx.fillStyle="#444";this._ctx.fillRect(a-r,0,r,n);this._ctx.fillStyle=this._color;this._ctx.fillRect(a-r,o,r,n-o);this._ctx.globalAlpha=.5;this._ctx.fillStyle="#fff";this._ctx.fillRect(a-r,o,r,r)}};return e}(i);var c=Math.round(window.devicePixelRatio||1);var h=function t(e,i){this._colors=i;this._canvas=document.createElement("canvas");this._ctx=this._canvas.getContext("2d");this._canvas.className="pstats-canvas";e.appendChild(this._canvas)};h.prototype.init=function t(e,i,a){var n=e*c;var s=i*c;this._canvas.width=n;this._canvas.height=s*a;this._canvas.style.width=e+"px";this._canvas.style.height=i*a+"px";this._ctx.globalAlpha=1;this._ctx.fillStyle="#444";this._ctx.fillRect(0,0,n,s*a)};h.prototype.draw=function t(e){var i=this;var a=this._canvas.width;var n=this._canvas.height;this._ctx.globalAlpha=1;this._ctx.drawImage(this._canvas,c,0,a-c,n,0,0,a-c,n);var s=0;for(var o=0;o<e.length;++o){var r=e[o]*n;i._ctx.fillStyle=i._colors[o];i._ctx.fillRect(a-c,s,c,r);s+=r}};var p=function t(e,i){this._id=e;this._opts=i||{};this._value=0;this._total=0;this._averageValue=0;this._accumValue=0;this._accumSamples=0;this._accumStart=window.performance.now()};var _={value:{}};p.prototype._average=function t(e){if(this._opts.average){this._accumValue+=e;++this._accumSamples;var i=performance.now();if(i-this._accumStart>=this._opts.average){this._averageValue=this._accumValue/this._accumSamples;this._accumValue=0;this._accumStart=i;this._accumSamples=0}}};_.value.get=function(){return this._value};_.value.set=function(t){this._value=t};p.prototype.sample=function t(){this._average(this._value)};p.prototype.human=function t(){var e=this._opts.average?this._averageValue:this._value;return Math.round(e*100)/100};p.prototype.alarm=function t(){return this._opts.below&&this._value<this._opts.below||this._opts.over&&this._value>this._opts.over};Object.defineProperties(p.prototype,_);var f=function(t){function e(e,i){t.call(this,e,i);this._time=window.performance.now()}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.start=function t(){this._time=window.performance.now()};e.prototype.end=function t(){this._value=window.performance.now()-this._time;this._average(this._value)};e.prototype.tick=function t(){this.end();this.start()};e.prototype.frame=function t(){var e=window.performance.now();var i=e-this._time;this._total++;var a=this._opts.average||1e3;if(i>a){this._value=this._total*1e3/i;this._total=0;this._time=e;this._average(this._value)}};return e}(p);var u=Math.log(1024);var v=["Bytes","KB","MB","GB","TB"];function d(t){var e=100;var i=Math.floor(Math.log(t)/u);if(t===0){return"n/a"}return Math.round(t*e/Math.pow(1024,i))/e+" "+v[i]}var m=function(t){function e(e,i,a){t.call(this,i,a);this._stats=e;this._start=0;if(a.extension.indexOf("memory.")===0){this._field=a.extension.substring(7)}}if(t)e.__proto__=t;e.prototype=Object.create(t&&t.prototype);e.prototype.constructor=e;e.prototype.snapshot=function t(){this._value=this._stats[this._field]};e.prototype.start=function t(){this._start=this._stats[this._field]};e.prototype.end=function t(){this._value=this._stats[this._field]-this._start};e.prototype.human=function e(){return d(t.prototype.human.call(this))};return e}(p);var x=function t(){var e=window.performance.memory;if(e.totalJSHeapSize===0){console.warn("totalJSHeapSize === 0, performance.memory is only available in Chrome.")}this._used=0;this._total=0;this._lastUsed=0};var w={alarm:{},used:{},total:{}};x.prototype.tick=function t(){this._lastUsed=this._used;this._used=window.performance.memory.usedJSHeapSize;this._total=window.performance.memory.totalJSHeapSize};w.alarm.get=function(){return this._used-this._lastUsed<0};w.used.get=function(){return window.performance.memory.usedJSHeapSize};w.total.get=function(){return this._total};x.prototype.counter=function t(e,i){return new m(this,e,i)};Object.defineProperties(x.prototype,w);var y={memory:x};var g=100;var b=10;var S="\n .pstats {\n position: fixed;\n z-index: 9999;\n\n padding: 5px;\n width: "+(g+150)+"px;\n right: 5px;\n bottom: 5px;\n\n font-size: 10px;\n font-family: 'Roboto Condensed', tahoma, sans-serif;\n overflow: hidden;\n user-select: none;\n cursor: default;\n\n background: #222;\n border-radius: 3px;\n }\n\n .pstats-container {\n display: block;\n position: relative;\n color: #888;\n white-space: nowrap;\n }\n\n .pstats-item {\n position: absolute;\n width: 250px;\n height: 12px;\n left: 0px;\n }\n\n .pstats-label {\n position: absolute;\n width: 150px;\n height: 12px;\n text-align: left;\n transition: background 0.3s;\n }\n\n .pstats-label.alarm {\n color: #ccc;\n background: #800;\n\n transition: background 0s;\n }\n\n .pstats-counter-id {\n position: absolute;\n width: 90px;\n left: 0px;\n }\n\n .pstats-counter-value {\n position: absolute;\n width: 60px;\n left: 90px;\n text-align: right;\n }\n\n .pstats-canvas {\n display: block;\n position: absolute;\n right: 0px;\n top: 1px;\n }\n\n .pstats-fraction {\n position: absolute;\n width: 250px;\n left: 0px;\n }\n\n .pstats-legend {\n position: absolute;\n width: 150px;\n\n text-align: right;\n }\n\n .pstats-legend > span {\n position: absolute;\n right: 0px;\n }\n";var R=document.createElement("style");R.type="text/css";R.textContent=S;document.head.appendChild(R);var C=function t(e,i){var a=this;i=i||{};this._showGraph=i.showGraph!==undefined?i._showGraph:true;this._values=i.values||{};this._fractions=i.fractions||[];this._id2counter={};this._id2item={};this._name2extStats={};if(i.css){var s=document.createElement("style");s.type="text/css";s.textContent=i.css;document.head.appendChild(s)}if(i.extensions){for(var r=0;r<i.extensions.length;++r){var c=i.extensions[r];var p=y[c];if(!p){console.warn("Can not find extensions "+c+", please register your extension via pstats.register().");continue}a._name2extStats[c]=new p}}this._root=document.createElement("div");this._root.className="pstats";var _=document.createElement("div");_.className="pstats-container";this._root.appendChild(_);var f=0;for(var u in a._values){var v=a._values[u];var d=document.createElement("div");d.className="pstats-item";var m=document.createElement("div");m.className="pstats-label";var x=document.createElement("span");x.className="pstats-counter-id";x.textContent=v.desc||u;var w=document.createElement("div");w.className="pstats-counter-value";var S=document.createTextNode("");S.nodeValue="0";m.appendChild(x);m.appendChild(w);w.appendChild(S);d.appendChild(m);var R=void 0;if(a._showGraph){if(v.min!==undefined||v.max!==undefined){R=new l(d,v.color,v.min||0,v.max||9999)}else if(v.threshold){R=new o(d,v.color)}else{R=new n(d,v.color)}R.init(g-5,b)}a._id2item[u]={label:m,valueText:S,graph:R};d.style.top=f+"px";_.appendChild(d);f+=12}if(this._showGraph&&i.fractions){for(var C=0;C<i.fractions.length;++C){var M=i.fractions[C];var A=M.steps;var E=A.length*b+2;M.colors=M.colors||["#850700","#c74900","#fcb300","#284280","#4c7c0c"];var k=document.createElement("div");k.className="pstats-fraction";var N=document.createElement("div");N.className="pstats-legend";N.style.height=E+"px";for(var z=0;z<A.length;++z){var G=document.createElement("span");G.textContent=A[z];G.style.color=M.colors[z];G.style.top=z*b+"px";N.appendChild(G)}k.appendChild(N);k.style.height=E+"px";k.style.top=f+"px";var O=new h(k,M.colors);O.init(g-5,b,A.length);M.graph=O;M.values=new Array(A.length);_.appendChild(k);f+=A.length*b+2}}_.style.height=f+"px";this._root.style.height=f+"px";if(!this._showGraph){this._root.style.width="150px"}e.appendChild(this._root)};C.prototype.item=function t(e){if(!e){return null}var i=this._id2counter[e];if(i){return i}var a=this._values[e];if(!a){return null}if(a.extension){var n=a.extension.indexOf(".");var s=a.extension.substring(0,n);var o=this._name2extStats[s];if(!o){console.error("extension "+s+" not found, make sure you have register and enable it.");return null}i=o.counter(e,a)}else{i=new f(e,a)}this._id2counter[e]=i;return i};C.prototype.tick=function t(){var e=this;for(var i in e._name2extStats){var a=e._name2extStats[i];a.tick()}for(var n in e._values){var s=e._id2counter[n];if(s){s.sample();var o=s.alarm();var r=s.human();var l=e._id2item[n];l.label.classList.toggle("alarm",o>0);l.valueText.nodeValue=r;if(e._showGraph){l.graph.draw(s.value,o)}}}if(this._showGraph){for(var c=0;c<this._fractions.length;++c){var h=e._fractions[c];var p=e._id2counter[h.base];if(p){var _=h.steps;for(var f=0;f<_.length;++f){var u=_[f];var v=e._id2counter[u];if(v){h.values[f]=v.value/p.value}}h.graph.draw(h.values)}}}};t();var M={new:function t(e,i){var a=new C(e,i);return function(t){if(!t){return a}return a.item(t)}},register:function t(e,i){y[e]=i}};return M}();
|