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