DataPreparation.java

Go to the documentation of this file.
00001 package edu.rice.cs.hpc.traceviewer.data.db;
00002 
00003 import org.eclipse.swt.graphics.Color;
00004 
00005 import edu.rice.cs.hpc.traceviewer.data.graph.CallPath;
00006 import edu.rice.cs.hpc.traceviewer.data.graph.ColorTable;
00007 import edu.rice.cs.hpc.traceviewer.data.timeline.ProcessTimeline;
00008 
00009 /***********************************************************************
00010  * 
00011  * Basic abstract class to prepare data for trace view and depth view
00012  * 
00013  * we will use an abstract method to finalize the data preparation since 
00014  *  depth view has slightly different way to paint compared to
00015  *  trace view
00016  * 
00017  ***********************************************************************/
00018 public abstract class DataPreparation
00019 {
00020     final protected ProcessTimeline ptl;
00021     final protected int depth;
00022     final protected int height;
00023     final protected double pixelLength;
00024     final protected ColorTable colorTable;
00025     final private long begTime;
00026     final private boolean usingMidpoint;
00027         
00028     /****
00029      * Abstract class constructor to paint a line (whether it's detail view or depth view) 
00030      * 
00031      * @param _colorTable : color table
00032      * @param _ptl : the time line manager of a process
00033      * @param _spp : the painter
00034      * @param _begTime : time start of the current view
00035      * @param _depth : the current depth
00036      * @param _height : the height (in pixel) of the line to paint
00037      * @param _pixelLength : the length (in pixel)
00038      * @param usingMidpoint : flag whether we should use midpoint or not
00039      */
00040     public DataPreparation(ColorTable _colorTable, ProcessTimeline _ptl, 
00041             long _begTime, int _depth, int _height, double _pixelLength, boolean _usingMidpoint)
00042     {
00043         this.ptl = _ptl;
00044         this.depth = _depth;
00045         this.height = _height;
00046         this.pixelLength = _pixelLength;
00047         this.colorTable = _colorTable;
00048         this.begTime = _begTime;
00049         this.usingMidpoint = _usingMidpoint;
00050     }
00051     
00053     public void collect()
00054     {
00055         int succSampleMidpoint = (int) Math.max(0, (ptl.getTime(0)-begTime)/pixelLength);
00056 
00057         CallPath cp = ptl.getCallPath(0, depth);
00058         if (cp==null)
00059             return;
00060         
00061         String succFunction = cp.getScopeAt(depth).getName(); 
00062         Color succColor = colorTable.getColor(succFunction);
00063         int last_ptl_index = ptl.size() - 1;
00064 
00065         for (int index = 0; index < ptl.size(); index++)
00066         {
00067             // in case of bad cpid, we just quit painting the view
00068             if (cp==null)
00069                 return;     // throwing an exception is more preferable, but it will make
00070                             // more complexity to handle inside a running thread
00071 
00072             final int currDepth = cp.getMaxDepth(); 
00073             int currSampleMidpoint = succSampleMidpoint;
00074             
00075             //-----------------------------------------------------------------------
00076             // skipping if the successor has the same color and depth
00077             //-----------------------------------------------------------------------
00078             boolean still_the_same = true;
00079             int indexSucc = index;
00080             int end = index;
00081 
00082             final Color currColor = succColor;
00083             
00084             while (still_the_same && (++indexSucc <= last_ptl_index))
00085             {
00086                 cp = ptl.getCallPath(indexSucc, depth);
00087                 if(cp != null)
00088                 {
00089                     succFunction = cp.getScopeAt(depth).getName(); 
00090                     succColor = colorTable.getColor(succFunction);
00091                     
00092                     // the color will be the same if and only if the two regions have the save function name
00093                     // regardless they are from different max depth and different call path.
00094                     // This can be misleading, but at the moment it is a good approximation
00095                     
00096                     // laksono 2012.01.23 fix: need to add a max depth condition to ensure that the adjacent
00097                     //                         has the same depth. In depth view, we don't want to mix with
00098                     //                          different depths
00099                     
00100                     still_the_same = (succColor.equals(currColor)) && currDepth == cp.getMaxDepth();
00101                     if (still_the_same)
00102                         end = indexSucc;
00103                 }
00104             }
00105             
00106             if (end < last_ptl_index)
00107             {
00108                 // --------------------------------------------------------------------
00109                 // start and middle samples: the rightmost point is the midpoint between
00110                 //  the two samples
00111                 // -------------------------------------------------------------------
00112                 // laksono 2014.11.04: previously midpoint(ptl.getTime(end),ptl.getTime(end+1)) : ptl.getTime(end);
00113                 
00114                 // assuming a range of three samples p0, p1 and p2 where p0 is the beginning, p1 is the last sample
00115                 //      that has the same color as p0, and p2 is the sample that has different color as p0 (and p1)
00116                 //      in time line: p0 < p1 < p2
00117                 // a non-midpoint policy then should have a range of p0 to p2 with p0 color.
00118                 
00119                 double succ = usingMidpoint ? midpoint(ptl.getTime(end),ptl.getTime(end+1)) : ptl.getTime(end+1);
00120                 succSampleMidpoint = (int) Math.max(0, ((succ-begTime)/pixelLength));
00121             }
00122             else
00123             {
00124                 // --------------------------------------------------------------------
00125                 // for the last iteration (or last sample), we don't have midpoint
00126                 //  so the rightmost point will be the time of the last sample
00127                 // --------------------------------------------------------------------
00128                 // succSampleMidpoint = (int) Math.max(0, ((ptl.getTime(index+1)-begTime)/pixelLength)); 
00129                 // johnmc: replaced above because it doesn't seem correct
00130                 succSampleMidpoint = (int) Math.max(0, ((ptl.getTime(end)-begTime)/pixelLength)); 
00131             }
00132             
00133             finishLine(currSampleMidpoint, succSampleMidpoint, currDepth, currColor, end - index + 1);
00134             index = end;
00135         }           
00136     }
00137      //This is potentially vulnerable to overflows but I think we are safe for now.
00139     private static long midpoint(long x1, long x2)
00140     {
00141         return (x1 + x2)/2;
00142     }
00143 
00144     public abstract TimelineDataSet getList();
00145 
00146     /***
00147      * Abstract method to finalize the painting given its range, depth and the function name
00148      * 
00149      * @param currSampleMidpoint : current sample
00150      * @param succSampleMidpoint : next sample
00151      * @param currDepth : current depth
00152      * @param functionName : name of the function (for coloring purpose)
00153      * @param sampleCount : the number of "samples"
00154      */
00155     public abstract void finishLine(int currSampleMidpoint, int succSampleMidpoint, int currDepth, Color color, int sampleCount);
00156 }

Generated on 5 May 2015 for HPCVIEWER by  doxygen 1.6.1