# HG changeset patch # User Alex Macdonald # Date 1467226910 14400 # Node ID 1f5dc3abcf1627dbf8207b5c016ffec605d758a0 # Parent 59385cdc7d0dc35269bf0a7689be82a77af11737 Sort profiler results table by execution time Backport of 4e6f50297303 from HEAD. PR3046 Reviewed-by: jerboaa Review-thread: http://icedtea.classpath.org/pipermail/thermostat/2016-June/019927.html diff -r 59385cdc7d0d -r 1f5dc3abcf16 vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileView.java --- a/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileView.java Wed Jun 29 15:01:48 2016 -0400 +++ b/vm-profiler/client-swing/src/main/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileView.java Wed Jun 29 15:01:50 2016 -0400 @@ -63,6 +63,8 @@ import javax.swing.JTable; import javax.swing.JToggleButton; import javax.swing.ListSelectionModel; +import javax.swing.RowSorter; +import javax.swing.SortOrder; import javax.swing.SwingUtilities; import javax.swing.SwingWorker; import javax.swing.WindowConstants; @@ -260,6 +262,10 @@ return super.getCellRenderer(row, column); } }; + List sortKeys = new ArrayList<>(); + sortKeys.add(new RowSorter.SortKey(COLUMN_METHOD_TIME, SortOrder.DESCENDING)); + profileTable.getRowSorter().setSortKeys(sortKeys); + profileTable.setName("METHOD_TABLE"); tabPane.addTab(translator.localize(LocaleResources.PROFILER_RESULTS_TABLE).getContents(), diff -r 59385cdc7d0d -r 1f5dc3abcf16 vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileViewTest.java --- a/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileViewTest.java Wed Jun 29 15:01:48 2016 -0400 +++ b/vm-profiler/client-swing/src/test/java/com/redhat/thermostat/vm/profiler/client/swing/internal/SwingVmProfileViewTest.java Wed Jun 29 15:01:50 2016 -0400 @@ -36,6 +36,7 @@ package com.redhat.thermostat.vm.profiler.client.swing.internal; +import com.redhat.thermostat.client.swing.components.ThermostatTable; import net.java.openjdk.cacio.ctc.junit.CacioFESTRunner; import static org.junit.Assert.assertEquals; @@ -67,6 +68,7 @@ import org.fest.swing.fixture.FrameFixture; import org.fest.swing.fixture.JLabelFixture; import org.fest.swing.fixture.JListFixture; +import org.fest.swing.fixture.JScrollPaneFixture; import org.fest.swing.fixture.JTableFixture; import org.fest.swing.fixture.JToggleButtonFixture; import org.junit.After; @@ -268,6 +270,40 @@ }); } + + @GUITest + @Test + public void testMethodsWithLargestExecutionTimeAppearFirst() throws InvocationTargetException, InterruptedException { + + frame.show(); + + final JScrollPaneFixture scrollPane = frame.scrollPane("METHOD_TABLE"); + + List data = new ArrayList<>(); + data.add(new ProfilingResult.MethodInfo(new MethodDescriptorConverter.MethodDeclaration( + "foo", Arrays.asList("int"), "int"), 10000, 70)); + data.add(new ProfilingResult.MethodInfo(new MethodDescriptorConverter.MethodDeclaration( + "bar", Arrays.asList("int"), "double"), 1000, 30)); + data.add(new ProfilingResult.MethodInfo(new MethodDescriptorConverter.MethodDeclaration( + "baz", Arrays.asList("double"), "double"), 100, 30)); + final ProfilingResult result = new ProfilingResult(data); + + view.setProfilingDetailData(result); + + SwingUtilities.invokeAndWait(new Runnable() { + @Override + public void run() { + TableModel model = + ((ThermostatTable) scrollPane.component().getViewport().getView()).getModel(); + assertEquals(3, model.getRowCount()); + + assertEquals("int foo(int)", model.getValueAt(0, 0).toString()); + assertEquals("double bar(int)", model.getValueAt(1, 0).toString()); + assertEquals("double baz(double)", model.getValueAt(2, 0).toString()); + } + }); + } + @GUITest @Test public void testSetProfilingDetailDataWithResults() throws InvocationTargetException,