DerivedPercentVisitor.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.metric.BaseMetric;
00004 import edu.rice.cs.hpc.data.experiment.metric.MetricValue;
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 
00018 public class DerivedPercentVisitor implements IScopeVisitor {
00019     private int iExclusive;
00020     private int iInclusive;
00021     private MetricValue objIncAggValue;
00022     private MetricValue objExcAggValue;
00023 
00024     public DerivedPercentVisitor(BaseMetric []metrics, RootScope scopeRoot, int iMetricInc, int iMetricExc) {
00025         this.iInclusive = iMetricInc;
00026         this.iExclusive = iMetricExc;
00027         objIncAggValue = scopeRoot.getMetricValue(iMetricInc);
00028         if (this.iExclusive > 0) {
00029             this.objExcAggValue = scopeRoot.getMetricValue(iMetricExc);
00030         }
00031         //System.out.println("DPV: inc:"+ objIncAggValue.getValue());
00032     }
00033     
00034     public void visit(Scope scope, ScopeVisitType vt) { calc(scope, vt); } 
00035     public void visit(RootScope scope, ScopeVisitType vt) { calc(scope, vt); }
00036     public void visit(LoadModuleScope scope, ScopeVisitType vt) { calc(scope, vt); }
00037     public void visit(FileScope scope, ScopeVisitType vt) { calc(scope, vt); }
00038     public void visit(ProcedureScope scope, ScopeVisitType vt) { calc(scope, vt); }
00039     public void visit(AlienScope scope, ScopeVisitType vt) { calc(scope, vt); }
00040     public void visit(LoopScope scope, ScopeVisitType vt) { calc(scope, vt); }
00041     public void visit(StatementRangeScope scope, ScopeVisitType vt) { calc(scope, vt); }
00042     public void visit(CallSiteScope scope, ScopeVisitType vt) { calc(scope, vt); }
00043     public void visit(LineScope scope, ScopeVisitType vt) { calc(scope, vt); }
00044     public void visit(GroupScope scope, ScopeVisitType vt) { calc(scope, vt); }
00045 
00046     //----------------------------------------------------
00047     // propagate a child's metric values to its parent
00048     //----------------------------------------------------
00049 
00050     protected void calc(Scope scope, ScopeVisitType vt) {
00051         if (vt == ScopeVisitType.PostVisit) {
00052             this.setPercent(scope, this.iInclusive, this.objIncAggValue);
00053             if (this.iExclusive > 0) {
00054                 this.setPercent(scope, this.iExclusive, this.objExcAggValue);
00055             }
00056         }
00057     }
00058 
00059     
00060     private void setPercent (Scope scope, int iMetricPosition, MetricValue objAggregate) {
00061         MetricValue m = scope.getMetricValue(iMetricPosition);
00062         if ( (m != MetricValue.NONE) && objAggregate != MetricValue.NONE ) {
00063             double value = MetricValue.getValue(m);
00064             double total = MetricValue.getValue(objAggregate);
00065             
00066             if ( total != 0.0 )
00067                 MetricValue.setAnnotationValue(m, value/total);
00068         }
00069     }
00070 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1