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

Unified Diff: tracing/tracing/value/histogram_parameter_collector.html

Issue 2747453003: Refactor histogram-set-view to an MVC pattern. (Closed)
Patch Set: Created 3 years, 8 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: tracing/tracing/value/histogram_parameter_collector.html
diff --git a/tracing/tracing/value/histogram_parameter_collector.html b/tracing/tracing/value/histogram_parameter_collector.html
new file mode 100644
index 0000000000000000000000000000000000000000..5be74254ba1b72d17c2dd9d414a8232868a809f6
--- /dev/null
+++ b/tracing/tracing/value/histogram_parameter_collector.html
@@ -0,0 +1,135 @@
+<!DOCTYPE html>
+<!--
+Copyright 2017 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.
+-->
+
+<link rel="import" href="/tracing/value/histogram_set.html">
+
+<script>
+'use strict';
+tr.exportTo('tr.v', function() {
+ const getDisplayLabel = tr.v.HistogramSet.GROUPINGS.DISPLAY_LABEL.callback;
+
+ const DEFAULT_POSSIBLE_GROUPS = [];
+
+ // Override HISTOGRAM_NAME so that we can display shortName.
+ DEFAULT_POSSIBLE_GROUPS.push(new tr.v.HistogramGrouping(
+ tr.v.HistogramSet.GROUPINGS.HISTOGRAM_NAME.key,
+ h => h.shortName || h.name));
+
+ for (const group of Object.values(tr.v.HistogramSet.GROUPINGS)) {
+ // DISPLAY_LABEL is used to define the columns, so don't allow grouping
+ // rows by it.
+ // HISTOGRAM_NAME is overridden.
+ if (group !== tr.v.HistogramSet.GROUPINGS.DISPLAY_LABEL &&
+ group !== tr.v.HistogramSet.GROUPINGS.HISTOGRAM_NAME) {
+ DEFAULT_POSSIBLE_GROUPS.push(group);
+ }
+ }
+
+ // This Processor collects various parameters from a set of Histograms such as
+ // their statistics, displayLabels, and grouping keys in a single pass.
+ class HistogramParameterCollector {
+ constructor() {
+ this.statisticNames_ = new Set(['avg']);
+
+ this.labelsToStartTimes_ = new Map();
+
+ // @typedef {!Map.<string,!tr.v.HistogramGrouping>}
+ this.keysToGroupings_ = new Map(DEFAULT_POSSIBLE_GROUPS.map(
+ g => [g.key, g]));
+
+ // Map from HistogramGrouping keys to Sets of return values from the
+ // HistogramGroupings' callbacks.
+ this.keysToValues_ = new Map(DEFAULT_POSSIBLE_GROUPS.map(
+ g => [g.key, new Set()]));
+
+ // Never remove 'name' from keysToGroupings.
+ this.keysToValues_.delete(tr.v.HistogramSet.GROUPINGS.HISTOGRAM_NAME.key);
+ }
+
+ process(histograms) {
+ for (const hist of histograms) {
+ for (const statName of hist.statisticsNames) {
+ this.statisticNames_.add(statName);
+ }
+
+ const telemetry = tr.v.d.TelemetryInfo.getFromHistogram(hist);
+
+ let startTime = 0;
+ if (telemetry && telemetry.benchmarkStart) {
+ startTime = telemetry.benchmarkStart.getTime();
+ }
+ const displayLabel = getDisplayLabel(hist);
+
+ this.labelsToStartTimes_.set(displayLabel, Math.min(
+ startTime, this.labelsToStartTimes_.get(displayLabel, 0)));
+
+ if (!telemetry) continue;
+
+ for (const [groupingKey, values] of this.keysToValues_) {
+ const grouping = this.keysToGroupings_.get(groupingKey);
+ const value = grouping.callback(hist);
+ if (!value) continue;
+ values.add(value);
+ if (values.size > 1) {
+ // This grouping will definitely stay in keysToGroupings_. We don't
+ // need to see any more values in the rest of histograms. Remove
+ // this groupingKey from this.keysToValues_ so that we don't compute
+ // it for any more histograms and so that we don't delete it from
+ // keysToGroupings_.
+ this.keysToValues_.delete(groupingKey);
+ }
+ }
+
+ // Translate storyGroupingKeys like {cache_temp: 'cold'} into
+ // HistogramGroupings like {
+ // key: 'storyGroupingKey_cache_temp',
+ // callback: (a function that takes a Histogram and returns its
+ // TelemetryInfo.storyGroupingKeys.get('cache_temp')),
+ // }
+
+ for (const [key, value] of telemetry.storyGroupingKeys) {
+ // If this storyGroupingKey is not yet known, then add a new
+ // HistogramGrouping to keysToGroupings_ and a new Set of values to
+ // keysToValues_
+ const groupingKey = 'storyGroupingKey_' + key;
+ if (this.keysToGroupings_.has(groupingKey)) continue;
+ this.keysToGroupings_.set(groupingKey, new tr.v.HistogramGrouping(
+ groupingKey,
+ tr.v.d.TelemetryInfo.makeStoryGroupingKeyLabelGetter(key)));
+ this.keysToValues_.set(groupingKey, new Set([value]));
+ }
+ }
+ }
+
+ get statisticNames() {
+ return Array.from(this.statisticNames_);
+ }
+
+ get labels() {
+ const displayLabels = Array.from(this.labelsToStartTimes_.keys());
+ displayLabels.sort((x, y) =>
+ this.labelsToStartTimes_.get(x) - this.labelsToStartTimes_.get(y));
+ return displayLabels;
+ }
+
+ get possibleGroupings() {
+ for (const [key, values] of this.keysToValues_) {
+ if (values.size >= 2) continue;
+ // Remove this grouping from keysToGroupings_ if there is fewer than
+ // 2 possible values.
+ this.keysToGroupings_.delete(key);
+ }
+
+ return Array.from(this.keysToGroupings_.values());
+ }
+ }
+
+ return {
+ HistogramParameterCollector,
+ };
+});
+</script>
« no previous file with comments | « tracing/tracing/value/histogram_importer.html ('k') | tracing/tracing/value/histogram_parameter_collector_test.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698