Skip to content

Commit 2a7d2ff

Browse files
committed
Merge branch 'profiling_in_dev' of https://github.com/mtanda/grafana into mtanda-profiling_in_dev
2 parents 67ad903 + 83c7698 commit 2a7d2ff

File tree

5 files changed

+33
-2
lines changed

5 files changed

+33
-2
lines changed

public/app/core/components/grafana_app.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export class GrafanaCtrl {
1717

1818
$scope._ = _;
1919

20-
$rootScope.profilingEnabled = store.getBool('profilingEnabled');
20+
$rootScope.profilingEnabled = store.getBool('profilingEnabled') || config.buildInfo.env === 'development';
2121
$rootScope.performance = { loadStart: new Date().getTime() };
2222
$rootScope.appSubUrl = config.appSubUrl;
2323

public/app/features/dashboard/dashboardCtrl.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,14 @@ function (angular, $, config, moment) {
6060
$scope.updateSubmenuVisibility();
6161
$scope.setWindowTitleAndTheme();
6262

63+
if ($scope.profilingEnabled) {
64+
$scope.performance.panels = [];
65+
$scope.performance.panelCount = 0;
66+
$scope.dashboard.rows.forEach(function(row) {
67+
$scope.performance.panelCount += row.panels.length;
68+
});
69+
}
70+
6371
$scope.appEvent("dashboard-loaded", $scope.dashboard);
6472
}).catch(function(err) {
6573
if (err.data && err.data.message) { err.message = err.data.message; }

public/app/features/dashboard/viewStateSrv.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,13 @@ function (angular, _, $) {
5151

5252
$scope.onAppEvent('panel-initialized', function(evt, payload) {
5353
self.registerPanel(payload.scope);
54+
55+
if ($scope.profilingEnabled) {
56+
$scope.performance.panelsInitialized++;
57+
if ($scope.performance.panelsInitialized === $scope.performance.panelCount) {
58+
$scope.performance.allPanelsInitialized = new Date().getTime();
59+
}
60+
}
5461
});
5562

5663
this.update(this.getQueryStringState());

public/app/features/panel/metrics_panel_ctrl.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,6 @@ class MetricsPanelCtrl extends PanelCtrl {
9595
}
9696

9797
setTimeQueryStart() {
98-
this.timing = {};
9998
this.timing.queryStart = new Date().getTime();
10099
}
101100

public/app/features/panel/panel_ctrl.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,15 @@ export class PanelCtrl {
3131
height: any;
3232
containerHeight: any;
3333
events: Emitter;
34+
timing: any;
3435

3536
constructor($scope, $injector) {
3637
this.$injector = $injector;
3738
this.$scope = $scope;
3839
this.$timeout = $injector.get('$timeout');
3940
this.editorTabIndex = 0;
4041
this.events = new Emitter();
42+
this.timing = {};
4143

4244
var plugin = config.panels[this.panel.type];
4345
if (plugin) {
@@ -58,6 +60,20 @@ export class PanelCtrl {
5860

5961
renderingCompleted() {
6062
this.$scope.$root.performance.panelsRendered++;
63+
this.timing.renderEnd = new Date().getTime();
64+
if (this.$scope.$root.profilingEnabled) {
65+
this.$scope.$root.performance.panels.push({
66+
panelId: this.panel.id,
67+
query: this.timing.queryEnd - this.timing.queryStart,
68+
render: this.timing.renderEnd - this.timing.renderStart,
69+
});
70+
71+
if (this.$scope.$root.performance.panelsRendered === this.$scope.$root.performance.panelCount) {
72+
this.$scope.$root.performance.allPanelsRendered = new Date().getTime();
73+
var timeTaken = this.$scope.$root.performance.allPanelsRendered - this.$scope.$root.performance.dashboardLoadStart;
74+
console.log("Dashboard::Performance - All panels rendered in " + timeTaken + " ms");
75+
}
76+
}
6177
}
6278

6379
refresh() {
@@ -169,6 +185,7 @@ export class PanelCtrl {
169185
}
170186

171187
this.calculatePanelHeight();
188+
this.timing.renderStart = new Date().getTime();
172189
this.events.emit('render', payload);
173190
}
174191

0 commit comments

Comments
 (0)