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
00029
00030
00031
00032
00033
00034
00035
00036
00037
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
00057
00058
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
00072
00073 private int currentDataIdx;
00074
00075
00076
00077
00078
00079
00080
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
00093
00094
00095
00096
00097
00098
00099 public SpaceTimeDataController(IWorkbenchWindow _window, InputStream expStream, String Name)
00100 throws InvalExperimentException, Exception
00101 {
00102 exp = new ExperimentWithoutMetrics();
00103
00104
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
00123
00124
00125
00126
00127 private void init(IWorkbenchWindow _window)
00128 throws InvalExperimentException
00129 {
00130
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
00139 colorTable.setColorTable();
00140
00141
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
00195
00196
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
00208
00209
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
00228
00229
00230 public int getTotalTraceCount() {
00231 return dataTrace.getNumberOfRanks();
00232 }
00233
00234 protected HashMap<Integer, CallPath> getScopeMap() {
00235 return scopeMap;
00236 }
00237
00238
00239
00240
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
00258
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
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
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
00330
00331
00332
00333
00334
00335
00336
00337
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 }