Search in sources :

Example 1 with Range

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

the class ProfilerScrollbar method animate.

@Override
public void animate(float frameLength) {
    Range dataRangeUs = myTimeline.getDataRange();
    Range viewRangeUs = myTimeline.getViewRange();
    int dataExtentMs = (int) ((dataRangeUs.getLength() - myTimeline.getViewBuffer()) / MS_TO_US);
    int viewExtentMs = Math.min(dataExtentMs, (int) (viewRangeUs.getLength() / MS_TO_US));
    int viewRelativeMinMs = Math.max(0, (int) ((viewRangeUs.getMin() - dataRangeUs.getMin()) / MS_TO_US));
    if (myScrolling) {
        int valueMs = getValue();
        setValues(valueMs, viewExtentMs, 0, dataExtentMs);
        double deltaUs = (valueMs - viewRelativeMinMs) * MS_TO_US;
        viewRangeUs.shift(deltaUs);
    } else {
        setValues(viewRelativeMinMs, viewExtentMs, 0, dataExtentMs);
    }
}
Also used : Range(com.android.tools.adtui.model.Range)

Example 2 with Range

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

the class CpuMonitorView method populateUi.

@Override
protected void populateUi(JPanel container, Choreographer choreographer) {
    container.setLayout(new TabularLayout("*", "*"));
    Range viewRange = getMonitor().getTimeline().getViewRange();
    Range dataRange = getMonitor().getTimeline().getDataRange();
    final JLabel label = new JLabel(getMonitor().getName());
    label.setBorder(MONITOR_LABEL_PADDING);
    label.setVerticalAlignment(JLabel.TOP);
    // Cpu usage is shown as percentages (e.g. 0 - 100) and no range animation is needed.
    Range leftYRange = new Range(0, 100);
    final JPanel axisPanel = new JBPanel(new BorderLayout());
    axisPanel.setOpaque(false);
    AxisComponent.Builder builder = new AxisComponent.Builder(leftYRange, CPU_USAGE_AXIS, AxisComponent.AxisOrientation.RIGHT).showAxisLine(false).showMax(true).showUnitAtMax(true).setMarkerLengths(MARKER_LENGTH, MARKER_LENGTH).clampToMajorTicks(true).setMargins(0, Y_AXIS_TOP_MARGIN);
    final AxisComponent leftAxis = builder.build();
    axisPanel.add(leftAxis, BorderLayout.WEST);
    final JPanel lineChartPanel = new JBPanel(new BorderLayout());
    lineChartPanel.setOpaque(false);
    lineChartPanel.setBorder(BorderFactory.createEmptyBorder(Y_AXIS_TOP_MARGIN, 0, 0, 0));
    final LineChart lineChart = new LineChart();
    RangedContinuousSeries cpuSeries = new RangedContinuousSeries("CPU", viewRange, leftYRange, getMonitor().getThisProcessCpuUsage());
    lineChart.addLine(cpuSeries, new LineConfig(ProfilerColors.CPU_USAGE).setFilled(true));
    lineChartPanel.add(lineChart, BorderLayout.CENTER);
    final LegendComponent legend = new LegendComponent(LegendComponent.Orientation.HORIZONTAL, LEGEND_UPDATE_FREQUENCY_MS);
    legend.setLegendData(Collections.singletonList(lineChart.createLegendRenderData(cpuSeries, CPU_USAGE_AXIS, dataRange)));
    final JPanel legendPanel = new JBPanel(new BorderLayout());
    legendPanel.setOpaque(false);
    legendPanel.add(label, BorderLayout.WEST);
    legendPanel.add(legend, BorderLayout.EAST);
    choreographer.register(lineChart);
    choreographer.register(leftAxis);
    choreographer.register(legend);
    container.add(legendPanel, new TabularLayout.Constraint(0, 0));
    container.add(leftAxis, new TabularLayout.Constraint(0, 0));
    container.add(lineChartPanel, new TabularLayout.Constraint(0, 0));
    container.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            getMonitor().expand();
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) TabularLayout(com.android.tools.adtui.TabularLayout) MouseAdapter(java.awt.event.MouseAdapter) AxisComponent(com.android.tools.adtui.AxisComponent) Range(com.android.tools.adtui.model.Range) LineConfig(com.android.tools.adtui.chart.linechart.LineConfig) JBPanel(com.intellij.ui.components.JBPanel) RangedContinuousSeries(com.android.tools.adtui.model.RangedContinuousSeries) LegendComponent(com.android.tools.adtui.LegendComponent) LineChart(com.android.tools.adtui.chart.linechart.LineChart)

Example 3 with Range

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

the class CpuProfilerStageView method formatCaptureLabel.

private String formatCaptureLabel(CpuCapture capture) {
    Range range = getStage().getStudioProfilers().getTimeline().getDataRange();
    long min = (long) (capture.getRange().getMin() - range.getMin());
    long max = (long) (capture.getRange().getMax() - range.getMin());
    return formatTime(min) + " - " + formatTime(max);
}
Also used : Range(com.android.tools.adtui.model.Range)

Example 4 with Range

use of com.android.tools.adtui.model.Range 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 5 with Range

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

the class NetworkProfilerVisualTest method createComponentsList.

@Override
protected List<Animatable> createComponentsList() {
    long startTimeUs = myDataStore.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);
    mySegment = new NetworkSegment(timeCurrentRangeUs, myDataStore, dummyDispatcher);
    myDetailedView = new NetworkDetailedView();
    myDetailedView.setVisible(false);
    generateNetworkCaptureData(startTimeUs);
    myCaptureSegment = new NetworkCaptureSegment(timeCurrentRangeUs, new TestNetworkCaptureModel(), httpData -> myDetailedView.setVisible(true), dummyDispatcher);
    myRadioSegment = new NetworkRadioSegment(timeCurrentRangeUs, myDataStore, dummyDispatcher);
    List<Animatable> animatables = new ArrayList<>();
    animatables.add(animatedTimeRange);
    mySegment.createComponentsList(animatables);
    myCaptureSegment.createComponentsList(animatables);
    myRadioSegment.createComponentsList(animatables);
    animatables.add(myCaptureSegment);
    return animatables;
}
Also used : AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) NetworkCaptureModel(com.android.tools.idea.monitor.ui.network.model.NetworkCaptureModel) Range(com.android.tools.adtui.model.Range) NetworkSegment(com.android.tools.idea.monitor.ui.network.view.NetworkSegment) 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) NetworkDetailedView(com.android.tools.idea.monitor.ui.network.view.NetworkDetailedView) ArrayList(java.util.ArrayList) java.awt(java.awt) VisualTest(com.android.tools.adtui.visualtests.VisualTest) HttpData(com.android.tools.idea.monitor.ui.network.model.HttpData) List(java.util.List) NonNull(com.android.annotations.NonNull) NetworkRadioSegment(com.android.tools.idea.monitor.ui.network.view.NetworkRadioSegment) NotNull(org.jetbrains.annotations.NotNull) SeriesDataStore(com.android.tools.datastore.SeriesDataStore) NetworkCaptureSegment(com.android.tools.idea.monitor.ui.network.view.NetworkCaptureSegment) javax.swing(javax.swing) ArrayList(java.util.ArrayList) NetworkCaptureSegment(com.android.tools.idea.monitor.ui.network.view.NetworkCaptureSegment) NetworkDetailedView(com.android.tools.idea.monitor.ui.network.view.NetworkDetailedView) Range(com.android.tools.adtui.model.Range) AnimatedTimeRange(com.android.tools.adtui.AnimatedTimeRange) Animatable(com.android.tools.adtui.Animatable) NetworkSegment(com.android.tools.idea.monitor.ui.network.view.NetworkSegment) ProfilerEventListener(com.android.tools.idea.monitor.tool.ProfilerEventListener) NetworkRadioSegment(com.android.tools.idea.monitor.ui.network.view.NetworkRadioSegment)

Aggregations

Range (com.android.tools.adtui.model.Range)38 RangedContinuousSeries (com.android.tools.adtui.model.RangedContinuousSeries)12 ArrayList (java.util.ArrayList)10 Test (org.junit.Test)10 JBPanel (com.intellij.ui.components.JBPanel)9 LineChart (com.android.tools.adtui.chart.linechart.LineChart)7 SeriesData (com.android.tools.adtui.model.SeriesData)7 LineConfig (com.android.tools.adtui.chart.linechart.LineConfig)6 NotNull (org.jetbrains.annotations.NotNull)6 java.awt (java.awt)5 javax.swing (javax.swing)5 Animatable (com.android.tools.adtui.Animatable)4 AnimatedTimeRange (com.android.tools.adtui.AnimatedTimeRange)4 DefaultDataSeries (com.android.tools.adtui.model.DefaultDataSeries)4 LongDataSeries (com.android.tools.adtui.model.LongDataSeries)4 List (java.util.List)4 com.android.tools.adtui (com.android.tools.adtui)3 SingleUnitAxisFormatter (com.android.tools.adtui.common.formatter.SingleUnitAxisFormatter)3 RangedSeries (com.android.tools.adtui.model.RangedSeries)3 ProfilerEventListener (com.android.tools.idea.monitor.tool.ProfilerEventListener)3