|
@@ -6,6 +6,7 @@ import _ from 'lodash';
|
|
|
import angular from 'angular';
|
|
import angular from 'angular';
|
|
|
import $ from 'jquery';
|
|
import $ from 'jquery';
|
|
|
import coreModule from 'app/core/core_module';
|
|
import coreModule from 'app/core/core_module';
|
|
|
|
|
+import {profiler} from 'app/core/profiler';
|
|
|
|
|
|
|
|
export class GrafanaCtrl {
|
|
export class GrafanaCtrl {
|
|
|
|
|
|
|
@@ -15,14 +16,10 @@ export class GrafanaCtrl {
|
|
|
$scope.init = function() {
|
|
$scope.init = function() {
|
|
|
$scope.contextSrv = contextSrv;
|
|
$scope.contextSrv = contextSrv;
|
|
|
|
|
|
|
|
- $scope._ = _;
|
|
|
|
|
-
|
|
|
|
|
- $rootScope.profilingEnabled = store.getBool('profilingEnabled') || config.buildInfo.env === 'development';
|
|
|
|
|
- $rootScope.performance = { loadStart: new Date().getTime() };
|
|
|
|
|
$rootScope.appSubUrl = config.appSubUrl;
|
|
$rootScope.appSubUrl = config.appSubUrl;
|
|
|
|
|
+ $scope._ = _;
|
|
|
|
|
|
|
|
- if ($rootScope.profilingEnabled) { $scope.initProfiling(); }
|
|
|
|
|
-
|
|
|
|
|
|
|
+ profiler.init(config, $rootScope);
|
|
|
alertSrv.init();
|
|
alertSrv.init();
|
|
|
utilSrv.init();
|
|
utilSrv.init();
|
|
|
|
|
|
|
@@ -59,82 +56,6 @@ export class GrafanaCtrl {
|
|
|
"#E0F9D7","#FCEACA","#CFFAFF","#F9E2D2","#FCE2DE","#BADFF4","#F9D9F9","#DEDAF7"
|
|
"#E0F9D7","#FCEACA","#CFFAFF","#F9E2D2","#FCE2DE","#BADFF4","#F9D9F9","#DEDAF7"
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
- $scope.getTotalWatcherCount = function() {
|
|
|
|
|
- var count = 0;
|
|
|
|
|
- var scopes = 0;
|
|
|
|
|
- var root = $(document.getElementsByTagName('body'));
|
|
|
|
|
-
|
|
|
|
|
- var f = function (element) {
|
|
|
|
|
- if (element.data().hasOwnProperty('$scope')) {
|
|
|
|
|
- scopes++;
|
|
|
|
|
- angular.forEach(element.data().$scope.$$watchers, function () {
|
|
|
|
|
- count++;
|
|
|
|
|
- });
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- angular.forEach(element.children(), function (childElement) {
|
|
|
|
|
- f($(childElement));
|
|
|
|
|
- });
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- f(root);
|
|
|
|
|
- $rootScope.performance.scopeCount = scopes;
|
|
|
|
|
- return count;
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
- $scope.initProfiling = function() {
|
|
|
|
|
- var count = 0;
|
|
|
|
|
-
|
|
|
|
|
- $scope.$watch(function digestCounter() {
|
|
|
|
|
- count++;
|
|
|
|
|
- }, function() {
|
|
|
|
|
- // something
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- $rootScope.performance.panels = [];
|
|
|
|
|
-
|
|
|
|
|
- $scope.$on('refresh', function() {
|
|
|
|
|
- if ($rootScope.performance.panels.length > 0) {
|
|
|
|
|
- var totalRender = 0;
|
|
|
|
|
- var totalQuery = 0;
|
|
|
|
|
-
|
|
|
|
|
- _.each($rootScope.performance.panels, function(panelTiming: any) {
|
|
|
|
|
- totalRender += panelTiming.render;
|
|
|
|
|
- totalQuery += panelTiming.query;
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- console.log('total query: ' + totalQuery);
|
|
|
|
|
- console.log('total render: ' + totalRender);
|
|
|
|
|
- console.log('avg render: ' + totalRender / $rootScope.performance.panels.length);
|
|
|
|
|
- }
|
|
|
|
|
-
|
|
|
|
|
- $rootScope.performance.panels = [];
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- $scope.onAppEvent('dashboard-loaded', function() {
|
|
|
|
|
- count = 0;
|
|
|
|
|
-
|
|
|
|
|
- setTimeout(function() {
|
|
|
|
|
- console.log("Dashboard::Performance Total Digests: " + count);
|
|
|
|
|
- console.log("Dashboard::Performance Total Watchers: " + $scope.getTotalWatcherCount());
|
|
|
|
|
- console.log("Dashboard::Performance Total ScopeCount: " + $rootScope.performance.scopeCount);
|
|
|
|
|
-
|
|
|
|
|
- var timeTaken = $rootScope.performance.allPanelsInitialized - $rootScope.performance.dashboardLoadStart;
|
|
|
|
|
- console.log("Dashboard::Performance - All panels initialized in " + timeTaken + " ms");
|
|
|
|
|
-
|
|
|
|
|
- // measure digest performance
|
|
|
|
|
- var rootDigestStart = window.performance.now();
|
|
|
|
|
- for (var i = 0; i < 30; i++) {
|
|
|
|
|
- $rootScope.$apply();
|
|
|
|
|
- }
|
|
|
|
|
- console.log("Dashboard::Performance Root Digest " + ((window.performance.now() - rootDigestStart) / 30));
|
|
|
|
|
-
|
|
|
|
|
- }, 3000);
|
|
|
|
|
-
|
|
|
|
|
- });
|
|
|
|
|
-
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
$scope.init();
|
|
$scope.init();
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|