sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.power/src/com/nokia/carbide/cpp/pi/power/PwrTrace.java
changeset 12 ae255c9aa552
parent 2 b9ab3b238396
--- a/sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.power/src/com/nokia/carbide/cpp/pi/power/PwrTrace.java	Wed Jun 23 14:49:59 2010 +0300
+++ b/sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.power/src/com/nokia/carbide/cpp/pi/power/PwrTrace.java	Wed Jun 23 15:05:09 2010 +0300
@@ -18,6 +18,8 @@
 package com.nokia.carbide.cpp.pi.power;
 
 import java.util.ArrayList;
+import java.util.Map;
+import java.util.TreeMap;
 
 import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository;
 import com.nokia.carbide.cpp.internal.pi.model.GenericSampledTrace;
@@ -33,6 +35,7 @@
 	transient private boolean complete = false;
 	transient private ArrayList<PwrSample> powerChangePoints;	// times when power samples change
 	transient private long maxEndTime;
+	transient private TreeMap<Long, Integer> backlightChangePoints;
 	
     private float voltage = 3.7f;
 	
@@ -45,7 +48,8 @@
 	private double min = 0.0;
 	private double max = 0.0;
 	private double synchValue = 0.0;
-	
+	private boolean backlightEnabled;	 
+	 
 	transient private int[] sampleTimes;
     transient private int[] ampValues;
     transient private int[] voltValues;
@@ -53,6 +57,7 @@
     transient private double maxAmps = Double.MIN_VALUE;
 	transient private double minAmps = Double.MAX_VALUE;
 	transient private double maxPower = 0.0;
+	
 
     public GenericTraceGraph getTraceGraph(int graphIndex, int uid)
 	{		
@@ -197,12 +202,19 @@
 	public void initData()
 	{
 		ArrayList<PwrSample> powerChangePoints = new ArrayList<PwrSample>();
+		if(backlightEnabled){
+			backlightChangePoints = new TreeMap<Long, Integer>();
+		}
 		PwrSample sample = (PwrSample) this.samples.get(0);
 			
 		long   currentTime     = sample.sampleSynchTime;
 		double currentCurrent  = sample.current;
 		double currentVoltage  = sample.voltage;
 		double currentCapacity = sample.capacity;
+		int currentBacklight = sample.backlight;
+		if(backlightEnabled){
+			backlightChangePoints.put(currentTime, currentBacklight);
+		}
 				
 		for (int i = 1; i < this.samples.size(); i++) {
 			sample = (PwrSample) this.samples.get(i);
@@ -216,13 +228,22 @@
 				currentVoltage  = sample.voltage;
 				currentCapacity = sample.capacity;
 			}
+			if(backlightEnabled){
+				if(sample.backlight != currentBacklight){
+					backlightChangePoints.put(sample.sampleSynchTime, sample.backlight);
+					currentBacklight = sample.backlight;
+				}
+			}
+		
 		}
 		
-		sample = powerChangePoints.get(powerChangePoints.size() - 1);
-		if (   sample.current  != currentCurrent
-			|| sample.voltage  != currentVoltage
-			|| sample.capacity != currentCapacity) {
-			powerChangePoints.add(new PwrSample(currentTime, currentCurrent, currentVoltage, currentCapacity));
+		if(powerChangePoints.size() > 0){
+			sample = powerChangePoints.get(powerChangePoints.size() - 1);
+			if (   sample.current  != currentCurrent
+				|| sample.voltage  != currentVoltage
+				|| sample.capacity != currentCapacity) {
+				powerChangePoints.add(new PwrSample(currentTime, currentCurrent, currentVoltage, currentCapacity));
+			}	
 		}
 
 		this.powerChangePoints = powerChangePoints;
@@ -319,4 +340,18 @@
   	public boolean isComplete() {
   		return this.complete;
   	}
+  	
+  	public boolean isBacklightEnabled(){
+  		//TODO remove this for enabling backlight visualization
+  		return false;
+  		//return backlightEnabled;
+  	}
+  	
+	public void setBacklightEnabled(boolean backlightEnabled){
+  		this.backlightEnabled = backlightEnabled;
+  	}
+	
+	public Map<Long, Integer> getBacklightChangePoints(){
+		return backlightChangePoints;
+	}
 }