Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3727)

Unified Diff: chrome/browser/resources/task_scheduler_internals/index.js

Issue 2420973002: Plumb Task Scheduler Histograms to the Task Scheduler Internals Page (Closed)
Patch Set: The Return of std::move Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/resources/task_scheduler_internals/index.js
diff --git a/chrome/browser/resources/task_scheduler_internals/index.js b/chrome/browser/resources/task_scheduler_internals/index.js
new file mode 100644
index 0000000000000000000000000000000000000000..72006c59a33b29e9cf3a87f9ca410ab0c5a51f65
--- /dev/null
+++ b/chrome/browser/resources/task_scheduler_internals/index.js
@@ -0,0 +1,68 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+var TaskSchedulerInternals = {};
+
+/**
+ * Updates the histograms on the page.
+ * @param {Array<Object>} histograms Array of histogram objects.
+ */
+TaskSchedulerInternals.updateHistograms = function(histograms) {
+ var histogramContainer = $('histogram-container');
+ for (var i in histograms) {
+ var histogram = histograms[i];
+ var title = document.createElement('div');
+ title.textContent = histogram.name;
+ histogramContainer.appendChild(title);
+ if (histogram.buckets.length > 0) {
+ histogramContainer.appendChild(
+ TaskSchedulerInternals.createHistogramTable(histogram.buckets));
+ } else {
+ var unavailable = document.createElement('div');
+ unavailable.textContent = 'No Data Recorded';
+ histogramContainer.appendChild(unavailable);
+ }
+ }
+};
+
+/**
+ * Returns a table representation of the histogram buckets.
+ * @param {Object} buckets The histogram buckets.
+ * @return {Object} A table element representation of the histogram buckets.
+ */
+TaskSchedulerInternals.createHistogramTable = function(buckets) {
+ var table = document.createElement('table');
+ var headerRow = document.createElement('tr');
+ var dataRow = document.createElement('tr');
+ for (var i in buckets) {
+ var bucket = buckets[i];
+ var header = document.createElement('th');
+ header.textContent = bucket.min + '-' + bucket.max;
+ headerRow.appendChild(header);
+ var data = document.createElement('td');
+ data.textContent = bucket.count;
+ dataRow.appendChild(data);
+ }
+ table.appendChild(headerRow);
+ table.appendChild(dataRow);
+ return table;
+};
+
+/**
+ * Handles callback from onGetTaskSchedulerData.
+ * @param {Object} data Dictionary containing all task scheduler metrics.
+ */
+TaskSchedulerInternals.onGetTaskSchedulerData = function(data) {
+ $('status').textContent =
+ data.instantiated ? 'Instantiated' : 'Not Instantiated';
+ $('details').hidden = !data.instantiated;
+ if (!data.instantiated)
+ return;
+
+ TaskSchedulerInternals.updateHistograms(data.histograms);
+};
+
+document.addEventListener('DOMContentLoaded', function() {
+ chrome.send('getTaskSchedulerData');
+});

Powered by Google App Engine
This is Rietveld 408576698