CallSiteScopeCallerView.java
Go to the documentation of this file.00001 package edu.rice.cs.hpc.data.experiment.scope;
00002
00003 import java.util.ArrayList;
00004 import java.util.Iterator;
00005 import java.util.LinkedList;
00006
00007 import edu.rice.cs.hpc.data.experiment.metric.AbstractCombineMetric;
00008 import edu.rice.cs.hpc.data.experiment.scope.filters.MetricValuePropagationFilter;
00009 import edu.rice.cs.hpc.data.experiment.scope.visitors.AbstractFinalizeMetricVisitor;
00010 import edu.rice.cs.hpc.data.experiment.scope.visitors.CallersViewScopeVisitor;
00011 import edu.rice.cs.hpc.data.experiment.scope.visitors.PercentScopeVisitor;
00012
00013
00014
00015
00016
00017
00018
00019
00020 public class CallSiteScopeCallerView extends CallSiteScope implements IMergedScope {
00021
00022 private boolean flag_scope_has_child;
00023
00024 private Scope scopeCCT;
00025 private Scope scopeCost;
00026
00027 private ArrayList<CallSiteScopeCallerView> listOfmerged;
00028
00029 static final private IncrementalCombineMetricUsingCopy combine_with_dupl = new IncrementalCombineMetricUsingCopy();
00030 static final private CombineMetricUsingCopyNoCondition combine_without_cond = new CombineMetricUsingCopyNoCondition();
00031
00040 public CallSiteScopeCallerView(LineScope scope, ProcedureScope scope2,
00041 CallSiteScopeType csst, int id, Scope cct, Scope s_cost) {
00042 super(scope, scope2, csst, id, cct.getFlatIndex());
00043
00044 this.scopeCCT = cct;
00045 this.scopeCost = s_cost;
00046 this.flag_scope_has_child = false;
00047 }
00048
00049
00050
00051
00052
00053 public Scope getScopeCCT() {
00054 return this.scopeCCT;
00055 }
00056
00057
00058
00059
00060
00061
00062
00063 public void merge(IMergedScope.MergingStatus status, CallSiteScopeCallerView scope, int counter_to_assign) {
00064 if (listOfmerged == null)
00065 listOfmerged = new ArrayList<CallSiteScopeCallerView>();
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 switch (status) {
00077 case INIT:
00078 scope.setCounter(this.getCounter());
00079 break;
00080
00081 case INCREMENTAL:
00082 scope.setCounter(counter_to_assign);
00083 break;
00084 }
00085
00086
00087 listOfmerged.add(scope);
00088 }
00089
00090
00091
00092
00093
00094
00095 public void markScopeHasChildren() {
00096 this.flag_scope_has_child = true;
00097 }
00098
00099
00100
00101
00102
00103 public boolean hasScopeChildren() {
00104 return this.flag_scope_has_child;
00105 }
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115 public Object[] getAllChildren(AbstractFinalizeMetricVisitor finalizeVisitor, PercentScopeVisitor percentVisitor,
00116 MetricValuePropagationFilter inclusiveOnly,
00117 MetricValuePropagationFilter exclusiveOnly ) {
00118
00119 boolean percent_need_recompute = false;
00120 Object children[] = this.getChildren();
00121
00122 if (children != null && children.length>0) {
00123
00124
00125
00126
00127 return this.getChildren();
00128
00129 } else {
00130
00131
00132
00133
00134
00135 LinkedList<CallSiteScopeCallerView> listOfChain = CallerScopeBuilder.createCallChain
00136 (this.scopeCCT, scopeCost, combine_without_cond, inclusiveOnly, exclusiveOnly);
00137
00138 if (!listOfChain.isEmpty())
00139 {
00140 CallSiteScopeCallerView first = listOfChain.removeFirst();
00141 CallersViewScopeVisitor.addNewPathIntoTree(this, first, listOfChain);
00142 percent_need_recompute = true;
00143 }
00144 }
00145
00146
00147
00148
00149
00150 if (this.listOfmerged != null) {
00151 for(Iterator<CallSiteScopeCallerView> iter = this.listOfmerged.iterator(); iter.hasNext(); ) {
00152
00153 CallSiteScopeCallerView scope = iter.next();
00154
00155 try {
00156 Scope scope_cct = scope.scopeCCT;
00157
00158
00159
00160
00161 LinkedList<CallSiteScopeCallerView> listOfChain = CallersViewScopeVisitor.createCallChain
00162 (scope_cct, scope, combine_without_cond, inclusiveOnly, exclusiveOnly);
00163
00164
00165
00166
00167
00168
00169 int counter_to_assign = scope.getCounter() - 1;
00170 if (counter_to_assign<0)
00171 counter_to_assign = 0;
00172
00173
00174
00175
00176 CallersViewScopeVisitor.mergeCallerPath(IMergedScope.MergingStatus.INCREMENTAL, counter_to_assign,
00177 this, listOfChain, combine_with_dupl, inclusiveOnly, exclusiveOnly);
00178
00179 percent_need_recompute = true;
00180
00181 } catch (java.lang.ClassCastException e) {
00182
00183
00184
00185
00186
00187
00188 System.err.println("Warning: dynamically merging procedure scope: " + scope.scopeCCT +
00189 " ["+scope.scopeCCT.flat_node_index+"]");
00190 }
00191
00192
00193 }
00194 }
00195
00196
00197
00198
00199 children = getChildren();
00200 if (percent_need_recompute && children != null) {
00201
00202 for(Object child: children) {
00203 if (child instanceof CallSiteScopeCallerView) {
00204 CallSiteScopeCallerView csChild = (CallSiteScopeCallerView) child;
00205
00206 csChild.dfsVisitScopeTree(finalizeVisitor);
00207 csChild.dfsVisitScopeTree(percentVisitor);
00208 }
00209 }
00210 }
00211
00212 return this.getChildren();
00213 }
00214
00215
00216
00217
00218
00219 public Object[] getMergedScopes() {
00220 if (this.listOfmerged != null)
00221 return this.listOfmerged.toArray();
00222 else
00223 return null;
00224 }
00225
00226
00227 public Scope getScopeCost() {
00228 return scopeCost;
00229 }
00230
00236 static private Scope getScopeOfCombineMetrics(Scope source) {
00237 Scope copy = source.duplicate();
00238 copy.setMetricValues( source.getCombinedValues() );
00239 return copy;
00240 }
00241
00242
00243
00244
00245
00246
00247
00248 static private class IncrementalCombineMetricUsingCopy extends AbstractCombineMetric {
00249
00250
00251
00252
00253
00254 public void combine(Scope target, Scope source,
00255 MetricValuePropagationFilter inclusiveOnly,
00256 MetricValuePropagationFilter exclusiveOnly) {
00257
00258
00259 if (target instanceof CallSiteScopeCallerView) {
00260
00261 Scope copy = getScopeOfCombineMetrics(source);
00262
00263
00264
00265
00266 if (inclusiveOnly != null && source.isCounterZero()) {
00267 target.safeCombine(copy, inclusiveOnly);
00268 }
00269
00270 if (exclusiveOnly != null)
00271 target.combine(copy, exclusiveOnly);
00272
00273 } else {
00274 System.err.println("ERROR-ICMUC: the target combine is incorrect: " + target + " -> " + target.getClass() );
00275 }
00276
00277 }
00278 }
00279
00280
00281
00282
00283
00284
00285
00286
00287 static private class CombineMetricUsingCopyNoCondition extends AbstractCombineMetric {
00288
00289
00290
00291
00292
00293
00294
00295 public void combine(Scope target, Scope source,
00296 MetricValuePropagationFilter inclusiveOnly,
00297 MetricValuePropagationFilter exclusiveOnly) {
00298
00299 if (target instanceof CallSiteScopeCallerView) {
00300 Scope copy = getScopeOfCombineMetrics(source);
00301
00302 if (inclusiveOnly != null) {
00303 target.safeCombine(copy, inclusiveOnly);
00304 }
00305 if (exclusiveOnly != null)
00306 target.combine(copy, exclusiveOnly);
00307
00308 target.setCounter(source.getCounter());
00309
00310 } else {
00311 System.err.println("ERROR-CMUCNC: the target combine is incorrect: " + target + " -> " + target.getClass() );
00312 }
00313
00314 }
00315 }
00316
00317 }