| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 timeline_page_element; | 5 library timeline_page_element; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:html'; | 9 import 'dart:html'; |
| 10 import 'observatory_element.dart'; | 10 import 'observatory_element.dart'; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 return label; | 90 return label; |
| 91 } | 91 } |
| 92 | 92 |
| 93 void _refreshRecorderUI() { | 93 void _refreshRecorderUI() { |
| 94 DivElement e = $['streamList']; | 94 DivElement e = $['streamList']; |
| 95 e.children.clear(); | 95 e.children.clear(); |
| 96 | 96 |
| 97 for (String streamName in _availableStreams) { | 97 for (String streamName in _availableStreams) { |
| 98 e.children.add(_makeStreamToggle(streamName)); | 98 e.children.add(_makeStreamToggle(streamName)); |
| 99 } | 99 } |
| 100 |
| 101 streamPresetSelector = streamPresetFromRecordedStreams(); |
| 102 } |
| 103 |
| 104 // Dart developers care about the following streams: |
| 105 List<String> _dartPreset = |
| 106 ['GC', 'Compiler', 'Dart']; |
| 107 |
| 108 // VM developers care about the following streams: |
| 109 List<String> _vmPreset = |
| 110 ['GC', 'Compiler', 'Dart', 'Debugger', 'Embedder', 'Isolate', 'VM']; |
| 111 |
| 112 String streamPresetFromRecordedStreams() { |
| 113 if (_availableStreams.length == 0) { |
| 114 return 'None'; |
| 115 } |
| 116 if (_recordedStreams.length == 0) { |
| 117 return 'None'; |
| 118 } |
| 119 if (_recordedStreams.length == _availableStreams.length) { |
| 120 return 'All'; |
| 121 } |
| 122 if ((_vmPreset.length == _recordedStreams.length) && |
| 123 _recordedStreams.containsAll(_vmPreset)) { |
| 124 return 'VM'; |
| 125 } |
| 126 if ((_dartPreset.length == _recordedStreams.length) && |
| 127 _recordedStreams.containsAll(_dartPreset)) { |
| 128 return 'Dart'; |
| 129 } |
| 130 return 'Custom'; |
| 131 } |
| 132 |
| 133 void _applyPreset() { |
| 134 switch (streamPresetSelector) { |
| 135 case 'None': |
| 136 _recordedStreams.clear(); |
| 137 break; |
| 138 case 'All': |
| 139 _recordedStreams.clear(); |
| 140 _recordedStreams.addAll(_availableStreams); |
| 141 break; |
| 142 case 'VM': |
| 143 _recordedStreams.clear(); |
| 144 _recordedStreams.addAll(_vmPreset); |
| 145 break; |
| 146 case 'Dart': |
| 147 _recordedStreams.clear(); |
| 148 _recordedStreams.addAll(_dartPreset); |
| 149 break; |
| 150 case 'Custom': |
| 151 return; |
| 152 } |
| 153 _applyStreamChanges(); |
| 154 _updateRecorderUI(); |
| 100 } | 155 } |
| 101 | 156 |
| 102 Future _updateRecorderUI() async { | 157 Future _updateRecorderUI() async { |
| 103 // Grab the current timeline flags. | 158 // Grab the current timeline flags. |
| 104 ServiceMap response = await app.vm.invokeRpc('_getVMTimelineFlags', {}); | 159 ServiceMap response = await app.vm.invokeRpc('_getVMTimelineFlags', {}); |
| 105 assert(response['type'] == 'TimelineFlags'); | 160 assert(response['type'] == 'TimelineFlags'); |
| 106 // Process them so we know available streams. | 161 // Process them so we know available streams. |
| 107 _processFlags(response); | 162 _processFlags(response); |
| 108 // Refresh the UI. | 163 // Refresh the UI. |
| 109 _refreshRecorderUI(); | 164 _refreshRecorderUI(); |
| 110 } | 165 } |
| 111 | 166 |
| 112 Future _setupInitialState() async { | 167 Future _setupInitialState() async { |
| 113 await _updateRecorderUI(); | 168 await _updateRecorderUI(); |
| 169 SelectElement e = $['selectPreset']; |
| 170 e.onChange.listen((_) { |
| 171 _applyPreset(); |
| 172 }); |
| 114 // Finally, trigger a reload so we start with the latest timeline. | 173 // Finally, trigger a reload so we start with the latest timeline. |
| 115 await refresh(); | 174 await refresh(); |
| 116 } | 175 } |
| 117 | 176 |
| 118 Future refresh() async { | 177 Future refresh() async { |
| 119 await app.vm.reload(); | 178 await app.vm.reload(); |
| 120 await app.vm.reloadIsolates(); | 179 await app.vm.reloadIsolates(); |
| 121 return postMessage('refresh'); | 180 return postMessage('refresh'); |
| 122 } | 181 } |
| 123 | 182 |
| (...skipping 16 matching lines...) Expand all Loading... |
| 140 final top = e.offset.top; | 199 final top = e.offset.top; |
| 141 final bottomMargin = 32; | 200 final bottomMargin = 32; |
| 142 final mainHeight = totalHeight - top - bottomMargin; | 201 final mainHeight = totalHeight - top - bottomMargin; |
| 143 e.style.setProperty('height', '${mainHeight}px'); | 202 e.style.setProperty('height', '${mainHeight}px'); |
| 144 e.style.setProperty('width', '100%'); | 203 e.style.setProperty('width', '100%'); |
| 145 } | 204 } |
| 146 | 205 |
| 147 | 206 |
| 148 StreamSubscription _resizeSubscription; | 207 StreamSubscription _resizeSubscription; |
| 149 @observable String recorderName; | 208 @observable String recorderName; |
| 209 @observable String streamPresetSelector = 'None'; |
| 150 final Set<String> _availableStreams = new Set<String>(); | 210 final Set<String> _availableStreams = new Set<String>(); |
| 151 final Set<String> _recordedStreams = new Set<String>(); | 211 final Set<String> _recordedStreams = new Set<String>(); |
| 152 } | 212 } |
| OLD | NEW |