| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library isolate_profile_element; | |
| 6 | |
| 7 import 'dart:html'; | |
| 8 import 'package:logging/logging.dart'; | |
| 9 import 'package:observatory/observatory.dart'; | |
| 10 import 'package:polymer/polymer.dart'; | |
| 11 import 'observatory_element.dart'; | |
| 12 | |
| 13 class ProfileCallerTreeRow extends TableTreeRow { | |
| 14 final Isolate isolate; | |
| 15 @observable final Code code; | |
| 16 | |
| 17 static String formatPercent(num a, num total) { | |
| 18 var percent = 100.0 * (a / total); | |
| 19 return '${percent.toStringAsFixed(2)}%'; | |
| 20 } | |
| 21 | |
| 22 ProfileCallerTreeRow(this.isolate, this.code, ProfileCallerTreeRow parent) : | |
| 23 super(parent) { | |
| 24 // When the row is created, fill out the columns. | |
| 25 columns.add( | |
| 26 formatPercent(code.exclusiveTicks, isolate.profile.totalSamples)); | |
| 27 if (parent == null) { | |
| 28 // Fill with dummy data. | |
| 29 columns.add(''); | |
| 30 } else { | |
| 31 var totalAttributedCalls = parent.code.callersCount(code); | |
| 32 var totalParentCalls = parent.code.sumCallersCount(); | |
| 33 columns.add(formatPercent(totalAttributedCalls, totalParentCalls)); | |
| 34 } | |
| 35 columns.add( | |
| 36 formatPercent(code.inclusiveTicks, isolate.profile.totalSamples)); | |
| 37 } | |
| 38 | |
| 39 void onShow() { | |
| 40 if (children.length > 0) { | |
| 41 // Child rows already created. | |
| 42 return; | |
| 43 } | |
| 44 // Create child rows on demand. | |
| 45 code.callers.forEach((CodeCallCount codeCaller) { | |
| 46 var row = | |
| 47 new ProfileCallerTreeRow(isolate, codeCaller.code, this); | |
| 48 children.add(row); | |
| 49 }); | |
| 50 } | |
| 51 | |
| 52 void onHide() { | |
| 53 } | |
| 54 } | |
| 55 | |
| 56 /// Displays an IsolateProfile | |
| 57 @CustomTag('isolate-profile') | |
| 58 class IsolateProfileElement extends ObservatoryElement { | |
| 59 IsolateProfileElement.created() : super.created(); | |
| 60 @observable int methodCountSelected = 0; | |
| 61 final List methodCounts = [10, 20, 50]; | |
| 62 @observable List topExclusiveCodes = toObservable([]); | |
| 63 final _id = '#tableTree'; | |
| 64 TableTree tree; | |
| 65 | |
| 66 void enteredView() { | |
| 67 var isolateId = app.locationManager.currentIsolateId(); | |
| 68 var isolate = app.isolateManager.getIsolate(isolateId); | |
| 69 if (isolate == null) { | |
| 70 return; | |
| 71 } | |
| 72 tree = new TableTree(['Method', 'Exclusive', 'Caller', 'Inclusive']); | |
| 73 _refresh(isolate); | |
| 74 } | |
| 75 | |
| 76 void _startRequest() { | |
| 77 // TODO(johnmccutchan): Indicate visually. | |
| 78 } | |
| 79 | |
| 80 void _endRequest() { | |
| 81 // TODO(johnmccutchan): Indicate visually. | |
| 82 } | |
| 83 | |
| 84 methodCountSelectedChanged(oldValue) { | |
| 85 var isolateId = app.locationManager.currentIsolateId(); | |
| 86 var isolate = app.isolateManager.getIsolate(isolateId); | |
| 87 if (isolate == null) { | |
| 88 return; | |
| 89 } | |
| 90 _refresh(isolate); | |
| 91 } | |
| 92 | |
| 93 void refresh(var done) { | |
| 94 var isolateId = app.locationManager.currentIsolateId(); | |
| 95 var isolate = app.isolateManager.getIsolate(isolateId); | |
| 96 if (isolate == null) { | |
| 97 Logger.root.info('No isolate found.'); | |
| 98 return; | |
| 99 } | |
| 100 var request = '/$isolateId/profile'; | |
| 101 _startRequest(); | |
| 102 app.requestManager.requestMap(request).then((Map profile) { | |
| 103 assert(profile['type'] == 'Profile'); | |
| 104 var samples = profile['samples']; | |
| 105 Logger.root.info('Profile contains ${samples} samples.'); | |
| 106 _loadProfileData(isolate, samples, profile); | |
| 107 _endRequest(); | |
| 108 }).catchError((e) { | |
| 109 _endRequest(); | |
| 110 }).whenComplete(done); | |
| 111 } | |
| 112 | |
| 113 void _loadProfileData(Isolate isolate, int totalSamples, Map response) { | |
| 114 isolate.profile = new Profile.fromMap(isolate, response); | |
| 115 _refresh(isolate); | |
| 116 } | |
| 117 | |
| 118 void _refresh(Isolate isolate) { | |
| 119 _refreshTopMethods(isolate); | |
| 120 _refreshTree(isolate); | |
| 121 } | |
| 122 | |
| 123 void _refreshTree(Isolate isolate) { | |
| 124 var rootChildren = []; | |
| 125 for (var code in topExclusiveCodes) { | |
| 126 var row = new ProfileCallerTreeRow(isolate, code, null); | |
| 127 rootChildren.add(row); | |
| 128 } | |
| 129 tree.initialize(rootChildren); | |
| 130 notifyPropertyChange(#tree, null, tree); | |
| 131 } | |
| 132 | |
| 133 | |
| 134 void _refreshTopMethods(Isolate isolate) { | |
| 135 topExclusiveCodes.clear(); | |
| 136 if ((isolate == null) || (isolate.profile == null)) { | |
| 137 return; | |
| 138 } | |
| 139 var count = methodCounts[methodCountSelected]; | |
| 140 var topExclusive = isolate.profile.topExclusive(count); | |
| 141 topExclusiveCodes.addAll(topExclusive); | |
| 142 } | |
| 143 | |
| 144 @observable String padding(TableTreeRow row) { | |
| 145 return 'padding-left: ${row.depth * 16}px;'; | |
| 146 } | |
| 147 | |
| 148 @observable String coloring(TableTreeRow row) { | |
| 149 const colors = const ['active', 'success', 'warning', 'danger', 'info']; | |
| 150 var index = row.depth % colors.length; | |
| 151 return colors[index]; | |
| 152 } | |
| 153 | |
| 154 @observable void toggleExpanded(Event e, var detail, Element target) { | |
| 155 var row = target.parent; | |
| 156 if (row is TableRowElement) { | |
| 157 // Subtract 1 to get 0 based indexing. | |
| 158 tree.toggle(row.rowIndex - 1); | |
| 159 } | |
| 160 } | |
| 161 } | |
| OLD | NEW |