Search in sources :

Example 16 with Client

use of com.android.ddmlib.Client in project android by JetBrains.

the class AndroidProcessHandler method addTargetDevice.

public void addTargetDevice(@NotNull final IDevice device) {
    myDevices.add(device.getSerialNumber());
    setMinDeviceApiLevel(device.getVersion());
    Client client = device.getClient(myApplicationId);
    if (client != null) {
        addClient(client);
    } else {
        notifyTextAvailable("Client not ready yet..", ProcessOutputTypes.STDOUT);
    }
    LOG.info("Adding device " + device.getName() + " to monitor for launched app: " + myApplicationId);
    myDeviceAdded = System.currentTimeMillis();
}
Also used : Client(com.android.ddmlib.Client)

Example 17 with Client

use of com.android.ddmlib.Client in project android by JetBrains.

the class DeviceSampler method startSamplingTask.

private synchronized void startSamplingTask() {
    Client client = myClient;
    if (myExecutingTask == null && client != null) {
        myRunning = true;
        myExecutingTask = ApplicationManager.getApplication().executeOnPooledThread(() -> {
            long timeToWait = mySampleFrequencyMs;
            CountDownLatch taskFinished = new CountDownLatch(1);
            myTaskFinished = taskFinished;
            try {
                while (myRunning) {
                    long start = System.currentTimeMillis();
                    boolean acquired = myDataSemaphore.tryAcquire(timeToWait, TimeUnit.MILLISECONDS);
                    if (myRunning && !myIsPaused) {
                        sample(acquired);
                    }
                    timeToWait -= System.currentTimeMillis() - start;
                    if (timeToWait <= 0) {
                        timeToWait = mySampleFrequencyMs;
                    }
                    if (!client.isValid()) {
                        ApplicationManager.getApplication().invokeLater(this::stop);
                        break;
                    }
                }
            } catch (InterruptedException ignored) {
            } finally {
                myRunning = false;
                taskFinished.countDown();
            }
        });
        client.setHeapInfoUpdateEnabled(true);
        for (TimelineEventListener listener : myListeners) {
            listener.onStart();
        }
    }
}
Also used : Client(com.android.ddmlib.Client) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 18 with Client

use of com.android.ddmlib.Client in project android by JetBrains.

the class GpuSampler method sample.

@Override
protected void sample(boolean forced) throws InterruptedException {
    Client client = getClient();
    assert client != null;
    IDevice device = client.getDevice();
    if (device != null) {
        try {
            ClientData data = client.getClientData();
            ThreeState newGpuProfilingState = myCurrentGfxinfoHandler.getIsEnabledOnDevice(device);
            if (newGpuProfilingState != ThreeState.UNSURE) {
                boolean newGpuBooleanState = newGpuProfilingState.toBoolean();
                setGpuProfileSetting(newGpuBooleanState);
            }
            if (myGpuProfileSetting) {
                myCurrentGfxinfoHandler.sample(device, data, getTimelineData());
            }
        } catch (RuntimeException e) {
            throw new InterruptedException("Sample error, interrupting.");
        } catch (Exception ignored) {
        }
    }
}
Also used : ThreeState(com.intellij.util.ThreeState) ClientData(com.android.ddmlib.ClientData) IDevice(com.android.ddmlib.IDevice) Client(com.android.ddmlib.Client)

Example 19 with Client

use of com.android.ddmlib.Client in project android by JetBrains.

the class DeviceSampler method stopSamplingTask.

private synchronized void stopSamplingTask() {
    Future<?> executingTask = myExecutingTask;
    Client client = myClient;
    if (executingTask == null) {
        return;
    }
    myRunning = false;
    myDataSemaphore.release();
    executingTask.cancel(true);
    CountDownLatch taskFinished = myTaskFinished;
    if (taskFinished != null) {
        try {
            taskFinished.await();
        } catch (InterruptedException ignored) {
        // We're stopping anyway, so just ignore the interruption.
        }
    }
    if (client != null) {
        client.setHeapInfoUpdateEnabled(false);
    }
    for (TimelineEventListener listener : myListeners) {
        listener.onStop();
    }
    myTaskFinished = null;
    myExecutingTask = null;
}
Also used : Client(com.android.ddmlib.Client) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 20 with Client

use of com.android.ddmlib.Client in project android by JetBrains.

the class MemorySampler method recordSample.

@SuppressWarnings("ConstantConditions")
protected void recordSample(int type) {
    float freeMb = 0.0f;
    float allocMb = 0.0f;
    Client client = getClient();
    if (client != null) {
        ClientData.HeapInfo m = client.getClientData().getVmHeapInfo(1);
        if (m != null) {
            allocMb = m.bytesAllocated / (1024.f * 1024.f);
            freeMb = m.sizeInBytes / (1024.f * 1024.f) - allocMb;
        }
    } else {
        type = TYPE_UNREACHABLE;
    }
    // We cannot use the timeStamp in HeapInfo because it's based on the current time of the attached device.
    getTimelineData().add(System.currentTimeMillis(), type, allocMb, freeMb);
}
Also used : ClientData(com.android.ddmlib.ClientData) Client(com.android.ddmlib.Client)

Aggregations

Client (com.android.ddmlib.Client)49 IDevice (com.android.ddmlib.IDevice)6 DumpData (com.android.preload.DumpData)5 Date (java.util.Date)5 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)3 ProcessHandler (com.intellij.execution.process.ProcessHandler)3 IOException (java.io.IOException)3 ClientData (com.android.ddmlib.ClientData)2 Project (com.intellij.openapi.project.Project)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 TreePath (javax.swing.tree.TreePath)2 Nullable (org.jetbrains.annotations.Nullable)2 IClientChangeListener (com.android.ddmlib.AndroidDebugBridge.IClientChangeListener)1 NullOutputReceiver (com.android.ddmlib.NullOutputReceiver)1 InstantRunClient (com.android.tools.fd.client.InstantRunClient)1 InstantRunPushFailedException (com.android.tools.fd.client.InstantRunPushFailedException)1 HierarchyViewAction (com.android.tools.idea.ddms.actions.HierarchyViewAction)1 GfxinfoHandler (com.android.tools.idea.monitor.gpu.gfxinfohandlers.GfxinfoHandler)1 AllocationTrackingSample (com.android.tools.idea.monitor.ui.memory.model.AllocationTrackingSample)1