| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library isolate_view_element; | |
| 6 | |
| 7 import 'dart:async'; | |
| 8 import 'observatory_element.dart'; | |
| 9 import 'package:observatory/app.dart'; | |
| 10 import 'package:observatory/service.dart'; | |
| 11 import 'package:polymer/polymer.dart'; | |
| 12 | |
| 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') | |
| 80 class IsolateViewElement extends ObservatoryElement { | |
| 81 @published Isolate isolate; | |
| 82 Timer _updateTimer; | |
| 83 TagProfileChart tagProfileChart = new TagProfileChart(); | |
| 84 IsolateViewElement.created() : super.created(); | |
| 85 | |
| 86 Future<ServiceObject> eval(String text) { | |
| 87 return isolate.get( | |
| 88 isolate.rootLib.id + "/eval?expr=${Uri.encodeComponent(text)}"); | |
| 89 } | |
| 90 | |
| 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() { | |
| 104 super.attached(); | |
| 105 // Start a timer to update the isolate summary once a second. | |
| 106 _updateTimer = new Timer(new Duration(seconds: 1), _updateTagProfile); | |
| 107 } | |
| 108 | |
| 109 @override | |
| 110 void detached() { | |
| 111 super.detached(); | |
| 112 if (_updateTimer != null) { | |
| 113 _updateTimer.cancel(); | |
| 114 _updateTimer = null; | |
| 115 } | |
| 116 } | |
| 117 | |
| 118 void _drawTagProfileChart() { | |
| 119 var element = shadowRoot.querySelector('#tagProfileChart'); | |
| 120 if (element != null) { | |
| 121 tagProfileChart.draw(element); | |
| 122 } | |
| 123 } | |
| 124 | |
| 125 void refresh(var done) { | |
| 126 isolate.reload().whenComplete(done); | |
| 127 } | |
| 128 | |
| 129 void refreshCoverage(var done) { | |
| 130 isolate.refreshCoverage().whenComplete(done); | |
| 131 } | |
| 132 | |
| 133 Future pause(_) { | |
| 134 return isolate.get("debug/pause").then((result) { | |
| 135 // TODO(turnidge): Instead of asserting here, handle errors | |
| 136 // properly. | |
| 137 assert(result.type == 'Success'); | |
| 138 return isolate.reload(); | |
| 139 }); | |
| 140 } | |
| 141 | |
| 142 Future resume(_) { | |
| 143 return isolate.get("resume").then((result) { | |
| 144 // TODO(turnidge): Instead of asserting here, handle errors | |
| 145 // properly. | |
| 146 assert(result.type == 'Success'); | |
| 147 return isolate.reload(); | |
| 148 }); | |
| 149 } | |
| 150 } | |
| OLD | NEW |