Dump the start/end time of usage collection time
[platform/core/system/batterymonitor.git] / src / bm_power_engine.c
index 8b820c0..e6acbbd 100644 (file)
@@ -40,6 +40,27 @@ int battery_capacity = 500;
 int gtimeo_id[2];
 static int data_collection_period = 600000;
 
+static struct timeval last_plugin_request_time;
+static struct timeval cur_plugin_request_time;
+
+void bm_update_plugin_request_time(void)
+{
+       ENTER;
+
+       if (!memcpy(&last_plugin_request_time, &cur_plugin_request_time, sizeof(struct timeval))) {
+               _ERR("memcpy failed");
+               return;
+       }
+
+       if (gettimeofday(&cur_plugin_request_time, NULL) != 0) {
+               _ERR("gettimeofday failed : %m");
+               return;
+       }
+
+       EXIT;
+       return;
+}
+
 int bm_engine_get_mah_usage_by_app_id_for_resource_id_ci(const gchar* app_id, gint resource_id, gint64 start_time, gint64 end_time, double *battery_usage)
 {
        ENTER;
@@ -593,6 +614,8 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
                history_item_s hi;
                bd_print_history_item_reset(&hi);
 
+               hi.time_current = (long long)last_plugin_request_time.tv_sec;
+
                hi.cmd_s = CM_USAGE;
                hi.usage_type = USAGE_BLUETOOTH;
                hi.usage = (RX_system + TX_system + RX_app + TX_app) / ((double)data_collection_period / 60000);        // bytes / minute
@@ -809,6 +832,8 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
                history_item_s hi;
                bd_print_history_item_reset(&hi);
 
+               hi.time_current = (long long)last_plugin_request_time.tv_sec;
+
                hi.cmd_s = CM_USAGE;
                hi.usage_type = USAGE_WIFI;
                hi.usage = (RX + TX) / ((double)data_collection_period / 60000);        // bytes / minute
@@ -1665,6 +1690,8 @@ int bm_start_getting_feature_data(void)
                }
        }
 
+       bm_update_plugin_request_time();
+
        /* request data from each plugin & store its handle */
 #ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
        for (id = BM_PLUGIN_ID_BLE; id < BM_PLUGIN_ID_MAX; ++id) {
@@ -2072,6 +2099,8 @@ int initialize_power_engine(void)
                _ERR("unable ro read battery capacity");
        battery_capacity *= cmah; //Battery Capacity in mAs
 
+       bm_update_plugin_request_time();
+
        EXIT;
        return ret_val;
 }