-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Start reporting isolate life cycle events #5312
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2016 The Chromium Authors. 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 'globals.dart'; | ||
import 'observatory.dart'; | ||
|
||
// Track and report isolate life cycle events. | ||
class IsolateTracker { | ||
IsolateTracker(this.serviceProtocol); | ||
|
||
// TODO(johnmccutchan): There can be more than one view. | ||
String _viewIsolateId; | ||
set viewIsolateId(String viewIsolateId) { | ||
_viewIsolateId = viewIsolateId; | ||
printStatus('View is now controlled by isolate $_viewIsolateId'); | ||
} | ||
final Observatory serviceProtocol; | ||
StreamSubscription<Event> _isolateEventSubscription; | ||
StreamSubscription<Event> _debugEventSubscription; | ||
|
||
bool _isViewIsolate(String isolateId) { | ||
return (_viewIsolateId != null) && (_viewIsolateId == isolateId); | ||
} | ||
|
||
void onEvent(Event event) { | ||
_onEvent(event); | ||
} | ||
|
||
Future<Null> _onEvent(Event event) async { | ||
const List<String> kInterestingEventKinds = | ||
const <String>['IsolateStart', | ||
'IsolateExit', | ||
'IsolateRunnable', | ||
'PauseStart', | ||
'PauseExit', | ||
'PauseBreakpoint', | ||
'PauseException']; | ||
if (!kInterestingEventKinds.contains(event.kind)) | ||
return; | ||
String messagePrefix = 'Isolate ${event.isolate.id}:'; | ||
if (_isViewIsolate(event.isolate.id)) { | ||
messagePrefix = 'View isolate ${event.isolate.id}:'; | ||
} | ||
if (event.kind == 'PauseExit') { | ||
// TODO(johnmccutchan): Load the isolate and get any error. | ||
} | ||
printStatus('$messagePrefix ${event.kind}'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Probably printTrace here - status should be for user facing messages. |
||
} | ||
|
||
Future<Null> start() async { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does this need to be async or return a Future? |
||
if (_isolateEventSubscription != null) { | ||
assert(_debugEventSubscription != null); | ||
return; | ||
} | ||
_isolateEventSubscription = | ||
serviceProtocol.onIsolateEvent.listen(onEvent); | ||
_debugEventSubscription = | ||
serviceProtocol.onDebugEvent.listen(onEvent); | ||
} | ||
|
||
Future<Null> stop() async { | ||
_isolateEventSubscription?.cancel(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should |
||
_debugEventSubscription?.cancel(); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
printTrace
?