diff options
-rw-r--r-- | src/battery_dump/bd_history_item.c | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/src/battery_dump/bd_history_item.c b/src/battery_dump/bd_history_item.c index f3c7114..569b7eb 100644 --- a/src/battery_dump/bd_history_item.c +++ b/src/battery_dump/bd_history_item.c @@ -285,33 +285,34 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration) g_string_free(dump_p, TRUE); - g_hash_table_iter_init(&iter, app_map); - while (g_hash_table_iter_next(&iter, &key, &value)) { - uid_n = (int *)key; appid = (char *)value; - _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_ci(appid, duration, end_t, &ret); - if (app_use == NULL || ret != BATTERY_MONITOR_ERROR_NONE) { - _ERR("For appid %s", appid); - continue; + if (app_map != NULL) { + g_hash_table_iter_init(&iter, app_map); + while (g_hash_table_iter_next(&iter, &key, &value)) { + uid_n = (int *)key; appid = (char *)value; + _DBG("%d %s", *uid_n, appid); usageMAh = 0; + 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; + } + usageMAh = (app_use->rId_ble + app_use->rId_wifi + app_use->rId_cpu + + app_use->rId_display + app_use->rId_device_network + + app_use->rId_gps); + // usage stored as mAs changed to mAh + usageMAh = (usageMAh/3600); + dump_p = g_string_sized_new(30); + BM_CHECK_MEM_ALLOC(dump_p, { BM_FREE(app_use); }); + g_string_append_printf(dump_p, "%s,%d,l,pwi,uid,%0.2f\n", + TIZEN_DUMP_VERSION, *uid_n, usageMAh); + + bm_appid_usage_free(app_use); + _DBG("%s", dump_p->str); + if (write(fd, dump_p->str, dump_p->len) < 0) + _WARN("write error"); + g_string_free(dump_p, TRUE); } - usageMAh = (app_use->rId_ble + app_use->rId_wifi + app_use->rId_cpu + - app_use->rId_display + app_use->rId_device_network + - app_use->rId_gps); - // usage stored as mAs changed to mAh - usageMAh = (usageMAh/3600); - dump_p = g_string_sized_new(30); - BM_CHECK_MEM_ALLOC(dump_p, { BM_FREE(app_use); }); - g_string_append_printf(dump_p, "%s,%d,l,pwi,uid,%0.2f\n", - TIZEN_DUMP_VERSION, *uid_n, usageMAh); - - bm_appid_usage_free(app_use); - _DBG("%s", dump_p->str); - if (write(fd, dump_p->str, dump_p->len) < 0) - _WARN("write error"); - g_string_free(dump_p, TRUE); } + // Resource usage; const char *rid_str = NULL; for (int i = 0; i < 6; i++) { |