use of org.dartlang.vm.service.consumer.GetIsolateConsumer in project flutter-intellij by flutter.
the class EvalOnDartLibrary method initialize.
private void initialize(String isolateId) {
this.isolateId = isolateId;
vmService.getIsolate(isolateId, new GetIsolateConsumer() {
@Override
public void received(Isolate response) {
for (LibraryRef library : response.getLibraries()) {
if (libraryNames.contains(library.getUri())) {
libraryRef.complete(library);
return;
}
}
libraryRef.completeExceptionally(new RuntimeException("No library matching " + libraryNames + " found."));
}
@Override
public void onError(RPCError error) {
libraryRef.completeExceptionally(new RuntimeException("RPCError calling getIsolate:" + error.toString()));
}
@Override
public void received(Sentinel response) {
libraryRef.completeExceptionally(new RuntimeException("Sentinel calling getIsolate:" + response.toString()));
}
});
}
use of org.dartlang.vm.service.consumer.GetIsolateConsumer in project flutter-intellij by flutter.
the class CanonicalBreakpoint method getCachedIsolate.
public CompletableFuture<Isolate> getCachedIsolate(@NotNull final String isolateId) {
return myIsolatesInfo.getCachedIsolate(isolateId, () -> {
final CompletableFuture<Isolate> isolateFuture = new CompletableFuture<>();
getIsolate(isolateId, new GetIsolateConsumer() {
@Override
public void onError(RPCError error) {
isolateFuture.completeExceptionally(new RuntimeException(error.getMessage()));
}
@Override
public void received(Isolate response) {
isolateFuture.complete(response);
}
@Override
public void received(Sentinel response) {
// Unable to get the isolate.
isolateFuture.complete(null);
}
});
return isolateFuture;
});
}
use of org.dartlang.vm.service.consumer.GetIsolateConsumer in project flutter-intellij by flutter.
the class HeapMonitor method collectIsolateInfo.
private void collectIsolateInfo(VM vm) {
final ElementList<IsolateRef> isolateRefs = vm.getIsolates();
// Stash count so we can know when we've processed them all.
final int isolateCount = isolateRefs.size();
final List<IsolateObject> isolates = new ArrayList<>();
for (IsolateRef isolateRef : isolateRefs) {
vmService.getIsolate(isolateRef.getId(), new GetIsolateConsumer() {
@Override
public void received(Isolate isolateResponse) {
isolates.add(new IsolateObject(isolateResponse.getJson()));
// Only update when we're done collecting from all isolates.
if (isolates.size() == isolateCount) {
notifyListeners(vm, isolates);
}
}
@Override
public void received(Sentinel sentinel) {
// Ignored.
}
@Override
public void onError(RPCError error) {
// TODO(pq): handle?
}
});
}
}
use of org.dartlang.vm.service.consumer.GetIsolateConsumer in project flutter-intellij by flutter.
the class ScriptManager method getCurrentIsolate.
@Nullable
private Isolate getCurrentIsolate() {
final Ref<Isolate> resultRef = Ref.create();
final Semaphore semaphore = new Semaphore();
semaphore.down();
vmService.getIsolate(isolateRef.getId(), new GetIsolateConsumer() {
@Override
public void received(Isolate isolate) {
resultRef.set(isolate);
semaphore.up();
}
@Override
public void received(Sentinel sentinel) {
semaphore.up();
}
@Override
public void onError(RPCError error) {
semaphore.up();
}
});
semaphore.waitFor(RESPONSE_WAIT_TIMEOUT);
return resultRef.get();
}
use of org.dartlang.vm.service.consumer.GetIsolateConsumer in project flutter-intellij by flutter.
the class CanonicalBreakpoint method doSetBreakpointsForIsolate.
private void doSetBreakpointsForIsolate(@NotNull final Set<XLineBreakpoint<XBreakpointProperties>> xBreakpoints, @NotNull final String isolateId, @Nullable final Runnable onFinished) {
if (xBreakpoints.isEmpty()) {
if (onFinished != null) {
onFinished.run();
}
return;
}
final AtomicInteger counter = new AtomicInteger(xBreakpoints.size());
for (final XLineBreakpoint<XBreakpointProperties> xBreakpoint : xBreakpoints) {
addBreakpoint(isolateId, xBreakpoint.getSourcePosition(), new VmServiceConsumers.BreakpointsConsumer() {
@Override
void sourcePositionNotApplicable() {
myBreakpointHandler.breakpointFailed(xBreakpoint);
checkDone();
}
@Override
void received(List<Breakpoint> breakpointResponses, List<RPCError> errorResponses) {
if (breakpointResponses.size() > 0) {
for (Breakpoint breakpoint : breakpointResponses) {
myBreakpointHandler.vmBreakpointAdded(xBreakpoint, isolateId, breakpoint);
}
} else if (errorResponses.size() > 0) {
myBreakpointHandler.breakpointFailed(xBreakpoint);
}
checkDone();
}
private void checkDone() {
if (counter.decrementAndGet() == 0 && onFinished != null) {
onFinished.run();
myVmService.getIsolate(isolateId, new GetIsolateConsumer() {
@Override
public void received(Isolate response) {
final Set<String> libraryUris = new HashSet<>();
final Set<String> fileNames = new HashSet<>();
for (LibraryRef library : response.getLibraries()) {
final String uri = library.getUri();
libraryUris.add(uri);
final String[] split = uri.split("/");
fileNames.add(split[split.length - 1]);
}
final ElementList<Breakpoint> breakpoints = response.getBreakpoints();
if (breakpoints.isEmpty()) {
return;
}
final Set<CanonicalBreakpoint> mappedCanonicalBreakpoints = new HashSet<>();
for (Breakpoint breakpoint : breakpoints) {
Object location = breakpoint.getLocation();
// In JIT mode, locations will be unresolved at this time since files aren't compiled until they are used.
if (location instanceof UnresolvedSourceLocation) {
final ScriptRef script = ((UnresolvedSourceLocation) location).getScript();
if (script != null && libraryUris.contains(script.getUri())) {
mappedCanonicalBreakpoints.add(breakpointNumbersToCanonicalMap.get(breakpoint.getBreakpointNumber()));
}
}
}
final Analytics analytics = FlutterInitializer.getAnalytics();
final String category = "breakpoint";
final Sets.SetView<CanonicalBreakpoint> initialDifference = Sets.difference(canonicalBreakpoints, mappedCanonicalBreakpoints);
final Set<CanonicalBreakpoint> finalDifference = new HashSet<>();
for (CanonicalBreakpoint missingBreakpoint : initialDifference) {
// built. So it's okay to ignore these breakpoints in our count.
if (fileNames.contains(missingBreakpoint.fileName)) {
finalDifference.add(missingBreakpoint);
}
}
analytics.sendEventMetric(category, "unmapped-count", finalDifference.size());
// For internal bazel projects, report files where mapping failed.
if (WorkspaceCache.getInstance(myDebugProcess.getSession().getProject()).isBazel()) {
for (CanonicalBreakpoint canonicalBreakpoint : finalDifference) {
if (canonicalBreakpoint.path.contains("google3")) {
analytics.sendEvent(category, String.format("unmapped-file|%s|%s", response.getRootLib().getUri(), canonicalBreakpoint.path));
}
}
}
}
@Override
public void received(Sentinel response) {
}
@Override
public void onError(RPCError error) {
}
});
}
}
});
}
}
Aggregations