| 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/app.dart'; |
| 10 import 'package:observatory/service.dart'; | 10 import 'package:observatory/service.dart'; |
| (...skipping 24 matching lines...) Expand all Loading... |
| 35 var _newPieDataTable; | 35 var _newPieDataTable; |
| 36 var _newPieChart; | 36 var _newPieChart; |
| 37 | 37 |
| 38 // Pie chart of old space usage. | 38 // Pie chart of old space usage. |
| 39 var _oldPieDataTable; | 39 var _oldPieDataTable; |
| 40 var _oldPieChart; | 40 var _oldPieChart; |
| 41 | 41 |
| 42 @observable ClassSortedTable classTable; | 42 @observable ClassSortedTable classTable; |
| 43 var _classTableBody; | 43 var _classTableBody; |
| 44 | 44 |
| 45 @published ServiceMap profile; | |
| 46 @published bool autoRefresh = false; | 45 @published bool autoRefresh = false; |
| 47 var _subscription; | 46 var _subscription; |
| 48 | 47 |
| 49 @observable Isolate isolate; | 48 @published Isolate isolate; |
| 49 @observable ServiceMap profile; |
| 50 | 50 |
| 51 HeapProfileElement.created() : super.created() { | 51 HeapProfileElement.created() : super.created() { |
| 52 // Create pie chart models. | 52 // Create pie chart models. |
| 53 _newPieDataTable = new DataTable(); | 53 _newPieDataTable = new DataTable(); |
| 54 _newPieDataTable.addColumn('string', 'Type'); | 54 _newPieDataTable.addColumn('string', 'Type'); |
| 55 _newPieDataTable.addColumn('number', 'Size'); | 55 _newPieDataTable.addColumn('number', 'Size'); |
| 56 _oldPieDataTable = new DataTable(); | 56 _oldPieDataTable = new DataTable(); |
| 57 _oldPieDataTable.addColumn('string', 'Type'); | 57 _oldPieDataTable.addColumn('string', 'Type'); |
| 58 _oldPieDataTable.addColumn('number', 'Size'); | 58 _oldPieDataTable.addColumn('number', 'Size'); |
| 59 | 59 |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 92 shadowRoot.querySelector('#newPieChart')); | 92 shadowRoot.querySelector('#newPieChart')); |
| 93 _oldPieChart = new Chart('PieChart', | 93 _oldPieChart = new Chart('PieChart', |
| 94 shadowRoot.querySelector('#oldPieChart')); | 94 shadowRoot.querySelector('#oldPieChart')); |
| 95 _classTableBody = shadowRoot.querySelector('#classTableBody'); | 95 _classTableBody = shadowRoot.querySelector('#classTableBody'); |
| 96 _subscription = app.vm.events.stream.where( | 96 _subscription = app.vm.events.stream.where( |
| 97 (event) => event.isolate == isolate).listen(_onEvent); | 97 (event) => event.isolate == isolate).listen(_onEvent); |
| 98 } | 98 } |
| 99 | 99 |
| 100 @override | 100 @override |
| 101 void detached() { | 101 void detached() { |
| 102 _subscription.cancel(); | 102 _subscription.cancel((){}); |
| 103 super.detached(); | 103 super.detached(); |
| 104 } | 104 } |
| 105 | 105 |
| 106 void _onEvent(ServiceEvent event) { | 106 void _onEvent(ServiceEvent event) { |
| 107 if (autoRefresh && event.eventType == 'GC') { | 107 if (autoRefresh && event.eventType == 'GC') { |
| 108 refresh((){}); | 108 refresh((){}); |
| 109 } | 109 } |
| 110 } | 110 } |
| 111 | 111 |
| 112 void _updatePieCharts() { | 112 void _updatePieCharts() { |
| 113 assert(profile != null); | 113 assert(profile != null); |
| 114 _newPieDataTable.clearRows(); | 114 _newPieDataTable.clearRows(); |
| 115 var isolate = profile.isolate; | |
| 116 _newPieDataTable.addRow(['Used', isolate.newSpace.used]); | 115 _newPieDataTable.addRow(['Used', isolate.newSpace.used]); |
| 117 _newPieDataTable.addRow(['Free', | 116 _newPieDataTable.addRow(['Free', |
| 118 isolate.newSpace.capacity - isolate.newSpace.used]); | 117 isolate.newSpace.capacity - isolate.newSpace.used]); |
| 119 _newPieDataTable.addRow(['External', isolate.newSpace.external]); | 118 _newPieDataTable.addRow(['External', isolate.newSpace.external]); |
| 120 _oldPieDataTable.clearRows(); | 119 _oldPieDataTable.clearRows(); |
| 121 _oldPieDataTable.addRow(['Used', isolate.oldSpace.used]); | 120 _oldPieDataTable.addRow(['Used', isolate.oldSpace.used]); |
| 122 _oldPieDataTable.addRow(['Free', | 121 _oldPieDataTable.addRow(['Free', |
| 123 isolate.oldSpace.capacity - isolate.oldSpace.used]); | 122 isolate.oldSpace.capacity - isolate.oldSpace.used]); |
| 124 _oldPieDataTable.addRow(['External', isolate.oldSpace.external]); | 123 _oldPieDataTable.addRow(['External', isolate.oldSpace.external]); |
| 125 } | 124 } |
| (...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 252 classTable.sortColumnIndex = target.cellIndex; | 251 classTable.sortColumnIndex = target.cellIndex; |
| 253 classTable.sortDescending = true; | 252 classTable.sortDescending = true; |
| 254 } else { | 253 } else { |
| 255 classTable.sortDescending = !classTable.sortDescending; | 254 classTable.sortDescending = !classTable.sortDescending; |
| 256 } | 255 } |
| 257 classTable.sort(); | 256 classTable.sort(); |
| 258 _updateClassTableInDom(); | 257 _updateClassTableInDom(); |
| 259 } | 258 } |
| 260 } | 259 } |
| 261 | 260 |
| 262 void refresh(var done) { | 261 void isolateChanged(oldValue) { |
| 263 if (profile == null) { | 262 if (isolate == null) { |
| 263 profile = null; |
| 264 return; | 264 return; |
| 265 } | 265 } |
| 266 var isolate = profile.isolate; | 266 isolate.invokeRpc('getAllocationProfile', {}).then(_update); |
| 267 isolate.get('/allocationprofile').then(_update).whenComplete(done); | 267 } |
| 268 |
| 269 void refresh(var done) { |
| 270 if (isolate == null) { |
| 271 return; |
| 272 } |
| 273 isolate.invokeRpc('getAllocationProfile', {}) |
| 274 .then(_update).whenComplete(done); |
| 268 } | 275 } |
| 269 | 276 |
| 270 void refreshGC(var done) { | 277 void refreshGC(var done) { |
| 271 if (profile == null) { | 278 if (isolate == null) { |
| 272 return; | 279 return; |
| 273 } | 280 } |
| 274 var isolate = profile.isolate; | 281 isolate.invokeRpc('getAllocationProfile', { 'gc': 'full' }) |
| 275 isolate.get('/allocationprofile?gc=full').then(_update).whenComplete(done); | 282 .then(_update).whenComplete(done); |
| 276 } | 283 } |
| 277 | 284 |
| 278 void resetAccumulator(var done) { | 285 void resetAccumulator(var done) { |
| 279 if (profile == null) { | 286 if (isolate == null) { |
| 280 return; | 287 return; |
| 281 } | 288 } |
| 282 var isolate = profile.isolate; | 289 isolate.invokeRpc('getAllocationProfile', { 'reset': 'true' }) |
| 283 isolate.get('/allocationprofile?reset=true').then(_update). | 290 .then(_update).whenComplete(done); |
| 284 whenComplete(done); | |
| 285 } | 291 } |
| 286 | 292 |
| 287 void _update(ServiceMap newProfile) { | 293 void _update(ServiceMap newProfile) { |
| 288 profile = newProfile; | 294 profile = newProfile; |
| 289 } | 295 } |
| 290 | 296 |
| 291 void profileChanged(oldValue) { | 297 void profileChanged(oldValue) { |
| 292 if (profile == null) { | 298 if (profile == null) { |
| 293 return; | 299 return; |
| 294 } | 300 } |
| 295 isolate = profile.isolate; | |
| 296 isolate.updateHeapsFromMap(profile['heaps']); | 301 isolate.updateHeapsFromMap(profile['heaps']); |
| 297 var millis = int.parse(profile['dateLastAccumulatorReset']); | 302 var millis = int.parse(profile['dateLastAccumulatorReset']); |
| 298 if (millis != 0) { | 303 if (millis != 0) { |
| 299 lastAccumulatorReset = | 304 lastAccumulatorReset = |
| 300 new DateTime.fromMillisecondsSinceEpoch(millis).toString(); | 305 new DateTime.fromMillisecondsSinceEpoch(millis).toString(); |
| 301 } | 306 } |
| 302 millis = int.parse(profile['dateLastServiceGC']); | 307 millis = int.parse(profile['dateLastServiceGC']); |
| 303 if (millis != 0) { | 308 if (millis != 0) { |
| 304 lastServiceGC = | 309 lastServiceGC = |
| 305 new DateTime.fromMillisecondsSinceEpoch(millis).toString(); | 310 new DateTime.fromMillisecondsSinceEpoch(millis).toString(); |
| 306 } | 311 } |
| 307 _updatePieCharts(); | 312 _updatePieCharts(); |
| 308 _updateClasses(); | 313 _updateClasses(); |
| 309 _updateClassTable(); | 314 _updateClassTable(); |
| 310 _updateClassTableInDom(); | 315 _updateClassTableInDom(); |
| 311 _drawCharts(); | 316 _drawCharts(); |
| 312 notifyPropertyChange(#formattedAverage, 0, 1); | 317 notifyPropertyChange(#formattedAverage, 0, 1); |
| 313 notifyPropertyChange(#formattedTotalCollectionTime, 0, 1); | 318 notifyPropertyChange(#formattedTotalCollectionTime, 0, 1); |
| 314 notifyPropertyChange(#formattedCollections, 0, 1); | 319 notifyPropertyChange(#formattedCollections, 0, 1); |
| 315 } | 320 } |
| 316 | 321 |
| 317 @observable String formattedAverage(bool newSpace) { | 322 @observable String formattedAverage(bool newSpace) { |
| 318 if (profile == null) { | 323 if (profile == null) { |
| 319 return ''; | 324 return ''; |
| 320 } | 325 } |
| 321 var heap = newSpace ? profile.isolate.newSpace : profile.isolate.oldSpace; | 326 var heap = newSpace ? isolate.newSpace : isolate.oldSpace; |
| 322 var avg = ((heap.totalCollectionTimeInSeconds * 1000.0) / heap.collections); | 327 var avg = ((heap.totalCollectionTimeInSeconds * 1000.0) / heap.collections); |
| 323 return '${avg.toStringAsFixed(2)} ms'; | 328 return '${avg.toStringAsFixed(2)} ms'; |
| 324 } | 329 } |
| 325 | 330 |
| 326 @observable String formattedCollections(bool newSpace) { | 331 @observable String formattedCollections(bool newSpace) { |
| 327 if (profile == null) { | 332 if (profile == null) { |
| 328 return ''; | 333 return ''; |
| 329 } | 334 } |
| 330 var heap = newSpace ? profile.isolate.newSpace : profile.isolate.oldSpace; | 335 var heap = newSpace ? isolate.newSpace : isolate.oldSpace; |
| 331 return heap.collections.toString(); | 336 return heap.collections.toString(); |
| 332 } | 337 } |
| 333 | 338 |
| 334 @observable String formattedTotalCollectionTime(bool newSpace) { | 339 @observable String formattedTotalCollectionTime(bool newSpace) { |
| 335 if (profile == null) { | 340 if (profile == null) { |
| 336 return ''; | 341 return ''; |
| 337 } | 342 } |
| 338 var heap = newSpace ? profile.isolate.newSpace : profile.isolate.oldSpace; | 343 var heap = newSpace ? isolate.newSpace : isolate.oldSpace; |
| 339 return '${Utils.formatSeconds(heap.totalCollectionTimeInSeconds)} secs'; | 344 return '${Utils.formatSeconds(heap.totalCollectionTimeInSeconds)} secs'; |
| 340 } | 345 } |
| 341 } | 346 } |
| OLD | NEW |