[battery-stats] Modified battery stats to remove expired logs more often 95/114595/1 accepted/tizen/3.0/common/20170215.121215 accepted/tizen/3.0/ivi/20170215.034340 accepted/tizen/3.0/mobile/20170215.034217 accepted/tizen/3.0/wearable/20170215.034327 submit/tizen_3.0/20170214.105858
authorSomin Kim <somin926.kim@samsung.com>
Tue, 14 Feb 2017 06:33:50 +0000 (15:33 +0900)
committerSomin Kim <somin926.kim@samsung.com>
Tue, 14 Feb 2017 06:33:50 +0000 (15:33 +0900)
Change-Id: Ib94c46e4d66e522f8a328c0fd8528bf31526f9b4
Signed-off-by: Somin Kim <somin926.kim@samsung.com>
src/battery-stats/BatteryMonitor.cpp
src/battery-stats/BatteryMonitor.h

index 1cc12bf..5d698af 100644 (file)
@@ -26,7 +26,6 @@
 
 #define DEFAULT_ROW_ID_STR "1"
 #define HEART_DB_QUERY_INTERVAL 10 * 60 * 1000
-#define ONE_DAY_IN_SEC 86400
 #define DEFAULT_TIME_DIFF      600
 #define TIME_DIFF_THRESHOLD    300
 
@@ -286,7 +285,6 @@ bool BatteryMonitor::__processBatteryUsage()
        ret = __updateLastCpuUsageLog(lastHeartCpuLog);
        IF_FAIL_RETURN_TAG(ret, false, _E, "Failed to update last cpu log");
 
-       __removeExpiredLog();
        __needSync = false;
 
        return true;
@@ -321,26 +319,15 @@ bool BatteryMonitor::__insertBatteryUsageLog(std::vector<Json>& usage)
        }
        query = query.substr(0, query.size() - 2);
 
+       // Remove expired log
+       query += "; DELETE FROM " + std::string(BATTERY_USAGE_TABLE)
+                       + " WHERE EndTime < " + std::to_string(CURRENT_TIME - LOG_RETENTION_PERIOD)
+                       + " OR EndTime > " + std::to_string(CURRENT_TIME) + ";";
+
        _D("Insert %d rows of per app battery usage", usage.size());
        return __dbMgr.executeSync(query.c_str(), NULL);
 }
 
-void BatteryMonitor::__removeExpiredLog()
-{
-       static int lastCleanupTime = 0;
-
-       int currentTime = CURRENT_TIME;
-       IF_FAIL_VOID(currentTime - lastCleanupTime >= ONE_DAY_IN_SEC);
-       lastCleanupTime = currentTime;
-
-       char *sql = sqlite3_mprintf(
-                       "DELETE FROM " BATTERY_USAGE_TABLE " WHERE EndTime < %d OR EndTime > %d",
-                       CURRENT_TIME - LOG_RETENTION_PERIOD, CURRENT_TIME);
-       __dbMgr.execute(0, sql, NULL);
-       sqlite3_free(sql);
-       _D("Remove expired log");
-}
-
 bool BatteryMonitor::__updateLastCpuUsageLog(CpuUsageMap& usage)
 {
        _D("Delete all rows from last cpu usage table");
index bb6092a..af8cbd3 100644 (file)
@@ -47,7 +47,6 @@ namespace ctx {
                bool __insertBatteryUsageLog(std::vector<Json>& usage);
                bool __updateLastCpuUsageLog(CpuUsageMap& usage);
                bool __getLastCpuUsageTable(CpuUsageMap* lastCpuUsage);
-               void __removeExpiredLog();
                void __modifyLastCpuUsage(int timeDiff);
 
                static void __chargerChangeCb(device_callback_e type, void* value, void* userData);