BaseExperiment.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.data.experiment;
00002 
00003 import java.io.File;
00004 import java.io.InputStream;
00005 
00006 import edu.rice.cs.hpc.data.experiment.extdata.TraceAttribute;
00007 import edu.rice.cs.hpc.data.experiment.scope.RootScope;
00008 import edu.rice.cs.hpc.data.experiment.scope.RootScopeType;
00009 import edu.rice.cs.hpc.data.experiment.scope.Scope;
00010 import edu.rice.cs.hpc.data.experiment.scope.visitors.DisposeResourcesVisitor;
00011 import edu.rice.cs.hpc.data.experiment.scope.visitors.FilterScopeVisitor;
00012 import edu.rice.cs.hpc.data.filter.IFilterData;
00013 import edu.rice.cs.hpc.data.util.IUserData;
00014 
00015 
00016 /***
00017  * Base abstract experiment that handle only call path.
00018  * 
00019  * No metric is associated in this experiment
00020  *
00021  */
00022 public abstract class BaseExperiment implements IExperiment 
00023 {
00025     protected ExperimentConfiguration configuration;
00026 
00027     protected RootScope rootScope;
00028     
00030     protected String version;
00031 
00032     private TraceAttribute attribute;
00033 
00034     protected IDatabaseRepresentation databaseRepresentation;
00035     
00036     /***
00037      * the root scope of the experiment
00038      * 
00039      * @param the root scope
00040      */
00041     public void setRootScope(Scope rootScope) {
00042         this.rootScope = (RootScope) rootScope;
00043     }
00044 
00045     
00046     /***
00047      * retrieve the root scope.
00048      * 
00049      * @return the root scope
00050      */
00051     public Scope getRootScope() {
00052         return rootScope;
00053     }
00054 
00055     
00056     /****
00057      * retrieve the root scope of caller tree (bottom-up view)
00058      * 
00059      * @return root scope
00060      */
00061     public RootScope getCallerTreeRoot() {
00062         RootScope root = (RootScope) getRootScope();
00063         if (root.getSubscopeCount()==3) {
00064             
00065             Scope scope = root.getSubscope(1);
00066             if (scope instanceof RootScope)
00067                 return (RootScope) scope;
00068             
00069         }
00070         return null;
00071     }
00072 
00073     
00074 
00075     public Object[] getRootScopeChildren() {
00076         RootScope root = (RootScope) getRootScope();
00077 
00078         if (root != null)
00079             return root.getChildren();
00080         else
00081             return null;
00082     }
00083     
00084     
00085     /****
00086      * open a local database
00087      * 
00088      * @param fileExperiment : file of the experiment xml
00089      * @param userData : map of user preferences
00090      * @param need_metric : whether we need to assign metrics or not
00091      * @throws Exception
00092      */
00093     public void open(File fileExperiment, IUserData<String, String> userData, boolean need_metric)
00094             throws  Exception
00095     {
00096         databaseRepresentation = new LocalDatabaseRepresentation(fileExperiment, this, userData, need_metric);
00097         databaseRepresentation.open();
00098         open_finalize();
00099     }
00100     
00101     
00102     /******
00103      * This method is used for opening XML from a remote machine
00104      *  
00105      * @param expStream : remote input stream
00106      * @param userData : customized user data
00107      * @param name : the remote directory
00108      * @throws Exception 
00109      *****/
00110     public void open(InputStream expStream, IUserData<String, String> userData,
00111         String name) throws Exception {
00112         databaseRepresentation = new RemoteDatabaseRepresentation(this, expStream, userData, name);
00113         databaseRepresentation.open();
00114         open_finalize();
00115     }
00116 
00117     /******
00118      * Reopening and reread the database and refresh the tree.<br/>
00119      * If the database has not been opened, it throws an exception.
00120      * @throws Exception
00121      */
00122     public void reopen() throws Exception
00123     {
00124         if (databaseRepresentation != null)
00125         {
00126             databaseRepresentation.open();
00127             open_finalize();
00128         } else {
00129             throw new Exception("Database has not been opened.");
00130         }
00131     }
00132 
00133     public void setVersion (String v) 
00134     {
00135         this.version = v;
00136     }
00137 
00138     public void setTraceAttribute(TraceAttribute _attribute) {
00139         this.attribute = _attribute;
00140     }
00141 
00142 
00143     public TraceAttribute getTraceAttribute() {
00144         return this.attribute;
00145     }
00146 
00147 
00148 
00149     /*************************************************************************
00150      *  Returns the name of the experiment.
00151      ************************************************************************/  
00152     public String getName()
00153     {
00154         return configuration.getName(ExperimentConfiguration.NAME_EXPERIMENT);
00155     }
00156 
00157 
00158     /*************************************************************************
00159      *  Sets the experiment's configuration.
00160      *
00161      *  This method is to be called only once, during <code>Experiment.open</code>.
00162      *
00163      ************************************************************************/
00164     public void setConfiguration(ExperimentConfiguration configuration)
00165     {
00166         this.configuration = configuration;
00167     }
00168 
00169     public ExperimentConfiguration getConfiguration()
00170     {
00171         return this.configuration;
00172     }
00173 
00174 
00175     /*************************************************************************
00176      *  Returns the default directory from which to resolve relative paths.
00177      ************************************************************************/
00178 
00179     public File getDefaultDirectory()
00180     {
00181         return getXMLExperimentFile().getParentFile();
00182     }
00183 
00184     public File getXMLExperimentFile() {
00185         return databaseRepresentation.getXMLFile().getFile();
00186     }
00187 
00188 
00189     /*****
00190      * disposing the experiment resources.
00191      */
00192     public void dispose()
00193     {
00194         DisposeResourcesVisitor visitor = new DisposeResourcesVisitor();
00195         rootScope.dfsVisitScopeTree(visitor);
00196         this.rootScope = null;
00197     }
00198 
00199 
00200     /*************************************************************************
00201      * Filter the cct 
00202      * <p>caller needs to call postprocess to ensure the callers tree and flat
00203      * tree are alsi filtered </p>
00204      * @param filter
00205      *************************************************************************/
00206     public void filter(IFilterData filter)
00207     {
00208         // TODO :  we assume the first child is the CCT
00209         final RootScope rootCCT = (RootScope) rootScope.getChildAt(0);
00210 
00211         // duplicate and filter the cct
00212         FilterScopeVisitor visitor = new FilterScopeVisitor(rootCCT, filter);
00213         rootCCT.dfsVisitFilterScopeTree(visitor);
00214 
00215         if (rootCCT.getType() == RootScopeType.CallingContextTree) {
00216             filter_finalize(rootCCT, filter);
00217         }
00218     }
00219 
00220     /************************************************************************
00221      * In case the experiment has a CCT, continue to create callers tree and
00222      * flat tree for the finalization.
00223      * 
00224      * @param rootCCT
00225      * @param filter
00226      ************************************************************************/
00227     abstract protected void filter_finalize(RootScope rootMain, IFilterData filter);
00228 
00229     abstract protected void open_finalize();
00230 
00231 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1