blob: 4277506c48d668632912415d60bfe1ba94a380a5 [file] [log] [blame]
Georgios Katsikas973a2652018-06-28 08:45:47 +02001/*
2 * Copyright 2018-present Open Networking Foundation
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17/*
18 ONOS GUI -- Latency View Module
19 */
20(function () {
21 'use strict';
22
23 // injected references
24 var $log, $scope, $location, ks, fs, cbs, ns;
25
26 var hasDeviceId;
27 // TODO: Pass this dynamically
28 var coresNb = 16;
29
30 var labels = new Array(1);
31 var data = new Array(coresNb);
32 for (var i = 0; i < coresNb; i++) {
33 data[i] = new Array(1);
34 data[i][0] = 0;
35 }
36
37 angular.module('ovLatency', ["chart.js"])
38 .controller('OvLatencyCtrl',
39 ['$log', '$scope', '$location', 'FnService', 'ChartBuilderService', 'NavService',
40
41 function (_$log_, _$scope_, _$location_, _fs_, _cbs_, _ns_) {
42 var params;
43 $log = _$log_;
44 $scope = _$scope_;
45 $location = _$location_;
46 fs = _fs_;
47 cbs = _cbs_;
48 ns = _ns_;
49
50 params = $location.search();
51
52 if (params.hasOwnProperty('devId')) {
53 $scope.devId = params['devId'];
54 hasDeviceId = true;
55 } else {
56 hasDeviceId = false;
57 }
58
59 cbs.buildChart({
60 scope: $scope,
61 tag: 'latency',
62 query: params
63 });
64
65 $scope.$watch('chartData', function () {
66 if (!fs.isEmptyObject($scope.chartData)) {
67 $scope.showLoader = false;
68 var length = $scope.chartData.length;
69 labels = new Array(length);
70 for (var i = 0; i < coresNb; i++) {
71 data[i] = new Array(length);
72 }
73
74 $scope.chartData.forEach(
75 function (cm, idx) {
76 // TODO: Squeeze using a working loop?
77 data[0][idx] = cm.latency_0;
78 data[1][idx] = cm.latency_1;
79 data[2][idx] = cm.latency_2;
80 data[3][idx] = cm.latency_3;
81 data[4][idx] = cm.latency_4;
82 data[5][idx] = cm.latency_5;
83 data[6][idx] = cm.latency_6;
84 data[7][idx] = cm.latency_7;
85 data[8][idx] = cm.latency_8;
86 data[9][idx] = cm.latency_9;
87 data[10][idx] = cm.latency_10;
88 data[11][idx] = cm.latency_11;
89 data[12][idx] = cm.latency_12;
90 data[13][idx] = cm.latency_13;
91 data[14][idx] = cm.latency_14;
92 data[15][idx] = cm.latency_15;
93
94 labels[idx] = cm.label;
95 }
96 );
97 }
98
99 $scope.labels = labels;
100 $scope.data = data;
101
102 $scope.options = {
103 scales: {
104 yAxes: [{
105 type: 'linear',
106 position: 'left',
107 id: 'y-axis-latency',
108 ticks: {
109 beginAtZero: true,
110 fontSize: 28,
111 },
112 scaleLabel: {
113 display: true,
114 labelString: 'Latency/CPU Core (ns)',
115 fontSize: 28,
116 }
117 }],
118 xAxes: [{
119 id: 'x-axis-servers-cores',
120 ticks: {
121 fontSize: 28,
122 },
123 scaleLabel: {
124 display: true,
125 fontSize: 28,
126 }
127 }]
128 }
129 };
130
131 $scope.onClick = function (points, evt) {
132 var label = labels[points[0]._index];
133 if (label) {
134 ns.navTo('latency', { devId: label });
135 $log.log(label);
136 }
137 };
138
139 if (!fs.isEmptyObject($scope.annots)) {
140 $scope.deviceIds = JSON.parse($scope.annots.deviceIds);
141 }
142
143 $scope.onChange = function (deviceId) {
144 ns.navTo('latency', { devId: deviceId });
145 };
146 });
147
148 $scope.series = new Array(coresNb);
149 for (var i = 0; i < coresNb; i++) {
150 $scope.series[i] = 'Latency-CPU ' + i;
151 }
152
153 $scope.labels = labels;
154 $scope.data = data;
155
156 // TODO: For some reason, this assignment does not work
157 $scope.chartColors = [
158 '#e6194b', // Red
159 '#3cb44b', // Green
160 '#ffe119', // Yellow
161 '#0082c8', // Blue
162 '#f58231', // Orange
163 '#808080', // Grey
164 '#fffac8', // Beige
165 '#aaffc3', // Mint
166 '#911eb4', // Purple
167 '#46f0f0', // Cyan
168 '#d2f53c', // Lime
169 '#800000', // Maroon
170 '#000000', // Black
171 '#f032e6', // Magenta
172 '#008080', // Teal
173 '#808000', // Olive
174 '#aa6e28' // Brown
175 ];
176 Chart.defaults.global.colours = $scope.chartColors;
177
178 $scope.showLoader = true;
179
180 $log.log('OvLatencyCtrl has been created');
181 }]);
182
183}());