Correct for last charge in runtime 83/232083/1 accepted/tizen/5.5/unified/20200428.222940 submit/tizen_5.5/20200428.093936
authorDewal Agarwal <d1.agarwal@samsung.com>
Tue, 28 Apr 2020 06:30:26 +0000 (12:00 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Tue, 28 Apr 2020 06:30:26 +0000 (12:00 +0530)
Change-Id: I53df84feb058e42f22aca230c1357acabd25966e
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
src/battery_dump/bd_history_item.c

index ee6219b..1d99b33 100644 (file)
@@ -47,6 +47,7 @@ char event_map[32][4] = {"Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur",
 char usage_map[32][4] = {"Bu", "Wu", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
        "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
 GHashTable *app_map = NULL;
+static long int lst_charge = -1;
 
 static int bd_print_pool_entry(int fd, int idx, history_tag_s *pool_info)
 {
@@ -193,6 +194,8 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
        GHashTableIter iter;
        gpointer key, value; GString *dump_p = NULL;
        char *appid = NULL; int *uid_n = NULL;
+       time_t crr_time = 0; time(&crr_time);
+       long int end_t = crr_time;
        float usageMAh = 0; int battery_capacity = 500;//default
 
        ret = bm_get_battery_power_params(&battery_capacity);
@@ -222,7 +225,7 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
                _DBG("%d %s", *uid_n, appid); usageMAh = 0;
                // Currently giving app usage of last one week;
                // Modify it wrt to time
-               appid_usage_s *app_use = bm_server_query_app_usage_by_appid(appid, 1, &ret);
+               appid_usage_s *app_use = bm_server_query_app_usage_by_appid_ci(appid, duration, end_t, &ret);
                if (app_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
                        _ERR("For appid %s", appid);
                        continue;
@@ -254,7 +257,7 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
                        return BATTERY_MONITOR_ERROR_INTERNAL;
                }
                resourceid_usage_s *res_use =
-                       bm_server_query_resource_usage_resourceid(rid_str, 1, &ret);
+                       bm_server_query_resource_usage_resourceid_ci(rid_str, duration, end_t, &ret);
                if (res_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
                        _ERR("For resourceid %s", rid_str);
                        continue;
@@ -364,9 +367,10 @@ static int bd_get_and_print_misc_stat_entry_from_dump(int fd, long int duration)
        g_string_append_printf(dump_p, "%ld,", on_time);
        g_string_append_printf(dump_p, "%ld", off_time);
        g_string_append(dump_p, "\n");
+/*
        _DBG("%s", dump_p->str);
        if (write(fd, dump_p->str, dump_p->len) < 0)
-               _WARN("write error");
+               _WARN("write error");*/
        g_string_free(dump_p, TRUE);
        BM_FREE(gbr_stat);
 
@@ -604,9 +608,11 @@ static int bd_get_and_print_gcpu_stat_entry_from_dump(int fd, long int duration)
 
        int ret = BATTERY_MONITOR_ERROR_NONE;
        const char *rid_str = NULL; int usage = 0;
+       time_t crr_time = 0; time(&crr_time);
+       long int end_t = crr_time;
        rid_str = bm_get_resource_id_string(2);
        resourceid_usage_s *res_use =
-               bm_server_query_resource_usage_resourceid(rid_str, 1, &ret);
+               bm_server_query_resource_usage_resourceid_ci(rid_str, duration, end_t, &ret);
        if (res_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) {
                _ERR("For resourceid %s", rid_str);
                return ret;
@@ -747,9 +753,6 @@ static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
        dump_node->event_tag = history_data[index].event_tag;
        if (dump_node->event_tag == NULL)
                _DBG("Event_Tag_NULL");
-       else//Remove
-               _DBG("%d %d %s", dump_node->event_tag->uid, dump_node->event_tag->sp_idx,
-               dump_node->event_tag->string_info->str);
        dump_node->wakelock_tag = history_data[index].wakelock_tag;
        if (dump_node->wakelock_tag == NULL)
                _DBG("Wakelock_Tag_NULL");
@@ -1207,8 +1210,12 @@ int bd_print_history_item_main(int fd, int num_h_items, long long base_time, boo
        if (ret != BATTERY_MONITOR_ERROR_NONE)
                _ERR("UID data dump failed");
        // Get Last charge time to dump "l" field
-       // for the time being dumping all data
-       long int duration = 0; //Time of last charge
+       long int duration = 0;
+       if (lst_charge < 0)
+               duration = base_time/1000;
+       else
+               duration = lst_charge;
+
        ret = bd_get_and_print_gn_stat_entry_from_dump(fd, duration);
        if (ret != BATTERY_MONITOR_ERROR_NONE)
                _ERR("GN dump failed");
@@ -1234,8 +1241,6 @@ int bd_print_history_item_main(int fd, int num_h_items, long long base_time, boo
        if (ret != BATTERY_MONITOR_ERROR_NONE)
                _ERR("MISc data dump failed");
        // Battery Usage Dump
-       // Add usage for each of the resource
-       // and each of the application
        ret = bd_get_and_print_battery_usage_from_dump(fd, duration);
        if (ret != BATTERY_MONITOR_ERROR_NONE)
                _ERR("Battery Usage failed");
@@ -1319,6 +1324,9 @@ static int bd_set_history_from_listener(history_item_s* nrec)
        history_data[h_count].time_s = ((long long)tv.tv_sec * 1000) + ((long long)tv.tv_usec / 1000);
 #endif
 
+       if (nrec->battery_plugtype > BD_BPLT_DIS)
+               lst_charge = tv.tv_sec;
+
        dvar1 = ((nrec->cmd_s) & 0xff) | ((nrec->battery_level << 8) & 0xff00) |
                ((nrec->battery_status << 16) & 0xf0000) |
                ((nrec->battery_health << 20) & 0xf00000) |