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  * special class for caller view's call site scope
00016  * 
00017  * @author laksonoadhianto
00018  *
00019  */
00020 public class CallSiteScopeCallerView extends CallSiteScope implements IMergedScope {
00021 
00022     private boolean flag_scope_has_child;
00023 
00024     private Scope scopeCCT; // store the orignal CCT scope
00025     private Scope scopeCost; // the original CCT cost scope. In caller view, a caller scope needs 2 pointers: the cct and the scope
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      * retrieve the CCT scope of this scope
00051      * @return
00052      */
00053     public Scope getScopeCCT() {
00054         return this.scopeCCT;
00055     }
00056     
00057     
00058     /***
00059      * add merged scope into the list
00060      * @param status
00061      * @param scope
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         // During the initialization phase (the first time a caller tree is created,
00069         //  the counter of the merged scope is equivalent to the counter of the existing scope.
00070         //  This counter would be then used in the future (in the second phase)
00071         //
00072         // In the second phase (incremental), the counter of the child of the merged scope is given from 
00073         //  the counter of the parent of this child. Since here we don't know who is the "real" parent,
00074         //  we need to pass it from the parameter
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 //      System.out.println("CSSCV merge this: " + this.getShortName() + " [" + this.scopeCCT.getCCTIndex()+"] " + this.iCounter +
00086 //          " --> ["+ scope.scopeCCT.getCCTIndex() +    "] " + scope.iCounter);
00087         listOfmerged.add(scope);    // include the new scope to merge
00088     }
00089     
00090 
00091     /*****
00092      * Mark that this scope has a child. The number of children is still unknown though
00093      *  and has to computed dynamically
00094      */
00095     public void markScopeHasChildren() {
00096         this.flag_scope_has_child = true;
00097     }
00098     
00099     /***
00100      * check if the scope has a child or not
00101      * @return
00102      */
00103     public boolean hasScopeChildren() {
00104         return this.flag_scope_has_child;
00105     }
00106 
00107     /*****************
00108      * retrieve the child scopes of this node. 
00109      * If a node has merged siblings, then we need to reconstruct the children of the merged scopes
00110      * @param finalizeVisitor: visitor traversal for finalization phase
00111      * @param percentVisitor: visitor traversal to compute the percentage
00112      * @param inclusiveOnly: filter for inclusive metrics
00113      * @param exclusiveOnly: filter for exclusive metrics 
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             // this scope has already computed children, we do nothing, just return them
00126             //-------------------------------------------------------------------------
00127             return this.getChildren();
00128             
00129         } else {
00130             
00131             //-------------------------------------------------------------------------
00132             // construct my own child
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         // get the list of children from the merged siblings
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                     // construct the child of this merged scope
00160                     //-------------------------------------------------------------------------
00161                     LinkedList<CallSiteScopeCallerView> listOfChain = CallersViewScopeVisitor.createCallChain
00162                         (scope_cct, scope, combine_without_cond, inclusiveOnly, exclusiveOnly);
00163                     
00164                     //-------------------------------------------------------------------------
00165                     // For recursive function where the counter is more than 1, the counter to 
00166                     //  assign to the child scope is the counter of the scope minus 1
00167                     // For normal function it has to be zero
00168                     //-------------------------------------------------------------------------
00169                     int counter_to_assign = scope.getCounter() - 1;
00170                     if (counter_to_assign<0)
00171                         counter_to_assign = 0;
00172                     
00173                     //-------------------------------------------------------------------------
00174                     // merge (if possible) the path of this new created merged scope
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                     // theoretically it is impossible to merge two main procedures 
00185                     // however thanks to "partial call path", the CCT can have two main procedures !
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         // set the percent
00198         //-------------------------------------------------------------------------
00199         children = getChildren();
00200         if (percent_need_recompute && children != null) {
00201             // there were some reconstruction of children. Let's finalize the metrics, and recompute the percent
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      * retrieve the list of merged scopes
00217      * @return
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      * combination class to combine two metrics
00244      * This class is specifically designed for combining merged nodes in incremental caller view
00245      * @author laksonoadhianto
00246      *
00247      *************************/
00248     static private class IncrementalCombineMetricUsingCopy extends AbstractCombineMetric {
00249 
00250         /*
00251          * (non-Javadoc)
00252          * @see edu.rice.cs.hpc.data.experiment.metric.AbstractCombineMetric#combine(edu.rice.cs.hpc.data.experiment.scope.Scope, edu.rice.cs.hpc.data.experiment.scope.Scope, edu.rice.cs.hpc.data.experiment.scope.filters.MetricValuePropagationFilter, edu.rice.cs.hpc.data.experiment.scope.filters.MetricValuePropagationFilter)
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                 // only combine the outermost "node" of incremental callsite
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      * combination class specific for the creation of incremental call site
00283      * in this phase, we need to store the information of counter from the source
00284      * @author laksonoadhianto
00285      *
00286      ************************/
00287     static private class CombineMetricUsingCopyNoCondition extends AbstractCombineMetric {
00288 
00289         /*
00290          * (non-Javadoc)
00291          * @see edu.rice.cs.hpc.data.experiment.metric.AbstractCombineMetric#combine(edu.rice.cs.hpc.data.experiment.scope.Scope, 
00292          * edu.rice.cs.hpc.data.experiment.scope.Scope, edu.rice.cs.hpc.data.experiment.scope.filters.MetricValuePropagationFilter, 
00293          * edu.rice.cs.hpc.data.experiment.scope.filters.MetricValuePropagationFilter)
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 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1