-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[ DDS ] Add getStreamHistory RPC and package:vm_service extensions
Adds a DDS RPC which allows for stream history to be manually requested in addition to being sent upon initial stream subscription. Also adds an initial implementation of package:dds/vm_service_extensions.dart, which adds DDS functionality to the `VmService` class. Fixes #44505 Change-Id: I198a6fd7fca15f131a6fdd95e7860a6f98ef06a7 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/177182 Reviewed-by: Kenzie Schmoll <kenzieschmoll@google.com> Commit-Queue: Ben Konyi <bkonyi@google.com>
- Loading branch information
Showing
10 changed files
with
195 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Copyright (c) 2020, 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:collection'; | ||
|
||
import 'package:meta/meta.dart'; | ||
import 'package:vm_service/src/vm_service.dart'; | ||
|
||
extension DdsExtension on VmService { | ||
static bool _factoriesRegistered = false; | ||
static Version _ddsVersion; | ||
|
||
/// The _getDartDevelopmentServiceVersion_ RPC is used to determine what version of | ||
/// the Dart Development Service Protocol is served by a DDS instance. | ||
/// | ||
/// The result of this call is cached for subsequent invocations. | ||
Future<Version> getDartDevelopmentServiceVersion() async { | ||
if (_ddsVersion == null) { | ||
_ddsVersion = | ||
await _callHelper<Version>('getDartDevelopmentServiceVersion'); | ||
} | ||
return _ddsVersion; | ||
} | ||
|
||
/// Retrieve the event history for `stream`. | ||
/// | ||
/// If `stream` does not have event history collected, a parameter error is | ||
/// returned. | ||
Future<StreamHistory> getStreamHistory(String stream) async { | ||
if (!(await _versionCheck(1, 2))) { | ||
throw UnimplementedError('getStreamHistory requires DDS version 1.2'); | ||
} | ||
return _callHelper<StreamHistory>('getStreamHistory', args: { | ||
'stream': stream, | ||
}); | ||
} | ||
|
||
Future<bool> _versionCheck(int major, int minor) async { | ||
if (_ddsVersion == null) { | ||
_ddsVersion = await getDartDevelopmentServiceVersion(); | ||
} | ||
return ((_ddsVersion.major == major && _ddsVersion.minor >= minor) || | ||
(_ddsVersion.major > major)); | ||
} | ||
|
||
Future<T> _callHelper<T>(String method, | ||
{String isolateId, Map args = const {}}) { | ||
if (!_factoriesRegistered) { | ||
_registerFactories(); | ||
} | ||
return callMethod( | ||
method, | ||
args: { | ||
if (isolateId != null) 'isolateId': isolateId, | ||
...args, | ||
}, | ||
).then((e) => e as T); | ||
} | ||
|
||
static void _registerFactories() { | ||
addTypeFactory('StreamHistory', StreamHistory.parse); | ||
_factoriesRegistered = true; | ||
} | ||
} | ||
|
||
/// A collection of historical [Event]s from some stream. | ||
class StreamHistory extends Response { | ||
static StreamHistory parse(Map<String, dynamic> json) => | ||
json == null ? null : StreamHistory._fromJson(json); | ||
|
||
StreamHistory({@required List<Event> history}) : _history = history; | ||
|
||
StreamHistory._fromJson(Map<String, dynamic> json) | ||
: _history = List<Event>.from( | ||
createServiceObject(json['history'], const ['Event']) as List ?? | ||
[]) { | ||
type = json['type']; | ||
} | ||
|
||
/// Historical [Event]s for a stream. | ||
List<Event> get history => UnmodifiableListView(_history); | ||
final List<Event> _history; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import 'dart:developer'; | ||
|
||
void main() { | ||
for (int i = 0; i < 10; ++i) { | ||
log(i.toString()); | ||
} | ||
debugger(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// Copyright (c) 2020, 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:io'; | ||
|
||
import 'package:dds/dds.dart'; | ||
import 'package:dds/vm_service_extensions.dart'; | ||
import 'package:test/test.dart'; | ||
import 'package:vm_service/vm_service_io.dart'; | ||
import 'common/test_helper.dart'; | ||
|
||
void main() { | ||
Process process; | ||
DartDevelopmentService dds; | ||
|
||
setUp(() async { | ||
process = await spawnDartProcess('get_stream_history_script.dart', | ||
pauseOnStart: false); | ||
}); | ||
|
||
tearDown(() async { | ||
await dds?.shutdown(); | ||
process?.kill(); | ||
dds = null; | ||
process = null; | ||
}); | ||
|
||
test('getStreamHistory returns log history', () async { | ||
dds = await DartDevelopmentService.startDartDevelopmentService( | ||
remoteVmServiceUri, | ||
); | ||
expect(dds.isRunning, true); | ||
final service = await vmServiceConnectUri(dds.wsUri.toString()); | ||
final result = await service.getStreamHistory('Logging'); | ||
expect(result, isNotNull); | ||
expect(result, isA<StreamHistory>()); | ||
expect(result.history.length, 10); | ||
}); | ||
} |