Search in sources :

Example 1 with MemoryUsage

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

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

the class HeapState method handleMemoryUsage.

public void handleMemoryUsage(List<MemoryUsage> memoryUsages) {
    int current = 0;
    int total = 0;
    int external = 0;
    for (MemoryUsage usage : memoryUsages) {
        current += usage.getHeapUsage();
        total += usage.getHeapCapacity();
        external += usage.getExternalUsage();
    }
    heapMaxInBytes = total;
    addSample(new HeapMonitor.HeapSample(current, external));
}
Also used : HeapMonitor(io.flutter.vmService.HeapMonitor) MemoryUsage(org.dartlang.vm.service.element.MemoryUsage)

Aggregations

MemoryUsage (org.dartlang.vm.service.element.MemoryUsage)2 HeapMonitor (io.flutter.vmService.HeapMonitor)1 ArrayList (java.util.ArrayList)1 GetMemoryUsageConsumer (org.dartlang.vm.service.consumer.GetMemoryUsageConsumer)1 IsolateRef (org.dartlang.vm.service.element.IsolateRef)1 RPCError (org.dartlang.vm.service.element.RPCError)1 Sentinel (org.dartlang.vm.service.element.Sentinel)1