Changeset 398

Show
Ignore:
Timestamp:
08/10/10 18:15:27 (1 year ago)
Author:
ke
Message:

Further steps towards execution profiler: implemented live profiling.

Files:

Legend:

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

    r396 r398  
    1 package org.kahina.core.profiler; 
     1package org.kahina.lp.profiler; 
    22 
    3 public class Profile 
     3import java.util.HashMap; 
     4import java.util.Map; 
     5 
     6import org.kahina.core.profiler.ProfileEntry; 
     7 
     8public class LogicProgrammingProfile 
    49{ 
     10        private final  Map<ProfileEntry, Integer> callsByEntry = new HashMap<ProfileEntry, Integer>(); 
     11         
     12        private final  Map<ProfileEntry, Integer> failsByEntry = new HashMap<ProfileEntry, Integer>(); 
     13         
     14        private final  Map<ProfileEntry, Integer> exitsByEntry = new HashMap<ProfileEntry, Integer>(); 
     15         
     16        private final  Map<ProfileEntry, Integer> redosByEntry = new HashMap<ProfileEntry, Integer>(); 
     17         
     18        public void call(ProfileEntry entry) 
     19        { 
     20                count(entry, callsByEntry); 
     21        } 
     22         
     23        public void redo(ProfileEntry entry) 
     24        { 
     25                count(entry, redosByEntry); 
     26        } 
     27 
     28        private void count(ProfileEntry entry, Map<ProfileEntry, Integer> map) 
     29        { 
     30                if (!map.containsKey(entry)) 
     31                { 
     32                        map.put(entry, 1); 
     33                } else 
     34                { 
     35                        map.put(entry, map.get(entry) + 1); 
     36                } 
     37        } 
     38 
     39        public void fail(ProfileEntry entry) 
     40        { 
     41                count(entry, failsByEntry); 
     42        } 
     43 
     44        public void exit(ProfileEntry entry) 
     45        { 
     46                count(entry, exitsByEntry); 
     47        } 
    548} 
  • kahina/trunk/src/org/kahina/lp/profiler/LogicProgrammingProfiler.java

    r396 r398  
    11package org.kahina.lp.profiler; 
    22 
     3import org.kahina.core.KahinaRunner; 
    34import org.kahina.core.control.KahinaListener; 
    45import org.kahina.core.event.KahinaEvent; 
    56import org.kahina.core.profiler.ProfileEntry; 
    67import org.kahina.core.util.Mapper; 
     8import org.kahina.lp.LogicProgrammingStep; 
    79import org.kahina.lp.event.LogicProgrammingBridgeEvent; 
     10import org.kahina.lp.event.LogicProgrammingBridgeEventType; 
    811 
    912public class LogicProgrammingProfiler implements KahinaListener 
     
    1215        private final Mapper<String, ProfileEntry> mapper; 
    1316         
     17        private final LogicProgrammingProfile profile = new LogicProgrammingProfile(); 
     18         
    1419        public LogicProgrammingProfiler(Mapper<String, ProfileEntry> mapper) 
    1520        { 
    1621                this.mapper = mapper; 
     22                KahinaRunner.getControl().registerListener("logic programming bridge", this); 
    1723        } 
    1824 
     
    2834        private void processLogicProgrammingBridgeEvent(LogicProgrammingBridgeEvent event) 
    2935        { 
    30                 // TODO Funny, there is no CALL event type yet. Need to change that first. 
     36                int eventType = event.getEventType(); 
     37                if (eventType == LogicProgrammingBridgeEventType.STEP_CALL) 
     38                { 
     39                        call(event.getID()); 
     40                } else if (eventType == LogicProgrammingBridgeEventType.STEP_FAIL) 
     41                { 
     42                        fail(event.getID()); 
     43                } else if (eventType == LogicProgrammingBridgeEventType.STEP_DET_EXIT) 
     44                { 
     45                        exit(event.getID()); 
     46                } else if (eventType == LogicProgrammingBridgeEventType.STEP_NONDET_EXIT) 
     47                { 
     48                        exit(event.getID()); 
     49                } else if (eventType == LogicProgrammingBridgeEventType.STEP_REDO) 
     50                { 
     51                        redo(event.getID()); 
     52                } 
     53        } 
     54         
     55        protected void call(int id) 
     56        { 
     57                profile.call(getProfileEntryForStepID(id)); 
     58        } 
     59         
     60        protected void fail(int id) 
     61        { 
     62                profile.fail(getProfileEntryForStepID(id)); 
     63        } 
     64         
     65        protected void exit(int id) 
     66        { 
     67                profile.exit(getProfileEntryForStepID(id)); 
     68        } 
     69         
     70        protected void redo(int id) 
     71        { 
     72                profile.redo(getProfileEntryForStepID(id)); 
     73        } 
     74 
     75        protected ProfileEntry getProfileEntryForStepID(int stepID) 
     76        { 
     77                return mapper.map(KahinaRunner.retrieve(LogicProgrammingStep.class, stepID).getGoalDesc()); 
     78        } 
     79         
     80        public LogicProgrammingProfile getProfile() 
     81        { 
     82                return profile; 
    3183        } 
    3284