use of com.android.tools.idea.monitor.ui.memory.model.AllocationTrackingSample in project android by JetBrains.
the class MemoryProfilerUiManager method setupExtendedOverviewUi.
@Override
public void setupExtendedOverviewUi(@NotNull JPanel toolbar, @NotNull JPanel overviewPanel) {
super.setupExtendedOverviewUi(toolbar, overviewPanel);
assert myPollerSet != null;
myTriggerHeapDumpButton = new JButton(AndroidIcons.Ddms.DumpHprof);
MemoryPoller poller = (MemoryPoller) Iterables.getOnlyElement(myPollerSet);
myTriggerHeapDumpButton.addActionListener(e -> {
if (poller.requestHeapDump()) {
myEventDispatcher.getMulticaster().profilerExpanded(ProfilerType.MEMORY);
}
});
toolbar.add(myTriggerHeapDumpButton, HorizontalLayout.LEFT);
myAllowAllocationTracking = true;
myAllocationTrackerButton = new JToggleButton(AndroidIcons.Ddms.AllocationTracker, false);
myClient.enableAllocationTracker(false);
myAllocationTrackerButton.addActionListener(e -> {
boolean selected = myAllocationTrackerButton.isSelected();
if (selected) {
if (!myAllowAllocationTracking) {
myAllocationTrackerButton.setSelected(false);
return;
}
myAllowAllocationTracking = false;
myClient.enableAllocationTracker(true);
final long startTime = TimeUnit.NANOSECONDS.toMicros(myDataStore.mapAbsoluteDeviceToRelativeTime(TimeUnit.MICROSECONDS.toNanos(myDataStore.getLatestTimeUs())));
AndroidDebugBridge.addClientChangeListener(new AndroidDebugBridge.IClientChangeListener() {
@Override
public void clientChanged(@NonNull Client client, int changeMask) {
if (client == myClient && (changeMask & Client.CHANGE_HEAP_ALLOCATIONS) != 0) {
final byte[] data = client.getClientData().getAllocationsData();
final long endTime = TimeUnit.NANOSECONDS.toMicros(myDataStore.mapAbsoluteDeviceToRelativeTime(TimeUnit.MICROSECONDS.toNanos(myDataStore.getLatestTimeUs())));
UIUtil.invokeLaterIfNeeded(() -> {
myEventDispatcher.getMulticaster().profilerExpanded(ProfilerType.MEMORY);
if (myProject.isDisposed()) {
return;
}
if (myDataCache != null) {
myDataCache.addAllocationTrackingData(new AllocationTrackingSample(startTime, endTime, data));
}
});
myAllowAllocationTracking = true;
AndroidDebugBridge.removeClientChangeListener(this);
}
}
});
} else {
myClient.requestAllocationDetails();
myClient.enableAllocationTracker(false);
}
myAllocationTrackerButton.updateUI();
});
toolbar.add(myAllocationTrackerButton, HorizontalLayout.LEFT);
}
Aggregations