Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 1 | <!DOCTYPE html> |
| 2 | <!-- |
| 3 | Copyright (c) 2013 The Chromium Authors. All rights reserved. |
| 4 | Use of this source code is governed by a BSD-style license that can be |
| 5 | found in the LICENSE file. |
| 6 | --> |
| 7 | |
| 8 | <link rel="import" href="/core/tracks/container_track.html"> |
| 9 | <link rel="import" href="/core/tracks/slice_track.html"> |
| 10 | <link rel="import" href="/core/filter.html"> |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 11 | <link rel="import" href="/base/ui.html"> |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 12 | <link rel="import" href="/model/model.html"> |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 13 | |
| 14 | <script> |
| 15 | 'use strict'; |
| 16 | |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 17 | tr.exportTo('tr.c.tracks', function() { |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 18 | |
| 19 | /** |
| 20 | * Visualizes a Cpu using a series of of SliceTracks. |
| 21 | * @constructor |
| 22 | */ |
| 23 | var CpuTrack = |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 24 | tr.b.ui.define('cpu-track', tr.c.tracks.ContainerTrack); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 25 | CpuTrack.prototype = { |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 26 | __proto__: tr.c.tracks.ContainerTrack.prototype, |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 27 | |
| 28 | decorate: function(viewport) { |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 29 | tr.c.tracks.ContainerTrack.prototype.decorate.call(this, viewport); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 30 | this.classList.add('cpu-track'); |
Chris Craik | 1983215 | 2015-04-16 15:43:38 -0700 | [diff] [blame] | 31 | this.detailedMode_ = true; |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 32 | }, |
| 33 | |
| 34 | get cpu() { |
| 35 | return this.cpu_; |
| 36 | }, |
| 37 | |
| 38 | set cpu(cpu) { |
| 39 | this.cpu_ = cpu; |
| 40 | this.updateContents_(); |
| 41 | }, |
| 42 | |
Chris Craik | 1983215 | 2015-04-16 15:43:38 -0700 | [diff] [blame] | 43 | get detailedMode() { |
| 44 | return this.detailedMode_; |
| 45 | }, |
| 46 | |
| 47 | set detailedMode(detailedMode) { |
| 48 | this.detailedMode_ = detailedMode; |
| 49 | this.updateContents_(); |
| 50 | }, |
| 51 | |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 52 | get tooltip() { |
| 53 | return this.tooltip_; |
| 54 | }, |
| 55 | |
| 56 | set tooltip(value) { |
| 57 | this.tooltip_ = value; |
| 58 | this.updateContents_(); |
| 59 | }, |
| 60 | |
| 61 | get hasVisibleContent() { |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame] | 62 | if (this.cpu_ === undefined) |
| 63 | return false; |
| 64 | var cpu = this.cpu_; |
| 65 | if (cpu.slices.length) |
| 66 | return true; |
| 67 | if (cpu.samples && cpu.samples.length) |
| 68 | return true; |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 69 | if (tr.b.dictionaryLength(cpu.counters) > 0) |
Chris Craik | 44c2820 | 2015-05-12 17:25:16 -0700 | [diff] [blame] | 70 | return true; |
| 71 | return false; |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 72 | }, |
| 73 | |
| 74 | updateContents_: function() { |
| 75 | this.detach(); |
| 76 | if (!this.cpu_) |
| 77 | return; |
| 78 | var slices = this.cpu_.slices; |
| 79 | if (slices.length) { |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 80 | var track = new tr.c.tracks.SliceTrack(this.viewport); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 81 | track.slices = slices; |
| 82 | track.heading = this.cpu_.userFriendlyName + ':'; |
| 83 | this.appendChild(track); |
| 84 | } |
| 85 | |
Chris Craik | 1983215 | 2015-04-16 15:43:38 -0700 | [diff] [blame] | 86 | if (this.detailedMode_) { |
| 87 | this.appendSamplesTracks_(); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 88 | |
Chris Craik | 1983215 | 2015-04-16 15:43:38 -0700 | [diff] [blame] | 89 | for (var counterName in this.cpu_.counters) { |
| 90 | var counter = this.cpu_.counters[counterName]; |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 91 | track = new tr.c.tracks.CounterTrack(this.viewport); |
Chris Craik | 1983215 | 2015-04-16 15:43:38 -0700 | [diff] [blame] | 92 | track.heading = this.cpu_.userFriendlyName + ' ' + |
| 93 | counter.name + ':'; |
| 94 | track.counter = counter; |
| 95 | this.appendChild(track); |
| 96 | } |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 97 | } |
| 98 | }, |
| 99 | |
| 100 | appendSamplesTracks_: function() { |
| 101 | var samples = this.cpu_.samples; |
| 102 | if (samples === undefined || samples.length === 0) |
| 103 | return; |
| 104 | var samplesByTitle = {}; |
| 105 | samples.forEach(function(sample) { |
| 106 | if (samplesByTitle[sample.title] === undefined) |
| 107 | samplesByTitle[sample.title] = []; |
| 108 | samplesByTitle[sample.title].push(sample); |
| 109 | }); |
| 110 | |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 111 | var sampleTitles = tr.b.dictionaryKeys(samplesByTitle); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 112 | sampleTitles.sort(); |
| 113 | |
| 114 | sampleTitles.forEach(function(sampleTitle) { |
| 115 | var samples = samplesByTitle[sampleTitle]; |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 116 | var samplesTrack = new tr.c.tracks.SliceTrack(this.viewport); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 117 | samplesTrack.group = this.cpu_; |
| 118 | samplesTrack.slices = samples; |
| 119 | samplesTrack.heading = this.cpu_.userFriendlyName + ': ' + |
| 120 | sampleTitle; |
| 121 | samplesTrack.tooltip = this.cpu_.userFriendlyDetails; |
| 122 | samplesTrack.selectionGenerator = function() { |
Chris Craik | 24385db | 2015-06-11 11:16:26 -0700 | [diff] [blame^] | 123 | var selection = new tr.c.Selection(); |
Chris Craik | b122baf | 2015-03-05 13:58:42 -0800 | [diff] [blame] | 124 | for (var i = 0; i < samplesTrack.slices.length; i++) { |
| 125 | selection.push(samplesTrack.slices[i]); |
| 126 | } |
| 127 | return selection; |
| 128 | }; |
| 129 | this.appendChild(samplesTrack); |
| 130 | }, this); |
| 131 | } |
| 132 | }; |
| 133 | |
| 134 | return { |
| 135 | CpuTrack: CpuTrack |
| 136 | }; |
| 137 | }); |
| 138 | </script> |