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.textContent = 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.textContent = '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.textContent = bucket.min + '-' + bucket.max; |
| 42 headerRow.appendChild(header); |
| 43 var data = document.createElement('td'); |
| 44 data.textContent = bucket.count; |
| 45 dataRow.appendChild(data); |
| 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 $('status').textContent = |
| 58 data.instantiated ? 'Instantiated' : 'Not Instantiated'; |
| 59 $('details').hidden = !data.instantiated; |
| 60 if (!data.instantiated) |
| 61 return; |
| 62 |
| 63 TaskSchedulerInternals.updateHistograms(data.histograms); |
| 64 }; |
| 65 |
| 66 document.addEventListener('DOMContentLoaded', function() { |
| 67 chrome.send('getTaskSchedulerData'); |
| 68 }); |
OLD | NEW |