AbstractInclusiveMetricsVisitor.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.data.experiment.scope.visitors;
00002 
00003 import edu.rice.cs.hpc.data.experiment.Experiment;
00004 import edu.rice.cs.hpc.data.experiment.scope.AlienScope;
00005 import edu.rice.cs.hpc.data.experiment.scope.CallSiteScope;
00006 import edu.rice.cs.hpc.data.experiment.scope.FileScope;
00007 import edu.rice.cs.hpc.data.experiment.scope.GroupScope;
00008 import edu.rice.cs.hpc.data.experiment.scope.LineScope;
00009 import edu.rice.cs.hpc.data.experiment.scope.LoadModuleScope;
00010 import edu.rice.cs.hpc.data.experiment.scope.LoopScope;
00011 import edu.rice.cs.hpc.data.experiment.scope.ProcedureScope;
00012 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
00013 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00014 import edu.rice.cs.hpc.data.experiment.scope.ScopeVisitType;
00015 import edu.rice.cs.hpc.data.experiment.scope.StatementRangeScope;
00016 import edu.rice.cs.hpc.data.experiment.scope.filters.InclusiveOnlyMetricPropagationFilter;
00017 import edu.rice.cs.hpc.data.experiment.scope.filters.MetricValuePropagationFilter;
00018 
00019 public abstract class AbstractInclusiveMetricsVisitor implements IScopeVisitor {
00020 
00021     protected MetricValuePropagationFilter filter;
00022 
00023     public AbstractInclusiveMetricsVisitor(Experiment experiment, MetricValuePropagationFilter currentFilter) {
00024         this.filter = currentFilter;
00025     }
00026     //----------------------------------------------------
00027     // visitor pattern instantiations for each Scope type
00028     //----------------------------------------------------
00029 
00030     public void visit(Scope scope, ScopeVisitType vt) { up(scope, vt); }
00031     public void visit(RootScope scope, ScopeVisitType vt) { }
00032     public void visit(LoadModuleScope scope, ScopeVisitType vt) { up(scope, vt); }
00033     public void visit(FileScope scope, ScopeVisitType vt) { up(scope, vt); }
00034     public void visit(ProcedureScope scope, ScopeVisitType vt) { up(scope, vt); }
00035     public void visit(AlienScope scope, ScopeVisitType vt) { up(scope, vt); }
00036     public void visit(LoopScope scope, ScopeVisitType vt) { up(scope, vt); }
00037     public void visit(LineScope scope, ScopeVisitType vt) { up(scope, vt); }
00038     public void visit(StatementRangeScope scope, ScopeVisitType vt) { up(scope, vt); }
00039     public void visit(CallSiteScope scope, ScopeVisitType vt) { up(scope, vt); }
00040     public void visit(GroupScope scope, ScopeVisitType vt) { up(scope, vt); }
00041 
00042     //----------------------------------------------------
00043     // propagate a child's metric values to its parent
00044     //----------------------------------------------------
00045 
00046     protected void up(Scope scope, ScopeVisitType vt) {
00047         if (vt == ScopeVisitType.PostVisit) {
00048             Scope parent = scope.getParentScope();
00049             if (parent != null) {
00050                 if (scope instanceof CallSiteScope) {
00051                     // inclusive view: add everything
00052                     accumulateToParent( parent, scope );
00053                 } else {
00054                     // New definition of exclusive cost:
00055                     //  The cost of Outer loop does not include the cost of inner loop 
00056                     if(parent instanceof LoopScope && scope instanceof LoopScope) {
00057                         // for nested loop: we need to accumulate the inclusive but not exclusive.
00058                         if(filter instanceof InclusiveOnlyMetricPropagationFilter) {
00059                             // During the creation of CCT, we call this class twice: one for exclusive, the other for incl
00060                             // so we need to make sure that only the inclusive is taken
00061                             accumulateToParent( parent, scope );
00062                         }
00063                         return;
00064                     } 
00065                     accumulateToParent( parent, scope );
00066                 }
00067             }
00068         }
00069     }
00070     
00071     
00077     abstract protected void accumulateToParent(Scope parent, Scope source) ;
00078 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1