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 'package:logging/logging.dart'; | 8 import 'package:logging/logging.dart'; |
| 9 import 'package:observatory/observatory.dart'; | |
| 9 import 'package:polymer/polymer.dart'; | 10 import 'package:polymer/polymer.dart'; |
| 10 import 'observatory_element.dart'; | 11 import 'observatory_element.dart'; |
| 12 import 'table_tree.dart'; | |
| 13 | |
| 14 class ProfileTreeRow extends TableTreeRow { | |
| 15 final Isolate isolate; | |
| 16 final Code code; | |
| 17 ProfileTreeRow(this.isolate, this.code, ProfileTreeRow parent) : | |
| 18 super(parent) { | |
| 19 // When the row is created, fill out the columns. | |
| 20 columns.add('${code.user_name} ${code.name}'); | |
| 21 var percent = 100.0 * | |
| 22 (code.exclusiveTicks / isolate.profile.totalSamples); | |
| 23 columns.add(percent.toStringAsFixed(2)); | |
| 24 if (parent == null) { | |
| 25 // Fill with dummy data. | |
| 26 columns.add(' '); | |
| 27 } else { | |
| 28 var totalAttributedCalls = parent.code.callersCount(code); | |
| 29 var totalParentCalls = parent.code.sumCallersCount(); | |
| 30 percent = 100.0 * (totalAttributedCalls / totalParentCalls); | |
| 31 columns.add(percent.toStringAsFixed(2)); | |
| 32 } | |
| 33 percent = 100.0 * | |
| 34 (code.inclusiveTicks / isolate.profile.totalSamples); | |
| 35 columns.add(percent.toStringAsFixed(2)); | |
| 36 } | |
| 37 | |
| 38 void onShow() { | |
| 39 if (children.length > 0) { | |
| 40 // Child rows already created. | |
| 41 return; | |
| 42 } | |
| 43 // Create child rows on demand. | |
| 44 code.callers.forEach((CodeCaller codeCaller) { | |
| 45 var row = new ProfileTreeRow(isolate, codeCaller.code_or_index, this); | |
| 46 children.add(row); | |
| 47 }); | |
| 48 } | |
| 49 | |
| 50 void onHide() { | |
| 51 } | |
| 52 } | |
| 11 | 53 |
| 12 /// Displays an IsolateProfile | 54 /// Displays an IsolateProfile |
| 13 @CustomTag('isolate-profile') | 55 @CustomTag('isolate-profile') |
| 14 class IsolateProfileElement extends ObservatoryElement { | 56 class IsolateProfileElement extends ObservatoryElement { |
| 15 IsolateProfileElement.created() : super.created(); | 57 IsolateProfileElement.created() : super.created(); |
| 16 @observable int methodCountSelected = 0; | 58 @observable int methodCountSelected = 0; |
| 17 final List methodCounts = [10, 20, 50]; | 59 final List methodCounts = [10, 20, 50]; |
| 18 @observable List topInclusiveCodes = toObservable([]); | |
| 19 @observable List topExclusiveCodes = toObservable([]); | 60 @observable List topExclusiveCodes = toObservable([]); |
| 61 final _id = '#tableTree'; | |
| 20 | 62 |
| 21 void enteredView() { | 63 void enteredView() { |
| 22 var isolateId = app.locationManager.currentIsolateId(); | 64 var isolateId = app.locationManager.currentIsolateId(); |
| 23 var isolate = app.isolateManager.getIsolate(isolateId); | 65 var isolate = app.isolateManager.getIsolate(isolateId); |
| 24 if (isolate == null) { | 66 if (isolate == null) { |
| 25 return; | 67 return; |
| 26 } | 68 } |
| 27 _refreshTopMethods(isolate); | 69 var tree = |
| 70 new TableTree(['Method', 'Exclusive', 'Caller', 'Inclusive']); | |
| 71 var tte = shadowRoot.querySelector(_id); | |
|
turnidge
2014/02/24 20:13:00
I can guess what this does, but I want to chat abo
| |
| 72 tte.tree = tree; | |
| 73 _refresh(isolate); | |
| 28 } | 74 } |
| 29 | 75 |
| 30 void _startRequest() { | 76 void _startRequest() { |
| 31 // TODO(johnmccutchan): Indicate visually. | 77 // TODO(johnmccutchan): Indicate visually. |
| 32 } | 78 } |
| 33 | 79 |
| 34 void _endRequest() { | 80 void _endRequest() { |
| 35 // TODO(johnmccutchan): Indicate visually. | 81 // TODO(johnmccutchan): Indicate visually. |
| 36 } | 82 } |
| 37 | 83 |
| 38 methodCountSelectedChanged(oldValue) {; | 84 methodCountSelectedChanged(oldValue) { |
| 39 var isolateId = app.locationManager.currentIsolateId(); | 85 var isolateId = app.locationManager.currentIsolateId(); |
| 40 var isolate = app.isolateManager.getIsolate(isolateId); | 86 var isolate = app.isolateManager.getIsolate(isolateId); |
| 41 if (isolate == null) { | 87 if (isolate == null) { |
| 42 return; | 88 return; |
| 43 } | 89 } |
| 44 _refreshTopMethods(isolate); | 90 _refresh(isolate); |
| 45 } | 91 } |
| 46 | 92 |
| 47 void refreshData(Event e, var detail, Node target) { | 93 void refreshData(Event e, var detail, Node target) { |
| 48 var isolateId = app.locationManager.currentIsolateId(); | 94 var isolateId = app.locationManager.currentIsolateId(); |
| 49 var isolate = app.isolateManager.getIsolate(isolateId); | 95 var isolate = app.isolateManager.getIsolate(isolateId); |
| 50 if (isolate == null) { | 96 if (isolate == null) { |
| 51 Logger.root.info('No isolate found.'); | 97 Logger.root.info('No isolate found.'); |
| 52 return; | 98 return; |
| 53 } | 99 } |
| 54 var request = '/$isolateId/profile'; | 100 var request = '/$isolateId/profile'; |
| 55 _startRequest(); | 101 _startRequest(); |
| 56 app.requestManager.requestMap(request).then((Map profile) { | 102 app.requestManager.requestMap(request).then((Map profile) { |
| 57 assert(profile['type'] == 'Profile'); | 103 assert(profile['type'] == 'Profile'); |
| 58 var samples = profile['samples']; | 104 var samples = profile['samples']; |
| 59 Logger.root.info('Profile contains ${samples} samples.'); | 105 Logger.root.info('Profile contains ${samples} samples.'); |
| 60 _loadProfileData(isolate, samples, profile); | 106 _loadProfileData(isolate, samples, profile); |
| 61 _endRequest(); | 107 _endRequest(); |
| 62 }).catchError((e) { | 108 }).catchError((e) { |
| 63 _endRequest(); | 109 _endRequest(); |
| 64 }); | 110 }); |
| 65 } | 111 } |
| 66 | 112 |
| 67 void _loadProfileData(Isolate isolate, int totalSamples, Map response) { | 113 void _loadProfileData(Isolate isolate, int totalSamples, Map response) { |
| 68 isolate.profile = new Profile.fromMap(isolate, response); | 114 isolate.profile = new Profile.fromMap(isolate, response); |
| 115 _refresh(isolate); | |
| 116 } | |
| 117 | |
| 118 void _refresh(Isolate isolate) { | |
| 69 _refreshTopMethods(isolate); | 119 _refreshTopMethods(isolate); |
| 120 _refreshTree(isolate); | |
| 70 } | 121 } |
| 71 | 122 |
| 123 void _refreshTree(Isolate isolate) { | |
| 124 TableTreeElement tte = shadowRoot.querySelector(_id); | |
| 125 var rootChildren = []; | |
| 126 for (var code in topExclusiveCodes) { | |
| 127 var row = new ProfileTreeRow(isolate, code, null); | |
| 128 rootChildren.add(row); | |
| 129 } | |
| 130 tte.tree.initialize(rootChildren); | |
| 131 } | |
| 132 | |
| 133 | |
| 72 void _refreshTopMethods(Isolate isolate) { | 134 void _refreshTopMethods(Isolate isolate) { |
| 73 topExclusiveCodes.clear(); | 135 topExclusiveCodes.clear(); |
| 74 topInclusiveCodes.clear(); | |
| 75 if ((isolate == null) || (isolate.profile == null)) { | 136 if ((isolate == null) || (isolate.profile == null)) { |
| 76 return; | 137 return; |
| 77 } | 138 } |
| 78 var count = methodCounts[methodCountSelected]; | 139 var count = methodCounts[methodCountSelected]; |
| 79 var topExclusive = isolate.profile.topExclusive(count); | 140 var topExclusive = isolate.profile.topExclusive(count); |
| 80 topExclusiveCodes.addAll(topExclusive); | 141 topExclusiveCodes.addAll(topExclusive); |
| 81 var topInclusive = isolate.profile.topInclusive(count); | |
| 82 topInclusiveCodes.addAll(topInclusive); | |
| 83 | |
| 84 } | |
| 85 | |
| 86 String codeTicks(Code code, bool inclusive) { | |
| 87 if (code == null) { | |
| 88 return ''; | |
| 89 } | |
| 90 return inclusive ? '${code.inclusiveTicks}' : '${code.exclusiveTicks}'; | |
| 91 } | |
| 92 | |
| 93 String codePercent(Code code, bool inclusive) { | |
| 94 if (code == null) { | |
| 95 return ''; | |
| 96 } | |
| 97 var isolateId = app.locationManager.currentIsolateId(); | |
| 98 var isolate = app.isolateManager.getIsolate(isolateId); | |
| 99 if (isolate == null) { | |
| 100 return ''; | |
| 101 } | |
| 102 var ticks = inclusive ? code.inclusiveTicks : code.exclusiveTicks; | |
| 103 var total = ticks / isolate.profile.totalSamples; | |
| 104 return (total * 100.0).toStringAsFixed(2); | |
| 105 } | |
| 106 | |
| 107 String codeName(Code code) { | |
| 108 if ((code == null) || (code.name == null)) { | |
| 109 return ''; | |
| 110 } | |
| 111 return code.name; | |
| 112 } | 142 } |
| 113 } | 143 } |
| OLD | NEW |