SpaceTimeDataControllerLocal.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.db.local;
00002 
00003 import java.io.File;
00004 import java.io.IOException;
00005 
00006 import org.eclipse.jface.action.IStatusLineManager;
00007 import org.eclipse.jface.dialogs.MessageDialog;
00008 import org.eclipse.ui.IWorkbenchWindow;
00009 
00010 import edu.rice.cs.hpc.data.experiment.InvalExperimentException;
00011 import edu.rice.cs.hpc.data.experiment.extdata.BaseData;
00012 import edu.rice.cs.hpc.data.experiment.extdata.FilteredBaseData;
00013 import edu.rice.cs.hpc.data.experiment.extdata.IBaseData;
00014 import edu.rice.cs.hpc.data.experiment.extdata.IFilteredData;
00015 import edu.rice.cs.hpc.data.experiment.extdata.TraceAttribute;
00016 import edu.rice.cs.hpc.data.util.MergeDataFiles;
00017 
00018 import edu.rice.cs.hpc.traceviewer.data.db.TraceDataByRank;
00019 import edu.rice.cs.hpc.traceviewer.data.timeline.ProcessTimeline;
00020 import edu.rice.cs.hpc.traceviewer.spaceTimeData.SpaceTimeDataController;
00021 import edu.rice.cs.hpc.traceviewer.util.TraceProgressReport;
00022 
00029 public class SpaceTimeDataControllerLocal extends SpaceTimeDataController 
00030 {   
00031     protected final static int MIN_TRACE_SIZE = TraceDataByRank.HeaderSzMin + TraceDataByRank.RecordSzMin * 2;
00032     private String traceFilePath;
00033 
00034     public SpaceTimeDataControllerLocal(IWorkbenchWindow _window, String databaseDirectory) 
00035             throws InvalExperimentException, Exception 
00036     {
00037         super(_window, new File(databaseDirectory));
00038     }
00039 
00040 
00041     /*********************
00042      * Start reading and initializing trace file
00043      * 
00044      * @param _window : current window instant
00045      * @param _statusMgr : the window's status manager
00046      * 
00047      * @return true if the trace file exists, false otherwise
00048      *********************/
00049     public boolean setupTrace(IWorkbenchWindow _window, IStatusLineManager _statusMgr)
00050     {
00051         final TraceAttribute trAttribute = exp.getTraceAttribute();
00052 
00053         if (trAttribute.dbGlob.charAt(0) == '*')
00054         {   // original format
00055             traceFilePath = getTraceFile(exp.getDefaultDirectory().getAbsolutePath(), _statusMgr);
00056             
00057         } else 
00058         {
00059             // new format
00060             traceFilePath = exp.getDefaultDirectory() + File.separator + trAttribute.dbGlob;
00061         }
00062         if (traceFilePath != null)
00063         {
00064             try {
00065                 dataTrace = new BaseData(traceFilePath, trAttribute.dbHeaderSize, 24);
00066                 return true;
00067                 
00068             } catch (IOException e) {
00069                 MessageDialog.openError(_window.getShell(), "I/O Error", e.getMessage());
00070                 System.err.println("Master buffer could not be created");
00071             }
00072         }
00073         return false;
00074     }
00075     
00076     /*********************
00077      * get the absolute path of the trace file (experiment.mt).
00078      * If the file doesn't exist, it is possible it is not merged yet 
00079      *  (in this case we'll merge them automatically)
00080      * 
00081      * @param directory
00082      * @param statusMgr
00083      * @return
00084      *********************/
00085     private String getTraceFile(String directory,   final IStatusLineManager statusMgr)
00086     {
00087         try {
00088             statusMgr.setMessage("Merging traces ...");
00089 
00090             final TraceProgressReport traceReport = new TraceProgressReport(
00091                     statusMgr);
00092             final String outputFile = directory
00093                     + File.separatorChar + "experiment.mt";
00094             
00095             File dirFile = new File(directory);
00096             final MergeDataFiles.MergeDataAttribute att = MergeDataFiles
00097                     .merge(dirFile, "*.hpctrace", outputFile,
00098                             traceReport);
00099             
00100             if (att != MergeDataFiles.MergeDataAttribute.FAIL_NO_DATA) {
00101                 File fileTrace = new File(outputFile);
00102                 if (fileTrace.length() > MIN_TRACE_SIZE) {
00103                     return fileTrace.getAbsolutePath();
00104                 }
00105                 
00106                 System.err.println("Warning! Trace file "
00107                         + fileTrace.getName()
00108                         + " is too small: "
00109                         + fileTrace.length() + "bytes .");
00110             }
00111             System.err
00112                     .println("Error: trace file(s) does not exist or fail to open "
00113                             + outputFile);
00114 
00115         } catch (IOException e) {
00116             e.printStackTrace();
00117         }
00118         return null;
00119     }
00120     
00121     /***********************************************************************
00122      * Gets the next available trace to be filled/painted
00123      * 
00124      * @param changedBounds
00125      *            Whether or not the thread should get the data.
00126      * @return The next trace.
00127      **********************************************************************/
00128     @Override
00129     public ProcessTimeline getNextTrace(boolean changedBounds) {
00130         
00131         int tracesToRender = Math.min(attributes.numPixelsV, attributes.getProcessInterval());
00132         
00133         // retrieve the current processing line, and atomically increment so that 
00134         // other threads will not increment at the same time
00135         // if the current line reaches the number of traces to render, we are done
00136         
00137         int currentLineNum = lineNum.getAndIncrement();
00138         if (currentLineNum < tracesToRender) {
00139             
00140             if (ptlService.getNumProcessTimeline() == 0)
00141                 ptlService.setProcessTimeline(new ProcessTimeline[tracesToRender]);
00142             
00143             if (changedBounds) {
00144                 ProcessTimeline currentTimeline = new ProcessTimeline(currentLineNum, getScopeMap(),
00145                         dataTrace, lineToPaint(currentLineNum),
00146                         attributes.numPixelsH, attributes.getTimeInterval(), 
00147                         minBegTime + attributes.getTimeBegin());
00148                 
00149                 ptlService.setProcessTimeline(currentLineNum, currentTimeline);
00150                 return currentTimeline;
00151             }
00152 
00153             return ptlService.getProcessTimeline(currentLineNum);
00154         }
00155         return null;
00156     }
00157 
00158     
00161     private int lineToPaint(int line) {
00162 
00163         int numTimelinesToPaint = attributes.getProcessInterval();
00164         if (numTimelinesToPaint > attributes.numPixelsV)
00165             return attributes.getProcessBegin() + (line * numTimelinesToPaint)
00166                     / (attributes.numPixelsV);
00167         else
00168             return attributes.getProcessBegin() + line;
00169     }
00170     
00171     
00172     /***
00173      * changing the trace data, caller needs to make sure to refresh the views
00174      * @param baseData
00175      */
00176     public void setBaseData(IBaseData baseData) 
00177     {
00178         dataTrace = baseData;
00179         
00180         // -------------------------------------------------------------
00181         // we have to change the range of displayed processes
00182         // -------------------------------------------------------------
00183         // hack: for unknown reason, "endProcess" is exclusive.
00184         // TODO: we should change to inclusive just like begProcess
00185         attributes.setProcess(0, baseData.getNumberOfRanks());
00186     }
00187 
00188 
00189 
00190     @Override
00191     public IFilteredData createFilteredBaseData() {
00192         try{
00193             return new FilteredBaseData(getTraceFileAbsolutePath(), 
00194                     exp.getTraceAttribute().dbHeaderSize, TraceAttribute.DEFAULT_RECORD_SIZE);
00195         }
00196         catch (Exception e){
00197             e.printStackTrace();
00198             return null;
00199         }
00200     }
00201     
00202     public String getTraceFileAbsolutePath(){
00203         return traceFilePath;
00204     }
00205 
00206     @Override
00207     public void closeDB() {
00208         dataTrace.dispose();
00209     }
00210     
00211     @Override
00212     public void dispose() {
00213         closeDB();
00214         super.dispose();
00215     }
00216 
00217 
00218     public void fillTracesWithData(boolean changedBounds, int numThreadsToLaunch) {
00219         //No need to do anything. The data for local is gotten from the file
00220         //on demand on a per-timeline basis.
00221     }
00222 
00223 
00224     @Override
00225     public String getName() {
00226         return exp.getDefaultDirectory().getPath();
00227     }
00228 
00229 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1