ComputedMetricVisitor.java
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00011 package edu.rice.cs.hpc.data.experiment.scope.visitors;
00012
00013 import edu.rice.cs.hpc.data.experiment.Experiment;
00014 import edu.rice.cs.hpc.data.experiment.metric.*;
00015 import edu.rice.cs.hpc.data.experiment.scope.*;
00016
00017 public class ComputedMetricVisitor implements IScopeVisitor {
00018 private int n;
00019 private double scaling;
00020 private MetricValue[] totals;
00021
00022 public ComputedMetricVisitor(int nMetrics, Scope root2, double scalingFactor) {
00023 this.n = nMetrics;
00024 this.scaling = scalingFactor;
00025
00026
00027 totals = new MetricValue[n];
00028 for (int i=0; i<n; i++)
00029 totals[i] = root2.getMetricValue(n+i);
00030 }
00031
00032
00033
00034
00035 public void visit(RootScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00036 public void visit(LoadModuleScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00037 public void visit(FileScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00038 public void visit(GroupScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00039 public void visit(Scope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00040 public void visit(CallSiteScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00041 public void visit(ProcedureScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00042 public void visit(LoopScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00043 public void visit(StatementRangeScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00044 public void visit(LineScope scope, ScopeVisitType vt) { addComputedMetrics(scope, vt); }
00045
00046 private void addComputedMetrics(Scope scope, ScopeVisitType vt) {
00047 if (vt == ScopeVisitType.PreVisit) {
00048
00049 int exp1 = 0, exp2 = n;
00050 final Experiment exp = (Experiment) scope.getExperiment();
00051 int cmi = exp.getMetricCount() - n;
00052
00053 for (int i=0; i<n; i++) {
00054 double mv1 = MetricValue.getValue(scope.getMetricValue(exp1+i));
00055 double mv2 = MetricValue.getValue(scope.getMetricValue(exp2+i));
00056 double t2 = MetricValue.getValue(totals[i]);
00057 if (mv2 < 0 || t2 <= 0) break;
00058 if (mv1 < 0) mv1 = 0.0;
00059
00060 double value = computeScalability(mv1,mv2,scaling,t2);
00061
00062 MetricValue val = new MetricValue();
00063 MetricValue.setValue(val, value);
00064 scope.setMetricValue(cmi+i, val);
00065 }
00066 }
00067 }
00068
00069 private double computeScalability(double mv1, double mv2, double scaling, double t2) {
00070
00071
00072 return ( mv2 / t2 ) - ( scaling * ( mv1 / t2 ));
00073 }
00074 }