Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library isolate_profile_element; | 5 library isolate_profile_element; |
| 6 | 6 |
| 7 import 'dart:html'; | 7 import 'dart:html'; |
| 8 import 'observatory_element.dart'; | 8 import 'observatory_element.dart'; |
| 9 import 'package:logging/logging.dart'; | 9 import 'package:logging/logging.dart'; |
| 10 import 'package:observatory/service.dart'; | 10 import 'package:observatory/service.dart'; |
| 11 import 'package:observatory/app.dart'; | 11 import 'package:observatory/app.dart'; |
| 12 import 'package:polymer/polymer.dart'; | 12 import 'package:polymer/polymer.dart'; |
| 13 | 13 |
| 14 class ProfileCodeTrieNodeTreeRow extends TableTreeRow { | 14 class ProfileCodeTrieNodeTreeRow extends TableTreeRow { |
| 15 final ServiceMap profile; | 15 final ServiceMap profile; |
| 16 @reflectable final CodeTrieNode root; | 16 @reflectable final CodeTrieNode root; |
| 17 @reflectable final CodeTrieNode node; | 17 @reflectable final CodeTrieNode node; |
| 18 @reflectable Code get code => node.code; | 18 @reflectable Code get code => node.code; |
| 19 | 19 |
| 20 static String formatPercent(num a, num total) { | 20 @reflectable String tipKind = ''; |
| 21 var percent = 100.0 * (a / total); | 21 @reflectable String tipTicks = ''; |
| 22 return '${percent.toStringAsFixed(2)}%'; | 22 @reflectable String tipTime = ''; |
|
turnidge
2014/04/17 20:18:54
Is the popup tip something that should be in a cus
Cutch
2014/04/17 22:12:39
I'd like that at some point.
| |
| 23 } | |
| 24 | 23 |
| 25 ProfileCodeTrieNodeTreeRow(this.profile, this.root, this.node, | 24 ProfileCodeTrieNodeTreeRow(this.profile, this.root, this.node, |
| 26 ProfileCodeTrieNodeTreeRow parent) | 25 ProfileCodeTrieNodeTreeRow parent) |
| 27 : super(parent) { | 26 : super(parent) { |
| 28 assert(root != null); | 27 assert(root != null); |
| 29 assert(node != null); | 28 assert(node != null); |
| 30 var totalSamples = root.count; | 29 var totalSamples = root.count; |
| 31 // When the row is created, fill out the columns. | 30 tipTicks = '${node.count}'; |
| 32 if (parent == null) { | 31 var period = profile['period']; |
| 33 columns.add(formatPercent(node.count, root.count)); | 32 var MICROSECONDS_PER_SECOND = 1000000.0; |
| 33 var seconds = (period * node.count) / MICROSECONDS_PER_SECOND; // seconds | |
| 34 tipTime = Utils.formatTimePrecise(seconds); | |
| 35 if (code.kind == CodeKind.Tag) { | |
| 36 columns.add(Utils.formatPercent(node.count, root.count)); | |
| 37 columns.add(Utils.formatPercent(node.count, root.count)); | |
| 38 tipKind = 'Tag (category)'; | |
| 34 } else { | 39 } else { |
| 35 columns.add(formatPercent(node.count, parent.node.count)); | 40 if (code.kind == CodeKind.Collected) { |
| 41 tipKind = 'Code is gone (collected)'; | |
| 42 } else if (code.kind == CodeKind.Reused) { | |
| 43 tipKind = 'Code is gone (collected then overwritten)'; | |
| 44 } else { | |
| 45 tipKind = '${code.kind} (Function)'; | |
| 46 } | |
| 47 if (parent == null) { | |
| 48 columns.add(Utils.formatPercent(node.count, root.count)); | |
| 49 } else { | |
| 50 columns.add(Utils.formatPercent(node.count, parent.node.count)); | |
| 51 } | |
| 52 columns.add(Utils.formatPercent(node.code.exclusiveTicks, totalSamples)); | |
| 36 } | 53 } |
| 37 columns.add(formatPercent(node.code.exclusiveTicks, totalSamples)); | |
| 38 } | 54 } |
| 39 | 55 |
| 40 bool shouldDisplayChild(CodeTrieNode childNode, double threshold) { | 56 bool shouldDisplayChild(CodeTrieNode childNode, double threshold) { |
| 41 return ((childNode.count / node.count) > threshold) || | 57 return ((childNode.count / node.count) > threshold) || |
| 42 ((childNode.code.exclusiveTicks / root.count) > threshold); | 58 ((childNode.code.exclusiveTicks / root.count) > threshold); |
| 43 } | 59 } |
| 44 | 60 |
| 45 void onShow() { | 61 void onShow() { |
| 46 var threshold = profile['threshold']; | 62 var threshold = profile['threshold']; |
| 47 if (children.length > 0) { | 63 if (children.length > 0) { |
| 48 // Child rows already created. | 64 // Child rows already created. |
| 49 return; | 65 return; |
| 50 } | 66 } |
| 51 for (var childNode in node.children) { | 67 for (var childNode in node.children) { |
| 52 if (!shouldDisplayChild(childNode, threshold)) { | 68 if (!shouldDisplayChild(childNode, threshold)) { |
| 53 continue; | 69 continue; |
| 54 } | 70 } |
| 55 var row = new ProfileCodeTrieNodeTreeRow(profile, root, childNode, this); | 71 var row = new ProfileCodeTrieNodeTreeRow(profile, root, childNode, this); |
| 56 children.add(row); | 72 children.add(row); |
| 57 } | 73 } |
| 58 } | 74 } |
| 59 | 75 |
| 60 void onHide() { | 76 void onHide() { |
| 61 } | 77 } |
| 62 } | 78 } |
| 63 | 79 |
| 64 class ProfileCallerTreeRow extends TableTreeRow { | |
| 65 final ServiceMap profile; | |
| 66 @reflectable final Code code; | |
| 67 | |
| 68 static String formatPercent(num a, num total) { | |
| 69 var percent = 100.0 * (a / total); | |
| 70 return '${percent.toStringAsFixed(2)}%'; | |
| 71 } | |
| 72 | |
| 73 ProfileCallerTreeRow(this.profile, this.code, ProfileCallerTreeRow parent) : | |
| 74 super(parent) { | |
| 75 assert(profile != null); | |
| 76 assert(code != null); | |
| 77 var totalSamples = profile['samples']; | |
| 78 // When the row is created, fill out the columns. | |
| 79 if (parent == null) { | |
| 80 var root = profile.isolate.tagRoot(); | |
| 81 var totalAttributedCalls = root.callersCount(code); | |
| 82 var totalParentCalls = root.sumCallersCount(); | |
| 83 columns.add(formatPercent(totalAttributedCalls, totalParentCalls)); | |
| 84 } else { | |
| 85 var totalAttributedCalls = parent.code.callersCount(code); | |
| 86 var totalParentCalls = parent.code.sumCallersCount(); | |
| 87 columns.add(formatPercent(totalAttributedCalls, totalParentCalls)); | |
| 88 } | |
| 89 columns.add(formatPercent(code.exclusiveTicks, totalSamples)); | |
| 90 } | |
| 91 | |
| 92 bool shouldDisplayChild(CodeCallCount childNode, totalSamples, | |
| 93 double threshold) { | |
| 94 var callerPercent = code.callersCount(childNode.code) / | |
| 95 code.sumCallersCount(); | |
| 96 return (callerPercent > threshold) || | |
| 97 ((childNode.code.exclusiveTicks / totalSamples) > threshold); | |
| 98 } | |
| 99 | |
| 100 void onShow() { | |
| 101 var threshold = profile['threshold']; | |
| 102 var totalSamples = profile['samples']; | |
| 103 if (children.length > 0) { | |
| 104 // Child rows already created. | |
| 105 return; | |
| 106 } | |
| 107 for (var codeCaller in code.callers) { | |
| 108 if (!shouldDisplayChild(codeCaller, totalSamples, threshold)) { | |
| 109 continue; | |
| 110 } | |
| 111 var row = new ProfileCallerTreeRow(profile, codeCaller.code, this); | |
| 112 children.add(row); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 void onHide() { | |
| 117 } | |
| 118 } | |
| 119 | |
| 120 /// Displays an IsolateProfile | 80 /// Displays an IsolateProfile |
| 121 @CustomTag('isolate-profile') | 81 @CustomTag('isolate-profile') |
| 122 class IsolateProfileElement extends ObservatoryElement { | 82 class IsolateProfileElement extends ObservatoryElement { |
| 123 IsolateProfileElement.created() : super.created(); | 83 IsolateProfileElement.created() : super.created(); |
| 124 @published ServiceMap profile; | 84 @published ServiceMap profile; |
| 125 @observable bool callGraphChecked; | |
| 126 @observable bool hideTagsChecked; | 85 @observable bool hideTagsChecked; |
| 127 @observable String sampleCount = ''; | 86 @observable String sampleCount = ''; |
| 128 @observable String refreshTime = ''; | 87 @observable String refreshTime = ''; |
| 129 @observable String sampleRate = ''; | 88 @observable String sampleRate = ''; |
| 130 @observable String sampleDepth = ''; | 89 @observable String sampleDepth = ''; |
| 131 @observable String displayCutoff = ''; | 90 @observable String displayCutoff = ''; |
| 132 @reflectable double displayThreshold = 0.0001; // 0.5%. | 91 @observable String timeSpan = ''; |
| 92 @reflectable double displayThreshold = 0.0002; // 0.02%. | |
| 133 | 93 |
| 134 final _id = '#tableTree'; | 94 final _id = '#tableTree'; |
| 135 TableTree tree; | 95 TableTree tree; |
| 136 | 96 |
| 137 static const MICROSECONDS_PER_SECOND = 1000000.0; | 97 static const MICROSECONDS_PER_SECOND = 1000000.0; |
| 138 | 98 |
| 139 void profileChanged(oldValue) { | 99 void profileChanged(oldValue) { |
| 140 if (profile == null) { | 100 if (profile == null) { |
| 141 return; | 101 return; |
| 142 } | 102 } |
| 143 var totalSamples = profile['samples']; | 103 var totalSamples = profile['samples']; |
| 144 var now = new DateTime.now(); | 104 var now = new DateTime.now(); |
| 145 sampleCount = totalSamples.toString(); | 105 sampleCount = totalSamples.toString(); |
| 146 refreshTime = now.toString(); | 106 refreshTime = now.toString(); |
| 147 sampleDepth = profile['depth'].toString(); | 107 sampleDepth = profile['depth'].toString(); |
| 148 var period = profile['period']; | 108 var period = profile['period']; |
| 149 sampleRate = (MICROSECONDS_PER_SECOND / period).toStringAsFixed(0); | 109 sampleRate = (MICROSECONDS_PER_SECOND / period).toStringAsFixed(0); |
| 110 timeSpan = formatTime(profile['timeSpan']); | |
| 150 displayCutoff = '${(displayThreshold * 100.0).toString()}%'; | 111 displayCutoff = '${(displayThreshold * 100.0).toString()}%'; |
| 151 profile.isolate.processProfile(profile); | 112 profile.isolate.processProfile(profile); |
| 152 profile['threshold'] = displayThreshold; | 113 profile['threshold'] = displayThreshold; |
| 153 _update(); | 114 _update(); |
| 154 } | 115 } |
| 155 | 116 |
| 156 void callGraphCheckedChanged(oldValue) { | |
| 157 _update(); | |
| 158 } | |
| 159 | |
| 160 | 117 |
| 161 void enteredView() { | 118 void enteredView() { |
| 162 tree = new TableTree(); | 119 tree = new TableTree(); |
| 163 _update(); | 120 _update(); |
| 164 } | 121 } |
| 165 | 122 |
| 166 void hideTagsCheckedChanged(oldValue) { | 123 void hideTagsCheckedChanged(oldValue) { |
| 167 refresh(null); | 124 refresh(null); |
| 168 } | 125 } |
| 169 | 126 |
| 170 void refresh(var done) { | 127 void refresh(var done) { |
| 171 var request = 'profile'; | 128 var request = 'profile'; |
| 172 if ((hideTagsChecked != null) && hideTagsChecked) { | 129 if ((hideTagsChecked != null) && hideTagsChecked) { |
| 173 request += '?tags=hide'; | 130 request += '?tags=hide'; |
| 174 } | 131 } |
| 175 profile.isolate.get(request).then((ServiceMap m) { | 132 profile.isolate.get(request).then((ServiceMap m) { |
| 176 // Assert we got back the a profile. | 133 // Assert we got back the a profile. |
| 177 assert(m.serviceType == 'Profile'); | 134 assert(m.serviceType == 'Profile'); |
| 178 profile = m; | 135 profile = m; |
| 179 }).whenComplete(done); | 136 }).whenComplete(done); |
| 180 } | 137 } |
| 181 | 138 |
| 182 void _update() { | 139 void _update() { |
| 183 if (profile == null) { | 140 if (profile == null) { |
| 184 return; | 141 return; |
| 185 } | 142 } |
| 186 _buildTree(); | 143 _buildTree(); |
| 187 } | 144 } |
| 188 | 145 |
| 189 void _buildCallersTree() { | |
| 190 assert(profile != null); | |
| 191 var root = profile.isolate.tagRoot(); | |
| 192 if (root == null) { | |
| 193 Logger.root.warning('No profile root tag.'); | |
| 194 } | |
| 195 try { | |
| 196 tree.initialize(new ProfileCallerTreeRow(profile, root, null)); | |
| 197 } catch (e, stackTrace) { | |
| 198 Logger.root.warning('_buildCallersTree', e, stackTrace); | |
| 199 } | |
| 200 | |
| 201 notifyPropertyChange(#tree, null, tree); | |
| 202 } | |
| 203 | |
| 204 void _buildStackTree() { | 146 void _buildStackTree() { |
| 205 var root = profile.isolate.profileTrieRoot; | 147 var root = profile.isolate.profileTrieRoot; |
| 206 if (root == null) { | 148 if (root == null) { |
| 207 Logger.root.warning('No profile trie root.'); | 149 return; |
| 208 } | 150 } |
| 209 try { | 151 try { |
| 210 tree.initialize( | 152 tree.initialize( |
| 211 new ProfileCodeTrieNodeTreeRow(profile, root, root, null)); | 153 new ProfileCodeTrieNodeTreeRow(profile, root, root, null)); |
| 212 } catch (e, stackTrace) { | 154 } catch (e, stackTrace) { |
| 213 Logger.root.warning('_buildStackTree', e, stackTrace); | 155 Logger.root.warning('_buildStackTree', e, stackTrace); |
| 214 } | 156 } |
| 215 notifyPropertyChange(#tree, null, tree); | 157 notifyPropertyChange(#tree, null, tree); |
| 216 } | 158 } |
| 217 | 159 |
| 218 void _buildTree() { | 160 void _buildTree() { |
| 219 if ((callGraphChecked) != null && callGraphChecked) { | 161 _buildStackTree(); |
| 220 _buildCallersTree(); | |
| 221 } else { | |
| 222 _buildStackTree(); | |
| 223 } | |
| 224 } | 162 } |
| 225 | 163 |
| 226 @observable String padding(TableTreeRow row) { | 164 @observable String padding(TableTreeRow row) { |
| 227 return 'padding-left: ${row.depth * 16}px;'; | 165 return 'padding-left: ${row.depth * 16}px;'; |
| 228 } | 166 } |
| 229 | 167 |
| 230 @observable String coloring(TableTreeRow row) { | 168 @observable String coloring(TableTreeRow row) { |
| 231 const colors = const ['active', 'success', 'warning', 'danger', 'info']; | 169 const colors = const ['color0', 'color1', 'color2', 'color4', 'color5', |
|
turnidge
2014/04/17 20:18:54
What happened to color3?
We should probably name
Cutch
2014/04/17 22:12:39
Fixed.
| |
| 232 var index = row.depth % colors.length; | 170 'color6', 'color7', 'color8']; |
| 171 var d = row.depth - 1; | |
| 172 var index = d % colors.length; | |
| 233 return colors[index]; | 173 return colors[index]; |
| 234 } | 174 } |
| 235 | 175 |
| 236 @observable void toggleExpanded(Event e, var detail, Element target) { | 176 @observable void toggleExpanded(Event e, var detail, Element target) { |
| 237 // We only want to expand a tree row if the target of the click is | 177 // We only want to expand a tree row if the target of the click is |
| 238 // the table cell (passed in as target) or the span containing the | 178 // the table cell (passed in as target) or the span containing the |
| 239 // expander symbol (#expand). | 179 // expander symbol (#expand). |
| 240 if ((e.target.id != 'expand') && (e.target != target)) { | 180 if ((e.target.id != 'expand') && (e.target != target)) { |
| 241 // Target of click was not the expander span or the table cell. | 181 // Target of click was not the expander span or the table cell. |
| 242 return; | 182 return; |
| 243 } | 183 } |
| 244 var row = target.parent; | 184 var row = target.parent; |
| 245 if (row is TableRowElement) { | 185 if (row is TableRowElement) { |
| 246 // Subtract 1 to get 0 based indexing. | 186 // Subtract 1 to get 0 based indexing. |
| 247 tree.toggle(row.rowIndex - 1); | 187 try { |
| 188 tree.toggle(row.rowIndex - 1); | |
| 189 } catch (e, stackTrace) { | |
| 190 Logger.root.warning('toggleExpanded', e, stackTrace); | |
| 191 } | |
| 248 } | 192 } |
| 249 } | 193 } |
| 250 } | 194 } |
| OLD | NEW |