Search in sources :

Example 1 with ThreadStateDataSeries

use of com.android.tools.profilers.cpu.ThreadStateDataSeries in project android by JetBrains.

the class ThreadsSegment method initializeStateChartsList.

private void initializeStateChartsList() {
    mThreadsList.setCellRenderer(new ThreadsStateCellRenderer());
    mThreadsList.setSelectionBackground(AdtUiUtils.DEFAULT_BACKGROUND_COLOR);
    mThreadsList.setFixedCellHeight(mCellHeight);
    if (mThreadSelectedListener != null) {
        mThreadsList.addListSelectionListener((event) -> {
            int[] selectedThreadsIndices = mThreadsList.getSelectedIndices();
            List<ThreadStateDataSeries> selectedThreads = new ArrayList<>();
            for (int i = 0; i < selectedThreadsIndices.length; i++) {
                selectedThreads.add(mThreadsListModel.get(selectedThreadsIndices[i]));
            }
            mThreadSelectedListener.onSelected(selectedThreads);
        });
    }
    mThreadsList.addMouseMotionListener(new MouseAdapter() {

        @Override
        public void mouseMoved(MouseEvent me) {
            Point p = new Point(me.getX(), me.getY());
            int index = mThreadsList.locationToIndex(p);
            if (index != mHoveredListIndex) {
                mHoveredListIndex = index;
                mThreadsList.repaint();
            }
        }
    });
}
Also used : MouseEvent(java.awt.event.MouseEvent) MouseAdapter(java.awt.event.MouseAdapter) ThreadStateDataSeries(com.android.tools.profilers.cpu.ThreadStateDataSeries)

Example 2 with ThreadStateDataSeries

use of com.android.tools.profilers.cpu.ThreadStateDataSeries in project android by JetBrains.

the class CpuProfilerUiManager method onSelected.

@Override
public void onSelected(@NotNull List<ThreadStateDataSeries> selectedThreads) {
    // TODO: Only support mono-selection for now:
    if (selectedThreads.size() != 1) {
        return;
    }
    myEventDispatcher.getMulticaster().profilerExpanded(ProfilerType.CPU);
    resetDetailedComponents();
    ThreadStateDataSeries selectedThread = selectedThreads.get(0);
    int threadId = selectedThread.getProcessId();
    AppTrace trace = TraceDataStore.getInstance().getLastThreadsActivity(myProject.getName());
    if (trace == null) {
        // No trace have been generated.
        return;
    }
    SparseArray<HNode<Method>> availableThreads = trace.getThreadsGraph();
    if (availableThreads.get(threadId) == null) {
        return;
    }
    // Setup topdown panel
    SparseArray<JComponent> topDownTrees = trace.getTopDownTrees();
    myTopdownJpanel.add(topDownTrees.get(threadId), BorderLayout.CENTER);
    // Setup bottomup panel
    SparseArray<JComponent> bottomUpTrees = trace.getBottomUpTrees();
    myBottomupJPanel.add(bottomUpTrees.get(threadId), BorderLayout.CENTER);
    // Setup execution panel
    HNode<Method> executionTree = availableThreads.get(threadId);
    myExecutionChart.setHTree(executionTree);
    if (AppTrace.Source.ART == trace.getSource()) {
        myExecutionChart.setHRenderer(new NativeMethodHRenderer());
    } else {
        myExecutionChart.setHRenderer(new JavaMethodHRenderer());
    }
    // Setup flame graph
    SparseArray<HNode<MethodUsage>> usageTrees = trace.getTopdownStats();
    HNode<MethodUsage> usageTree = usageTrees.get(threadId);
    myFlameChart.setHTree(usageTree);
    myFlameChartRange.set(usageTree.getStart(), usageTree.getEnd());
    myFlameChart.setXRange(myFlameChartRange);
    if (AppTrace.Source.ART == trace.getSource()) {
        myFlameChart.setHRenderer(new NativeMethodUsageHRenderer());
    } else {
        myFlameChart.setHRenderer(new JavaMethodUsageHRenderer());
    }
    // TODO: Selection doesn't seem right. Fix it and also set the proper color (red highlight).
    // TODO: Reinvestigate sycning selection with the LineChart
    myTimeSelectionRangeUs.set(executionTree.getStart(), executionTree.getEnd());
//myTimeSelectionRangeUs.lockValues();
// Setup view with a little bit of margin so selection can be seen.
//long duration = executionTree.getEnd() - executionTree.getStart();
//long durationMargin = duration / 10;
//myTimeCurrentRangeUs.set(executionTree.getStart() - durationMargin, executionTree.getEnd() + durationMargin);
//myTimeCurrentRangeUs.lockValues();
}
Also used : HNode(com.android.tools.adtui.model.HNode) ThreadStateDataSeries(com.android.tools.profilers.cpu.ThreadStateDataSeries) AppTrace(com.android.tools.idea.monitor.ui.cpu.model.AppTrace)

Aggregations

ThreadStateDataSeries (com.android.tools.profilers.cpu.ThreadStateDataSeries)2 HNode (com.android.tools.adtui.model.HNode)1 AppTrace (com.android.tools.idea.monitor.ui.cpu.model.AppTrace)1 MouseAdapter (java.awt.event.MouseAdapter)1 MouseEvent (java.awt.event.MouseEvent)1