use of org.dartlang.vm.service.element.IsolateRef in project flutter-intellij by flutter.
the class FlutterTestRunner method run.
protected RunContentDescriptor run(@NotNull TestLaunchState launcher, @NotNull ExecutionEnvironment env) throws ExecutionException {
final ExecutionResult executionResult = launcher.execute(env.getExecutor(), this);
final ObservatoryConnector connector = new Connector(executionResult.getProcessHandler());
ApplicationManager.getApplication().executeOnPooledThread(() -> {
// Poll, waiting for "flutter run" to give us a websocket.
// This is adapted from DartVmServiceDebugProcess::scheduleConnect.
String url = connector.getWebSocketUrl();
while (url == null) {
if (launcher.isTerminated()) {
return;
}
TimeoutUtil.sleep(100);
url = connector.getWebSocketUrl();
}
if (launcher.isTerminated()) {
return;
}
final VmService vmService;
try {
vmService = VmService.connect(url);
} catch (IOException | RuntimeException e) {
if (!launcher.isTerminated()) {
launcher.notifyTextAvailable("Failed to connect to the VM service at: " + url + "\n" + e.toString() + "\n", ProcessOutputTypes.STDERR);
}
return;
}
// Listen for debug 'PauseStart' events for isolates after the initial connect and resume those isolates.
vmService.streamListen(VmService.DEBUG_STREAM_ID, VmServiceConsumers.EMPTY_SUCCESS_CONSUMER);
vmService.addVmServiceListener(new VmServiceListenerAdapter() {
@Override
public void received(String streamId, Event event) {
if (EventKind.PauseStart.equals(event.getKind())) {
resumePausedAtStartIsolate(launcher, vmService, event.getIsolate());
}
}
});
// Resume any isolates paused at the initial connect.
vmService.getVM(new VMConsumer() {
@Override
public void received(VM response) {
final ElementList<IsolateRef> isolates = response.getIsolates();
for (IsolateRef isolateRef : isolates) {
resumePausedAtStartIsolate(launcher, vmService, isolateRef);
}
}
@Override
public void onError(RPCError error) {
if (!launcher.isTerminated()) {
launcher.notifyTextAvailable("Error connecting to VM: " + error.getCode() + " " + error.getMessage() + "\n", ProcessOutputTypes.STDERR);
}
}
});
});
return new RunContentBuilder(executionResult, env).showRunContent(env.getContentToReuse());
}
use of org.dartlang.vm.service.element.IsolateRef in project flutter-intellij by flutter.
the class HeapState method createJPanelView.
public static JPanel createJPanelView(Disposable parentDisposable, FlutterApp app) {
final JPanel panel = new JPanel(new BorderLayout());
panel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
panel.setPreferredSize(new Dimension(100, PANEL_HEIGHT));
final JBLabel rssLabel = new JBLabel();
rssLabel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
rssLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
rssLabel.setForeground(UIUtil.getLabelDisabledForeground());
rssLabel.setBorder(JBUI.Borders.empty(4));
final JBLabel heapLabel = new JBLabel("", SwingConstants.RIGHT);
heapLabel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
heapLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
heapLabel.setForeground(UIUtil.getLabelDisabledForeground());
heapLabel.setBorder(JBUI.Borders.empty(4));
final HeapState heapState = new HeapState(60 * 1000);
final HeapDisplay graph = new HeapDisplay(state -> {
rssLabel.setText(heapState.getRSSSummary());
heapLabel.setText(heapState.getHeapSummary());
SwingUtilities.invokeLater(rssLabel::repaint);
SwingUtilities.invokeLater(heapLabel::repaint);
});
graph.setLayout(new BoxLayout(graph, BoxLayout.X_AXIS));
graph.add(rssLabel);
graph.add(Box.createHorizontalGlue());
graph.add(heapLabel);
panel.add(graph, BorderLayout.CENTER);
final HeapListener listener = new HeapListener() {
@Override
public void handleIsolatesInfo(VM vm, List<IsolateObject> isolates) {
heapState.handleIsolatesInfo(vm, isolates);
graph.updateFrom(heapState);
SwingUtilities.invokeLater(panel::repaint);
}
@Override
public void handleGCEvent(IsolateRef iIsolateRef, HeapSpace newHeapSpace, HeapSpace oldHeapSpace) {
heapState.handleGCEvent(iIsolateRef, newHeapSpace, oldHeapSpace);
graph.updateFrom(heapState);
SwingUtilities.invokeLater(panel::repaint);
}
};
assert app.getPerfService() != null;
app.getPerfService().addListener(listener);
Disposer.register(parentDisposable, () -> app.getPerfService().removeListener(listener));
return panel;
}
use of org.dartlang.vm.service.element.IsolateRef in project flutter-intellij by flutter.
the class VmServiceWidgetPerfProvider method setupConnection.
private void setupConnection(@NotNull VmService vmService) {
if (isDisposed || connected) {
return;
}
final VMServiceManager vmServiceManager = app.getVMServiceManager();
assert vmServiceManager != null;
connected = true;
isolateRefStreamSubscription = vmServiceManager.getCurrentFlutterIsolate((isolateRef) -> requestRepaint(When.soon), false);
vmService.addVmServiceListener(new VmServiceListenerAdapter() {
@Override
public void received(String streamId, Event event) {
onVmServiceReceived(streamId, event);
}
@Override
public void connectionClosed() {
}
});
inspectorService = InspectorService.create(app, app.getFlutterDebugProcess(), app.getVmService());
inspectorService.whenCompleteAsync((service, throwable) -> Disposer.register(this, service));
requestRepaint(When.soon);
}
use of org.dartlang.vm.service.element.IsolateRef in project flutter-intellij by flutter.
the class HeapMonitor method collectMemoryUsage.
private void collectMemoryUsage() {
final List<IsolateRef> isolateRefs = vmServiceWrapper.getExistingIsolates();
if (isolateRefs.isEmpty()) {
return;
}
final List<MemoryUsage> memoryUsage = new ArrayList<>();
final CountDownLatch latch = new CountDownLatch(isolateRefs.size());
for (IsolateRef isolateRef : isolateRefs) {
vmServiceWrapper.getVmService().getMemoryUsage(isolateRef.getId(), new GetMemoryUsageConsumer() {
@Override
public void received(MemoryUsage usage) {
memoryUsage.add(usage);
latch.countDown();
}
@Override
public void received(Sentinel sentinel) {
latch.countDown();
}
@Override
public void onError(RPCError error) {
// TODO(devoncarew): Remove rpcInternalError once https://github.com/dart-lang/webdev/issues/781
// lands and rolls into flutter.
final int rpcInternalError = -32603;
final int rpcMethodNotFound = -32601;
// {"jsonrpc":"2.0","error":{"code":-32603,"message":"UnimplementedError..."}}
if (error.getCode() == rpcInternalError || error.getCode() == rpcMethodNotFound) {
handleMemoryApiNotSupported();
}
latch.countDown();
}
});
}
try {
latch.await();
} catch (InterruptedException ignored) {
}
if (pollingScheduler != null) {
heapListeners.forEach(listener -> listener.handleMemoryUsage(memoryUsage));
}
}
use of org.dartlang.vm.service.element.IsolateRef in project flutter-intellij by flutter.
the class CanonicalBreakpoint method handleDebuggerConnected.
public void handleDebuggerConnected() {
streamListen(VmService.DEBUG_STREAM_ID, new VmServiceConsumers.SuccessConsumerWrapper() {
@Override
public void received(final Success success) {
myVmServiceReceiverThreadId = Thread.currentThread().getId();
streamListen(VmService.ISOLATE_STREAM_ID, new VmServiceConsumers.SuccessConsumerWrapper() {
@Override
public void received(final Success success) {
getVm(new VmServiceConsumers.VmConsumerWrapper() {
@Override
public void received(final VM vm) {
for (final IsolateRef isolateRef : vm.getIsolates()) {
getIsolate(isolateRef.getId(), new VmServiceConsumers.GetIsolateConsumerWrapper() {
@Override
public void received(final Isolate isolate) {
final Event event = isolate.getPauseEvent();
final EventKind eventKind = event.getKind();
// yet, and we'll get lifecycle events for them later.
if (eventKind == EventKind.None) {
return;
}
// This is the entry point for attaching a debugger to a running app.
if (eventKind == EventKind.Resume) {
attachIsolate(isolateRef, isolate);
return;
}
// if event is not PauseStart it means that PauseStart event will follow later and will be handled by listener
handleIsolate(isolateRef, eventKind == EventKind.PauseStart);
// Handle the case of isolates paused when we connect (this can come up in remote debugging).
if (eventKind == EventKind.PauseBreakpoint || eventKind == EventKind.PauseException || eventKind == EventKind.PauseInterrupted) {
myDebugProcess.isolateSuspended(isolateRef);
ApplicationManager.getApplication().executeOnPooledThread(() -> {
final ElementList<Breakpoint> breakpoints = eventKind == EventKind.PauseBreakpoint ? event.getPauseBreakpoints() : null;
final InstanceRef exception = eventKind == EventKind.PauseException ? event.getException() : null;
myVmServiceListener.onIsolatePaused(isolateRef, breakpoints, exception, event.getTopFrame(), event.getAtAsyncSuspension());
});
}
}
});
}
}
});
}
});
}
});
}
Aggregations