Search in sources :

Example 1 with Capture

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();
        }
    });
}
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 Capture

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);
            }
        }
    });
}
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)

Example 3 with Capture

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;
}
Also used : CaptureType(com.android.tools.idea.profiling.capture.CaptureType) CaptureNode(com.android.tools.idea.profiling.view.nodes.CaptureNode) CaptureService(com.android.tools.idea.profiling.capture.CaptureService) Collection(java.util.Collection) CaptureTypeNode(com.android.tools.idea.profiling.view.nodes.CaptureTypeNode) Map(java.util.Map) Capture(com.android.tools.idea.profiling.capture.Capture)

Example 4 with Capture

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);
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) CaptureService(com.android.tools.idea.profiling.capture.CaptureService) OpenFileDescriptor(com.intellij.openapi.fileEditor.OpenFileDescriptor) IOException(java.io.IOException) Capture(com.android.tools.idea.profiling.capture.Capture)

Aggregations

Capture (com.android.tools.idea.profiling.capture.Capture)4 CaptureService (com.android.tools.idea.profiling.capture.CaptureService)4 IOException (java.io.IOException)3 CaptureHandle (com.android.tools.idea.profiling.capture.CaptureHandle)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 CaptureType (com.android.tools.idea.profiling.capture.CaptureType)1 CaptureNode (com.android.tools.idea.profiling.view.nodes.CaptureNode)1 CaptureTypeNode (com.android.tools.idea.profiling.view.nodes.CaptureTypeNode)1 FutureCallback (com.google.common.util.concurrent.FutureCallback)1 OpenFileDescriptor (com.intellij.openapi.fileEditor.OpenFileDescriptor)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 Collection (java.util.Collection)1 Map (java.util.Map)1 CountDownLatch (java.util.concurrent.CountDownLatch)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1