Add Battery Capacity in Dump 44/227944/2
authorDewal Agarwal <d1.agarwal@samsung.com>
Thu, 12 Mar 2020 12:46:39 +0000 (18:16 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Tue, 17 Mar 2020 10:35:09 +0000 (10:35 +0000)
Change-Id: I8b7038d2a35c106ec04378f15a5cefc6ca0124e6
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
src/battery_dump/bd_history_item.c

index aef2104..6ff59c6 100644 (file)
@@ -29,6 +29,7 @@
 #include "bm_server_db.h"
 #include "bm_private.h"
 #include "bd_private.h"
+#include "bm_config_parser.h"
 
 //#define DUMP_DUMMY 1
 #ifdef DUMP_DUMMY
@@ -135,69 +136,6 @@ static int bd_get_pool_entry_from_dump(int fd)
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
-/* Depricated till there are no separate UID related events
-static int bd_print_uid_entry(int idx, history_tag_s *pool_info)
-{
-       ENTER;
-       BM_CHECK_INPUT_PARAM(pool_info);
-       GString *dump_p = g_string_sized_new(30);
-       BM_CHECK_MEM_ALLOC(dump_p, {});
-       g_string_append_printf(dump_p, "%d,", pool_info->uid);
-       if (pool_info->string_info != NULL) {
-               gchar *temp = g_strdup(pool_info->string_info->str);
-               g_string_append(dump_p, temp);
-               g_free(temp);
-       }
-       g_string_append(dump_p, "\n");
-       _DBG("%s", dump_p->str);//write
-       g_free(dump_p->str);
-       EXIT;
-       return BATTERY_MONITOR_ERROR_NONE;
-}
-
-static int bd_get_uid_entry_from_dump(void)
-{
-       ENTER;
-       // should be maintained at listeners for uniqueness
-       // move there and modify
-       GString *dump_p = g_string_sized_new(30);
-       BM_CHECK_MEM_ALLOC(dump_p, {});
-       g_string_append(dump_p, TIZEN_DUMP_VERSION);
-       g_string_append(dump_p, ",0");
-       g_string_append(dump_p, ",i");
-       g_string_append(dump_p, ",uid,");
-       int ret = BATTERY_MONITOR_ERROR_NONE;
-       int log_count = h_count;
-       for (int i = 0; i < log_count; i++) {
-               history_tag_s *pool_info = NULL;
-               if (history_data[i].event_tag != NULL) {
-                       pool_info = history_data[i].event_tag;
-                       _DBG("%s", dump_p->str);//write
-                       ret = bd_print_uid_entry(i, pool_info);
-                       if (ret != BATTERY_MONITOR_ERROR_NONE)
-                               return BATTERY_MONITOR_ERROR_INTERNAL;
-               }
-               if (history_data[i].wakelock_tag != NULL) {
-                       pool_info = history_data[i].wakelock_tag;
-                       _DBG("%s", dump_p->str);//write
-                       ret = bd_print_uid_entry(i, pool_info);
-                       if (ret != BATTERY_MONITOR_ERROR_NONE)
-                               return BATTERY_MONITOR_ERROR_INTERNAL;
-               }
-               if (history_data[i].wakereason_tag != NULL) {
-                       pool_info = history_data[i].wakereason_tag;
-                       _DBG("%s", dump_p->str);//write
-                       ret = bd_print_uid_entry(i, pool_info);
-                       if (ret != BATTERY_MONITOR_ERROR_NONE)
-                               return BATTERY_MONITOR_ERROR_INTERNAL;
-               }
-       }
-       g_free(dump_p->str);
-       EXIT;
-       return BATTERY_MONITOR_ERROR_NONE;
-}
-*/
-
 static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
 {
        ENTER;
@@ -206,7 +144,25 @@ 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;
-       float usageMAh = 0;
+       float usageMAh = 0; int battery_capacity = 500;//default
+
+       ret = bm_get_battery_power_params(&battery_capacity);
+       if (ret != BATTERY_MONITOR_ERROR_NONE) {
+               _ERR("unable read read battery capacity");
+               battery_capacity = 500;
+       }
+
+       dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
+       g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       // Power Capacity
+       g_string_append_printf(dump_p, ",0,l,pws,%d,0,0,0", battery_capacity);
+       g_string_append(dump_p, "\n");
+       _DBG("%s", dump_p->str);
+       if (write(fd, dump_p->str, dump_p->len) < 0)
+               _WARN("write error");
+       g_free(dump_p->str);
+
        g_hash_table_iter_init(&iter, app_map);
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                uid_n = (int *)key; appid = (char *)value;
@@ -1342,16 +1298,6 @@ int bd_store_history_item(history_item_s* nrec)
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
-/*
-int bd_set_old_state_to_history_item(history_item_s* nrec)
-{
-       ENTER;
-       //Move this with listeners
-       EXIT;
-       return BATTERY_MONITOR_ERROR_NONE;
-}
-*/
-
 static int *dumpsys_handler;
 
 int bd_callback(const int fd, const int argc, char **argv)