PercentScopeVisitor.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.MetricValue;
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
00017 public class PercentScopeVisitor implements IScopeVisitor {
00018 RootScope root;
00019 int metricCount;
00020 int metricOffset;
00021
00022 public PercentScopeVisitor(int metricCount, RootScope r) {
00023 this.metricCount = metricCount;
00024 metricOffset = 0;
00025 root = r;
00026 }
00027
00028 public PercentScopeVisitor(int metricOffset, int metricCount, RootScope r) {
00029 this.metricCount = metricCount;
00030 this.metricOffset = metricOffset;
00031 root = r;
00032 }
00033
00034
00035
00036
00037
00038 public void visit(Scope scope, ScopeVisitType vt) { calc(scope, vt); }
00039 public void visit(RootScope scope, ScopeVisitType vt) { calc(scope, vt); }
00040 public void visit(LoadModuleScope scope, ScopeVisitType vt) { calc(scope, vt); }
00041 public void visit(FileScope scope, ScopeVisitType vt) { calc(scope, vt); }
00042 public void visit(ProcedureScope scope, ScopeVisitType vt) { calc(scope, vt); }
00043 public void visit(AlienScope scope, ScopeVisitType vt) { calc(scope, vt); }
00044 public void visit(LoopScope scope, ScopeVisitType vt) { calc(scope, vt); }
00045 public void visit(StatementRangeScope scope, ScopeVisitType vt) { calc(scope, vt); }
00046 public void visit(CallSiteScope scope, ScopeVisitType vt) { calc(scope, vt); }
00047 public void visit(LineScope scope, ScopeVisitType vt) { calc(scope, vt); }
00048 public void visit(GroupScope scope, ScopeVisitType vt) { calc(scope, vt); }
00049
00050
00051
00052
00053
00054 protected void calc(Scope scope, ScopeVisitType vt) {
00055 if (vt == ScopeVisitType.PostVisit) {
00056 setPercentValue(scope);
00057 }
00058 }
00059
00060
00061
00062
00063
00064
00065
00066
00067 protected void setPercentValue(Scope scope) {
00068 for (int i = metricOffset; i < metricCount; i++) {
00069 MetricValue m = scope.getMetricValue(i);
00070 MetricValue root_value = root.getMetricValue(i);
00071 if (m != MetricValue.NONE && root_value != MetricValue.NONE) {
00072 double myValue = MetricValue.getValue(m);
00073 double total = MetricValue.getValue(root_value);
00074 if (total != 0.0) MetricValue.setAnnotationValue(m, myValue/total);
00075 }
00076
00077 }
00078 }
00079 }