From 59a2109cabece5584a4beb906354af1e75d66d1e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Torkel=20=C3=96degaard?= Date: Sat, 9 May 2015 15:26:39 +0200 Subject: [PATCH] Investigating some performance optimizations, added more perf instrumentation & measurements --- public/app/controllers/grafanaCtrl.js | 20 +++++++++++++ public/app/features/panel/panelHelper.js | 37 +++++++++++++++++++++++- public/app/features/panellinks/module.js | 2 +- public/app/panels/graph/module.js | 2 +- 4 files changed, 58 insertions(+), 3 deletions(-) diff --git a/public/app/controllers/grafanaCtrl.js b/public/app/controllers/grafanaCtrl.js index 08ae1b9c1a8..16e505a68dc 100644 --- a/public/app/controllers/grafanaCtrl.js +++ b/public/app/controllers/grafanaCtrl.js @@ -83,6 +83,26 @@ function (angular, config, _, $, store) { }, function() { }); + $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) { + 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; diff --git a/public/app/features/panel/panelHelper.js b/public/app/features/panel/panelHelper.js index cb549c6bf43..f0b803b03e4 100644 --- a/public/app/features/panel/panelHelper.js +++ b/public/app/features/panel/panelHelper.js @@ -9,7 +9,39 @@ function (angular, _, kbn, $) { var module = angular.module('grafana.services'); - module.service('panelHelper', function(timeSrv) { + module.service('panelHelper', function(timeSrv, $rootScope) { + var self = this; + + this.setTimeQueryStart = function(scope) { + scope.timing = {}; + scope.timing.queryStart = new Date().getTime(); + }; + + this.setTimeQueryEnd = function(scope) { + scope.timing.queryEnd = new Date().getTime(); + }; + + this.setTimeRenderStart = function(scope) { + scope.timing.renderStart = new Date().getTime(); + }; + + this.setTimeRenderEnd = function(scope) { + scope.timing.renderEnd = new Date().getTime(); + }; + + this.broadcastRender = function(scope, data) { + this.setTimeRenderStart(scope); + scope.$broadcast('render', data); + this.setTimeRenderEnd(scope); + + if ($rootScope.profilingEnabled) { + $rootScope.performance.panels.push({ + panelId: scope.panel.id, + query: scope.timing.queryEnd - scope.timing.queryStart, + render: scope.timing.renderEnd - scope.timing.renderStart, + }); + } + }; this.updateTimeRange = function(scope) { scope.range = timeSrv.timeRange(); @@ -72,7 +104,10 @@ function (angular, _, kbn, $) { cacheTimeout: scope.panel.cacheTimeout }; + this.setTimeQueryStart(scope); return datasource.query(metricsQuery).then(function(results) { + self.setTimeQueryEnd(scope); + if (scope.dashboard.snapshot) { scope.panel.snapshotData = results; } diff --git a/public/app/features/panellinks/module.js b/public/app/features/panellinks/module.js index 7b2a9adf25e..cebb2d3a505 100644 --- a/public/app/features/panellinks/module.js +++ b/public/app/features/panellinks/module.js @@ -15,7 +15,7 @@ function (angular, _) { }, restrict: 'E', controller: 'PanelLinksEditorCtrl', - templateUrl: 'app/features/panellinkeditor/module.html', + templateUrl: 'app/features/panellinks/module.html', link: function() { } }; diff --git a/public/app/panels/graph/module.js b/public/app/panels/graph/module.js index dfcd5901594..6671ef33289 100644 --- a/public/app/panels/graph/module.js +++ b/public/app/panels/graph/module.js @@ -197,7 +197,7 @@ function (angular, app, $, _, kbn, moment, TimeSeries, PanelMeta) { }; $scope.render = function(data) { - $scope.$broadcast('render', data); + panelHelper.broadcastRender($scope, data); }; $scope.changeSeriesColor = function(series, color) {