[ VM / dart:io ] Added service extension scaffolding for dart:io network profiling

Change-Id: I531f002da65a3ea1439a6ed93d9698323f48bd31
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/121888
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
This commit is contained in:
Ben Konyi 2019-10-16 22:48:46 +00:00 committed by commit-bot@chromium.org
parent c6c79e529e
commit 558875d480
8 changed files with 165 additions and 0 deletions

View file

@ -634,6 +634,15 @@ Dart_Handle DartUtils::SetupIOLibrary(const char* namespc_path,
Dart_Handle set_script_name =
Dart_SetField(platform_type, script_name, dart_script);
RETURN_IF_ERROR(set_script_name);
Dart_Handle network_profiling_type =
GetDartType(DartUtils::kIOLibURL, "_NetworkProfiling");
RETURN_IF_ERROR(network_profiling_type);
Dart_Handle result =
Dart_Invoke(network_profiling_type,
NewString("_registerServiceExtension"), 0, nullptr);
RETURN_IF_ERROR(result);
return Dart_Null();
}

View file

@ -0,0 +1,38 @@
// Copyright (c) 2019, 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.
import 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'package:observatory/service_io.dart';
import 'package:observatory/sample_profile.dart';
import 'package:unittest/unittest.dart';
import 'service_test_common.dart';
import 'test_helper.dart';
void test() {
// TODO(bkonyi): do actual network operations.
print('hello world!');
}
var tests = <IsolateTest>[
(Isolate isolate) async {
await isolate.load();
// Ensure all network profiling service extensions are registered.
const kGetHttpProfileRPC = 'ext.dart.io.getHttpProfile';
const kGetSocketProfileRPC = 'ext.dart.io.getSocketProfile';
expect(isolate.extensionRPCs.length, greaterThanOrEqualTo(2));
expect(isolate.extensionRPCs.contains(kGetHttpProfileRPC), isTrue);
expect(isolate.extensionRPCs.contains(kGetSocketProfileRPC), isTrue);
// Test invocations (will throw on failure).
var response = await isolate.invokeRpcNoUpgrade(kGetHttpProfileRPC, {});
expect(response['type'], 'HttpProfile');
response = await isolate.invokeRpcNoUpgrade(kGetSocketProfileRPC, {});
expect(response['type'], 'SocketProfile');
},
];
main(args) async => runIsolateTests(args, tests, testeeConcurrent: test);

View file

@ -213,6 +213,7 @@ part 'io_sink.dart';
part 'io_service.dart';
part 'link.dart';
part 'namespace_impl.dart';
part 'network_profiling.dart';
part 'overrides.dart';
part 'platform.dart';
part 'platform_impl.dart';

View file

@ -21,6 +21,7 @@ io_sdk_sources = [
"io_service.dart",
"link.dart",
"namespace_impl.dart",
"network_profiling.dart",
"overrides.dart",
"platform.dart",
"platform_impl.dart",

View file

@ -0,0 +1,57 @@
// Copyright (c) 2019, 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.
part of dart.io;
@pragma('vm:entry-point')
abstract class _NetworkProfiling {
static const _kGetHttpProfileRPC = 'ext.dart.io.getHttpProfile';
static const _kGetSocketProfileRPC = 'ext.dart.io.getSocketProfile';
@pragma('vm:entry-point')
static void _registerServiceExtension() {
registerExtension(_kGetHttpProfileRPC, _serviceExtensionHandler);
registerExtension(_kGetSocketProfileRPC, _serviceExtensionHandler);
}
static Future<ServiceExtensionResponse> _serviceExtensionHandler(
String method, Map<String, String> parameters) {
String responseJson;
switch (method) {
case _kGetHttpProfileRPC:
responseJson = _HttpProfile.toJSON();
break;
case _kGetSocketProfileRPC:
responseJson = _SocketProfile.toJSON();
break;
default:
return Future.value(ServiceExtensionResponse.error(
ServiceExtensionResponse.extensionError,
'Method $method does not exist'));
}
return Future.value(ServiceExtensionResponse.result(responseJson));
}
}
abstract class _HttpProfile {
static const _kType = 'HttpProfile';
// TODO(bkonyi): implement.
static String toJSON() {
final response = <String, dynamic>{
'type': _kType,
};
return json.encode(response);
}
}
abstract class _SocketProfile {
static const _kType = 'SocketProfile';
// TODO(bkonyi): implement.
static String toJSON() {
final response = <String, dynamic>{
'type': _kType,
};
return json.encode(response);
}
}

View file

@ -215,6 +215,7 @@ part 'io_sink.dart';
part 'io_service.dart';
part 'link.dart';
part 'namespace_impl.dart';
part 'network_profiling.dart';
part 'overrides.dart';
part 'platform.dart';
part 'platform_impl.dart';

View file

@ -21,6 +21,7 @@ io_sdk_sources = [
"io_service.dart",
"link.dart",
"namespace_impl.dart",
"network_profiling.dart",
"overrides.dart",
"platform.dart",
"platform_impl.dart",

View file

@ -0,0 +1,57 @@
// Copyright (c) 2019, 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.
part of dart.io;
@pragma('vm:entry-point')
abstract class _NetworkProfiling {
static const _kGetHttpProfileRPC = 'ext.dart.io.getHttpProfile';
static const _kGetSocketProfileRPC = 'ext.dart.io.getSocketProfile';
@pragma('vm:entry-point')
static void _registerServiceExtension() {
registerExtension(_kGetHttpProfileRPC, _serviceExtensionHandler);
registerExtension(_kGetSocketProfileRPC, _serviceExtensionHandler);
}
static Future<ServiceExtensionResponse> _serviceExtensionHandler(
String method, Map<String, String> parameters) {
String responseJson;
switch (method) {
case _kGetHttpProfileRPC:
responseJson = _HttpProfile.toJSON();
break;
case _kGetSocketProfileRPC:
responseJson = _SocketProfile.toJSON();
break;
default:
return Future.value(ServiceExtensionResponse.error(
ServiceExtensionResponse.extensionError,
'Method $method does not exist'));
}
return Future.value(ServiceExtensionResponse.result(responseJson));
}
}
abstract class _HttpProfile {
static const _kType = 'HttpProfile';
// TODO(bkonyi): implement.
static String toJSON() {
final response = <String, dynamic>{
'type': _kType,
};
return json.encode(response);
}
}
abstract class _SocketProfile {
static const _kType = 'SocketProfile';
// TODO(bkonyi): implement.
static String toJSON() {
final response = <String, dynamic>{
'type': _kType,
};
return json.encode(response);
}
}