| 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 part of app; | 5 part of app; |
| 6 | 6 |
| 7 /// A [Page] controls the user interface of Observatory. At any given time | 7 /// A [Page] controls the user interface of Observatory. At any given time |
| 8 /// one page will be the current page. Pages are registered at startup. | 8 /// one page will be the current page. Pages are registered at startup. |
| 9 /// When the user navigates within the application, each page is asked if it | 9 /// When the user navigates within the application, each page is asked if it |
| 10 /// can handle the current location, the first page to say yes, wins. | 10 /// can handle the current location, the first page to say yes, wins. |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 serviceElement.object = obj; | 64 serviceElement.object = obj; |
| 65 }).catchError((e) { | 65 }).catchError((e) { |
| 66 Logger.root.severe('ServiceObjectPage visit error: $e'); | 66 Logger.root.severe('ServiceObjectPage visit error: $e'); |
| 67 }); | 67 }); |
| 68 } | 68 } |
| 69 | 69 |
| 70 /// Catch all. | 70 /// Catch all. |
| 71 bool canVisit(String url) => true; | 71 bool canVisit(String url) => true; |
| 72 } | 72 } |
| 73 | 73 |
| 74 /// Class tree page. | 74 class IsolateSuffixPage extends Page { |
| 75 class ClassTreePage extends Page { | 75 final String pagePrefix; |
| 76 static const _urlPrefix = 'class-tree/'; | 76 final String elementTagName; |
| 77 | 77 String _isolateId; |
| 78 ClassTreePage(app) : super(app); | 78 String get isolateId => _isolateId; |
| 79 IsolateSuffixPage(this.pagePrefix, this.elementTagName, app) : super(app); |
| 79 | 80 |
| 80 void onInstall() { | 81 void onInstall() { |
| 81 if (element == null) { | 82 if (element == null) { |
| 82 element = new Element.tag('class-tree'); | 83 element = new Element.tag(elementTagName); |
| 83 } | 84 } |
| 84 } | 85 } |
| 85 | 86 |
| 86 void _visit(String url) { | 87 void _visit(String url) { |
| 87 assert(element != null); | 88 assert(url != null); |
| 88 assert(canVisit(url)); | 89 assert(canVisit(url)); |
| 89 // ClassTree urls are 'class-tree/isolate-id', chop off prefix, leaving | 90 _isolateId = url.substring(pagePrefix.length); |
| 90 // isolate url. | 91 } |
| 91 // | 92 |
| 92 // TODO(turnidge): Many pages share the isolate parsing/fetching | 93 Future<Isolate> getIsolate() { |
| 93 // code. Consider refactoring. | 94 return app.vm.get(isolateId).catchError((e) { |
| 94 url = url.substring(_urlPrefix.length); | 95 Logger.root.severe('$pagePrefix visit error: $e'); |
| 95 /// Request the isolate url. | 96 return e; |
| 96 app.vm.get(url).then((isolate) { | 97 }); |
| 98 } |
| 99 |
| 100 bool canVisit(String url) => url.startsWith(pagePrefix); |
| 101 } |
| 102 |
| 103 |
| 104 /// Class tree page. |
| 105 class ClassTreePage extends IsolateSuffixPage { |
| 106 ClassTreePage(app) : super('class-tree/', 'class-tree', app); |
| 107 |
| 108 void _visit(String url) { |
| 109 super._visit(url); |
| 110 getIsolate().then((isolate) { |
| 97 if (element != null) { | 111 if (element != null) { |
| 98 /// Update the page. | 112 /// Update the page. |
| 99 ClassTreeElement page = element; | 113 ClassTreeElement page = element; |
| 100 page.isolate = isolate; | 114 page.isolate = isolate; |
| 101 } | 115 } |
| 102 }).catchError((e) { | |
| 103 Logger.root.severe('ClassTreePage visit error: $e'); | |
| 104 }); | 116 }); |
| 105 } | 117 } |
| 106 | |
| 107 /// Catch all. | |
| 108 bool canVisit(String url) => url.startsWith(_urlPrefix); | |
| 109 } | 118 } |
| 110 | 119 |
| 111 class DebuggerPage extends Page { | 120 class DebuggerPage extends IsolateSuffixPage { |
| 112 static const _urlPrefix = 'debugger/'; | 121 DebuggerPage(app) : super('debugger/', 'debugger-page', app); |
| 113 | |
| 114 DebuggerPage(app) : super(app); | |
| 115 | |
| 116 void onInstall() { | |
| 117 if (element == null) { | |
| 118 element = new Element.tag('debugger-page'); | |
| 119 } | |
| 120 } | |
| 121 | 122 |
| 122 void _visit(String url) { | 123 void _visit(String url) { |
| 123 assert(element != null); | 124 super._visit(url); |
| 124 assert(canVisit(url)); | 125 getIsolate().then((isolate) { |
| 125 // Debugger urls are 'debugger/isolate-id', chop off prefix, leaving | |
| 126 // isolate url. | |
| 127 url = url.substring(_urlPrefix.length); | |
| 128 /// Request the isolate url. | |
| 129 app.vm.get(url).then((isolate) { | |
| 130 if (element != null) { | 126 if (element != null) { |
| 131 /// Update the page. | 127 /// Update the page. |
| 132 DebuggerPageElement page = element; | 128 DebuggerPageElement page = element; |
| 133 page.isolate = isolate; | 129 page.isolate = isolate; |
| 134 } | 130 } |
| 135 }).catchError((e) { | |
| 136 Logger.root.severe('Unexpected debugger error: $e'); | |
| 137 }); | 131 }); |
| 138 } | 132 } |
| 139 | |
| 140 /// Catch all. | |
| 141 bool canVisit(String url) => url.startsWith(_urlPrefix); | |
| 142 } | 133 } |
| 143 | 134 |
| 144 class CpuProfilerPage extends Page { | 135 class CpuProfilerPage extends IsolateSuffixPage { |
| 145 static const _urlPrefix = 'profiler/'; | 136 CpuProfilerPage(app) : super('profiler/', 'cpu-profile', app); |
| 146 | |
| 147 CpuProfilerPage(app) : super(app); | |
| 148 | |
| 149 void onInstall() { | |
| 150 if (element == null) { | |
| 151 element = new Element.tag('cpu-profile'); | |
| 152 } | |
| 153 } | |
| 154 | 137 |
| 155 void _visit(String url) { | 138 void _visit(String url) { |
| 156 assert(element != null); | 139 super._visit(url); |
| 157 assert(canVisit(url)); | 140 getIsolate().then((isolate) { |
| 158 // CpuProfiler urls are 'profiler/isolate-id', chop off prefix, leaving | |
| 159 // isolate url. | |
| 160 url = url.substring(_urlPrefix.length); | |
| 161 /// Request the isolate url. | |
| 162 app.vm.get(url).then((isolate) { | |
| 163 if (element != null) { | 141 if (element != null) { |
| 164 /// Update the page. | 142 /// Update the page. |
| 165 CpuProfileElement page = element; | 143 CpuProfileElement page = element; |
| 166 page.isolate = isolate; | 144 page.isolate = isolate; |
| 167 } | 145 } |
| 168 }).catchError((e) { | |
| 169 Logger.root.severe('Unexpected profiler error: $e'); | |
| 170 }); | 146 }); |
| 171 } | 147 } |
| 172 | |
| 173 /// Catch all. | |
| 174 bool canVisit(String url) => url.startsWith(_urlPrefix); | |
| 175 } | 148 } |
| 176 | 149 |
| 177 class AllocationProfilerPage extends Page { | 150 class AllocationProfilerPage extends IsolateSuffixPage { |
| 178 static const _urlPrefix = 'allocation-profiler/'; | 151 AllocationProfilerPage(app) |
| 179 | 152 : super('allocation-profiler/', 'heap-profile', app); |
| 180 AllocationProfilerPage(app) : super(app); | |
| 181 | |
| 182 void onInstall() { | |
| 183 if (element == null) { | |
| 184 element = new Element.tag('heap-profile'); | |
| 185 } | |
| 186 } | |
| 187 | 153 |
| 188 void _visit(String url) { | 154 void _visit(String url) { |
| 189 assert(element != null); | 155 super._visit(url); |
| 190 assert(canVisit(url)); | 156 getIsolate().then((isolate) { |
| 191 // Allocation profiler urls are 'allocation-profiler/isolate-id', | |
| 192 // chop off prefix, leaving isolate url. | |
| 193 url = url.substring(_urlPrefix.length); | |
| 194 /// Request the isolate url. | |
| 195 app.vm.get(url).then((isolate) { | |
| 196 if (element != null) { | 157 if (element != null) { |
| 197 /// Update the page. | 158 /// Update the page. |
| 198 HeapProfileElement page = element; | 159 HeapProfileElement page = element; |
| 199 page.isolate = isolate; | 160 page.isolate = isolate; |
| 200 } | 161 } |
| 201 }).catchError((e) { | |
| 202 Logger.root.severe('Unexpected allocation profiler error: $e'); | |
| 203 }); | 162 }); |
| 204 } | 163 } |
| 205 | |
| 206 /// Catch all. | |
| 207 bool canVisit(String url) => url.startsWith(_urlPrefix); | |
| 208 } | 164 } |
| 209 | 165 |
| 210 class HeapMapPage extends Page { | 166 class HeapMapPage extends IsolateSuffixPage { |
| 211 static const _urlPrefix = 'heap-map/'; | 167 HeapMapPage(app) : super('heap-map/', 'heap-map', app); |
| 212 | |
| 213 HeapMapPage(app) : super(app); | |
| 214 | |
| 215 void onInstall() { | |
| 216 if (element == null) { | |
| 217 element = new Element.tag('heap-map'); | |
| 218 } | |
| 219 } | |
| 220 | 168 |
| 221 void _visit(String url) { | 169 void _visit(String url) { |
| 222 assert(element != null); | 170 super._visit(url); |
| 223 assert(canVisit(url)); | 171 getIsolate().then((isolate) { |
| 224 // Allocation profiler urls are 'heap-map/isolate-id', | |
| 225 // chop off prefix, leaving isolate url. | |
| 226 url = url.substring(_urlPrefix.length); | |
| 227 /// Request the isolate url. | |
| 228 app.vm.get(url).then((isolate) { | |
| 229 if (element != null) { | 172 if (element != null) { |
| 230 /// Update the page. | 173 /// Update the page. |
| 231 HeapMapElement page = element; | 174 HeapMapElement page = element; |
| 232 page.isolate = isolate; | 175 page.isolate = isolate; |
| 233 } | 176 } |
| 234 }).catchError((e) { | |
| 235 Logger.root.severe('Unexpected heap map error: $e'); | |
| 236 }); | 177 }); |
| 237 } | 178 } |
| 238 | |
| 239 /// Catch all. | |
| 240 bool canVisit(String url) => url.startsWith(_urlPrefix); | |
| 241 } | 179 } |
| 242 | 180 |
| 243 class ErrorViewPage extends Page { | 181 class ErrorViewPage extends Page { |
| 244 ErrorViewPage(app) : super(app); | 182 ErrorViewPage(app) : super(app); |
| 245 | 183 |
| 246 void onInstall() { | 184 void onInstall() { |
| 247 if (element == null) { | 185 if (element == null) { |
| 248 /// Lazily create page. | 186 /// Lazily create page. |
| 249 element = new Element.tag('service-view'); | 187 element = new Element.tag('service-view'); |
| 250 } | 188 } |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 338 void _visit(String url) { | 276 void _visit(String url) { |
| 339 assert(element != null); | 277 assert(element != null); |
| 340 assert(canVisit(url)); | 278 assert(canVisit(url)); |
| 341 app.vm.get(_isolateId(url)).then((i) { | 279 app.vm.get(_isolateId(url)).then((i) { |
| 342 (element as MetricsPageElement).isolate = i; | 280 (element as MetricsPageElement).isolate = i; |
| 343 }); | 281 }); |
| 344 } | 282 } |
| 345 | 283 |
| 346 bool canVisit(String url) => _matcher.hasMatch(url); | 284 bool canVisit(String url) => _matcher.hasMatch(url); |
| 347 } | 285 } |
| OLD | NEW |