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