SRADA-1014: Fixed unneeded division by cores number for CPU load values.
authorMaria Guseva <m.guseva@samsung.com>
Thu, 11 Aug 2016 10:40:38 +0000 (13:40 +0300)
committerMaria Guseva <m.guseva@samsung.com>
Thu, 11 Aug 2016 13:08:21 +0000 (22:08 +0900)
* SystemData.getTotalCPULoad() - fixed to return scaled CPU load in range 0-100.
* CPUChart.inputChartSeries() - fixed calculation of appLoadSeries data:
removed unneeded division by cores number.
* Comments added/updated to specify CPU load value range.

Change-Id: Ie939e1b14899a9215a25b7a1e99467894742dada

org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/data/ProcessProfileData.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/swap/model/data/SystemData.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/SystemDataDBTable.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/TargetProcessDBTable.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/chart/CPUChart.java
org.tizen.dynamicanalyzer/src/org/tizen/dynamicanalyzer/ui/timeline/common/TimelineDataManager.java

index 7ba7c7b..8580252 100644 (file)
@@ -28,7 +28,7 @@ package org.tizen.dynamicanalyzer.swap.model.data;
 
 public class ProcessProfileData {
        private int pid; // protocol 3.0
-       private float processLoad; // protocol 3.0
+       private float processLoad; // protocol 3.0, in range [0-100]%
        private long virtualMemory; // protocol 3.0
        private long residentMemory; // protocol 3.0
        private long sharedMemory; // protocol 3.0
index 549330f..723466d 100644 (file)
@@ -54,7 +54,7 @@ public class SystemData extends LogData {
        }
 
        double[] cpuFrequency = null; // protocol 3.0
-       double[] cpuLoad = null; // protocol 3.0
+       double[] cpuLoad = null; // protocol 3.0 , in range [0-100]%
        long systemMemoryUsed = 0; // protocol 3.0
        int targetProcessCount = 0; // protocol 3.0
        ProcessProfileData[] processProfileDataList = null; // protocol 3.0
@@ -486,23 +486,34 @@ public class SystemData extends LogData {
                this.otherProcessLoad = otherProcessLoad;
        }
 
+       /**
+        * Get total system CPU load value.
+        * @return percentage of CPU load, scaled by number of CPU cores to be in range [0-100]%
+        */
        public double getTotalCPULoad() {
                if (cpuLoad == null) {
                        return 0.0;
                }
+
+               // Calculate CPU load based on each core load information
                double totalCPULoad = 0.0;
                for (int i = 0; i < cpuLoad.length; i++) {
                        totalCPULoad += cpuLoad[i];
                }
+               // Each core CPU load is in range 0-100%, so the sum should be scaled by CPU number
+               totalCPULoad /= cpuLoad.length;
+
+               // Calculate CPU load based on each process load information
                double processCPULoad = getProcessCPULoad();
+
+               /*
+                * Revise "total cpu load" to prevent "total load" from being shown less than
+                * "process load". This problem occurs because time gap of calculating "total load"
+                * and "process load".
+                */
                if (totalCPULoad < processCPULoad) {
                        Logger.warning("totalCPULoad [" + totalCPULoad + "] is less than processCPULoad [ + "
                                        + processCPULoad + "].");
-                       /*
-                        * Revise "total cpu load" to prevent "total load" from being shown less than
-                        * "process load". This problem is occurs because time gap of calculating "total load"
-                        * and "process load".
-                        */
                        totalCPULoad = processCPULoad;
                }
                return totalCPULoad;
index d1f2489..5d5a042 100644 (file)
@@ -37,11 +37,16 @@ import org.tizen.dynamicanalyzer.database.DBConstants;
 import org.tizen.dynamicanalyzer.database.DBTable;
 import org.tizen.dynamicanalyzer.util.Logger;
 
+/**
+ * DB table representing the system information summarized for all running
+ * processes.
+ */
 public class SystemDataDBTable extends DBTable {
        private static final String TABLENAME = "TIMELINE_SYSTEM_DATA";
 
        public static enum COLUMN {
                SAMPLING_TIME,
+               // CPU load in %, scaled by number of CPU cores to be in range [0-100]%
                CPU_LOAD_TOTAL,
                PROCESS_COUNT_OTHER,
                PROCESS_COUNT_TARGET,
index 354cfa4..d92d387 100644 (file)
@@ -37,12 +37,17 @@ import org.tizen.dynamicanalyzer.database.DBConstants;
 import org.tizen.dynamicanalyzer.database.DBTable;
 import org.tizen.dynamicanalyzer.util.Logger;
 
+/**
+ * DB table representing system information for a process of traced application
+ * (aka "target process")
+ */
 public class TargetProcessDBTable extends DBTable {
        private static final String TABLENAME = "TIMELINE_TARGET_PROCESS";
 
        public static enum COLUMN {
                SAMPLING_TIME,
                PID,
+               // CPU load in %, scaled by number of CPU cores to be in range [0-100]%
                CPU_LOAD,
                MEMORY_VIRTUAL,
                MEMORY_RESIDENT,
index 40c9683..f2b82fd 100755 (executable)
@@ -61,7 +61,17 @@ import org.tizen.dynamicanalyzer.widgets.chartBoard.DAChartBoardItem;
 import org.tizen.dynamicanalyzer.widgets.popupMenu.DAPopupMenu;
 
 public class CPUChart extends TimelineChart {
+       /**
+        * For each time moment this series presents
+        * the summary CPU load(%) for all processes of traced application.
+        * The CPU load is scaled by number of CPU cores to be in range [0-100]%
+        */
        private DAChartSeries appLoadSeries;
+       /**
+        * For each time moment this series presents
+        * the summary CPU load(%) for all processes in system.
+        * The CPU load is scaled by number of CPU cores to be in range [0-100]%
+        */
        private DAChartSeries totalLoadSeries;
 
        private DAChartBoard chartBoard = null;
@@ -187,6 +197,7 @@ public class CPUChart extends TimelineChart {
                                        / TimelineConstants.MEGA_DOUBLE;
 
                        try {
+                               // systemAvgLoad is already scaled by number of CPU cores to be in range [0-100]%
                                double systemAvgLoad = (Float) row.get(SystemDataDBTable.COLUMN.CPU_LOAD_TOTAL
                                                .ordinal());
                                totalLoadSeries.addSeriesItem(new DAChartSeriesItem(time, systemAvgLoad, Formatter
@@ -235,6 +246,7 @@ public class CPUChart extends TimelineChart {
                        for (int i = 0; i < data.size(); i++) {
                                List<Object> oneTime = data.get(i);
                                Long time = (Long) oneTime.get(TargetProcessDBTable.COLUMN.SAMPLING_TIME.ordinal());
+                               // cpuLoad is already scaled by number of CPU cores to be in range [0-100]%
                                Float cpuLoad = (Float) oneTime.get(TargetProcessDBTable.COLUMN.CPU_LOAD.ordinal());
                                Float processLoadSum = processLoadSumMap.get(time);
                                if (processLoadSum == null) {
@@ -251,10 +263,10 @@ public class CPUChart extends TimelineChart {
                Iterator<Long> iterProcessLoadSum = timeSortedLoadList.iterator();
                while (iterProcessLoadSum.hasNext()) {
                        Long time = iterProcessLoadSum.next();
+                       // cpuLoadSum is already scaled by number of CPU cores to be in range [0-100]%
                        Float cpuLoadSum = processLoadSumMap.get(time);
-                       double cpuAvgLoad = cpuLoadSum / coreSize;
                        appLoadSeries.addSeriesItem(new DAChartSeriesItem(time / TimelineConstants.MEGA_DOUBLE,
-                                       cpuAvgLoad, Formatter.toPercentageFormat(cpuAvgLoad)));
+                                       cpuLoadSum.doubleValue(), Formatter.toPercentageFormat(cpuLoadSum.doubleValue())));
                }
 
                if (prevChildSize != childSeriesMap.size()) {
index d4bd64c..4308de7 100644 (file)
@@ -200,7 +200,8 @@ public class TimelineDataManager extends PageDataManager {
                                /*
                                 * Make SystemData Table data
                                 */
-                               double systemAvgCPULoad = log.getTotalCPULoad() / coreSize;
+                               // systemAvgCPULoad is already scaled by number of CPU cores to be in range [0-100]%
+                               double systemAvgCPULoad = log.getTotalCPULoad();
                                ArrayList<Object> dbSystemData = new ArrayList<Object>();
                                dbSystemData.add(new Long(log.getTime()));
                                dbSystemData.add(new Float(systemAvgCPULoad));