Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(754)

Side by Side Diff: runtime/bin/vmservice/client/lib/src/observatory/isolate.dart

Issue 184233007: Refactor Observatory (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 observatory; 5 part of app;
6
7 6
8 /// State for a running isolate. 7 /// State for a running isolate.
9 class Isolate extends Observable { 8 class Isolate extends Observable implements ServiceObject {
10 static ObservatoryApplication _application; 9 final VM vm;
10 String _id;
11 String _serviceType = 'Isolate';
12 Isolate get isolate => this;
13 String get link => _id;
14 String get id => _id;
15 String get serviceType => _serviceType;
16
17 Isolate(this.vm, this._id);
18
19 /// Refresh [this]. Returns a future which completes to [this].
20 Future refresh() {
21 return vm.fetchMap(_id).then((m) => update(m)).then((_) => this);
22 }
23
24 /// Creates a link to [objectId] relative to [this].
25 String relativeLink(String objectId) => '$id/$objectId';
26 /// Creates a relative link to [objectId] with a '#/' prefix.
27 String hashLink(String objectId) => '#/${relativeLink(objectId)}';
11 28
12 @observable Profile profile; 29 @observable Profile profile;
13 @observable final Map<String, Script> scripts = 30 @observable final Map<String, Script> scripts =
14 toObservable(new Map<String, Script>()); 31 toObservable(new Map<String, Script>());
15 @observable final List<Code> codes = new List<Code>(); 32 @observable final List<Code> codes = new List<Code>();
16 @observable String id;
17 @observable String name; 33 @observable String name;
18 @observable String vmName; 34 @observable String vmName;
19 @observable Map entry; 35 @observable Map entry;
20 @observable String rootLib; 36 @observable String rootLib;
21 @observable final Map<String, double> timers = 37 @observable final Map<String, double> timers =
22 toObservable(new Map<String, double>()); 38 toObservable(new Map<String, double>());
23 39
24 @observable int newHeapUsed = 0; 40 @observable int newHeapUsed = 0;
25 @observable int oldHeapUsed = 0; 41 @observable int oldHeapUsed = 0;
26 42
27 @observable Map topFrame = null; 43 @observable Map topFrame = null;
28 @observable String fileAndLine = null; 44 @observable String fileAndLine = null;
29
30 Isolate.fromId(this.id) : name = 'isolate' {}
31
32 Isolate.fromMap(Map map)
33 : id = map['id'], name = map['name'] {
34 }
35 45
36 Future refresh() { 46 Isolate.fromId(this.vm, this._id) : name = 'isolate' {}
37 var request = '/$id/'; 47
38 return _application.requestManager.requestMap(request).then((map) { 48 Isolate.fromMap(this.vm, Map map)
39 update(map); 49 : _id = map['id'], name = map['name'] {
40 }).catchError((e, trace) {
41 Logger.root.severe('Error while updating isolate summary: $e\n$trace' );
42 });
43 } 50 }
44 51
45 void update(Map map) { 52 void update(Map map) {
46 if (map['type'] != 'Isolate') { 53 if (map['type'] != 'Isolate') {
47 Logger.root.severe('Unexpected message type in Isolate.update: ${map["type "]}'); 54 Logger.root.severe('Unexpected message type in Isolate.update: ${map["type "]}');
48 return; 55 return;
49 } 56 }
50 if (map['rootLib'] == null || 57 if (map['rootLib'] == null ||
51 map['timers'] == null || 58 map['timers'] == null ||
52 map['heap'] == null) { 59 map['heap'] == null) {
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 var id = coverage['script']['id']; 122 var id = coverage['script']['id'];
116 var script = scripts[id]; 123 var script = scripts[id];
117 if (script == null) { 124 if (script == null) {
118 script = new Script.fromMap(coverage['script']); 125 script = new Script.fromMap(coverage['script']);
119 scripts[id] = script; 126 scripts[id] = script;
120 } 127 }
121 assert(script != null); 128 assert(script != null);
122 script._processCoverageHits(coverage['hits']); 129 script._processCoverageHits(coverage['hits']);
123 } 130 }
124 } 131 }
132
133 // TODO(johnmccutchan): Kill.
turnidge 2014/03/05 21:02:47 Maybe more verbose on the comment.
Cutch 2014/03/05 21:54:23 Done.
134 void _setModelResponse(String type, String modelName, dynamic model) {
135 var response = {
136 'type': type,
137 modelName: model
138 };
139 vm.app.setResponse(response);
140 }
141
142 void _setResponseRequestError(HttpRequest request) {
143 String error = '${request.status} ${request.statusText}';
144 if (request.status == 0) {
145 error = 'No service found. Did you run with --enable-vm-service ?';
146 }
147 vm.app.setResponseError(error, 'RequestError');
148 }
149
150 void _requestCatchError(e, st) {
151 if (e is ProgressEvent) {
152 _setResponseRequestError(e.target);
153 } else {
154 vm.app.setResponseError('$e $st');
155 }
156 }
157
158 static final RegExp _codeMatcher = new RegExp(r'/code/');
159 static bool isCodeId(objectId) => _codeMatcher.hasMatch(objectId);
160 static int codeAddressFromRequest(String objectId) {
161 Match m = _codeMatcher.matchAsPrefix(objectId);
162 if (m == null) {
163 return 0;
164 }
165 try {
166 var a = int.parse(m.input.substring(m.end), radix: 16);
167 return a;
168 } catch (e) {
169 return 0;
170 }
171 }
172
173 /// Handle 'Code' requests
174 void _getCode(String objectId) {
175 var address = codeAddressFromRequest(objectId);
176 if (address == 0) {
177 vm.app.setResponseError('$objectId is not a valid code request.');
178 return;
179 }
180 var code = isolate.findCodeByAddress(address);
181 if (code != null) {
182 Logger.root.info(
183 'Found code with 0x${address.toRadixString(16)} in isolate.');
184 _setModelResponse('Code', 'code', code);
185 return;
186 }
187 getMap(objectId).then((map) {
188 assert(map['type'] == 'Code');
189 var code = new Code.fromMap(map);
190 Logger.root.info(
191 'Added code with 0x${address.toRadixString(16)} to isolate.');
192 isolate.codes.add(code);
193 _setModelResponse('Code', 'code', code);
194 }).catchError(_requestCatchError);
195 }
196
197 static final RegExp _scriptMatcher = new RegExp(r'scripts/.+');
198 static bool isScriptId(objectId) => _scriptMatcher.hasMatch(objectId);
199 void _getScript(String objectId) {
200 var script = scripts[objectId];
201 if ((script != null) && !script.needsSource) {
202 Logger.root.info('Found script ${script.scriptRef['name']} in isolate');
203 _setModelResponse('Script', 'script', script);
204 return;
205 }
206 if (script != null) {
207 // The isolate has the script but no script source code.
208 getMap(objectId).then((response) {
209 assert(response['type'] == 'Script');
210 script._processSource(response['source']);
211 Logger.root.info(
212 'Grabbed script ${script.scriptRef['name']} source.');
213 _setModelResponse('Script', 'script', script);
214 });
215 return;
216 }
217 // New script.
218 getMap(objectId).then((response) {
219 assert(response['type'] == 'Script');
220 var script = new Script.fromMap(response);
221 Logger.root.info(
222 'Added script ${script.scriptRef['name']} to isolate.');
223 _setModelResponse('Script', 'script', script);
224 scripts[objectId] = script;
225 });
226 }
227
228 /// Requests [objectId] from [this]. Completes to a [ServiceObject].
229 Future<ServiceObject> get(String objectId) {
230 if (isCodeId(objectId)) {
231 _getCode(objectId);
232 // TODO(johnmccutchan): FIX.
233 return null;
234 }
235 if (isScriptId(objectId)) {
236 _getScript(objectId);
237 // TODO(johnmccutchan): FIX.
238 return null;
239 }
240 return vm.fetchMap(relativeLink(objectId)).then((m) =>
241 upgradeToServiceObject(objectId, m));
242 }
243
244 /// Requests [objectId] from [this]. Completes to a [Map].
245 Future<Map> getMap(String objectId) {
turnidge 2014/03/05 21:02:47 Future<ObservableMap>
Cutch 2014/03/05 21:54:23 Done here and elsewhere.
246 return vm.fetchMap(relativeLink(objectId));
247 }
248
249 /// Upgrades response ([m]) for [objectId] to a [ServiceObject].
250 ServiceObject upgradeToServiceObject(String objectId, Map m) {
251 return new ServiceMap.fromMap(this, m);
252 }
125 } 253 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698