Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 var TaskSchedulerInternals = {}; | |
| 6 | |
| 7 /** | |
| 8 * Updates the histograms on the page. | |
| 9 * @param {Array<Object>} histograms Array of histogram objects. | |
| 10 */ | |
| 11 TaskSchedulerInternals.updateHistograms = function(histograms) { | |
| 12 var histogramContainer = $('histogram-container'); | |
| 13 for (var i in histograms) { | |
| 14 var histogram = histograms[i]; | |
| 15 var title = document.createElement('div'); | |
| 16 title.innerHTML = histogram.name; | |
| 17 histogramContainer.appendChild(title); | |
| 18 if (histogram.buckets.length > 0) { | |
| 19 histogramContainer.appendChild( | |
| 20 TaskSchedulerInternals.createHistogramTable(histogram.buckets)); | |
| 21 } else { | |
| 22 var unavailable = document.createElement('div'); | |
| 23 unavailable.innerHTML = 'No Data Recorded'; | |
| 24 histogramContainer.appendChild(unavailable); | |
| 25 } | |
| 26 } | |
| 27 }; | |
| 28 | |
| 29 /** | |
| 30 * Returns a table representation of the histogram buckets. | |
| 31 * @param {Object} buckets The histogram buckets. | |
| 32 * @return {Object} A table element representation of the histogram buckets. | |
| 33 */ | |
| 34 TaskSchedulerInternals.createHistogramTable = function(buckets) { | |
| 35 var table = document.createElement('table'); | |
| 36 var headerRow = document.createElement('tr'); | |
| 37 var dataRow = document.createElement('tr'); | |
| 38 for (var i in buckets) { | |
| 39 var bucket = buckets[i]; | |
| 40 var header = document.createElement('th'); | |
| 41 header.innerHTML = bucket.min + '-' + bucket.max; | |
| 42 headerRow.appendChild(header); | |
| 43 var data = document.createElement('td'); | |
| 44 data.innerHTML = bucket.count; | |
| 45 dataRow.appendChild(data); | |
|
fdoray
2016/10/14 20:59:06
Could we reuse the ASCII charts from chrome://hist
robliao
2016/10/17 22:36:57
We're going to have spiffy HTML tables that will u
| |
| 46 } | |
| 47 table.appendChild(headerRow); | |
| 48 table.appendChild(dataRow); | |
| 49 return table; | |
| 50 }; | |
| 51 | |
| 52 /** | |
| 53 * Handles callback from onGetTaskSchedulerData. | |
| 54 * @param {Object} data Dictionary containing all task scheduler metrics. | |
| 55 */ | |
| 56 TaskSchedulerInternals.onGetTaskSchedulerData = function(data) { | |
| 57 console.log(data); | |
| 58 $('status').innerHTML = | |
| 59 data.instantiated ? 'Instantiated' : 'Not Instantiated'; | |
| 60 $('details').style.visibility = data.instantiated ? 'visible' : 'hidden'; | |
| 61 if (!data.instantiated) | |
| 62 return; | |
| 63 | |
| 64 TaskSchedulerInternals.updateHistograms(data.histograms); | |
| 65 }; | |
| 66 | |
| 67 document.addEventListener('DOMContentLoaded', function() { | |
| 68 chrome.send('getTaskSchedulerData'); | |
| 69 }); | |
| OLD | NEW |