Commit 0ca6b671 by Torkel Ödegaard

Added some performance profiling code

parent 9390b1ee
...@@ -98,7 +98,6 @@ function (angular, _, moment) { ...@@ -98,7 +98,6 @@ function (angular, _, moment) {
$httpProvider.interceptors.push('mupp'); $httpProvider.interceptors.push('mupp');
}); });
module.controller('ConsoleCtrl', function($scope) { module.controller('ConsoleCtrl', function($scope) {
$scope.events = events; $scope.events = events;
......
...@@ -26,9 +26,9 @@ function (angular, $, config, _) { ...@@ -26,9 +26,9 @@ function (angular, $, config, _) {
$scope.setupDashboard = function(event, dashboardData) { $scope.setupDashboard = function(event, dashboardData) {
timer.cancel_all(); timer.cancel_all();
$scope.performance.dashboardLoadStart = new Date().getTime(); $rootScope.performance.dashboardLoadStart = new Date().getTime();
$scope.performance.panelsInitialized = 0; $rootScope.performance.panelsInitialized = 0;
$scope.performance.panelsRendered= 0; $rootScope.performance.panelsRendered= 0;
$scope.dashboard = dashboardSrv.create(dashboardData); $scope.dashboard = dashboardSrv.create(dashboardData);
$scope.dashboardViewState = dashboardViewStateSrv.create($scope); $scope.dashboardViewState = dashboardViewStateSrv.create($scope);
......
...@@ -12,29 +12,21 @@ function (angular, config, _, $) { ...@@ -12,29 +12,21 @@ function (angular, config, _, $) {
module.controller('GrafanaCtrl', function($scope, alertSrv, grafanaVersion, $rootScope) { module.controller('GrafanaCtrl', function($scope, alertSrv, grafanaVersion, $rootScope) {
$scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion; $scope.grafanaVersion = grafanaVersion[0] === '@' ? 'master' : grafanaVersion;
$scope.performance = { loadStart: new Date().getTime() }; $scope.consoleEnabled = (window.localStorage && window.localStorage.grafanaConsole === 'true');
var count = 0; $rootScope.profilingEnabled = (window.localStorage && window.localStorage.profilingEnabled === 'true');
$scope.$watch(function() { $rootScope.performance = { loadStart: new Date().getTime() };
console.log(1);
count++;
}, function() {
});
setTimeout(function() {
console.log("Dashboard::Performance Total Digests: " + count);
console.log("Dashboard::Performance Total Watchers: " + $scope.getTotalWatcherCount());
console.log("Dashboard::Performance Total ScopeCount: " + $scope.performance.scopeCount);
}, 3000);
$scope.init = function() { $scope.init = function() {
$scope._ = _; $scope._ = _;
if ($rootScope.profilingEnabled) {
$scope.initProfiling();
}
$scope.dashAlerts = alertSrv; $scope.dashAlerts = alertSrv;
$scope.grafana = { $scope.grafana = {
style: 'dark' style: 'dark'
}; };
$scope.consoleEnabled = (window.localStorage && window.localStorage.grafanaConsole === 'true');
}; };
$scope.toggleConsole = function() { $scope.toggleConsole = function() {
...@@ -80,10 +72,26 @@ function (angular, config, _, $) { ...@@ -80,10 +72,26 @@ function (angular, config, _, $) {
}; };
f(root); f(root);
$scope.performance.scopeCount = scopes; $rootScope.performance.scopeCount = scopes;
return count; return count;
}; };
$scope.initProfiling = function() {
var count = 0;
$scope.$watch(function() {
console.log(1);
count++;
}, function() {
});
setTimeout(function() {
console.log("Dashboard::Performance Total Digests: " + count);
console.log("Dashboard::Performance Total Watchers: " + $scope.getTotalWatcherCount());
console.log("Dashboard::Performance Total ScopeCount: " + $scope.performance.scopeCount);
}, 3000);
};
$scope.init(); $scope.init();
}); });
......
...@@ -130,10 +130,12 @@ function (angular, _) { ...@@ -130,10 +130,12 @@ function (angular, _) {
} }
} }
$scope.performance.panelsInitialized++; if ($rootScope.profilingEnabled) {
if ($scope.performance.panelsInitialized === $scope.dashboard.rows.length) { $rootScope.performance.panelsInitialized++;
var timeTaken = new Date().getTime() - $scope.performance.dashboardLoadStart; if ($rootScope.performance.panelsInitialized === $scope.dashboard.rows.length) {
console.log("Dashboard::Performance - All panels initialized in " + timeTaken + " ms"); var timeTaken = new Date().getTime() - $scope.performance.dashboardLoadStart;
console.log("Dashboard::Performance - All panels initialized in " + timeTaken + " ms");
}
} }
}; };
}); });
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment