stats.min.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. // stats.js - http://github.com/mrdoob/stats.js
  2. var Stats = function() {
  3. function h(a) {
  4. c.appendChild(a.dom);
  5. return a
  6. }
  7. function k(a) {
  8. for (var d = 0; d < c.children.length; d++)
  9. c.children[d].style.display = d === a ? "block" : "none";
  10. l = a
  11. }
  12. var l = 0
  13. , c = document.createElement("div");
  14. c.style.cssText = "position:fixed;top:0;left:0;cursor:pointer;opacity:0.9;z-index:10000";
  15. c.addEventListener("click", function(a) {
  16. a.preventDefault();
  17. k(++l % c.children.length)
  18. }, !1);
  19. var g = (performance || Date).now()
  20. , e = g
  21. , a = 0
  22. , r = h(new Stats.Panel("FPS","#0ff","#002"))
  23. , f = h(new Stats.Panel("MS","#0f0","#020"));
  24. var info = {dur:0, aveFps:0}, pauseTime = 0, startIntervalTime = 0 ;
  25. if (self.performance && self.performance.memory)
  26. var t = h(new Stats.Panel("MB","#f08","#201"));
  27. k(0);
  28. return {
  29. REVISION: 16,
  30. dom: c,
  31. addPanel: h,
  32. showPanel: k,
  33. intervalFun : null
  34. ,
  35. begin: function(blurEvent) {
  36. g = (performance || Date).now()
  37. this.blurEvent = blurEvent
  38. document.addEventListener('visibilitychange',this.blurEvent)
  39. },
  40. pause: function(){
  41. pauseTime = (performance || Date).now();
  42. },
  43. resume:function(){
  44. var delta = (performance || Date).now() - pauseTime;
  45. e += delta
  46. startIntervalTime += delta
  47. },
  48. end: function() {
  49. /* a++;
  50. var c = (performance || Date).now();
  51. if(f.dom.clientWidth) f.update(c - g, 200);
  52. if (c > e + 1E3 && (r.dom.clientWidth && r.update(1E3 * a / (c - e), 100),
  53. e = c,
  54. a = 0,
  55. t && t.dom.clientWidth)) {
  56. var d = performance.memory;
  57. t.update(d.usedJSHeapSize / 1048576, d.jsHeapSizeLimit / 1048576)
  58. }
  59. return 1E3 * a / (c - e)//c */
  60. a++;
  61. var c = (performance || Date).now();
  62. var update = this.intervalFun && (c - startIntervalTime > 5000);
  63. if( c > e + 1E3){
  64. var v = 1E3 * a / (c - e)
  65. var {min,max} = r.update(v, 100)
  66. info = {min, max, fps:v, dur : info.dur + c - e, aveFps:(info.aveFps * (info.dur / 1000 ) + v ) / ((info.dur + c - e) / 1000)}
  67. e = c
  68. a = 0
  69. if(update){
  70. var a2 = this.intervalFun()
  71. startIntervalTime = c;
  72. if(!a2){
  73. this.intervalFun = null
  74. }
  75. }
  76. return info
  77. }else{
  78. }
  79. },
  80. update: function() {
  81. var a1 = this.end()
  82. if(this.intervalFun && startIntervalTime){
  83. }
  84. return a1
  85. },
  86. addInterval: function(f){
  87. startIntervalTime = (performance || Date).now();
  88. this.intervalFun = f;
  89. }
  90. ,
  91. dispose:function(){
  92. document.removeEventListener('visibilitychange',this.blurEvent)
  93. }
  94. ,
  95. domElement: c,
  96. setMode: k
  97. }
  98. };
  99. Stats.Panel = function(h, k, l) {
  100. var c = Infinity
  101. , g = 0
  102. , e = Math.round
  103. , a = e(window.devicePixelRatio || 1)
  104. , r = 80 * a
  105. , f = 48 * a
  106. , t = 3 * a
  107. , u = 2 * a
  108. , d = 3 * a
  109. , m = 15 * a
  110. , n = 74 * a
  111. , p = 30 * a
  112. , q = document.createElement("canvas");
  113. q.width = r;
  114. q.height = f;
  115. q.style.cssText = "width:80px;height:48px";
  116. var b = q.getContext("2d");
  117. b.font = "bold " + 9 * a + "px Helvetica,Arial,sans-serif";
  118. b.textBaseline = "top";
  119. b.fillStyle = l;
  120. b.fillRect(0, 0, r, f);
  121. b.fillStyle = k;
  122. b.fillText(h, t, u);
  123. b.fillRect(d, m, n, p);
  124. b.fillStyle = l;
  125. b.globalAlpha = .9;
  126. b.fillRect(d, m, n, p);
  127. return {
  128. dom: q,
  129. update: function(f, v) {
  130. c = Math.min(c, f);
  131. g = Math.max(g, f);
  132. b.fillStyle = l;
  133. b.globalAlpha = 1;
  134. b.fillRect(0, 0, r, m);
  135. b.fillStyle = k;
  136. b.fillText(e(f) + " " + h + " (" + e(c) + "-" + e(g) + ")", t, u);
  137. b.drawImage(q, d + a, m, n - a, p, d, m, n - a, p);
  138. b.fillRect(d + n - a, m, a, p);
  139. b.fillStyle = l;
  140. b.globalAlpha = .9;
  141. b.fillRect(d + n - a, m, a, e((1 - f / v) * p))
  142. return {min:c, max:g}
  143. }
  144. }
  145. }
  146. ;
  147. "object" === typeof module && (module.exports = Stats);