Battery Dump for Plugin Data 02/222402/5
authorDewal Agarwal <d1.agarwal@samsung.com>
Tue, 14 Jan 2020 11:21:05 +0000 (16:51 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Wed, 15 Jan 2020 10:43:42 +0000 (16:13 +0530)
Change-Id: I509b256585218049cf57dc30b07010bed017216a
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
include/bm_common.h
src/battery_dump/bd_history_item.c

index 0ef3ca6..20ea93f 100644 (file)
@@ -162,6 +162,14 @@ typedef enum {
                return ret_val; \
        } else {}
 
+/* validating memory allocation */
+#define BM_CHECK_MEM_ALLOC(eval, expr) \
+       if (!(eval)) { \
+               expr; \
+               _ERR("Memory Allocation Failed"); \
+               return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY; \
+       } else {}
+
 /* snprintf wrapper */
 #define BM_SNPRINTF(dest, size, format, arg...) \
        do { \
index 47c5bce..0dfcea7 100644 (file)
 #include <time.h>
 #include <glib/gprintf.h>
 #include <stdio.h>
-#include <bd_history_item.h>
-#include <bm_dbg.h>
-#include <bm_common.h>
+#include "bd_history_item.h"
+#include "bm_util.h"
+#include "bm_dbg.h"
+#include "bm_common.h"
+#include "bm_server_db.h"
+#include "bm_private.h"
+#include "bd_private.h"
+//#include "bm_power_engine.h"
 
 dump_data_s history_data[HISTORY_SIZE_MAX];
 int h_count = 0; int h_flag = false;
@@ -31,15 +36,17 @@ char state2_map[32][5] = {"", "", "", "", "", "", "", "", "", "", "", "", "", ""
        "", "Ud", "Chtp", "bles", "ca", "b", "Pcl", "ch", "", "", "fl", "W", "Ww", "v", "ps"};
 char event_map[32][4] = {"Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
        "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", "Esw", "Ewa", "Elw", "Eec"};
+GHashTable *app_map = NULL;
 //FILE *fp = NULL;
 
 static int bd_print_pool_entry(int idx, history_tag_s *pool_info)
 {
        ENTER;
-
+       BM_CHECK_INPUT_PARAM(pool_info);
        _DBG("Value from history data %d", idx);
 
        GString *dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
 
        dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
        dump_p = g_string_append_c(dump_p, ',');
@@ -58,7 +65,8 @@ static int bd_print_pool_entry(int idx, history_tag_s *pool_info)
        dump_p = g_string_append(dump_p, "\"");
        dump_p = g_string_append(dump_p, "\n");
        _DBG("%s", dump_p->str);
-//     fputs(dump_p->str, fp);//TEMP
+       //fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
 
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
@@ -69,6 +77,7 @@ static int bd_get_pool_entry_from_dump(void)
        ENTER;
 
        GString *dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
        dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
        dump_p = g_string_append(dump_p, ",0");
        dump_p = g_string_append(dump_p, ",i");
@@ -76,8 +85,9 @@ static int bd_get_pool_entry_from_dump(void)
        dump_p = g_string_append(dump_p, ",19,150,NMF26V,NMF26V");
        dump_p = g_string_append(dump_p, "\n");
        _DBG("%s", dump_p->str);
-//     fputs(dump_p->str, fp);//TEMP
+       //fputs(dump_p->str, fp);//TEMP
        g_free(dump_p->str);
+
        int ret = BATTERY_MONITOR_ERROR_NONE;
        int log_count = h_count;
        for (int i = 0; i < log_count; i++) {
@@ -106,11 +116,13 @@ static int bd_get_pool_entry_from_dump(void)
        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);
@@ -120,17 +132,17 @@ static int bd_print_uid_entry(int idx, history_tag_s *pool_info)
        dump_p = 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, {});
        dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
        dump_p = g_string_append(dump_p, ",0");
        dump_p = g_string_append(dump_p, ",i");
@@ -162,15 +174,347 @@ static int bd_get_uid_entry_from_dump(void)
                }
        }
        g_free(dump_p->str);
-
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
-// The index passed in the fn should be preferrably continuous,
-// Other things should be implemented at dumping function.
+*/
+
+static int bd_get_and_print_battery_usage_from_dump(long int duration)
+{
+       ENTER;
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       // Application usage;
+       GHashTableIter iter;
+       gpointer key, value; GString *dump_p = NULL;
+       char *appid = NULL; int *uid_n = NULL;
+       float usageMAh = 0;
+       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(appid, 1, &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 + app_use->rId_hrm);
+               //ret = bm_engine_get_total_usage_by_app_id(appid, 1, &usage);
+               usageMAh = (usageMAh/1000);
+               dump_p = g_string_sized_new(30);
+               BM_CHECK_MEM_ALLOC(dump_p, {});
+               g_string_append(dump_p, TIZEN_DUMP_VERSION);
+               g_string_append_printf(dump_p, ",%d,l,pwi,uid,", *uid_n);
+               g_string_append_printf(dump_p, "%0.2f", usageMAh);
+               g_string_append(dump_p, "\n");
+               bm_appid_usage_free(app_use);
+               _DBG("%s", dump_p->str);
+               //fputs(dump_p->str, fp);//TEMP
+               g_free(dump_p->str);
+       }
+       // Resource usage;
+       const char *resource_id_str = NULL;
+       for (int i = 0; i < 5; i++) {
+               int usage = 0;
+               //ret = bm_engine_get_total_usage_by_resource_id(i, 1, &usage);i
+               resource_id_str = bm_get_resource_id_string(i);
+               if (g_strcmp0(resource_id_str, "UNKNOWN RESOURCE-ID") == 0) {
+                       _ERR("invalid resource-id");
+                       return BATTERY_MONITOR_ERROR_INTERNAL;
+               }
+               resourceid_usage_s *resource_usage = bm_server_query_resource_usage_resourceid(resource_id_str, 1, &ret);
+               usage = resource_usage->usage;
+               usageMAh = (float)usage/1000;
+               dump_p = g_string_sized_new(30);
+               BM_CHECK_MEM_ALLOC(dump_p, {});
+               g_string_append(dump_p, TIZEN_DUMP_VERSION);
+               g_string_append_printf(dump_p, ",%d,l,pwi,%s,", *uid_n, resource_id_str);
+               g_string_append_printf(dump_p, "%0.2f", usageMAh);
+               g_string_append(dump_p, "\n");
+               bm_resourceid_usage_free(resource_usage);
+               _DBG("%s", dump_p->str);
+               //fputs(dump_p->str, fp);//TEMP
+               g_free(dump_p->str);
+       }
+
+       EXIT;
+       return ret;
+}
+
+static int bd_get_and_print_gbr_stat_entry_from_dump(long int duration)
+{
+       ENTER;
+       // Dump brightness Data
+       bd_gl_sbr_stat_s *gbr_stat = (bd_gl_sbr_stat_s *)calloc(1, sizeof(bd_gl_sbr_stat_s));
+       BM_CHECK_MEM_ALLOC(gbr_stat, {});
+       GString *dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
+
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       ret = bm_server_battery_dump_query_from_db(gbr_stat, 3, duration);
+       if (ret != BATTERY_MONITOR_ERROR_NONE) {
+               _ERR("Unable to fetch data from DB");
+               return ret;
+       }
+       g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       g_string_append(dump_p, ",0,l,");
+       g_string_append(dump_p, "br,");
+       g_string_append_printf(dump_p, "%ld,", gbr_stat->dark); //OFF
+       g_string_append_printf(dump_p, "%ld,", gbr_stat->dim); // All are time values
+       g_string_append_printf(dump_p, "%ld,", gbr_stat->medium);
+       g_string_append_printf(dump_p, "%ld,", gbr_stat->light); //DEF: 0
+       g_string_append_printf(dump_p, "%ld", gbr_stat->bright);
+       g_string_append(dump_p, "\n");
+       _DBG("%s", dump_p->str);//write
+       //fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
+       BM_FREE(gbr_stat);
+
+       EXIT;
+       return ret;
+}
+
+static int bd_get_and_print_gn_stat_entry_from_dump(long int duration)
+{
+       ENTER;
+       // Dump Network Data
+       bd_gl_ntw_stat_s *gn_stat = (bd_gl_ntw_stat_s *)calloc(1, sizeof(bd_gl_ntw_stat_s));
+       BM_CHECK_MEM_ALLOC(gn_stat, {});
+
+       GString *dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
+
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       ret = bm_server_battery_dump_query_from_db(gn_stat, 2, duration);
+       if (ret != BATTERY_MONITOR_ERROR_NONE) {
+               _ERR("Unable to fetch data from DB");
+               return ret;
+       }
+       g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       g_string_append(dump_p, ",0,l,");
+       g_string_append(dump_p, "gn,");
+       g_string_append_printf(dump_p, "%ld,", gn_stat->dn_rx_byt);
+       g_string_append_printf(dump_p, "%ld,", gn_stat->dn_tx_byt);
+       g_string_append_printf(dump_p, "%ld,", gn_stat->wifi_rx_byt);
+       g_string_append_printf(dump_p, "%ld,", gn_stat->wifi_tx_byt);
+       g_string_append_printf(dump_p, "%ld,", gn_stat->dn_rx_pkt);
+       g_string_append_printf(dump_p, "%ld,", gn_stat->dn_tx_pkt);
+       g_string_append_printf(dump_p, "%ld,", gn_stat->wifi_rx_pkt);
+       g_string_append_printf(dump_p, "%ld,", gn_stat->wifi_tx_pkt);
+       g_string_append_printf(dump_p, "%d,", 0); //add this to struct as well
+       g_string_append_printf(dump_p, "%d", 0);
+       g_string_append(dump_p, "\n");
+
+       _DBG("%s", dump_p->str);//write
+       //fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
+       BM_FREE(gn_stat);
+
+       EXIT;
+       return ret;
+}
+
+static int bd_get_and_print_gwf_stat_entry_from_dump(long int duration)
+{
+       ENTER;
+       // Dump Wifi Stats
+       bd_gl_wifi_stat_s *gwfl_stat = (bd_gl_wifi_stat_s *)calloc(1, sizeof(bd_gl_wifi_stat_s));
+       BM_CHECK_MEM_ALLOC(gwfl_stat, {});
+       GString *dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
+
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       ret = bm_server_battery_dump_query_from_db(gwfl_stat, 1, duration);
+       if (ret != BATTERY_MONITOR_ERROR_NONE) {
+               _ERR("Unable to fetch data from DB");
+               return ret;
+       }
+       g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       g_string_append(dump_p, ",0,l,");
+       g_string_append(dump_p, "gwfl,");
+       g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_on_time);
+       g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_conn_time);
+       g_string_append(dump_p, "0,0,0");//legacy
+
+       g_string_append(dump_p, "\n");
+       _DBG("%s", dump_p->str);//write
+       //fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
+
+       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,l,");
+       g_string_append(dump_p, "gwfcd,");
+       //idle rx pwi tx
+       g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_idle_time);
+       g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_rx_time);
+       g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_pwi_val);
+       g_string_append_printf(dump_p, "%ld", gwfl_stat->wifi_tx_time);
+       g_string_append(dump_p, "\n");
+       _DBG("%s", dump_p->str);//write
+       //fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
+       BM_FREE(gwfl_stat);
+
+       EXIT;
+       return ret;
+}
+
+static int bd_get_and_print_gble_stat_entry_from_dump(long int duration)
+{
+       ENTER;
+       // Dump bt Data
+       bd_gl_ble_stat_s *gble_stat = (bd_gl_ble_stat_s *)calloc(1, sizeof(bd_gl_ble_stat_s));
+       BM_CHECK_MEM_ALLOC(gble_stat, {});
+       GString *dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
+
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       ret = bm_server_battery_dump_query_from_db(gble_stat, 0, duration);
+       if (ret != BATTERY_MONITOR_ERROR_NONE) {
+               _ERR("Unable to fetch data from DB");
+               return ret;
+       }
+       g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       g_string_append(dump_p, ",0,l,");
+       g_string_append(dump_p, "gble,");
+       g_string_append_printf(dump_p, "%ld,", gble_stat->ble_idle_time);
+       g_string_append_printf(dump_p, "%ld,", gble_stat->ble_rx_time);
+       g_string_append_printf(dump_p, "%ld,", gble_stat->ble_tx_time);
+       g_string_append_printf(dump_p, "%ld", gble_stat->ble_pwi_val);
+       g_string_append(dump_p, "\n");
+
+       _DBG("%s", dump_p->str);//write
+       //fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
+       BM_FREE(gble_stat);
+
+       EXIT;
+       return ret;
+}
+
+static int bd_get_and_print_gst_stat_entry_from_dump(long int duration)
+{
+       ENTER;
+       bd_gl_sgt_stat_s *gst_stat = (bd_gl_sgt_stat_s *)calloc(1, sizeof(bd_gl_sgt_stat_s));
+       BM_CHECK_MEM_ALLOC(gst_stat, {});
+       GString *dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
+
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       ret = bm_server_battery_dump_query_from_db(gst_stat, 4, duration);
+       if (ret != BATTERY_MONITOR_ERROR_NONE) {
+               _ERR("Unable to fetch data from DB");
+               return ret;
+       }
+       g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       g_string_append(dump_p, ",0,l,");
+       g_string_append(dump_p, "sgt,");
+       g_string_append_printf(dump_p, "%ld,", gst_stat->none_time);
+       g_string_append_printf(dump_p, "%ld,", gst_stat->poor_time);
+       g_string_append_printf(dump_p, "%ld,", gst_stat->med_time);
+       g_string_append_printf(dump_p, "%ld,", gst_stat->good_time);
+       g_string_append_printf(dump_p, "%ld", gst_stat->grt_time);
+       g_string_append(dump_p, "\n");
+
+       _DBG("%s", dump_p->str);//write
+       g_free(dump_p->str);
+
+       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,l,");
+       g_string_append(dump_p, "sst,");
+       g_string_append_printf(dump_p, "%ld", gst_stat->scan_time);
+
+       g_string_append(dump_p, "\n");
+       _DBG("%s", dump_p->str);//write
+       //fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
+       BM_FREE(gst_stat);
+
+       EXIT;
+       return ret;
+}
+
+static int bd_get_and_print_gwst_stat_entry_from_dump(long int duration)
+{
+       ENTER;
+       bd_gl_wst_stat_s *gwst_stat = (bd_gl_wst_stat_s *)calloc(1, sizeof(bd_gl_wst_stat_s));
+       BM_CHECK_MEM_ALLOC(gwst_stat, {});
+       GString *dump_p = g_string_sized_new(30);
+       BM_CHECK_MEM_ALLOC(dump_p, {});
+
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       ret = bm_server_battery_dump_query_from_db(gwst_stat, 5, duration);
+       if (ret != BATTERY_MONITOR_ERROR_NONE) {
+               _ERR("Unable to fetch data from DB");
+               return ret;
+       }
+       g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       g_string_append(dump_p, ",0,l,");
+       g_string_append(dump_p, "wsgt,");
+//     g_string_append_printf(dump_p, "%ld,", gwst_stat->wscan_time);
+       g_string_append_printf(dump_p, "%ld,", gwst_stat->wnone_time);
+       g_string_append_printf(dump_p, "%ld,", gwst_stat->wpoor_time);
+       g_string_append_printf(dump_p, "%ld,", gwst_stat->wmed_time);
+       g_string_append_printf(dump_p, "%ld,", gwst_stat->wgood_time);
+       g_string_append_printf(dump_p, "%ld", gwst_stat->wgrt_time);
+       g_string_append(dump_p, "\n");
+       _DBG("%s", dump_p->str);//write
+       //fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
+       BM_FREE(gwst_stat);
+
+       EXIT;
+       return ret;
+}
+
+static int bd_get_and_print_uid_info_entry_from_dump(void)
+{
+       ENTER;
+       // Dump UID entry
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       GSList *list = bm_server_query_appid_map(&ret);
+       if (list == NULL) {
+               _ERR("NO LIST DATA FOUND");
+               return ret;
+       }
+       app_map = g_hash_table_new_full(g_int_hash, g_int_equal, g_free, g_free);
+       GSList *iter = NULL; GString *dump_p = NULL;
+       for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
+               dump_p = g_string_sized_new(30);
+               BM_CHECK_MEM_ALLOC(dump_p, {bm_set_free_gslist_appid_map(list); });
+               dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
+               dump_p = g_string_append(dump_p, ",0");
+               dump_p = g_string_append(dump_p, ",i");
+               dump_p = g_string_append(dump_p, ",uid,");
+               appid_map_s *amap_data = (appid_map_s *)iter->data;
+               g_string_append_printf(dump_p, "%d,", amap_data->id);
+               gchar *temp_str = g_strdup(amap_data->AppId);
+               g_string_append(dump_p, amap_data->AppId);
+               dump_p = g_string_append(dump_p, "\n");
+               _DBG("%s", dump_p->str);//write
+               //fputs(dump_p->str, fp);//TEMP
+               int *temp_id = (int *)malloc(4);
+               *temp_id = amap_data->id;
+               _DBG("Insert id %d, str %s, res %d", *temp_id, temp_str,
+               g_hash_table_insert(app_map, temp_id, temp_str));
+               g_free(dump_p->str);
+       }
+       bm_set_free_gslist_appid_map(list);
+
+       EXIT;
+       return ret;
+}
+
 static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
 {
        ENTER;
+       BM_CHECK_INPUT_PARAM(dump_node);
 
        if (h_count >= HISTORY_SIZE_MAX || index > h_count) {
                _ERR("Some Error occured with global index");
@@ -179,7 +523,7 @@ static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
 
        _DBG("Value of index %d", index);
        _DBG("Value of h_count %d", h_count);
-       // Print time if required
+
        int dvar1 = 0, dvar2 = 0;
        dvar1 = history_data[index].dump_1;
        dvar2 = history_data[index].dump_2;
@@ -189,26 +533,37 @@ static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
 
        dump_node->cmd_s = ((dvar1) & 0xff);
        _DBG("cmd_s %d", dump_node->cmd_s);
+
        dump_node->battery_level = ((dvar1>>8) & 0xff);
        _DBG("battery_level %d", dump_node->battery_level);
+
        dump_node->battery_status = ((dvar1>>16) & 0xf);
        _DBG("battery_status %d", dump_node->battery_status);
+
        dump_node->battery_health = ((dvar1>>20) & 0xf);
        _DBG("battery_health %d", dump_node->battery_health);
+
        dump_node->battery_plugtype = ((dvar1>>24) & 0xf);
        _DBG("battery_plugtype %d", dump_node->battery_plugtype);
+
        dump_node->battery_temperature = ((dvar2) & 0xffff);
        _DBG("battery_temperature %d", dump_node->battery_temperature);
+
        dump_node->battery_voltage = ((dvar2>>16) & 0xffff);
        _DBG("battery_voltage %d", dump_node->battery_voltage);
+
        dump_node->battery_charge = history_data[index].battery_chargeUAh;
        _DBG("battery_charge %d", dump_node->battery_charge);
+
        dump_node->event_code = history_data[index].event_code;
        _DBG("eventcode %d", dump_node->event_code);
+
        dump_node->state_1 = history_data[index].state_1;
        _DBG("state_1 %d", dump_node->state_1);
+
        dump_node->state_2 = history_data[index].state_2;
        _DBG("state_2 %d", dump_node->state_2);
+
        dump_node->event_tag = history_data[index].event_tag;
        if (dump_node->event_tag == NULL)
                _DBG("Event_Tag_NULL");
@@ -222,8 +577,10 @@ static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
        //:Not supported
        if (dump_node->wakereason_tag == NULL)
                _DBG("Wakereason_Tag_NULL");
+
        dump_node->time_s = history_data[index].time_s;
        _DBG("TIME_S is %ld", dump_node->time_s);
+
        dump_node->time_current = history_data[index].time_current;
        _DBG("C TIME is %ld", dump_node->time_current);
 
@@ -234,10 +591,12 @@ static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
 static int bd_print_history_item_reset(history_item_s* old_state)
 {
        ENTER;
+       BM_CHECK_INPUT_PARAM(old_state);
 
        old_state->time_s = -1;
        old_state->state_1 = 0;
        old_state->state_2 = 0;
+       //TEMP: Change to 0;
        old_state->battery_level = -1;
        old_state->battery_status = -1;
        old_state->battery_health = -1;
@@ -270,23 +629,21 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                _ERR("Old State reset failed");
                return ret;
        }
-
-//     fp = fopen("/tmp/test.txt", "w+");//TEMP
+       //fp = fopen("/tmp/test.txt", "w+");//TEMP
 
        ret = bd_get_pool_entry_from_dump();
        if (ret != BATTERY_MONITOR_ERROR_NONE)
                _ERR("S pool data dump failed");
 
-       int log_count = h_count;
+       int log_count = h_count; GString *dump_p = NULL;
        for (int i = 0; i < log_count; i++) {
-
                ret = bd_get_history_detail_from_dump(i, &new_state);
                if (ret != BATTERY_MONITOR_ERROR_NONE) {
                        _ERR("Decode Failed");
                        return ret;
                }
-
-               GString *dump_p = g_string_sized_new(30);
+               dump_p = g_string_sized_new(30);
+               BM_CHECK_MEM_ALLOC(dump_p, {});
                if (chkin) {
                        dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
                        dump_p = g_string_append_c(dump_p, ',');
@@ -312,7 +669,7 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                                dump_p = g_string_append_c(dump_p, ':');
                                _DBG("value %s", dump_p->str);
                        } else {
-                               //
+                               //NC
                        }
                        dump_p = g_string_append(dump_p, "START\n");
                        _DBG("value %s", dump_p->str);
@@ -335,14 +692,14 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                                dump_p = g_string_append(dump_p, "\n");
                                _DBG("value %s", dump_p->str);
                        } else {
-                               //
+                               //NC
                        }
                } else if (new_state.cmd_s == CM_SHTDN) {
                        if (chkin) {
                                dump_p = g_string_append_c(dump_p, ':');
                                _DBG("value %s", dump_p->str);
                        } else {
-                               //
+                               //NC
                        }
                        dump_p = g_string_append(dump_p, "SHUTDOWN\n");
                        _DBG("value %s", dump_p->str);
@@ -355,7 +712,7 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                        _DBG("value %s", dump_p->str);
                } else {
                        if (!chkin) {
-                               //
+                               //NC
                        } else {
                                if (old_state.battery_level != new_state.battery_level) {
                                        old_state.battery_level = new_state.battery_level;
@@ -550,16 +907,46 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                }
                        _DBG("State assigned");
                        _DBG("%s", dump_p->str);
-//                     fputs(dump_p->str, fp);//TEMP
+                       //fputs(dump_p->str, fp);//TEMP
                        g_free(dump_p->str);
        }
                //Dump i & l values after this
-               ret = bd_get_uid_entry_from_dump();
+               ret = bd_get_and_print_uid_info_entry_from_dump();
                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
+               ret = bd_get_and_print_gn_stat_entry_from_dump(duration);
+               if (ret != BATTERY_MONITOR_ERROR_NONE)
+                       _ERR("GN dump failed");
+               ret = bd_get_and_print_gwf_stat_entry_from_dump(duration);
+               if (ret != BATTERY_MONITOR_ERROR_NONE)
+                       _ERR("GWF data dump failed");
+               ret = bd_get_and_print_gble_stat_entry_from_dump(duration);
+               if (ret != BATTERY_MONITOR_ERROR_NONE)
+                       _ERR("GBL data dump failed");
+               ret = bd_get_and_print_gbr_stat_entry_from_dump(duration);
+               if (ret != BATTERY_MONITOR_ERROR_NONE)
+                       _ERR("GBR data dump failed");
+               ret = bd_get_and_print_gst_stat_entry_from_dump(duration);
+               if (ret != BATTERY_MONITOR_ERROR_NONE)
+                       _ERR("GST data dump failed");
+               ret = bd_get_and_print_gwst_stat_entry_from_dump(duration);
+               if (ret != BATTERY_MONITOR_ERROR_NONE)
+                       _ERR("GWST 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(duration);
+               if (ret != BATTERY_MONITOR_ERROR_NONE)
+                       _ERR("Battery Usage failed");
+
+               _DBG("DUMP COMPLETED/DELETE HASH TABLE");
 
+               g_hash_table_destroy(app_map);
                h_flag = true;
-//             fclose(fp);//TEMP
+               //fclose(fp);//TEMP
                EXIT;
                return BATTERY_MONITOR_ERROR_NONE;
 }
@@ -567,6 +954,7 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
 static int bd_set_history_from_listener(history_item_s* nrec)
 {
        ENTER;
+       BM_CHECK_INPUT_PARAM(nrec);
 
        int dvar1 = 0, dvar2 = 0;
        time_t current_time;
@@ -594,15 +982,12 @@ static int bd_set_history_from_listener(history_item_s* nrec)
 
        if (nrec->wakelock_tag != NULL)
                history_data[h_count].wakelock_tag = nrec->wakelock_tag;
-
        if (nrec->wakereason_tag != NULL)
                history_data[h_count].wakereason_tag = nrec->wakereason_tag;
-
        if (nrec->event_code != ET_NONE) {
                history_data[h_count].event_code = nrec->event_code;
                history_data[h_count].event_tag = nrec->event_tag;
        }
-
        if (nrec->cmd_s == CM_CRR_TIME || nrec->cmd_s == CM_RST)
                history_data[h_count].time_current = current_time;
 
@@ -616,7 +1001,6 @@ static int bd_set_history_from_listener(history_item_s* nrec)
                int ret = bd_print_history_item_main(0, current_time, 1);
                if (ret != BATTERY_MONITOR_ERROR_NONE)
                        return ret;
-
                h_count = 0;
        }
 
@@ -627,17 +1011,12 @@ static int bd_set_history_from_listener(history_item_s* nrec)
 int bd_store_history_item(history_item_s* nrec)
 {
        ENTER;
-
-       if (nrec == NULL) {
-               _ERR("Invalid history item");
-               return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
-       }
+       BM_CHECK_INPUT_PARAM(nrec);
 
        if (!h_flag) {
                _ERR("Data Dump in progress");
                return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
        }
-
        int ret = BATTERY_MONITOR_ERROR_NONE;
        ret = bd_set_history_from_listener(nrec);
        if (ret != BATTERY_MONITOR_ERROR_NONE) {
@@ -659,18 +1038,21 @@ int bd_set_old_state_to_history_item(history_item_s* nrec)
 }
 */
 
-/*
-//: remove this
+/*// remove this
 static int bd_test_fn()
 {
        ENTER;
 
        history_item_s ts;
 
-       ts.cmd_s = CM_UPD;
-       ts.time_s = 0;
-       ts.time_current = 0;
+       bd_print_history_item_reset(&ts);
+       ts.cmd_s = CM_CRR_TIME; ts.event_code = ET_NONE;
+       ts.event_tag = NULL; ts.wakelock_tag = NULL;
+       ts.wakereason_tag = NULL;
+       bd_set_history_from_listener(&ts);
 
+       ts.cmd_s = CM_UPD; ts.time_s = 0;
+       ts.time_current = 0;
        ts.state_1 = 0;
        ts.state_1 = ST1_WIFI_SCAN_FLAG;
        ts.state_1 |= (ST1_SCREEN_ON_FLAG);
@@ -688,9 +1070,10 @@ static int bd_test_fn()
                _DBG("Memory created successfully");
                GString *temp = ts.event_tag->string_info;
                temp = g_string_sized_new(30);
-               ts.event_tag->uid = 40;
+               BM_CHECK_MEM_ALLOC(temp, {});
+               ts.event_tag->uid = 0;
                ts.event_tag->sp_idx = 1;
-               temp = g_string_append(temp, "test-app");
+               temp = g_string_append(temp, "tizen");
                ts.event_tag->string_info = temp;
                _DBG("%s _1", ts.event_tag->string_info->str);
        }
@@ -715,8 +1098,8 @@ static int bd_make_string_maps()
 
        bd_test_fn();
        history_item_s ts;
-       bd_get_history_detail_from_dump(0, &ts);
-       bd_get_history_detail_from_dump(1, &ts);
+       for (int i = 0; i < h_count; i++)
+               bd_get_history_detail_from_dump(i, &ts);
        bd_print_history_item_main(0, 1576753138, true);
 
        EXIT;