Search in sources :

Example 1 with MemoryPoller

use of com.android.tools.idea.monitor.ui.memory.model.MemoryPoller 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);
}
Also used : AllocationTrackingSample(com.android.tools.idea.monitor.ui.memory.model.AllocationTrackingSample) MemoryPoller(com.android.tools.idea.monitor.ui.memory.model.MemoryPoller) Client(com.android.ddmlib.Client) AndroidDebugBridge(com.android.ddmlib.AndroidDebugBridge)

Example 2 with MemoryPoller

use of com.android.tools.idea.monitor.ui.memory.model.MemoryPoller in project android by JetBrains.

the class MemoryProfilerUiManager method createPollers.

@NotNull
@Override
public Set<Poller> createPollers(int pid) {
    myDataCache = new MemoryDataCache(myMemoryEventDispatcher);
    MemoryPoller poller = new MemoryPoller(myDataStore, myDataCache, pid);
    Map<SeriesDataType, DataAdapter> adapters = poller.createAdapters();
    for (Map.Entry<SeriesDataType, DataAdapter> entry : adapters.entrySet()) {
        // TODO these need to be de-registered
        myDataStore.registerAdapter(entry.getKey(), entry.getValue());
    }
    if (myMemoryDetailView != null) {
        myMemoryDetailView.notifyDataIsReady(myDataCache);
    }
    return Sets.newHashSet(poller);
}
Also used : MemoryDataCache(com.android.tools.idea.monitor.ui.memory.model.MemoryDataCache) MemoryPoller(com.android.tools.idea.monitor.ui.memory.model.MemoryPoller) DataAdapter(com.android.tools.datastore.DataAdapter) SeriesDataType(com.android.tools.datastore.SeriesDataType) Map(java.util.Map) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

MemoryPoller (com.android.tools.idea.monitor.ui.memory.model.MemoryPoller)2 AndroidDebugBridge (com.android.ddmlib.AndroidDebugBridge)1 Client (com.android.ddmlib.Client)1 DataAdapter (com.android.tools.datastore.DataAdapter)1 SeriesDataType (com.android.tools.datastore.SeriesDataType)1 AllocationTrackingSample (com.android.tools.idea.monitor.ui.memory.model.AllocationTrackingSample)1 MemoryDataCache (com.android.tools.idea.monitor.ui.memory.model.MemoryDataCache)1 Map (java.util.Map)1 NotNull (org.jetbrains.annotations.NotNull)1