TraceDataVisitor.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.spaceTimeData;
00002 
00003 import java.util.HashMap;
00004 
00005 import edu.rice.cs.hpc.data.experiment.scope.AlienScope;
00006 import edu.rice.cs.hpc.data.experiment.scope.CallSiteScope;
00007 import edu.rice.cs.hpc.data.experiment.scope.FileScope;
00008 import edu.rice.cs.hpc.data.experiment.scope.GroupScope;
00009 import edu.rice.cs.hpc.data.experiment.scope.LineScope;
00010 import edu.rice.cs.hpc.data.experiment.scope.LoadModuleScope;
00011 import edu.rice.cs.hpc.data.experiment.scope.LoopScope;
00012 import edu.rice.cs.hpc.data.experiment.scope.ProcedureScope;
00013 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
00014 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00015 import edu.rice.cs.hpc.data.experiment.scope.ScopeVisitType;
00016 import edu.rice.cs.hpc.data.experiment.scope.StatementRangeScope;
00017 import edu.rice.cs.hpc.data.experiment.scope.visitors.IScopeVisitor;
00018 import edu.rice.cs.hpc.data.util.IProcedureTable;
00019 
00020 import edu.rice.cs.hpc.traceviewer.data.graph.CallPath;
00021 import edu.rice.cs.hpc.traceviewer.data.graph.ColorTable;
00022 
00023 /**********************************************************
00024  * Visitor class for gathering procedure names and the 
00025  * maximum depth.
00026  * 
00027  * To get the maximum depth, the caller requires to instantiate
00028  * the class, call dfsVisitScopeTree() method from the CCT root
00029  * and call the method getMaxDepth()
00030  **********************************************************/
00031 public class TraceDataVisitor implements IScopeVisitor 
00032 {
00033     final private HashMap<Integer, CallPath> map;
00034     final private IProcedureTable colorTable;
00035     private int maxDepth = 0;
00036 
00037     public TraceDataVisitor() {
00038         map = new HashMap<Integer, CallPath>();
00039         colorTable = new ColorTable();
00040     }
00041 
00042     //----------------------------------------------------
00043     // visitor pattern instantiations for each Scope type
00044     //----------------------------------------------------
00045 
00046     public void visit(Scope scope, ScopeVisitType vt) {  }
00047     public void visit(RootScope scope, ScopeVisitType vt) { }
00048     public void visit(LoadModuleScope scope, ScopeVisitType vt) { }
00049     public void visit(FileScope scope, ScopeVisitType vt) { }
00050     public void visit(AlienScope scope, ScopeVisitType vt) { }
00051     public void visit(LoopScope scope, ScopeVisitType vt) { }
00052     public void visit(StatementRangeScope scope, ScopeVisitType vt) { } 
00053     public void visit(GroupScope scope, ScopeVisitType vt) { }
00054 
00055     public void visit(ProcedureScope scope, ScopeVisitType vt) { 
00056         addProcedure(scope);
00057     }
00058 
00059     public void visit(CallSiteScope scope, ScopeVisitType vt) { 
00060         addProcedure(scope);
00061     }
00062 
00063     public void visit(LineScope scope, ScopeVisitType vt) { 
00064         if (vt == ScopeVisitType.PreVisit) {
00065             int cpid = scope.getCpid();
00066             if (cpid > 0)
00067             {
00068                 Scope cur = scope;
00069                 int depth = 0;
00070                 do
00071                 {
00072                     Scope parent = cur.getParentScope();
00073                     if((cur instanceof CallSiteScope) || (cur instanceof ProcedureScope))
00074                         ++depth;
00075                     cur = parent;
00076                 }
00077                 while(cur != null && !(cur instanceof RootScope));
00078                 this.map.put(cpid, new CallPath(scope, depth));
00079                 maxDepth = Math.max(maxDepth, depth);
00080             }
00081         }
00082     }
00083     
00084     /****
00085      * get the maximum depth from the tree traversal based on the scope
00086      * where this visitor is used.
00087      * 
00088      * @return the maximum depth of a given scope 
00089      */
00090     public int getMaxDepth()
00091     {
00092         return maxDepth;
00093     }
00094     
00095     /****
00096      * get the map of cpid and its call path
00097      * @return a hash map
00098      */
00099     public HashMap<Integer, CallPath> getMap()
00100     {
00101         return map;
00102     }
00103     
00104     /****
00105      * get the list of procedure names used in a given scope.
00106      * 
00107      * @return the instance of IProcedureTable
00108      */
00109     public IProcedureTable getProcedureTable()
00110     {
00111         return colorTable;
00112     }
00113     
00114     private void addProcedure(Scope scope)
00115     {
00116         colorTable.addProcedure(scope.getName());
00117     }
00118 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1