Search in sources :

Example 1 with CaptureHandle

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();
        }
    });
}
Also used : CollectingOutputReceiver(com.android.ddmlib.CollectingOutputReceiver) CaptureService(com.android.tools.idea.profiling.capture.CaptureService) IOException(java.io.IOException) CountDownLatch(java.util.concurrent.CountDownLatch) NotNull(org.jetbrains.annotations.NotNull) Capture(com.android.tools.idea.profiling.capture.Capture) IOException(java.io.IOException) SystemInfoCaptureType(com.android.tools.idea.editors.systeminfo.SystemInfoCaptureType) CaptureHandle(com.android.tools.idea.profiling.capture.CaptureHandle) FutureCallback(com.google.common.util.concurrent.FutureCallback) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with CaptureHandle

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);
            }
        }
    });
}
Also used : CaptureService(com.android.tools.idea.profiling.capture.CaptureService) IOException(java.io.IOException) Capture(com.android.tools.idea.profiling.capture.Capture) IClientChangeListener(com.android.ddmlib.AndroidDebugBridge.IClientChangeListener) CaptureHandle(com.android.tools.idea.profiling.capture.CaptureHandle) Client(com.android.ddmlib.Client)

Aggregations

Capture (com.android.tools.idea.profiling.capture.Capture)2 CaptureHandle (com.android.tools.idea.profiling.capture.CaptureHandle)2 CaptureService (com.android.tools.idea.profiling.capture.CaptureService)2 IOException (java.io.IOException)2 IClientChangeListener (com.android.ddmlib.AndroidDebugBridge.IClientChangeListener)1 Client (com.android.ddmlib.Client)1 CollectingOutputReceiver (com.android.ddmlib.CollectingOutputReceiver)1 SystemInfoCaptureType (com.android.tools.idea.editors.systeminfo.SystemInfoCaptureType)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1