From: Kunal Date: Fri, 9 Dec 2016 08:14:00 +0000 (+0900) Subject: Fixed to compare pid, instead of using cpu time difference, when an app is re-launced. X-Git-Tag: submit/tizen_3.0/20161219.115913^2~5 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=9f42eed73a9907361c8a9bc179cda6978763b108;p=platform%2Fcore%2Fcontext%2Fcontext-provider.git Fixed to compare pid, instead of using cpu time difference, when an app is re-launced. Change-Id: Ib2c72bd5634d2555ccdf517985c6711e4818325c Signed-off-by: Kunal --- diff --git a/src/battery-stats/BatteryMonitor.cpp b/src/battery-stats/BatteryMonitor.cpp index 7098c9f..6e1687e 100644 --- a/src/battery-stats/BatteryMonitor.cpp +++ b/src/battery-stats/BatteryMonitor.cpp @@ -224,18 +224,21 @@ bool BatteryMonitor::__getLastCpuUsageTable(CpuUsageMap* lastCpuUsage) int timestamp; int stime; int utime; + int pid; while (k < lastCpuUsageLog.size()) { lastCpuUsageLog[k].get(NULL, BATTERY_APP_ID, &appId); lastCpuUsageLog[k].get(NULL, BATTERY_TIMESTAMP, ×tamp); lastCpuUsageLog[k].get(NULL, BATTERY_UTIME, &utime); lastCpuUsageLog[k].get(NULL, BATTERY_STIME, &stime); + lastCpuUsageLog[k].get(NULL, BATTERY_PID, &pid); k++; LastAppCpuUsageInfo lastAppCpuUsage; lastAppCpuUsage.timestamp = timestamp; lastAppCpuUsage.utime = utime; lastAppCpuUsage.stime = stime; + lastAppCpuUsage.pid = pid; (*lastCpuUsage)[appId] = lastAppCpuUsage; } return true; @@ -361,10 +364,10 @@ bool BatteryMonitor::__insertLastCpuUsageLog(CpuUsageMap& usage) _D("Delete all rows from app last times table"); __dbMgr.executeSync("DELETE FROM " BATTERY_LAST_CPU_USAGE_TABLE, NULL); - std::string query("INSERT INTO " BATTERY_LAST_CPU_USAGE_TABLE "(" BATTERY_APP_ID ", " BATTERY_UTIME ", " BATTERY_STIME "," BATTERY_TIMESTAMP ") VALUES"); + std::string query("INSERT INTO " BATTERY_LAST_CPU_USAGE_TABLE "(" BATTERY_APP_ID ", " BATTERY_UTIME ", " BATTERY_STIME ", " BATTERY_TIMESTAMP ", " BATTERY_PID ") VALUES"); std::string appId; - int stime, utime; + int stime, utime, pid; int timestamp; for (auto it = usage.begin(); it != usage.end(); it++) { @@ -372,11 +375,13 @@ bool BatteryMonitor::__insertLastCpuUsageLog(CpuUsageMap& usage) timestamp = (it->second).timestamp; utime = (it->second).utime; stime = (it->second).stime; + pid = (it->second).pid; query += " ('" + appId + "', " + std::to_string(utime) + ", " + std::to_string(stime) - + ", " + std::to_string(timestamp) + ")"; + + ", " + std::to_string(timestamp) + + ", " + std::to_string(pid) + ")"; query += ", "; } diff --git a/src/battery-stats/BatteryStatisticsTypes.h b/src/battery-stats/BatteryStatisticsTypes.h index d22faa7..31622bc 100644 --- a/src/battery-stats/BatteryStatisticsTypes.h +++ b/src/battery-stats/BatteryStatisticsTypes.h @@ -44,7 +44,7 @@ #define BATTERY_LAST_CPU_USAGE_TABLE "Temp_LastCpuUsagePerApp" #define BATTERY_LAST_CPU_USAGE_TABLE_COLUMNS \ "AppId TEXT PRIMARY KEY, Utime INTEGER NOT NULL DEFAULT 0, " \ - "Stime INTEGER NOT NULL DEFAULT 0, Timestamp INTEGER NOT NULL DEFAULT 0" + "Stime INTEGER NOT NULL DEFAULT 0, Timestamp INTEGER NOT NULL DEFAULT 0, Pid INTEGER NOT NULL DEFAULT 0" #define BATTERY_APP_ID "AppId" #define BATTERY_INDEX "idx" @@ -61,6 +61,7 @@ #define BATTERY_LAST_PERCENT_TIME "LastPercentTime" #define BATTERY_LAST_HEART_TIMESTAMP "LastHeartTimestamp" #define BATTERY_ROW_ID "RowId" +#define BATTERY_PID "Pid" #define CURRENT_TIME (int)(time(0)) @@ -70,6 +71,7 @@ namespace ctx { int timestamp; int utime; int stime; + int pid; }; typedef std::map CpuUsageMap; } diff --git a/src/battery-stats/BatteryUsageAnalyzer.cpp b/src/battery-stats/BatteryUsageAnalyzer.cpp index 66dd430..9a01f02 100644 --- a/src/battery-stats/BatteryUsageAnalyzer.cpp +++ b/src/battery-stats/BatteryUsageAnalyzer.cpp @@ -48,6 +48,7 @@ bool BatteryUsageAnalyzer::calculateBatteryUsage(int lastTime, int currTime, std int stime; int utime; int idx; + int pid; int totalUtime = 0; int totalStime = 0; @@ -57,6 +58,7 @@ bool BatteryUsageAnalyzer::calculateBatteryUsage(int lastTime, int currTime, std cpuUsageLog[i].get(NULL, BATTERY_UTIME, &utime); cpuUsageLog[i].get(NULL, BATTERY_STIME, &stime); cpuUsageLog[i].get(NULL, BATTERY_INDEX, &idx); + cpuUsageLog[i].get(NULL, BATTERY_PID, &pid); if (timestamp < lastTime) { continue; @@ -75,14 +77,16 @@ bool BatteryUsageAnalyzer::calculateBatteryUsage(int lastTime, int currTime, std int prevUtime = 0; int prevStime = 0; int prevTimestamp = 0; + int prevPid = 0; if (lastAppCpuUsage != lastCpuUsage.end()) { prevTimestamp = (lastAppCpuUsage->second).timestamp; prevUtime = (lastAppCpuUsage->second).utime; prevStime = (lastAppCpuUsage->second).stime; + prevPid = (lastAppCpuUsage->second).pid; // If the app is killed and launched again - if (prevStime > stime || prevUtime > utime) { + if (pid != prevPid) { prevUtime = 0; prevStime = 0; prevTimestamp = lastTime; @@ -118,6 +122,7 @@ bool BatteryUsageAnalyzer::calculateBatteryUsage(int lastTime, int currTime, std lastAppUsage.timestamp = timestamp; lastAppUsage.utime = utime; lastAppUsage.stime = stime; + lastAppUsage.pid = pid; lastCpuUsage[appId] = lastAppUsage; } __normalizeBatteryUsage(usage, totalUtime, totalStime); diff --git a/src/battery-stats/HeartDbReader.cpp b/src/battery-stats/HeartDbReader.cpp index 456d0d5..b19a5a0 100644 --- a/src/battery-stats/HeartDbReader.cpp +++ b/src/battery-stats/HeartDbReader.cpp @@ -132,4 +132,5 @@ void HeartDbReader::__convertCpuUsageLog(Json& row, Json* newRow) newRow->set(NULL, BATTERY_STIME, stime); newRow->set(NULL, BATTERY_TYPE, type); newRow->set(NULL, BATTERY_INDEX, index); + newRow->set(NULL, BATTERY_PID, pid); }