Search in sources :

Example 1 with LongDataSeries

use of com.android.tools.adtui.model.LongDataSeries in project android by JetBrains.

the class ThreadCallsVisualTest method actionPerformed.

/**
   * Invoked when an action occurs.
   */
@Override
public void actionPerformed(ActionEvent e) {
    if (ACTION_START_RECORDING.equals(e.getActionCommand())) {
        if (mSampler == null) {
            mSampler = new Sampler();
        }
        mSampler.startSampling();
        mRecordButton.setActionCommand(ACTION_STOP_RECORDING);
        mRecordButton.setText("Stop Recording");
    } else if (ACTION_STOP_RECORDING.equals(e.getActionCommand())) {
        mSampler.stopSampling();
        mRecordButton.setActionCommand(ACTION_START_RECORDING);
        mRecordButton.setText("Record");
        setData(mSampler.getData());
    } else if (ACTION_SAVE_RECORDING.equals(e.getActionCommand())) {
    } else if (ACTION_LOAD_RECORDING.equals(e.getActionCommand())) {
    } else if (ACTION_THREAD_SELECTED.equals(e.getActionCommand())) {
        int selected = mComboBox.getSelectedIndex();
        if (selected >= 0 && selected < mComboBox.getItemCount()) {
            String threadName = (String) mComboBox.getSelectedItem();
            mtree = forest.get(threadName);
            mChart.setHTree(mtree);
            double start = mtree.getFirstChild().getStart();
            double end = mtree.getLastChild().getEnd();
            mTimeGlobalRangeUs.setMin(start);
            mTimeGlobalRangeUs.setMax(end);
            mTimeSelectionRangeUs.setMin(start);
            mTimeSelectionRangeUs.setMax(end);
            // Generate dummy values to simulate CPU Load.
            LongDataSeries series = new LongDataSeries();
            RangedContinuousSeries rangedSeries = new RangedContinuousSeries("Threads", mTimeGlobalRangeUs, new Range(0.0, 200.0), series);
            Random r = new Random(System.currentTimeMillis());
            for (int i = 0; i < 100; i++) {
                series.add((long) (start + (end - start) / 100 * i), (long) r.nextInt(100));
            }
            mLineChart.addLine(rangedSeries);
            mScrollBar.setValues(0, mChart.getHeight(), 0, mChart.getMaximumHeight());
        }
    }
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries)

Example 2 with LongDataSeries

use of com.android.tools.adtui.model.LongDataSeries in project android by JetBrains.

the class AccordionVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    mStartTimeUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime());
    Range timeGlobalRangeUs = new Range(0, 0);
    mAnimatedTimeRange = new AnimatedTimeRange(timeGlobalRangeUs, mStartTimeUs);
    mPanelX = new JBPanel();
    mPanelY = new JBPanel();
    mAccordionX = new AccordionLayout(mPanelX, AccordionLayout.Orientation.HORIZONTAL);
    mAccordionY = new AccordionLayout(mPanelY, AccordionLayout.Orientation.VERTICAL);
    mPanelX.setLayout(mAccordionX);
    mPanelY.setLayout(mAccordionY);
    List<Animatable> componentsList = new ArrayList<>();
    // Add the scene components to the list
    componentsList.add(mAccordionX);
    componentsList.add(mAccordionY);
    componentsList.add(mAnimatedTimeRange);
    mRangedData = new ArrayList<>();
    mData = new ArrayList<>();
    Range yRange = new Range(0.0, 100.0);
    for (int i = 0; i < 4; i++) {
        if (i % 2 == 0) {
            yRange = new Range(0.0, 100.0);
        }
        LongDataSeries series = new LongDataSeries();
        RangedContinuousSeries ranged = new RangedContinuousSeries("Widgets", timeGlobalRangeUs, yRange, series);
        mRangedData.add(ranged);
        mData.add(series);
    }
    return componentsList;
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) ArrayList(java.util.ArrayList) Range(com.android.tools.adtui.model.Range) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries)

Example 3 with LongDataSeries

use of com.android.tools.adtui.model.LongDataSeries in project android by JetBrains.

the class AccordionVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    panel.setLayout(new GridLayout(0, 1));
    Thread mUpdateDataThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - mStartTimeUs;
                    for (LongDataSeries series : mData) {
                        ImmutableList<SeriesData<Long>> data = series.getAllData();
                        long last = data.isEmpty() ? 0 : data.get(data.size() - 1).value;
                        float delta = 10 * ((float) Math.random() - 0.45f);
                        series.add(nowUs, last + (long) delta);
                    }
                    Thread.sleep(LINECHART_DATA_DELAY);
                }
            } catch (InterruptedException e) {
            }
        }
    };
    mUpdateDataThread.start();
    // Creates the vertical accordion at the top half.
    JBPanel yPanel = new JBPanel();
    panel.add(yPanel);
    yPanel.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR));
    final JPanel controlsY = VisualTest.createControlledPane(yPanel, mPanelY);
    controlsY.add(VisualTest.createButton("Reset Weights", listener -> {
        mAccordionY.resetComponents();
    }));
    controlsY.add(VisualTest.createButton("Add Chart", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, 0, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Add Chart With Min", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, MIN_SIZE, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Add Chart With Small Max", listener -> {
        final LineChart chart = generateChart(mAccordionY, AccordionLayout.Orientation.VERTICAL, 0, PREFERRED_SIZE, MAX_SIZE);
        mPanelY.add(chart);
        mChartCountY++;
    }));
    controlsY.add(VisualTest.createButton("Remove Last Chart", listener -> {
        mPanelY.remove(--mChartCountY);
    }));
    controlsY.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
    // Creates the horizontal accordion at the bottom half.
    JBPanel xPanel = new JBPanel();
    panel.add(xPanel);
    xPanel.setBorder(BorderFactory.createLineBorder(AdtUiUtils.DEFAULT_BORDER_COLOR));
    final JPanel controlsX = VisualTest.createControlledPane(xPanel, mPanelX);
    controlsX.add(VisualTest.createButton("Reset Weights", listener -> {
        mAccordionX.resetComponents();
    }));
    controlsX.add(VisualTest.createButton("Add Chart", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, 0, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Add Chart With Min", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, MIN_SIZE, PREFERRED_SIZE, Integer.MAX_VALUE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Add Chart With Small Max", listener -> {
        final LineChart chart = generateChart(mAccordionX, AccordionLayout.Orientation.HORIZONTAL, 0, PREFERRED_SIZE, MAX_SIZE);
        mPanelX.add(chart);
        mChartCountX++;
    }));
    controlsX.add(VisualTest.createButton("Remove Last Chart", listener -> {
        mPanelX.remove(--mChartCountX);
    }));
    controlsX.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart) ImmutableList(com.intellij.util.containers.ImmutableList) AdtUiUtils(com.android.tools.adtui.common.AdtUiUtils) MouseEvent(java.awt.event.MouseEvent) ArrayList(java.util.ArrayList) java.awt(java.awt) TimeUnit(java.util.concurrent.TimeUnit) com.android.tools.adtui(com.android.tools.adtui) List(java.util.List) SeriesData(com.android.tools.adtui.model.SeriesData) JBPanel(com.intellij.ui.components.JBPanel) MouseAdapter(java.awt.event.MouseAdapter) NotNull(org.jetbrains.annotations.NotNull) javax.swing(javax.swing) LongDataSeries(com.android.tools.adtui.model.LongDataSeries) JBPanel(com.intellij.ui.components.JBPanel) SeriesData(com.android.tools.adtui.model.SeriesData) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 4 with LongDataSeries

use of com.android.tools.adtui.model.LongDataSeries in project android by JetBrains.

the class AxisLineChartVisualTest method populateUi.

@Override
protected void populateUi(@NotNull JPanel panel) {
    panel.setLayout(new BorderLayout());
    JLayeredPane mockTimelinePane = createMockTimeline();
    panel.add(mockTimelinePane, BorderLayout.CENTER);
    final JBPanel controls = new JBPanel();
    LayoutManager manager = new BoxLayout(controls, BoxLayout.Y_AXIS);
    controls.setLayout(manager);
    panel.add(controls, BorderLayout.WEST);
    final AtomicInteger variance = new AtomicInteger(10);
    final AtomicInteger delay = new AtomicInteger(10);
    Thread mUpdateDataThread = new Thread() {

        @Override
        public void run() {
            try {
                while (true) {
                    long nowUs = TimeUnit.NANOSECONDS.toMicros(System.nanoTime()) - mStartTimeUs;
                    for (LongDataSeries series : mData) {
                        ImmutableList<SeriesData<Long>> data = series.getAllData();
                        long last = data.isEmpty() ? 0 : data.get(data.size() - 1).value;
                        float delta = 10 * ((float) Math.random() - 0.45f);
                        series.add(nowUs, last + (long) delta);
                    }
                    Thread.sleep(delay.get());
                }
            } catch (InterruptedException e) {
            }
        }
    };
    mUpdateDataThread.start();
    controls.add(VisualTest.createVariableSlider("Delay", 10, 5000, new VisualTests.Value() {

        @Override
        public void set(int v) {
            delay.set(v);
        }

        @Override
        public int get() {
            return delay.get();
        }
    }));
    controls.add(VisualTest.createVariableSlider("Variance", 0, 50, new VisualTests.Value() {

        @Override
        public void set(int v) {
            variance.set(v);
        }

        @Override
        public int get() {
            return variance.get();
        }
    }));
    controls.add(VisualTest.createCheckbox("Stable Scroll", itemEvent -> mScrollbar.setStableScrolling(itemEvent.getStateChange() == ItemEvent.SELECTED)));
    controls.add(VisualTest.createCheckbox("Clamp To Major Ticks", itemEvent -> mMemoryAxis1.setClampToMajorTicks(itemEvent.getStateChange() == ItemEvent.SELECTED)));
    controls.add(VisualTest.createCheckbox("Sync Vertical Axes", itemEvent -> mMemoryAxis2.setParentAxis(itemEvent.getStateChange() == ItemEvent.SELECTED ? mMemoryAxis1 : null)));
    controls.add(new Box.Filler(new Dimension(0, 0), new Dimension(300, Integer.MAX_VALUE), new Dimension(300, Integer.MAX_VALUE)));
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) ItemEvent(java.awt.event.ItemEvent) Range(com.android.tools.adtui.model.Range) Arrays(java.util.Arrays) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LineChart(com.android.tools.adtui.chart.linechart.LineChart) ImmutableList(com.intellij.util.containers.ImmutableList) ComponentEvent(java.awt.event.ComponentEvent) ArrayList(java.util.ArrayList) java.awt(java.awt) ComponentAdapter(java.awt.event.ComponentAdapter) TimeUnit(java.util.concurrent.TimeUnit) com.android.tools.adtui(com.android.tools.adtui) List(java.util.List) MemoryAxisFormatter(com.android.tools.adtui.common.formatter.MemoryAxisFormatter) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) SeriesData(com.android.tools.adtui.model.SeriesData) JBLayeredPane(com.intellij.ui.components.JBLayeredPane) JBPanel(com.intellij.ui.components.JBPanel) NotNull(org.jetbrains.annotations.NotNull) TimeAxisFormatter(com.android.tools.adtui.common.formatter.TimeAxisFormatter) javax.swing(javax.swing) LongDataSeries(com.android.tools.adtui.model.LongDataSeries) JBPanel(com.intellij.ui.components.JBPanel) SeriesData(com.android.tools.adtui.model.SeriesData) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 5 with LongDataSeries

use of com.android.tools.adtui.model.LongDataSeries in project android by JetBrains.

the class FlameGraphVisualTest method actionPerformed.

/**
   * Invoked when an action occurs.
   */
@Override
public void actionPerformed(ActionEvent e) {
    if (ACTION_START_RECORDING.equals(e.getActionCommand())) {
        if (mSampler == null) {
            mSampler = new Sampler();
        }
        mSampler.startSampling();
        mRecordButton.setActionCommand(ACTION_STOP_RECORDING);
        mRecordButton.setText("Stop Recording");
    } else if (ACTION_STOP_RECORDING.equals(e.getActionCommand())) {
        mSampler.stopSampling();
        mRecordButton.setActionCommand(ACTION_START_RECORDING);
        mRecordButton.setText("Record");
        setData(mSampler.getData());
    } else if (ACTION_SAVE_RECORDING.equals(e.getActionCommand())) {
    } else if (ACTION_LOAD_RECORDING.equals(e.getActionCommand())) {
    } else if (ACTION_THREAD_SELECTED.equals(e.getActionCommand())) {
        int selected = mComboBox.getSelectedIndex();
        if (selected >= 0 && selected < mComboBox.getItemCount()) {
            String threadName = (String) mComboBox.getSelectedItem();
            mtree = furnace.get(threadName);
            mChart.setHTree(mtree);
            double start = mtree.getFirstChild().getStart();
            double end = mtree.getLastChild().getEnd();
            mTimeGlobalRangeUs.setMin(start);
            mTimeGlobalRangeUs.setMax(end);
            mTimeSelectionRangeUs.setMin(start);
            mTimeSelectionRangeUs.setMax(end);
            // Generate dummy values to simulate CPU Load.
            LongDataSeries series = new LongDataSeries();
            RangedContinuousSeries rangedSeries = new RangedContinuousSeries("CPU Load", mTimeGlobalRangeUs, new Range(0.0, (float) Sampler.MAX_VALUE), series);
            Random r = new Random(System.currentTimeMillis());
            for (int i = 0; i < 100; i++) {
                series.add((long) (start + (end - start) / 100 * i), (long) r.nextInt(100));
            }
            mLineChart.addLine(rangedSeries);
            mScrollBar.setValues(mChart.getMaximumHeight() - mChart.getHeight(), mChart.getHeight(), 0, mChart.getMaximumHeight());
        }
    }
}
Also used : LongDataSeries(com.android.tools.adtui.model.LongDataSeries) Range(com.android.tools.adtui.model.Range) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries)

Aggregations

LongDataSeries (com.android.tools.adtui.model.LongDataSeries)6 Range (com.android.tools.adtui.model.Range)6 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)6 ArrayList (java.util.ArrayList)4 LineChart (com.android.tools.adtui.chart.linechart.LineChart)3 JBPanel (com.intellij.ui.components.JBPanel)3 com.android.tools.adtui (com.android.tools.adtui)2 SeriesData (com.android.tools.adtui.model.SeriesData)2 ImmutableList (com.intellij.util.containers.ImmutableList)2 java.awt (java.awt)2 List (java.util.List)2 TimeUnit (java.util.concurrent.TimeUnit)2 javax.swing (javax.swing)2 NotNull (org.jetbrains.annotations.NotNull)2 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)1 AdtUiUtils (com.android.tools.adtui.common.AdtUiUtils)1 MemoryAxisFormatter (com.android.tools.adtui.common.formatter.MemoryAxisFormatter)1 TimeAxisFormatter (com.android.tools.adtui.common.formatter.TimeAxisFormatter)1 JBLayeredPane (com.intellij.ui.components.JBLayeredPane)1 ComponentAdapter (java.awt.event.ComponentAdapter)1