00001 package edu.rice.cs.hpc.viewer.scope.bottomup; 00002 00003 import edu.rice.cs.hpc.data.experiment.Experiment; 00004 import edu.rice.cs.hpc.data.experiment.scope.CallSiteScopeCallerView; 00005 import edu.rice.cs.hpc.data.experiment.scope.IMergedScope; 00006 import edu.rice.cs.hpc.data.experiment.scope.ProcedureScope; 00007 import edu.rice.cs.hpc.data.experiment.scope.RootScope; 00008 import edu.rice.cs.hpc.data.experiment.scope.Scope; 00009 import edu.rice.cs.hpc.data.experiment.scope.filters.ExclusiveOnlyMetricPropagationFilter; 00010 import edu.rice.cs.hpc.data.experiment.scope.filters.InclusiveOnlyMetricPropagationFilter; 00011 import edu.rice.cs.hpc.data.experiment.scope.visitors.FinalizeMetricVisitorWithBackup; 00012 import edu.rice.cs.hpc.data.experiment.scope.visitors.PercentScopeVisitor; 00013 import edu.rice.cs.hpc.viewer.scope.AbstractContentProvider; 00014 00015 /************************************************************************ 00016 * 00017 * Content provider class specifically for caller view 00018 * This class will update the children of a scope dynamically, unlike 00019 * other views 00020 * 00021 ************************************************************************/ 00022 public class CallerViewContentProvider extends AbstractContentProvider 00023 { 00024 private ExclusiveOnlyMetricPropagationFilter exclusiveOnly; 00025 private InclusiveOnlyMetricPropagationFilter inclusiveOnly; 00026 private PercentScopeVisitor percentVisitor; 00027 private FinalizeMetricVisitorWithBackup finalizeVisitor; 00028 00029 public CallerViewContentProvider() 00030 { 00031 } 00032 00036 @Override 00037 public Object[] getElements(Object inputElement) { 00038 return getChildren(inputElement); 00039 } 00040 00044 public Object[] getChildren(Object parentElement) { 00045 Object []results = null; 00046 00047 if(parentElement instanceof IMergedScope) { 00048 // normal mode 00049 IMergedScope parent = ((IMergedScope) parentElement); 00050 results = parent.getAllChildren(finalizeVisitor, percentVisitor, inclusiveOnly, exclusiveOnly); 00051 00052 } else if (parentElement instanceof Scope) { 00053 Scope scope = (Scope) parentElement; 00054 results = scope.getChildren(); 00055 } 00056 return results; 00057 } 00058 00059 /* 00060 * (non-Javadoc) 00061 * @see org.eclipse.jface.viewers.ITreeContentProvider#hasChildren(java.lang.Object) 00062 */ 00063 public boolean hasChildren(Object element) { 00064 if(element instanceof Scope) { 00065 Scope node = (Scope) element; 00066 boolean has_children = node.hasChildren(); 00067 if (!has_children) { 00068 if (node instanceof CallSiteScopeCallerView) { 00069 CallSiteScopeCallerView cc = (CallSiteScopeCallerView) node; 00070 has_children = cc.hasScopeChildren(); //cc.numChildren>0; 00071 } else if ( !(node instanceof ProcedureScope)){ 00072 throw new RuntimeException("Unexpected scope node: " + node); 00073 } 00074 } 00075 return has_children; // !((Scope.Node) element).isLeaf(); 00076 } 00077 else 00078 return false; 00079 } 00080 00081 00082 /*** 00083 * Update the database 00084 * @param experiment 00085 */ 00086 public void setDatabase(Experiment experiment) { 00087 exclusiveOnly = new ExclusiveOnlyMetricPropagationFilter(experiment); 00088 inclusiveOnly = new InclusiveOnlyMetricPropagationFilter(experiment); 00089 00090 RootScope root = experiment.getCallerTreeRoot(); 00091 percentVisitor = new PercentScopeVisitor(experiment.getMetricCount(), root); 00092 finalizeVisitor = new FinalizeMetricVisitorWithBackup(experiment.getMetrics()); 00093 } 00094 }