DerivedMetricVisitor.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.metric.BaseMetric;
00005 import edu.rice.cs.hpc.data.experiment.metric.MetricValue;
00006 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
00007 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00008 import edu.rice.cs.hpc.data.experiment.scope.ScopeVisitType;
00009 import edu.rice.cs.hpc.data.experiment.scope.filters.MetricValuePropagationFilter;
00010 
00016 public class DerivedMetricVisitor extends AbstractInclusiveMetricsVisitor {
00017 
00018     private int iExclusive;
00019     private int iInclusive;
00020     private int iBaseMetric;
00021     private boolean withExclusiveAndInclusive;
00022     private Experiment _experiment;
00023     
00031     public DerivedMetricVisitor(Experiment experiment, MetricValuePropagationFilter filter, int iMetricInc, int iMetricExc) {
00032         super(experiment, filter);
00033         this.iExclusive = iMetricExc;
00034         this.iInclusive = iMetricInc;
00035         this.withExclusiveAndInclusive = (iMetricExc > 0);
00036         this._experiment = experiment;
00037         
00038         iBaseMetric = (withExclusiveAndInclusive? iMetricExc:iInclusive);
00039         assert (iMetricInc > 0);
00040     }
00041     
00042     //----------------------------------------------------
00043     // visitor pattern instantiations for each Scope type
00044     //----------------------------------------------------
00045     public void visit(RootScope scope, ScopeVisitType vt) { 
00046         if (vt == ScopeVisitType.PostVisit) {
00047             MetricValue mv = this._experiment.getMetric(this.iInclusive).getValue(scope);
00048             scope.setMetricValue(this.iInclusive, mv);
00049         }
00050     }
00051     
00052     
00058     protected void up(Scope scope, ScopeVisitType vt) {
00059         if (vt == ScopeVisitType.PostVisit) {
00060 
00061         } else if (vt == ScopeVisitType.PreVisit) {
00062             // first, create metric exclusive
00063             BaseMetric metricExc = this._experiment.getMetric(iBaseMetric);
00064             // compute the derived metric of this scope
00065             MetricValue mv = metricExc.getValue(scope);
00066             // set the value of the derived metric into the scope
00067             if (withExclusiveAndInclusive) {
00068                 scope.setMetricValue(this.iExclusive, mv);
00069             }
00070             // copy to the inclusive metric
00071             scope.setMetricValue(this.iInclusive, mv);
00072         }
00073     }
00074     
00080     protected void accumulateToParent(Scope parent, Scope source) {
00081         if (withExclusiveAndInclusive)
00082             // we only compute inclusive metric when the information of exclusive metric is available
00083             parent.accumulateMetric(source, this.iInclusive, this.iInclusive, filter);
00084     }
00085 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1