SpaceTimeDataController.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.spaceTimeData;
00002 
00003 import java.io.File;
00004 import java.io.IOException;
00005 import java.io.InputStream;
00006 import java.util.HashMap;
00007 import java.util.concurrent.atomic.AtomicInteger;
00008 
00009 import org.eclipse.ui.IWorkbenchWindow;
00010 import org.eclipse.ui.services.ISourceProviderService;
00011 
00012 import edu.rice.cs.hpc.common.util.ProcedureAliasMap;
00013 import edu.rice.cs.hpc.data.experiment.ExperimentWithoutMetrics;
00014 import edu.rice.cs.hpc.data.experiment.InvalExperimentException;
00015 import edu.rice.cs.hpc.data.experiment.extdata.IBaseData;
00016 import edu.rice.cs.hpc.data.experiment.extdata.IFilteredData;
00017 import edu.rice.cs.hpc.data.experiment.extdata.TraceAttribute;
00018 import edu.rice.cs.hpc.traceviewer.painter.ImageTraceAttributes;
00019 import edu.rice.cs.hpc.traceviewer.services.ProcessTimelineService;
00020 
00021 import edu.rice.cs.hpc.traceviewer.data.graph.ColorTable;
00022 import edu.rice.cs.hpc.traceviewer.data.graph.CallPath;
00023 import edu.rice.cs.hpc.traceviewer.data.timeline.ProcessTimeline;
00024 
00025 
00026 /*******************************************************************************************
00027  * 
00028  * Class to store global information concerning the database and the trace.
00029  * The class is designed to work for both local and remote database. Any references have to 
00030  *  be addressed to the methods of this class instead of the derived class to enable
00031  *  transparency.
00032  * 
00033  * @author Original authors: Sinchan Banarjee, Michael France, Reed Lundrum and Philip Taffet
00034  * 
00035  * Modification:
00036  * - 2013 Philip: refactoring into three classes : abstract (this class), local and remote
00037  * - 2014.2.1 Laksono: refactoring to make it as simple as possible and avoid code redundancy
00038  *
00039  *******************************************************************************************/
00040 public abstract class SpaceTimeDataController 
00041 {
00042     protected ImageTraceAttributes attributes;
00047     protected long maxEndTime, minBegTime;
00048 
00049 
00050     protected ProcessTimelineService ptlService;
00051 
00052     
00054     private HashMap<Integer, CallPath> scopeMap;
00055     
00056     // We probably want to get away from this. The for code that needs it should be
00057     // in one of the threads. It's here so that both local and remote can use
00058     // the same thread class yet get their information differently.
00059     protected AtomicInteger lineNum;
00060     AtomicInteger depthLineNum;
00061         
00063     protected int maxDepth;
00064     
00065     protected ColorTable colorTable;
00066     private boolean enableMidpoint;
00067     
00068     protected IBaseData dataTrace = null;
00069     final protected ExperimentWithoutMetrics exp;
00070     
00071     // nathan's data index variable
00072     // TODO: we need to remove this and delegate to the inherited class instead !
00073     private int currentDataIdx;
00074 
00075     /***
00076      * Constructor to create a data based on File. This constructor is more suitable
00077      * for local database
00078      * 
00079      * @param _window : SWT window
00080      * @param expFile : experiment file (XML format)
00081      */
00082     public SpaceTimeDataController(IWorkbenchWindow _window, File expFile) 
00083             throws InvalExperimentException, Exception 
00084     {           
00085         exp = new ExperimentWithoutMetrics();
00086         exp.open(expFile, new ProcedureAliasMap());
00087         
00088         init(_window);
00089     }
00090     
00091     /*****
00092      * Constructor to create a data based on input stream, which is convenient for remote database
00093      * 
00094      * @param _window : SWT window
00095      * @param expStream : input stream
00096      * @param Name : the name of the file on the remote server
00097      * @throws InvalExperimentException 
00098      *****/
00099     public SpaceTimeDataController(IWorkbenchWindow _window, InputStream expStream, String Name) 
00100             throws InvalExperimentException, Exception 
00101     {   
00102         exp = new ExperimentWithoutMetrics();
00103 
00104         // Without metrics, so param 3 is false
00105         exp.open(expStream, new ProcedureAliasMap(), Name);
00106         
00107         init(_window);
00108     }
00109 
00110     public void setDataIndex(int dataIndex) 
00111     {
00112         currentDataIdx = dataIndex;
00113     }
00114     
00115     
00116     public int getDataIndex()
00117     {
00118         return currentDataIdx;
00119     }
00120     
00121     /******
00122      * Initialize the object
00123      * 
00124      * @param _window
00125      * @throws Exception 
00126      ******/
00127     private void init(IWorkbenchWindow _window) 
00128             throws InvalExperimentException 
00129     {   
00130         // tree traversal to get the list of cpid, procedures and max depth
00131         TraceDataVisitor visitor = new TraceDataVisitor();
00132         exp.getRootScope().dfsVisitScopeTree(visitor);
00133 
00134         maxDepth   = visitor.getMaxDepth();
00135         scopeMap   = visitor.getMap();
00136         colorTable = (ColorTable) visitor.getProcedureTable();
00137         
00138         // initialize colors
00139         colorTable.setColorTable();
00140         
00141         // attributes initialization
00142         attributes   = new ImageTraceAttributes();
00143         lineNum      = new AtomicInteger(0);
00144         depthLineNum = new AtomicInteger(0);
00145 
00146         ISourceProviderService sourceProviderService = (ISourceProviderService) _window.getService(ISourceProviderService.class);
00147         ptlService = (ProcessTimelineService) sourceProviderService.getSourceProvider(ProcessTimelineService.PROCESS_TIMELINE_PROVIDER); 
00148 
00149         TraceAttribute trAttribute = exp.getTraceAttribute();
00150         
00151         if (trAttribute == null) {
00152             throw new InvalExperimentException("Database does not contain traces: " + exp.getDefaultDirectory());
00153         }
00154         minBegTime = trAttribute.dbTimeMin;
00155         maxEndTime = trAttribute.dbTimeMax;
00156     }
00157 
00158     public int getMaxDepth() 
00159     {
00160         return maxDepth;
00161     }
00162     
00163     
00164     private int getCurrentlySelectedProcess()
00165     {
00166         return attributes.getPosition().process;
00167     }
00168     
00176     public int computeScaledProcess() {
00177         int numTracesShown = Math.min(attributes.getProcessInterval(), attributes.numPixelsV);
00178         int selectedProc = getCurrentlySelectedProcess();
00179         
00180         double scaledDTProcess = (((double) numTracesShown -1 )
00181                     / ((double) attributes.getProcessInterval() - 1) * 
00182                     (selectedProc - attributes.getProcessBegin()));
00183         return (int)scaledDTProcess;
00184     }
00185 
00186 
00187 
00188     public ProcessTimeline getDepthTrace() {
00189         int scaledDTProcess = computeScaledProcess();
00190         return  ptlService.getProcessTimeline(scaledDTProcess);
00191     }
00192     
00193     /***********************************************************************
00194      * Gets the next available trace to be filled/painted from the DepthTimeView
00195      * 
00196      * @return The next trace.
00197      **********************************************************************/
00198     public synchronized ProcessTimeline getNextDepthTrace() {
00199         
00200         ProcessTimeline depthTrace = getDepthTrace();
00201         if (depthTrace == null)
00202             return null;
00203         
00204         int currentDepthLineNum = depthLineNum.getAndIncrement();
00205         if (currentDepthLineNum < Math.min(attributes.numPixelsDepthV, maxDepth)) {
00206             
00207             // I can't get the data from the ProcessTimeline directly, so create
00208             // a ProcessTimeline with data=null and then copy the actual data to
00209             // it.
00210             ProcessTimeline toDonate = new ProcessTimeline(currentDepthLineNum,
00211                     scopeMap, dataTrace, getCurrentlySelectedProcess(), attributes.numPixelsH,
00212                     attributes.getTimeInterval(), minBegTime
00213                             + attributes.getTimeBegin());
00214 
00215             toDonate.copyDataFrom(depthTrace);
00216 
00217             return toDonate;
00218         } else
00219             return null;
00220     }
00221     
00222     public IBaseData getBaseData(){
00223         return dataTrace;
00224     }
00225 
00226     /******************************************************************************
00227      * Returns number of processes (ProcessTimelines) held in this
00228      * SpaceTimeData.
00229      ******************************************************************************/
00230     public int getTotalTraceCount() {
00231         return dataTrace.getNumberOfRanks();
00232     }
00233     
00234     protected HashMap<Integer, CallPath> getScopeMap() {
00235         return scopeMap;
00236     }
00237 
00238     /******************************************************************************
00239      * getter/setter trace attributes
00240      * @return
00241      ******************************************************************************/
00242     
00243     public int getPixelHorizontal() {
00244         return attributes.numPixelsH;
00245     }
00246     
00247     
00248     public void setTraceAttributes(ImageTraceAttributes attributes) {
00249         this.attributes = attributes;
00250     }
00251 
00252     public ImageTraceAttributes getAttributes() {
00253         return attributes;
00254     }
00255 
00256     /*************************************************************************
00257      * Returns width of the spaceTimeData: The width (the last time in the
00258      * ProcessTimeline) of the longest ProcessTimeline.
00259      ************************************************************************/
00260     public long getTimeWidth() {
00261         return maxEndTime - minBegTime;
00262     }
00263 
00264     public long getMaxEndTime() {
00265         return maxEndTime;
00266     }
00267 
00268     public long getMinBegTime() {
00269         return minBegTime;
00270     }
00271 
00272     public ColorTable getColorTable() {
00273         return colorTable;
00274     }
00275 
00276     public void dispose() {
00277         colorTable.dispose();
00278     }
00279 
00280     public void setEnableMidpoint(boolean enable) {
00281         this.enableMidpoint = enable;
00282     }
00283 
00284     public boolean isEnableMidpoint() {
00285         return enableMidpoint;
00286     }
00287 
00288     public void resetCounters() {
00289         lineNum.set(0);
00290         depthLineNum.set(0);
00291     }
00292     
00293     public int getNumberOfLines() {
00294         return lineNum.get();
00295     }
00296     
00297     public int getNumberOfDepthLines() {
00298         return depthLineNum.get();
00299     }
00300     
00301     //see the note where this is called in FilterRanks
00302     public IFilteredData getFilteredBaseData() {
00303         if (dataTrace instanceof IFilteredData)
00304             return (IFilteredData) dataTrace;
00305         return null;
00306     }
00311     public void setBaseData(IFilteredData filteredBaseData) {
00312         dataTrace = filteredBaseData;
00313 
00314         int endProcess = attributes.getProcessEnd();
00315         int begProcess = attributes.getProcessBegin();
00316         
00317         //Snap it back into the acceptable limits.
00318         if (endProcess > dataTrace.getNumberOfRanks())
00319             endProcess  = dataTrace.getNumberOfRanks();
00320         
00321         if (begProcess >= endProcess)
00322             begProcess = 0;
00323         
00324         attributes.setProcess(begProcess, endProcess);
00325     }
00326 
00328     // Abstract methods
00330     
00331     /*************************************************************************
00332      * Retrieve the name of the database. The name can be either the path of
00333      * the directory, or the name of the profiled application, or both.
00334      * <p>
00335      * Ideally the name should be unique to distinguish with other databases. 
00336      * 
00337      * @return String: the name of the database
00338      *************************************************************************/
00339     abstract public String getName() ;
00340 
00341     public abstract ProcessTimeline getNextTrace(boolean changedBounds);
00342 
00343     public abstract void closeDB();
00344 
00345     public abstract IFilteredData createFilteredBaseData();
00346 
00347     public abstract void fillTracesWithData(boolean changedBounds, int numThreadsToLaunch)
00348             throws IOException;
00349 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1