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 part of app; | 5 part of app; |
6 | 6 |
7 /// The observatory application. Instances of this are created and owned | 7 /// The observatory application. Instances of this are created and owned |
8 /// by the observatory_application custom element. | 8 /// by the observatory_application custom element. |
9 class ObservatoryApplication extends Observable { | 9 class ObservatoryApplication extends Observable { |
10 static ObservatoryApplication app; | 10 static ObservatoryApplication app; |
11 final _pageRegistry = new List<Page>(); | 11 final _pageRegistry = new List<Page>(); |
| 12 LocationManager _locationManager; |
| 13 LocationManager get locationManager => _locationManager; |
12 @observable Page currentPage; | 14 @observable Page currentPage; |
13 @observable final LocationManager locationManager; | |
14 VM _vm; | 15 VM _vm; |
15 VM get vm => _vm; | 16 VM get vm => _vm; |
16 set vm(VM vm) { | 17 set vm(VM vm) { |
17 if (_vm == vm) { | 18 if (_vm == vm) { |
18 // Do nothing. | 19 // Do nothing. |
19 return; | 20 return; |
20 } | 21 } |
21 if (_vm != null) { | 22 if (_vm != null) { |
22 // Disconnect from current VM. | 23 // Disconnect from current VM. |
23 notifications.clear(); | 24 notifications.clear(); |
(...skipping 11 matching lines...) Expand all Loading... |
35 } | 36 } |
36 final TargetManager targets; | 37 final TargetManager targets; |
37 @reflectable final ObservatoryApplicationElement rootElement; | 38 @reflectable final ObservatoryApplicationElement rootElement; |
38 | 39 |
39 TraceViewElement _traceView = null; | 40 TraceViewElement _traceView = null; |
40 | 41 |
41 @reflectable ServiceObject lastErrorOrException; | 42 @reflectable ServiceObject lastErrorOrException; |
42 @observable ObservableList<ServiceEvent> notifications = | 43 @observable ObservableList<ServiceEvent> notifications = |
43 new ObservableList<ServiceEvent>(); | 44 new ObservableList<ServiceEvent>(); |
44 | 45 |
45 void _initOnce(bool chromium) { | 46 void _initOnce() { |
46 assert(app == null); | 47 assert(app == null); |
47 app = this; | 48 app = this; |
48 _registerPages(); | 49 _registerPages(); |
49 Analytics.initialize(); | 50 Analytics.initialize(); |
50 locationManager._init(this); | 51 // Visit the current page. |
| 52 locationManager._visit(); |
51 } | 53 } |
52 | 54 |
53 void removePauseEvents(Isolate isolate) { | 55 void removePauseEvents(Isolate isolate) { |
54 bool isPauseEvent(var event) { | 56 bool isPauseEvent(var event) { |
55 return (event.eventType == ServiceEvent.kPauseStart || | 57 return (event.eventType == ServiceEvent.kPauseStart || |
56 event.eventType == ServiceEvent.kPauseExit || | 58 event.eventType == ServiceEvent.kPauseExit || |
57 event.eventType == ServiceEvent.kPauseBreakpoint || | 59 event.eventType == ServiceEvent.kPauseBreakpoint || |
58 event.eventType == ServiceEvent.kPauseInterrupted || | 60 event.eventType == ServiceEvent.kPauseInterrupted || |
59 event.eventType == ServiceEvent.kPauseException); | 61 event.eventType == ServiceEvent.kPauseException); |
60 } | 62 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
98 } | 100 } |
99 } | 101 } |
100 | 102 |
101 void _registerPages() { | 103 void _registerPages() { |
102 _pageRegistry.add(new VMPage(this)); | 104 _pageRegistry.add(new VMPage(this)); |
103 _pageRegistry.add(new FlagsPage(this)); | 105 _pageRegistry.add(new FlagsPage(this)); |
104 _pageRegistry.add(new InspectPage(this)); | 106 _pageRegistry.add(new InspectPage(this)); |
105 _pageRegistry.add(new ClassTreePage(this)); | 107 _pageRegistry.add(new ClassTreePage(this)); |
106 _pageRegistry.add(new DebuggerPage(this)); | 108 _pageRegistry.add(new DebuggerPage(this)); |
107 _pageRegistry.add(new CpuProfilerPage(this)); | 109 _pageRegistry.add(new CpuProfilerPage(this)); |
| 110 _pageRegistry.add(new TableCpuProfilerPage(this)); |
108 _pageRegistry.add(new AllocationProfilerPage(this)); | 111 _pageRegistry.add(new AllocationProfilerPage(this)); |
109 _pageRegistry.add(new HeapMapPage(this)); | 112 _pageRegistry.add(new HeapMapPage(this)); |
110 _pageRegistry.add(new VMConnectPage(this)); | 113 _pageRegistry.add(new VMConnectPage(this)); |
111 _pageRegistry.add(new ErrorViewPage(this)); | 114 _pageRegistry.add(new ErrorViewPage(this)); |
112 _pageRegistry.add(new MetricsPage(this)); | 115 _pageRegistry.add(new MetricsPage(this)); |
113 // Note that ErrorPage must be the last entry in the list as it is | 116 // Note that ErrorPage must be the last entry in the list as it is |
114 // the catch all. | 117 // the catch all. |
115 _pageRegistry.add(new ErrorPage(this)); | 118 _pageRegistry.add(new ErrorPage(this)); |
116 } | 119 } |
117 | 120 |
118 void _onError(ServiceError error) { | 121 void _onError(ServiceError error) { |
119 lastErrorOrException = error; | 122 lastErrorOrException = error; |
120 _visit('error/', null); | 123 _visit(Uri.parse('error/'), null); |
121 } | 124 } |
122 | 125 |
123 void _onException(ServiceException exception) { | 126 void _onException(ServiceException exception) { |
124 lastErrorOrException = exception; | 127 lastErrorOrException = exception; |
125 if (exception.kind == 'NetworkException') { | 128 if (exception.kind == 'NetworkException') { |
126 // Got a network exception, visit the vm-connect page. | 129 // Got a network exception, visit the vm-connect page. |
127 this.vm = null; | 130 this.vm = null; |
128 locationManager.go(locationManager.makeLink('/vm-connect/')); | 131 locationManager.go(locationManager.makeLink('/vm-connect/')); |
129 } else { | 132 } else { |
130 _visit('error/', null); | 133 _visit(Uri.parse('error/'), null); |
131 } | 134 } |
132 } | 135 } |
133 | 136 |
134 void _visit(String url, String args) { | 137 void _visit(Uri uri, Map internalArguments) { |
135 var argsMap; | 138 if (internalArguments['trace'] != null) { |
136 if (args == null) { | 139 var traceArg = internalArguments['trace']; |
137 argsMap = {}; | |
138 } else { | |
139 argsMap = Uri.splitQueryString(args); | |
140 } | |
141 if (argsMap['trace'] != null) { | |
142 var traceArg = argsMap['trace']; | |
143 if (traceArg == 'on') { | 140 if (traceArg == 'on') { |
144 Tracer.start(); | 141 Tracer.start(); |
145 } else if (traceArg == 'off') { | 142 } else if (traceArg == 'off') { |
146 Tracer.stop(); | 143 Tracer.stop(); |
147 } | 144 } |
148 } | 145 } |
149 if (Tracer.current != null) { | 146 if (Tracer.current != null) { |
150 Tracer.current.reset(); | 147 Tracer.current.reset(); |
151 } | 148 } |
152 if (_traceView != null) { | 149 if (_traceView != null) { |
153 _traceView.tracer = Tracer.current; | 150 _traceView.tracer = Tracer.current; |
154 } | 151 } |
155 Uri uri = Uri.parse(url); | |
156 for (var i = 0; i < _pageRegistry.length; i++) { | 152 for (var i = 0; i < _pageRegistry.length; i++) { |
157 var page = _pageRegistry[i]; | 153 var page = _pageRegistry[i]; |
158 if (page.canVisit(uri)) { | 154 if (page.canVisit(uri)) { |
159 _installPage(page); | 155 _installPage(page); |
160 page.visit(uri, argsMap); | 156 page.visit(uri, internalArguments); |
161 return; | 157 return; |
162 } | 158 } |
163 } | 159 } |
164 throw new FallThroughError(); | 160 throw new FallThroughError(); |
165 } | 161 } |
166 | 162 |
167 /// Set the Observatory application page. | 163 /// Set the Observatory application page. |
168 void _installPage(Page page) { | 164 void _installPage(Page page) { |
169 assert(page != null); | 165 assert(page != null); |
170 if (currentPage == page) { | 166 if (currentPage == page) { |
(...skipping 18 matching lines...) Expand all Loading... |
189 // Add tracing support. | 185 // Add tracing support. |
190 _traceView = new Element.tag('trace-view'); | 186 _traceView = new Element.tag('trace-view'); |
191 _traceView.tracer = Tracer.current; | 187 _traceView.tracer = Tracer.current; |
192 rootElement.children.add(_traceView); | 188 rootElement.children.add(_traceView); |
193 | 189 |
194 // Remember page. | 190 // Remember page. |
195 currentPage = page; | 191 currentPage = page; |
196 } | 192 } |
197 | 193 |
198 ObservatoryApplication(this.rootElement) : | 194 ObservatoryApplication(this.rootElement) : |
199 locationManager = new HashLocationManager(), | |
200 targets = new TargetManager() { | 195 targets = new TargetManager() { |
| 196 _locationManager = new LocationManager(this); |
201 vm = new WebSocketVM(targets.defaultTarget); | 197 vm = new WebSocketVM(targets.defaultTarget); |
202 _initOnce(false); | 198 _initOnce(); |
203 } | 199 } |
204 | 200 |
205 void _removeDisconnectEvents() { | 201 void _removeDisconnectEvents() { |
206 notifications.removeWhere((oldEvent) { | 202 notifications.removeWhere((oldEvent) { |
207 return (oldEvent.eventType == ServiceEvent.kVMDisconnected); | 203 return (oldEvent.eventType == ServiceEvent.kVMDisconnected); |
208 }); | 204 }); |
209 } | 205 } |
210 | 206 |
211 _vmConnected(VM vm) { | 207 _vmConnected(VM vm) { |
212 if (vm is WebSocketVM) { | 208 if (vm is WebSocketVM) { |
213 targets.add(vm.target); | 209 targets.add(vm.target); |
214 } | 210 } |
215 _removeDisconnectEvents(); | 211 _removeDisconnectEvents(); |
216 } | 212 } |
217 | 213 |
218 _vmDisconnected(VM vm) { | 214 _vmDisconnected(VM vm) { |
219 if (this.vm != vm) { | 215 if (this.vm != vm) { |
220 // This disconnect event occured *after* a new VM was installed. | 216 // This disconnect event occured *after* a new VM was installed. |
221 return; | 217 return; |
222 } | 218 } |
223 this.vm = null; | 219 this.vm = null; |
224 notifications.add(new ServiceEvent.vmDisconencted()); | 220 notifications.add(new ServiceEvent.vmDisconencted()); |
225 } | 221 } |
226 } | 222 } |
OLD | NEW |