| <!DOCTYPE html> |
| <!-- |
| Copyright 2015 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/base/category_util.html"> |
| <link rel="import" href="/tracing/ui/base/table.html"> |
| <link rel="import" href="/tracing/ui/side_panel/side_panel.html"> |
| |
| <polymer-element name='tr-ui-e-s-category-summary-side-panel' |
| extends='tr-ui-side-panel'> |
| <template> |
| <style> |
| :host { |
| display: block; |
| width: 450px; |
| overflow-x: auto; |
| } |
| </style> |
| |
| <tr-ui-b-table id="table"></tr-ui-b-table> |
| </template> |
| |
| <script> |
| 'use strict'; |
| |
| Polymer({ |
| ready: function() { |
| }, |
| |
| get model() { |
| return this.model_; |
| }, |
| |
| set model(model) { |
| this.model_ = model; |
| this.updateContents_(); |
| }, |
| |
| get listeningToKeys() { |
| return false; |
| }, |
| |
| set selection(selection) { |
| }, |
| |
| set rangeOfInterest(rangeOfInterest) { |
| }, |
| |
| updateContents_: function() { |
| this.$.table.tableColumns = [ |
| { |
| title: 'Category / Title', |
| value: function(row) { |
| return row.title; |
| } |
| }, |
| { |
| title: 'Events', |
| textAlign: 'right', |
| value: function(row) { |
| return row.count; |
| } |
| } |
| ]; |
| |
| if (this.model_ === undefined) { |
| this.$.table.tableRows = []; |
| return; |
| } |
| |
| var categories = {}; |
| |
| this.model_.iterateAllEvents(function handleEvent(event) { |
| if (!(event instanceof tr.model.Slice) && |
| !(event instanceof tr.model.AsyncSlice) && |
| !(event instanceof tr.model.InstantEvent) && |
| !(event instanceof tr.model.FlowEvent)) |
| return; |
| |
| tr.b.getCategoryParts(event.category).forEach(function(category) { |
| if (categories[category] === undefined) { |
| categories[category] = {}; |
| } |
| var titleCounts = categories[category]; |
| if (titleCounts[event.title] === undefined) { |
| titleCounts[event.title] = 0; |
| } |
| titleCounts[event.title] += 1; |
| }); |
| }); |
| |
| function compareCounts(a, b) { |
| return b.count - a.count; |
| } |
| |
| var rows = []; |
| for (var category in categories) { |
| var categoryRow = { |
| title: category, |
| subRows: [], |
| count: 0 |
| }; |
| rows.push(categoryRow); |
| |
| var titleCounts = categories[category]; |
| for (var title in titleCounts) { |
| var count = titleCounts[title]; |
| categoryRow.count += count; |
| categoryRow.subRows.push({ |
| title: title, |
| count: count |
| }); |
| } |
| categoryRow.subRows.sort(compareCounts); |
| } |
| rows.sort(compareCounts); |
| |
| this.$.table.tableRows = rows; |
| }, |
| |
| supportsModel: function(m) { |
| if (m == undefined) { |
| return { |
| supported: false, |
| reason: 'Unknown tracing model' |
| }; |
| } |
| |
| return { |
| supported: true |
| }; |
| }, |
| |
| get textLabel() { |
| return 'Categories'; |
| } |
| }); |
| </script> |
| </polymer-element> |