sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.instr/src/com/nokia/carbide/cpp/pi/instr/IttSample.java
changeset 2 b9ab3b238396
child 5 844b047e260d
equal deleted inserted replaced
1:1050670c6980 2:b9ab3b238396
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of the License "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: 
       
    15  *
       
    16  */
       
    17 
       
    18 package com.nokia.carbide.cpp.pi.instr;
       
    19 
       
    20 import com.nokia.carbide.cpp.internal.pi.model.Binary;
       
    21 import com.nokia.carbide.cpp.internal.pi.model.Function;
       
    22 import com.nokia.carbide.cpp.internal.pi.model.FunctionResolver;
       
    23 import com.nokia.carbide.cpp.internal.pi.model.GenericSampleWithFunctions;
       
    24 
       
    25 
       
    26 public class IttSample extends GenericSampleWithFunctions
       
    27 {
       
    28   private static final long serialVersionUID = 31446918621985951L;
       
    29 	
       
    30   public long[] instructions;
       
    31   public long checksum;
       
    32   public long programCounter;
       
    33 
       
    34   public Function currentFunctionItt;
       
    35   public Binary currentBinaryItt;
       
    36   public Function currentFunctionSym;
       
    37   public Binary currentBinarySym;
       
    38   
       
    39   public IttSample(int size)
       
    40   {
       
    41     instructions = new long[size];
       
    42     sampleSynchTime = 0;
       
    43   }
       
    44 
       
    45   public long[] reversedInstructions()
       
    46   {
       
    47     long[] revs = new long[instructions.length];
       
    48     for (int i=0;i<instructions.length;i++)
       
    49     {
       
    50       revs[i] |= (((instructions[i] & 0x000000ff) << 24) & 0xff000000);
       
    51       revs[i] |= (((instructions[i] & 0x0000ff00) << 8) & 0x00ff0000);
       
    52       revs[i] |= (((instructions[i] & 0x00ff0000) >> 8) & 0x0000ff00);
       
    53       revs[i] |= (((instructions[i] & 0xff000000) >> 24) & 0x000000ff);
       
    54 
       
    55       //System.out.print("\nOriginal "+Integer.toHexString((int)instructions[i]));
       
    56 
       
    57       String temp = Long.toHexString(revs[i]);
       
    58       String nulls = ""; //$NON-NLS-1$
       
    59       for (int n=0;n<8-temp.length();n++) nulls=nulls+"0"; //$NON-NLS-1$
       
    60       temp = nulls+temp;
       
    61       //System.out.println(" reversed "+temp);
       
    62     }
       
    63     return revs;
       
    64   }
       
    65 
       
    66   public void resolveFunction(FunctionResolver res)
       
    67   {
       
    68   	if (res.getResolverName().equals("Symbol"))  //$NON-NLS-1$
       
    69   	{
       
    70   		this.currentFunctionSym = res.findFunctionForAddress(programCounter);
       
    71   		
       
    72   		if (this.currentFunctionSym != null)
       
    73   			this.currentBinarySym = this.currentFunctionSym.functionBinary;
       
    74   	}
       
    75   	else if (res.getResolverName().equals("ITT"))  //$NON-NLS-1$
       
    76   	{
       
    77   		if (currentFunctionSym == null) {
       
    78 	  		this.currentFunctionItt = res.findFunctionForAddress(programCounter);
       
    79 	  		
       
    80 	  		if (this.currentFunctionItt != null)
       
    81 	  			this.currentBinaryItt = this.currentFunctionItt.functionBinary;
       
    82   		}
       
    83   	}
       
    84   }
       
    85    
       
    86   public String toReversedString()
       
    87   {
       
    88     String s = ""; //$NON-NLS-1$
       
    89     long[] revs = this.reversedInstructions();
       
    90     
       
    91     for (int i=0;i<instructions.length;i++)
       
    92     {
       
    93       String nulls = ""; //$NON-NLS-1$
       
    94       String temp = ""; //$NON-NLS-1$
       
    95       temp = Integer.toHexString((int)revs[i]);
       
    96       for (int t = 0;t<(8-temp.length());t++) nulls = nulls+"0"; //$NON-NLS-1$
       
    97       s = s+(nulls+temp+Messages.getString("IttSample.space")); //$NON-NLS-1$
       
    98     }
       
    99     return s;
       
   100   }
       
   101   
       
   102   public String toString()
       
   103   {
       
   104   	long diff = 0;
       
   105   	
       
   106   	if (this.currentBinaryItt != null && this.currentBinarySym != null)
       
   107   		diff = this.currentBinaryItt.startAddress+this.currentBinaryItt.offsetToCodeStart-
       
   108 			   this.currentBinarySym.startAddress;
       
   109   	else
       
   110   	{
       
   111   		System.out.println("NULL"); //$NON-NLS-1$
       
   112   	}
       
   113   	
       
   114   	String result = "Itt:#"+this.sampleSynchTime+ //$NON-NLS-1$
       
   115 			" @0x"+Long.toHexString(this.programCounter)+ //$NON-NLS-1$
       
   116 			" fS:"+this.currentFunctionSym.functionName+ //$NON-NLS-1$
       
   117 			" oS:"+Long.toHexString(this.currentFunctionSym.startAddress.longValue())+" +"+(this.programCounter-this.currentFunctionSym.startAddress.longValue())+ //$NON-NLS-1$ //$NON-NLS-2$
       
   118 			" fI:"+this.currentFunctionItt.functionName+ //$NON-NLS-1$
       
   119 			" oI:"+Long.toHexString(this.currentFunctionItt.startAddress.longValue())+" +"+(this.programCounter-this.currentFunctionItt.startAddress.longValue()); //$NON-NLS-1$ //$NON-NLS-2$
       
   120   	
       
   121   	if (diff != 0) result=" DIFF: "+diff+" "+result; //$NON-NLS-1$ //$NON-NLS-2$
       
   122   	
       
   123   	return result;
       
   124   }
       
   125 
       
   126   
       
   127 }