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 dart._vmservice; | 5 library dart._vmservice; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:collection'; | 8 import 'dart:collection'; |
9 import 'dart:convert'; | 9 import 'dart:convert'; |
10 import 'dart:isolate'; | 10 import 'dart:isolate'; |
(...skipping 312 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
323 | 323 |
324 Isolate.spawnUri(Uri.parse(uri), args, msg).then((isolate) { | 324 Isolate.spawnUri(Uri.parse(uri), args, msg).then((isolate) { |
325 _spawnUriNotify(isolate.controlPort, token); | 325 _spawnUriNotify(isolate.controlPort, token); |
326 }).catchError((e) { | 326 }).catchError((e) { |
327 _spawnUriNotify(e.toString(), token); | 327 _spawnUriNotify(e.toString(), token); |
328 }); | 328 }); |
329 | 329 |
330 return encodeSuccess(message); | 330 return encodeSuccess(message); |
331 } | 331 } |
332 | 332 |
| 333 static responseAsJson(portResponse) { |
| 334 if (portResponse is String) { |
| 335 return JSON.decode(portResponse); |
| 336 } else { |
| 337 var cstring = portResponse[0]; |
| 338 return JSON.fuse(UTF8).decode(cstring); |
| 339 } |
| 340 } |
| 341 |
333 // TODO(johnmccutchan): Turn this into a command line tool that uses the | 342 // TODO(johnmccutchan): Turn this into a command line tool that uses the |
334 // service library. | 343 // service library. |
335 Future<String> _getCrashDump(Message message) async { | 344 Future<String> _getCrashDump(Message message) async { |
336 var client = message.client; | 345 var client = message.client; |
337 final perIsolateRequests = [ | 346 final perIsolateRequests = [ |
338 // ?isolateId=<isolate id> will be appended to each of these requests. | 347 // ?isolateId=<isolate id> will be appended to each of these requests. |
339 // Isolate information. | 348 // Isolate information. |
340 Uri.parse('getIsolate'), | 349 Uri.parse('getIsolate'), |
341 // State of heap. | 350 // State of heap. |
342 Uri.parse('_getAllocationProfile'), | 351 Uri.parse('_getAllocationProfile'), |
343 // Call stack + local variables. | 352 // Call stack + local variables. |
344 Uri.parse('getStack?_full=true'), | 353 Uri.parse('getStack?_full=true'), |
345 ]; | 354 ]; |
346 | 355 |
347 // Snapshot of running isolates. | 356 // Snapshot of running isolates. |
348 var isolates = runningIsolates.isolates.values.toList(); | 357 var isolates = runningIsolates.isolates.values.toList(); |
349 | 358 |
350 // Collect the mapping from request uris to responses. | 359 // Collect the mapping from request uris to responses. |
351 var responses = { | 360 var responses = { |
352 }; | 361 }; |
353 | 362 |
354 // Request VM. | 363 // Request VM. |
355 var getVM = Uri.parse('getVM'); | 364 var getVM = Uri.parse('getVM'); |
356 var getVmResponse = JSON.decode( | 365 var getVmResponse = responseAsJson( |
357 await new Message.fromUri(client, getVM).sendToVM()); | 366 await new Message.fromUri(client, getVM).sendToVM()); |
358 responses[getVM.toString()] = getVmResponse['result']; | 367 responses[getVM.toString()] = getVmResponse['result']; |
359 | 368 |
360 // Request command line flags. | 369 // Request command line flags. |
361 var getFlagList = Uri.parse('getFlagList'); | 370 var getFlagList = Uri.parse('getFlagList'); |
362 var getFlagListResponse = JSON.decode( | 371 var getFlagListResponse = responseAsJson( |
363 await new Message.fromUri(client, getFlagList).sendToVM()); | 372 await new Message.fromUri(client, getFlagList).sendToVM()); |
364 responses[getFlagList.toString()] = getFlagListResponse['result']; | 373 responses[getFlagList.toString()] = getFlagListResponse['result']; |
365 | 374 |
366 // Make requests to each isolate. | 375 // Make requests to each isolate. |
367 for (var isolate in isolates) { | 376 for (var isolate in isolates) { |
368 for (var request in perIsolateRequests) { | 377 for (var request in perIsolateRequests) { |
369 var message = new Message.forIsolate(client, request, isolate); | 378 var message = new Message.forIsolate(client, request, isolate); |
370 // Decode the JSON and and insert it into the map. The map key | 379 // Decode the JSON and and insert it into the map. The map key |
371 // is the request Uri. | 380 // is the request Uri. |
372 var response = JSON.decode(await isolate.route(message)); | 381 var response = responseAsJson(await isolate.route(message)); |
373 responses[message.toUri().toString()] = response['result']; | 382 responses[message.toUri().toString()] = response['result']; |
374 } | 383 } |
375 // Dump the object id ring requests. | 384 // Dump the object id ring requests. |
376 var message = | 385 var message = |
377 new Message.forIsolate(client, Uri.parse('_dumpIdZone'), isolate); | 386 new Message.forIsolate(client, Uri.parse('_dumpIdZone'), isolate); |
378 var response = JSON.decode(await isolate.route(message)); | 387 var response = responseAsJson(await isolate.route(message)); |
379 // Insert getObject requests into responses map. | 388 // Insert getObject requests into responses map. |
380 for (var object in response['result']['objects']) { | 389 for (var object in response['result']['objects']) { |
381 final requestUri = | 390 final requestUri = |
382 'getObject&isolateId=${isolate.serviceId}?objectId=${object["id"]}'; | 391 'getObject&isolateId=${isolate.serviceId}?objectId=${object["id"]}'; |
383 responses[requestUri] = object; | 392 responses[requestUri] = object; |
384 } | 393 } |
385 } | 394 } |
386 | 395 |
387 // Encode the entire crash dump. | 396 // Encode the entire crash dump. |
388 return encodeResult(message, responses); | 397 return encodeResult(message, responses); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
438 external bool _vmListenStream(String streamId); | 447 external bool _vmListenStream(String streamId); |
439 | 448 |
440 /// Cancel a subscription to a service stream. | 449 /// Cancel a subscription to a service stream. |
441 external void _vmCancelStream(String streamId); | 450 external void _vmCancelStream(String streamId); |
442 | 451 |
443 /// Get the bytes to the tar archive. | 452 /// Get the bytes to the tar archive. |
444 external Uint8List _requestAssets(); | 453 external Uint8List _requestAssets(); |
445 | 454 |
446 /// Notify the vm service that an isolate has been spawned via rpc. | 455 /// Notify the vm service that an isolate has been spawned via rpc. |
447 external void _spawnUriNotify(obj, String token); | 456 external void _spawnUriNotify(obj, String token); |
OLD | NEW |