mirror of
https://github.com/dart-lang/sdk
synced 2024-09-05 08:24:39 +00:00
Add getIsolateID to Service class in dart:developer
Fixes https://github.com/dart-lang/sdk/issues/23924 BUG= R=asiva@google.com Review URL: https://codereview.chromium.org/2542003002 .
This commit is contained in:
parent
1e5fc38884
commit
6bf86eacd7
|
@ -172,4 +172,16 @@ DEFINE_NATIVE_ENTRY(Developer_webServerControl, 2) {
|
|||
#endif
|
||||
}
|
||||
|
||||
|
||||
DEFINE_NATIVE_ENTRY(Developer_getIsolateIDFromSendPort, 1) {
|
||||
#if defined(PRODUCT)
|
||||
return Object::null();
|
||||
#else
|
||||
GET_NON_NULL_NATIVE_ARGUMENT(SendPort, port, arguments->NativeArgAt(0));
|
||||
int64_t port_id = port.Id();
|
||||
return String::NewFormatted(ISOLATE_SERVICE_ID_FORMAT_STRING, port_id);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
} // namespace dart
|
||||
|
|
|
@ -154,7 +154,10 @@ _postResponse(SendPort replyPort,
|
|||
|
||||
@patch int _getServiceMinorVersion() native "Developer_getServiceMinorVersion";
|
||||
|
||||
@patch void _getServerInfo(SendPort sp) native "Developer_getServerInfo";
|
||||
@patch void _getServerInfo(SendPort sendPort) native "Developer_getServerInfo";
|
||||
|
||||
@patch void _webServerControl(SendPort sp, bool enable)
|
||||
@patch void _webServerControl(SendPort sendPort, bool enable)
|
||||
native "Developer_webServerControl";
|
||||
|
||||
@patch String _getIsolateIDFromSendPort(SendPort sendPort)
|
||||
native "Developer_getIsolateIDFromSendPort";
|
||||
|
|
|
@ -0,0 +1,90 @@
|
|||
// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file
|
||||
// for details. All rights reserved. Use of this source code is governed by a
|
||||
// BSD-style license that can be found in the LICENSE file.
|
||||
// VMOptions=--error_on_bad_type --error_on_bad_override
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:developer' as dev;
|
||||
import 'dart:isolate' as Core;
|
||||
|
||||
import 'package:observatory/service_io.dart' as Service;
|
||||
import 'package:unittest/unittest.dart';
|
||||
import 'service_test_common.dart';
|
||||
import 'test_helper.dart';
|
||||
|
||||
|
||||
// testee state.
|
||||
String selfId;
|
||||
Core.Isolate childIsolate;
|
||||
String childId;
|
||||
|
||||
void spawnEntry(int i) {
|
||||
dev.debugger();
|
||||
}
|
||||
|
||||
Future testeeMain() async {
|
||||
dev.debugger();
|
||||
// Spawn an isolate.
|
||||
childIsolate = await Core.Isolate.spawn(spawnEntry, 0);
|
||||
// Assign the id for this isolate and it's child to strings so they can
|
||||
// be read by the tester.
|
||||
selfId = dev.Service.getIsolateID(Core.Isolate.current);
|
||||
childId = dev.Service.getIsolateID(childIsolate);
|
||||
dev.debugger();
|
||||
}
|
||||
|
||||
// tester state:
|
||||
Service.Isolate initialIsolate;
|
||||
Service.Isolate localChildIsolate;
|
||||
|
||||
var tests = [
|
||||
(Service.VM vm) async {
|
||||
// Sanity check.
|
||||
expect(vm.isolates.length, 1);
|
||||
initialIsolate = vm.isolates[0];
|
||||
await hasStoppedAtBreakpoint(initialIsolate);
|
||||
// Resume.
|
||||
await initialIsolate.resume();
|
||||
},
|
||||
(Service.VM vm) async {
|
||||
// Initial isolate has paused at second debugger call.
|
||||
await hasStoppedAtBreakpoint(initialIsolate);
|
||||
},
|
||||
(Service.VM vm) async {
|
||||
// Reload the VM.
|
||||
await vm.reload();
|
||||
|
||||
// Grab the child isolate.
|
||||
localChildIsolate =
|
||||
vm.isolates.firstWhere(
|
||||
(Service.Isolate i) => i != initialIsolate);
|
||||
expect(localChildIsolate, isNotNull);
|
||||
|
||||
// Reload the initial isolate.
|
||||
await initialIsolate.reload();
|
||||
|
||||
// Grab the root library.
|
||||
Service.Library rootLbirary = await initialIsolate.rootLibrary.load();
|
||||
|
||||
// Grab self id.
|
||||
Service.Instance localSelfId =
|
||||
await initialIsolate.eval(rootLbirary, 'selfId');
|
||||
|
||||
// Check that the id reported from dart:developer matches the id reported
|
||||
// from the service protocol.
|
||||
expect(localSelfId.isString, true);
|
||||
expect(initialIsolate.id, equals(localSelfId.valueAsString));
|
||||
|
||||
// Grab the child isolate's id.
|
||||
Service.Instance localChildId =
|
||||
await initialIsolate.eval(rootLbirary, 'childId');
|
||||
|
||||
// Check that the id reported from dart:developer matches the id reported
|
||||
// from the service protocol.
|
||||
expect(localChildId.isString, true);
|
||||
expect(localChildIsolate.id, equals(localChildId.valueAsString));
|
||||
}
|
||||
];
|
||||
|
||||
main(args) async => runVMTests(args, tests,
|
||||
testeeConcurrent: testeeMain);
|
|
@ -157,7 +157,7 @@ Future<Isolate> hasPausedFor(Isolate isolate, String kind) {
|
|||
isolate.vm.getEventStream(VM.kDebugStream).then((stream) {
|
||||
var subscription;
|
||||
subscription = stream.listen((ServiceEvent event) {
|
||||
if (event.kind == kind) {
|
||||
if ((isolate == event.isolate) && (event.kind == kind)) {
|
||||
if (completer != null) {
|
||||
// Reload to update isolate.pauseEvent.
|
||||
print('Paused with $kind');
|
||||
|
|
|
@ -71,6 +71,7 @@ namespace dart {
|
|||
V(Bigint_getDigits, 1) \
|
||||
V(Bigint_allocate, 4) \
|
||||
V(Developer_debugger, 2) \
|
||||
V(Developer_getIsolateIDFromSendPort, 1) \
|
||||
V(Developer_getServerInfo, 1) \
|
||||
V(Developer_getServiceMajorVersion, 0) \
|
||||
V(Developer_getServiceMinorVersion, 0) \
|
||||
|
|
|
@ -1974,7 +1974,7 @@ void Isolate::PrintJSON(JSONStream* stream, bool ref) {
|
|||
}
|
||||
JSONObject jsobj(stream);
|
||||
jsobj.AddProperty("type", (ref ? "@Isolate" : "Isolate"));
|
||||
jsobj.AddFixedServiceId("isolates/%" Pd64 "",
|
||||
jsobj.AddFixedServiceId(ISOLATE_SERVICE_ID_FORMAT_STRING,
|
||||
static_cast<int64_t>(main_port()));
|
||||
|
||||
jsobj.AddProperty("name", debugger_name());
|
||||
|
|
|
@ -41,6 +41,7 @@ class ServiceIdZone {
|
|||
private:
|
||||
};
|
||||
|
||||
#define ISOLATE_SERVICE_ID_FORMAT_STRING "isolates/%" Pd64 ""
|
||||
|
||||
class RingServiceIdZone : public ServiceIdZone {
|
||||
public:
|
||||
|
|
|
@ -117,11 +117,16 @@ int _getServiceMinorVersion() {
|
|||
}
|
||||
|
||||
@patch
|
||||
void _getServerInfo(SendPort sp) {
|
||||
sp.send(null);
|
||||
void _getServerInfo(SendPort sendPort) {
|
||||
sendPort.send(null);
|
||||
}
|
||||
|
||||
@patch
|
||||
void _webServerControl(SendPort sp, bool enable) {
|
||||
sp.send(null);
|
||||
void _webServerControl(SendPort sendPort, bool enable) {
|
||||
sendPort.send(null);
|
||||
}
|
||||
|
||||
@patch
|
||||
String _getIsolateIDFromSendPort(SendPort sendPort) {
|
||||
return null;
|
||||
}
|
|
@ -17,7 +17,7 @@ library dart.developer;
|
|||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:isolate' show RawReceivePort, SendPort;
|
||||
import 'dart:isolate' show Isolate, RawReceivePort, SendPort;
|
||||
|
||||
part 'extension.dart';
|
||||
part 'profiler.dart';
|
||||
|
|
|
@ -73,13 +73,26 @@ class Service {
|
|||
receivePort.close();
|
||||
return new ServiceProtocolInfo(uri);
|
||||
}
|
||||
|
||||
/// Returns a [String] token representing the ID of [isolate].
|
||||
///
|
||||
/// Returns null if the running Dart environment does not support the service
|
||||
/// protocol.
|
||||
static String getIsolateID(Isolate isolate) {
|
||||
if (isolate is! Isolate) {
|
||||
throw new ArgumentError.value(isolate,
|
||||
'isolate',
|
||||
'Must be an Isolate');
|
||||
}
|
||||
return _getIsolateIDFromSendPort(isolate.controlPort);
|
||||
}
|
||||
}
|
||||
|
||||
/// [sp] will receive a Uri or null.
|
||||
external void _getServerInfo(SendPort sp);
|
||||
/// [sendPort] will receive a Uri or null.
|
||||
external void _getServerInfo(SendPort sendPort);
|
||||
|
||||
/// [sp] will receive a Uri or null.
|
||||
external void _webServerControl(SendPort sp, bool enable);
|
||||
/// [sendPort] will receive a Uri or null.
|
||||
external void _webServerControl(SendPort sendPort, bool enable);
|
||||
|
||||
/// Returns the major version of the service protocol.
|
||||
external int _getServiceMajorVersion();
|
||||
|
@ -87,3 +100,5 @@ external int _getServiceMajorVersion();
|
|||
/// Returns the minor version of the service protocol.
|
||||
external int _getServiceMinorVersion();
|
||||
|
||||
/// Returns the service id for the isolate that owns [sendPort].
|
||||
external String _getIsolateIDFromSendPort(SendPort sendPort);
|
Loading…
Reference in a new issue