Monitor.html 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-perf-Monitor'>/**
  19. </span> * @class Ext.perf.Monitor
  20. * @singleton
  21. * @private
  22. */
  23. Ext.define('Ext.perf.Monitor', {
  24. singleton: true,
  25. alternateClassName: 'Ext.Perf',
  26. requires: [
  27. 'Ext.perf.Accumulator'
  28. ],
  29. constructor: function () {
  30. this.accumulators = [];
  31. this.accumulatorsByName = {};
  32. },
  33. calibrate: function () {
  34. var accum = new Ext.perf.Accumulator('$'),
  35. total = accum.total,
  36. getTimestamp = Ext.perf.Accumulator.getTimestamp,
  37. count = 0,
  38. frame,
  39. endTime,
  40. startTime;
  41. startTime = getTimestamp();
  42. do {
  43. frame = accum.enter();
  44. frame.leave();
  45. ++count;
  46. } while (total.sum &lt; 100);
  47. endTime = getTimestamp();
  48. return (endTime - startTime) / count;
  49. },
  50. get: function (name) {
  51. var me = this,
  52. accum = me.accumulatorsByName[name];
  53. if (!accum) {
  54. me.accumulatorsByName[name] = accum = new Ext.perf.Accumulator(name);
  55. me.accumulators.push(accum);
  56. }
  57. return accum;
  58. },
  59. enter: function (name) {
  60. return this.get(name).enter();
  61. },
  62. monitor: function (name, fn, scope) {
  63. this.get(name).monitor(fn, scope);
  64. },
  65. report: function () {
  66. var me = this,
  67. accumulators = me.accumulators,
  68. calibration = me.calibrate();
  69. accumulators.sort(function (a, b) {
  70. return (a.name &lt; b.name) ? -1 : ((b.name &lt; a.name) ? 1 : 0);
  71. });
  72. me.updateGC();
  73. Ext.log('Calibration: ' + Math.round(calibration * 100) / 100 + ' msec/sample');
  74. Ext.each(accumulators, function (accum) {
  75. Ext.log(accum.format(calibration));
  76. });
  77. },
  78. getData: function (all) {
  79. var ret = {},
  80. accumulators = this.accumulators;
  81. Ext.each(accumulators, function (accum) {
  82. if (all || accum.count) {
  83. ret[accum.name] = accum.getData();
  84. }
  85. });
  86. return ret;
  87. },
  88. reset: function(){
  89. Ext.each(this.accumulators, function(accum){
  90. var me = accum;
  91. me.count = me.childCount = me.depth = me.maxDepth = 0;
  92. me.pure = {
  93. min: Number.MAX_VALUE,
  94. max: 0,
  95. sum: 0
  96. };
  97. me.total = {
  98. min: Number.MAX_VALUE,
  99. max: 0,
  100. sum: 0
  101. };
  102. });
  103. },
  104. updateGC: function () {
  105. var accumGC = this.accumulatorsByName.GC,
  106. toolbox = Ext.senchaToolbox,
  107. bucket;
  108. if (accumGC) {
  109. accumGC.count = toolbox.garbageCollectionCounter || 0;
  110. if (accumGC.count) {
  111. bucket = accumGC.pure;
  112. accumGC.total.sum = bucket.sum = toolbox.garbageCollectionMilliseconds;
  113. bucket.min = bucket.max = bucket.sum / accumGC.count;
  114. bucket = accumGC.total;
  115. bucket.min = bucket.max = bucket.sum / accumGC.count;
  116. }
  117. }
  118. },
  119. watchGC: function () {
  120. Ext.perf.getTimestamp(); // initializes SenchaToolbox (if available)
  121. var toolbox = Ext.senchaToolbox;
  122. if (toolbox) {
  123. this.get(&quot;GC&quot;);
  124. toolbox.watchGarbageCollector(false); // no logging, just totals
  125. }
  126. },
  127. setup: function (config) {
  128. if (!config) {
  129. config = {
  130. /*insertHtml: {
  131. 'Ext.dom.Helper': 'insertHtml'
  132. },*/
  133. /*xtplCompile: {
  134. 'Ext.XTemplateCompiler': 'compile'
  135. },*/
  136. // doInsert: {
  137. // 'Ext.Template': 'doInsert'
  138. // },
  139. // applyOut: {
  140. // 'Ext.XTemplate': 'applyOut'
  141. // },
  142. render: {
  143. 'Ext.AbstractComponent': 'render'
  144. },
  145. // fnishRender: {
  146. // 'Ext.AbstractComponent': 'finishRender'
  147. // },
  148. // renderSelectors: {
  149. // 'Ext.AbstractComponent': 'applyRenderSelectors'
  150. // },
  151. // compAddCls: {
  152. // 'Ext.AbstractComponent': 'addCls'
  153. // },
  154. // compRemoveCls: {
  155. // 'Ext.AbstractComponent': 'removeCls'
  156. // },
  157. // getStyle: {
  158. // 'Ext.core.Element': 'getStyle'
  159. // },
  160. // setStyle: {
  161. // 'Ext.core.Element': 'setStyle'
  162. // },
  163. // addCls: {
  164. // 'Ext.core.Element': 'addCls'
  165. // },
  166. // removeCls: {
  167. // 'Ext.core.Element': 'removeCls'
  168. // },
  169. // measure: {
  170. // 'Ext.layout.component.Component': 'measureAutoDimensions'
  171. // },
  172. // moveItem: {
  173. // 'Ext.layout.Layout': 'moveItem'
  174. // },
  175. // layoutFlush: {
  176. // 'Ext.layout.Context': 'flush'
  177. // },
  178. layout: {
  179. 'Ext.layout.Context': 'run'
  180. }
  181. };
  182. }
  183. this.currentConfig = config;
  184. var key, prop,
  185. accum, className, methods;
  186. for (key in config) {
  187. if (config.hasOwnProperty(key)) {
  188. prop = config[key];
  189. accum = Ext.Perf.get(key);
  190. for (className in prop) {
  191. if (prop.hasOwnProperty(className)) {
  192. methods = prop[className];
  193. accum.tap(className, methods);
  194. }
  195. }
  196. }
  197. }
  198. this.watchGC();
  199. }
  200. });
  201. </pre>
  202. </body>
  203. </html>