sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.perfcounters/src/com/nokia/carbide/cpp/pi/internal/perfcounters/PecTraceParser.java
changeset 12 ae255c9aa552
parent 5 844b047e260d
--- a/sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.perfcounters/src/com/nokia/carbide/cpp/pi/internal/perfcounters/PecTraceParser.java	Wed Jun 23 14:49:59 2010 +0300
+++ b/sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.perfcounters/src/com/nokia/carbide/cpp/pi/internal/perfcounters/PecTraceParser.java	Wed Jun 23 15:05:09 2010 +0300
@@ -42,6 +42,8 @@
 	private static final int INSTRUCTIONS_EXECUTED = 0x7;
 	private static final int CPU_CLOCK_TICK_DIV64 = 0xFFFF;
 	private static final int DUMMY_MIPS_ID = -1;
+	private static final int DUMMY_CPU_CLOCK_ID = -2;
+	private static final String DATA_FORMAT_VERSION_OLD = "Bappea_V1.24_PEC";
 	
 	
 	private boolean debug = false;
@@ -53,7 +55,7 @@
 	
 	/** produce MIPS graph data */
 	protected boolean mipsEnabled;
-	/** the processor speed to use for MIPS graph calculations */
+	/** the processor speed to use for MIPS graph calculations. Updated from data samples if data is available */
 	protected int processorSpeed;
 	
 	/**
@@ -65,31 +67,32 @@
 		this.allowUserInteraction = allowUserInteraction;
 	}
 
-	private static final Map<Integer, String> eventTypeTable = new HashMap<Integer, String>();
+	private static final Map<Integer, String> EVENT_TYPE_TABLE = new HashMap<Integer, String>();
 	static {
-		eventTypeTable.put(0x0,Messages.PecTraceParser_0);
-		eventTypeTable.put(0x1,Messages.PecTraceParser_1);
-		eventTypeTable.put(0x2,Messages.PecTraceParser_2);
-		eventTypeTable.put(0x3,Messages.PecTraceParser_3);
-		eventTypeTable.put(0x4, Messages.PecTraceParser_4);
-		eventTypeTable.put(0x5, Messages.PecTraceParser_5);
-		eventTypeTable.put(0x6, Messages.PecTraceParser_6);
-		eventTypeTable.put(INSTRUCTIONS_EXECUTED, Messages.PecTraceParser_7);
-		eventTypeTable.put(0x9, Messages.PecTraceParser_8);
-		eventTypeTable.put(0xA, Messages.PecTraceParser_9);
-		eventTypeTable.put(0xB, Messages.PecTraceParser_10);
-		eventTypeTable.put(0xC, Messages.PecTraceParser_11);
-		eventTypeTable.put(0xD, Messages.PecTraceParser_12);
-		eventTypeTable.put(0xF, Messages.PecTraceParser_13);
-		eventTypeTable.put(0x10, Messages.PecTraceParser_14);
-		eventTypeTable.put(0x11, Messages.PecTraceParser_15);
-		eventTypeTable.put(0x12, Messages.PecTraceParser_16);
-		eventTypeTable.put(0x20, Messages.PecTraceParser_17);
-		eventTypeTable.put(0x21, Messages.PecTraceParser_18);
-		eventTypeTable.put(0x22, Messages.PecTraceParser_19);
-		eventTypeTable.put(0xFF, Messages.PecTraceParser_20);
-		eventTypeTable.put(CPU_CLOCK_TICK_DIV64, Messages.PecTraceParser_21);
-		eventTypeTable.put(DUMMY_MIPS_ID, PecTrace.MIPS_NAME);
+		EVENT_TYPE_TABLE.put(0x0,Messages.PecTraceParser_0);
+		EVENT_TYPE_TABLE.put(0x1,Messages.PecTraceParser_1);
+		EVENT_TYPE_TABLE.put(0x2,Messages.PecTraceParser_2);
+		EVENT_TYPE_TABLE.put(0x3,Messages.PecTraceParser_3);
+		EVENT_TYPE_TABLE.put(0x4, Messages.PecTraceParser_4);
+		EVENT_TYPE_TABLE.put(0x5, Messages.PecTraceParser_5);
+		EVENT_TYPE_TABLE.put(0x6, Messages.PecTraceParser_6);
+		EVENT_TYPE_TABLE.put(INSTRUCTIONS_EXECUTED, Messages.PecTraceParser_7);
+		EVENT_TYPE_TABLE.put(0x9, Messages.PecTraceParser_8);
+		EVENT_TYPE_TABLE.put(0xA, Messages.PecTraceParser_9);
+		EVENT_TYPE_TABLE.put(0xB, Messages.PecTraceParser_10);
+		EVENT_TYPE_TABLE.put(0xC, Messages.PecTraceParser_11);
+		EVENT_TYPE_TABLE.put(0xD, Messages.PecTraceParser_12);
+		EVENT_TYPE_TABLE.put(0xF, Messages.PecTraceParser_13);
+		EVENT_TYPE_TABLE.put(0x10, Messages.PecTraceParser_14);
+		EVENT_TYPE_TABLE.put(0x11, Messages.PecTraceParser_15);
+		EVENT_TYPE_TABLE.put(0x12, Messages.PecTraceParser_16);
+		EVENT_TYPE_TABLE.put(0x20, Messages.PecTraceParser_17);
+		EVENT_TYPE_TABLE.put(0x21, Messages.PecTraceParser_18);
+		EVENT_TYPE_TABLE.put(0x22, Messages.PecTraceParser_19);
+		EVENT_TYPE_TABLE.put(0xFF, Messages.PecTraceParser_20);
+		EVENT_TYPE_TABLE.put(CPU_CLOCK_TICK_DIV64, Messages.PecTraceParser_21);
+		EVENT_TYPE_TABLE.put(DUMMY_MIPS_ID, PecTrace.MIPS_NAME);
+		EVENT_TYPE_TABLE.put(DUMMY_CPU_CLOCK_ID, Messages.PecTraceParser_23);
 	}
 				
 	/* (non-Javadoc)
@@ -123,27 +126,52 @@
 			int firstData = dis.readUnsignedByte();
 			int secondData = dis.readUnsignedByte();
 			int thirdData = CPU_CLOCK_TICK_DIV64;
-			
-			if (allowUserInteraction && (firstData == INSTRUCTIONS_EXECUTED || secondData == INSTRUCTIONS_EXECUTED)){
-				Display.getDefault().syncExec( new Runnable() {
+
+			if (this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+				if (allowUserInteraction && (firstData == INSTRUCTIONS_EXECUTED || secondData == INSTRUCTIONS_EXECUTED)){
+					Display.getDefault().syncExec( new Runnable() {
 
-					public void run () {
-						// in future, if we don't want to have a dialog in the core parser class
-						// we could call into an interface which ProcessorSpeedInputDialog would have to implement
-						ProcessorSpeedInputDialog dialog = new ProcessorSpeedInputDialog(
-								PlatformUI.getWorkbench()
-										.getActiveWorkbenchWindow().getShell());
-						if (dialog.open() == Window.OK){
-							processorSpeed = dialog.getIntValue();
-							mipsEnabled = true;
+						public void run () {
+							// in future, if we don't want to have a dialog in the core parser class
+							// we could call into an interface which ProcessorSpeedInputDialog would have to implement
+							ProcessorSpeedInputDialog dialog = new ProcessorSpeedInputDialog(
+									PlatformUI.getWorkbench()
+											.getActiveWorkbenchWindow().getShell());
+							if (dialog.open() == Window.OK){
+								processorSpeed = dialog.getIntValue();
+								mipsEnabled = true;
+							}
 						}
-					}
-				});
-				
-				
+					});
+				}
 			}
+			
+			// >=Bappea_V1.25_PEC
+			else {
+				if (firstData == INSTRUCTIONS_EXECUTED || secondData == INSTRUCTIONS_EXECUTED) {
+					mipsEnabled = true;
+				}
 
-			Integer[] valueTypeVector = new Integer[mipsEnabled ? 4 : 3];
+				long cpuClockRate = readCpuClockRate(dis);
+				if(cpuClockRate > 0){
+					// Hz => MHz
+					trace.setCpuClockRate((int) cpuClockRate / 1000000);
+				}
+			
+			}
+			
+			int graphCount = 0;
+			
+			if (this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+				graphCount = 4;
+			}
+			// >=Bappea_V1.25_PEC
+			else {
+				graphCount = 5;
+			}
+			
+			Integer[] valueTypeVector = new Integer[mipsEnabled ? graphCount : 3];
+			
 			valueTypeVector[0] = Integer.valueOf(firstData);
 			valueTypeVector[1] = Integer.valueOf(secondData);
 			// this type is always the cpu clock tick div 64
@@ -151,6 +179,11 @@
 			
 			if (mipsEnabled){
 				valueTypeVector[3] = DUMMY_MIPS_ID;
+				// >=Bappea_V1.25_PEC
+				if (!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD))
+				{
+					valueTypeVector[4] = DUMMY_CPU_CLOCK_ID;
+				}
 			}
 			
 			trace.setValueTypes(this.parseValueTypes(valueTypeVector));
@@ -171,65 +204,131 @@
 
 	private PecSample readSample(DataInputStream dis,PecSample prevSample) throws IOException
 	{
-		int headerByte = (dis.readByte() << 24) >>> 24;
+		int headerByte = 0;
+		int negBitOffset = 0;
+		int sampleBitOffset = 0;
+		
+		if (this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+			headerByte = (dis.readByte() << 24) >>> 24;
+		}
+		// >=Bappea_V1.25_PEC
+		else {
+			int headerByte1 = (dis.readByte() << 24) >>> 24;
+			int headerByte2 = (dis.readByte() << 24) >>> 24;
+			headerByte = ((headerByte1) | (headerByte2) << 8);
+			negBitOffset = 1;
+			sampleBitOffset = 2;
+		}
+		
 		int neg0 = 0;
 		int neg1 = 0;
 		int neg2 = 0;
+		int neg3 = 0;
 		
 		int prev0 = 0;
 		int prev1 = 0;
 		int prev2 = 0;
+		int prev3 = 0;
 		
 		if(prevSample != null)
 		{
 			prev0 = prevSample.values[0];
 			prev1 = prevSample.values[1];
 			prev2 = prevSample.values[2]/64;
+			prev3 = processorSpeed;
 		}
 		if(debug) if(this.time > 7820 && this.time < 7830) System.out.println("header: "+Long.toHexString(headerByte)+" = "+Integer.toBinaryString(headerByte));  //$NON-NLS-1$//$NON-NLS-2$
 		
-		if( ((headerByte >>> 7)&1) != 0)
+		if( ((headerByte >>> 7 + negBitOffset + sampleBitOffset)&1) != 0)
 		{
 			neg0 = 1;
 		}
 		
-		if( ((headerByte >>> 6)&1) != 0)
+		if( ((headerByte >>> 6 + negBitOffset + sampleBitOffset)&1) != 0)
 		{
 			neg1 = 1;
 		}
 		
-		if( ((headerByte >>> 5)&1) != 0)
+		if( ((headerByte >>> 5 + negBitOffset + sampleBitOffset)&1) != 0)
 		{
 			neg2 = 1;
 		}
 		
-		int len0 = (((headerByte >> 3) << 30) >>> 30)+1;
-		int len1 = (((headerByte >> 1) << 30) >>> 30)+1;
-		int len2 = ((((headerByte) << 31) >>> 31)+1)*2;
+		// >=Bappea_V1.25_PEC
+		if(!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD) && ((headerByte >>> 7)&1) != 0) {
+			neg3 = 1;
+		}
+	
+		int len0 = (((headerByte >> 3 + sampleBitOffset) << 30) >>> 30)+1;
+		int len1 = (((headerByte >> 1 + sampleBitOffset) << 30) >>> 30)+1;
+		int len2 = ((((headerByte >> sampleBitOffset) << 31) >>> 31)+1)*2;
+		int len3 = -1;
+		// >=Bappea_V1.25_PEC
+		if(!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+			len3 = ((((headerByte) << 30) >>> 30)+1);
+		}
 		
-		if(debug) if(this.time > 7820 && this.time < 7830) System.out.println("T:"+this.time+" len0:"+len0+" len1:"+len1+" len2:"+len2); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-		if(debug) if(this.time > 7900 && this.time < 7900) System.out.println("H: "+Integer.toBinaryString(headerByte)+" N0:"+neg0+" N1:"+neg1+" N2:"+neg2);   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
+		if(debug) {
+			if(!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+				if(debug) if(this.time > 7820 && this.time < 7830) System.out.println("T:"+this.time+" len0:"+len0+" len1:"+len1+" len2:"+len2+" len3:"+len3); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+				if(debug) if(this.time > 7900 && this.time < 7900) System.out.println("H: "+Integer.toBinaryString(headerByte)+" N0:"+neg0+" N1:"+neg1+" N2:"+neg2+" N3:"+neg3);   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+
+			} else {
+				if(debug) if(this.time > 7820 && this.time < 7830) System.out.println("T:"+this.time+" len0:"+len0+" len1:"+len1+" len2:"+len2); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+				if(debug) if(this.time > 7900 && this.time < 7900) System.out.println("H: "+Integer.toBinaryString(headerByte)+" N0:"+neg0+" N1:"+neg1+" N2:"+neg2);   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
+			}
+		}
 		
 		long val0 = readVal(neg0,len0,dis);
 		long val1 = readVal(neg1,len1,dis);
 		long val2 = readVal(neg2,len2,dis);
+		long val3 = -1;
 		
-		if(debug) if(this.time > 7820 && this.time < 7900) System.out.println("READ T:"+this.time+"   V0:"+Long.toHexString(val0)+" V1:"+Long.toHexString(val1)+" V2:"+Long.toHexString(val2));   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
+		// >=Bappea_V1.25_PEC
+		if(!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+			if (mipsEnabled) {
+				val3 = readVal(neg3,len3,dis);
+			}
+		}
+		
+		if(debug) {
+			if(!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+				if(this.time > 7820 && this.time < 7900) System.out.println("READ T:"+this.time+"   V0:"+Long.toHexString(val0)+" V1:"+Long.toHexString(val1)+" V2:"+Long.toHexString(val2)+" V3:"+Long.toHexString(val3));   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+			} else {
+				if(this.time > 7820 && this.time < 7900) System.out.println("READ T:"+this.time+"   V0:"+Long.toHexString(val0)+" V1:"+Long.toHexString(val1)+" V2:"+Long.toHexString(val2));   //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$ //$NON-NLS-4$
+			}
+		}	
+		
 		val0 = prev0-val0;
 		val1 = prev1-val1;
 		val2 = prev2-val2;
 		
+		// >=Bappea_V1.25_PEC
+		if(!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+			val3 = prev3-val3;
+			processorSpeed = (int)val3;
+		}
+		
 		int[] values;
-		if (mipsEnabled){
+		if (!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD) && mipsEnabled) {
+			values = new int[]{(int)val0,(int)val1,((int)val2)*64, (int)((val3 / 1000000) * val1 / (val2*64)), ((int)(val3 / 1000000))};
+		} else if (mipsEnabled) {
 			values = new int[]{(int)val0,(int)val1,((int)val2)*64, (int)(processorSpeed * val1 / (val2*64))};
 		} else {
-			values = new int[]{(int)val0,(int)val1,((int)val2)*64};			
+			values = new int[]{(int)val0,(int)val1,((int)val2)*64};
 		}
 		
-		PecSample ps = new PecSample(values, this.time);		
+		PecSample ps = new PecSample(values, this.time);
 		
-		if(debug) if(this.time > 7820 && this.time < 7900) System.out.println("T:"+this.time+"   V0:"+Long.toHexString(val0)+" V1:"+Long.toHexString(val1)+" V2:"+Long.toHexString(val2));  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
-		if(debug) if(this.time > 7820 && this.time < 7900) System.out.println("T:"+this.time+" "+val0+" "+val1+" "+val2);   //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
+		if (debug) {
+			if(!this.traceVersion.equals(DATA_FORMAT_VERSION_OLD)) {
+				if(this.time > 7820 && this.time < 7900) System.out.println("T:"+this.time+"   V0:"+Long.toHexString(val0)+" V1:"+Long.toHexString(val1)+" V2:"+Long.toHexString(val2)+" V3:"+Long.toHexString(val3));  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+				if(this.time > 7820 && this.time < 7900) System.out.println("T:"+this.time+" "+val0+" "+val1+" "+val2+" "+val3);   //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4//$NON-NLS-5$$
+			} else {
+				if(this.time > 7820 && this.time < 7900) System.out.println("T:"+this.time+"   V0:"+Long.toHexString(val0)+" V1:"+Long.toHexString(val1)+" V2:"+Long.toHexString(val2));  //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
+				if(this.time > 7820 && this.time < 7900) System.out.println("T:"+this.time+" "+val0+" "+val1+" "+val2);   //$NON-NLS-1$//$NON-NLS-2$ //$NON-NLS-3$//$NON-NLS-4$
+			}
+		}
 		this.time++;
 		
 		return ps;
@@ -277,7 +376,7 @@
 	}
 	
 	private String convertValueType(int value) {
-		String s = eventTypeTable.get(Integer.valueOf(value));
+		String s = EVENT_TYPE_TABLE.get(Integer.valueOf(value));
 		if (s == null){
 			s = String.format(
 					Messages.PecTraceParser_22,
@@ -286,5 +385,12 @@
 		return s;
 
 	}
-
+	private long readCpuClockRate(DataInputStream dis) throws IOException
+	{	
+		long result = dis.readUnsignedByte();
+		result += dis.readUnsignedByte() << 8;
+		result += dis.readUnsignedByte() << 16;
+		result += dis.readUnsignedByte() << 24;
+		return result;
+	}
 }