Search in sources :

Example 6 with Sentinel

use of org.dartlang.vm.service.element.Sentinel 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 7 with Sentinel

use of org.dartlang.vm.service.element.Sentinel in project flutter-intellij by flutter.

the class CanonicalBreakpoint method addBreakpoint.

public void addBreakpoint(@NotNull final String isolateId, @Nullable final XSourcePosition position, @NotNull final VmServiceConsumers.BreakpointsConsumer consumer) {
    if (position == null || position.getFile().getFileType() != DartFileType.INSTANCE) {
        consumer.sourcePositionNotApplicable();
        return;
    }
    addRequest(() -> {
        final int line = position.getLine() + 1;
        final Collection<String> scriptUris = myDebugProcess.getUrisForFile(position.getFile());
        final CanonicalBreakpoint canonicalBreakpoint = new CanonicalBreakpoint(position.getFile().getName(), position.getFile().getCanonicalPath(), line);
        canonicalBreakpoints.add(canonicalBreakpoint);
        final List<Breakpoint> breakpointResponses = new ArrayList<>();
        final List<RPCError> errorResponses = new ArrayList<>();
        for (String uri : scriptUris) {
            myVmService.addBreakpointWithScriptUri(isolateId, uri, line, new AddBreakpointWithScriptUriConsumer() {

                @Override
                public void received(Breakpoint response) {
                    breakpointResponses.add(response);
                    breakpointNumbersToCanonicalMap.put(response.getBreakpointNumber(), canonicalBreakpoint);
                    checkDone();
                }

                @Override
                public void received(Sentinel response) {
                    checkDone();
                }

                @Override
                public void onError(RPCError error) {
                    errorResponses.add(error);
                    checkDone();
                }

                private void checkDone() {
                    if (scriptUris.size() == breakpointResponses.size() + errorResponses.size()) {
                        consumer.received(breakpointResponses, errorResponses);
                    }
                }
            });
        }
    });
}
Also used : XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(org.dartlang.vm.service.element.Breakpoint) AddBreakpointWithScriptUriConsumer(org.dartlang.vm.service.consumer.AddBreakpointWithScriptUriConsumer) Sentinel(org.dartlang.vm.service.element.Sentinel) ArrayList(java.util.ArrayList) RPCError(org.dartlang.vm.service.element.RPCError) XLineBreakpoint(com.intellij.xdebugger.breakpoints.XLineBreakpoint) Breakpoint(org.dartlang.vm.service.element.Breakpoint)

Aggregations

RPCError (org.dartlang.vm.service.element.RPCError)7 Sentinel (org.dartlang.vm.service.element.Sentinel)7 ArrayList (java.util.ArrayList)3 XLineBreakpoint (com.intellij.xdebugger.breakpoints.XLineBreakpoint)2 GetIsolateConsumer (org.dartlang.vm.service.consumer.GetIsolateConsumer)2 Breakpoint (org.dartlang.vm.service.element.Breakpoint)2 Isolate (org.dartlang.vm.service.element.Isolate)2 Sets (com.google.common.collect.Sets)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 XBreakpointProperties (com.intellij.xdebugger.breakpoints.XBreakpointProperties)1 XExecutionStack (com.intellij.xdebugger.frame.XExecutionStack)1 XStackFrame (com.intellij.xdebugger.frame.XStackFrame)1 XDebugSessionImpl (com.intellij.xdebugger.impl.XDebugSessionImpl)1 Analytics (io.flutter.analytics.Analytics)1 DartAsyncMarkerFrame (io.flutter.vmService.frame.DartAsyncMarkerFrame)1 DartVmServiceStackFrame (io.flutter.vmService.frame.DartVmServiceStackFrame)1 HashSet (java.util.HashSet)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AddBreakpointWithScriptUriConsumer (org.dartlang.vm.service.consumer.AddBreakpointWithScriptUriConsumer)1