You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
angularjs-batarang/js/services/appPerf.js

54 lines
1.2 KiB
JavaScript

// Service for retrieving and caching performance data
panelApp.factory('appPerf', function (chromeExtension) {
var _histogramCache = [],
_watchNameToPerf = {},
_totalCache = 0;
var getHistogramData = function (callback) {
chromeExtension.eval(function (window) {
if (!window.__ngDebug) {
return {};
}
return window.__ngDebug.getWatchPerf();
},
function (data) {
if (data && data.length) {
updateHistogram(data);
}
callback();
});
};
var updateHistogram = function (data) {
data.forEach(function (info) {
_totalCache += info.time;
if (_watchNameToPerf[info.name]) {
_watchNameToPerf[info.name].time += info.time;
} else {
_watchNameToPerf[info.name] = info;
_histogramCache.push(info);
}
});
// recalculate all percentages
_histogramCache.forEach(function (item) {
item.percent = (100 * item.time / _totalCache).toPrecision(3);
});
};
// Public API
// ==========
return {
get: function (callback) {
getHistogramData(function () {
callback(_histogramCache);
});
},
clear: function () {
_histogramCache = [];
}
};
});