Dump the start/end time of usage collection time 26/235326/1
authorKichan Kwon <k_c.kwon@samsung.com>
Tue, 19 May 2020 08:11:10 +0000 (17:11 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 4 Jun 2020 01:35:32 +0000 (10:35 +0900)
- Dumped end time is different with real end time
  - Dumped end time = Real end time + additional CPU idle checking time
  - Additional CPU idle checking time = (real - minimum) time

Change-Id: Ib943325174f5a7cc39b2055591a2c71f1f05140a
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
src/battery_dump/bd_history_item.c
src/bm_power_engine.c

index c004bca..53f48df 100644 (file)
@@ -49,6 +49,8 @@ char usage_map[32][4] = {"Bu", "Wu", "", "", "", "", "", "", "", "", "", "", "",
 GHashTable *app_map = NULL;
 static long int lst_charge = -1;
 
+static long long min_idle_check_time;
+
 static int bd_print_pool_entry(int fd, int idx, int pc, history_tag_s *pool_info)
 {
        ENTER;
@@ -936,6 +938,10 @@ int bd_print_history_item_main(int fd, int num_h_items, long long base_time, boo
                                        g_string_append_printf(dump_p, "%s", usage_map[i]);
                                        g_string_append(dump_p, "=");
                                        g_string_append_printf(dump_p, "%d", new_state.usage);
+                                       g_string_append(dump_p, ",");
+                                       g_string_append_printf(dump_p, "%lld", new_state.time_current);
+                                       g_string_append(dump_p, ",");
+                                       g_string_append_printf(dump_p, "%lld", (new_state.time_s - min_idle_check_time) / 1000);
                                        g_string_append(dump_p, "\n");
                                        _DBG("value %d", new_state.usage);
                                }
@@ -1368,6 +1374,8 @@ static int bd_set_history_from_listener(history_item_s* nrec)
        }
        if (nrec->cmd_s == CM_CRR_TIME || nrec->cmd_s == CM_RST)
                history_data[h_count].time_current = ((long long)tv.tv_sec * 1000) + ((long long)tv.tv_usec / 1000);
+       else if (nrec->cmd_s == CM_USAGE)
+               history_data[h_count].time_current = nrec->time_current;
 
        history_data[h_count].state_1 = nrec->state_1;
        history_data[h_count].state_2 = nrec->state_2;
@@ -1450,6 +1458,27 @@ int bd_callback(const int fd, const int argc, char **argv)
        return 0;
 }
 
+void bd_get_idle_check_time()
+{
+       ENTER;
+
+       int ret;
+       int not_used_int;
+       int data_collection_try_period;
+       int data_collection_accept_count;
+
+       ret = bm_get_job_scheduler_params(&not_used_int, &data_collection_try_period, &data_collection_accept_count, &not_used_int);
+       if (ret != BATTERY_MONITOR_ERROR_NONE) {
+               min_idle_check_time = 0;
+               return;
+       }
+
+       min_idle_check_time = (long long)data_collection_try_period * data_collection_accept_count;
+
+       EXIT;
+       return;
+}
+
 int bd_initialize_battery_dump()
 {
        ENTER;
@@ -1477,6 +1506,8 @@ int bd_initialize_battery_dump()
                return BATTERY_MONITOR_ERROR_NOT_INITIALIZED;
        }
 
+       bd_get_idle_check_time();
+
        _INFO("Battery Dump Init Successful");
 
        EXIT;
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;
 }