Search in sources :

Example 1 with HeapListener

use of io.flutter.perf.HeapMonitor.HeapListener in project flutter-intellij by flutter.

the class HeapState method createJPanelView.

public static JPanel createJPanelView(Disposable parentDisposable, FlutterApp app) {
    final JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(IdeBorderFactory.createBorder(SideBorder.TOP));
    panel.setPreferredSize(new Dimension(100, PANEL_HEIGHT));
    final JBLabel rssLabel = new JBLabel();
    rssLabel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    rssLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    rssLabel.setForeground(UIUtil.getLabelDisabledForeground());
    rssLabel.setBorder(JBUI.Borders.empty(4));
    final JBLabel heapLabel = new JBLabel("", SwingConstants.RIGHT);
    heapLabel.setAlignmentY(Component.BOTTOM_ALIGNMENT);
    heapLabel.setFont(UIUtil.getLabelFont(UIUtil.FontSize.SMALL));
    heapLabel.setForeground(UIUtil.getLabelDisabledForeground());
    heapLabel.setBorder(JBUI.Borders.empty(4));
    final HeapState heapState = new HeapState(60 * 1000);
    final HeapDisplay graph = new HeapDisplay(state -> {
        rssLabel.setText(heapState.getRSSSummary());
        heapLabel.setText(heapState.getHeapSummary());
        SwingUtilities.invokeLater(rssLabel::repaint);
        SwingUtilities.invokeLater(heapLabel::repaint);
    });
    graph.setLayout(new BoxLayout(graph, BoxLayout.X_AXIS));
    graph.add(rssLabel);
    graph.add(Box.createHorizontalGlue());
    graph.add(heapLabel);
    panel.add(graph, BorderLayout.CENTER);
    final HeapListener listener = new HeapListener() {

        @Override
        public void handleIsolatesInfo(VM vm, List<IsolateObject> isolates) {
            heapState.handleIsolatesInfo(vm, isolates);
            graph.updateFrom(heapState);
            SwingUtilities.invokeLater(panel::repaint);
        }

        @Override
        public void handleGCEvent(IsolateRef iIsolateRef, HeapSpace newHeapSpace, HeapSpace oldHeapSpace) {
            heapState.handleGCEvent(iIsolateRef, newHeapSpace, oldHeapSpace);
            graph.updateFrom(heapState);
            SwingUtilities.invokeLater(panel::repaint);
        }
    };
    assert app.getPerfService() != null;
    app.getPerfService().addListener(listener);
    Disposer.register(parentDisposable, () -> app.getPerfService().removeListener(listener));
    return panel;
}
Also used : IsolateRef(org.dartlang.vm.service.element.IsolateRef) HeapListener(io.flutter.perf.HeapMonitor.HeapListener) HeapSpace(io.flutter.perf.HeapMonitor.HeapSpace) JBLabel(com.intellij.ui.components.JBLabel) VM(org.dartlang.vm.service.element.VM) List(java.util.List)

Aggregations

JBLabel (com.intellij.ui.components.JBLabel)1 HeapListener (io.flutter.perf.HeapMonitor.HeapListener)1 HeapSpace (io.flutter.perf.HeapMonitor.HeapSpace)1 List (java.util.List)1 IsolateRef (org.dartlang.vm.service.element.IsolateRef)1 VM (org.dartlang.vm.service.element.VM)1