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

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

Issue 148153007: Add Google Charts to Observatory and use it in allocation profiler (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 10 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) 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:html'; 8 import 'dart:html';
8 import 'package:logging/logging.dart'; 9 import 'package:logging/logging.dart';
9 import 'package:polymer/polymer.dart'; 10 import 'package:polymer/polymer.dart';
10 import 'observatory_element.dart'; 11 import 'observatory_element.dart';
11 12
12 /// Displays an Error response. 13 /// Displays an Error response.
13 @CustomTag('heap-profile') 14 @CustomTag('heap-profile')
14 class HeapProfileElement extends ObservatoryElement { 15 class HeapProfileElement extends ObservatoryElement {
15 // Indexes into VM provided map. 16 // Indexes into VM provided map.
16 static const ALLOCATED_BEFORE_GC = 0; 17 static const ALLOCATED_BEFORE_GC = 0;
17 static const ALLOCATED_BEFORE_GC_SIZE = 1; 18 static const ALLOCATED_BEFORE_GC_SIZE = 1;
18 static const LIVE_AFTER_GC = 2; 19 static const LIVE_AFTER_GC = 2;
19 static const LIVE_AFTER_GC_SIZE = 3; 20 static const LIVE_AFTER_GC_SIZE = 3;
20 static const ALLOCATED_SINCE_GC = 4; 21 static const ALLOCATED_SINCE_GC = 4;
21 static const ALLOCATED_SINCE_GC_SIZE = 5; 22 static const ALLOCATED_SINCE_GC_SIZE = 5;
22 23
24 var _newPieDataTable;
25 var _newPieChart;
26
27 var _oldPieDataTable;
28 var _oldPieChart;
29
30 var _tableDataTable;
31 var _tableChart;
32
23 @published Map profile; 33 @published Map profile;
24 @published List sortedProfile;
25 int _sortColumnIndex = 1;
26 HeapProfileElement.created() : super.created();
27 34
28 // Display columns. 35 HeapProfileElement.created() : super.created() {
29 @observable final List<String> columns = [ 36 _tableDataTable = new DataTable();
30 'Class', 37 _tableDataTable.addColumn('string', 'Class');
31 'Current (new)', 38 _tableDataTable.addColumn('number', 'Current (new)');
32 'Allocated Since GC (new)', 39 _tableDataTable.addColumn('number', 'Allocated Since GC (new)');
33 'Total before GC (new)', 40 _tableDataTable.addColumn('number', 'Total before GC (new)');
34 'Survivors (new)', 41 _tableDataTable.addColumn('number', 'Survivors (new)');
35 'Current (old)', 42 _tableDataTable.addColumn('number', 'Current (old)');
36 'Allocated Since GC (old)', 43 _tableDataTable.addColumn('number', 'Allocated Since GC (old)');
37 'Total before GC (old)', 44 _tableDataTable.addColumn('number', 'Total before GC (old)');
38 'Survivors (old)', 45 _tableDataTable.addColumn('number', 'Survivors (old)');
39 ]; 46 _newPieDataTable = new DataTable();
47 _newPieDataTable.addColumn('string', 'Type');
48 _newPieDataTable.addColumn('number', 'Size');
49 _oldPieDataTable = new DataTable();
50 _oldPieDataTable.addColumn('string', 'Type');
51 _oldPieDataTable.addColumn('number', 'Size');
52 }
53
54 void enteredView() {
55 super.enteredView();
56 _tableChart = new Chart('Table',
57 shadowRoot.querySelector('#table'));
58 _tableChart.options['allowHtml'] = true;
59 _tableChart.options['sortColumn'] = 1;
60 _tableChart.options['sortAscending'] = false;
61 _newPieChart = new Chart('PieChart',
62 shadowRoot.querySelector('#newPieChart'));
63 _newPieChart.options['title'] = 'New Space';
64 _oldPieChart = new Chart('PieChart',
65 shadowRoot.querySelector('#oldPieChart'));
66 _oldPieChart.options['title'] = 'Old Space';
67 _draw();
68 }
69
70 bool _first = true;
71
72 void _updateChartData() {
73 if ((profile == null) || (profile['members'] is! List) ||
74 (profile['members'].length == 0)) {
75 return;
76 }
77 assert(_tableDataTable != null);
78 _tableDataTable.clearRows();
79 for (Map cls in profile['members']) {
80 var url =
81 app.locationManager.currentIsolateRelativeLink(cls['class']['id']);
82 _tableDataTable.addRow(
83 ['<a href="$url">${_columnValue(cls, 0)}</a>',
84 _columnValue(cls, 1),
85 _columnValue(cls, 2),
86 _columnValue(cls, 3),
87 _columnValue(cls, 4),
88 _columnValue(cls, 5),
89 _columnValue(cls, 6),
90 _columnValue(cls, 7),
91 _columnValue(cls, 8)]);
92 }
93 _newPieDataTable.clearRows();
94 var heap = profile['heaps']['new'];
95 _newPieDataTable.addRow(['Used', heap['used']]);
96 _newPieDataTable.addRow(['Free', heap['capacity'] - heap['used']]);
97 _oldPieDataTable.clearRows();
98 heap = profile['heaps']['old'];
99 _oldPieDataTable.addRow(['Used', heap['used']]);
100 _oldPieDataTable.addRow(['Free', heap['capacity'] - heap['used']]);
101 _draw();
102 }
103
104 void _draw() {
105 if (_tableChart == null) {
106 return;
107 }
108 _tableChart.draw(_tableDataTable);
109 _newPieChart.draw(_newPieDataTable);
110 _oldPieChart.draw(_oldPieDataTable);
111 }
40 112
41 dynamic _columnValue(Map v, int index) { 113 dynamic _columnValue(Map v, int index) {
42 assert(columns.length == 9); 114 assert(index >= 0);
115 assert(index < 9);
43 switch (index) { 116 switch (index) {
44 case 0: 117 case 0:
45 return v['class']['user_name']; 118 return v['class']['user_name'];
46 case 1: 119 case 1:
47 return v['new'][LIVE_AFTER_GC_SIZE] + v['new'][ALLOCATED_SINCE_GC_SIZE]; 120 return v['new'][LIVE_AFTER_GC_SIZE] + v['new'][ALLOCATED_SINCE_GC_SIZE];
48 case 2: 121 case 2:
49 return v['new'][ALLOCATED_SINCE_GC_SIZE]; 122 return v['new'][ALLOCATED_SINCE_GC_SIZE];
50 case 3: 123 case 3:
51 return v['new'][ALLOCATED_BEFORE_GC_SIZE]; 124 return v['new'][ALLOCATED_BEFORE_GC_SIZE];
52 case 4: 125 case 4:
53 return v['new'][LIVE_AFTER_GC_SIZE]; 126 return v['new'][LIVE_AFTER_GC_SIZE];
54 case 5: 127 case 5:
55 return v['old'][LIVE_AFTER_GC_SIZE] + v['old'][ALLOCATED_SINCE_GC_SIZE]; 128 return v['old'][LIVE_AFTER_GC_SIZE] + v['old'][ALLOCATED_SINCE_GC_SIZE];
56 case 6: 129 case 6:
57 return v['old'][ALLOCATED_SINCE_GC_SIZE]; 130 return v['old'][ALLOCATED_SINCE_GC_SIZE];
58 case 7: 131 case 7:
59 return v['old'][ALLOCATED_BEFORE_GC_SIZE]; 132 return v['old'][ALLOCATED_BEFORE_GC_SIZE];
60 case 8: 133 case 8:
61 return v['old'][LIVE_AFTER_GC_SIZE]; 134 return v['old'][LIVE_AFTER_GC_SIZE];
62 } 135 }
63 } 136 }
64 137
65 int _sortColumn(Map a, Map b, int index) {
66 var aValue = _columnValue(a, index);
67 var bValue = _columnValue(b, index);
68 return Comparable.compare(bValue, aValue);
69 }
70
71 _sort() {
72 if ((profile == null) || (profile['members'] is! List) ||
73 (profile['members'].length == 0)) {
74 sortedProfile = toObservable([]);
75 return;
76 }
77 sortedProfile = profile['members'].toList();
78 sortedProfile.sort((a, b) => _sortColumn(a, b, _sortColumnIndex));
79 sortedProfile = toObservable(sortedProfile);
80 notifyPropertyChange(#sortedProfile, [], sortedProfile);
81 notifyPropertyChange(#current, 0, 1);
82 notifyPropertyChange(#allocated, 0, 1);
83 notifyPropertyChange(#beforeGC, 0, 1);
84 notifyPropertyChange(#afterGC, 0, 1);
85 }
86
87 void changeSortColumn(Event e, var detail, Element target) {
88 var message = target.attributes['data-msg'];
89 var index;
90 try {
91 index = int.parse(message);
92 } catch (e) {
93 return;
94 }
95 assert(index is int);
96 assert(index > 0);
97 assert(index < columns.length);
98 _sortColumnIndex = index;
99 _sort();
100 }
101
102 void refreshData(Event e, var detail, Node target) { 138 void refreshData(Event e, var detail, Node target) {
103 var isolateId = app.locationManager.currentIsolateId(); 139 var isolateId = app.locationManager.currentIsolateId();
104 var isolate = app.isolateManager.getIsolate(isolateId); 140 var isolate = app.isolateManager.getIsolate(isolateId);
105 if (isolate == null) { 141 if (isolate == null) {
106 Logger.root.info('No isolate found.'); 142 Logger.root.info('No isolate found.');
107 return; 143 return;
108 } 144 }
109 var request = '/$isolateId/allocationprofile'; 145 var request = '/$isolateId/allocationprofile';
110 app.requestManager.requestMap(request).then((Map response) { 146 app.requestManager.requestMap(request).then((Map response) {
111 assert(response['type'] == 'AllocationProfile'); 147 assert(response['type'] == 'AllocationProfile');
112 profile = response; 148 profile = response;
113 }).catchError((e, st) { 149 }).catchError((e, st) {
114 Logger.root.info('$e $st'); 150 Logger.root.info('$e $st');
115 }); 151 });
116 } 152 }
117 153
118 void profileChanged(oldValue) { 154 void profileChanged(oldValue) {
119 _sort(); 155 _updateChartData();
120 notifyPropertyChange(#status, [], status); 156 notifyPropertyChange(#formattedAverage, [], formattedAverage);
157 notifyPropertyChange(#formattedTotalCollectionTime, [],
158 formattedTotalCollectionTime);
159 notifyPropertyChange(#formattedCollections, [], formattedCollections);
121 } 160 }
122 161
123 String status(bool new_space) { 162 @observable String formattedAverage(bool newSpace) {
124 if (profile == null) { 163 if (profile == null) {
125 return ''; 164 return '';
126 } 165 }
127 String space = new_space ? 'new' : 'old'; 166 String space = newSpace ? 'new' : 'old';
128 Map heap = profile['heaps'][space]; 167 Map heap = profile['heaps'][space];
129 var usage = '${ObservatoryApplication.scaledSizeUnits(heap['used'])} / ' 168 var r = ((heap['time'] * 1000.0) / heap['collections']).toStringAsFixed(2);
130 '${ObservatoryApplication.scaledSizeUnits(heap['capacity'])}'; 169 return '$r ms';
131 var timings = '${ObservatoryApplication.timeUnits(heap['time'])} secs';
132 var collections = '${heap['collections']} collections';
133 var avgTime = '${(heap['time'] * 1000.0) / heap['collections']} ms';
134 return '$usage ($timings) [$collections] $avgTime';
135 } 170 }
136 171
137 String current(Map cls, bool new_space, [bool instances = false]) { 172 @observable String formattedCollections(bool newSpace) {
138 if (cls is !Map) { 173 if (profile == null) {
139 return ''; 174 return '';
140 } 175 }
141 List data = cls[new_space ? 'new' : 'old']; 176 String space = newSpace ? 'new' : 'old';
142 if (data == null) { 177 Map heap = profile['heaps'][space];
178 return '${heap['collections']}';
179 }
180
181 @observable String formattedTotalCollectionTime(bool newSpace) {
182 if (profile == null) {
143 return ''; 183 return '';
144 } 184 }
145 int current = data[instances ? LIVE_AFTER_GC : LIVE_AFTER_GC_SIZE] + 185 String space = newSpace ? 'new' : 'old';
146 data[instances ? ALLOCATED_SINCE_GC : ALLOCATED_SINCE_GC_SIZE]; 186 Map heap = profile['heaps'][space];
147 if (instances) { 187 return '${ObservatoryApplication.timeUnits(heap['time'])} secs';
148 return '$current';
149 }
150 return ObservatoryApplication.scaledSizeUnits(current);
151 }
152
153 String allocated(Map cls, bool new_space, [bool instances = false]) {
154 if (cls is !Map) {
155 return '';
156 }
157 List data = cls[new_space ? 'new' : 'old'];
158 if (data == null) {
159 return '';
160 }
161 int current =
162 data[instances ? ALLOCATED_SINCE_GC : ALLOCATED_SINCE_GC_SIZE];
163 if (instances) {
164 return '$current';
165 }
166 return ObservatoryApplication.scaledSizeUnits(current);
167 }
168
169 String beforeGC(Map cls, bool new_space, [bool instances = false]) {
170 if (cls is! Map) {
171 return '';
172 }
173 List data = cls[new_space ? 'new' : 'old'];
174 if (data == null) {
175 return '';
176 }
177 int current =
178 data[instances ? ALLOCATED_BEFORE_GC : ALLOCATED_BEFORE_GC_SIZE];
179 if (instances) {
180 return '$current';
181 }
182 return ObservatoryApplication.scaledSizeUnits(current);
183 }
184
185 String afterGC(Map cls, bool new_space, [bool instances = false]) {
186 if (cls is! Map) {
187 return '';
188 }
189 List data = cls[new_space ? 'new' : 'old'];
190 if (data == null) {
191 return '';
192 }
193 int current = data[instances ? LIVE_AFTER_GC : LIVE_AFTER_GC_SIZE];
194 if (instances) {
195 return '$current';
196 }
197 return ObservatoryApplication.scaledSizeUnits(current);
198 } 188 }
199 } 189 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698