sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/model/ProfiledGeneric.java
changeset 5 844b047e260d
parent 2 b9ab3b238396
child 12 ae255c9aa552
equal deleted inserted replaced
4:615035072f7e 5:844b047e260d
    23 import org.eclipse.swt.graphics.Color;
    23 import org.eclipse.swt.graphics.Color;
    24 import org.eclipse.swt.graphics.RGB;
    24 import org.eclipse.swt.graphics.RGB;
    25 
    25 
    26 import com.nokia.carbide.cpp.pi.util.ColorPalette;
    26 import com.nokia.carbide.cpp.pi.util.ColorPalette;
    27 
    27 
       
    28 /**
       
    29  * Generic class for a profiled element, such as a thread, a binary or a function
       
    30  *
       
    31  */
    28 public abstract class ProfiledGeneric
    32 public abstract class ProfiledGeneric
    29 {
    33 {
       
    34 	/** number of graphs */
       
    35 	protected static final int GRAPH_COUNT = 3;
       
    36 	
       
    37 	/**
       
    38 	 * Unique ordinal for this profiled element, given on creation. The first created profiled element
       
    39 	 * of this kind has an index of zero, each following is incremented by one.
       
    40 	 */
    30     protected int index = -1;
    41     protected int index = -1;
       
    42     /** Name of this profiled element */
    31     private String nameString;
    43     private String nameString;
       
    44     /** Colour with which this profiled element is represented in any graph or legend view*/
    32     protected Color color;
    45     protected Color color;
    33     protected int totalSampleCount;
    46     /** overall sample count of this profiled element in the trace */
       
    47 	protected int totalSampleCount;
       
    48 	/** timestamp of the first sample for this profiled element */
    34     protected int firstSample = -1;
    49     protected int firstSample = -1;
       
    50 	/** timestamp of the last sample for this profiled element */
    35     protected int lastSample = -1;
    51     protected int lastSample = -1;
    36     private int   recentSample = -1;
    52 
    37     private int   recentSampleCount = 0;
       
    38     private int   recentPercentage = -1;
       
    39     protected int[] activityList;
       
    40     private int[] sampleList;
       
    41     private int[][] cumulativeList = new int[3][];
       
    42     
       
    43 	// since each instance may be used by table viewers for multiple graphs,
    53 	// since each instance may be used by table viewers for multiple graphs,
    44 	// keep per graph (for a maximum of 3 graphs):
    54 	// keep per graph (for a maximum of 3 graphs):
    45     //	whether the thread/binary/function is currently enabled
    55     //	whether the thread/binary/function is currently enabled
    46     //	sample count in the selected graph area
    56     //	sample count in the selected graph area
    47     //	% load in the selected graph area
    57     //	% load in the selected graph area
    48 	//  string version of graph percent load
    58 	//  string version of graph percent load
    49     protected boolean[] enableValue = {true, true, true};
    59     
    50 	protected int[]   graphSampleCount = { 0, 0, 0 };
    60     /**
    51 	protected float[] graphPercentLoad = { 0.0f, 0.0f, 0.0f };
    61   	 * The cumulative list contains for each bucket the 
    52     private String[]  averageLoadValueString = { "", "", "" }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    62   	 * cumulative sample percentage of the same bucket of all ProfiledGenerics
    53 	
    63   	 * so far processed (not including the values of the current ProfiledGeneric).
    54     private PointList[] pointList  = {new PointList(), new PointList(), new PointList()};
    64   	 * 
    55     protected int[] activityP = null;
    65   	 * In other words it's containing the bottom or start value of this
       
    66   	 * profiled element to draw on the graph (the graph drawn just underneath the 
       
    67   	 * graph of this profiled element)
       
    68   	 */
       
    69     private float[][] cumulativeList;
       
    70     /** checkbox enabled state of this profiled element for each of the graphs */
       
    71     protected boolean[] enableValue;
       
    72     /** current sample count of this profiled element for each of the graphs, changes with enabled state, selected time frame, master filtering */
       
    73 	protected int[]   graphSampleCount;
       
    74     /** current sample percentage load of this profiled element for each of the graphs, changes with enabled state, selected time frame, master filtering */
       
    75 	protected float[] graphPercentLoad;
       
    76     /** current sample average load of this profiled element for each of the graphs, changes with enabled state, selected time frame, master filtering */
       
    77     private String[]  averageLoadValueString; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$	
       
    78     /** PointList for each graphs polyline */
       
    79     private PointList[] pointList;
       
    80     
       
    81     //  bucket values 
       
    82     //
       
    83     /** holds the sample count value for all buckets, calculated as one-off when trace is first processed */
       
    84     private int[] activityN = null;
       
    85     /** holds percentage value for all buckets, calculated as one-off when trace is first processed */
       
    86     protected float[] activityP = null;
       
    87     /** holds start timestamp of all buckets, calculated as one-off when trace is first processed */
    56     private int[] activityT = null;
    88     private int[] activityT = null;
       
    89     /** the index of the bucket currently updated */
    57     protected int activityIndx = 0;
    90     protected int activityIndx = 0;
    58     
    91     
    59     public ProfiledGeneric()
    92     /** total number of CPUs in the system; 1 for non-SMP trace */
    60     {
    93 	private int cpuCount;
    61       // default to light gray
    94 
    62       this.color = ColorPalette.getColor(new RGB(192, 192, 192));
    95     //for SMP
    63      }
    96     protected boolean isSMP;
    64     
    97 	protected int[] totalSampleCountSMP;
       
    98     
       
    99     protected float[][] activityPSMP;
       
   100     private int[][] activityNSMP;
       
   101     
       
   102 	/**
       
   103 	 * Constructor
       
   104 	 * @param cpuCount number of CPUs present in the trace
       
   105 	 * @param graphCount number of graphs to display
       
   106 	 */
       
   107 	public ProfiledGeneric(int cpuCount, int graphCount) {
       
   108 		if (graphCount < 0){
       
   109 			throw new IllegalArgumentException("graphCount must be greater than 0.");
       
   110 		}
       
   111 		// default to light gray
       
   112 		this.color = ColorPalette.getColor(new RGB(192, 192, 192));
       
   113 		this.cpuCount = cpuCount;
       
   114 		
       
   115 		// init variables for values per graph
       
   116 		cumulativeList = new float[graphCount][];
       
   117 		enableValue = new boolean[graphCount];
       
   118 		graphSampleCount = new int[graphCount];
       
   119 		graphPercentLoad = new float[graphCount];
       
   120 		averageLoadValueString = new String[graphCount];
       
   121 		pointList = new PointList[graphCount];
       
   122 		for (int graph = 0; graph < graphCount; graph++) {
       
   123 		    enableValue[graph] = true;
       
   124 			averageLoadValueString[graph] = ""; //$NON-NLS-1$
       
   125 			pointList[graph] = new PointList();
       
   126 		}
       
   127 
       
   128 		if (cpuCount > 1) { // SMP
       
   129 
       
   130 			isSMP = true;
       
   131 			totalSampleCountSMP = new int[cpuCount];
       
   132 
       
   133 			activityPSMP = new float[cpuCount][];
       
   134 			activityNSMP = new int[cpuCount][];
       
   135 		}
       
   136 	}
       
   137     
       
   138     /**
       
   139      * Setter for the name of the profiled element
       
   140      * @param nameString
       
   141      */
    65     public void setNameString(String nameString)
   142     public void setNameString(String nameString)
    66     {
   143     {
    67     	this.nameString = nameString;
   144     	this.nameString = nameString;
    68     }
   145     }
    69     
   146     
       
   147     /**
       
   148      * Adds a point to the PointList of the given graph
       
   149      * @param graphIndex the graph to use
       
   150      * @param x the X-coordinate of the point
       
   151      * @param y the Y-coordinate of the point
       
   152      */
    70     public void addPointToPolyline(int graphIndex, int x, int y)
   153     public void addPointToPolyline(int graphIndex, int x, int y)
    71     {
   154     {
    72     	pointList[graphIndex].addPoint(x, y);
   155     	pointList[graphIndex].addPoint(x, y);
    73     }
   156     }
    74     
   157     
    85     public int getIndex()
   168     public int getIndex()
    86     {
   169     {
    87     	return this.index;
   170     	return this.index;
    88     }
   171     }
    89     
   172     
    90     public void setActivityMarkCount(int size)
   173     /**
    91     {
   174      * Creates bucket arrays. This also propagates to SMP bucket arrays.  
    92     	this.activityP = new int[size];
   175      * @param numberOfBuckets The total number of buckets to use.
    93     	this.activityT = new int[size];
   176      */
    94     }
   177     public void createBuckets(int numberOfBuckets){
    95     
   178     	this.activityP = new float[numberOfBuckets];
    96     // zero the samples of this profiled generic in the time range starting at the time stamp
   179     	this.activityT = new int[numberOfBuckets];
    97     public void zeroActivityMarkValues(int timeStamp)
   180     	this.activityN = new int[numberOfBuckets];
    98     {
   181     	if (isSMP){
    99         addActivityMarkValues(timeStamp, 0, 0);
   182 			for (int cpu = 0; cpu < cpuCount; cpu++) {
   100     }
   183 		    	this.activityPSMP[cpu] = new float[numberOfBuckets];
   101 
   184 		    	this.activityNSMP[cpu] = new int[numberOfBuckets];
   102     // set the samples of of this profiled generic in the time range starting at the time stamp
   185 			}						    		
   103     public void addActivityMarkValues(int timeStamp, int percentage, int sampleCount)
   186     	}
   104     {
   187     }
   105       this.activityT[this.activityIndx] = timeStamp;
   188     
   106       this.activityP[this.activityIndx] = percentage;
   189     /**
   107 
   190      * this is intended to initialise the newly created bucket arrays
   108       if (this.firstSample == -1 && percentage != 0)
   191      * @param duration length of time each bucket represents 
   109       {
   192      */
   110     	  this.firstSample = this.recentSample;
   193     public void initialiseBuckets(int duration){
   111       }
   194     	for (int i = 0; i < activityT.length; i++) {
   112 
   195 			//this is important for calculating the x values later, so use mid-bucket values
   113    	  if (this.recentSampleCount > 0)
   196     		activityT[i] = duration*i + duration / 2;
   114    		  this.lastSample = timeStamp;
   197 		}
   115 
   198     }
   116       this.recentSample      = timeStamp;
   199     
   117       this.recentSampleCount = sampleCount;
   200     /**
   118       this.recentPercentage  = percentage;
   201      * Updates the bucket percentage values. This requires that sample counts have
   119       this.activityIndx++;
   202      * already been calculated for each bucket.
   120     }
   203      * @param bucketTotalArr Total number of samples per bucket
   121 
   204      * @param bucketTotalArrSMP total number of samples per cpu and bucket. May be null for non-SMP systems.
   122     public void addActivityMark(int timeStamp, int percentage)
   205      */
   123     {
   206     public void calculateBucketPercentages(int[] bucketTotalArr, int[][] bucketTotalArrSMP){
   124       this.activityT[this.activityIndx] = timeStamp;
   207     	if (activityN != null){ 
   125       this.activityP[this.activityIndx] = percentage;
   208         	for (int b = 0; b < activityN.length; b++) {//loop through sample counts per bucket
   126       this.activityIndx++;
   209         		if (bucketTotalArr[b] > 0){
       
   210             		activityP[b] = (float)activityN[b]*100/bucketTotalArr[b];
       
   211         			
       
   212         		}
       
   213         		
       
   214         		activityIndx = activityP.length; //TODO: temporarily needed, remove later
       
   215         		
       
   216     			if (isSMP){
       
   217     				for (int cpu = 0; cpu < bucketTotalArrSMP.length; cpu++) {
       
   218     					if (bucketTotalArrSMP[cpu][b]>0){
       
   219     						activityPSMP[cpu][b] = (float)activityNSMP[cpu][b]*100/bucketTotalArrSMP[cpu][b];
       
   220     					}
       
   221 					}
       
   222     			}
       
   223     		}    		
       
   224     	}	    		
       
   225     }
       
   226     
       
   227     /**
       
   228      * Increases total sample count as well as sample count for the given bucket. Takes care of SMP values
       
   229      * if SMP trace.
       
   230      * @param bucketIndex The index of the bucket to use
       
   231      * @param timestamp the timestamp of the sample
       
   232      * @param cpu the CPU number of the sample
       
   233      */
       
   234     public void increaseSampleCount(int bucketIndex, int timestamp, int cpu){
       
   235     	//note, activityT (bucket times) is constant and has been set during initialisation
       
   236     	//activityP (bucket percentages) will be calculated after all samples have been processed
       
   237     	
       
   238 		incTotalSampleCount();
       
   239 		if (isSMP){
       
   240 			incTotalSampleCountForSMP(cpu);				
       
   241 		}
       
   242 		
       
   243     	this.activityN[bucketIndex]++; //increase sample count in bucket
       
   244     	if (firstSample == -1){
       
   245     		firstSample = timestamp;
       
   246     	}
       
   247     	lastSample = timestamp;
       
   248     	if (isSMP){
       
   249     		this.activityNSMP[cpu][bucketIndex]++;
       
   250     	}
   127     }
   251     }
   128 
   252 
   129   	public void setupCumulativeList(int graphIndex)
   253   	public void setupCumulativeList(int graphIndex)
   130   	{
   254   	{
   131   		if (this.activityIndx != 0)
   255   		if (this.activityT != null && activityT.length != 0)
   132   		{	
   256   		{	
   133   			if (cumulativeList[graphIndex] == null)
   257   			if (cumulativeList[graphIndex] == null)
   134   				cumulativeList[graphIndex] = new int[this.activityIndx];
   258   				cumulativeList[graphIndex] = new float[this.activityT.length];
   135   			else
   259   			else
   136   			{
   260   			{
   137   				for (int i = 0; i < cumulativeList[graphIndex].length; i++)
   261   				for (int i = 0; i < cumulativeList[graphIndex].length; i++)
   138   				{
   262   				{
   139   					cumulativeList[graphIndex][i] = 0;
   263   					cumulativeList[graphIndex][i] = 0;
   140   				}
   264   				}
   141   			}
   265   			}
   142   		}
   266   		}
   143   	}
   267   	}
   144 
   268 
   145   	public int[] getCumulativeList(int graphIndex)
   269   	/**
       
   270   	 * The cumulative list contains for each bucket the 
       
   271   	 * cumulative sample percentage of the same bucket of all ProfiledGenerics
       
   272   	 * so far processed (not including the values of the current ProfiledGeneric).
       
   273   	 * 
       
   274   	 * Typically used for drawing a stacked-area chart
       
   275   	 * @param graphIndex the graph ordinal to use
       
   276   	 * @return
       
   277   	 */
       
   278   	public float[] getCumulativeList(int graphIndex)
   146   	{
   279   	{
   147   		return this.cumulativeList[graphIndex];
   280   		return this.cumulativeList[graphIndex];
   148   	}
   281   	}
   149 
   282 
   150   	public void setCumulativeValue(int graphIndex, int index, int value)
   283   	public void setCumulativeValue(int graphIndex, int index, float value)
   151   	{
   284   	{
   152   		this.cumulativeList[graphIndex][index] = value;
   285   		this.cumulativeList[graphIndex][index] = value;
   153   	}
   286   	}
   154   	
   287   	
   155   	//returns x-coordinates
   288   	/**
       
   289   	 * returns x-coordinates
       
   290   	 * @return
       
   291   	 */
   156   	public int[] getSampleList()
   292   	public int[] getSampleList()
   157   	{
   293   	{
   158   		if (sampleList == null && this.activityIndx != 0)
   294   		if (activityT != null){
   159   		{
   295   			//Arrays.copyOf() is only supported from Java 6
   160   			sampleList = new int[this.activityIndx];
   296   			//return Arrays.copyOf(this.activityT, this.activityT.length);
   161  
   297   			int[] ret = new int[activityT.length];
   162   			for (int i = 0; i < this.activityIndx; i++)
   298   			for (int i = 0; i < ret.length; i++) {
   163   			{
   299 				ret[i] = activityT[i];
   164   				this.sampleList[i] = this.activityT[i];
   300 			}
   165   			}
   301   			return ret;
   166   			this.activityT = null;
       
   167   		}
   302   		}
   168   		return this.sampleList;
   303   		return null;
   169   	}
   304   	}
   170   	
   305   	
   171   	// returns y-coordinates
   306   	/**
   172   	public int[] getActivityList()
   307   	 *  returns y-coordinates
       
   308   	 * @return
       
   309   	 */
       
   310   	public float[] getActivityList(){
       
   311   		if (activityP != null){
       
   312   			//Arrays.copyOf() is only supported from Java 6
       
   313   			//return Arrays.copyOf(this.activityP, this.activityP.length);
       
   314   			float[] ret = new float[activityP.length];
       
   315   			for (int i = 0; i < ret.length; i++) {
       
   316 				ret[i] = activityP[i];
       
   317 			}
       
   318   			return ret;
       
   319   		}
       
   320   		return null;
       
   321    	}
       
   322   	
       
   323   	/**
       
   324   	 *  returns y-coordinates (percentage values of activity)
       
   325   	 * @param cpu 
       
   326   	 * @return
       
   327   	 */
       
   328   	public float[] getActivityListForSMP(int cpu)
   173   	{
   329   	{
   174   		if (activityList == null && this.activityIndx != 0)
   330   		if (isSMP && this.activityPSMP[cpu] != null){
   175   		{
   331   			//Arrays.copyOf() is only supported from Java 6
   176   			activityList = new int[this.activityIndx];
   332   			//return Arrays.copyOf(activityPSMP[cpu], activityPSMP[cpu].length);
   177 
   333   			float[] ret = new float[activityPSMP[cpu].length];
   178   			for (int i = 0; i < this.activityIndx; i++)
   334   			for (int i = 0; i < ret.length; i++) {
   179   			{
   335 				ret[i] = activityPSMP[cpu][i];
   180   			  activityList[i] = this.activityP[i];
   336 			}
   181   			}
   337   			return ret;
   182   			this.activityP = null;
       
   183   		}
   338   		}
   184 
   339   		return null;
   185   		return this.activityList;
       
   186   	}
   340   	}
   187 
   341 
   188     public int getFirstSample()
   342     public int getFirstSample()
   189     {
   343     {
   190       if (this.firstSample == -1)
   344       if (this.firstSample == -1)
   191     	  return 0;
   345     	  return 0;
   192       else
   346       else
   193     	  return this.firstSample;
   347     	  return this.firstSample;
   194     }
   348     }
   195 
   349 
   196     public int getRealFirstSample()
       
   197     {
       
   198    	  return this.firstSample;
       
   199     }
       
   200 
   350 
   201     public int getLastSample()
   351     public int getLastSample()
   202     {
   352     {
   203       if (this.lastSample == -1)
   353       if (this.lastSample == -1)
   204     	  return 0;
   354     	  return 0;
   213     
   363     
   214     public void setLastSample(int lastSample)
   364     public void setLastSample(int lastSample)
   215     {
   365     {
   216     	this.lastSample = lastSample;
   366     	this.lastSample = lastSample;
   217     }
   367     }
   218 
   368     
   219     private int findNearestSampleIndexFromStart(int sampleNum)
   369     /**
   220     {
   370      * Setter for this ordinal of this profiled element
   221     	int i = 0;
   371      * @param index the ordinal to set
   222     	while (i < this.sampleList.length && this.sampleList[i] < sampleNum)
   372      */
   223     	{
       
   224     		i++;
       
   225     	}    
       
   226     	return i;
       
   227     }
       
   228 
       
   229     private int findNearestSampleIndexFromEnd(int sampleNum)
       
   230     {
       
   231     	int i = sampleList.length - 1;
       
   232     	while (this.sampleList[i] > sampleNum && i > 0)
       
   233     	{
       
   234     		i--;
       
   235     	}
       
   236     	return i;
       
   237     }
       
   238 
       
   239     public float getAverageLoad(double startTime, double endTime)
       
   240     {
       
   241         return getAverageLoad((int) startTime,(int) endTime);
       
   242     }
       
   243     
       
   244     public float getAverageLoad(int startSample,int endSample)
       
   245     {
       
   246     	if (startSample == -1 || endSample == -1) return -666;
       
   247     	if (endSample < startSample) return -777;
       
   248 
       
   249     	if (this.activityList == null || this.sampleList == null) return -888;
       
   250 
       
   251     	int firstSampleIndx = 0;
       
   252     	int lastSampleIndx = 0;
       
   253 
       
   254     	firstSampleIndx = this.findNearestSampleIndexFromStart(startSample) + 1;
       
   255     	lastSampleIndx  = this.findNearestSampleIndexFromEnd(endSample) + 1;
       
   256    
       
   257     	if (firstSampleIndx < 0)
       
   258     		firstSampleIndx = 0;
       
   259     	if (firstSampleIndx >= activityList.length)
       
   260     		firstSampleIndx = activityList.length - 1;
       
   261     	
       
   262     	if (lastSampleIndx < 0)
       
   263     		lastSampleIndx = 0;
       
   264     	if (lastSampleIndx >= activityList.length)
       
   265     		lastSampleIndx = activityList.length - 1;
       
   266       
       
   267     	if (firstSampleIndx > lastSampleIndx)
       
   268     	{
       
   269     		int temp = firstSampleIndx;
       
   270     		firstSampleIndx = lastSampleIndx;
       
   271     		lastSampleIndx = temp;
       
   272     	}
       
   273     	
       
   274     	int totalTime = sampleList[lastSampleIndx - 1] - sampleList[firstSampleIndx - 1];
       
   275     	int totalLoad = 0;
       
   276     	
       
   277     	for (int i = firstSampleIndx; i < lastSampleIndx; i++)
       
   278     	{
       
   279     		totalLoad += this.activityList[i];
       
   280     	}
       
   281      	
       
   282     	totalLoad *= (sampleList[1] - sampleList[0]);
       
   283 
       
   284     	if (totalTime == 0)
       
   285     	{
       
   286     		return 0;
       
   287     	}
       
   288     	else
       
   289     	{
       
   290     		return (float)(((float)totalLoad) / ((float)totalTime));
       
   291     	}
       
   292     }
       
   293     
       
   294     public int getTotalLoad(int startSample,int endSample)
       
   295     {
       
   296     	if (startSample == -1 || endSample == -1) return -666;
       
   297     	if (endSample < startSample) return -777;
       
   298 
       
   299     	if (this.activityList == null || this.sampleList == null) return -888;
       
   300 
       
   301     	int firstSampleIndx = 0;
       
   302     	int lastSampleIndx = 0;
       
   303 
       
   304     	firstSampleIndx = this.findNearestSampleIndexFromStart(startSample) + 1;
       
   305     	lastSampleIndx  = this.findNearestSampleIndexFromEnd(endSample) + 1;
       
   306   
       
   307     	if (firstSampleIndx < 0)
       
   308     		firstSampleIndx = 0;
       
   309     	if (firstSampleIndx >= activityList.length)
       
   310     		firstSampleIndx = activityList.length - 1;
       
   311     	
       
   312     	if (lastSampleIndx < 0)
       
   313     		lastSampleIndx = 0;
       
   314     	if (lastSampleIndx >= activityList.length)
       
   315     		lastSampleIndx = activityList.length - 1;
       
   316       
       
   317     	if (firstSampleIndx > lastSampleIndx)
       
   318     	{
       
   319     		int temp = firstSampleIndx;
       
   320     		firstSampleIndx = lastSampleIndx;
       
   321     		lastSampleIndx = temp;
       
   322     	}
       
   323     	
       
   324     	int totalTime = sampleList[lastSampleIndx - 1] - sampleList[firstSampleIndx - 1];
       
   325     	int totalLoad = 0;
       
   326    	
       
   327     	for (int i = firstSampleIndx; i < lastSampleIndx; i++)
       
   328     	{
       
   329     		totalLoad += this.activityList[i];
       
   330     	}
       
   331      	
       
   332     	if (totalTime == 0)
       
   333     	{
       
   334     		return 0;
       
   335     	}
       
   336     	else
       
   337     	{
       
   338     		return (int) totalLoad;
       
   339     	}
       
   340     }
       
   341     
       
   342     public void setIndex(int index)
   373     public void setIndex(int index)
   343     {
   374     {
   344     	this.index = index;
   375     	this.index = index;
   345     }
   376     }
   346     
   377     
   352     public void setAverageLoadValueString(int graphIndex, float value)
   383     public void setAverageLoadValueString(int graphIndex, float value)
   353     {
   384     {
   354     	this.averageLoadValueString[graphIndex] = (new DecimalFormat(Messages.getString("ProfiledGeneric.decimalFormat"))).format(value); //$NON-NLS-1$
   385     	this.averageLoadValueString[graphIndex] = (new DecimalFormat(Messages.getString("ProfiledGeneric.decimalFormat"))).format(value); //$NON-NLS-1$
   355     }
   386     }
   356 
   387 
   357     public void setAverageLoadValueString(int graphIndex)
       
   358     {
       
   359     	this.averageLoadValueString[graphIndex] = (new DecimalFormat(Messages.getString("ProfiledGeneric.decimalFormat"))).format(this.graphPercentLoad[graphIndex]); //$NON-NLS-1$
       
   360     }
       
   361 
   388 
   362     public String getAverageLoadValueString(int graphIndex)
   389     public String getAverageLoadValueString(int graphIndex)
   363     {
   390     {
   364     	return this.averageLoadValueString[graphIndex];
   391     	return this.averageLoadValueString[graphIndex];
   365     }
   392     }
   366 
   393 
       
   394     /**
       
   395      * Setter for this colour of this profiled element
       
   396      * @param c the colour to set
       
   397      */
   367     public void setColor(Color c)
   398     public void setColor(Color c)
   368     {
   399     {
   369     	this.color = c;
   400     	this.color = c;
   370     }
   401     }
   371 
   402 
       
   403     /**
       
   404      * Sets enabled state for this profiled element in the given graph
       
   405      * @param graphIndex the graph index to use
       
   406      * @param enableValue true for enabled, false for disabled
       
   407      */
   372     public void setEnabled(int graphIndex, boolean enableValue)
   408     public void setEnabled(int graphIndex, boolean enableValue)
   373     {
   409     {
   374     	this.enableValue[graphIndex] = enableValue;
   410     	this.enableValue[graphIndex] = enableValue;
   375     }
   411     }
   376 
   412 
       
   413     /**
       
   414      * Checks enabled state for this profiled element in the given graph
       
   415      * @param graphIndex the graph index to use
       
   416      * @return true if enabled, false if disabled
       
   417      */
   377     public boolean isEnabled(int graphIndex)
   418     public boolean isEnabled(int graphIndex)
   378     {
   419     {
   379     	return enableValue[graphIndex];
   420     	return enableValue[graphIndex];
   380     }
   421     }
   381 
   422 
       
   423     /**
       
   424      * @return the colour of this profiled element
       
   425      */
   382     public Color getColor()
   426     public Color getColor()
   383     {
   427     {
   384     	return this.color;
   428     	return this.color;
   385     }
   429     }
   386     
   430     
       
   431     /**
       
   432      * @return the name of this profiled element
       
   433      */
   387     public String getNameString()
   434     public String getNameString()
   388     {
   435     {
   389     	return this.nameString;
   436     	return this.nameString;
   390     }
   437     }
   391     
   438     
       
   439     /**
       
   440      * @return the total sample count of this profiled element over the entire trace data
       
   441      */
   392     public int getTotalSampleCount()
   442     public int getTotalSampleCount()
   393     {
   443     {
   394     	return this.totalSampleCount;
   444     	return this.totalSampleCount;
   395     }
   445     }
   396     
   446     
   397     public void incTotalSampleCount()
   447     /**
       
   448      * Increased the total sample count of this profiled element by one
       
   449      */
       
   450    public void incTotalSampleCount()
   398     {
   451     {
   399     	this.totalSampleCount++;
   452     	this.totalSampleCount++;
   400     }
   453     }
   401 
   454     
       
   455     /**
       
   456      * returns the total sample count over the entire trace data for the given CPU
       
   457      * @param cpu the CPU to use
       
   458      * @return the total sample count for given CPU
       
   459      */
       
   460     public int getTotalSampleCountForSMP(int cpu)
       
   461     {
       
   462     	return this.totalSampleCountSMP[cpu];
       
   463     }
       
   464     
       
   465     /**
       
   466      * Increases the total sample count for the given CPU by one
       
   467      * @param cpu the CPU to use
       
   468      */
       
   469     public void incTotalSampleCountForSMP(int cpu)
       
   470     {
       
   471     	this.totalSampleCountSMP[cpu]++;
       
   472     }
       
   473 
       
   474 	/**
       
   475 	 * Getter for the given graph's sample count
       
   476 	 * @param graphIndex
       
   477 	 * @return
       
   478 	 */
   402 	public int getSampleCount(int graphIndex)
   479 	public int getSampleCount(int graphIndex)
   403 	{
   480 	{
   404 		return this.graphSampleCount[graphIndex];
   481 		return this.graphSampleCount[graphIndex];
   405 	}
   482 	}
   406 	
   483 	
   412 	public void incSampleCount(int graphIndex)
   489 	public void incSampleCount(int graphIndex)
   413 	{
   490 	{
   414 		this.graphSampleCount[graphIndex]++;
   491 		this.graphSampleCount[graphIndex]++;
   415 	}
   492 	}
   416 	
   493 	
   417 	public void setSampleCounts(int sampleCount0, int sampleCount1, int sampleCount2)
       
   418 	{
       
   419 		this.graphSampleCount[0] = sampleCount0;
       
   420 		this.graphSampleCount[1] = sampleCount1;
       
   421 		this.graphSampleCount[2] = sampleCount2;
       
   422 	}
       
   423 	
       
   424 	public float getPercentLoad(int graphIndex)
   494 	public float getPercentLoad(int graphIndex)
   425 	{
   495 	{
   426 		return this.graphPercentLoad[graphIndex];
   496 		return this.graphPercentLoad[graphIndex];
   427 	}
   497 	}
   428 	
   498 	
   435 		if (percentLoad >= 0.005f)
   505 		if (percentLoad >= 0.005f)
   436 			this.averageLoadValueString[graphIndex] = (new DecimalFormat(Messages.getString("ProfiledGeneric.decimalFormat"))).format(percentLoad); //$NON-NLS-1$
   506 			this.averageLoadValueString[graphIndex] = (new DecimalFormat(Messages.getString("ProfiledGeneric.decimalFormat"))).format(percentLoad); //$NON-NLS-1$
   437 		else
   507 		else
   438 			this.averageLoadValueString[graphIndex] = Messages.getString("ProfiledGeneric.zeroFormat"); //$NON-NLS-1$
   508 			this.averageLoadValueString[graphIndex] = Messages.getString("ProfiledGeneric.zeroFormat"); //$NON-NLS-1$
   439 	}
   509 	}
       
   510 
   440 	
   511 	
   441 	public void setPercentLoads(float percentLoad0, float percentLoad1, float percentLoad2)
       
   442 	{
       
   443 		this.graphPercentLoad[0] = percentLoad0;
       
   444 		this.graphPercentLoad[1] = percentLoad1;
       
   445 		this.graphPercentLoad[2] = percentLoad2;
       
   446 
       
   447 		// doesn't hurt to set the strings here, too
       
   448 		// you may not need to set the strings when you set the float
       
   449 		if (percentLoad0 >= 0.005f)
       
   450 			this.averageLoadValueString[0] = (new DecimalFormat(Messages.getString("ProfiledGeneric.decimalFormat"))).format(percentLoad0); //$NON-NLS-1$
       
   451 		else
       
   452 			this.averageLoadValueString[0] = Messages.getString("ProfiledGeneric.zeroFormat"); //$NON-NLS-1$
       
   453 		if (percentLoad1 >= 0.005f)
       
   454 			this.averageLoadValueString[1] = (new DecimalFormat(Messages.getString("ProfiledGeneric.decimalFormat"))).format(percentLoad1); //$NON-NLS-1$
       
   455 		else
       
   456 			this.averageLoadValueString[1] = Messages.getString("ProfiledGeneric.zeroFormat"); //$NON-NLS-1$
       
   457 		if (percentLoad2 >= 0.005f)
       
   458 			this.averageLoadValueString[2] = (new DecimalFormat(Messages.getString("ProfiledGeneric.decimalFormat"))).format(percentLoad2); //$NON-NLS-1$
       
   459 		else
       
   460 			this.averageLoadValueString[2] = Messages.getString("ProfiledGeneric.zeroFormat"); //$NON-NLS-1$
       
   461 	}
       
   462 }
   512 }