Skip to content

Commit ac729af

Browse files
committed
GH-423 allow to filter zero self-time nodes
1 parent 9cd2080 commit ac729af

File tree

4 files changed

+64
-28
lines changed

4 files changed

+64
-28
lines changed

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/Bundle.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,7 @@ CPUView_FilterScopeTooltip=Filter scope
176176
CPUView_SearchCalleesScope=Search Callees
177177
CPUView_SearchCallersScope=Search Callers
178178
CPUView_SearchScopeTooltip=Search scope
179+
CPUView_HideZeroSelfTimeTooltip=Hide Nodes With Zero Self Time
179180
CPUView_ExpandMenu=Expand / Collapse
180181
CPUView_ExpandPlainItem=Expand Plain Path
181182
CPUView_ExpandTopmostItem=Expand Topmost Path

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/CPUTreeTableView.java

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@
3636
import javax.swing.JCheckBoxMenuItem;
3737
import javax.swing.JLabel;
3838
import javax.swing.JPopupMenu;
39+
import javax.swing.JToggleButton;
3940
import javax.swing.JTree;
4041
import javax.swing.RowFilter;
4142
import javax.swing.SortOrder;
43+
import javax.swing.SwingUtilities;
4244
import javax.swing.tree.TreeNode;
4345
import javax.swing.tree.TreePath;
4446
import org.graalvm.visualvm.lib.jfluid.client.ClientUtils;
@@ -325,34 +327,64 @@ public boolean include(RowFilter.Entry entry) {
325327
}
326328

327329
protected Component[] getFilterOptions() {
328-
if (!reverse) return super.getFilterOptions();
329-
330-
PopupButton pb = new PopupButton (Icons.getIcon(ProfilerIcons.TAB_CALL_TREE)) {
331-
protected void populatePopup(JPopupMenu popup) {
332-
popup.add(new JCheckBoxMenuItem(FILTER_CALLEES_SCOPE, filterTopMethods) {
333-
{
334-
if (!filterCallerMethods) setEnabled(false);
335-
}
336-
protected void fireActionPerformed(ActionEvent e) {
337-
super.fireActionPerformed(e);
338-
filterTopMethods = !filterTopMethods;
339-
enableFilter();
340-
}
341-
});
342-
popup.add(new JCheckBoxMenuItem(FILTER_CALLERS_SCOPE, filterCallerMethods) {
343-
{
344-
if (!filterTopMethods) setEnabled(false);
345-
}
346-
protected void fireActionPerformed(ActionEvent e) {
347-
super.fireActionPerformed(e);
348-
filterCallerMethods = !filterCallerMethods;
349-
enableFilter();
350-
}
351-
});
330+
if (reverse) {
331+
PopupButton pb = new PopupButton (Icons.getIcon(ProfilerIcons.TAB_CALL_TREE)) {
332+
protected void populatePopup(JPopupMenu popup) {
333+
popup.add(new JCheckBoxMenuItem(FILTER_CALLEES_SCOPE, filterTopMethods) {
334+
{
335+
if (!filterCallerMethods) setEnabled(false);
336+
}
337+
protected void fireActionPerformed(ActionEvent e) {
338+
super.fireActionPerformed(e);
339+
filterTopMethods = !filterTopMethods;
340+
enableFilter();
341+
}
342+
});
343+
popup.add(new JCheckBoxMenuItem(FILTER_CALLERS_SCOPE, filterCallerMethods) {
344+
{
345+
if (!filterTopMethods) setEnabled(false);
346+
}
347+
protected void fireActionPerformed(ActionEvent e) {
348+
super.fireActionPerformed(e);
349+
filterCallerMethods = !filterCallerMethods;
350+
enableFilter();
351+
}
352+
});
353+
}
354+
};
355+
pb.setToolTipText(FILTER_SCOPE_TOOLTIP);
356+
return new Component[] { Box.createHorizontalStrut(5), pb };
357+
} else {
358+
final RowFilter zeroFilter = new RowFilterImpl();
359+
final JToggleButton zeroSelfTime = new JToggleButton(Icons.getIcon(ProfilerIcons.NODE_LEAF)) {
360+
361+
protected void fireActionPerformed(ActionEvent e) {
362+
super.fireActionPerformed(e);
363+
boolean selected = isSelected();
364+
365+
SwingUtilities.invokeLater(() -> {
366+
if (selected) {
367+
treeTable.addRowFilter(zeroFilter);
368+
} else {
369+
treeTable.removeRowFilter(zeroFilter);
370+
}
371+
});
372+
}
373+
};
374+
zeroSelfTime.setToolTipText(HIDE_ZERO_SELF_TIME_TOOLTIP);
375+
return new Component[]{Box.createHorizontalStrut(5), zeroSelfTime};
376+
}
377+
}
378+
379+
private static class RowFilterImpl extends RowFilter implements ProfilerTreeTable.DeleteNodes {
380+
381+
public boolean include(RowFilter.Entry entry) {
382+
PrestimeCPUCCTNode node = (PrestimeCPUCCTNode) entry.getIdentifier();
383+
if (node.isSelfTimeNode() && node.getTotalTime0() == 0) {
384+
return false;
352385
}
353-
};
354-
pb.setToolTipText(FILTER_SCOPE_TOOLTIP);
355-
return new Component[] { Box.createHorizontalStrut(5), pb };
386+
return true;
387+
}
356388
}
357389

358390
protected SearchUtils.TreeHelper getSearchHelper() {

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/cpu/CPUView.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ public abstract class CPUView extends DataView {
6969
static final String SEARCH_CALLEES_SCOPE = messages.getString("CPUView_SearchCalleesScope"); // NOI18N
7070
static final String SEARCH_CALLERS_SCOPE = messages.getString("CPUView_SearchCallersScope"); // NOI18N
7171
static final String SEARCH_SCOPE_TOOLTIP = messages.getString("CPUView_SearchScopeTooltip"); // NOI18N
72+
static final String HIDE_ZERO_SELF_TIME_TOOLTIP = messages.getString("CPUView_HideZeroSelfTimeTooltip"); // NOI18N
7273
static final String EXPAND_MENU = messages.getString("CPUView_ExpandMenu"); // NOI18N
7374
static final String EXPAND_PLAIN_ITEM = messages.getString("CPUView_ExpandPlainItem"); // NOI18N
7475
static final String EXPAND_TOPMOST_ITEM = messages.getString("CPUView_ExpandTopmostItem"); // NOI18N

visualvm/libs.profiler/lib.profiler.ui/src/org/graalvm/visualvm/lib/ui/swing/ProfilerTreeTable.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,6 +440,7 @@ public static abstract class NodeExpansionEvaluator {
440440

441441
}
442442

443+
public static interface DeleteNodes {}
443444

444445
public void setCellRenderer(TreeCellRenderer renderer) {
445446
if (tree != null) {
@@ -960,6 +961,7 @@ protected void fireTreeStructureChanged(Object source, Object[] path,
960961
private List filteredChildren(Object parent) {
961962
if (cache == null) cache = new HashMap();
962963

964+
boolean createFilteredNode = !(filter instanceof DeleteNodes);
963965
TreeNode tParent = (TreeNode)parent;
964966
TreePathKey parentKey = new TreePathKey(getPathToRoot(tParent));
965967
List children = cache.get(parentKey);
@@ -977,7 +979,7 @@ private List filteredChildren(Object parent) {
977979
else entry.setContext(renderer.toString(), child);
978980
if (filter.include(entry)) {
979981
children.add(child);
980-
} else if (parent instanceof CCTNode) {
982+
} else if (createFilteredNode && parent instanceof CCTNode) {
981983
if (filtered == null) filtered = ((CCTNode)child).createFilteredNode();
982984
else filtered.merge((CCTNode)child);
983985
}

0 commit comments

Comments
 (0)