Changeset 400

Show
Ignore:
Timestamp:
08/10/10 22:21:21 (1 year ago)
Author:
ke
Message:

Further steps towards execution profiler: implemented post-mortem profiling, plugged most things (state, eventing, menu) together.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • kahina/trunk/src/org/kahina/core/KahinaInstance.java

    r399 r400  
    3030import org.kahina.core.io.magazine.ObjectMagazine; 
    3131import org.kahina.core.util.FileUtilities; 
     32import org.kahina.core.util.KahinaSwingUtilities; 
    3233import org.kahina.core.util.ProgressMonitorWrapper; 
    33 import org.kahina.core.util.KahinaSwingUtilities; 
    3434import org.kahina.core.visual.KahinaDefaultView; 
    3535import org.kahina.core.visual.source.KahinaSourceCodeView; 
  • kahina/trunk/src/org/kahina/core/behavior/KahinaTreeBehavior.java

    r397 r400  
    22 
    33import org.kahina.core.KahinaInstance; 
    4 import org.kahina.core.KahinaRunner; 
    54import org.kahina.core.control.KahinaListener; 
    65import org.kahina.core.data.tree.KahinaTree; 
  • kahina/trunk/src/org/kahina/core/event/KahinaDialogEvent.java

    r371 r400  
    1313    public static final int CREEP_POINTS = 7; 
    1414    public static final int FAIL_POINTS = 8; 
     15        public static final int FULL_PROFILE = 9; 
     16        public static final int CALL_SUBTREE_PROFILE = 10; 
     17        public static final int SEARCH_SUBTREE_PROFILE = 11; 
     18        public static final int EDIT_WARNINGS = 12; 
    1519     
    1620    public KahinaDialogEvent(int dialogEventType) 
  • kahina/trunk/src/org/kahina/core/gui/KahinaGUI.java

    r390 r400  
    106106                        System.err.println("Generating views for step fields:"); 
    107107                } 
     108                Field[] fields = stepType.getFields(); 
    108109                for (Field field : stepType.getFields()) 
    109110                { 
     
    150151        if (view1 == null || view2 == null) 
    151152        { 
    152             System.err.println("Error integrating views: " + var1 + " and " + var2); 
     153            throw new RuntimeException("Error integrating views: " + var1 + " and " + var2); 
    153154        } 
    154155        else 
  • kahina/trunk/src/org/kahina/core/gui/KahinaMainWindow.java

    r399 r400  
    3737                JMenuBar menuBar = new JMenuBar(); 
    3838                menuBar.add(new KahinaSessionMenu()); 
     39                 
     40                // TODO these three menus are specific to logic programming or TraleSLD, should be added dynamically 
    3941                menuBar.add(new KahinaParseMenu()); 
    4042                menuBar.add(new KahinaBreakpointMenu()); 
    4143                menuBar.add(new KahinaProfilerMenu()); 
     44                 
    4245                menuBar.add(new KahinaHelpMenu()); 
    4346                this.setJMenuBar(menuBar); 
  • kahina/trunk/src/org/kahina/core/gui/profiler/KahinaProfilerMenu.java

    r399 r400  
    66import javax.swing.JMenu; 
    77 
     8import org.kahina.core.KahinaRunner; 
     9import org.kahina.core.event.KahinaDialogEvent; 
    810import org.kahina.core.util.KahinaSwingUtilities; 
    911 
     
    2628        public void actionPerformed(ActionEvent e) 
    2729        { 
    28                 // TODO Auto-generated method stub 
    29                  
     30                String command = e.getActionCommand(); 
     31                if (command.equals("fullProfile")) 
     32                { 
     33                        KahinaRunner.processEvent(new KahinaDialogEvent(KahinaDialogEvent.FULL_PROFILE)); 
     34                } else if (command.equals("callSubtreeProfile")) 
     35                { 
     36                        KahinaRunner.processEvent(new KahinaDialogEvent(KahinaDialogEvent.CALL_SUBTREE_PROFILE)); 
     37                } else if (command.equals("searchSubtreeProfile")) 
     38                { 
     39                        KahinaRunner.processEvent(new KahinaDialogEvent(KahinaDialogEvent.SEARCH_SUBTREE_PROFILE)); 
     40                } else if (command.equals("editWarnings")) 
     41                { 
     42                        KahinaRunner.processEvent(new KahinaDialogEvent(KahinaDialogEvent.EDIT_WARNINGS)); 
     43                } 
    3044        } 
    3145 
  • kahina/trunk/src/org/kahina/lp/LogicProgrammingState.java

    r384 r400  
    1717import org.kahina.core.event.KahinaMessageEvent; 
    1818import org.kahina.lp.data.text.LogicProgrammingLineReference; 
     19import org.kahina.lp.profiler.LogicProgrammingProfile; 
    1920 
    2021public class LogicProgrammingState extends KahinaState 
     
    3839    protected List<KahinaBreakpoint> failPoints; 
    3940     
     41    protected LogicProgrammingProfile profile; 
     42     
    4043    public LogicProgrammingState() 
    4144    { 
     
    5255        failPoints = new ArrayList<KahinaBreakpoint>(); 
    5356         
    54         //database variant turned out to be too slow 
    55         /* switch (dataHandlingMethod) 
    56         { 
    57             case KahinaDataHandlingMethod.DATABASE: 
    58             { 
    59                 stepTree = new KahinaDbTree(KahinaRunner.getDatabaseHandler()); 
    60                 secondaryStepTree = new KahinaDbTree(KahinaRunner.getDatabaseHandler()); 
    61                 break; 
    62             } 
    63             case KahinaDataHandlingMethod.MEMORY: 
    64             { 
    65                 stepTree = new KahinaMemTree(); 
    66                 secondaryStepTree = new KahinaMemTree(); 
    67                 break; 
    68             } 
    69         }*/ 
     57        profile = new LogicProgrammingProfile(); 
    7058    } 
    7159     
     
    8876        } 
    8977        refs.add(ref); 
    90         //ref.store(); 
    9178        KahinaRunner.processEvent(new KahinaMessageEvent(ref)); 
    9279    } 
     
    173160        return Collections.unmodifiableList(result); 
    174161    } 
     162 
     163        public LogicProgrammingProfile getFullProfile() 
     164        { 
     165                return profile; 
     166        } 
    175167     
    176168} 
  • kahina/trunk/src/org/kahina/lp/LogicProgrammingStep.java

    r383 r400  
    1818    public KahinaSourceCodeLocation codeLocation; 
    1919     
     20    public boolean redone; 
     21     
    2022    public LogicProgrammingStep copy() 
    2123    { 
     
    2426        copy.externalID = externalID; 
    2527        copy.codeLocation = codeLocation; 
     28        copy.redone = redone; 
    2629        return copy; 
    2730    } 
     
    6164        return KahinaRunner.retrieve(LogicProgrammingStep.class, id); 
    6265    } 
     66     
     67    public void setRedone(boolean redone) 
     68    { 
     69        this.redone = redone; 
     70    } 
     71 
     72        public boolean isRedone() 
     73        { 
     74                return redone; 
     75        } 
    6376} 
  • kahina/trunk/src/org/kahina/lp/bridge/LogicProgrammingBridge.java

    r397 r400  
    9090                        LogicProgrammingStep step = LogicProgrammingStep.get(stepID); 
    9191                        step.setGoalDesc(nodeLabel); 
     92                        step.setRedone(false); 
    9293                        step.setSourceCodeLocation(LogicProgrammingStep.get(currentID).getSourceCodeLocation()); 
    9394                        KahinaRunner.store(stepID, step); 
     
    159160                        LogicProgrammingStep lastStep = LogicProgrammingStep.get(lastStepID); 
    160161                        LogicProgrammingStep newStep = lastStep.copy(); 
     162                        newStep.setRedone(true); 
    161163                        int newStepID = state.nextStepID(); 
    162164                        KahinaRunner.store(newStepID, newStep); 
  • kahina/trunk/src/org/kahina/lp/gui/LogicProgrammingGUI.java

    r384 r400  
    44import java.awt.event.KeyEvent; 
    55 
     6import javax.swing.JFrame; 
     7 
    68import org.kahina.core.KahinaInstance; 
    79import org.kahina.core.KahinaRunner; 
    810import org.kahina.core.KahinaStep; 
     11import org.kahina.core.LogicProgrammingInstance; 
    912import org.kahina.core.breakpoint.KahinaBreakpointType; 
    1013import org.kahina.core.control.KahinaController; 
     
    1316import org.kahina.core.gui.KahinaGUI; 
    1417import org.kahina.core.gui.breakpoint.BreakpointEditorWindow; 
     18import org.kahina.core.profiler.DefaultProfileEntryMapper; 
     19import org.kahina.core.profiler.ProfileEntry; 
     20import org.kahina.core.util.Mapper; 
    1521import org.kahina.core.visual.tree.KahinaLayeredTreeView; 
    1622import org.kahina.lp.LogicProgrammingState; 
    1723import org.kahina.lp.LogicProgrammingStepType; 
     24import org.kahina.lp.gui.profiler.LogicProgrammingProfileWindow; 
    1825 
    1926public class LogicProgrammingGUI extends KahinaGUI 
     
    108115                                break; 
    109116                        } 
     117                        case KahinaDialogEvent.FULL_PROFILE: 
     118                        { 
     119                                JFrame window = new LogicProgrammingProfileWindow(((LogicProgrammingState) kahina.getState()).getFullProfile()); 
     120                                window.setTitle("Full profile"); 
     121                                window.setVisible(true); 
     122                                break; 
     123                        } 
     124                        case KahinaDialogEvent.CALL_SUBTREE_PROFILE: 
     125                        { 
     126                                LogicProgrammingState state = (LogicProgrammingState) kahina.getState(); 
     127                                JFrame window = new LogicProgrammingProfileWindow(((LogicProgrammingInstance<?, ?, ?>) kahina).getProfiler().profileSubtree(state.getSecondaryStepTree(), state.getSelectedStepID())); 
     128                                window.setTitle("Call subtree profile"); 
     129                                window.setVisible(true); 
     130                                break; 
     131                        } 
     132                        case KahinaDialogEvent.SEARCH_SUBTREE_PROFILE: 
     133                        { 
     134                                LogicProgrammingState state = (LogicProgrammingState) kahina.getState(); 
     135                                JFrame window = new LogicProgrammingProfileWindow(((LogicProgrammingInstance<?, ?, ?>) kahina).getProfiler().profileSubtree(state.getStepTree(), state.getSelectedStepID())); 
     136                                window.setTitle("Search subtree profile"); 
     137                                window.setVisible(true); 
     138                                break; 
     139                        } 
    110140                } 
    111141        } 
     142 
     143        protected Mapper<String, ProfileEntry> getProfileEntryMapper() 
     144        { 
     145                return new DefaultProfileEntryMapper(); 
     146        } 
    112147} 
  • kahina/trunk/src/org/kahina/lp/profiler/LogicProgrammingProfile.java

    r398 r400  
    11package org.kahina.lp.profiler; 
    22 
     3import java.io.Serializable; 
    34import java.util.HashMap; 
    45import java.util.Map; 
     
    67import org.kahina.core.profiler.ProfileEntry; 
    78 
    8 public class LogicProgrammingProfile 
     9public class LogicProgrammingProfile implements Serializable 
    910{ 
     11        /** 
     12         *  
     13         */ 
     14        private static final long serialVersionUID = 4869556554829662187L; 
     15 
    1016        private final  Map<ProfileEntry, Integer> callsByEntry = new HashMap<ProfileEntry, Integer>(); 
    1117         
  • kahina/trunk/src/org/kahina/lp/profiler/LogicProgrammingProfiler.java

    r398 r400  
    11package org.kahina.lp.profiler; 
     2 
     3import java.util.HashSet; 
     4import java.util.Set; 
    25 
    36import org.kahina.core.KahinaRunner; 
    47import org.kahina.core.control.KahinaListener; 
     8import org.kahina.core.data.tree.KahinaTree; 
    59import org.kahina.core.event.KahinaEvent; 
    610import org.kahina.core.profiler.ProfileEntry; 
    711import org.kahina.core.util.Mapper; 
    812import org.kahina.lp.LogicProgrammingStep; 
     13import org.kahina.lp.LogicProgrammingStepType; 
    914import org.kahina.lp.event.LogicProgrammingBridgeEvent; 
    1015import org.kahina.lp.event.LogicProgrammingBridgeEventType; 
     
    1520        private final Mapper<String, ProfileEntry> mapper; 
    1621         
    17         private final LogicProgrammingProfile profile = new LogicProgrammingProfile()
     22        private final LogicProgrammingProfile profile
    1823         
    19         public LogicProgrammingProfiler(Mapper<String, ProfileEntry> mapper
     24        public LogicProgrammingProfiler(Mapper<String, ProfileEntry> mapper, LogicProgrammingProfile profile
    2025        { 
    2126                this.mapper = mapper; 
     27                this.profile = profile; 
    2228                KahinaRunner.getControl().registerListener("logic programming bridge", this); 
    2329        } 
     
    8389        } 
    8490 
     91        public LogicProgrammingProfile profileSubtree(KahinaTree tree, int subtreeRootID) 
     92        { 
     93                LogicProgrammingProfile result = new LogicProgrammingProfile(); 
     94                profileSubtree(tree, subtreeRootID, result, new HashSet<Integer>()); 
     95                return result; 
     96        } 
     97 
     98        private void profileSubtree(KahinaTree tree, int stepID, LogicProgrammingProfile profile, Set<Integer> externalIDs) 
     99        { 
     100                profileNode(tree, stepID, profile, externalIDs); 
     101                for (int childID : tree.getChildren(stepID)) 
     102                { 
     103                        profileSubtree(tree, childID, profile, externalIDs); 
     104                } 
     105        } 
     106 
     107        protected void profileNode(KahinaTree tree, int stepID, LogicProgrammingProfile profile, Set<Integer> externalIDs) 
     108        { 
     109                LogicProgrammingStep step = KahinaRunner.retrieve(LogicProgrammingStep.class, stepID); 
     110                profileNode(step, tree, stepID, profile, externalIDs); 
     111        } 
     112 
     113        protected void profileNode(LogicProgrammingStep step, KahinaTree tree, int stepID, LogicProgrammingProfile profile, Set<Integer> externalIDs) 
     114        { 
     115                ProfileEntry entry = mapper.map(step.getGoalDesc()); 
     116                profileNode(entry, step, tree, stepID, profile, externalIDs); 
     117        } 
     118 
     119        protected void profileNode(ProfileEntry entry, LogicProgrammingStep step, KahinaTree tree, int stepID, LogicProgrammingProfile profile2, Set<Integer> externalIDs) 
     120        { 
     121                if (step.isRedone()) 
     122                { 
     123                        profile.redo(entry); 
     124                } else 
     125                { 
     126                        profile.call(entry); 
     127                } 
     128                int status = tree.getNodeStatus(stepID); 
     129                if (status == LogicProgrammingStepType.DET_EXIT || status == LogicProgrammingStepType.EXIT) 
     130                { 
     131                        profile.exit(entry); 
     132                } else if (status == LogicProgrammingStepType.FAIL) 
     133                { 
     134                        profile.fail(entry); 
     135                } 
     136        } 
     137 
    85138} 
  • kahina/trunk/src/org/kahina/tralesld/TraleSLDInstance.java

    r381 r400  
    11package org.kahina.tralesld; 
    22 
    3 import org.kahina.core.KahinaInstance; 
    43import org.kahina.core.KahinaRunner; 
     4import org.kahina.core.LogicProgrammingInstance; 
    55import org.kahina.core.event.KahinaEvent; 
    66import org.kahina.core.gui.KahinaViewRegistry; 
     
    99import org.kahina.core.gui.event.KahinaSelectionEvent; 
    1010import org.kahina.core.gui.event.KahinaUpdateEvent; 
     11import org.kahina.lp.profiler.LogicProgrammingProfiler; 
    1112import org.kahina.tralesld.behavior.TraleSLDTreeBehavior; 
    1213import org.kahina.tralesld.bridge.TraleSLDBridge; 
     
    1415import org.kahina.tralesld.data.fs.TraleSLDVariableBindingSet; 
    1516import org.kahina.tralesld.gui.TraleSLDGUI; 
     17import org.kahina.tralesld.profiler.TraleSLDProfiler; 
    1618import org.kahina.tralesld.visual.fs.TraleSLDFeatureStructureView; 
    1719import org.kahina.tralesld.visual.fs.TraleSLDVariableBindingSetView; 
    1820 
    19 public class TraleSLDInstance extends KahinaInstance<TraleSLDState, TraleSLDGUI, TraleSLDBridge> 
     21public class TraleSLDInstance extends LogicProgrammingInstance<TraleSLDState, TraleSLDGUI, TraleSLDBridge> 
    2022{ 
     23         
     24        private final TraleSLDProfiler profiler;  
    2125 
    2226        public TraleSLDInstance() 
     
    2428                // TODO: this reeks a wee bit of Bad Software Design 
    2529                new TraleSLDTreeBehavior(state.getStepTree(), this, state.getSecondaryStepTree()); 
     30                profiler = new TraleSLDProfiler(state.getFullProfile()); 
    2631                // gui = new TraleSLDGUI(TraleSLDStep.class, this); 
    2732                // bridge = new TraleSLDBridge(this, gui); 
     
    3338        { 
    3439                super(state); 
     40                profiler = new TraleSLDProfiler(state.getFullProfile()); 
    3541        KahinaRunner.getControl().registerListener("edge select", this); 
    3642        KahinaRunner.getControl().registerListener("update", this); 
     
    103109                } 
    104110        } 
     111 
     112        @Override 
     113        public LogicProgrammingProfiler getProfiler() 
     114        { 
     115                return profiler; 
     116        } 
    105117} 
  • kahina/trunk/src/org/kahina/tralesld/bridge/TraleSLDBridge.java

    r396 r400  
    218218                        final TraleSLDStep newStep = generateStep(); 
    219219                        newStep.setGoalDesc("rule(" + ruleName + ")"); 
     220                        newStep.setRedone(false); 
    220221                        newStep.setExternalID(extID); 
    221222                        int newStepID = state.nextStepID(); 
  • kahina/trunk/src/org/kahina/tralesld/gui/TraleSLDGUI.java

    r329 r400  
    55import org.kahina.core.KahinaStep; 
    66import org.kahina.core.gui.KahinaViewIntegrationType; 
     7import org.kahina.core.profiler.ProfileEntry; 
     8import org.kahina.core.util.Mapper; 
    79import org.kahina.core.visual.chart.KahinaChartView; 
    810import org.kahina.lp.gui.LogicProgrammingGUI; 
     
    1113import org.kahina.tralesld.data.chart.TraleSLDChartEdgeStatus; 
    1214import org.kahina.tralesld.data.tree.TraleSLDLayerDecider; 
     15import org.kahina.tralesld.profiler.TraleSLDProfileEntryMapper; 
    1316import org.kahina.tralesld.visual.chart.TraleSLDChartEdgeDisplayDecider; 
    1417 
     
    7275        getWindowForVarName("chart").setLocation(0, 150); 
    7376    } 
     77 
     78    @Override 
     79        protected Mapper<String, ProfileEntry> getProfileEntryMapper() 
     80        { 
     81                return new TraleSLDProfileEntryMapper(); 
     82        } 
    7483} 
  • kahina/trunk/src/org/kahina/tralesld/profiler/TraleSLDProfiler.java

    r398 r400  
    1 package org.kahina.lp.profiler; 
     1package org.kahina.tralesld.profiler; 
     2 
     3import java.util.Set; 
    24 
    35import org.kahina.core.KahinaRunner; 
     6import org.kahina.core.data.tree.KahinaTree; 
    47import org.kahina.core.event.KahinaEvent; 
     8import org.kahina.core.profiler.ProfileEntry; 
     9import org.kahina.lp.LogicProgrammingStep; 
     10import org.kahina.lp.profiler.LogicProgrammingProfile; 
     11import org.kahina.lp.profiler.LogicProgrammingProfiler; 
     12import org.kahina.tralesld.TraleSLDStep; 
     13import org.kahina.tralesld.TraleSLDStepType; 
    514import org.kahina.tralesld.control.event.TraleSLDBridgeEvent; 
    615import org.kahina.tralesld.control.event.TraleSLDBridgeEventType; 
    7 import org.kahina.tralesld.profiler.TraleSLDProfileEntryMapper; 
    816 
    917public class TraleSLDProfiler extends LogicProgrammingProfiler 
    1018{ 
    1119 
    12         public TraleSLDProfiler(
     20        public TraleSLDProfiler(LogicProgrammingProfile profile
    1321        { 
    14                 super(new TraleSLDProfileEntryMapper()); 
     22                super(new TraleSLDProfileEntryMapper(), profile); 
    1523                KahinaRunner.getControl().registerListener("traleSLD bridge", this); 
    1624        } 
     
    3341                } 
    3442        } 
     43         
     44        @Override 
     45        protected void profileNode(KahinaTree tree, int stepID, LogicProgrammingProfile profile, Set<Integer> externalIDs) 
     46        { 
     47                TraleSLDStep step = KahinaRunner.retrieve(TraleSLDStep.class, stepID); 
     48                profileNode(step, tree, stepID, profile, externalIDs); 
     49        } 
     50         
     51        @Override 
     52        protected void profileNode(ProfileEntry entry, LogicProgrammingStep step, KahinaTree tree, int stepID, LogicProgrammingProfile profile, Set<Integer> externalIDs) 
     53        { 
     54                super.profileNode(step, tree, stepID, profile, externalIDs); 
     55                if (tree.getNodeStatus(stepID) == TraleSLDStepType.FINISHED) 
     56                { 
     57                        profile.fail(entry); 
     58                } 
     59        } 
    3560 
    3661}