sysperfana/perfinvestigator/com.nokia.carbide.cpp.pi.power/src/com/nokia/carbide/cpp/internal/pi/power/actions/PowerStatisticsDialog.java
author Toni Pulkkinen <ext-toni.p.pulkkinen@nokia.com>
Wed, 23 Jun 2010 15:05:09 +0300
changeset 12 ae255c9aa552
parent 5 844b047e260d
permissions -rw-r--r--
Performance Investigator Carbide extension 2.4.0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     1
/*
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     2
 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). 
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     3
 * All rights reserved.
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     8
 *
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
     9
 * Initial Contributors:
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    11
 *
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    12
 * Contributors:
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    13
 *
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    14
 * Description: 
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    15
 *
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    16
 */
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    17
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    18
package com.nokia.carbide.cpp.internal.pi.power.actions;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    19
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    20
import java.text.DecimalFormat;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    21
import java.util.ArrayList;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    22
import java.util.Arrays;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    23
import java.util.Comparator;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    24
import java.util.Hashtable;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    25
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    26
import org.eclipse.swt.SWT;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    27
import org.eclipse.swt.events.SelectionEvent;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    28
import org.eclipse.swt.events.SelectionListener;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    29
import org.eclipse.swt.layout.GridData;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    30
import org.eclipse.swt.layout.GridLayout;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    31
import org.eclipse.swt.widgets.Button;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    32
import org.eclipse.swt.widgets.Composite;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    33
import org.eclipse.swt.widgets.Display;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    34
import org.eclipse.swt.widgets.Group;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    35
import org.eclipse.swt.widgets.Label;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    36
import org.eclipse.swt.widgets.Shell;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    37
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    38
import com.nokia.carbide.cpp.internal.pi.analyser.NpiInstanceRepository;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    39
import com.nokia.carbide.cpp.internal.pi.analyser.ProfileVisualiser;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    40
import com.nokia.carbide.cpp.pi.editors.PIPageEditor;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    41
import com.nokia.carbide.cpp.pi.power.PowerTraceGraph;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    42
import com.nokia.carbide.cpp.pi.power.PwrTrace;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    43
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    44
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    45
public class PowerStatisticsDialog {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    46
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    47
	private Shell shell;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    48
	private GridData gridData;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    49
	private DecimalFormat voltageFormat     = new DecimalFormat(Messages.getString("PowerStatisticsDialog.voltageFormat")); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    50
	private DecimalFormat powerFormat       = new DecimalFormat(Messages.getString("PowerStatisticsDialog.powerFormat")); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    51
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    52
	private PwrTrace trace;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    53
	private double startTime;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    54
	private double endTime;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    55
	
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    56
	private double levelMaxPower;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    57
	private double level90Power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    58
	private double level75Power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    59
	private double level50Power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    60
	private double level25Power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    61
	private double level10Power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    62
	private double levelMinPower;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    63
	private double levelVarPower;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    64
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    65
	public PowerStatisticsDialog(Display display)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    66
	{
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    67
		int batterySize;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    68
		float voltage;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    69
		Group group;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    70
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    71
		shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    72
		shell.setText(Messages.getString("PowerStatisticsDialog.statsTitle")); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    73
		shell.setLayout(new GridLayout(4, false));
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    74
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    75
    	startTime = PIPageEditor.currentPageEditor().getStartTime();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    76
    	endTime   = PIPageEditor.currentPageEditor().getEndTime();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    77
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    78
		trace = (PwrTrace)NpiInstanceRepository.getInstance().activeUidGetTrace("com.nokia.carbide.cpp.pi.power"); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    79
	
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    80
		int uid = NpiInstanceRepository.getInstance().activeUid();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    81
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    82
		PowerTraceGraph graph = trace.getPowerGraph(0, uid); // since they are in lockstep, any graph will do
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    83
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    84
		voltage = trace.getVoltage();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    85
		batterySize = (int) trace.getBatterySize();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    86
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    87
		calculateStats();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    88
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    89
		group = new Group(shell, SWT.SHADOW_NONE);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    90
		group.setText(Messages.getString("PowerStatisticsDialog.interval")); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    91
		group.setFont(PIPageEditor.helvetica_9);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    92
		gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    93
		gridData.horizontalSpan = 4;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    94
		group.setLayoutData(gridData);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    95
		group.setLayout(new GridLayout(4, false));//new FillLayout());
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    96
		textGrid(group, showTimeInterval(startTime, endTime), SWT.CENTER, SWT.CENTER, 4);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    97
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    98
		group = new Group(shell, SWT.NONE);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
    99
		group.setText(Messages.getString("PowerStatisticsDialog.battery")); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   100
		group.setFont(PIPageEditor.helvetica_9);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   101
		gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   102
		gridData.horizontalSpan = 4;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   103
		group.setLayoutData(gridData);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   104
		group.setLayout(new GridLayout(4, false));//new FillLayout());
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   105
		textGrid(group, batterySize + Messages.getString("PowerStatisticsDialog.capacityVoltage2"), SWT.LEFT, SWT.CENTER, 2); //$NON-NLS-1$ //$NON-NLS-2$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   106
		textGrid(group, Messages.getString("PowerStatisticsDialog.capacityVoltage3") + voltageFormat.format(voltage) + Messages.getString("PowerStatisticsDialog.capacityVoltage4"), SWT.RIGHT, SWT.CENTER, 2); //$NON-NLS-1$ //$NON-NLS-2$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   107
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   108
		group = new Group(shell, SWT.NONE);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   109
		group.setText(Messages.getString("PowerStatisticsDialog.currentSelection")); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   110
		group.setFont(PIPageEditor.helvetica_9);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   111
		gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   112
		gridData.horizontalSpan = 4;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   113
		group.setLayoutData(gridData);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   114
		group.setLayout(new GridLayout(4, false));//new FillLayout());
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   115
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   116
		double meanPower;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   117
		double meanEnergy;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   118
		long   meanLife;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   119
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   120
		meanPower  = graph.getAverageConsumption();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   121
		meanEnergy = graph.getCumulativeConsumption();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   122
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   123
		if (meanPower == 0)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   124
			meanLife = 0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   125
		else
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   126
			meanLife = Math.round((float) graph.getBatterySize() * 3600 * graph.getVoltage() / meanPower);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   127
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   128
		textGrid(group, Messages.getString("PowerStatisticsDialog.energy1"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   129
		textGrid(group, (int) (meanEnergy + 0.5)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   130
						+ Messages.getString("PowerStatisticsDialog.energy2"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   131
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   132
		long hours   = meanLife / 3600;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   133
		long minutes = (meanLife - hours * 3600) / 60;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   134
		textGrid(group, Messages.getString("PowerStatisticsDialog.life1"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   135
		textGrid(group, hours + Messages.getString("PowerStatisticsDialog.life2") //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   136
						+ minutes + Messages.getString("PowerStatisticsDialog.life3"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   137
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   138
		textGrid(group, "", SWT.RIGHT, SWT.RIGHT, 4); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   139
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   140
		textGrid(group, Messages.getString("PowerStatisticsDialog.avgPower1"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   141
		textGrid(group, powerFormat.format(meanPower) + Messages.getString("PowerStatisticsDialog.avgPower2"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   142
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   143
		textGrid(group, Messages.getString("PowerStatisticsDialog.maxa"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   144
		textGrid(group, powerFormat.format(levelMaxPower / 1000) + Messages.getString("PowerStatisticsDialog.maxb"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   145
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   146
		textGrid(group, Messages.getString("PowerStatisticsDialog.90a"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   147
		textGrid(group, powerFormat.format(level90Power / 1000) + Messages.getString("PowerStatisticsDialog.90b"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   148
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   149
		textGrid(group, Messages.getString("PowerStatisticsDialog.75a"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   150
		textGrid(group, powerFormat.format(level75Power / 1000) + Messages.getString("PowerStatisticsDialog.75b"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   151
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   152
		textGrid(group, Messages.getString("PowerStatisticsDialog.50a"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   153
		textGrid(group, powerFormat.format(level50Power / 1000) + Messages.getString("PowerStatisticsDialog.50b"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   154
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   155
		textGrid(group, Messages.getString("PowerStatisticsDialog.25a"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   156
		textGrid(group, powerFormat.format(level25Power / 1000) + Messages.getString("PowerStatisticsDialog.25b"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   157
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   158
		textGrid(group, Messages.getString("PowerStatisticsDialog.10a"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   159
		textGrid(group, powerFormat.format(level10Power / 1000) + Messages.getString("PowerStatisticsDialog.10b"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   160
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   161
		textGrid(group, Messages.getString("PowerStatisticsDialog.mina"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   162
		textGrid(group, powerFormat.format(levelMinPower / 1000) + Messages.getString("PowerStatisticsDialog.minb"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   163
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   164
		textGrid(group, Messages.getString("PowerStatisticsDialog.variancea"), SWT.RIGHT, SWT.RIGHT, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   165
		textGrid(group, powerFormat.format(levelVarPower / 1000) + Messages.getString("PowerStatisticsDialog.varianceb"), SWT.CENTER, SWT.CENTER, 2); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   166
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   167
		// create the Close button
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   168
		Button close = new Button(shell, SWT.NONE);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   169
		close.setText(Messages.getString("PowerStatisticsDialog.close")); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   170
		gridData = new GridData(SWT.CENTER, SWT.CENTER, true, true);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   171
		gridData.minimumWidth = 60;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   172
		gridData.horizontalSpan = 4;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   173
		close.setLayoutData(gridData);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   174
		close.addSelectionListener(new SelectionListener(){
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   175
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   176
			public void widgetSelected(SelectionEvent e) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   177
				shell.close();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   178
			}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   179
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   180
			public void widgetDefaultSelected(SelectionEvent e) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   181
				widgetSelected(e);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   182
			}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   183
		});
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   184
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   185
		shell.pack();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   186
		shell.open();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   187
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   188
		while (!shell.isDisposed()) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   189
			if (!shell.getDisplay().readAndDispatch()) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   190
				shell.getDisplay().sleep();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   191
			}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   192
		}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   193
	}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   194
	
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   195
	private void textGrid(Composite parent, String text, int labelStyle, int gridStyle, int gridSpan)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   196
	{
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   197
		Label label = new Label(parent, labelStyle);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   198
		label.setFont(PIPageEditor.helvetica_9);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   199
		label.setText(text);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   200
		gridData = new GridData(SWT.FILL, gridStyle, true, true);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   201
		gridData.horizontalSpan = gridSpan;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   202
		label.setLayoutData(gridData);		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   203
	}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   204
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   205
	public void dispose()
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   206
	{
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   207
		if (this.shell != null) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   208
			if (!this.shell.isDisposed()) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   209
				this.shell.close();				
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   210
			}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   211
			this.shell.dispose();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   212
		}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   213
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   214
		this.shell = null;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   215
	}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   216
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   217
	private static String showTimeInterval(double startTime, double endTime)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   218
	{
5
844b047e260d Performance Investigator Carbide extension 2.3.0
Toni Pulkkinen <ext-toni.p.pulkkinen@nokia.com>
parents: 2
diff changeset
   219
		return ProfileVisualiser.TIME_FORMAT.format(startTime)
844b047e260d Performance Investigator Carbide extension 2.3.0
Toni Pulkkinen <ext-toni.p.pulkkinen@nokia.com>
parents: 2
diff changeset
   220
		     + Messages.getString("PowerStatisticsDialog.interval1") + ProfileVisualiser.TIME_FORMAT.format(endTime) //$NON-NLS-1$
844b047e260d Performance Investigator Carbide extension 2.3.0
Toni Pulkkinen <ext-toni.p.pulkkinen@nokia.com>
parents: 2
diff changeset
   221
		     + Messages.getString("PowerStatisticsDialog.interval2")  + ProfileVisualiser.TIME_FORMAT.format(endTime - startTime) //$NON-NLS-1$
2
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   222
		     + Messages.getString("PowerStatisticsDialog.interval3"); //$NON-NLS-1$
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   223
	}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   224
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   225
	private class PowerStat {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   226
		public double power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   227
		public int count;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   228
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   229
		PowerStat(double power) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   230
			this.power = power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   231
			this.count = 0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   232
		}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   233
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   234
		PowerStat(double power, int count) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   235
			this.power = power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   236
			this.count = count;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   237
		}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   238
	}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   239
	
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   240
	private void calculateStats()
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   241
	{
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   242
		PowerStat powerStat;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   243
		Object[] powerLevelArray;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   244
		ArrayList<PowerStat> powerLevel = new ArrayList<PowerStat>();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   245
		Hashtable<Double,PowerStat> powerStatHash = new Hashtable<Double,PowerStat>();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   246
		double sumOfSquares = 0.0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   247
		double sum = 0.0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   248
		int count = 0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   249
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   250
		int selStart = (int)(this.startTime * 1000 + 0.0005) + 1;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   251
		int selEnd   = (int)(this.endTime * 1000 + 0.0005);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   252
		int totalCount = selEnd - selStart + 1;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   253
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   254
		levelVarPower = 0.0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   255
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   256
		if (selEnd < trace.getFirstSampleNumber() || selStart > selEnd)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   257
		{
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   258
			powerLevelArray = new PowerStat[1];
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   259
			powerLevelArray[0] = new PowerStat(0.0, 1);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   260
			totalCount = 1;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   261
		}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   262
		else
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   263
		{
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   264
			PowerTraceGraph graph = trace.getPowerGraph(0, NpiInstanceRepository.getInstance().activeUid()); // since graphs are in lockstep, any will do
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   265
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   266
			int index = graph.timeIndex(selStart);
12
ae255c9aa552 Performance Investigator Carbide extension 2.4.0
Toni Pulkkinen <ext-toni.p.pulkkinen@nokia.com>
parents: 5
diff changeset
   267
		    if(index == -1){
ae255c9aa552 Performance Investigator Carbide extension 2.4.0
Toni Pulkkinen <ext-toni.p.pulkkinen@nokia.com>
parents: 5
diff changeset
   268
		     	return;
ae255c9aa552 Performance Investigator Carbide extension 2.4.0
Toni Pulkkinen <ext-toni.p.pulkkinen@nokia.com>
parents: 5
diff changeset
   269
		    }
2
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   270
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   271
	        // count time before the first sample as a bunch of zeros
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   272
	        if (selStart < trace.getFirstSampleNumber()) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   273
	        	count = trace.getFirstSampleNumber() - selStart;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   274
				powerStat = new PowerStat(0, count);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   275
				powerLevel.add(powerStat);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   276
				powerStatHash.put(0.0, powerStat);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   277
	        	index = 0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   278
	        }
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   279
	        
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   280
	        int[] sampleTimes = trace.getSampleTimes();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   281
	        int[] ampValues   = trace.getAmpValues();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   282
	        
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   283
			for (int j = index; j < sampleTimes.length; j++)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   284
			{	
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   285
				int time = sampleTimes[j] + 1;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   286
				if (time < selStart)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   287
					time = selStart;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   288
				
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   289
				int nextTime = j == sampleTimes.length - 1 ? Integer.MAX_VALUE : sampleTimes[j + 1];
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   290
				
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   291
				count = Math.min(nextTime - time + 1, selEnd - time + 1);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   292
				double power = ampValues[j] * this.trace.getVoltage() * 1000.0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   293
				sumOfSquares += power * power * count;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   294
				sum += power * count;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   295
				time += count;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   296
				
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   297
				powerStat = powerStatHash.get(power);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   298
				if (powerStat == null) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   299
					powerStat = new PowerStat(power,count);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   300
					powerLevel.add(powerStat);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   301
					powerStatHash.put(power, powerStat);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   302
				} else {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   303
					powerStat.count += count;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   304
				}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   305
				
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   306
				if (time > selEnd)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   307
					break;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   308
			}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   309
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   310
			powerLevelArray = powerLevel.toArray();
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   311
			Arrays.sort(powerLevelArray, new Comparator<Object>() {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   312
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   313
				public int compare(Object o1, Object o2) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   314
					if (!(o1 instanceof PowerStat) || !(o2 instanceof PowerStat))
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   315
						return 0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   316
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   317
					double powerDiff = ((PowerStat)o1).power - ((PowerStat)o2).power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   318
					
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   319
					return powerDiff == 0.0 ? 0	: (powerDiff < 0.0 ? -1 : 1);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   320
				}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   321
			});
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   322
		}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   323
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   324
		levelMaxPower = ((PowerStat) powerLevelArray[powerLevelArray.length - 1]).power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   325
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   326
		level90Power  = getPowerLevel(powerLevelArray, (totalCount * 90) / 100);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   327
		level75Power  = getPowerLevel(powerLevelArray, (totalCount * 75) / 100);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   328
		level50Power  = getPowerLevel(powerLevelArray, (totalCount * 50) / 100);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   329
		level25Power  = getPowerLevel(powerLevelArray, (totalCount * 25) / 100);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   330
		level10Power  = getPowerLevel(powerLevelArray, (totalCount * 10) / 100);
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   331
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   332
		levelMinPower = ((PowerStat) powerLevelArray[0]).power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   333
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   334
		levelVarPower = (sumOfSquares - (sum * sum)/totalCount)/totalCount;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   335
	}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   336
	
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   337
	// given array powerLevelArray of PowerStat elements (each representing PowerStat.count entries), find
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   338
	// power value of entry number index
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   339
	private double getPowerLevel(Object[] powerLevelArray, int index)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   340
	{
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   341
		if (index == 0 || powerLevelArray == null || powerLevelArray.length == 0)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   342
			return 0.0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   343
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   344
		for (int i = 0; (i < powerLevelArray.length) && (powerLevelArray[i] instanceof PowerStat); i++) {
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   345
			PowerStat powerStat = (PowerStat) powerLevelArray[i];
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   346
			if (index <= powerStat.count)
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   347
				return powerStat.power;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   348
			index -= powerStat.count;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   349
		}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   350
		
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   351
		return 0.0;
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   352
	}
b9ab3b238396 Initial version of Performance Investigator under EPL
Matti Laitinen <matti.t.laitinen@nokia.com>
parents:
diff changeset
   353
}