OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <!-- | 2 <!-- |
3 Copyright 2017 The Chromium Authors. All rights reserved. | 3 Copyright 2017 The Chromium Authors. All rights reserved. |
4 Use of this source code is governed by a BSD-style license that can be | 4 Use of this source code is governed by a BSD-style license that can be |
5 found in the LICENSE file. | 5 found in the LICENSE file. |
6 --> | 6 --> |
7 | 7 |
8 <link rel="import" href="/tracing/value/histogram_set.html"> | 8 <link rel="import" href="/tracing/value/histogram_set.html"> |
9 | 9 |
10 <script> | 10 <script> |
11 'use strict'; | 11 'use strict'; |
12 tr.exportTo('tr.v', function() { | 12 tr.exportTo('tr.v', function() { |
13 function deleteMergedToDiagnostics(histogramArrayMap) { | |
14 for (const [name, histograms] of histogramArrayMap) { | |
15 if (histograms instanceof Array) { | |
16 for (const histogram of histograms) { | |
17 histogram.diagnostics.delete(tr.v.d.RESERVED_NAMES.MERGED_TO); | |
18 } | |
19 } else if (histograms instanceof Map) { | |
20 deleteMergedToDiagnostics(histograms); | |
21 } | |
22 } | |
23 } | |
24 | |
25 /* | 13 /* |
26 * See also HistogramSet.groupHistogramsRecursively(). | 14 * See also HistogramSet.groupHistogramsRecursively(). |
27 * See also tr.v.ui.HistogramSetTableRow. | 15 * See also tr.v.ui.HistogramSetTableRow. |
28 */ | 16 */ |
29 class HistogramSetHierarchy { | 17 class HistogramSetHierarchy { |
30 /** | 18 /** |
31 * @param {string} name | 19 * @param {string} name |
32 */ | 20 */ |
33 constructor(name) { | 21 constructor(name) { |
34 this.name = name; | 22 this.name = name; |
(...skipping 28 matching lines...) Expand all Loading... |
63 for (const row of HistogramSetHierarchy.walkAll(rootRows)) { | 51 for (const row of HistogramSetHierarchy.walkAll(rootRows)) { |
64 for (const hist of row.columns.values()) { | 52 for (const hist of row.columns.values()) { |
65 if (!(hist instanceof tr.v.Histogram)) continue; | 53 if (!(hist instanceof tr.v.Histogram)) continue; |
66 histograms.addHistogram(hist); | 54 histograms.addHistogram(hist); |
67 } | 55 } |
68 } | 56 } |
69 | 57 |
70 histograms.deduplicateDiagnostics(); | 58 histograms.deduplicateDiagnostics(); |
71 | 59 |
72 for (const row of HistogramSetHierarchy.walkAll(rootRows)) { | 60 for (const row of HistogramSetHierarchy.walkAll(rootRows)) { |
73 for (const [name, hist] of row.columns) { | |
74 if (!(hist instanceof tr.v.Histogram)) continue; | |
75 if (!row.mergeRelationshipsForColumn_.get(name)) continue; | |
76 hist.diagnostics.mergeRelationships(hist); | |
77 } | |
78 } | |
79 | |
80 // Delete "mergedTo" diagnostics from the original Histograms, or else | |
81 // they'll accumulate as the user re-groups them, and slow down future | |
82 // mergeRelationships operations. | |
83 deleteMergedToDiagnostics(histogramArrayMap); | |
84 | |
85 for (const row of HistogramSetHierarchy.walkAll(rootRows)) { | |
86 row.maybeRebin_(); | 61 row.maybeRebin_(); |
87 } | 62 } |
88 | 63 |
89 return rootRows; | 64 return rootRows; |
90 } | 65 } |
91 | 66 |
92 maybeRebin_() { | 67 maybeRebin_() { |
93 // if all of |this| row's columns are single-bin, then re-bin all of them. | 68 // if all of |this| row's columns are single-bin, then re-bin all of them. |
94 const dataRange = new tr.b.math.Range(); | 69 const dataRange = new tr.b.math.Range(); |
95 for (const hist of this.columns.values()) { | 70 for (const hist of this.columns.values()) { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
147 row.mergeRelationshipsForColumn_.set(columnName, true); | 122 row.mergeRelationshipsForColumn_.set(columnName, true); |
148 continue; | 123 continue; |
149 } | 124 } |
150 | 125 |
151 if (existing instanceof tr.v.HistogramSet) { | 126 if (existing instanceof tr.v.HistogramSet) { |
152 // There have already been unmergeable histograms. | 127 // There have already been unmergeable histograms. |
153 existing.addHistogram(histogram); | 128 existing.addHistogram(histogram); |
154 continue; | 129 continue; |
155 } | 130 } |
156 | 131 |
157 if (!existing.canAddHistogram(histogram)) { | |
158 // Remember all of the original unmergeable Histograms so that | |
159 // filter() can keep the rows that match the given HistogramSet even | |
160 // if the rows will only be able to display (unmergeable). | |
161 const unmergeableHistograms = new tr.v.HistogramSet([histogram]); | |
162 const mergedFrom = existing.diagnostics.get( | |
163 tr.v.d.RESERVED_NAMES.MERGED_FROM); | |
164 if (mergedFrom !== undefined) { | |
165 for (const [unusedName, origHist] of mergedFrom) { | |
166 unmergeableHistograms.addHistogram(origHist); | |
167 } | |
168 } | |
169 row.columns.set(columnName, unmergeableHistograms); | |
170 continue; | |
171 } | |
172 | |
173 if (existing.name !== histogram.name) { | 132 if (existing.name !== histogram.name) { |
174 // It won't make sense to merge relationships for this merged | 133 // It won't make sense to merge relationships for this merged |
175 // Histogram. | 134 // Histogram. |
176 row.mergeRelationshipsForColumn_.set(name, false); | 135 row.mergeRelationshipsForColumn_.set(name, false); |
177 } | 136 } |
178 | 137 |
179 existing.addHistogram(histogram); | 138 existing.addHistogram(histogram); |
180 } | 139 } |
181 } | 140 } |
182 | 141 |
(...skipping 21 matching lines...) Expand all Loading... |
204 rootRows.push(row); | 163 rootRows.push(row); |
205 } else { | 164 } else { |
206 const parentRow = hierarchy[hierarchy.length - 1]; | 165 const parentRow = hierarchy[hierarchy.length - 1]; |
207 parentRow.subRows.push(row); | 166 parentRow.subRows.push(row); |
208 } | 167 } |
209 } | 168 } |
210 } | 169 } |
211 } | 170 } |
212 | 171 |
213 /** | 172 /** |
214 * Clones and filters |rows| to contain only |histograms|. | 173 * Clones and filters |rows| to contain only |histogramNames|. |
215 * | 174 * |
216 * @param {!Array.<HistogramSetHierarchy>} rows | 175 * @param {!Array.<HistogramSetHierarchy>} rows |
217 * @param {!tr.v.HistogramSet} histograms | 176 * @param {!Set.<string>} histogramNames |
218 * @returns {!Array.<HistogramSetHierarchy>} | 177 * @returns {!Array.<HistogramSetHierarchy>} |
219 */ | 178 */ |
220 static filter(rows, histograms) { | 179 static filter(rows, histogramNames) { |
221 const results = []; | 180 const results = []; |
222 for (const row of rows) { | 181 for (const row of rows) { |
223 let filteredSubRows = []; | 182 let filteredSubRows = []; |
224 if (row.subRows.length > 0) { | 183 if (row.subRows.length > 0) { |
225 // This is a branch row. Drop it if all of its subrows were dropped. | 184 // This is a branch row. Drop it if all of its subrows were dropped. |
226 filteredSubRows = HistogramSetHierarchy.filter( | 185 filteredSubRows = HistogramSetHierarchy.filter( |
227 row.subRows, histograms); | 186 row.subRows, histogramNames); |
228 if (filteredSubRows.length === 0) continue; | 187 if (filteredSubRows.length === 0) continue; |
229 } else { | 188 } else { |
230 // This is a leaf row. Drop it if none of the Histograms in | 189 // This is a leaf row. Drop it if none of the Histograms in |
231 // |row.columns| were merged from any in |histograms|. | 190 // |row.columns| are named in |histogramNames|. |
232 let found = false; | 191 let found = false; |
233 for (const testHist of row.columns.values()) { | 192 for (const testHist of row.columns.values()) { |
234 if (testHist instanceof tr.v.HistogramSet) { | |
235 // Keep this unmergeable cell if it was merged from any of | |
236 // |histograms|. | |
237 for (const origHist of testHist) { | |
238 if (histograms.lookupHistogram(origHist.guid) !== undefined) { | |
239 found = true; | |
240 break; | |
241 } | |
242 } | |
243 if (found) break; | |
244 | |
245 continue; | |
246 } | |
247 | |
248 if (!(testHist instanceof tr.v.Histogram)) { | 193 if (!(testHist instanceof tr.v.Histogram)) { |
249 throw new Error( | 194 throw new Error( |
250 'Cells can only contain Histogram or HistogramSet'); | 195 'Cells can only contain Histogram or HistogramSet'); |
251 } | 196 } |
252 | 197 |
253 if (histograms.lookupHistogram(testHist.guid) !== undefined) { | 198 if (histogramNames.has(testHist.name)) { |
254 found = true; | 199 found = true; |
255 break; | 200 break; |
256 } | 201 } |
257 | |
258 const mergedFrom = testHist.diagnostics.get( | |
259 tr.v.d.RESERVED_NAMES.MERGED_FROM); | |
260 if (mergedFrom !== undefined) { | |
261 for (const [unusedName, origHist] of mergedFrom) { | |
262 if (histograms.lookupHistogram(origHist.guid) !== undefined) { | |
263 found = true; | |
264 break; | |
265 } | |
266 } | |
267 } | |
268 if (found) break; | |
269 } | 202 } |
270 // If none of the Histograms in |row| were merged from any of | |
271 // |histograms|, then drop this row. | |
272 if (!found) continue; | 203 if (!found) continue; |
273 } | 204 } |
274 | 205 |
275 const clone = new HistogramSetHierarchy(row.name); | 206 const clone = new HistogramSetHierarchy(row.name); |
276 clone.description = row.description; | 207 clone.description = row.description; |
277 clone.depth = row.depth; | 208 clone.depth = row.depth; |
278 clone.subRows = filteredSubRows; | 209 clone.subRows = filteredSubRows; |
279 // Don't need to clone Histograms. | 210 // Don't need to clone Histograms. |
280 clone.columns = row.columns; | 211 clone.columns = row.columns; |
281 results.push(clone); | 212 results.push(clone); |
282 } | 213 } |
283 return results; | 214 return results; |
284 } | 215 } |
285 } | 216 } |
286 | 217 |
287 return { | 218 return { |
288 HistogramSetHierarchy, | 219 HistogramSetHierarchy, |
289 }; | 220 }; |
290 }); | 221 }); |
291 </script> | 222 </script> |
OLD | NEW |