Skip to content

Batch Debugger.ScriptParsed events sent from the debug extension #1628

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions dwds/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
- Convert JavaScript stack traces in uncaught exceptions to Dart stack traces.
- Fix failure to set breakpoints on windows with a base change in index.html.
- Add the setIsolatePauseMode method to Chrome Proxy Service.
- Batch extension `Debugger.scriptParsed` events and send batches every 1000ms
to the server.
- Move `batched_stream.dart` into shared utilities.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more nit: Looks like the DWDS change is actually just moving batched_stream.dart into shared utilities. Let's update CHANGELOG to reflect that

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done!

## 14.0.2
- Update the min SDK constraint to 2.17.0.
Expand Down
5 changes: 5 additions & 0 deletions dwds/debug_extension/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@

## 1.30
- Batch extension `Debugger.scriptParsed` events and send batches every 1000ms
to the server.

## 1.29

- Notify the debugger and inspector panels when the debug session is disconnected.
Expand Down
4 changes: 2 additions & 2 deletions dwds/debug_extension/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
- With dart2js:

```
pub run build_runner build web -o build -r
dart run build_runner build web -o build -r
```

This will build to the `/web` directory.

- With DDC:

```
pub run build_runner build web -o build
dart run build_runner build web -o build
```

This will build to the `/build/web` directory.
Expand Down
2 changes: 1 addition & 1 deletion dwds/debug_extension/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: extension
publish_to: none
version: 1.29.0
version: 1.30.0
homepage: https://github.com/dart-lang/webdev
description: >-
A chrome extension for Dart debugging.
Expand Down
50 changes: 42 additions & 8 deletions dwds/debug_extension/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import 'package:dwds/data/devtools_request.dart';
import 'package:dwds/data/extension_request.dart';
import 'package:dwds/data/serializers.dart';
import 'package:dwds/src/sockets.dart';
import 'package:dwds/src/utilities/batched_stream.dart';
import 'package:js/js.dart';
import 'package:js/js_util.dart' as js_util;
import 'package:pub_semver/pub_semver.dart';
Expand Down Expand Up @@ -61,8 +62,6 @@ Tab _mostRecentDartTab;
DebuggerTrigger _debuggerTrigger;

class DebugSession {
final SocketClient socketClient;

// The tab ID that contains the running Dart application.
final int appTabId;

Expand All @@ -72,7 +71,38 @@ class DebugSession {
// The tab ID that contains the corresponding Dart DevTools.
int devtoolsTabId;

DebugSession(this.socketClient, this.appTabId, this.appId);
// Socket client for communication with dwds extension backend.
final SocketClient _socketClient;

// How often to send batched events.
static const int _batchDelayMilliseconds = 1000;

// Collect events into batches to be send periodically to the server.
final _batchController =
BatchedStreamController<ExtensionEvent>(delay: _batchDelayMilliseconds);
StreamSubscription<List<ExtensionEvent>> _batchSubscription;

DebugSession(this._socketClient, this.appTabId, this.appId) {
// Collect extension events and send them periodically to the server.
_batchSubscription = _batchController.stream.listen((events) {
_socketClient.sink.add(jsonEncode(serializers.serialize(BatchedEvents(
(b) => b.events = ListBuilder<ExtensionEvent>(events)))));
});
}

void sendEvent(ExtensionEvent event) {
_socketClient.sink.add(jsonEncode(serializers.serialize(event)));
}

void sendBatchedEvent(ExtensionEvent event) {
_batchController.sink.add(event);
}

void close() {
_socketClient.close();
_batchSubscription.cancel();
_batchController.close();
}
}

class DevToolsPanel {
Expand Down Expand Up @@ -101,7 +131,7 @@ void main() {
onMessageAddListener(allowInterop(_handleMessageFromContentScripts));

// Attaches a debug session to the app when the extension receives a
// Runtime.executionContextCreated event from DWDS:
// Runtime.executionContextCreated event from Chrome:
addDebuggerListener(allowInterop(_maybeAttachDebugSession));

// When a Dart application tab is closed, detach the corresponding debug
Expand Down Expand Up @@ -264,7 +294,7 @@ void _maybeAttachDebugSession(
Object params,
) async {
// Return early if it's not a Runtime.executionContextCreated event (sent from
// DWDS):
// Chrome):
if (method != 'Runtime.executionContextCreated') return;

var context = json.decode(stringify(params))['context'];
Expand Down Expand Up @@ -303,8 +333,8 @@ int _removeDebugSessionForTab(int tabId) {
// https://github.com/dart-lang/webdev/pull/1595#issuecomment-1116773378
final event =
_extensionEventFor('DebugExtension.detached', js_util.jsify({}));
session.socketClient.sink.add(jsonEncode(serializers.serialize(event)));
session.socketClient.close();
session.sendEvent(event);
session.close();
_debugSessions.remove(session);

// Notify the Dart DevTools panel that the session has been detached by
Expand Down Expand Up @@ -590,7 +620,11 @@ void _filterAndForwardToBackend(Debuggee source, String method, Object params) {

var event = _extensionEventFor(method, params);

debugSession.socketClient.sink.add(jsonEncode(serializers.serialize(event)));
if (method == 'Debugger.scriptParsed') {
debugSession.sendBatchedEvent(event);
} else {
debugSession.sendEvent(event);
}
}

class Notifier<T> {
Expand Down
Loading