ExclusiveCallingContextVisitor.java
Go to the documentation of this file.00001
00004 package edu.rice.cs.hpc.data.experiment.scope.visitors;
00005
00006 import edu.rice.cs.hpc.data.experiment.Experiment;
00007 import edu.rice.cs.hpc.data.experiment.scope.CallSiteScope;
00008 import edu.rice.cs.hpc.data.experiment.scope.FileScope;
00009 import edu.rice.cs.hpc.data.experiment.scope.GroupScope;
00010 import edu.rice.cs.hpc.data.experiment.scope.LineScope;
00011 import edu.rice.cs.hpc.data.experiment.scope.LoadModuleScope;
00012 import edu.rice.cs.hpc.data.experiment.scope.LoopScope;
00013 import edu.rice.cs.hpc.data.experiment.scope.ProcedureScope;
00014 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
00015 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00016 import edu.rice.cs.hpc.data.experiment.scope.ScopeVisitType;
00017 import edu.rice.cs.hpc.data.experiment.scope.StatementRangeScope;
00018 import edu.rice.cs.hpc.data.experiment.scope.filters.ExclusiveOnlyMetricPropagationFilter;
00019
00024 public class ExclusiveCallingContextVisitor implements IScopeVisitor {
00025
00026 private ExclusiveOnlyMetricPropagationFilter filterExclusive;
00027 private int numberOfPrimaryMetrics;
00028
00032 public ExclusiveCallingContextVisitor(Experiment experiment) {
00033 this.numberOfPrimaryMetrics = experiment.getMetricCount();
00034 this.filterExclusive = new ExclusiveOnlyMetricPropagationFilter(experiment);
00035 }
00036
00037
00038
00039
00040 public void visit(LoopScope scope, ScopeVisitType vt) {
00041 if (vt == ScopeVisitType.PostVisit) {
00042 Scope parent = scope.getParentScope();
00043 if(parent != null) {
00044 if ( (parent instanceof LoopScope) ) {
00045 this.accumulateAncestor(scope);
00046 } else {
00047
00048
00049
00050 parent.accumulateMetrics(scope, this.filterExclusive, this.numberOfPrimaryMetrics);
00051 }
00052 }
00053 }
00054 }
00055
00056
00057
00058
00059 public void visit(CallSiteScope scope, ScopeVisitType vt) {
00060 if (vt == ScopeVisitType.PostVisit) {
00061 Scope parent = scope.getParentScope();
00062 if(parent != null)
00063 parent.accumulateMetrics(scope.getLineScope(), this.filterExclusive, numberOfPrimaryMetrics);
00064 }
00065
00066 }
00067
00068
00069
00070
00071 public void visit(RootScope scope, ScopeVisitType vt) {
00072
00073 }
00077 public void visit(LineScope scope, ScopeVisitType vt) {add(scope, vt); }
00078 public void visit(StatementRangeScope scope, ScopeVisitType vt) { add(scope, vt); }
00079 public void visit(ProcedureScope scope, ScopeVisitType vt) { add(scope, vt); }
00080 public void visit(FileScope scope, ScopeVisitType vt) { add(scope, vt); }
00081 public void visit(GroupScope scope, ScopeVisitType vt) { add(scope, vt); }
00082 public void visit(LoadModuleScope scope, ScopeVisitType vt) { add(scope, vt); }
00083 public void visit(Scope scope, ScopeVisitType vt) { add(scope, vt); }
00084
00085
00086
00087 private void add(Scope scope, ScopeVisitType vt) {
00088 if (vt == ScopeVisitType.PostVisit) {
00089 Scope parent = scope.getParentScope();
00090 if (parent == null)
00091 return;
00092
00093 parent.accumulateMetrics(scope, this.filterExclusive, this.numberOfPrimaryMetrics);
00094 }
00095 }
00096
00097 private void accumulateAncestor(Scope scope) {
00098 Scope parent = scope.getParentScope();
00099 if(parent != null) {
00100 if(parent instanceof RootScope)
00101 return;
00102 while ( (parent != null) && !(parent instanceof CallSiteScope) &&
00103 !(parent instanceof RootScope) && !(parent instanceof ProcedureScope) ) {
00104 parent = parent.getParentScope();
00105 }
00106 if (parent != null) {
00107 if ( (parent instanceof CallSiteScope) || (parent instanceof ProcedureScope) ) {
00108 parent.accumulateMetrics(scope, this.filterExclusive, this.numberOfPrimaryMetrics);
00109 }
00110 }
00111 }
00112 }
00113 }