use of com.android.tools.idea.profiling.capture.Capture 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.Capture 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);
}
}
});
}
use of com.android.tools.idea.profiling.capture.Capture in project android by JetBrains.
the class CapturesTreeStructure method update.
public void update() {
CaptureService service = CaptureService.getInstance(myProject);
myRoot.clear();
Map<CaptureType, CaptureTypeNode> types = Maps.newHashMap();
for (CaptureType type : service.getTypes()) {
CaptureTypeNode typeNode = myTypeNodes.get(type);
if (typeNode == null) {
typeNode = new CaptureTypeNode(type);
}
types.put(type, typeNode);
myRoot.addType(typeNode);
}
myTypeNodes = types;
Map<Capture, CaptureNode> captures = Maps.newHashMap();
for (Map.Entry<CaptureType, Collection<Capture>> entry : service.getCapturesByType().asMap().entrySet()) {
CaptureTypeNode typeNode = myTypeNodes.get(entry.getKey());
typeNode.clear();
for (Capture capture : entry.getValue()) {
CaptureNode captureNode = myCaptureNodes.get(capture);
if (captureNode == null) {
captureNode = new CaptureNode(myProject, capture);
} else {
captureNode.update();
}
captures.put(capture, captureNode);
typeNode.addCapture(captureNode);
}
}
myCaptureNodes = captures;
}
use of com.android.tools.idea.profiling.capture.Capture in project android by JetBrains.
the class HierarchyViewCaptureTask method onSuccess.
@Override
public void onSuccess() {
if (myError != null) {
Messages.showErrorDialog("Error obtaining view hierarchy: " + StringUtil.notNullize(myError), TITLE);
return;
}
CaptureService service = CaptureService.getInstance(myProject);
try {
Capture capture = service.createCapture(HierarchyViewCaptureType.class, myData, service.getSuggestedName(myClient));
final VirtualFile file = capture.getFile();
file.refresh(true, false, new Runnable() {
@Override
public void run() {
UIUtil.invokeLaterIfNeeded(new Runnable() {
@Override
public void run() {
OpenFileDescriptor descriptor = new OpenFileDescriptor(myProject, file);
FileEditorManager.getInstance(myProject).openEditor(descriptor, true);
}
});
}
});
} catch (IOException e) {
Messages.showErrorDialog("Error creating hierarchy view capture: " + e, TITLE);
}
}
Aggregations