-
Notifications
You must be signed in to change notification settings - Fork 8
/
index_html.h
418 lines (414 loc) · 11.3 KB
/
index_html.h
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
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
/*
* index_html.h: RAPL power meter web interface script
*
* Copyright (C) 2014 Intel Corporation. All rights reserved.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License version
* 2 or later as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* Author Name <[email protected]>
*
*/
#ifndef INDEX_HTML_H_
#define INDEX_HTML_H_
const char index_html_contents_header[] = {
" <!DOCTYPE html>\n"
" <html>\n"
" <head>\n"
" <script>\n"
};
const char index_html_contents_contents[] = {
" var xmlhttp;\n"
" var start = 0;\n"
" var refresh_interval = 5;\n"
" var refreshIntervalId;\n"
" var domain_name;\n"
" var max_domains = 10;\n"
" var max_sub_domains = 10;\n"
" var csv_store_headers = '';\n"
" var log_enable = 0;\n"
" var csv_store = '';\n"
"\n"
" function init_array(rows, cols, defaultValue) {\n"
" var array = [];\n"
" for (var i = 0; i < rows; i++) {\n"
" array.push([]);\n"
" array[i].push(new Array(cols));\n"
" for (var j = 0; j < cols; j++) {\n"
" array[i][j] = defaultValue;\n"
" }\n"
" }\n"
"\n"
" return array;\n"
" }\n"
"\n"
" var energy_store = init_array(max_domains, max_domains, 0);\n"
" var max_energy_store = init_array(max_domains, max_domains, 0);\n"
"\n"
" function addRow(tableID, name, value) {\n"
"\n"
" var table = document.getElementById(tableID);\n"
" var rowCount = table.rows.length;\n"
" var row = table.insertRow(rowCount);\n"
"\n"
" var cell0 = row.insertCell(0);\n"
" cell0.innerHTML = name;\n"
" var cell1 = row.insertCell(1);\n"
" cell1.innerHTML = value;\n"
"\n"
"\n"
" var cell2 = row.insertCell(2);\n"
" cell2.innerHTML = '000.00W';\n"
"\n"
" }\n"
"\n"
" function deleteRow(tableID) {\n"
" var table = document.getElementById(tableID);\n"
" var rowCount = table.rows.length;\n"
"\n"
" for (var i = 0; i < rowCount; i++) {\n"
" var row = table.rows[i];\n"
" var chkbox = row.cells[0].childNodes[0];\n"
" if (null != chkbox && true == chkbox.checked) {\n"
" table.deleteRow(i);\n"
" rowCount--;\n"
" i--;\n"
" }\n"
" }\n"
" }\n"
"\n"
" function deleteAllRows(tableID) {\n"
" var table = document.getElementById(tableID);\n"
" var rowCount = table.rows.length;\n"
"\n"
" for (var i = 0; i < rowCount; i++) {\n"
" table.deleteRow(i);\n"
" rowCount--;\n"
" i--;\n"
" }\n"
" }\n"
"\n"
" function print_table(tableID) {\n"
" var table = document.getElementById(tableID);\n"
" var rowCount = table.rows.length;\n"
"\n"
" for (var i = 0; i < rowCount; i++) {\n"
" var row = table.rows[i];\n"
" console.log(row.cells[0].innerHTML,\n"
" row.cells[1].innerHTML,\n"
" row.cells[2].innerHTML);\n"
" }\n"
" }\n"
"\n"
" function loadXMLDoc(url, cfunc) {\n"
" if (window.XMLHttpRequest) {\n"
" xmlhttp = new XMLHttpRequest();\n"
"\n"
" } else {\n"
" xmlhttp =\n"
" new ActiveXObject(\"Microsoft.XMLHTTP\");\n"
" }\n"
" xmlhttp.onreadystatechange = cfunc;\n"
" console.log('GET URL ' + url);\n"
" xmlhttp.open(\"Get\", url, false);\n"
" xmlhttp.send();\n"
" console.log('Response recd');\n"
" }\n"
"\n"
" function get_domain_name(tableid, domain, sub_domain) {\n"
" var domain_path;\n"
"\n"
" if (sub_domain == -1) domain_path = root_path +\n"
" 'rapl_domain_name/' + domain;\n"
" else domain_path = root_path + 'rapl_domain_name/' +\n"
" domain + '/' + sub_domain;\n"
"\n"
" loadXMLDoc(domain_path, function () {\n"
" if (xmlhttp.readyState == 4 &&\n"
" xmlhttp.status == 200) {\n"
" if (sub_domain == -1) {\n"
" addRow(tableid,\n"
" xmlhttp.responseText, ' ', ' ');\n"
" } else {\n"
" addRow(tableid, ' ',\n"
" xmlhttp.responseText, ' ');\n"
" }\n"
" csv_store_headers = csv_store_headers + xmlhttp.responseText.replace(\n"
" /(\\r\\n|\\n|\\r)/gm, \" \") + ',';\n"
" return;\n"
"\n"
" }\n"
" });\n"
" }\n"
"\n"
" function create_sub_domain_rows(domain, tableid) {\n"
" var count;\n"
" loadXMLDoc(root_path + 'rapl_domains_count/' + domain,\n"
" function () {\n"
" if (xmlhttp.readyState == 4 &&\n"
" xmlhttp.status == 200) {\n"
" count = xmlhttp.responseText;\n"
" for (var i = 0; i < count; ++i) {\n"
" get_domain_name(tableid, domain, i);\n"
" }\n"
" }\n"
" });\n"
" }\n"
"\n"
" function create_domain_rows(tableid) {\n"
" loadXMLDoc(root_path + 'rapl_domains_count',\n"
" function () {\n"
" if (xmlhttp.readyState == 4 &&\n"
" xmlhttp.status == 200) {\n"
" var count = xmlhttp.responseText;\n"
" for (var i = 0; i < count; ++i) {\n"
" get_domain_name(tableid, i, -1);\n"
" create_sub_domain_rows(i, tableid);\n"
" }\n"
" }\n"
" });\n"
" csv_store_headers = csv_store_headers + '\\r\\n';\n"
" }\n"
"\n"
"\n"
" function getPower(domain, sub_domain, row) {\n"
" var url;\n"
" var curr_energy;\n"
" var power;\n"
" var diff;\n"
" var valid;\n"
" if (sub_domain == -1) url = root_path +\n"
" 'rapl_domain_energy/' + domain;\n"
" else url = root_path + 'rapl_domain_energy/' +\n"
" domain + '/' + sub_domain;\n"
"\n"
" loadXMLDoc(url, function () {\n"
" if (xmlhttp.readyState == 4 &&\n"
" xmlhttp.status == 200) {\n"
" curr_energy = xmlhttp.responseText;\n"
" if (curr_energy < energy_store[domain][\n"
" sub_domain + 1\n"
" ]) {\n"
" if (max_energy_store[domain][sub_domain + 1]) {\n"
" diff = max_energy_store[domain][\n"
" sub_domain + 1\n"
" ] -\n"
" energy_store[domain][\n"
" sub_domain + 1\n"
" ];\n"
" diff = diff + curr_energy;\n"
" }\n"
" } else {\n"
" diff = curr_energy - energy_store[\n"
" domain][sub_domain + 1];\n"
" }\n"
" if (diff) {\n"
" power = diff / (1000000 * refresh_interval);\n"
" power = Math.round(power * 1000) / 1000;\n"
"\n"
" if (energy_store[domain][sub_domain + 1]) {\n"
" row.cells[2].innerHTML = power + 'W';\n"
" if (log_enable)\n"
" csv_store = csv_store + power + ',';\n"
" } else {\n"
" row.cells[2].innerHTML = 'Sampling...';\n"
" if (log_enable)\n"
" csv_store = csv_store + '00.00' + ',';\n"
" }\n"
" }\n"
" energy_store[domain][sub_domain + 1] =\n"
" curr_energy;\n"
"\n"
" return power;\n"
" }\n"
" });\n"
"\n"
" }\n"
"\n"
" function getMaxEnergy(domain, sub_domain) {\n"
" var url;\n"
" var max_energy;\n"
" var power;\n"
"\n"
" if (sub_domain == -1)\n"
" url = root_path + 'rapl_domain_max_energy/' +\n"
" domain;\n"
" else\n"
" url = root_path + 'rapl_domain_max_energy/' +\n"
" domain + '/' + sub_domain;\n"
"\n"
" loadXMLDoc(url, function () {\n"
" if (xmlhttp.readyState == 4 &&\n"
" xmlhttp.status == 200) {\n"
" max_energy_store[domain][\n"
" sub_domain + 1\n"
" ] =\n"
" xmlhttp.responseText;\n"
" }\n"
" });\n"
" }\n"
"\n"
" function update_table(tableID) {\n"
" var table = document.getElementById(tableID);\n"
" var rowCount = table.rows.length;\n"
" var domain_cnt = 0;\n"
" var sub_domain_cnt = 0;\n"
" var power;\n"
"\n"
" domain_cnt = -1;\n"
"\n"
" for (var i = 0; i < rowCount; i++) {\n"
" var row = table.rows[i];\n"
" if (domain_cnt >= max_domains) break;\n"
" if (sub_domain_cnt >= max_sub_domains)\n"
" break;\n"
" if (row.cells[0].innerHTML == ' ') {\n"
" getPower(domain_cnt, sub_domain_cnt,\n"
" row);\n"
" sub_domain_cnt = sub_domain_cnt + 1;\n"
" } else {\n"
" sub_domain_cnt = 0;\n"
" domain_cnt = domain_cnt + 1;\n"
" getPower(domain_cnt, -1, row);\n"
" }\n"
" }\n"
" if (log_enable)\n"
" csv_store = csv_store + '\\r\\n';\n"
" }\n"
"\n"
" function startFunction(tableid) {\n"
" var sub_domain_cnt = 0;\n"
" var table = document.getElementById(tableid);\n"
" var rowCount;\n"
"\n"
" var store_refresh_interval = refresh_interval;\n"
" if (start == 1)\n"
" return;\n"
" start = 1;\n"
" csv_store = '';\n"
" csv_store_headers = '';\n"
" deleteAllRows(tableid);\n"
" create_domain_rows(tableid);\n"
" domain_cnt = -1;\n"
" rowCount = table.rows.length;\n"
" for (var i = 0; i < rowCount; i++) {\n"
" var row = table.rows[i];\n"
" if (domain_cnt >= max_domains) break;\n"
" if (sub_domain_cnt >= max_sub_domains)\n"
" break;\n"
" if (row.cells[0].innerHTML == ' ') {\n"
" getMaxEnergy(domain_cnt,\n"
" sub_domain_cnt, row);\n"
" energy_store[domain_cnt][\n"
" sub_domain_cnt + 1\n"
" ] = 0;\n"
" sub_domain_cnt = sub_domain_cnt + 1;\n"
" } else {\n"
" sub_domain_cnt = 0;\n"
" domain_cnt = domain_cnt + 1;\n"
" getMaxEnergy(domain_cnt, -1, row);\n"
" energy_store[domain_cnt][\n"
" sub_domain_cnt\n"
" ] = 0;\n"
" }\n"
" row.cells[2].innerHTML = '0.00' + 'W';\n"
" }\n"
" update_table(tableid);\n"
" refreshIntervalId = setInterval(function () {\n"
" update_table(tableid);\n"
" }, (refresh_interval * 1000));\n"
"\n"
" }\n"
"\n"
" function stopFunction() {\n"
" start = 0;\n"
" log_enable = 0;\n"
" clearInterval(refreshIntervalId);\n"
" }\n"
"\n"
" function download(filename) {\n"
" var contentType = 'application/text';\n"
" var a = document.createElement('a');\n"
" var content;\n"
" content = csv_store_headers + csv_store;\n"
" var blob = new Blob([content], {\n"
" 'type': contentType\n"
" });\n"
" a.href = window.URL.createObjectURL(blob);\n"
" a.download = filename;\n"
" a.click();\n"
" }\n"
"\n"
" function log_start_stop(start) {\n"
" if (start == 'TRUE') {\n"
" log_enable = 1;\n"
" csv_store = '';\n"
" } else\n"
" log_enable = 0;\n"
" }\n"
"\n"
" function updatePollInterval(id) {\n"
" var form = document.getElementById(id);\n"
"\n"
" console.log('form data:' + form.value);\n"
" if (form.value > 0) {\n"
" refresh_interval = form.value;\n"
" }\n"
" }\n"
" </script>\n"
"</head>\n"
"\n"
"<body>\n"
"\n"
" <div style=\"width:600px;border:3px inset blue;text-align:center\">\n"
" <h2>\n"
" Software Power Meter\n"
" </h2>\n"
" <button type=\"button\" onclick=\"startFunction('domains')\">\n"
" Start\n"
" </button>\n"
" <button type=\"button\" onclick=\"stopFunction()\">\n"
" Stop\n"
" </button>\n"
"\n"
" <br>\n"
" <br>\n"
" <form name='pollIntervalForm'>\n"
" Poll Interval (Seconds)\n"
" <input type='text' onChange=\"updatePollInterval('poll_interval');\"\n"
" id=\"poll_interval\" />\n"
" <br />\n"
" </form>\n"
" <br>\n"
" <br>\n"
" <table id=\"domains\" border=\"1\" align=\"center\" style=\"font-family:Georgia, Garamond, Serif;color:blue;font-style:italic;\">\n"
" </table>\n"
" <br>\n"
" <button type=\"button\" onclick=\"log_start_stop('TRUE')\">\n"
" Enable Log\n"
" </button>\n"
" <button type=\"button\" onclick=\"log_start_stop('FALSE')\">\n"
" Disable Log\n"
" </button>\n"
" <button type=\"button\" onclick=\"download('rapl_power_log.csv')\">\n"
" Download\n"
" </button>\n"
" <br>\n"
" <h4>\n"
" Using Running Average Power Limit (RAPL) feature on\n"
" <br>\n"
" Intel® Processors\n"
" </h4>\n"
" </div>\n"
"\n"
"</body>\n"
"\n"
"</html>\n"
};
#endif /* INDEX_HTML_H_ */