Changeset 401

Show
Ignore:
Timestamp:
08/11/10 00:51:48 (1 year ago)
Author:
ke
Message:

Added ultra-simple GUI for showing profiles (of the whole tree, or of call or search subtree rooted in selected node).

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • kahina/trunk/src/org/kahina/lp/gui/profiler/LogicProgrammingProfileWindow.java

    r400 r401  
    11package org.kahina.lp.gui.profiler; 
    22 
     3import java.awt.Component; 
     4 
     5import javax.swing.BoxLayout; 
    36import javax.swing.JFrame; 
     7import javax.swing.JPanel; 
     8import javax.swing.JScrollPane; 
     9import javax.swing.JTable; 
    410import javax.swing.WindowConstants; 
    511 
     
    1723        { 
    1824                setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 
    19                 // TODO everything 
     25                setSize(800, 600); 
     26                add(createMainPanel(profile)); 
     27        } 
     28 
     29        private Component createMainPanel(LogicProgrammingProfile profile) 
     30        { 
     31                JPanel result = new JPanel(); 
     32                result.setLayout(new BoxLayout(result, BoxLayout.X_AXIS)); 
     33                result.add(new JScrollPane(createTable(profile))); 
     34                return result; 
     35        } 
     36 
     37        private Component createTable(LogicProgrammingProfile profile) 
     38        { 
     39                JTable result = new JTable(profile.getTableModel()); 
     40                result.setAutoCreateRowSorter(true); 
     41                result.setFillsViewportHeight(true); 
     42                return result; 
    2043        } 
    2144 
  • kahina/trunk/src/org/kahina/lp/profiler/LogicProgrammingProfile.java

    r400 r401  
    33import java.io.Serializable; 
    44import java.util.HashMap; 
     5import java.util.HashSet; 
    56import java.util.Map; 
     7import java.util.Set; 
     8 
     9import javax.swing.table.AbstractTableModel; 
     10import javax.swing.table.TableModel; 
    611 
    712import org.kahina.core.profiler.ProfileEntry; 
     
    1318         */ 
    1419        private static final long serialVersionUID = 4869556554829662187L; 
     20         
     21        private static final String[] COLUMN_NAMES = {"Category", "Name", "Calls", "Redos", "Exits", "Fails"}; 
    1522 
    16         private final Map<ProfileEntry, Integer> callsByEntry = new HashMap<ProfileEntry, Integer>(); 
     23        private final Map<ProfileEntry, Integer> callsByEntry = new HashMap<ProfileEntry, Integer>(); 
    1724         
    18         private final Map<ProfileEntry, Integer> failsByEntry = new HashMap<ProfileEntry, Integer>(); 
     25        private final Map<ProfileEntry, Integer> failsByEntry = new HashMap<ProfileEntry, Integer>(); 
    1926         
    20         private final Map<ProfileEntry, Integer> exitsByEntry = new HashMap<ProfileEntry, Integer>(); 
     27        private final Map<ProfileEntry, Integer> exitsByEntry = new HashMap<ProfileEntry, Integer>(); 
    2128         
    22         private final Map<ProfileEntry, Integer> redosByEntry = new HashMap<ProfileEntry, Integer>(); 
     29        private final Map<ProfileEntry, Integer> redosByEntry = new HashMap<ProfileEntry, Integer>(); 
    2330         
    2431        public void call(ProfileEntry entry) 
     
    5259                count(entry, exitsByEntry); 
    5360        } 
     61         
     62        public TableModel getTableModel() 
     63        { 
     64                Set<ProfileEntry> entrySet = new HashSet<ProfileEntry>(); 
     65                entrySet.addAll(callsByEntry.keySet()); 
     66                entrySet.addAll(redosByEntry.keySet()); 
     67                entrySet.addAll(exitsByEntry.keySet()); 
     68                entrySet.addAll(failsByEntry.keySet()); 
     69                final int size = entrySet.size(); 
     70                final String[] category = new String[size]; 
     71                final String[] name = new String[size]; 
     72                int[] calls = new int[size]; 
     73                int[] redos = new int[size]; 
     74                int[] exits = new int[size]; 
     75                int[] fails = new int[size]; 
     76                int i = 0; 
     77                for (ProfileEntry entry : entrySet) 
     78                { 
     79                        category[i] = entry.getCategory(); 
     80                        name[i] = entry.getName(); 
     81                        calls[i] = nullToZero(callsByEntry.get(entry)); 
     82                        redos[i] = nullToZero(redosByEntry.get(entry)); 
     83                        exits[i] = nullToZero(exitsByEntry.get(entry)); 
     84                        fails[i] = nullToZero(failsByEntry.get(entry)); 
     85                        i++; 
     86                } 
     87                final int[][] numbers = new int[][] {null, null, calls, redos, exits, fails}; 
     88                return new AbstractTableModel() 
     89                { 
     90 
     91                        /** 
     92                         *  
     93                         */ 
     94                        private static final long serialVersionUID = -8811999723282268512L; 
     95 
     96                        @Override 
     97                        public int getColumnCount() 
     98                        { 
     99                                return 6; 
     100                        } 
     101 
     102                        @Override 
     103                        public int getRowCount() 
     104                        { 
     105                                return size; 
     106                        } 
     107 
     108                        @Override 
     109                        public Object getValueAt(int rowIndex, int columnIndex) 
     110                        { 
     111                                if (columnIndex == 0) 
     112                                { 
     113                                        return category[rowIndex]; 
     114                                } 
     115                                if (columnIndex == 1) 
     116                                { 
     117                                        return name[rowIndex]; 
     118                                } 
     119                                return numbers[columnIndex][rowIndex]; 
     120                        } 
     121                         
     122                        @Override 
     123                        public String getColumnName(int columnIndex) 
     124                        { 
     125                                return COLUMN_NAMES[columnIndex]; 
     126                        } 
     127                         
     128                }; 
     129        } 
     130 
     131        private int nullToZero(Integer integer) 
     132        { 
     133                if (integer == null) 
     134                { 
     135                        return 0; 
     136                } 
     137                return integer; 
     138        } 
    54139} 
  • kahina/trunk/src/org/kahina/lp/profiler/LogicProgrammingProfiler.java

    r400 r401  
    1717public class LogicProgrammingProfiler implements KahinaListener 
    1818{ 
     19         
     20        private static final boolean VERBOSE = true; 
    1921         
    2022        private final Mapper<String, ProfileEntry> mapper; 
     
    9193        public LogicProgrammingProfile profileSubtree(KahinaTree tree, int subtreeRootID) 
    9294        { 
     95                if (VERBOSE) 
     96                { 
     97                        System.err.println(this + ".profileSubtree(" + tree + ", " + subtreeRootID + ")"); 
     98                } 
    9399                LogicProgrammingProfile result = new LogicProgrammingProfile(); 
    94100                profileSubtree(tree, subtreeRootID, result, new HashSet<Integer>()); 
     
    117123        } 
    118124 
    119         protected void profileNode(ProfileEntry entry, LogicProgrammingStep step, KahinaTree tree, int stepID, LogicProgrammingProfile profile2, Set<Integer> externalIDs) 
     125        protected void profileNode(ProfileEntry entry, LogicProgrammingStep step, KahinaTree tree, int stepID, LogicProgrammingProfile profile, Set<Integer> externalIDs) 
    120126        { 
    121127                if (step.isRedone()) 
  • kahina/trunk/src/org/kahina/tralesld/profiler/TraleSLDProfiler.java

    r400 r401  
    5252        protected void profileNode(ProfileEntry entry, LogicProgrammingStep step, KahinaTree tree, int stepID, LogicProgrammingProfile profile, Set<Integer> externalIDs) 
    5353        { 
    54                 super.profileNode(step, tree, stepID, profile, externalIDs); 
     54                super.profileNode(entry, step, tree, stepID, profile, externalIDs); 
    5555                if (tree.getNodeStatus(stepID) == TraleSLDStepType.FINISHED) 
    5656                { 
  • kahina/trunk/src/org/kahina/tralesld/visual/fs/TraleSLDVariableBindingSetViewPanel.java

    r357 r401  
    2626        private final JPanel innerPanel; 
    2727         
    28         private final VariableBindingTableModel tableModel = new VariableBindingTableModel();; 
     28        private final VariableBindingTableModel tableModel = new VariableBindingTableModel(); 
    2929 
    30         private VisualizationUtility util = VisualizationUtility.getDefault(); 
     30        private final VisualizationUtility util = VisualizationUtility.getDefault(); 
    3131 
    3232        public TraleSLDVariableBindingSetViewPanel() 
  • kahina/trunk/src/org/kahina/tralesld/visual/fs/VariableBindingTableModel.java

    r354 r401  
    1717        private static final long serialVersionUID = 3379369094266283475L; 
    1818 
    19         private static final String[] columnNames = new String[] { "Variable", "Type" }; 
     19        private static final String[] COLUMN_NAMES = new String[] { "Variable", "Type" }; 
    2020 
    2121        private String[] variableNames = new String[0]; 
     
    2828        public String getColumnName(int columnIndex) 
    2929        { 
    30                 return columnNames[columnIndex]; 
     30                return COLUMN_NAMES[columnIndex]; 
    3131        } 
    3232