Search in sources :

Example 1 with MemorySegment

use of com.android.tools.idea.monitor.ui.memory.view.MemorySegment in project android by JetBrains.

the class ProfilerOverviewVisualTest method populateUi.

@Override
public void populateUi(JPanel panel) {
    GridBagLayout gbl = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    JBPanel gridBagPanel = new JBPanel();
    gridBagPanel.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR, 1));
    gridBagPanel.setLayout(gbl);
    // TODO create some controls.
    final JPanel controls = VisualTest.createControlledPane(panel, gridBagPanel);
    // Add Mock Toolbar
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy = 0;
    gbc.gridx = 0;
    gbc.gridwidth = 4;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gridBagPanel.add(createToolbarPanel(), gbc);
    // Add Selection Overlay
    // TODO define sizes for x columns 0 and 1
    gbc.fill = GridBagConstraints.BOTH;
    gbc.gridy = 1;
    gbc.gridx = 2;
    gbc.gridwidth = 1;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gridBagPanel.add(mSelection, gbc);
    // Add Accordion Control
    gbc.gridx = 0;
    gbc.gridwidth = 4;
    gbc.gridy = 1;
    gbc.weighty = 0;
    gbc.weightx = 0;
    gridBagPanel.add(mSegmentsContainer, gbc);
    // Add Scrollbar
    gbc.gridy = 2;
    gridBagPanel.add(mScrollbar, gbc);
    // TODO: fix me, currently it's throwing IllegalArgumentException, the reason is:
    // EventSegment is using {@code DeviceProfilerService} which doesn't exist in visual test concept.
    // Mock event segment
    //BaseSegment eventSegment = new EventSegment(mTimeCurrentRange, mDataStore, ICONS, mEventDispatcher);
    //setupAndRegisterSegment(eventSegment, EVENT_MIN_HEIGHT, MONITOR_PREFERRED_HEIGHT, MONITOR_MAX_HEIGHT);
    // Mock monitor segments
    BaseSegment networkSegment = new NetworkSegment(mTimeCurrentRange, mDataStore, mEventDispatcher);
    setupAndRegisterSegment(networkSegment, 0, MONITOR_PREFERRED_HEIGHT, MONITOR_MAX_HEIGHT);
    BaseSegment memorySegment = new MemorySegment(mTimeCurrentRange, mDataStore, mEventDispatcher);
    setupAndRegisterSegment(memorySegment, 0, MONITOR_PREFERRED_HEIGHT, MONITOR_MAX_HEIGHT);
    BaseSegment cpuSegment = new CpuUsageSegment(mTimeCurrentRange, mDataStore, mEventDispatcher);
    setupAndRegisterSegment(cpuSegment, 0, MONITOR_PREFERRED_HEIGHT, MONITOR_MAX_HEIGHT);
    // Timeline segment
    BaseSegment timeSegment = new TimeAxisSegment(mTimeCurrentRange, mTimeAxis, mEventDispatcher);
    setupAndRegisterSegment(timeSegment, TIME_AXIS_HEIGHT, TIME_AXIS_HEIGHT, TIME_AXIS_HEIGHT);
    // Add left spacer
    Dimension leftSpacer = new Dimension(BaseSegment.getSpacerWidth() + networkSegment.getLabelColumnWidth(), 0);
    gbc.gridy = 0;
    gbc.gridx = 0;
    gbc.gridwidth = 2;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gridBagPanel.add(new Box.Filler(leftSpacer, leftSpacer, leftSpacer), gbc);
    // Add right spacer
    Dimension rightSpacerWidth = new Dimension(BaseSegment.getSpacerWidth(), 0);
    Box.Filler rightSpacer = new Box.Filler(rightSpacerWidth, rightSpacerWidth, rightSpacerWidth);
    gbc.gridy = 0;
    gbc.gridx = 3;
    gbc.gridwidth = 1;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gridBagPanel.add(rightSpacer, gbc);
    // hide right space in L1 by default.
    rightSpacer.setVisible(false);
    // Resize the SelectionComponent based on whether we are in L1 or L2 view.
    // TODO construct/destroyed Level3 segment/elements as we expand/collapse segments
    mEventDispatcher.addListener(new ProfilerEventListener() {

        @Override
        public void profilerExpanded(@NotNull BaseProfilerUiManager.ProfilerType profilerType) {
            switch(profilerType) {
                case NETWORK:
                    maximizeSegment(networkSegment);
                    break;
                case CPU:
                    maximizeSegment(cpuSegment);
                    break;
                case MEMORY:
                    maximizeSegment(memorySegment);
                    break;
            }
            rightSpacer.setVisible(true);
            mResetProfilersButton.setEnabled(true);
        }

        @Override
        public void profilersReset() {
            // Sets all the components back to their preferred states.
            mLayout.resetComponents();
            rightSpacer.setVisible(false);
            mResetProfilersButton.setEnabled(false);
            backProfilersToL1();
        }

        private void maximizeSegment(BaseSegment segment) {
            mLayout.setState(segment, AccordionLayout.AccordionState.MAXIMIZE);
            segment.toggleView(true);
        }

        private void backProfilersToL1() {
            networkSegment.toggleView(false);
            cpuSegment.toggleView(false);
            memorySegment.toggleView(false);
        }
    });
}
Also used : CpuUsageSegment(com.android.tools.idea.monitor.ui.cpu.view.CpuUsageSegment) BaseProfilerUiManager(com.android.tools.idea.monitor.ui.BaseProfilerUiManager) JBPanel(com.intellij.ui.components.JBPanel) MemorySegment(com.android.tools.idea.monitor.ui.memory.view.MemorySegment) TimeAxisSegment(com.android.tools.idea.monitor.ui.TimeAxisSegment) BaseSegment(com.android.tools.idea.monitor.ui.BaseSegment) NetworkSegment(com.android.tools.idea.monitor.ui.network.view.NetworkSegment) ProfilerEventListener(com.android.tools.idea.monitor.tool.ProfilerEventListener)

Example 2 with MemorySegment

use of com.android.tools.idea.monitor.ui.memory.view.MemorySegment in project android by JetBrains.

the class MemoryProfilerVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    long startTimeUs = mDataStore.getLatestTimeUs();
    Range timeCurrentRangeUs = new Range(startTimeUs - RangeScrollbar.DEFAULT_VIEW_LENGTH_US, startTimeUs);
    AnimatedTimeRange animatedTimeRange = new AnimatedTimeRange(timeCurrentRangeUs, 0);
    EventDispatcher<ProfilerEventListener> dummyDispatcher = EventDispatcher.create(ProfilerEventListener.class);
    mSegment = new MemorySegment(timeCurrentRangeUs, mDataStore, dummyDispatcher);
    mRoot = new MemoryInfoTreeNode("Root");
    mDetailSegment = new MemoryDetailSegment(timeCurrentRangeUs, mRoot, dummyDispatcher);
    List<Animatable> animatables = new ArrayList<>();
    animatables.add(animatedTimeRange);
    mSegment.createComponentsList(animatables);
    mDetailSegment.createComponentsList(animatables);
    // Simulate allocation data with stack frames.
    mUpdateDataThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    updateTree(mRoot);
                    Thread.sleep(10);
                }
            } catch (InterruptedException e) {
            }
        }
    };
    mUpdateDataThread.start();
    return animatables;
}
Also used : AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) MemoryInfoTreeNode(com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode) ArrayList(java.util.ArrayList) Range(com.android.tools.adtui.model.Range) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) MemorySegment(com.android.tools.idea.monitor.ui.memory.view.MemorySegment) MemoryDetailSegment(com.android.tools.idea.monitor.ui.memory.view.MemoryDetailSegment) Animatable(com.android.tools.adtui.Animatable) ProfilerEventListener(com.android.tools.idea.monitor.tool.ProfilerEventListener)

Aggregations

ProfilerEventListener (com.android.tools.idea.monitor.tool.ProfilerEventListener)2 MemorySegment (com.android.tools.idea.monitor.ui.memory.view.MemorySegment)2 Animatable (com.android.tools.adtui.Animatable)1 AnimatedTimeRange (com.android.tools.adtui.AnimatedTimeRange)1 Range (com.android.tools.adtui.model.Range)1 BaseProfilerUiManager (com.android.tools.idea.monitor.ui.BaseProfilerUiManager)1 BaseSegment (com.android.tools.idea.monitor.ui.BaseSegment)1 TimeAxisSegment (com.android.tools.idea.monitor.ui.TimeAxisSegment)1 CpuUsageSegment (com.android.tools.idea.monitor.ui.cpu.view.CpuUsageSegment)1 MemoryInfoTreeNode (com.android.tools.idea.monitor.ui.memory.model.MemoryInfoTreeNode)1 MemoryDetailSegment (com.android.tools.idea.monitor.ui.memory.view.MemoryDetailSegment)1 NetworkSegment (com.android.tools.idea.monitor.ui.network.view.NetworkSegment)1 JBPanel (com.intellij.ui.components.JBPanel)1 ArrayList (java.util.ArrayList)1