1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
|
<h2>{{lang_benchmarkResult}}</h2>
<div class=progress id="progress">
<div class="progress-bar bg-warning" role="progressbar" aria-valuenow="0" aria-valuemax="100"
id="progress-bar"></div>
</div>
<span id="progress-clients" class="justify-content-center"></span>
<div id="graphs"></div>
<div id="errors" class="alert"></div>
<script>
document.addEventListener('DOMContentLoaded', function () {
var errorsFound = 0;
// This is the list of clients we expect, so as long as there's less entries in result, we're not done yet
var clients = {{{wanted}}};
// Store the initial number of clients since we remove them later (needed for updating progress bar)
var NumClients = clients.length;
var graphs = {};
// This is the old estimate, there's not much point polling for results before this expires
var remaining = {{remaining}};
updateProgressBar();
var counter = 0;
var remainingInterval, getDataInterval;
function formatBytes(val) {
return Math.floor(val / 1024 / 1024) + "\u2009MiB/s";
}
function renderX(val, index) {
return Math.floor(val / 1000) + '\u2009s';
}
function getData() {
$('#remaining').remove();
$.get('?do=vmstore&id=' + {{id}}).done(function (data) {
// Use slice method to make an actual copy of the array and do not reference the old array
clients_temp = clients.slice();
$.each(clients_temp, function (index, item) {
if (typeof data != "undefined" && item in data) {
clients.splice(clients.indexOf(item), 1);
updateProgressBar();
if (data[item].stdout || data[item].stderr) renderError(data, item);
}
});
// Only render graphs if we actually received client data
if (clients_temp.length != clients.length) {
makeGraph('SEQ', data, 'net', 'Sequential Reads');
makeGraph('RND', data, 'net', 'Random 1M');
}
// All clients in Data
if (clients.length === 0) {
$('#progress').remove();
$('#progress-clients').remove();
// Render a success window if we did not recieve any errors
if (!errorsFound) {
$('#errors').html('No errors found in client data');
$('#errors').addClass('alert-success');
}
clearInterval(getDataInterval);
}
}) // .always( set timeout( ... 1000) );
}
function renderError(result, uuid) {
var $err = $('#errors');
$err.addClass('alert-danger');
if (errorsFound == 0) $err.append('<h4> Errors </h4>');
errorsFound = 1;
var $frame = $('<div class="panel panel-body">');
$frame.append($('<h5>').text(result[uuid].name));
if (result[uuid].stdout) {
$frame.append($('<label>').text('stdout'));
$frame.append($('<pre>').text(result[uuid].stdout));
}
if (result[uuid].stderr) {
$frame.append($('<label>').text('stderr'));
$frame.append($('<pre>').text(result[uuid].stderr));
}
$err.append($frame);
}
function makeGraph(typeKey, result, resourceKey, caption) {
var uuid;
var ds = [];
var gmin = 0, rmax = 0;
var colors = [];
var cnt = 0;
for (uuid in result) {
if (!result[uuid][typeKey]) {
delete result[uuid];
continue;
console.log("Result empty");
}
if (gmin === 0 || result[uuid][typeKey].start < gmin) {
gmin = result[uuid][typeKey].start;
}
cnt++;
}
if (cnt === 1) {
colors.push('rgb(0, 128, 0)');
} else {
for (i = 0; i < cnt; ++i) {
colors.push('rgb(0, 128, ' + (i / (cnt - 1)) * 255 + ')');
}
}
var v, i, o, idx;
var sums = [];
for (uuid in result) {
o = result[uuid][typeKey].start - gmin; // Adjust according to earliest client
v = result[uuid][typeKey].values[resourceKey];
for (i = 0; i < v.length; ++i) {
v[i].x += o;
if (cnt > 1) {
idx = Math.round(v[i].x / 250);
if (sums[idx]) {
sums[idx] += v[i].y | 0;
} else {
sums[idx] = v[i].y | 0;
}
}
}
if (v[v.length - 1].x > rmax) {
rmax = v[v.length - 1].x; // Get max value
if (graphs[typeKey]) {
// If the graph was already rendered we have to update the max Value for the x Scale
// and re calculate the labels array
graphs[typeKey].options.scales.x.max = v[v.length - 1].x;
var ls = [];
for (i = 0; i <= rmax; i += 250) ls.push(i);
graphs[typeKey].data.labels = ls;
}
}
ds.push({data: v, label: result[uuid].name, borderColor: colors[ds.length], fill: false});
}
if (cnt > 1) {
ds.push({data: sums, label: 'Sum', borderColor: '#c00'});
}
if (!graphs[typeKey]) {
var $e = $('#graphs');
var $c = $('<canvas style="width:100%;height:250px">');
$e.append($('<h3>').text(caption));
$e.append($c);
var ls = [];
for (i = 0; i <= rmax; i += 250) ls.push(i); // Generate steps for graph
graphs[typeKey] = new Chart($c[0].getContext('2d'), {
data: {datasets: ds, labels: ls}, type: 'scatter', options: {
animation: false,
responsive: true,
borderWidth: 2,
pointBorderWidth: 0,
showLine: true,
scales: {y: {ticks: {callback: formatBytes}}, x: {ticks: {callback: renderX}, max: rmax}},
plugins: {
tooltip: {
callbacks: {
label: function (context) {
if (context.parsed.y !== null) {
return context.dataset.label + ": " + formatBytes(context.parsed.y);
}
return context.dataset.label;
}
}
},
legend: {position: 'left'}
}
}
});
} else {
graphs[typeKey].data.datasets = ds;
graphs[typeKey].update();
}
}
function updateRemaining() {
counter += 1;
if (counter >= remaining) {
clearInterval(remainingInterval);
}
updateProgressBar();
}
function updateProgressBar() {
var progress;
if (remaining > 0) {
// reserve 80% of the progress bar for the initial "remaining" time
// and 20% for the clients we receive
progress = counter / remaining * 0.8 + (NumClients - clients.length) / NumClients * 0.2;
} else {
progress = 0.8 + (NumClients - clients.length) / NumClients * 0.2;
}
$('#progress-bar').attr('aria-valuenow', progress * 100).css('width', progress * 100 + '%');
$('#progress-bar').html(Math.round(progress * 100) + '%');
$('#progress-clients').html(clients.length + ' Client(s) remaining');
}
setTimeout(function() {
getDataInterval = setInterval(getData, 1000)
}, remaining > 0 ? remaining * 1000 - 1000 : 1);
remainingInterval = setInterval(updateRemaining, 1000);
});
</script>
|