use of com.android.tools.idea.profiling.capture.CaptureHandle in project android by JetBrains.
the class DumpSysAction method performAction.
public void performAction() {
final CountDownLatch completionLatch = new CountDownLatch(1);
final CollectingOutputReceiver receiver = new CollectingOutputReceiver();
String description = myClient == null ? null : myClient.getClientData().getClientDescription();
final String pkgName = description != null ? description : "";
final String command = String.format(Locale.US, "dumpsys %1$s %2$s", myService, pkgName).trim();
ApplicationManager.getApplication().invokeAndWait(new Runnable() {
@Override
public void run() {
ApplicationManager.getApplication().executeOnPooledThread(new Runnable() {
@Override
public void run() {
try {
myDevice.executeShellCommand(command, receiver, 0, null);
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
try {
final CaptureService service = CaptureService.getInstance(myProject);
String name = service.getSuggestedName(myClient);
CaptureHandle handle = service.startCaptureFile(SystemInfoCaptureType.class, name, false);
service.appendData(handle, receiver.getOutput().getBytes());
service.finalizeCaptureFileAsynchronous(handle, new FutureCallback<Capture>() {
@Override
public void onSuccess(@Nullable Capture result) {
if (result != null) {
result.getFile().refresh(true, false);
service.notifyCaptureReady(result);
}
}
@Override
public void onFailure(@NotNull Throwable t) {
showError(myProject, "Unexpected error while saving system information", t);
}
}, EdtExecutor.INSTANCE);
} catch (IOException e) {
showError(myProject, "Unexpected error while saving system information", e);
}
}
});
} catch (Exception e) {
showError(myProject, "Unexpected error while obtaining system information", e);
} finally {
completionLatch.countDown();
}
}
});
new ShellTask(myProject, completionLatch, receiver).queue();
}
});
}
use of com.android.tools.idea.profiling.capture.CaptureHandle in project android by JetBrains.
the class ToggleAllocationTrackingAction method installListener.
private void installListener(@NotNull final Client listeningClient, @NotNull final Project project) {
AndroidDebugBridge.addClientChangeListener(new IClientChangeListener() {
@Override
public void clientChanged(Client client, int changeMask) {
if (client == listeningClient && (changeMask & Client.CHANGE_HEAP_ALLOCATIONS) != 0) {
final byte[] data = client.getClientData().getAllocationsData();
ApplicationManager.getApplication().invokeLater(new Runnable() {
@Override
public void run() {
try {
if (myProject.isDisposed()) {
return;
}
final CaptureService service = CaptureService.getInstance(myProject);
String name = service.getSuggestedName(listeningClient);
CaptureHandle handle = service.startCaptureFile(AllocationCaptureType.class, name, true);
service.appendDataCopy(handle, data);
service.finalizeCaptureFileAsynchronous(handle, new FutureCallback<Capture>() {
@Override
public void onSuccess(Capture result) {
service.notifyCaptureReady(result);
}
@Override
public void onFailure(Throwable t) {
throw new RuntimeException(t);
}
}, EdtExecutor.INSTANCE);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
});
// Remove self from listeners.
AndroidDebugBridge.removeClientChangeListener(this);
}
}
});
}
Aggregations