Search in sources :

Example 1 with IsolateRef

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());
}
Also used : ObservatoryConnector(io.flutter.ObservatoryConnector) IsolateRef(org.dartlang.vm.service.element.IsolateRef) VmService(org.dartlang.vm.service.VmService) VMConsumer(org.dartlang.vm.service.consumer.VMConsumer) ExecutionResult(com.intellij.execution.ExecutionResult) RPCError(org.dartlang.vm.service.element.RPCError) ObservatoryConnector(io.flutter.ObservatoryConnector) IOException(java.io.IOException) ElementList(org.dartlang.vm.service.element.ElementList) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) VM(org.dartlang.vm.service.element.VM) Event(org.dartlang.vm.service.element.Event) RunContentBuilder(com.intellij.execution.runners.RunContentBuilder)

Example 2 with IsolateRef

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;
}
Also used : IsolateRef(org.dartlang.vm.service.element.IsolateRef) HeapListener(io.flutter.perf.HeapMonitor.HeapListener) HeapSpace(io.flutter.perf.HeapMonitor.HeapSpace) JBLabel(com.intellij.ui.components.JBLabel) VM(org.dartlang.vm.service.element.VM) List(java.util.List)

Example 3 with IsolateRef

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);
}
Also used : JsonObject(com.google.gson.JsonObject) DiagnosticsNode(io.flutter.inspector.DiagnosticsNode) IsolateRef(org.dartlang.vm.service.element.IsolateRef) Event(org.dartlang.vm.service.element.Event) StringUtil(com.intellij.openapi.util.text.StringUtil) VmService(org.dartlang.vm.service.VmService) InspectorService(io.flutter.inspector.InspectorService) VMServiceManager(io.flutter.vmService.VMServiceManager) CompletableFuture(java.util.concurrent.CompletableFuture) FileEditor(com.intellij.openapi.fileEditor.FileEditor) StreamSubscription(io.flutter.utils.StreamSubscription) Disposer(com.intellij.openapi.util.Disposer) VmServiceListener(org.dartlang.vm.service.VmServiceListener) NotNull(org.jetbrains.annotations.NotNull) FlutterApp(io.flutter.run.daemon.FlutterApp) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter) VMServiceManager(io.flutter.vmService.VMServiceManager) Event(org.dartlang.vm.service.element.Event) VmServiceListenerAdapter(io.flutter.utils.VmServiceListenerAdapter)

Example 4 with IsolateRef

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));
    }
}
Also used : IsolateRef(org.dartlang.vm.service.element.IsolateRef) GetMemoryUsageConsumer(org.dartlang.vm.service.consumer.GetMemoryUsageConsumer) Sentinel(org.dartlang.vm.service.element.Sentinel) ArrayList(java.util.ArrayList) RPCError(org.dartlang.vm.service.element.RPCError) MemoryUsage(org.dartlang.vm.service.element.MemoryUsage)

Example 5 with IsolateRef

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());
                                            });
                                        }
                                    }
                                });
                            }
                        }
                    });
                }
            });
        }
    });
}
Also used : XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(org.dartlang.vm.service.element.Breakpoint) InstanceRef(org.dartlang.vm.service.element.InstanceRef) IsolateRef(org.dartlang.vm.service.element.IsolateRef) EventKind(org.dartlang.vm.service.element.EventKind) Success(org.dartlang.vm.service.element.Success) VM(org.dartlang.vm.service.element.VM) Isolate(org.dartlang.vm.service.element.Isolate) Event(org.dartlang.vm.service.element.Event)

Aggregations

IsolateRef (org.dartlang.vm.service.element.IsolateRef)5 Event (org.dartlang.vm.service.element.Event)3 VM (org.dartlang.vm.service.element.VM)3 VmServiceListenerAdapter (io.flutter.utils.VmServiceListenerAdapter)2 VmService (org.dartlang.vm.service.VmService)2 RPCError (org.dartlang.vm.service.element.RPCError)2 JsonObject (com.google.gson.JsonObject)1 ExecutionResult (com.intellij.execution.ExecutionResult)1 RunContentBuilder (com.intellij.execution.runners.RunContentBuilder)1 FileEditor (com.intellij.openapi.fileEditor.FileEditor)1 Disposer (com.intellij.openapi.util.Disposer)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 JBLabel (com.intellij.ui.components.JBLabel)1 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)1 ObservatoryConnector (io.flutter.ObservatoryConnector)1 DiagnosticsNode (io.flutter.inspector.DiagnosticsNode)1 InspectorService (io.flutter.inspector.InspectorService)1 HeapListener (io.flutter.perf.HeapMonitor.HeapListener)1 HeapSpace (io.flutter.perf.HeapMonitor.HeapSpace)1 FlutterApp (io.flutter.run.daemon.FlutterApp)1