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

Side by Side Diff: runtime/bin/vmservice/client/lib/src/observatory_elements/heap_profile.dart

Issue 184233007: Refactor Observatory (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
(Empty)
1 // Copyright (c) 2014, 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 heap_profile_element;
6
7 import 'dart:html';
8 import 'package:logging/logging.dart';
9 import 'package:polymer/polymer.dart';
10 import 'observatory_element.dart';
11
12 /// Displays an Error response.
13 @CustomTag('heap-profile')
14 class HeapProfileElement extends ObservatoryElement {
15 // Indexes into VM provided map.
16 static const ALLOCATED_BEFORE_GC = 0;
17 static const ALLOCATED_BEFORE_GC_SIZE = 1;
18 static const LIVE_AFTER_GC = 2;
19 static const LIVE_AFTER_GC_SIZE = 3;
20 static const ALLOCATED_SINCE_GC = 4;
21 static const ALLOCATED_SINCE_GC_SIZE = 5;
22 static const ACCUMULATED = 6;
23 static const ACCUMULATED_SIZE = 7;
24
25 // Pie chart of new space usage.
26 var _newPieDataTable;
27 var _newPieChart;
28
29 // Pie chart of old space usage.
30 var _oldPieDataTable;
31 var _oldPieChart;
32
33 // The combined chart has old and new space merged.
34 var _combinedDataTable;
35 var _combinedChart;
36
37 // The full chart has separate columns for new and old space.
38 var _fullDataTable;
39 var _fullChart;
40
41 @published Map profile;
42
43 HeapProfileElement.created() : super.created() {
44 _fullDataTable = new DataTable();
45 _fullDataTable.addColumn('string', 'Class');
46 _fullDataTable.addColumn('number', 'Current (new)');
47 _fullDataTable.addColumn('number', 'Allocated Since GC (new)');
48 _fullDataTable.addColumn('number', 'Total before GC (new)');
49 _fullDataTable.addColumn('number', 'Survivors (new)');
50 _fullDataTable.addColumn('number', 'Current (old)');
51 _fullDataTable.addColumn('number', 'Allocated Since GC (old)');
52 _fullDataTable.addColumn('number', 'Total before GC (old)');
53 _fullDataTable.addColumn('number', 'Survivors (old)');
54 _newPieDataTable = new DataTable();
55 _newPieDataTable.addColumn('string', 'Type');
56 _newPieDataTable.addColumn('number', 'Size');
57 _oldPieDataTable = new DataTable();
58 _oldPieDataTable.addColumn('string', 'Type');
59 _oldPieDataTable.addColumn('number', 'Size');
60 _combinedDataTable = new DataTable();
61 _combinedDataTable.addColumn('string', 'Class');
62 _combinedDataTable.addColumn('number', 'Accumulator');
63 _combinedDataTable.addColumn('number', 'Accumulator Instances');
64 _combinedDataTable.addColumn('number', 'Current');
65 _combinedDataTable.addColumn('number', 'Allocated Since GC');
66 _combinedDataTable.addColumn('number', 'Total before GC');
67 _combinedDataTable.addColumn('number', 'Survivors after GC');
68 }
69
70 void enteredView() {
71 super.enteredView();
72 _fullChart = new Chart('Table',
73 shadowRoot.querySelector('#table'));
74 _fullChart.options['allowHtml'] = true;
75 _fullChart.options['sortColumn'] = 1;
76 _fullChart.options['sortAscending'] = false;
77 _newPieChart = new Chart('PieChart',
78 shadowRoot.querySelector('#newPieChart'));
79 _newPieChart.options['title'] = 'New Space';
80 _oldPieChart = new Chart('PieChart',
81 shadowRoot.querySelector('#oldPieChart'));
82 _oldPieChart.options['title'] = 'Old Space';
83 _combinedChart = new Chart('Table',
84 shadowRoot.querySelector('#simpleTable'));
85 _combinedChart.options['allowHtml'] = true;
86 _combinedChart.options['sortColumn'] = 1;
87 _combinedChart.options['sortAscending'] = false;
88 _draw();
89 }
90
91 bool _first = true;
92
93 void _updateChartData() {
94 if ((profile == null) || (profile['members'] is! List) ||
95 (profile['members'].length == 0)) {
96 return;
97 }
98 assert(_fullDataTable != null);
99 assert(_combinedDataTable != null);
100 _fullDataTable.clearRows();
101 _combinedDataTable.clearRows();
102 for (Map cls in profile['members']) {
103 if (_classHasNoAllocations(cls)) {
104 // If a class has no allocations, don't display it.
105 continue;
106 }
107 var vm_name = cls['class']['name'];
108 var url =
109 app.locationManager.currentIsolateRelativeLink(cls['class']['id']);
110 _fullDataTable.addRow([
111 '<a title="$vm_name" href="$url">'
112 '${_fullTableColumnValue(cls, 0)}</a>',
113 _fullTableColumnValue(cls, 1),
114 _fullTableColumnValue(cls, 2),
115 _fullTableColumnValue(cls, 3),
116 _fullTableColumnValue(cls, 4),
117 _fullTableColumnValue(cls, 5),
118 _fullTableColumnValue(cls, 6),
119 _fullTableColumnValue(cls, 7),
120 _fullTableColumnValue(cls, 8)]);
121 _combinedDataTable.addRow([
122 '<a title="$vm_name" href="$url">'
123 '${_combinedTableColumnValue(cls, 0)}</a>',
124 _combinedTableColumnValue(cls, 1),
125 _combinedTableColumnValue(cls, 2),
126 _combinedTableColumnValue(cls, 3),
127 _combinedTableColumnValue(cls, 4),
128 _combinedTableColumnValue(cls, 5),
129 _combinedTableColumnValue(cls, 6)]);
130 }
131 _newPieDataTable.clearRows();
132 var heap = profile['heaps']['new'];
133 _newPieDataTable.addRow(['Used', heap['used']]);
134 _newPieDataTable.addRow(['Free', heap['capacity'] - heap['used']]);
135 _oldPieDataTable.clearRows();
136 heap = profile['heaps']['old'];
137 _oldPieDataTable.addRow(['Used', heap['used']]);
138 _oldPieDataTable.addRow(['Free', heap['capacity'] - heap['used']]);
139 _draw();
140 }
141
142 void _draw() {
143 if ((_fullChart == null) || (_combinedChart == null)) {
144 return;
145 }
146 _combinedChart.refreshOptionsSortInfo();
147 _combinedChart.draw(_combinedDataTable);
148 _fullChart.refreshOptionsSortInfo();
149 _fullChart.draw(_fullDataTable);
150 _newPieChart.draw(_newPieDataTable);
151 _oldPieChart.draw(_oldPieDataTable);
152 }
153
154 bool _classHasNoAllocations(Map v) {
155 var newSpace = v['new'];
156 var oldSpace = v['old'];
157 for (var allocation in newSpace) {
158 if (allocation != 0) {
159 return false;
160 }
161 }
162 for (var allocation in oldSpace) {
163 if (allocation != 0) {
164 return false;
165 }
166 }
167 return true;
168 }
169
170 dynamic _fullTableColumnValue(Map v, int index) {
171 assert(index >= 0);
172 assert(index < 9);
173 switch (index) {
174 case 0:
175 return v['class']['user_name'];
176 case 1:
177 return v['new'][LIVE_AFTER_GC_SIZE] + v['new'][ALLOCATED_SINCE_GC_SIZE];
178 case 2:
179 return v['new'][ALLOCATED_SINCE_GC_SIZE];
180 case 3:
181 return v['new'][ALLOCATED_BEFORE_GC_SIZE];
182 case 4:
183 return v['new'][LIVE_AFTER_GC_SIZE];
184 case 5:
185 return v['old'][LIVE_AFTER_GC_SIZE] + v['old'][ALLOCATED_SINCE_GC_SIZE];
186 case 6:
187 return v['old'][ALLOCATED_SINCE_GC_SIZE];
188 case 7:
189 return v['old'][ALLOCATED_BEFORE_GC_SIZE];
190 case 8:
191 return v['old'][LIVE_AFTER_GC_SIZE];
192 }
193 throw new FallThroughError();
194 }
195
196 dynamic _combinedTableColumnValue(Map v, int index) {
197 assert(index >= 0);
198 assert(index < 7);
199 switch (index) {
200 case 0:
201 return v['class']['user_name'];
202 case 1:
203 return v['new'][ACCUMULATED_SIZE] +
204 v['old'][ACCUMULATED_SIZE];
205 case 2:
206 return v['new'][ACCUMULATED] +
207 v['old'][ACCUMULATED];
208 case 3:
209 return v['new'][LIVE_AFTER_GC_SIZE] +
210 v['new'][ALLOCATED_SINCE_GC_SIZE] +
211 v['old'][LIVE_AFTER_GC_SIZE] +
212 v['old'][ALLOCATED_SINCE_GC_SIZE];
213 case 4:
214 return v['new'][ALLOCATED_SINCE_GC_SIZE] +
215 v['old'][ALLOCATED_SINCE_GC_SIZE];
216 case 5:
217 return v['new'][ALLOCATED_BEFORE_GC_SIZE] +
218 v['old'][ALLOCATED_BEFORE_GC_SIZE];
219 case 6:
220 return v['new'][LIVE_AFTER_GC_SIZE] + v['old'][LIVE_AFTER_GC_SIZE];
221 }
222 throw new FallThroughError();
223 }
224
225 void refresh(var done) {
226 var isolateId = app.locationManager.currentIsolateId();
227 var isolate = app.isolateManager.getIsolate(isolateId);
228 if (isolate == null) {
229 Logger.root.info('No isolate found.');
230 return;
231 }
232 var request = '/$isolateId/allocationprofile';
233 app.requestManager.requestMap(request).then((Map response) {
234 assert(response['type'] == 'AllocationProfile');
235 profile = response;
236 }).catchError((e, st) {
237 Logger.root.info('$e $st');
238 }).whenComplete(done);
239 }
240
241 void resetAccumulator(Event e, var detail, Node target) {
242 var isolateId = app.locationManager.currentIsolateId();
243 var isolate = app.isolateManager.getIsolate(isolateId);
244 if (isolate == null) {
245 Logger.root.info('No isolate found.');
246 return;
247 }
248 var request = '/$isolateId/allocationprofile/reset';
249 app.requestManager.requestMap(request).then((Map response) {
250 assert(response['type'] == 'AllocationProfile');
251 profile = response;
252 }).catchError((e, st) {
253 Logger.root.info('$e $st');
254 });
255 }
256
257 void profileChanged(oldValue) {
258 _updateChartData();
259 notifyPropertyChange(#formattedAverage, [], formattedAverage);
260 notifyPropertyChange(#formattedTotalCollectionTime, [],
261 formattedTotalCollectionTime);
262 notifyPropertyChange(#formattedCollections, [], formattedCollections);
263 }
264
265 @observable String formattedAverage(bool newSpace) {
266 if (profile == null) {
267 return '';
268 }
269 String space = newSpace ? 'new' : 'old';
270 Map heap = profile['heaps'][space];
271 var r = ((heap['time'] * 1000.0) / heap['collections']).toStringAsFixed(2);
272 return '$r ms';
273 }
274
275 @observable String formattedCollections(bool newSpace) {
276 if (profile == null) {
277 return '';
278 }
279 String space = newSpace ? 'new' : 'old';
280 Map heap = profile['heaps'][space];
281 return '${heap['collections']}';
282 }
283
284 @observable String formattedTotalCollectionTime(bool newSpace) {
285 if (profile == null) {
286 return '';
287 }
288 String space = newSpace ? 'new' : 'old';
289 Map heap = profile['heaps'][space];
290 return '${ObservatoryApplication.timeUnits(heap['time'])} secs';
291 }
292 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698