Search in sources :

Example 1 with CpuUsageSegment

use of com.android.tools.idea.monitor.ui.cpu.view.CpuUsageSegment 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 CpuUsageSegment

use of com.android.tools.idea.monitor.ui.cpu.view.CpuUsageSegment in project android by JetBrains.

the class CpuProfilerVisualTest 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);
    //TODO Update test data for CpuUsageSegment to be exactly what it was.
    EventDispatcher<ProfilerEventListener> dummyDispatcher = EventDispatcher.create(ProfilerEventListener.class);
    mCPULevel2Segment = new CpuUsageSegment(timeCurrentRangeUs, mDataStore, dummyDispatcher);
    mThreadsSegment = new ThreadsSegment(timeCurrentRangeUs, mDataStore, dummyDispatcher, (threads) -> {
    // TODO: show L3 segment with the charts corresponding to threads selected.
    // Hide any charts corresponding to unselected threads and hide L3 segment in case no threads are selected
    });
    List<Animatable> animatables = new ArrayList<>();
    animatables.add(animatedTimeRange);
    animatables.add(mThreadsSegment);
    mCPULevel2Segment.createComponentsList(animatables);
    mThreadsSegment.createComponentsList(animatables);
    return animatables;
}
Also used : AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) ThreadsSegment(com.android.tools.idea.monitor.ui.cpu.view.ThreadsSegment) ThreadStateDataSeries(com.android.tools.profilers.cpu.ThreadStateDataSeries) Range(com.android.tools.adtui.model.Range) CpuUsageSegment(com.android.tools.idea.monitor.ui.cpu.view.CpuUsageSegment) EventDispatcher(com.intellij.util.EventDispatcher) Animatable(com.android.tools.adtui.Animatable) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) ProfilerEventListener(com.android.tools.idea.monitor.tool.ProfilerEventListener) RangeScrollbar(com.android.tools.adtui.RangeScrollbar) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) VisualTest(com.android.tools.adtui.visualtests.VisualTest) List(java.util.List) SeriesData(com.android.tools.adtui.model.SeriesData) ThreadsSegment(com.android.tools.idea.monitor.ui.cpu.view.ThreadsSegment) TestDataGenerator(com.android.tools.idea.monitor.ui.visual.data.TestDataGenerator) CpuProfiler(com.android.tools.profiler.proto.CpuProfiler) SeriesDataType(com.android.tools.datastore.SeriesDataType) NotNull(org.jetbrains.annotations.NotNull) SeriesDataStore(com.android.tools.datastore.SeriesDataStore) javax.swing(javax.swing) CpuUsageSegment(com.android.tools.idea.monitor.ui.cpu.view.CpuUsageSegment) ArrayList(java.util.ArrayList) Animatable(com.android.tools.adtui.Animatable) ProfilerEventListener(com.android.tools.idea.monitor.tool.ProfilerEventListener) Range(com.android.tools.adtui.model.Range) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange)

Aggregations

ProfilerEventListener (com.android.tools.idea.monitor.tool.ProfilerEventListener)2 CpuUsageSegment (com.android.tools.idea.monitor.ui.cpu.view.CpuUsageSegment)2 Animatable (com.android.tools.adtui.Animatable)1 AnimatedTimeRange (com.android.tools.adtui.AnimatedTimeRange)1 RangeScrollbar (com.android.tools.adtui.RangeScrollbar)1 Range (com.android.tools.adtui.model.Range)1 SeriesData (com.android.tools.adtui.model.SeriesData)1 VisualTest (com.android.tools.adtui.visualtests.VisualTest)1 SeriesDataStore (com.android.tools.datastore.SeriesDataStore)1 SeriesDataType (com.android.tools.datastore.SeriesDataType)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 ThreadsSegment (com.android.tools.idea.monitor.ui.cpu.view.ThreadsSegment)1 MemorySegment (com.android.tools.idea.monitor.ui.memory.view.MemorySegment)1 NetworkSegment (com.android.tools.idea.monitor.ui.network.view.NetworkSegment)1 TestDataGenerator (com.android.tools.idea.monitor.ui.visual.data.TestDataGenerator)1 CpuProfiler (com.android.tools.profiler.proto.CpuProfiler)1 ThreadStateDataSeries (com.android.tools.profilers.cpu.ThreadStateDataSeries)1 JBPanel (com.intellij.ui.components.JBPanel)1