Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(465)

Side by Side Diff: runtime/bin/vmservice/client/lib/src/elements/isolate_profile.dart

Issue 192443004: Complete the switch to ServiceObject (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 'isolate_element.dart'; 8 import 'observatory_element.dart';
9 import 'package:logging/logging.dart'; 9 import 'package:observatory/service.dart';
10 import 'package:observatory/app.dart'; 10 import 'package:observatory/app.dart';
11 import 'package:polymer/polymer.dart'; 11 import 'package:polymer/polymer.dart';
12 12
13 class ProfileCallerTreeRow extends TableTreeRow { 13 class ProfileCallerTreeRow extends TableTreeRow {
14 final Isolate isolate; 14 final ServiceMap profile;
15 @observable final Code code; 15 @reflectable final Code code;
16 16
17 static String formatPercent(num a, num total) { 17 static String formatPercent(num a, num total) {
18 var percent = 100.0 * (a / total); 18 var percent = 100.0 * (a / total);
19 return '${percent.toStringAsFixed(2)}%'; 19 return '${percent.toStringAsFixed(2)}%';
20 } 20 }
21 21
22 ProfileCallerTreeRow(this.isolate, this.code, ProfileCallerTreeRow parent) : 22 ProfileCallerTreeRow(this.profile, this.code, ProfileCallerTreeRow parent) :
23 super(parent) { 23 super(parent) {
24 assert(profile != null);
25 assert(code != null);
26 var totalSamples = profile['samples'];
24 // When the row is created, fill out the columns. 27 // When the row is created, fill out the columns.
25 columns.add( 28 columns.add(
26 formatPercent(code.exclusiveTicks, isolate.profile.totalSamples)); 29 formatPercent(code.exclusiveTicks, totalSamples));
27 if (parent == null) { 30 if (parent == null) {
28 // Fill with dummy data. 31 // Fill with dummy data.
29 columns.add(''); 32 columns.add('');
30 } else { 33 } else {
31 var totalAttributedCalls = parent.code.callersCount(code); 34 var totalAttributedCalls = parent.code.callersCount(code);
32 var totalParentCalls = parent.code.sumCallersCount(); 35 var totalParentCalls = parent.code.sumCallersCount();
33 columns.add(formatPercent(totalAttributedCalls, totalParentCalls)); 36 columns.add(formatPercent(totalAttributedCalls, totalParentCalls));
34 } 37 }
35 columns.add(
36 formatPercent(code.inclusiveTicks, isolate.profile.totalSamples));
37 } 38 }
38 39
39 void onShow() { 40 void onShow() {
40 if (children.length > 0) { 41 if (children.length > 0) {
41 // Child rows already created. 42 // Child rows already created.
42 return; 43 return;
43 } 44 }
44 // Create child rows on demand. 45 // Create child rows on demand.
45 code.callers.forEach((CodeCallCount codeCaller) { 46 code.callers.forEach((CodeCallCount codeCaller) {
46 var row = 47 var row =
47 new ProfileCallerTreeRow(isolate, codeCaller.code, this); 48 new ProfileCallerTreeRow(profile, codeCaller.code, this);
48 children.add(row); 49 children.add(row);
49 }); 50 });
50 } 51 }
51 52
52 void onHide() { 53 void onHide() {
53 } 54 }
54 } 55 }
55 56
56 /// Displays an IsolateProfile 57 /// Displays an IsolateProfile
57 @CustomTag('isolate-profile') 58 @CustomTag('isolate-profile')
58 class IsolateProfileElement extends IsolateElement { 59 class IsolateProfileElement extends ObservatoryElement {
59 IsolateProfileElement.created() : super.created(); 60 IsolateProfileElement.created() : super.created();
61 @published ServiceMap profile;
62 @reflectable final topExclusiveCodes = new ObservableList<Code>();
60 @observable int methodCountSelected = 0; 63 @observable int methodCountSelected = 0;
64 @observable String sampleCount = '';
65 @observable String refreshTime = '';
66
61 final List methodCounts = [10, 20, 50]; 67 final List methodCounts = [10, 20, 50];
62 @observable List topExclusiveCodes = toObservable([]);
63 final _id = '#tableTree'; 68 final _id = '#tableTree';
64 TableTree tree; 69 TableTree tree;
65 @published Map profile;
66 @observable String sampleCount = '';
67 @observable String refreshTime = '';
68 70
69 void profileChanged(oldValue) { 71 void profileChanged(oldValue) {
70 if (profile == null) { 72 if (profile == null) {
71 return; 73 return;
72 } 74 }
73 print('profile changed'); 75 var totalSamples = profile['samples'];
74 var samples = profile['samples']; 76 var now = new DateTime.now();
75 _loadProfileData(isolate, samples, profile); 77 sampleCount = totalSamples.toString();
76 _refresh(isolate); 78 refreshTime = now.toString();
79 profile.isolate.processProfile(profile);
80 _update();
77 } 81 }
78 82
79 void enteredView() { 83 void enteredView() {
80 tree = new TableTree(['Method', 'Exclusive', 'Caller', 'Inclusive']); 84 tree = new TableTree(['Method', 'Exclusive', 'Caller']);
81 _refresh(isolate); 85 _update();
82 } 86 }
83 87
84 methodCountSelectedChanged(oldValue) { 88 methodCountSelectedChanged(oldValue) {
85 _refresh(isolate); 89 _update();
86 } 90 }
87 91
88 void refresh(var done) { 92 void refresh(var done) {
89 isolate.getMap('profile').then((Map profile) { 93 profile.isolate.get('profile').then((ServiceMap m) {
90 assert(profile['type'] == 'Profile'); 94 // Assert we got back the a profile.
91 var samples = profile['samples']; 95 assert(m.serviceType == 'Profile');
92 Logger.root.info('Profile contains ${samples} samples.'); 96 profile = m;
93 _loadProfileData(isolate, samples, profile);
94 }).catchError((e, st) {
95 Logger.root.warning('Error refreshing profile', e, st);
96 }).whenComplete(done); 97 }).whenComplete(done);
97 } 98 }
98 99
99 void _loadProfileData(Isolate isolate, int totalSamples, Map response) { 100 void _update() {
100 sampleCount = totalSamples.toString(); 101 if (profile == null) {
101 var now = new DateTime.now(); 102 return;
102 refreshTime = now.toString(); 103 }
103 isolate.profile = new Profile.fromMap(isolate, response); 104 _refreshTopMethods();
104 _refresh(isolate); 105 _rebuildTree();
105 } 106 }
106 107
107 void _refresh(Isolate isolate) { 108 void _refreshTopMethods() {
108 _refreshTopMethods(isolate); 109 assert(profile != null);
109 _refreshTree(isolate); 110 var count = methodCounts[methodCountSelected];
111 topExclusiveCodes.clear();
112 topExclusiveCodes.addAll(profile.isolate.codes.topExclusive(count));
110 } 113 }
111 114
112 void _refreshTree(Isolate isolate) { 115 void _rebuildTree() {
116 assert(profile != null);
113 var rootChildren = []; 117 var rootChildren = [];
114 for (var code in topExclusiveCodes) { 118 for (var code in topExclusiveCodes) {
115 var row = new ProfileCallerTreeRow(isolate, code, null); 119 var row = new ProfileCallerTreeRow(profile, code, null);
116 rootChildren.add(row); 120 rootChildren.add(row);
117 } 121 }
118 tree.initialize(rootChildren); 122 tree.initialize(rootChildren);
119 notifyPropertyChange(#tree, null, tree); 123 notifyPropertyChange(#tree, null, tree);
120 } 124 }
121 125
122
123 void _refreshTopMethods(Isolate isolate) {
124 topExclusiveCodes.clear();
125 if ((isolate == null) || (isolate.profile == null)) {
126 return;
127 }
128 var count = methodCounts[methodCountSelected];
129 var topExclusive = isolate.profile.topExclusive(count);
130 topExclusiveCodes.addAll(topExclusive);
131 }
132
133 @observable String padding(TableTreeRow row) { 126 @observable String padding(TableTreeRow row) {
134 return 'padding-left: ${row.depth * 16}px;'; 127 return 'padding-left: ${row.depth * 16}px;';
135 } 128 }
136 129
137 @observable String coloring(TableTreeRow row) { 130 @observable String coloring(TableTreeRow row) {
138 const colors = const ['active', 'success', 'warning', 'danger', 'info']; 131 const colors = const ['active', 'success', 'warning', 'danger', 'info'];
139 var index = row.depth % colors.length; 132 var index = row.depth % colors.length;
140 return colors[index]; 133 return colors[index];
141 } 134 }
142 135
143 @observable void toggleExpanded(Event e, var detail, Element target) { 136 @observable void toggleExpanded(Event e, var detail, Element target) {
144 var row = target.parent; 137 var row = target.parent;
145 if (row is TableRowElement) { 138 if (row is TableRowElement) {
146 // Subtract 1 to get 0 based indexing. 139 // Subtract 1 to get 0 based indexing.
147 tree.toggle(row.rowIndex - 1); 140 tree.toggle(row.rowIndex - 1);
148 } 141 }
149 } 142 }
143
150 } 144 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698