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());
}
}
}
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;
}
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)));
}
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)));
}
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());
}
}
}
Aggregations