<!DOCTYPE html>
|
<html>
|
<head>
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<title>The source code</title>
|
<link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
|
<script type="text/javascript" src="../resources/prettify/prettify.js"></script>
|
<style type="text/css">
|
.highlight { display: block; background-color: #ddd; }
|
</style>
|
<script type="text/javascript">
|
function highlight() {
|
document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
|
}
|
</script>
|
</head>
|
<body onload="prettyPrint(); highlight();">
|
<pre class="prettyprint lang-js">// @tag extras,core
|
// @require Accumulator.js
|
|
<span id='Ext-perf-Monitor'>/**
|
</span> * @class Ext.perf.Monitor
|
* @singleton
|
* @private
|
*/
|
Ext.define('Ext.perf.Monitor', {
|
singleton: true,
|
alternateClassName: 'Ext.Perf',
|
|
requires: [
|
'Ext.perf.Accumulator'
|
],
|
|
<span id='Ext-perf-Monitor-method-constructor'> constructor: function () {
|
</span> this.accumulators = [];
|
this.accumulatorsByName = {};
|
},
|
|
<span id='Ext-perf-Monitor-method-calibrate'> calibrate: function () {
|
</span> var accum = new Ext.perf.Accumulator('$'),
|
total = accum.total,
|
getTimestamp = Ext.perf.Accumulator.getTimestamp,
|
count = 0,
|
frame,
|
endTime,
|
startTime;
|
|
startTime = getTimestamp();
|
|
do {
|
frame = accum.enter();
|
frame.leave();
|
++count;
|
} while (total.sum < 100);
|
|
endTime = getTimestamp();
|
|
return (endTime - startTime) / count;
|
},
|
|
<span id='Ext-perf-Monitor-method-get'> get: function (name) {
|
</span> var me = this,
|
accum = me.accumulatorsByName[name];
|
|
if (!accum) {
|
me.accumulatorsByName[name] = accum = new Ext.perf.Accumulator(name);
|
me.accumulators.push(accum);
|
}
|
|
return accum;
|
},
|
|
<span id='Ext-perf-Monitor-method-enter'> enter: function (name) {
|
</span> return this.get(name).enter();
|
},
|
|
<span id='Ext-perf-Monitor-method-monitor'> monitor: function (name, fn, scope) {
|
</span> this.get(name).monitor(fn, scope);
|
},
|
|
<span id='Ext-perf-Monitor-method-report'> report: function () {
|
</span> var me = this,
|
accumulators = me.accumulators,
|
calibration = me.calibrate();
|
|
accumulators.sort(function (a, b) {
|
return (a.name < b.name) ? -1 : ((b.name < a.name) ? 1 : 0);
|
});
|
|
me.updateGC();
|
|
Ext.log('Calibration: ' + Math.round(calibration * 100) / 100 + ' msec/sample');
|
Ext.each(accumulators, function (accum) {
|
Ext.log(accum.format(calibration));
|
});
|
},
|
|
<span id='Ext-perf-Monitor-method-getData'> getData: function (all) {
|
</span> var ret = {},
|
accumulators = this.accumulators;
|
|
Ext.each(accumulators, function (accum) {
|
if (all || accum.count) {
|
ret[accum.name] = accum.getData();
|
}
|
});
|
|
return ret;
|
},
|
|
<span id='Ext-perf-Monitor-method-reset'> reset: function(){
|
</span> Ext.each(this.accumulators, function(accum){
|
var me = accum;
|
me.count = me.childCount = me.depth = me.maxDepth = 0;
|
me.pure = {
|
min: Number.MAX_VALUE,
|
max: 0,
|
sum: 0
|
};
|
me.total = {
|
min: Number.MAX_VALUE,
|
max: 0,
|
sum: 0
|
};
|
});
|
},
|
|
<span id='Ext-perf-Monitor-method-updateGC'> updateGC: function () {
|
</span> var accumGC = this.accumulatorsByName.GC,
|
toolbox = Ext.senchaToolbox,
|
bucket;
|
|
if (accumGC) {
|
accumGC.count = toolbox.garbageCollectionCounter || 0;
|
|
if (accumGC.count) {
|
bucket = accumGC.pure;
|
accumGC.total.sum = bucket.sum = toolbox.garbageCollectionMilliseconds;
|
bucket.min = bucket.max = bucket.sum / accumGC.count;
|
bucket = accumGC.total;
|
bucket.min = bucket.max = bucket.sum / accumGC.count;
|
}
|
}
|
},
|
|
<span id='Ext-perf-Monitor-method-watchGC'> watchGC: function () {
|
</span> Ext.perf.getTimestamp(); // initializes SenchaToolbox (if available)
|
|
var toolbox = Ext.senchaToolbox;
|
|
if (toolbox) {
|
this.get("GC");
|
toolbox.watchGarbageCollector(false); // no logging, just totals
|
}
|
},
|
|
<span id='Ext-perf-Monitor-method-setup'> setup: function (config) {
|
</span> if (!config) {
|
config = {
|
/*insertHtml: {
|
'Ext.dom.Helper': 'insertHtml'
|
},*/
|
/*xtplCompile: {
|
'Ext.XTemplateCompiler': 'compile'
|
},*/
|
// doInsert: {
|
// 'Ext.Template': 'doInsert'
|
// },
|
// applyOut: {
|
// 'Ext.XTemplate': 'applyOut'
|
// },
|
render: {
|
'Ext.AbstractComponent': 'render'
|
},
|
// fnishRender: {
|
// 'Ext.AbstractComponent': 'finishRender'
|
// },
|
// renderSelectors: {
|
// 'Ext.AbstractComponent': 'applyRenderSelectors'
|
// },
|
// compAddCls: {
|
// 'Ext.AbstractComponent': 'addCls'
|
// },
|
// compRemoveCls: {
|
// 'Ext.AbstractComponent': 'removeCls'
|
// },
|
// getStyle: {
|
// 'Ext.core.Element': 'getStyle'
|
// },
|
// setStyle: {
|
// 'Ext.core.Element': 'setStyle'
|
// },
|
// addCls: {
|
// 'Ext.core.Element': 'addCls'
|
// },
|
// removeCls: {
|
// 'Ext.core.Element': 'removeCls'
|
// },
|
// measure: {
|
// 'Ext.layout.component.Component': 'measureAutoDimensions'
|
// },
|
// moveItem: {
|
// 'Ext.layout.Layout': 'moveItem'
|
// },
|
// layoutFlush: {
|
// 'Ext.layout.Context': 'flush'
|
// },
|
layout: {
|
'Ext.layout.Context': 'run'
|
}
|
};
|
}
|
|
this.currentConfig = config;
|
|
var key, prop,
|
accum, className, methods;
|
for (key in config) {
|
if (config.hasOwnProperty(key)) {
|
prop = config[key];
|
accum = Ext.Perf.get(key);
|
|
for (className in prop) {
|
if (prop.hasOwnProperty(className)) {
|
methods = prop[className];
|
accum.tap(className, methods);
|
}
|
}
|
}
|
}
|
|
this.watchGC();
|
}
|
});
|
</pre>
|
</body>
|
</html>
|