sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi/src/com/nokia/carbide/cpp/internal/pi/model/ProfiledThread.java
changeset 12 ae255c9aa552
parent 5 844b047e260d
equal deleted inserted replaced
11:5b9d4d8641ce 12:ae255c9aa552
    17 
    17 
    18 package com.nokia.carbide.cpp.internal.pi.model;
    18 package com.nokia.carbide.cpp.internal.pi.model;
    19 
    19 
    20 import java.io.Serializable;
    20 import java.io.Serializable;
    21 
    21 
    22 /*
    22 import org.eclipse.core.runtime.Platform;
    23  *
       
    24  * PRI HOMMAT KOMMENTOITU TÄSTÄ FILESTÄ TOISTAISEKSI
       
    25  *
       
    26  */
       
    27 
    23 
    28 public class ProfiledThread extends ProfiledGeneric implements Serializable
    24 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository;
       
    25 import com.nokia.carbide.cpp.pi.PiPlugin;
       
    26 
       
    27 
       
    28 public class ProfiledThread extends ProfiledGeneric implements Serializable, ICPUScaleAdapter
    29 {
    29 {
    30 	private static final long serialVersionUID = 20150633093396772L;
    30 	private static final long serialVersionUID = 20150633093396772L;
    31 
    31 
    32 	private char name; //char symbol of the thread
    32 	private char name; //char symbol of the thread
    33 
    33 
    34 	private int threadId; //thread's real id
    34 	private int threadId; //thread's real id
       
    35 	
       
    36 	private float[] calculatedActivity;
    35  
    37  
    36 	public ProfiledThread(int cpuCount, int graphCount)
    38 	public ProfiledThread(int cpuCount, int graphCount)
    37 	{
    39 	{
    38 		super(cpuCount, graphCount);
    40 		super(cpuCount, graphCount);
    39 	}
    41 	}
    68 
    70 
    69 	public void setThreadId(int threadId) 
    71 	public void setThreadId(int threadId) 
    70 	{
    72 	{
    71 		this.threadId = threadId;
    73 		this.threadId = threadId;
    72 	}
    74 	}
       
    75 
       
    76 	/* (non-Javadoc)
       
    77 	 * @see com.nokia.carbide.cpp.internal.pi.model.ProfiledGeneric#getActivityList()
       
    78 	 */
       
    79 	@Override
       
    80 	public float[] getActivityList() {
       
    81 		float[] activityList = super.getActivityList();
       
    82 	
       
    83 		boolean scaleCPU = isScaledCpu();
       
    84 		if(scaleCPU){
       
    85 			Object object = getAdapter(ICPUScale.class);		
       
    86 			if(object instanceof ICPUScale){		
       
    87 				ICPUScale  cpuScale = (ICPUScale) object;
       
    88 				if(calculatedActivity != null && calculatedActivity.length == activityList.length){
       
    89 					activityList =  calculatedActivity;					
       
    90 				}else{				
       
    91 					int[] sampleList = getSampleList();			
       
    92 					for (int i = 0; i < sampleList.length; i++) {
       
    93 						float value = activityList[i] / 100;
       
    94 						value = value * cpuScale.calculateScale(sampleList[i]) * 100;
       
    95 						activityList[i] = value;				
       
    96 					}
       
    97 					calculatedActivity = activityList;
       
    98 				}	
       
    99 			}
       
   100 		}
       
   101 
       
   102 		return activityList;
       
   103 	}
       
   104 
       
   105 	/*
       
   106 	 * (non-Javadoc)
       
   107 	 * @see org.eclipse.core.runtime.IAdaptable#getAdapter(java.lang.Class)
       
   108 	 */
       
   109 	@SuppressWarnings("unchecked")
       
   110 	public Object getAdapter(Class adapter) {
       
   111 		if(adapter == null){
       
   112 			return null;
       
   113 		}
       
   114 		return Platform.getAdapterManager().loadAdapter(this, adapter.getName());
       
   115 	}
       
   116 	
       
   117 	/**
       
   118 	 * Check are threads scaled or not
       
   119 	 * 
       
   120 	 * @return
       
   121 	 */
       
   122 	public boolean isScaledCpu(){
       
   123 		boolean scaleCPU = false;
       
   124 
       
   125 		Object obj = NpiInstanceRepository.getInstance().activeUidGetPersistState(
       
   126 				PiPlugin.ACTION_SCALE_CPU);
       
   127 		if ((obj != null) && (obj instanceof Boolean)){
       
   128 			// retrieve the current value
       
   129 			scaleCPU = (Boolean) obj;
       
   130 		}else{
       
   131 			// set the initial value
       
   132 			NpiInstanceRepository.getInstance().activeUidSetPersistState(
       
   133 					PiPlugin.ACTION_SCALE_CPU, scaleCPU);
       
   134 		}
       
   135 		return scaleCPU;
       
   136 	}
    73 }
   137 }