sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/model/GenericSampledTrace.java
changeset 5 844b047e260d
parent 2 b9ab3b238396
child 12 ae255c9aa552
equal deleted inserted replaced
4:615035072f7e 5:844b047e260d
    20 import java.util.Enumeration;
    20 import java.util.Enumeration;
    21 import java.util.Vector;
    21 import java.util.Vector;
    22 
    22 
    23 public abstract class GenericSampledTrace extends GenericTrace
    23 public abstract class GenericSampledTrace extends GenericTrace
    24 {
    24 {
    25 	private static final long serialVersionUID = -5030416972125713453L;
    25 	private static final long serialVersionUID = 5248402326692863890L;
    26 	
    26 	private long lastSampleTime;
    27 	public Vector samples;
    27 	
       
    28 	public Vector<GenericSample> samples;
    28 	
    29 	
    29 	public GenericSampledTrace()
    30 	public GenericSampledTrace()
    30 	{
    31 	{
    31 	  this.samples = new Vector();
    32 	  this.samples = new Vector<GenericSample>();
    32 	}
    33 	}
    33 	
    34 	
    34 	public void addSample(GenericSample sample)
    35 	public void addSample(GenericSample sample)
    35 	{
    36 	{
    36 	  this.samples.add(sample);
    37 	  this.samples.add(sample);
    37 	}
    38 	  if (sample.sampleSynchTime > lastSampleTime){
    38 	
    39 		  lastSampleTime = sample.sampleSynchTime;
    39 	public Enumeration getSamples()
    40 	  }
       
    41 	}
       
    42 	
       
    43 	/**
       
    44 	 * Returns the highest sampleSyncTime found in the set of samples.
       
    45 	 * 
       
    46 	 * @return last sample time
       
    47 	 */
       
    48 	public long getLastSampleTime(){
       
    49 		if (lastSampleTime == 0 && samples.size()>0){
       
    50 			//someone has added samples without going through the addSample() API in this class
       
    51 			//really, this.samples should be private
       
    52 			//let's try to recalculate lastSampleTime
       
    53 			for (GenericSample s : samples) {
       
    54 				  if (s.sampleSynchTime > lastSampleTime){
       
    55 					  lastSampleTime = s.sampleSynchTime;
       
    56 				  }
       
    57 			}
       
    58 		}
       
    59 		return lastSampleTime;
       
    60 	}
       
    61 	
       
    62 	public Enumeration<GenericSample> getSamples()
    40 	{
    63 	{
    41 	  return samples.elements();
    64 	  return samples.elements();
    42 	}
    65 	}
    43 	
    66 	
    44 	public GenericSample getSample(int number)
    67 	public GenericSample getSample(int number)
    46 	  return (GenericSample)this.samples.elementAt(number);
    69 	  return (GenericSample)this.samples.elementAt(number);
    47 	}
    70 	}
    48 	
    71 	
    49 	public Vector<GenericSample> getSamplesInsideTimePeriod(long start, long end)
    72 	public Vector<GenericSample> getSamplesInsideTimePeriod(long start, long end)
    50 	{
    73 	{
    51 		Enumeration sEnum = samples.elements();
    74 		Enumeration<GenericSample> sEnum = samples.elements();
    52 		Vector<GenericSample> okSamples = new Vector<GenericSample>();
    75 		Vector<GenericSample> okSamples = new Vector<GenericSample>();
    53 		
    76 		
    54 		while(sEnum.hasMoreElements())
    77 		while(sEnum.hasMoreElements())
    55 		{
    78 		{
    56 			GenericSample s = (GenericSample)sEnum.nextElement();
    79 			GenericSample s = (GenericSample)sEnum.nextElement();
   193 			return (int)this.getSample(0).sampleSynchTime;
   216 			return (int)this.getSample(0).sampleSynchTime;
   194 		else
   217 		else
   195 			return 0;
   218 			return 0;
   196 	}
   219 	}
   197 	
   220 	
       
   221 	/**
       
   222 	 * Returns the highest sample time in the trace. Note, on SMP systems,
       
   223 	 * this may not be the time of the last sample.
       
   224 	 * @return
       
   225 	 */
   198 	public int getLastSampleNumber()
   226 	public int getLastSampleNumber()
   199 	{
   227 	{
   200 		if (this.samples.size() > 0)
   228 		return (int)getLastSampleTime();
   201 			return (int)((GenericSample)this.samples.lastElement()).sampleSynchTime;
       
   202 		else
       
   203 			return 0;
       
   204 	}
   229 	}
   205 	
   230 	
   206 	public String toString()
   231 	public String toString()
   207 	{
   232 	{
   208 		Enumeration sEnum = this.getSamples();
   233 		Enumeration<GenericSample> sEnum = this.getSamples();
   209 	  	Vector strings = new Vector();
   234 	  	Vector<String> strings = new Vector<String>();
   210 	  	int totalLength = 0;
   235 	  	int totalLength = 0;
   211 	  	while(sEnum.hasMoreElements())
   236 	  	while(sEnum.hasMoreElements())
   212 	  	{	
   237 	  	{	
   213 	  		GenericSample s = (GenericSample)sEnum.nextElement();
   238 	  		GenericSample s = (GenericSample)sEnum.nextElement();
   214 	  		String uus = s.toString() + "\n"; //$NON-NLS-1$
   239 	  		String uus = s.toString() + "\n"; //$NON-NLS-1$
   216 	  		strings.add(uus);
   241 	  		strings.add(uus);
   217 	  	}
   242 	  	}
   218 	  	
   243 	  	
   219 	  	System.out.println(Messages.getString("GenericSampledTrace.totalLength") + totalLength); //$NON-NLS-1$
   244 	  	System.out.println(Messages.getString("GenericSampledTrace.totalLength") + totalLength); //$NON-NLS-1$
   220 	  	byte[] bytes = new byte[totalLength];
   245 	  	byte[] bytes = new byte[totalLength];
   221 	  	sEnum = strings.elements();
   246 	  	Enumeration<String> sEnumString = strings.elements();
   222 	  	int index = 0;
   247 	  	int index = 0;
   223 	  	while(sEnum.hasMoreElements())
   248 	  	while(sEnumString.hasMoreElements())
   224 	  	{
   249 	  	{
   225 	  		String s = (String)sEnum.nextElement();
   250 	  		String s = (String)sEnumString.nextElement();
   226 	  		byte[] sB = s.getBytes();
   251 	  		byte[] sB = s.getBytes();
   227 	  		for (int i = index; i < index + sB.length; i++)
   252 	  		for (int i = index; i < index + sB.length; i++)
   228 	  		{
   253 	  		{
   229 	  			bytes[i] = sB[i - index];
   254 	  			bytes[i] = sB[i - index];
   230 	  		}
   255 	  		}