| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 isolate_view_element; | 5 library isolate_view_element; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'observatory_element.dart'; | 8 import 'observatory_element.dart'; |
| 9 import 'package:observatory/app.dart'; | |
| 10 import 'package:observatory/service.dart'; | 9 import 'package:observatory/service.dart'; |
| 11 import 'package:polymer/polymer.dart'; | 10 import 'package:polymer/polymer.dart'; |
| 12 | 11 |
| 13 class TagProfileChart { | |
| 14 var _table = new DataTable(); | |
| 15 var _chart; | |
| 16 | |
| 17 void update(TagProfile tagProfile) { | |
| 18 if (_table.columns == 0) { | |
| 19 // Initialize. | |
| 20 _table.addColumn('string', 'Time'); | |
| 21 for (var tagName in tagProfile.names) { | |
| 22 if (tagName == 'Idle') { | |
| 23 // Skip Idle tag. | |
| 24 continue; | |
| 25 } | |
| 26 _table.addColumn('number', tagName); | |
| 27 } | |
| 28 } | |
| 29 _table.clearRows(); | |
| 30 var idleIndex = tagProfile.names.indexOf('Idle'); | |
| 31 assert(idleIndex != -1); | |
| 32 var t = tagProfile.updatedAtSeconds; | |
| 33 for (var i = 0; i < tagProfile.snapshots.length; i++) { | |
| 34 var snapshotTime = tagProfile.snapshots[i].seconds; | |
| 35 var row = []; | |
| 36 if (snapshotTime > 0.0) { | |
| 37 row.add('t ${(snapshotTime - t).toStringAsFixed(2)}'); | |
| 38 } else { | |
| 39 row.add(''); | |
| 40 } | |
| 41 var sum = tagProfile.snapshots[i].sum; | |
| 42 if (sum == 0) { | |
| 43 for (var j = 0; j < tagProfile.snapshots[i].counters.length; j++) { | |
| 44 if (j == idleIndex) { | |
| 45 // Skip idle. | |
| 46 continue; | |
| 47 } | |
| 48 row.add(0); | |
| 49 } | |
| 50 } else { | |
| 51 for (var j = 0; j < tagProfile.snapshots[i].counters.length; j++) { | |
| 52 if (j == idleIndex) { | |
| 53 // Skip idle. | |
| 54 continue; | |
| 55 } | |
| 56 var percentage = tagProfile.snapshots[i].counters[j] / sum * 100.0; | |
| 57 row.add(percentage.toInt()); | |
| 58 } | |
| 59 } | |
| 60 _table.addRow(row); | |
| 61 } | |
| 62 } | |
| 63 | |
| 64 void draw(var element) { | |
| 65 if (_chart == null) { | |
| 66 assert(element != null); | |
| 67 _chart = new Chart('SteppedAreaChart', element); | |
| 68 _chart.options['isStacked'] = true; | |
| 69 _chart.options['connectSteps'] = false; | |
| 70 _chart.options['vAxis'] = { | |
| 71 'minValue': 0.0, | |
| 72 'maxValue': 100.0, | |
| 73 }; | |
| 74 } | |
| 75 _chart.draw(_table); | |
| 76 } | |
| 77 } | |
| 78 | |
| 79 @CustomTag('isolate-view') | 12 @CustomTag('isolate-view') |
| 80 class IsolateViewElement extends ObservatoryElement { | 13 class IsolateViewElement extends ObservatoryElement { |
| 81 @published Isolate isolate; | 14 @published Isolate isolate; |
| 82 @published Library rootLibrary; | 15 @published Library rootLibrary; |
| 83 Timer _updateTimer; | |
| 84 TagProfileChart tagProfileChart = new TagProfileChart(); | |
| 85 IsolateViewElement.created() : super.created(); | 16 IsolateViewElement.created() : super.created(); |
| 86 | 17 |
| 87 Future<ServiceObject> evaluate(String expression) { | 18 Future<ServiceObject> evaluate(String expression) { |
| 88 return isolate.rootLibrary.evaluate(expression); | 19 return isolate.rootLibrary.evaluate(expression); |
| 89 } | 20 } |
| 90 | 21 |
| 91 void _updateTagProfile() { | |
| 92 isolate.updateTagProfile().then((tagProfile) { | |
| 93 tagProfileChart.update(tagProfile); | |
| 94 _drawTagProfileChart(); | |
| 95 if (_updateTimer != null) { | |
| 96 // Start the timer again. | |
| 97 _updateTimer = new Timer(new Duration(seconds: 1), _updateTagProfile); | |
| 98 } | |
| 99 }); | |
| 100 } | |
| 101 | |
| 102 @override | |
| 103 void attached() { | 22 void attached() { |
| 104 super.attached(); | 23 super.attached(); |
| 105 // Start a timer to update the isolate summary once a second. | |
| 106 _updateTimer = new Timer(new Duration(seconds: 1), _updateTagProfile); | |
| 107 if (isolate.topFrame != null) { | 24 if (isolate.topFrame != null) { |
| 108 isolate.topFrame.function.load(); | 25 isolate.topFrame.function.load(); |
| 109 } | 26 } |
| 110 isolate.rootLibrary.load().then((lib) => rootLibrary = lib); | 27 isolate.rootLibrary.load().then((lib) => rootLibrary = lib); |
| 111 } | 28 } |
| 112 | 29 |
| 113 @override | |
| 114 void detached() { | |
| 115 super.detached(); | |
| 116 if (_updateTimer != null) { | |
| 117 _updateTimer.cancel(); | |
| 118 _updateTimer = null; | |
| 119 } | |
| 120 } | |
| 121 | |
| 122 void _drawTagProfileChart() { | |
| 123 var element = shadowRoot.querySelector('#tagProfileChart'); | |
| 124 if (element != null) { | |
| 125 tagProfileChart.draw(element); | |
| 126 } | |
| 127 } | |
| 128 | |
| 129 Future refresh() async { | 30 Future refresh() async { |
| 130 await isolate.reload(); | 31 await isolate.reload(); |
| 131 if (isolate.topFrame != null) { | 32 if (isolate.topFrame != null) { |
| 132 await isolate.topFrame.function.load(); | 33 await isolate.topFrame.function.load(); |
| 133 } | 34 } |
| 134 } | 35 } |
| 135 | 36 |
| 136 Future refreshCoverage() { | 37 Future refreshCoverage() { |
| 137 return isolate.refreshCoverage(); | 38 return isolate.refreshCoverage(); |
| 138 } | 39 } |
| 139 } | 40 } |
| OLD | NEW |