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

Side by Side Diff: runtime/observatory/lib/src/elements/heap_profile.dart

Issue 1310153002: Switch from Google charts to Charted (Closed) Base URL: git@github.com:dart-lang/sdk.git@master
Patch Set: Created 5 years, 3 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
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 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 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 heap_profile_element; 5 library heap_profile_element;
6 6
7 import 'dart:async'; 7 import 'dart:async';
8 import 'dart:html'; 8 import 'dart:html';
9 import 'observatory_element.dart'; 9 import 'observatory_element.dart';
10 import 'package:charted/charted.dart';
10 import 'package:observatory/app.dart'; 11 import 'package:observatory/app.dart';
11 import 'package:observatory/service.dart'; 12 import 'package:observatory/service.dart';
12 import 'package:observatory/elements.dart'; 13 import 'package:observatory/elements.dart';
13 import 'package:polymer/polymer.dart'; 14 import 'package:polymer/polymer.dart';
14 15
15 class ClassSortedTable extends SortedTable { 16 class ClassSortedTable extends SortedTable {
16 17
17 ClassSortedTable(columns) : super(columns); 18 ClassSortedTable(columns) : super(columns);
18 19
19 @override 20 @override
20 dynamic getSortKeyFor(int row, int col) { 21 dynamic getSortKeyFor(int row, int col) {
21 if (col == 0) { 22 if (col == 0) {
22 // Use class name as sort key. 23 // Use class name as sort key.
23 return rows[row].values[col].name; 24 return rows[row].values[col].name;
24 } 25 }
25 return super.getSortKeyFor(row, col); 26 return super.getSortKeyFor(row, col);
26 } 27 }
27 } 28 }
28 29
29 @CustomTag('heap-profile') 30 @CustomTag('heap-profile')
30 class HeapProfileElement extends ObservatoryElement { 31 class HeapProfileElement extends ObservatoryElement {
31 @observable String lastServiceGC = '---'; 32 @observable String lastServiceGC = '---';
32 @observable String lastAccumulatorReset = '---'; 33 @observable String lastAccumulatorReset = '---';
33 34
34 // Pie chart of new space usage. 35 // Pie chart of new space usage.
35 var _newPieDataTable;
36 var _newPieChart; 36 var _newPieChart;
37 37 final _newPieChartRows = [];
38 // Pie chart of old space usage. 38 // Pie chart of old space usage.
39 var _oldPieDataTable;
40 var _oldPieChart; 39 var _oldPieChart;
40 final _oldPieChartRows = [];
41 41
42 @observable ClassSortedTable classTable; 42 @observable ClassSortedTable classTable;
43 var _classTableBody; 43 var _classTableBody;
44 44
45 @published bool autoRefresh = false; 45 @published bool autoRefresh = false;
46 var _subscriptionFuture; 46 var _subscriptionFuture;
47 47
48 @published Isolate isolate; 48 @published Isolate isolate;
49 @observable ServiceMap profile; 49 @observable ServiceMap profile;
50 50
51 final _pieChartColumns = [
52 new ChartColumnSpec(label: 'Type', type: ChartColumnSpec.TYPE_STRING),
53 new ChartColumnSpec(label: 'Size', formatter: (v) => v.toString())
54 ];
55
51 HeapProfileElement.created() : super.created() { 56 HeapProfileElement.created() : super.created() {
52 // Create pie chart models. 57 _newPieChartRows.add(['Used', 0]);
53 _newPieDataTable = new DataTable(); 58 _newPieChartRows.add(['Free', 0]);
54 _newPieDataTable.addColumn('string', 'Type'); 59 _newPieChartRows.add(['External', 0]);
55 _newPieDataTable.addColumn('number', 'Size'); 60 _oldPieChartRows.add(['Used', 0]);
56 _oldPieDataTable = new DataTable(); 61 _oldPieChartRows.add(['Free', 0]);
57 _oldPieDataTable.addColumn('string', 'Type'); 62 _oldPieChartRows.add(['External', 0]);
turnidge 2015/09/16 17:00:28 Couldl have a helper: initBlahPieChartRows(_newPi
Cutch 2015/09/28 20:58:17 Done.
58 _oldPieDataTable.addColumn('number', 'Size');
59
60 // Create class table model. 63 // Create class table model.
61 var columns = [ 64 var columns = [
62 new SortedTableColumn('Class'), 65 new SortedTableColumn('Class'),
63 new SortedTableColumn(''), // Spacer column. 66 new SortedTableColumn(''), // Spacer column.
64 new SortedTableColumn.withFormatter('Accumulated Size (New)', 67 new SortedTableColumn.withFormatter('Accumulated Size (New)',
65 Utils.formatSize), 68 Utils.formatSize),
66 new SortedTableColumn.withFormatter('Accumulated Instances', 69 new SortedTableColumn.withFormatter('Accumulated Instances',
67 Utils.formatCommaSeparated), 70 Utils.formatCommaSeparated),
68 new SortedTableColumn.withFormatter('Current Size', 71 new SortedTableColumn.withFormatter('Current Size',
69 Utils.formatSize), 72 Utils.formatSize),
70 new SortedTableColumn.withFormatter('Current Instances', 73 new SortedTableColumn.withFormatter('Current Instances',
71 Utils.formatCommaSeparated), 74 Utils.formatCommaSeparated),
72 new SortedTableColumn(''), // Spacer column. 75 new SortedTableColumn(''), // Spacer column.
73 new SortedTableColumn.withFormatter('Accumulator Size (Old)', 76 new SortedTableColumn.withFormatter('Accumulator Size (Old)',
74 Utils.formatSize), 77 Utils.formatSize),
75 new SortedTableColumn.withFormatter('Accumulator Instances', 78 new SortedTableColumn.withFormatter('Accumulator Instances',
76 Utils.formatCommaSeparated), 79 Utils.formatCommaSeparated),
77 new SortedTableColumn.withFormatter('Current Size', 80 new SortedTableColumn.withFormatter('Current Size',
78 Utils.formatSize), 81 Utils.formatSize),
79 new SortedTableColumn.withFormatter('Current Instances', 82 new SortedTableColumn.withFormatter('Current Instances',
80 Utils.formatCommaSeparated) 83 Utils.formatCommaSeparated)
81 ]; 84 ];
82 classTable = new ClassSortedTable(columns); 85 classTable = new ClassSortedTable(columns);
83 // By default, start with accumulated new space bytes. 86 // By default, start with accumulated new space bytes.
84 classTable.sortColumnIndex = 2; 87 classTable.sortColumnIndex = 2;
85 } 88 }
86 89
90 LayoutArea _makePieChart(String id, List rows) {
91 var wrapper = shadowRoot.querySelector(id);
92 var areaHost = wrapper.querySelector('.chart-host');
93 assert(areaHost != null);
94 var legendHost = wrapper.querySelector('.chart-legend-host');
95 assert(legendHost != null);
96 var series = new ChartSeries(id, [1], new PieChartRenderer());
turnidge 2015/09/16 17:00:28 Just curious, what is a ChartSeries?
Cutch 2015/09/28 20:58:17 It is "one or more columns of ChartData rendered t
97 var config = new ChartConfig([series], [0]);
98 config.minimumSize = new Rect(300, 300);
99 config.legend = new ChartLegend(legendHost, showValues: true);
100 var data = new ChartData(_pieChartColumns, rows);
101 var area = new LayoutArea(areaHost,
102 data,
103 config,
104 state: new ChartState(),
105 autoUpdate: false);
106 area.addChartBehavior(new AxisLabelTooltip());
107 return area;
108 }
109
87 @override 110 @override
88 void attached() { 111 void attached() {
89 super.attached(); 112 super.attached();
90 // Grab the pie chart divs. 113 _newPieChart = _makePieChart('#new-pie-chart', _newPieChartRows);
91 _newPieChart = new Chart('PieChart', 114 _oldPieChart = _makePieChart('#old-pie-chart', _oldPieChartRows);
92 shadowRoot.querySelector('#newPieChart'));
93 _oldPieChart = new Chart('PieChart',
94 shadowRoot.querySelector('#oldPieChart'));
95 _classTableBody = shadowRoot.querySelector('#classTableBody'); 115 _classTableBody = shadowRoot.querySelector('#classTableBody');
96 _subscriptionFuture = 116 _subscriptionFuture =
97 app.vm.listenEventStream(VM.kGCStream, _onEvent); 117 app.vm.listenEventStream(VM.kGCStream, _onEvent);
98 } 118 }
99 119
100 @override 120 @override
101 void detached() { 121 void detached() {
102 cancelFutureSubscription(_subscriptionFuture); 122 cancelFutureSubscription(_subscriptionFuture);
103 _subscriptionFuture = null; 123 _subscriptionFuture = null;
104 super.detached(); 124 super.detached();
(...skipping 22 matching lines...) Expand all
127 refreshAutoPending = false; 147 refreshAutoPending = false;
128 // Keep refreshing if at least one GC event was received while waiting. 148 // Keep refreshing if at least one GC event was received while waiting.
129 if (refreshAutoQueued) { 149 if (refreshAutoQueued) {
130 refreshAuto(); 150 refreshAuto();
131 } 151 }
132 }).catchError(app.handleException); 152 }).catchError(app.handleException);
133 } 153 }
134 154
135 void _updatePieCharts() { 155 void _updatePieCharts() {
136 assert(profile != null); 156 assert(profile != null);
137 _newPieDataTable.clearRows(); 157 _newPieChartRows[0][1] = isolate.newSpace.used;
138 _newPieDataTable.addRow(['Used', isolate.newSpace.used]); 158 _newPieChartRows[1][1] = isolate.newSpace.capacity - isolate.newSpace.used;
139 _newPieDataTable.addRow(['Free', 159 _newPieChartRows[2][1] = isolate.newSpace.external;
140 isolate.newSpace.capacity - isolate.newSpace.used]); 160 _oldPieChartRows[0][1] = isolate.oldSpace.used;
141 _newPieDataTable.addRow(['External', isolate.newSpace.external]); 161 _oldPieChartRows[1][1] = isolate.oldSpace.capacity - isolate.oldSpace.used;
142 _oldPieDataTable.clearRows(); 162 _oldPieChartRows[2][1] = isolate.oldSpace.external;
turnidge 2015/09/16 17:00:28 Consider naming the indices: 0 -> kUsedIdx, 1 -> k
Cutch 2015/09/28 20:58:17 Done.
143 _oldPieDataTable.addRow(['Used', isolate.oldSpace.used]);
144 _oldPieDataTable.addRow(['Free',
145 isolate.oldSpace.capacity - isolate.oldSpace.used]);
146 _oldPieDataTable.addRow(['External', isolate.oldSpace.external]);
147 } 163 }
148 164
149 void _updateClasses() { 165 void _updateClasses() {
150 for (ServiceMap clsAllocations in profile['members']) { 166 for (ServiceMap clsAllocations in profile['members']) {
151 Class cls = clsAllocations['class']; 167 Class cls = clsAllocations['class'];
152 if (cls == null) { 168 if (cls == null) {
153 continue; 169 continue;
154 } 170 }
155 cls.newSpace.update(clsAllocations['new']); 171 cls.newSpace.update(clsAllocations['new']);
156 cls.oldSpace.update(clsAllocations['old']); 172 cls.oldSpace.update(clsAllocations['old']);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
261 assert(_classTableBody.children.length == classTable.sortedRows.length); 277 assert(_classTableBody.children.length == classTable.sortedRows.length);
262 // Fill table. 278 // Fill table.
263 for (var i = 0; i < classTable.sortedRows.length; i++) { 279 for (var i = 0; i < classTable.sortedRows.length; i++) {
264 var rowIndex = classTable.sortedRows[i]; 280 var rowIndex = classTable.sortedRows[i];
265 var tr = _classTableBody.children[i]; 281 var tr = _classTableBody.children[i];
266 _fillClassTableDomRow(tr, rowIndex); 282 _fillClassTableDomRow(tr, rowIndex);
267 } 283 }
268 } 284 }
269 285
270 void _drawCharts() { 286 void _drawCharts() {
271 _newPieChart.draw(_newPieDataTable); 287 _newPieChart.draw();
272 _oldPieChart.draw(_oldPieDataTable); 288 _oldPieChart.draw();
273 } 289 }
274 290
275 @observable void changeSort(Event e, var detail, Element target) { 291 @observable void changeSort(Event e, var detail, Element target) {
276 if (target is TableCellElement) { 292 if (target is TableCellElement) {
277 if (classTable.sortColumnIndex != target.cellIndex) { 293 if (classTable.sortColumnIndex != target.cellIndex) {
278 classTable.sortColumnIndex = target.cellIndex; 294 classTable.sortColumnIndex = target.cellIndex;
279 classTable.sortDescending = true; 295 classTable.sortDescending = true;
280 } else { 296 } else {
281 classTable.sortDescending = !classTable.sortDescending; 297 classTable.sortDescending = !classTable.sortDescending;
282 } 298 }
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
366 } 382 }
367 383
368 @observable String formattedTotalCollectionTime(bool newSpace) { 384 @observable String formattedTotalCollectionTime(bool newSpace) {
369 if (profile == null) { 385 if (profile == null) {
370 return ''; 386 return '';
371 } 387 }
372 var heap = newSpace ? isolate.newSpace : isolate.oldSpace; 388 var heap = newSpace ? isolate.newSpace : isolate.oldSpace;
373 return '${Utils.formatSeconds(heap.totalCollectionTimeInSeconds)} secs'; 389 return '${Utils.formatSeconds(heap.totalCollectionTimeInSeconds)} secs';
374 } 390 }
375 } 391 }
OLDNEW
« no previous file with comments | « runtime/observatory/lib/src/elements/debugger.dart ('k') | runtime/observatory/lib/src/elements/heap_profile.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698