Dump the start/end time of usage collection time
[platform/core/system/batterymonitor.git] / src / battery_dump / bd_history_item.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;