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