Storing Data from Plugins 58/221958/3
authorDewal Agarwal <d1.agarwal@samsung.com>
Wed, 8 Jan 2020 11:00:21 +0000 (16:30 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Wed, 15 Jan 2020 06:07:12 +0000 (06:07 +0000)
Change-Id: Icd7892b79bbf04cfd02beed4461a3a4d89251add
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
include/bd_private.h [new file with mode: 0644]
include/bm_server_db.h
packaging/batterymonitor.spec
src/bm_power_engine.c
src/bm_server_db.c

diff --git a/include/bd_private.h b/include/bd_private.h
new file mode 100644 (file)
index 0000000..7b2c690
--- /dev/null
@@ -0,0 +1,160 @@
+/*
+ *  Battery-Monitor Dump
+ *
+ * Copyright (c) 2019 Samsung Electronics Co., Ltd. All rights reserved.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+#ifndef __BD_PRIVATE_H__
+#define __BD_PRIVATE_H__
+
+#include <stdlib.h>
+
+#ifdef __cplusplus
+extern "C"
+{
+#endif
+
+typedef struct _gbl_ble_stat_s {
+       long int time_s;
+       long int ble_idle_time;
+       long int ble_rx_time;
+       long int ble_tx_time;
+       long int ble_pwi_val;
+} bd_gl_ble_stat_s;
+
+typedef struct _gbl_wifi_stat_s {
+       long int time_s;
+       long int wifi_on_time;
+       long int wifi_conn_time;
+       long int wifi_idle_time;
+       long int wifi_rx_time;
+       long int wifi_tx_time;
+       long int wifi_pwi_val;
+} bd_gl_wifi_stat_s;
+
+typedef struct _gbl_ntw_stat_s {
+       long int time_s;
+       long int dn_rx_byt;
+       long int dn_tx_byt;
+       long int wifi_rx_byt;
+       long int wifi_tx_byt;
+       long int dn_rx_pkt;
+       long int dn_tx_pkt;
+       long int wifi_rx_pkt;
+       long int wifi_tx_pkt;
+} bd_gl_ntw_stat_s;
+
+typedef struct _gbl_sbr_stat_s {
+       long int time_s;
+       long int dark; //OFF
+       long int dim; // All are time values
+       long int medium;
+       long int light; //DEF: 0
+       long int bright;
+} bd_gl_sbr_stat_s;
+
+typedef struct _gbl_sig_stat_s {
+       long int time_s;
+       long int scan_time;
+       long int none_time;
+       long int poor_time;
+       long int med_time;
+       long int good_time;
+       long int grt_time;
+} bd_gl_sgt_stat_s;
+
+typedef struct _gbl_wst_stat_s {
+       long int time_s;
+       long int wscan_time;
+       long int wnone_time;
+       long int wpoor_time;
+       long int wmed_time;
+       long int wgood_time;
+       long int wgrt_time;
+} bd_gl_wst_stat_s;
+
+typedef struct _gbl_bst_stat_s {
+       long int time_s;
+       long int off_time;
+       long int low_time;
+       long int med_time;
+       long int high_time;
+} bd_gl_bst_stat_s;
+
+typedef enum {
+       BD_GBLESTAT_NONE = -1,
+       BD_GBLESTAT_IDLE,
+       BD_GBLESTAT_RX,
+       BD_GBLESTAT_TX,
+       BD_GBLESTAT_PWI_VAL,
+} BD_GBLESTAT_DB_IDX;
+
+typedef enum {
+       BD_GWFLSTAT_NONE = -1,
+       BD_GWFLSTAT_ON,
+       BD_GWFLSTAT_CON,
+       BD_GWFLSTAT_IDLE,
+       BD_GWFLSTAT_RX,
+       BD_GWFLSTAT_TX,
+       BD_GWFLSTAT_PWI_VAL,
+} BD_GWFLSTAT_DB_IDX;
+
+typedef enum {
+       BD_GNTWSTAT_NONE = -1,
+       BD_GNTWSTAT_DN_RXB,
+       BD_GNTWSTAT_DN_TXB,
+       BD_GNTWSTAT_WIFI_RXB,
+       BD_GNTWSTAT_WIFI_TXB,
+       BD_GNTWSTAT_DN_RXP,
+       BD_GNTWSTAT_DN_TXP,
+       BD_GNTWSTAT_WIFI_RXP,
+       BD_GNTWSTAT_WIFI_TXP,
+} BD_GNTWSTAT_DB_IDX;
+
+typedef enum {
+       BD_GSBRSTAT_NONE = -1,
+       BD_GSBRSTAT_DARK,
+       BD_GSBRSTAT_DIM,
+       BD_GSBRSTAT_MEDIUM,
+       BD_GSBRSTAT_LIGHT,
+       BD_GSBRSTAT_BRIGHT,
+} BD_GSBRSTAT_DB_IDX;
+
+typedef enum {
+       BD_GSGTSTAT_NONE = -1,
+       BD_GSGTSTAT_SCAN,
+       BD_GSGTSTAT_NO,
+       BD_GSGTSTAT_POOR,
+       BD_GSGTSTAT_MED,
+       BD_GSGTSTAT_GOOD,
+       BD_GSGTSTAT_GRT,
+} BD_GSGTSTAT_DB_IDX;
+
+// Check if separate enums are really reqiured for wst?
+
+typedef enum {
+       BD_GBSTSTAT_NONE = -1,
+       BD_GBSTSTAT_OFF,
+       BD_GBSTSTAT_LOW,
+       BD_GBSTSTAT_MED,
+       BD_GBSTSTAT_HIGH,
+} BD_GBSTSTAT_DB_IDX;
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __BD_PRIVATE_H__*/
index 71a1083..a87aa39 100644 (file)
@@ -78,6 +78,81 @@ BM_RESOURCE_ID_MAX,
 "usage INT "\
 ");"
 
+#define GBL_BLE_STAT_SCHEMA "create table gble_stat \n"\
+       "(\n"\
+"time_s LONG INT, "\
+"ble_idle_time INT, "\
+"ble_rx_time INT, "\
+"ble_tx_time INT, "\
+"ble_pwi_val INT "\
+");"
+
+
+#define GBL_WFL_STAT_SCHEMA "create table gwfl_stat \n"\
+       "(\n"\
+"time_s LONG INT, "\
+"wifi_on_time INT, "\
+"wifi_conn_time INT, "\
+"wifi_idle_time INT, "\
+"wifi_rx_time INT, "\
+"wifi_tx_time INT, "\
+"wifi_pwi_val INT "\
+");"
+
+#define GBL_NT_STAT_SCHEMA "create table gn_stat \n"\
+       "(\n"\
+"time_s LONG INT, "\
+"dn_rx_byt INT, "\
+"dn_tx_byt INT, "\
+"wifi_rx_byt INT, "\
+"wifi_tx_byt INT, "\
+"dn_rx_pkt INT, "\
+"dn_tx_pkt INT, "\
+"wifi_rx_pkt INT, "\
+"wifi_tx_pkt INT "\
+");"
+
+#define GBL_BR_STAT_SCHEMA "create table gbr_stat \n"\
+       "(\n"\
+"time_s LONG INT, "\
+"dark INT, "\
+"dim INT, "\
+"medium INT, "\
+"light INT, "\
+"bright INT "\
+");"
+
+#define GBL_SGT_STAT_SCHEMA "create table gsgt_stat \n"\
+       "(\n"\
+"time_s LONG INT, "\
+"scan_time INT, "\
+"none_time INT, "\
+"poor_time INT, "\
+"med_time INT, "\
+"good_time INT, "\
+"grt_time INT "\
+");"
+
+#define GBL_WST_STAT_SCHEMA "create table gwst_stat \n"\
+       "(\n"\
+"time_s LONG INT, "\
+"wscan_time INT, "\
+"wnone_time INT, "\
+"wpoor_time INT, "\
+"wmed_time INT, "\
+"wgood_time INT, "\
+"wgrt_time INT "\
+");"
+
+#define GBL_BST_STAT_SCHEMA "create table gbst_stat \n"\
+       "(\n"\
+"time_s LONG INT, "\
+"off_time INT, "\
+"low_time INT, "\
+"med_time INT, "\
+"high_time INT "\
+");"
+
 #define OWNER_ROOT 0
 
 /* Macros of Time Duration */
@@ -89,9 +164,16 @@ BM_RESOURCE_ID_MAX,
 #define BATTERY_MONITOR_APP_ID_MAP_TABLE               "appid_map"
 #define BATTERY_MONITOR_APP_ID_USAGE_TABLE             "appid_usage"
 #define BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE                "resourceid_usage"
+#define BATTERY_MONITOR_GBL_BLE_STAT_TABLE             "gble_stat"
+#define BATTERY_MONITOR_GBL_WFL_STAT_TABLE             "gwfl_stat"
+#define BATTERY_MONITOR_GBL_NT_STAT_TABLE              "gn_stat"
+#define BATTERY_MONITOR_GBL_BR_STAT_TABLE              "gbr_stat"
+#define BATTERY_MONITOR_GBL_SGT_STAT_TABLE             "gsgt_stat"
+#define BATTERY_MONITOR_GBL_WST_STAT_TABLE             "gwst_stat"
+#define BATTERY_MONITOR_GBL_BST_STAT_TABLE             "gbst_stat"
 #define BATTERY_MONITOR_SQLITE_SEQ                     "sqlite_sequence"
 #define BATTERY_MONITOR_SQL_LEN_MAX                    1024
-#define BATTERY_MONITOR_TABLE_COUNT                    3
+#define BATTERY_MONITOR_TABLE_COUNT                    10
 
 typedef sqlite3_stmt *bm_stmt;
 
@@ -108,6 +190,8 @@ resourceid_usage_s *bm_server_query_resource_usage_resourceid(const char *resour
 
 int bm_server_resource_usage_insert_to_db(resourceid_usage_s *bm_resource_type);
 
+int bm_server_battery_dump_insert_to_db(void* str_data, int type);
+
 int bm_server_delete_table_by_appid(const char* app_id);
 
 int bm_server_delete_table_by_time_interval(void);
index d7a1a21..b01fab6 100644 (file)
@@ -1,6 +1,6 @@
 Name:          batterymonitor
 Summary:       batterymonitor service daemon
-Version:       0.0.2
+Version:       0.0.3
 Release:       1
 License:       Apache-2.0
 Source0:       %{name}-%{version}.tar.gz
@@ -81,6 +81,17 @@ then
        CREATE TABLE if not exists appid_usage (AppId TEXT, log_time INT, rId_ble INT, rId_wifi INT, rId_cpu INT, rId_display INT, rId_device_network INT,
        rId_gps INT, rId_hrm INT, rId_battery INT, rId_newone INT, rId_newtwo INT, rId_newthree INT);
        CREATE TABLE if not exists resourceid_usage (ResourceId TEXT, log_time INT, usage INT);
+       CREATE TABLE if not exists gble_stat (time_s LONG INT, ble_idle_time INT, ble_rx_time INT, ble_tx_time INT, ble_pwi_val INT);
+       CREATE TABLE if not exists gwfl_stat (time_s LONG INT, wifi_on_time INT, wifi_conn_time INT, wifi_idle_time INT,
+       wifi_rx_time INT, wifi_tx_time INT, wifi_pwi_val INT);
+       CREATE TABLE if not exists gn_stat (time_s LONG INT, dn_rx_byt INT, dn_tx_byt INT, wifi_rx_byt INT, wifi_tx_byt INT,
+       dn_rx_pkt INT, dn_tx_pkt INT, wifi_rx_pkt INT, wifi_tx_pkt INT);
+       CREATE TABLE if not exists gbr_stat (time_s LONG INT, dark INT, dim INT, medium INT, light INT, bright INT);
+       CREATE TABLE if not exists gsgt_stat (time_s LONG INT, scan_time INT, none_time INT, poor_time INT, med_time INT,
+       good_time INT, grt_time INT);
+       CREATE TABLE if not exists gwst_stat (time_s LONG INT, wscan_time INT, wnone_time INT, wpoor_time INT, wmed_time INT,
+       wgood_time INT, wgrt_time INT);
+       CREATE TABLE if not exists gbst_stat (time_s LONG INT, off_time INT, low_time INT, med_time INT, high_time INT);
 '
 fi
 
index cced36b..e06508a 100644 (file)
@@ -25,6 +25,7 @@
 #include "bm_plugin_manager.h"
 #include "bm_server_db.h"
 #include "bm_private.h"
+#include "bd_private.h"
 #include "bm_util.h"
 
 bm_feature_data_h bm_data_handle = NULL;
@@ -398,10 +399,8 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
 
        GSList *bt_data_iterator = NULL;
        GSList *bt_atm_iterator = NULL;
-
        void *prv_data = NULL;
        void *prv_app_id = NULL;
-
        int ret_val = BATTERY_MONITOR_ERROR_NONE;
 
        /* creating hash-map with (key, value) = (app-id, data) */
@@ -409,60 +408,40 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
 
        long int edTime = 0, stTime = 0;
        int sesTime = 0, scTime = 0, conTime = 0, RX = 0, TX = 0, onTime = 0;
-
        /* iterating over list for data accumulation */
        for (bt_data_iterator = handle->bt_data_list; bt_data_iterator; bt_data_iterator = bt_data_iterator->next) {
-
                bm_bluetooth_st *datalistnode = (bm_bluetooth_st *)(bt_data_iterator->data);
-
                edTime = datalistnode->stopTime;
                stTime = datalistnode->startTime;
                scTime += datalistnode->scanTime;
                conTime += datalistnode->connectedTime;
                sesTime += (edTime-stTime);
-
-               //bt_atm_iterator = ((bm_bluetooth_st *)(bt_data_iterator->data))->atm_list;
                bt_atm_iterator = datalistnode->atm_list;
-
                for ( ; bt_atm_iterator; bt_atm_iterator = bt_atm_iterator->next) {
-
                        app_time_map_st2 *bt_atm_node = NULL;
                        bt_atm_node = bt_atm_iterator->data;
-
                        if (!bt_atm_node) {
                                _DBG("no data available");
                                continue;
                        }
-
                        _DBG("bt data available");
-
                        RX += bt_atm_node->rx;
                        TX += bt_atm_node->tx;
                        onTime += bt_atm_node->time;
-
                        prv_data = NULL;
                        prv_app_id = NULL;
-
                        if (g_hash_table_lookup_extended(hash, bt_atm_node->app_id, &prv_app_id, &prv_data) == true) {
-
                                _DBG("previous app_id = %s", (char *)prv_app_id);
-
                                app_time_map_st2 *temp = (app_time_map_st2 *)prv_data;
-
                                bt_atm_node->time += temp->time;
                                bt_atm_node->rx += temp->rx;
                                bt_atm_node->tx += temp->tx;
-
                                _DBG("update - app_id(%s), time(%d), rx(%d), tx(%d)", bt_atm_node->app_id,
                                                bt_atm_node->time, bt_atm_node->rx, bt_atm_node->tx);
-
                                _INFO("updated - %d", g_hash_table_replace(hash, bt_atm_node->app_id, bt_atm_node));
-
                        } else {
-
                                _DBG("insert - app_id(%s), time(%d), rx(%d), tx(%d)", bt_atm_node->app_id,
                                                bt_atm_node->time, bt_atm_node->rx, bt_atm_node->tx);
-
                                _INFO("inserted - %d", g_hash_table_insert(hash, bt_atm_node->app_id, bt_atm_node));
                        }
                }
@@ -477,28 +456,22 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
 
        _DBG("received bt power params - idle[%d], scan[%d], connected[%d], rx[%d], tx[%d]",
                        sP_power_bt_idle, sP_power_bt_scan, sP_power_bt_conn, sP_power_bt_tx, sP_power_bt_rx);
-
        /* BT power consumption Level - 1 at the Resource Level */
        int P_power_bt = 0, P_power_data = 0, P_power_conn = 0;
-
        P_power_conn = ((sP_power_bt_idle) * (sesTime - (scTime + conTime))) + ((sP_power_bt_scan) * (scTime)) + ((sP_power_bt_conn) * (conTime));
-
        P_power_data = ((sP_power_bt_tx) * TX) + ((sP_power_bt_rx) * RX);
-
        P_power_bt = P_power_conn + P_power_data;
 
        _DBG("Calculated Power for Bluetooth P_power_bt(%d),  P_power_conn (%d), P_power_data(%d)", P_power_bt, P_power_conn, P_power_data);
-
        /* BT power consumption Level - 2 at the Application Level */
        GHashTableIter iter;
        gpointer key, value;
-
        g_hash_table_iter_init(&iter, hash);
 
        int P_power_app_bt = 0, P_power_app_data = 0, P_power_app_conn = 0;
        char *appid = NULL;
        int apprx = 0, apptx = 0, apptime = 0;
-
+       long int rx_t = 0, tx_t = 0;
        long int ret_time = bm_get_log_time();
 
        appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
@@ -508,19 +481,14 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
        }
 
        while (g_hash_table_iter_next(&iter, &key, &value)) {
-
-               P_power_app_bt = 0; P_power_app_data = 0 ; P_power_app_conn = 0;
+               P_power_app_bt = 0, P_power_app_data = 0, P_power_app_conn = 0;
                apprx = 0, apptx = 0, apptime = 0;
-
                app_time_map_st2 *temp = (app_time_map_st2 *)value;
-
                appid = temp->app_id;
-               apprx = temp->rx;
-               apptx = temp->tx;
+               apprx = temp->rx; rx_t += apprx;
+               apptx = temp->tx; tx_t += apptx;
                apptime = temp->time;
-
                P_power_app_data = ((sP_power_bt_tx) * apptx) + ((sP_power_bt_rx) * apprx);
-
                if (onTime != 0)
                        P_power_app_conn = (P_power_conn * apptime)/onTime; //check for 0 denominator & same units
                P_power_app_bt = P_power_app_data + P_power_app_conn;
@@ -528,11 +496,9 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
                app_usage->AppId = appid;
                app_usage->rId_ble = P_power_app_bt;
                app_usage->log_time = ret_time;
-
                /* Call Insert Function */
                _DBG("Calculated Power for Appid(%s) -  P_power_app_bt(%d), P_power_app_conn(%d), P_power_app_data(%d)",
                                        appid, P_power_app_bt, P_power_app_conn, P_power_app_data);
-
                if (mode) {
                        ret_val = bm_server_appid_insert_to_db(app_usage->AppId);
                        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
@@ -540,8 +506,6 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
                        ret_val = bm_server_app_usage_insert_to_db(app_usage);
                } else/* Call Global Hash */
                        ret_val = bm_appid_session_usage_map(g_strdup(app_usage->AppId), app_usage->rId_ble, BM_PLUGIN_ID_BLE);
-
-               /* Error Check */
                if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                        _ERR("Insert of BT App failed ");
                else
@@ -561,15 +525,31 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
        res_usage->usage = P_power_bt;
 
        ret_val = bm_server_resource_usage_insert_to_db(res_usage);
-       /* Error Check */
        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                _ERR("Insert of BT resource failed ");
-       else
-               _DBG("Insert successful");
 
        bm_appid_usage_free(app_usage);
        bm_resourceid_usage_free(res_usage);
 
+       bd_gl_ble_stat_s *gble_st = (bd_gl_ble_stat_s *)calloc(1, sizeof(bd_gl_ble_stat_s));
+       if (gble_st == NULL) {
+               _ERR("memory allocation failed");
+               return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+       }
+       gble_st->time_s = ret_time; gble_st->ble_idle_time = (sesTime - (scTime + conTime));
+       if (tx_t != 0 || rx_t != 0) {
+               gble_st->ble_rx_time = (conTime * rx_t) / (rx_t + tx_t);
+               gble_st->ble_tx_time = (conTime * tx_t) / (rx_t + tx_t);
+       }
+       gble_st->ble_pwi_val = P_power_bt;
+
+       ret_val = bm_server_battery_dump_insert_to_db(gble_st, 0);
+       if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+               _ERR("Insert of GBLE failed ");
+       else
+               _DBG("Insert successful");
+       BM_FREE(gble_st);
+       //Add bst times
        /* Free the hash map */
        g_hash_table_destroy(hash);
 
@@ -585,28 +565,20 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
 
        GSList *wifi_data_iterator = NULL;
        GSList *wifi_atm_iterator = NULL;
-
        void *prv_data = NULL;
        void *prv_app_id = NULL;
-
        int ret_val = BATTERY_MONITOR_ERROR_NONE;
 
        /* creating hash-map with (key, value) = (app-id, data) */
        GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st2_free);
 
-       long int edTime = 0;
-       long int stTime = 0;
-       int sesTime = 0;
-       int scTime = 0;
+       long int edTime = 0, stTime = 0;
+       int sesTime = 0, scTime = 0, onTime = 0 /*applications*/, tl_total = 0;
        int tl0 = 0, tl1 = 0, tl2 = 0, tl3 = 0, tl4 = 0;
-       int RX = 0, TX = 0;
-       int onTime = 0;
-
+       long int RX = 0, TX = 0;
        /* iterating over list for data accumulation */
        for (wifi_data_iterator = handle->wifi_data_list; wifi_data_iterator; wifi_data_iterator = wifi_data_iterator->next) {
-
                bm_wifi_st *datalistnode = (bm_wifi_st *)(wifi_data_iterator->data);
-
                edTime = datalistnode->endTime;
                stTime = datalistnode->startTime;
                sesTime += edTime - stTime;
@@ -616,48 +588,32 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
                tl2 += datalistnode->time_level_2;
                tl3 += datalistnode->time_level_3;
                tl4 += datalistnode->time_level_4;
-
                wifi_atm_iterator = datalistnode->atm_list;
-
                for ( ; wifi_atm_iterator; wifi_atm_iterator = wifi_atm_iterator->next) {
-
                        app_time_map_st2 *wifi_atm_node = NULL;
                        wifi_atm_node = wifi_atm_iterator->data;
-
                        if (!wifi_atm_node) {
                                _DBG("no data available");
                                continue;
                        }
-
                        _DBG("wifi data available");
-
                        RX += wifi_atm_node->rx;
                        TX += wifi_atm_node->tx;
                        onTime += wifi_atm_node->time;
-
                        prv_app_id = NULL;
                        prv_data = NULL;
-
                        if (g_hash_table_lookup_extended(hash, wifi_atm_node->app_id, &prv_app_id, &prv_data) == true) {
-
                                _DBG("previous app_id = %s", (char *)prv_app_id);
-
                                app_time_map_st2 *temp = (app_time_map_st2 *)prv_data;
-
                                wifi_atm_node->time += temp->time;
                                wifi_atm_node->rx += temp->rx;
                                wifi_atm_node->tx += temp->tx;
-
                                _DBG("update - app_id(%s), time(%d), rx(%d), tx(%d)", wifi_atm_node->app_id,
                                                wifi_atm_node->time, wifi_atm_node->rx, wifi_atm_node->tx);
-
                                _INFO("updated - %d", g_hash_table_replace(hash, wifi_atm_node->app_id, wifi_atm_node));
-
                        } else {
-
                                _DBG("insert - app_id(%s), time(%d), rx(%d), tx(%d)", wifi_atm_node->app_id,
                                                wifi_atm_node->time, wifi_atm_node->rx, wifi_atm_node->tx);
-
                                _INFO("inserted - %d", g_hash_table_insert(hash, wifi_atm_node->app_id, wifi_atm_node));
                        }
                }
@@ -676,34 +632,26 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
                        idle[%d], rx[%d], tx[%d]", sP_power_wf_tl0, sP_power_wf_tl1, sP_power_wf_tl2, sP_power_wf_tl3,
                        sP_power_wf_tl4, sP_power_wf_scan, sP_power_wf_idle, sP_power_wf_rx, sP_power_wf_tx);
 
-       int tl_total = 0;
-
        tl_total = tl0 + tl1 + tl2 + tl3 + tl4;
-
        /* Wifi power consumption Level - 1 at the Resource Level */
        int P_power_wifi = 0; int P_power_data = 0; int P_power_conn = 0;
-
        P_power_conn = ((sP_power_wf_tl0 * tl0) + (sP_power_wf_tl1 * tl1) +
                        (sP_power_wf_tl2 * tl2) + (sP_power_wf_tl3 * tl3) +
                        (sP_power_wf_tl4 * tl4) + (sP_power_wf_scan * scTime) +
-                       (sP_power_wf_idle * tl_total));
-
+                       (sP_power_wf_idle * (sesTime - (tl_total + scTime))));
        P_power_data = ((sP_power_wf_tx) * TX) + ((sP_power_wf_rx) * RX);
-
        P_power_wifi = P_power_conn + P_power_data;
 
        _DBG("Calculated Power for Wifi P_power_wifi(%d),  P_power_conn (%d), P_power_data(%d)", P_power_wifi, P_power_conn, P_power_data);
-
        /* Wifi power consumption Level - 2 at the Application Level */
        GHashTableIter iter;
        gpointer key, value;
-
        g_hash_table_iter_init(&iter, hash);
 
        int P_power_app_wifi = 0, P_power_app_data = 0, P_power_app_conn = 0;
        char *appid = NULL;
        int apprx = 0, apptx = 0, apptime = 0;
-
+       long int rx_t = 0, tx_t = 0;
        long int ret_time = bm_get_log_time();
 
        appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
@@ -713,16 +661,13 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
        }
 
        while (g_hash_table_iter_next(&iter, &key, &value)) {
-               P_power_app_wifi = 0; P_power_app_data = 0 ; P_power_app_conn = 0;
+               P_power_app_wifi = 0; P_power_app_data = 0; P_power_app_conn = 0;
                apprx = 0, apptx = 0, apptime = 0;
-
                app_time_map_st2 *temp = (app_time_map_st2 *)value;
-
                appid = temp->app_id;
-               apprx = temp->rx;
-               apptx = temp->tx;
+               apprx = temp->rx; rx_t += apprx;
+               apptx = temp->tx; tx_t += apptx;
                apptime = temp->time;
-
                P_power_app_data = ((sP_power_wf_tx) * apptx) + ((sP_power_wf_rx) * apprx);
 
                if (onTime != 0)
@@ -732,7 +677,6 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
                app_usage->AppId = appid;
                app_usage->rId_wifi = P_power_app_wifi;
                app_usage->log_time = ret_time;
-
                /* Call Insert Function */
                _DBG("Calculated Power for Appid(%s) -  P_power_app_wifi(%d), P_power_app_conn(%d), P_power_app_data(%d)",
                                        appid, P_power_app_wifi, P_power_app_conn, P_power_app_data);
@@ -744,8 +688,6 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
                        ret_val = bm_server_app_usage_insert_to_db(app_usage);
                } else/* Call Global Hash */
                        ret_val = bm_appid_session_usage_map(g_strdup(app_usage->AppId), app_usage->rId_wifi, BM_PLUGIN_ID_WIFI);
-
-               /* Error Check */
                if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                        _ERR("Insert of Wifi App failed ");
                else
@@ -765,7 +707,6 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
        res_usage->usage = P_power_wifi;
 
        ret_val = bm_server_resource_usage_insert_to_db(res_usage);
-       /* Error Check */
        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                _ERR("Insert of Wifi resource failed ");
        else
@@ -774,6 +715,38 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
        bm_appid_usage_free(app_usage);
        bm_resourceid_usage_free(res_usage);
 
+       bd_gl_wifi_stat_s *gwfl_st = (bd_gl_wifi_stat_s *)calloc(1, sizeof(bd_gl_wifi_stat_s));
+       if (gwfl_st == NULL) {
+               _ERR("memory allocation failed");
+               return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+       }
+       gwfl_st->time_s = ret_time; gwfl_st->wifi_on_time = sesTime;
+       gwfl_st->wifi_conn_time = tl_total; gwfl_st->wifi_idle_time = (sesTime - (tl_total + scTime));
+       if (tx_t != 0 || rx_t != 0) {
+               gwfl_st->wifi_rx_time = (tl_total * rx_t) / (rx_t + tx_t);
+               gwfl_st->wifi_tx_time = (tl_total * tx_t) / (rx_t + tx_t);
+       }
+       ret_val = bm_server_battery_dump_insert_to_db(gwfl_st, 1);
+       if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+               _ERR("Insert of GWFL failed ");
+       else
+               _DBG("Insert successful");
+       BM_FREE(gwfl_st);
+       bd_gl_wst_stat_s *gwst_st = (bd_gl_wst_stat_s *)calloc(1, sizeof(bd_gl_wst_stat_s));
+       if (gwst_st == NULL) {
+               _ERR("memory allocation failed");
+               return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+       }
+       gwst_st->time_s = ret_time; gwst_st->wscan_time = scTime;
+       gwst_st->wnone_time = tl0; gwst_st->wpoor_time = tl1; gwst_st->wmed_time = tl2;
+       gwst_st->wgood_time = tl3; gwst_st->wgrt_time = tl4;
+       ret_val = bm_server_battery_dump_insert_to_db(gwst_st, 5);
+       if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+               _ERR("Insert of GWFL failed ");
+       else
+               _DBG("Insert successful");
+       BM_FREE(gwst_st);
+
        /* Free the Hash Map */
        g_hash_table_destroy(hash);
 
@@ -789,10 +762,8 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
 
        GSList *cpu_data_iterator = NULL;
        GSList *cpu_atm_iterator = NULL;
-
        void *prv_data = NULL;
        void *prv_app_id = NULL;
-
        int ret_val = BATTERY_MONITOR_ERROR_NONE;
 
        /* creating hash-map with (key, value) = (app-id, data) */
@@ -801,46 +772,30 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
        int fgTime = 0;
        int bgTime = 0;
        int onTime = 0;
-
        /* iterating over list for data accumulation */
        for (cpu_data_iterator = handle->cpu_data_list; cpu_data_iterator; cpu_data_iterator = cpu_data_iterator->next) {
-
                bm_cpu_st *datalistnode = (bm_cpu_st *)(cpu_data_iterator->data);
                fgTime += datalistnode->cpuTimeForeground;
                bgTime += datalistnode->cpuTimeBackground;
-
                cpu_atm_iterator = datalistnode->atm_list;
-
                for ( ; cpu_atm_iterator; cpu_atm_iterator = cpu_atm_iterator->next) {
                        app_time_map_st1 *cpu_atm_node = (app_time_map_st1 *)cpu_atm_iterator->data;
                        if (!cpu_atm_node) {
                                _DBG("no data available");
                                continue;
                        }
-
                        _DBG("cpu data available");
-
                        onTime += cpu_atm_node->time;
-
                        prv_app_id = NULL;
                        prv_data = NULL;
-
                        if (g_hash_table_lookup_extended(hash, cpu_atm_node->app_id, &prv_app_id, &prv_data) == true) {
-
                                _DBG("previous app_id = %s", (char *)prv_app_id);
-
                                app_time_map_st1 *cpu_atm_prv_node = (app_time_map_st1 *)prv_data;
-
                                cpu_atm_node->time += cpu_atm_prv_node->time;
-
                                _DBG("update - app_id(%s), time(%d)", cpu_atm_node->app_id, cpu_atm_node->time);
-
                                _INFO("updated - %d", g_hash_table_replace(hash, cpu_atm_node->app_id, cpu_atm_node));
-
                        } else {
-
                                _DBG("insert - app_id(%s), time(%d)", cpu_atm_node->app_id, cpu_atm_node->time);
-
                                _INFO("inserted - %d", g_hash_table_insert(hash, cpu_atm_node->app_id, cpu_atm_node));
                        }
                }
@@ -855,24 +810,19 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
        _DBG("received cpu power params - fg[%d]\n, bg[%d]\n", sP_power_cpu_fg, sP_power_cpu_bg);
        /* CPU power consumption Level - 1 at the Resource Level */
        int P_power_cpu = 0, P_power_fg = 0, P_power_bg = 0;
-
        P_power_fg = ((sP_power_cpu_fg * fgTime));
        P_power_bg = ((sP_power_cpu_bg * bgTime));
-
        P_power_cpu = P_power_bg + P_power_fg;
 
        _DBG("Calculated Power for CPU P_power_cpu (%d),  P_power_bg (%d), P_power_fg (%d)", P_power_cpu, P_power_bg, P_power_fg);
-
        /* CPU power consumption Level - 2 at the Application Level */
        GHashTableIter iter;
        gpointer key, value;
-
        g_hash_table_iter_init(&iter, hash);
 
        int P_power_app_cpu = 0, P_power_app_use = 0;
        char *appid = NULL;
        int apptime = 0;
-
        long int ret_time = bm_get_log_time();
 
        appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
@@ -884,12 +834,9 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                P_power_app_cpu = 0; P_power_app_use = 0;
                apptime = 0;
-
                app_time_map_st1 *temp = (app_time_map_st1 *)value;
-
                appid = temp->app_id;
                apptime = temp->time;
-
                if (onTime != 0)
                        P_power_app_use = (P_power_cpu * apptime)/onTime; //check for 0 denominator & same units
                P_power_app_cpu = P_power_app_use;
@@ -897,7 +844,6 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
                app_usage->AppId = appid;
                app_usage->rId_cpu = P_power_app_cpu;
                app_usage->log_time = ret_time;
-
                /* Call Insert Function */
                _DBG("Calculated Power for Appid (%s) P_power_app_cpu (%d),  P_power_app_use (%d)", appid, P_power_app_cpu, P_power_app_use);
 
@@ -915,7 +861,6 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
                        _DBG("Insert successful");
        }
 
-       /* commit to database the output after power calculation */
        resourceid_usage_s *res_usage = (resourceid_usage_s *)calloc(1, sizeof(resourceid_usage_s));
        if (res_usage == NULL) {
                _ERR("memory allocation failed");
@@ -928,11 +873,8 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
        res_usage->usage = P_power_cpu;
 
        ret_val = bm_server_resource_usage_insert_to_db(res_usage);
-       /* Error Check */
        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                _ERR("Insert of CPU resource failed ");
-       else
-               _DBG("Insert successful");
 
        bm_appid_usage_free(app_usage);
        bm_resourceid_usage_free(res_usage);
@@ -952,10 +894,8 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
 
        GSList *dp_data_iterator = NULL;
        GSList *dp_atm_iterator = NULL;
-
        void *prv_data = NULL;
        void *prv_app_id = NULL;
-
        int ret_val = BATTERY_MONITOR_ERROR_NONE;
 
        /* creating hash-map with (key, value) = (app-id, data) */
@@ -963,14 +903,10 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
 
        long int edTime = 0;
        long int stTime = 0;
-       int sesTime = 0;
-
+       int sesTime = 0, onTime = 0;
        int highTime = 0, medTime = 0, lowTime = 0;
-       int onTime = 0;
-
        /* iterating over list for data accumulation */
        for (dp_data_iterator = handle->display_list; dp_data_iterator; dp_data_iterator = dp_data_iterator->next) {
-
                bm_display_st *datalistnode = (bm_display_st *)(dp_data_iterator->data);
                edTime = datalistnode->stop;
                stTime = datalistnode->start;
@@ -978,41 +914,25 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
                medTime += datalistnode->med;
                lowTime += datalistnode->low;
                sesTime += edTime - stTime;
-
                dp_atm_iterator = datalistnode->atm_list;
-
                for ( ; dp_atm_iterator; dp_atm_iterator = dp_atm_iterator->next) {
-
                        app_time_map_st1 *dp_atm_node = (app_time_map_st1 *)dp_atm_iterator->data;
-
                        if (!dp_atm_node) {
                                _DBG("no data available");
                                continue;
                        }
-
                        _DBG("display data available");
-
                        onTime += dp_atm_node->time;
-
                        prv_data = NULL;
                        prv_app_id = NULL;
-
                        if (g_hash_table_lookup_extended(hash, dp_atm_node->app_id, &prv_app_id, &prv_data) == true) {
-
                                _DBG("previous app_id = %s", (char *)prv_app_id);
-
                                app_time_map_st1 *dp_atm_prv_node = (app_time_map_st1 *)prv_data;
-
                                dp_atm_node->time += dp_atm_prv_node->time;
-
                                _DBG("update - app_id(%s), time(%d)", dp_atm_node->app_id, dp_atm_node->time);
-
                                _INFO("updated - %d", g_hash_table_replace(hash, dp_atm_node->app_id, dp_atm_node));
-
                        } else {
-
                                _DBG("insert - app_id(%s), time(%d)", dp_atm_node->app_id, dp_atm_node->time);
-
                                _INFO("inserted - %d", g_hash_table_insert(hash, dp_atm_node->app_id, dp_atm_node));
                        }
                }
@@ -1026,24 +946,19 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
                _ERR("failed to get cpu power params");
 
        _DBG("received display power params - high[%d], medium[%d], low[%d]", sP_power_dp_high, sP_power_dp_med, sP_power_dp_low);
-
        /* Display power consumption Level - 1 at the Resource Level */
        int P_power_disp = 0, P_power_on = 0;
        P_power_on = ((sP_power_dp_low * lowTime) + (sP_power_dp_med * medTime) * (sP_power_dp_high * highTime));
-
        P_power_disp = P_power_on;
        _DBG("Calculated Power for Display P_power_disp (%d),  P_power_on (%d)", P_power_disp, P_power_on);
-
        /* Display power consumption Level - 2 at the Application Level */
        GHashTableIter iter;
        gpointer key, value;
-
        g_hash_table_iter_init(&iter, hash);
 
        int P_power_app_disp = 0, P_power_app_on = 0;
        char *appid = NULL;
        int apptime = 0;
-
        long int ret_time = bm_get_log_time();
 
        appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
@@ -1055,9 +970,7 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                P_power_app_disp = 0; P_power_app_on = 0;
                apptime = 0;
-
                app_time_map_st1 *temp = (app_time_map_st1 *)value;
-
                appid = temp->app_id;
                apptime = temp->time;
 
@@ -1068,7 +981,6 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
                app_usage->AppId = appid;
                app_usage->rId_display = P_power_app_disp;
                app_usage->log_time = ret_time;
-
                /* Call Insert Function */
                _DBG("Calculated Power for Appid (%s) P_power_app_disp(%d),  P_power_app_on (%d)", appid, P_power_app_disp, P_power_app_on);
                if (mode) {
@@ -1098,16 +1010,30 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
        res_usage->usage = P_power_disp;
 
        ret_val = bm_server_resource_usage_insert_to_db(res_usage);
-       /* Error Check */
        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                _ERR("Insert of Display resource failed ");
        else
                _DBG("Insert successful");
 
-
        bm_appid_usage_free(app_usage);
        bm_resourceid_usage_free(res_usage);
 
+       bd_gl_sbr_stat_s *gbr_st = (bd_gl_sbr_stat_s *)calloc(1, sizeof(bd_gl_sbr_stat_s));
+       if (gbr_st == NULL) {
+               _ERR("memory allocation failed");
+               return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+       }
+
+       gbr_st->time_s = ret_time; gbr_st->dark = BATTERY_MONITOR_GET_DATA_JOB_PERIOD;
+       gbr_st->dark -= sesTime; gbr_st->dim = lowTime; gbr_st->medium = medTime;
+       gbr_st->bright = highTime;
+
+       ret_val = bm_server_battery_dump_insert_to_db(gbr_st, 3);
+       if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+               _ERR("Insert of GBR failed ");
+       else
+               _DBG("Insert GBR successful");
+       BM_FREE(gbr_st);
        /* Free the Hash Map */
        g_hash_table_destroy(hash);
 
@@ -1123,22 +1049,17 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
 
        GSList *dn_data_iterator = NULL;
        GSList *dn_atm_iterator = NULL;
-
        void *prv_data = NULL;
        void *prv_app_id = NULL;
-
        int ret_val = BATTERY_MONITOR_ERROR_NONE;
 
        /* creating hash-map with (key, value) = (app-id, data) */
        GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st2_free);
 
-       /* Session variables for Data accumulation */
        int tl0 = 0, tl1 = 0, tl2 = 0, tl3 = 0, tl4 = 0, tl5 = 0, tl6 = 0;
-       int RX = 0, TX = 0;
-
+       long int RX = 0, TX = 0, tl_total = 0;
        /* iterating over list for data accumulation */
        for (dn_data_iterator = handle->dn_data_list; dn_data_iterator; dn_data_iterator = dn_data_iterator->next) {
-
                bm_device_network_st *datalistnode = (bm_device_network_st *)(dn_data_iterator->data);
                tl0 += datalistnode->time_level_0;
                tl1 += datalistnode->time_level_1;
@@ -1147,46 +1068,30 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
                tl4 += datalistnode->time_level_4;
                tl5 += datalistnode->time_level_5;
                tl6 += datalistnode->time_level_6;
-
                dn_atm_iterator = datalistnode->atm_list;
-
                for ( ; dn_atm_iterator; dn_atm_iterator = dn_atm_iterator->next) {
-
                        app_time_map_st2 *dn_atm_node = (app_time_map_st2 *)dn_atm_iterator->data;
-
                        if (!dn_atm_node) {
                                _DBG("no data available");
                                continue;
                        }
-
                        _DBG("device-network data available");
-
                        RX += dn_atm_node->rx;
                        TX += dn_atm_node->tx;
-
                        prv_data = NULL;
                        prv_app_id = NULL;
-
                        if (g_hash_table_lookup_extended(hash, dn_atm_node->app_id, &prv_app_id, &prv_data) == true) {
-
                                _DBG("previous app_id = %s", (char *)prv_app_id);
-
                                app_time_map_st2 *dn_atm_prv_node = (app_time_map_st2 *)prv_data;
-
                                dn_atm_node->time += dn_atm_prv_node->time;
                                dn_atm_node->rx += dn_atm_prv_node->rx;
                                dn_atm_node->tx += dn_atm_prv_node->tx;
-
                                _DBG("update - app_id(%s), time(%d), rx(%d), tx(%d)", dn_atm_node->app_id,
                                                dn_atm_node->time, dn_atm_node->rx, dn_atm_node->tx);
-
                                _INFO("updated - %d", g_hash_table_replace(hash, dn_atm_node->app_id, dn_atm_node));
-
                        } else {
-
                                _DBG("insert - app_id(%s), time(%d), rx(%d), tx(%d)", dn_atm_node->app_id,
                                                dn_atm_node->time, dn_atm_node->rx, dn_atm_node->tx);
-
                                _INFO("inserted - %d", g_hash_table_insert(hash, dn_atm_node->app_id, dn_atm_node));
                        }
                }
@@ -1200,34 +1105,27 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
                        &sP_power_dn_tl4, &sP_power_dn_tl5, &sP_power_dn_tl6, &sP_power_dn_rx, &sP_power_dn_tx);
        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                _ERR("failed to get cpu power params");
-
        _DBG("received device-network power params - signal_0[%d]\n, signal_1[%d]\n, signal_2[%d]\n, \
                        signal_3[%d]\n, signal_4[%d]\n, signal_5[%d]\n, signal_6[%d]\n, rx[%d]\n, tx[%d]\n",
                        sP_power_dn_tl0, sP_power_dn_tl1, sP_power_dn_tl2, sP_power_dn_tl3, sP_power_dn_tl4, sP_power_dn_tl5,
                        sP_power_dn_tl6, sP_power_dn_rx, sP_power_dn_tx);
 
-       int tl_total = 0;
        tl_total = tl0 + tl1 + tl2 + tl3 + tl4 + tl5 + tl6;
-
        /* Device Network power consumption Level - 1 at the Resource Level */
        int P_power_dntw = 0, P_power_data = 0, P_power_conn = 0;
        P_power_conn = ((sP_power_dn_tl0 * tl0) + (sP_power_dn_tl1 * tl1) + (sP_power_dn_tl2 * tl2) + (sP_power_dn_tl3 * tl3) + (sP_power_dn_tl4 * tl4) + (sP_power_dn_tl5 * tl5) + (sP_power_dn_tl6 * tl6));
        P_power_data = ((sP_power_dn_tx) * TX) + ((sP_power_dn_rx) * RX);
-
        P_power_dntw = P_power_conn + P_power_data;
 
        _DBG("Calculated Power for Device Network P_power_ntw(%d),  P_power_conn (%d), P_power_data(%d)", P_power_dntw, P_power_conn, P_power_data);
-
        /* Device Network power consumption Level - 2 at the Application Level */
        GHashTableIter iter;
        gpointer key, value;
-
        g_hash_table_iter_init(&iter, hash);
 
        int P_power_app_dntw = 0, P_power_app_data = 0, P_power_app_conn = 0;
        char *appid = NULL;
        int apprx = 0, apptx = 0, apptime = 0;
-
        long int ret_time = bm_get_log_time();
 
        appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
@@ -1239,14 +1137,11 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                P_power_app_dntw = 0; P_power_app_data = 0 ; P_power_app_conn = 0;
                apprx = 0, apptx = 0, apptime = 0;
-
                app_time_map_st2 *temp = (app_time_map_st2 *)value;
-
                appid = temp->app_id;
                apprx = temp->rx;
                apptx = temp->tx;
                apptime = temp->time;
-
                P_power_app_data = ((sP_power_dn_tx) * apptx) + ((sP_power_dn_rx) * apprx);
                if (tl_total != 0)
                        P_power_app_conn = (P_power_conn * apptime)/tl_total; //check for 0 denominator & same units
@@ -1255,7 +1150,6 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
                app_usage->AppId = appid;
                app_usage->rId_device_network = P_power_app_dntw;
                app_usage->log_time = ret_time;
-
                /* Call Insert Function */
                _DBG("Calculated Power for Appid (%s) P_power_app_dntw(%d),  P_power_app_conn (%d), P_power_app_data(%d)", appid, P_power_app_dntw, P_power_app_conn, P_power_app_data);
                if (mode) {
@@ -1265,8 +1159,6 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
                        ret_val = bm_server_app_usage_insert_to_db(app_usage);
                } else
                        ret_val = bm_appid_session_usage_map(g_strdup(app_usage->AppId), app_usage->rId_device_network, BM_PLUGIN_ID_DEVICE_NETWORK);
-
-               /* Error Check */
                if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                        _ERR("Insert of Data Ntwk App failed ");
                else
@@ -1286,16 +1178,30 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
        res_usage->usage = P_power_dntw;
 
        ret_val = bm_server_resource_usage_insert_to_db(res_usage);
-       /* Error Check */
        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                _ERR("Insert of Data Network resource failed ");
        else
                _DBG("Insert successful");
 
-
        bm_appid_usage_free(app_usage);
        bm_resourceid_usage_free(res_usage);
 
+       bd_gl_sgt_stat_s *gst_st = (bd_gl_sgt_stat_s *)calloc(1, sizeof(bd_gl_sgt_stat_s));
+       if (gst_st == NULL) {
+               _ERR("memory allocation failed");
+               return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
+       }
+
+       gst_st->time_s = ret_time; gst_st->scan_time = tl0; gst_st->none_time = tl1;
+       gst_st->poor_time = tl2; gst_st->med_time = tl3 + tl4;
+       gst_st->good_time = tl5; gst_st->grt_time = tl6;
+       ret_val = bm_server_battery_dump_insert_to_db(gst_st, 4);
+       if (ret_val != BATTERY_MONITOR_ERROR_NONE)
+               _ERR("Insert of GWFL failed ");
+       else
+               _DBG("Insert successful");
+       BM_FREE(gst_st);
+
        /* Free the Hash Map */
        g_hash_table_destroy(hash);
 
@@ -1312,10 +1218,8 @@ int bm_gps_calc_power_and_commit(bm_gps_st *handle)
 
        GSList *gps_data_iterator = NULL;
        GSList *gps_atm_iterator = NULL;
-
        void *prv_data = NULL;
        void *prv_app_id = NULL;
-
        int ret_val = BATTERY_MONITOR_ERROR_NONE;
 
        /* creating hash-map with (key, value) = (app-id, data) */
@@ -1325,51 +1229,31 @@ int bm_gps_calc_power_and_commit(bm_gps_st *handle)
        long int stTime = 0;
        int sesTime = 0;
        int onTime = 0;
-
        /* iterating over list for data accumulation */
        for (gps_data_iterator = handle->gps_data_list; gps_data_iterator; gps_data_iterator = gps_data_iterator->next) {
-
                bm_gps_st *datalistnode = (bm_gps_st *)(gps_data_iterator->data);
-
                edTime = datalistnode->connStartTime;
                stTime = datalistnode->connStopTime;
                sesTime = edTime - stTime;
-
                gps_atm_iterator = datalistnode->atm_list;
-//             gps_atm_iterator = ((bm_gps_st *)(gps_data_iterator->data))->atm_list;
-
                for ( ; gps_atm_iterator; gps_atm_iterator = gps_atm_iterator->next) {
-
                        app_time_map_st1 *gps_atm_node = (app_time_map_st1 *)gps_atm_iterator->data;
-
                        if (!gps_atm_node) {
                                _DBG("no bt data available");
                                continue;
                        }
-
                        _DBG("gps data available");
-
                        onTime += gps_atm_node->time;
-
                        prv_app_id = NULL;
                        prv_data = NULL;
-
                        if (g_hash_table_lookup_extended(hash, gps_atm_node->app_id, &prv_app_id, &prv_data) == true) {
-
                                _DBG("previous app_id = %s", (char *)prv_app_id);
-
                                app_time_map_st1 *gps_atm_prv_node = (app_time_map_st1 *)prv_data;
-
                                gps_atm_node->time += gps_atm_prv_node->time;
-
                                _DBG("update - app_id(%s), time(%d)", gps_atm_node->app_id, gps_atm_node->time);
-
                                _INFO("updated - %d", g_hash_table_replace(hash, gps_atm_node->app_id, gps_atm_node));
-
                        } else {
-
                                _DBG("insert - app_id(%s), time(%d)", gps_atm_node->app_id, gps_atm_node->time);
-
                                _INFO("inserted - %d", g_hash_table_insert(hash, gps_atm_node->app_id, gps_atm_node));
                        }
                }
@@ -1383,7 +1267,6 @@ int bm_gps_calc_power_and_commit(bm_gps_st *handle)
                _ERR("failed to get gps-sensor power params");
 
        _DBG("gps-sensor power params - gps[%d]", sP_power_gps_conn);
-
        /* GPS power consumption Level - 1 at the Resource Level */
        int P_power_gps = 0, P_power_conn = 0;
        P_power_conn = ((sP_power_gps_conn * sesTime));
@@ -1394,13 +1277,11 @@ int bm_gps_calc_power_and_commit(bm_gps_st *handle)
        /* GPS power consumption Level - 2 at the Application Level */
        GHashTableIter iter;
        gpointer key, value;
-
        g_hash_table_iter_init(&iter, hash);
 
        int P_power_app_gps = 0, P_power_app_conn = 0;
        char *appid = NULL;
        int apptime = 0;
-
        long int ret_time = bm_get_log_time();
 
        appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
@@ -1412,9 +1293,7 @@ int bm_gps_calc_power_and_commit(bm_gps_st *handle)
        while (g_hash_table_iter_next(&iter, &key, &value)) {
                P_power_app_gps = 0; P_power_app_conn = 0;
                apptime = 0;
-
                app_time_map_st1 *temp = (app_time_map_st1 *)value;
-
                appid = temp->app_id;
                apptime = temp->time;
 
@@ -1425,11 +1304,9 @@ int bm_gps_calc_power_and_commit(bm_gps_st *handle)
                app_usage->AppId = appid;
                app_usage->rId_gps = P_power_app_gps;
                app_usage->log_time = ret_time;
-
                /* Call Insert Function */
                _DBG("Calculated Power for Appid (%s) P_power_app_gps (%d),  P_power_app_conn (%d)", appid, P_power_app_gps, P_power_app_conn);
                ret_val = bm_server_app_usage_insert_to_db(app_usage);
-               /* Error Check */
                if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                        _ERR("Insert of GPS App failed ");
                else
@@ -1449,7 +1326,6 @@ int bm_gps_calc_power_and_commit(bm_gps_st *handle)
        res_usage->usage = P_power_gps;
 
        ret_val = bm_server_resource_usage_insert_to_db(res_usage);
-       /* Error Check */
        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                _ERR("Insert of GPS resource failed ");
        else
index 044725d..669e532 100644 (file)
@@ -29,6 +29,7 @@
 #include <tzplatform_config.h>
 
 #include "bm_private.h"
+#include "bd_private.h"
 #include "bm_server_db.h"
 #include "bm_common.h"
 #include "bm_dbg.h"
@@ -93,7 +94,6 @@ static int bm_execute_query(sqlite3 *bm_db_handle, const char *query)
                _ERR("NULL query\n");
                return BATTERY_MONITOR_ERROR_QUERY_SYNTAX_ERROR;
        }
-
        if (!bm_db_handle) {
                _ERR("DB is not opened\n");
                return BATTERY_MONITOR_ERROR_DB_NOT_OPENED;
@@ -129,6 +129,7 @@ static int bm_query_finalize(bm_stmt pStmt)
                return BATTERY_MONITOR_ERROR_DB_FAILED;
        }
 
+       EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
@@ -211,17 +212,14 @@ static int bm_end_transaction(sqlite3 *bm_db_handle, bool is_success)
                ret = bm_execute_query(bm_db_handle, "ROLLBACK TRANSACTION");
                _DBG("bm_end_transaction ROLLBACK");
        }
-
        if (ret == SQLITE_PERM) {
                _ERR("Battery Monitor permission denied :: %d", ret);
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
        }
-
        if (ret == SQLITE_BUSY) {
                _DBG(" sqlite3 busy = %d", ret);
                return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
        }
-
        if (ret != SQLITE_OK) {
                _ERR("bm_svc_end_transaction fail :: %d", ret);
                return BATTERY_MONITOR_ERROR_DB_FAILED;
@@ -239,7 +237,6 @@ static int bm_query_bind_int(bm_stmt pStmt, int pos, int num)
                _ERR("statement is null");
                return -1;
        }
-
        if (pos < 0) {
                _ERR("invalid pos");
                return -1;
@@ -257,7 +254,6 @@ static int bm_query_bind_text(bm_stmt pStmt, int pos, const char *str)
                _ERR("statement is null");
                return -1;
        }
-
        if (str) {
                _INFO("sqlite3_bind_text");
                return sqlite3_bind_text(pStmt, pos, (const char *)str, strlen(str), SQLITE_STATIC);
@@ -265,6 +261,8 @@ static int bm_query_bind_text(bm_stmt pStmt, int pos, const char *str)
                _INFO("sqlite3_bind_null");
                return sqlite3_bind_null(pStmt, pos);
        }
+
+       EXIT;
 }
 
 static int bm_query_table_column_int(bm_stmt pStmt, int pos)
@@ -275,7 +273,6 @@ static int bm_query_table_column_int(bm_stmt pStmt, int pos)
                _ERR("statement is null");
                return -1;
        }
-
        if (pos < 0) {
                _ERR("invalid pos");
                return -1;
@@ -292,7 +289,6 @@ static const char* bm_query_table_column_text(bm_stmt pStmt, int pos)
                _ERR("statement is null");
                return NULL;
        }
-
        if (pos < 0) {
                _ERR("invalid pos");
                return NULL;
@@ -344,9 +340,6 @@ static int bm_appid_map_usage_convert_to_sql(const char* app_id, bm_stmt hstmt,
        ENTER;
 
        int count = 1;
-
-       /* Caution : Keep insert query orders. */
-
        bm_query_bind_text(hstmt, count++, app_id);
 
        EXIT;
@@ -358,27 +351,16 @@ static int bm_appid_usage_convert_to_sql(appid_usage_s *bm_app_type, bm_stmt hst
        ENTER;
 
        int count = 1;
-
-       /* Caution : Keep insert query orders. */
-
        bm_query_bind_text(hstmt, count++, (char *)bm_app_type->AppId);
-
        bm_query_bind_int(hstmt, count++, bm_app_type->log_time);
-
        bm_query_bind_int(hstmt, count++, bm_app_type->rId_ble);
-
        bm_query_bind_int(hstmt, count++, bm_app_type->rId_wifi);
-
        bm_query_bind_int(hstmt, count++, bm_app_type->rId_cpu);
-
        bm_query_bind_int(hstmt, count++, bm_app_type->rId_display);
-
        bm_query_bind_int(hstmt, count++, bm_app_type->rId_device_network);
 #ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
        bm_query_bind_int(hstmt, count++, bm_app_type->rId_gps);
-
        bm_query_bind_int(hstmt, count++, bm_app_type->rId_hrm);
-
        bm_query_bind_int(hstmt, count++, bm_app_type->rId_battery);
 #endif
        EXIT;
@@ -390,17 +372,127 @@ static int bm_resourceid_usage_convert_to_sql(resourceid_usage_s *bm_resource_ty
        ENTER;
 
        int count = 1;
+       bm_query_bind_text(hstmt, count++, (char *)bm_resource_type->ResourceId);
+       bm_query_bind_int(hstmt, count++, bm_resource_type->log_time);
+       bm_query_bind_int(hstmt, count++, bm_resource_type->usage);
 
-       /* Caution : Keep insert query orders. */
+       EXIT;
+       return count;
+}
 
-       bm_query_bind_text(hstmt, count++, (char *)bm_resource_type->ResourceId);
+static int bm_gl_ble_stat_convert_to_sql(bd_gl_ble_stat_s *gble_st, bm_stmt hstmt, char *sql_value)
+{
+       ENTER;
 
-       bm_query_bind_int(hstmt, count++, bm_resource_type->log_time);
+       int count = 1;
+       bm_query_bind_int(hstmt, count++, gble_st->time_s);
+       bm_query_bind_int(hstmt, count++, gble_st->ble_idle_time);
+       bm_query_bind_int(hstmt, count++, gble_st->ble_rx_time);
+       bm_query_bind_int(hstmt, count++, gble_st->ble_tx_time);
+       bm_query_bind_int(hstmt, count++, gble_st->ble_pwi_val);
 
-       bm_query_bind_int(hstmt, count++, bm_resource_type->usage);
+       EXIT;
+       return count;
+}
+
+static int bm_gl_wifi_stat_convert_to_sql(bd_gl_wifi_stat_s *gwfl_st, bm_stmt hstmt, char *sql_value)
+{
+       ENTER;
+
+       int count = 1;
+       bm_query_bind_int(hstmt, count++, gwfl_st->time_s);
+       bm_query_bind_int(hstmt, count++, gwfl_st->wifi_on_time);
+       bm_query_bind_int(hstmt, count++, gwfl_st->wifi_conn_time);
+       bm_query_bind_int(hstmt, count++, gwfl_st->wifi_idle_time);
+       bm_query_bind_int(hstmt, count++, gwfl_st->wifi_rx_time);
+       bm_query_bind_int(hstmt, count++, gwfl_st->wifi_tx_time);
+       bm_query_bind_int(hstmt, count++, gwfl_st->wifi_pwi_val);
 
        EXIT;
+       return count;
+}
+
+static int bm_gl_ntw_stat_convert_to_sql(bd_gl_ntw_stat_s *gn_st, bm_stmt hstmt, char *sql_value)
+{
+       ENTER;
+
+       int count = 1;
+       bm_query_bind_int(hstmt, count++, gn_st->time_s);
+       bm_query_bind_int(hstmt, count++, gn_st->dn_rx_byt);
+       bm_query_bind_int(hstmt, count++, gn_st->dn_tx_byt);
+       bm_query_bind_int(hstmt, count++, gn_st->wifi_rx_byt);
+       bm_query_bind_int(hstmt, count++, gn_st->wifi_tx_byt);
+       bm_query_bind_int(hstmt, count++, gn_st->dn_rx_pkt);
+       bm_query_bind_int(hstmt, count++, gn_st->dn_tx_pkt);
+       bm_query_bind_int(hstmt, count++, gn_st->wifi_rx_pkt);
+       bm_query_bind_int(hstmt, count++, gn_st->wifi_tx_pkt);
+
+       EXIT;
+       return count;
+}
+
+static int bm_gl_sbr_stat_convert_to_sql(bd_gl_sbr_stat_s *gbr_st, bm_stmt hstmt, char *sql_value)
+{
+       ENTER;
+
+       int count = 1;
+       bm_query_bind_int(hstmt, count++, gbr_st->time_s);
+       bm_query_bind_int(hstmt, count++, gbr_st->dark);
+       bm_query_bind_int(hstmt, count++, gbr_st->dim);
+       bm_query_bind_int(hstmt, count++, gbr_st->medium);
+       bm_query_bind_int(hstmt, count++, gbr_st->light);
+       bm_query_bind_int(hstmt, count++, gbr_st->bright);
+
+       EXIT;
+       return count;
+}
+
+static int bm_gl_sgt_stat_convert_to_sql(bd_gl_sgt_stat_s *gst_st, bm_stmt hstmt, char *sql_value)
+{
+       ENTER;
+
+       int count = 1;
+       bm_query_bind_int(hstmt, count++, gst_st->time_s);
+       bm_query_bind_int(hstmt, count++, gst_st->scan_time);
+       bm_query_bind_int(hstmt, count++, gst_st->none_time);
+       bm_query_bind_int(hstmt, count++, gst_st->poor_time);
+       bm_query_bind_int(hstmt, count++, gst_st->med_time);
+       bm_query_bind_int(hstmt, count++, gst_st->good_time);
+       bm_query_bind_int(hstmt, count++, gst_st->grt_time);
+
+       EXIT;
+       return count;
+}
+
+static int bm_gl_wst_stat_convert_to_sql(bd_gl_wst_stat_s *gwst_st, bm_stmt hstmt, char *sql_value)
+{
+       ENTER;
+
+       int count = 1;
+       bm_query_bind_int(hstmt, count++, gwst_st->time_s);
+       bm_query_bind_int(hstmt, count++, gwst_st->wscan_time);
+       bm_query_bind_int(hstmt, count++, gwst_st->wnone_time);
+       bm_query_bind_int(hstmt, count++, gwst_st->wpoor_time);
+       bm_query_bind_int(hstmt, count++, gwst_st->wmed_time);
+       bm_query_bind_int(hstmt, count++, gwst_st->wgood_time);
+       bm_query_bind_int(hstmt, count++, gwst_st->wgrt_time);
+
+       EXIT;
+       return count;
+}
+
+static int bm_gl_bst_stat_convert_to_sql(bd_gl_bst_stat_s *gbst_st, bm_stmt hstmt, char *sql_value)
+{
+       ENTER;
+
+       int count = 1;
+       bm_query_bind_int(hstmt, count++, gbst_st->time_s);
+       bm_query_bind_int(hstmt, count++, gbst_st->off_time);
+       bm_query_bind_int(hstmt, count++, gbst_st->low_time);
+       bm_query_bind_int(hstmt, count++, gbst_st->med_time);
+       bm_query_bind_int(hstmt, count++, gbst_st->high_time);
 
+       EXIT;
        return count;
 }
 
@@ -409,14 +501,10 @@ static void bm_convert_column_to_resourceid_usage(bm_stmt hstmt, resourceid_usag
        ENTER;
 
        const char *textbuf = NULL;
-
        textbuf = bm_query_table_column_text(hstmt, BM_RESOURCEUSAGE_FIELD_RESID);
        bm_db_data_to_text(textbuf, &(bm_resource_type->ResourceId));
-
        _DBG("bm_resource_type->ResourceId =[%s]", bm_resource_type->ResourceId);
-
        bm_resource_type->log_time = -1;
-
        bm_resource_type->usage = bm_query_table_column_int(hstmt, BM_RESOURCEUSAGE_FIELD_USAGE);
 
        EXIT;
@@ -428,28 +516,18 @@ static void bm_convert_column_to_appid_usage(bm_stmt hstmt, appid_usage_s* bm_ap
        ENTER;
 
        const char *textbuf = NULL;
-
        textbuf = bm_query_table_column_text(hstmt, BM_APPUSAGE_FIELD_APPID);
        bm_db_data_to_text(textbuf, &(bm_app_type->AppId));
-
        _DBG("bm_app_type->AppId =[%s]", bm_app_type->AppId);
-
        bm_app_type->log_time = -1;
-
        bm_app_type->rId_ble = bm_query_table_column_int(hstmt, BM_APPUSAGE_FIELD_RID_BLE);
-
        bm_app_type->rId_wifi = bm_query_table_column_int(hstmt, BM_APPUSAGE_FIELD_RID_WIFI);
-
        bm_app_type->rId_cpu = bm_query_table_column_int(hstmt, BM_APPUSAGE_FIELD_RID_CPU);
-
        bm_app_type->rId_display = bm_query_table_column_int(hstmt, BM_APPUSAGE_FIELD_RID_DISPLAY);
-
        bm_app_type->rId_device_network = bm_query_table_column_int(hstmt, BM_APPUSAGE_FIELD_RID_DEV_NTW);
 #ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
        bm_app_type->rId_gps = bm_query_table_column_int(hstmt, BM_APPUSAGE_FIELD_RID_GPS);
-
        bm_app_type->rId_hrm = bm_query_table_column_int(hstmt, BM_APPUSAGE_FIELD_RID_HRM);
-
        bm_app_type->rId_battery = -1;
 #endif
        EXIT;
@@ -515,9 +593,13 @@ static int bm_check_is_all_table_exists(sqlite3 *bm_db_handle)
        char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0,};
        BM_MEMSET(query, 0, sizeof(query));
 
-       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s', '%s', '%s')",
+       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in \
+                       ('%s', '%s', '%s', '%s','%s', '%s', '%s', '%s','%s', '%s')",
                        BATTERY_MONITOR_APP_ID_MAP_TABLE, BATTERY_MONITOR_APP_ID_USAGE_TABLE,
-                       BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE);
+                       BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE, BATTERY_MONITOR_GBL_BLE_STAT_TABLE,
+                       BATTERY_MONITOR_GBL_WFL_STAT_TABLE, BATTERY_MONITOR_GBL_NT_STAT_TABLE,
+                       BATTERY_MONITOR_GBL_BR_STAT_TABLE, BATTERY_MONITOR_GBL_SGT_STAT_TABLE,
+                       BATTERY_MONITOR_GBL_WST_STAT_TABLE, BATTERY_MONITOR_GBL_BST_STAT_TABLE);
 
        rc = bm_get_record_count(bm_db_handle, query);
 
@@ -534,63 +616,132 @@ static int bm_create_all_tables(sqlite3 *bm_db_handle)
 
        int rc = -1;
        int error_code = BATTERY_MONITOR_ERROR_NONE;
-
-       _INFO("Create all tables - BEGIN");
-
        char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
        BM_MEMSET(query, 0, sizeof(query));
 
        /* Create the appid map table */
        BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
                                                BATTERY_MONITOR_APP_ID_MAP_TABLE);
-
        rc = bm_get_record_count(bm_db_handle, query);
-
        if (rc <= 0) {
                rc = bm_execute_query(bm_db_handle, APP_ID_MAP_SCHEMA);
-
                if (rc == SQLITE_BUSY)
                        return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
-
                BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
                        ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
                         APP_ID_MAP_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
        }
-
        /* Create the app based usage table */
        BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
                                                BATTERY_MONITOR_APP_ID_USAGE_TABLE);
-
        rc = bm_get_record_count(bm_db_handle, query);
-
        if (rc <= 0) {
                rc = bm_execute_query(bm_db_handle, APP_ID_USAGE_SCHEMA);
-
                if (rc == SQLITE_BUSY)
                        return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
-
                BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
                        ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
                         APP_ID_USAGE_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
        }
-
        /* Create the resource based usage table */
        BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
                                                BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE);
-
        rc = bm_get_record_count(bm_db_handle, query);
-
        if (rc <= 0) {
                rc = bm_execute_query(bm_db_handle, RESOURCE_ID_USAGE_SCHEMA);
-
                if (rc == SQLITE_BUSY)
                        return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
-
                BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
                        ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
                         RESOURCE_ID_USAGE_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
        }
 
+       /* Battery Dump Tables */
+       /* Create the global bluetooth stats table */
+       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
+                       BATTERY_MONITOR_GBL_BLE_STAT_TABLE);
+       rc = bm_get_record_count(bm_db_handle, query);
+       if (rc <= 0) {
+               rc = bm_execute_query(bm_db_handle, GBL_BLE_STAT_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
+                               ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
+                                GBL_BLE_STAT_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
+       }
+       /* Create the global wifi stats table */
+       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
+                       BATTERY_MONITOR_GBL_WFL_STAT_TABLE);
+       rc = bm_get_record_count(bm_db_handle, query);
+       if (rc <= 0) {
+               rc = bm_execute_query(bm_db_handle, GBL_WFL_STAT_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
+                               ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
+                                GBL_WFL_STAT_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
+       }
+       /* Create the global network stats table */
+       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
+                       BATTERY_MONITOR_GBL_NT_STAT_TABLE);
+       rc = bm_get_record_count(bm_db_handle, query);
+       if (rc <= 0) {
+               rc = bm_execute_query(bm_db_handle, GBL_NT_STAT_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
+                               ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
+                                GBL_NT_STAT_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
+       }
+       /* Create the global brightness stats table */
+       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
+                       BATTERY_MONITOR_GBL_BR_STAT_TABLE);
+       rc = bm_get_record_count(bm_db_handle, query);
+       if (rc <= 0) {
+               rc = bm_execute_query(bm_db_handle, GBL_BR_STAT_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
+                               ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
+                                GBL_BR_STAT_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
+       }
+       /* Create the global signal stats table */
+       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
+                       BATTERY_MONITOR_GBL_SGT_STAT_TABLE);
+       rc = bm_get_record_count(bm_db_handle, query);
+       if (rc <= 0) {
+               rc = bm_execute_query(bm_db_handle, GBL_SGT_STAT_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
+                               ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
+                                GBL_SGT_STAT_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
+       }
+       /* Create the global wifi signal stats table */
+       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
+                       BATTERY_MONITOR_GBL_WST_STAT_TABLE);
+       rc = bm_get_record_count(bm_db_handle, query);
+       if (rc <= 0) {
+               rc = bm_execute_query(bm_db_handle, GBL_WST_STAT_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
+                               ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
+                                GBL_WST_STAT_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
+       }
+       /* Create the global bt signal stats table */
+       BM_SNPRINTF(query, sizeof(query), "select count(*) from sqlite_master where name in ('%s')",
+                       BATTERY_MONITOR_GBL_BST_STAT_TABLE);
+       rc = bm_get_record_count(bm_db_handle, query);
+       if (rc <= 0) {
+               rc = bm_execute_query(bm_db_handle, GBL_BST_STAT_SCHEMA);
+               if (rc == SQLITE_BUSY)
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               BM_RETURN_VAL((SQLITE_OK == rc), {}, BATTERY_MONITOR_ERROR_DB_FAILED,
+                               ("bm_execute_query(bm_db_handle, %s) failed(%d, %s).\n",
+                                GBL_BST_STAT_SCHEMA, rc, bm_db_err_msg(bm_db_handle)));
+       }
+
        EXIT;
        return error_code;
 }
@@ -801,7 +952,6 @@ static int bm_appid_usage_insert_to_db(sqlite3 *bm_db_handle, appid_usage_s *bm_
 #endif
 
        hstmt = bm_prepare_query(bm_db_handle, query);
-
        if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
                _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
@@ -831,6 +981,167 @@ static int bm_appid_usage_insert_to_db(sqlite3 *bm_db_handle, appid_usage_s *bm_
        return error_code;
 }
 
+static int bm_battery_stat_insert_to_db(sqlite3 *bm_db_handle, void *str_data, int type)
+{
+       ENTER;
+
+       int rc = 0;
+       char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
+       int error_code = BATTERY_MONITOR_ERROR_NONE;
+       bm_stmt hstmt = NULL;
+
+       BM_MEMSET(query, 0x00, sizeof(query));
+
+       switch (type) {
+       case 0: //;GBLE DATA
+               _DBG("GBLE_DATA");
+               bd_gl_ble_stat_s *gble_st = (bd_gl_ble_stat_s *)str_data;
+               _DBG("time %ld idle_time %ld rx_time %ld tx_time %ld pwi %ld", gble_st->time_s, gble_st->ble_idle_time,
+                               gble_st->ble_rx_time, gble_st->ble_tx_time, gble_st->ble_pwi_val);
+               BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s(time_s, ble_idle_time, ble_rx_time, \
+                       ble_tx_time, ble_pwi_val) values " "(?, ?, ?, ?, ?)", BATTERY_MONITOR_GBL_BLE_STAT_TABLE);
+               hstmt = bm_prepare_query(bm_db_handle, query);
+               if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+                       _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+               } else if (bm_db_err_code(bm_db_handle) == SQLITE_BUSY) {
+                       _ERR("Database Busy(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               }
+               BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
+               bm_gl_ble_stat_convert_to_sql(gble_st, hstmt, query);
+               break;
+       case 1:
+               _DBG("GWFL_DATA");
+               bd_gl_wifi_stat_s *gwfl_st = (bd_gl_wifi_stat_s *)str_data;
+               _DBG("time %ld on_time %ld conn_time %ld idle_time %ld rx_time %ld tx_time %ld pwi %ld", gwfl_st->time_s,
+                               gwfl_st->wifi_on_time, gwfl_st->wifi_conn_time, gwfl_st->wifi_idle_time, gwfl_st->wifi_rx_time,
+                               gwfl_st->wifi_tx_time, gwfl_st->wifi_pwi_val);
+               BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s(time_s, wifi_on_time, wifi_conn_time, wifi_idle_time, \
+                       wifi_rx_time, wifi_tx_time, wifi_pwi_val) values" "(?, ?, ?, ?, ?, ?, ?)", BATTERY_MONITOR_GBL_WFL_STAT_TABLE);
+               hstmt = bm_prepare_query(bm_db_handle, query);
+               if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+                       _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+               } else if (bm_db_err_code(bm_db_handle) == SQLITE_BUSY) {
+                       _ERR("Database Busy(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               }
+               BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
+               bm_gl_wifi_stat_convert_to_sql(gwfl_st, hstmt, query);
+               break;
+       case 2:
+               _DBG("GNTW_DATA");
+               bd_gl_ntw_stat_s *gn_st = (bd_gl_ntw_stat_s *)str_data;
+               _DBG("time %ld dn_rx %ld dn_tx %ld wifi_rx %ld wifi_tx %ld dn_rx_pkt %ld dn_tx_pkt %ld wifi_rx_pkt %ld wifi_tx_pkt %ld",
+                               gn_st->time_s, gn_st->dn_rx_byt, gn_st->dn_tx_byt, gn_st->wifi_rx_byt, gn_st->wifi_tx_byt,
+                               gn_st->dn_rx_pkt, gn_st->dn_tx_pkt, gn_st->wifi_rx_pkt, gn_st->wifi_tx_pkt);
+               BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s(time_s, dn_rx_byt, dn_tx_byt, wifi_rx_byt, wifi_tx_byt, \
+                       dn_rx_pkt, dn_tx_pkt, wifi_rx_pkt, wifi_tx_pkt) values" "(?, ?, ?, ?, ?, ?, ?, ?, ?)", BATTERY_MONITOR_GBL_NT_STAT_TABLE);
+               hstmt = bm_prepare_query(bm_db_handle, query);
+               if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+                       _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+               } else if (bm_db_err_code(bm_db_handle) == SQLITE_BUSY) {
+                       _ERR("Database Busy(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               }
+               BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
+               bm_gl_ntw_stat_convert_to_sql(gn_st, hstmt, query);
+               break;
+       case 3:
+               _DBG("GSBR_DATA");
+               bd_gl_sbr_stat_s *gbr_st = (bd_gl_sbr_stat_s *)str_data;
+               _DBG("time %ld dark %ld dim %ld medium %ld light %ld bright %ld", gbr_st->time_s,
+                               gbr_st->dark, gbr_st->dim, gbr_st->medium, gbr_st->light, gbr_st->bright);
+               BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s(time_s, dark, dim, medium, light, bright) values" \
+                               "(?, ?, ?, ?, ?, ?)", BATTERY_MONITOR_GBL_BR_STAT_TABLE);
+               hstmt = bm_prepare_query(bm_db_handle, query);
+               if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+                       _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+               } else if (bm_db_err_code(bm_db_handle) == SQLITE_BUSY) {
+                       _ERR("Database Busy(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               }
+               BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
+               bm_gl_sbr_stat_convert_to_sql(gbr_st, hstmt, query);
+               break;
+       case 4:
+               _DBG("GSGT_DATA");
+               bd_gl_sgt_stat_s *gst_st = (bd_gl_sgt_stat_s *)str_data;
+               _DBG("time %ld scan %ld no %ld poor %ld med %ld good %ld great %ld", gst_st->time_s, gst_st->scan_time,
+                               gst_st->none_time, gst_st->poor_time, gst_st->med_time, gst_st->good_time, gst_st->grt_time);
+               BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s(time_s, scan_time, none_time, poor_time, med_time, good_time, \
+                       grt_time) values" "(?, ?, ?, ?, ?, ?, ?)", BATTERY_MONITOR_GBL_SGT_STAT_TABLE);
+               hstmt = bm_prepare_query(bm_db_handle, query);
+               if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+                       _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+               } else if (bm_db_err_code(bm_db_handle) == SQLITE_BUSY) {
+                       _ERR("Database Busy(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               }
+               BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
+               bm_gl_sgt_stat_convert_to_sql(gst_st, hstmt, query);
+               break;
+       case 5:
+               _DBG("GWST_DATA");
+               bd_gl_wst_stat_s *gwst_st = (bd_gl_wst_stat_s *)str_data;
+               _DBG("time %ld wscan %ld wno %ld wpoor %ld wmed %ld wgood %ld wgreat %ld", gwst_st->time_s, gwst_st->wscan_time,
+                               gwst_st->wnone_time, gwst_st->wpoor_time, gwst_st->wmed_time, gwst_st->wgood_time, gwst_st->wgrt_time);
+               BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s(time_s, wscan_time, wnone_time, wpoor_time, wmed_time, wgood_time, \
+                       wgrt_time) values" "(?, ?, ?, ?, ?, ?, ?)", BATTERY_MONITOR_GBL_WST_STAT_TABLE);
+               hstmt = bm_prepare_query(bm_db_handle, query);
+               if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+                       _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+               } else if (bm_db_err_code(bm_db_handle) == SQLITE_BUSY) {
+                       _ERR("Database Busy(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               }
+               BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
+               bm_gl_wst_stat_convert_to_sql(gwst_st, hstmt, query);
+               break;
+       case 6:
+               _DBG("GBST_DATA");
+               bd_gl_bst_stat_s *gbst_st = (bd_gl_bst_stat_s *)str_data;
+               _DBG("time %ld off %ld low %ld med %ld high %ld", gbst_st->time_s, gbst_st->off_time, gbst_st->low_time,
+                               gbst_st->med_time, gbst_st->high_time);
+               BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s(time_s, off_time, low_time, med_time, high_time) values "\
+                               "(?, ?, ?, ?, ?)", BATTERY_MONITOR_GBL_BST_STAT_TABLE);
+               hstmt = bm_prepare_query(bm_db_handle, query);
+               if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
+                       _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+               } else if (bm_db_err_code(bm_db_handle) == SQLITE_BUSY) {
+                       _ERR("Database Busy(%s)", bm_db_err_msg(bm_db_handle));
+                       return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+               }
+               BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
+               bm_gl_bst_stat_convert_to_sql(gbst_st, hstmt, query);
+               break;
+       default:
+               break;
+       }
+
+       rc = bm_query_step(hstmt);
+       if (rc == SQLITE_BUSY) {
+               _ERR("bm_db_query_step() failed(%d, %s)", rc, bm_db_err_msg(bm_db_handle));
+               error_code = BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+       } else if (rc != SQLITE_DONE) {
+               _ERR("bm_db_query_step() failed(%d, %s)", rc, bm_db_err_msg(bm_db_handle));
+               error_code = BATTERY_MONITOR_ERROR_DB_FAILED;
+       }
+
+       rc = bm_query_finalize(hstmt);
+       BM_RETURN_VAL((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
+       hstmt = NULL;
+
+       EXIT;
+       return error_code;
+}
+
 static int bm_resourceid_usage_insert_to_db(sqlite3 *bm_db_handle, resourceid_usage_s *bm_resource_type)
 {
        ENTER;
@@ -848,11 +1159,9 @@ static int bm_resourceid_usage_insert_to_db(sqlite3 *bm_db_handle, resourceid_us
                return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
 
        BM_MEMSET(query, 0x00, sizeof(query));
-
        BM_SNPRINTF(query, sizeof(query), "INSERT INTO %s( ResourceId, log_time, usage ) values " "(?, ?, ?)", BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE);
 
        hstmt = bm_prepare_query(bm_db_handle, query);
-
        if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
                _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
@@ -864,7 +1173,6 @@ static int bm_resourceid_usage_insert_to_db(sqlite3 *bm_db_handle, resourceid_us
        BM_RETURN_VAL((hstmt != NULL), {}, BATTERY_MONITOR_ERROR_DB_FAILED, ("bm_prepare_query() failed(%s).\n", bm_db_err_msg(bm_db_handle)));
 
        bm_resourceid_usage_convert_to_sql(bm_resource_type, hstmt, query);
-
        rc = bm_query_step(hstmt);
        if (rc == SQLITE_BUSY) {
                _ERR("bm_db_query_step() failed(%d, %s)", rc, bm_db_err_msg(bm_db_handle));
@@ -903,7 +1211,6 @@ int bm_appid_map_insert_to_db(sqlite3 *bm_db_handle, const char *app_id)
                        "(?)", BATTERY_MONITOR_APP_ID_MAP_TABLE);
 
        hstmt = bm_prepare_query(bm_db_handle, query);
-
        if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
                _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
@@ -939,12 +1246,10 @@ static appid_usage_s* bm_query_usage_by_appid(sqlite3 *bm_db_handle, const char
 
        long int duration  = 0;
        duration = bm_get_time_bias(period_type);
-
        if (duration == 0) {
                _ERR("Invalid period_type [%d]", period_type);
                return NULL;
        }
-
        _DBG("Value for duration is [%ld]", duration);
 
        bm_stmt hstmt = NULL;
@@ -954,10 +1259,8 @@ static appid_usage_s* bm_query_usage_by_appid(sqlite3 *bm_db_handle, const char
 
        BM_RETURN_VAL((app_id != NULL), { *error_code = BATTERY_MONITOR_ERROR_INVALID_PARAMETER; },
                                                NULL, ("APP ID IS NULL"));
-
        BM_RETURN_VAL((bm_db_handle != NULL), { *error_code = BATTERY_MONITOR_ERROR_DB_NOT_OPENED; },
                                                NULL, ("The database isn't connected."));
-
        BM_MEMSET(query, 0x00, BATTERY_MONITOR_SQL_LEN_MAX);
 
 #ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
@@ -971,7 +1274,6 @@ static appid_usage_s* bm_query_usage_by_appid(sqlite3 *bm_db_handle, const char
 #endif
 
        hstmt = bm_prepare_query(bm_db_handle, query);
-
        if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
                _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
                *error_code = BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
@@ -979,7 +1281,6 @@ static appid_usage_s* bm_query_usage_by_appid(sqlite3 *bm_db_handle, const char
        }
 
        appid_usage_s *bm_app_type = NULL;
-
        rc = bm_query_step(hstmt);
        BM_CATCH_ERROR_P(rc == SQLITE_ROW, {}, BATTERY_MONITOR_ERROR_RECORD_NOT_FOUND,
                                ("The record isn't found.(%s)\n", app_id));
@@ -1002,7 +1303,6 @@ static appid_usage_s* bm_query_usage_by_appid(sqlite3 *bm_db_handle, const char
        rc = bm_query_finalize(hstmt);
        BM_CATCH_ERROR_P((rc == BATTERY_MONITOR_ERROR_NONE), {}, rc, ("finalize error"));
        hstmt = NULL;
-
        *error_code = BATTERY_MONITOR_ERROR_NONE;
 
 CATCH:
@@ -1014,12 +1314,10 @@ CATCH:
                }
                hstmt = NULL;
        }
-
        if ((*error_code != BATTERY_MONITOR_ERROR_NONE) && bm_app_type) {
                BM_FREE(bm_app_type);
                bm_app_type = NULL;
        }
-
        if ((*error_code == BATTERY_MONITOR_ERROR_NONE) && bm_app_type != NULL) {
                _INFO("Returning appid usage");
                return bm_app_type;
@@ -1137,9 +1435,7 @@ static int bm_delete_table(sqlite3 *bm_db_handle, bm_stmt *phstmt, int num_app_i
                BM_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE AppName = ?", table);
 
        hstmt = bm_prepare_query(bm_db_handle, query);
-
        bm_query_bind_text(hstmt, binding_count++, app_id);
-
        if (hstmt == NULL) {
                _ERR("bm_svc_query_prepare(%s) failed(%s).\n", query, bm_db_err_msg(bm_db_handle));
                error_code = BATTERY_MONITOR_ERROR_DB_FAILED;
@@ -1162,8 +1458,8 @@ static int bm_delete_table(sqlite3 *bm_db_handle, bm_stmt *phstmt, int num_app_i
 
        hstmt =  NULL;
        _INFO("bm_delete_table end");
-END:
 
+END:
        EXIT;
        return error_code;
 }
@@ -1188,7 +1484,6 @@ static int bm_delete_table_by_app_id(sqlite3 *bm_db_handle, const char *AppId)
        BM_SNPRINTF(query, sizeof(query), "SELECT COUNT(*) FROM %s WHERE AppName = '%s'", BATTERY_MONITOR_APP_ID_MAP_TABLE, AppId);
 
        count = bm_get_record_count(bm_db_handle, query);
-
        if (bm_db_err_code(bm_db_handle) == SQLITE_PERM) {
                _ERR("Access failed(%s)", bm_db_err_msg(bm_db_handle));
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
@@ -1201,7 +1496,6 @@ static int bm_delete_table_by_app_id(sqlite3 *bm_db_handle, const char *AppId)
 
        /* transaction control required */
        ret_transaction = bm_begin_transaction(bm_db_handle);
-
        if (ret_transaction == BATTERY_MONITOR_ERROR_DATABASE_BUSY) {
                _ERR("database busy(%s)", bm_db_err_msg(bm_db_handle));
                return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
@@ -1239,7 +1533,6 @@ CATCH:
        }
 
        ret_transaction = bm_end_transaction(bm_db_handle, is_success);
-
        if (ret_transaction != BATTERY_MONITOR_ERROR_NONE)
                _ERR("bm_svc_delete:bm_svc_end_transaction fail %d, is_success=%d\n", ret_transaction, is_success);
 
@@ -1251,24 +1544,22 @@ static int bm_delete_table_by_time_interval(sqlite3 *bm_db_handle, const char* t
 {
        ENTER;
 
-       _INFO("bm_delete_table start - table[%s]", table);
+       _DBG("bm_delete_table start - table[%s]", table);
        int error_code = BATTERY_MONITOR_ERROR_NONE;
        int rc = 0;
        char query[BATTERY_MONITOR_SQL_LEN_MAX] = {0, };
        long int duration = bm_get_time_bias(1);
-
        bm_stmt hstmt = NULL;
 
        BM_RETURN_VAL((bm_db_handle != NULL), {}, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
        BM_RETURN_VAL((table != NULL), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, ("table is null!"));
 
-       if ((g_strcmp0(table, BATTERY_MONITOR_APP_ID_USAGE_TABLE) == 0))
-               BM_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE log_time <= %ld", table, duration);
-       else if (g_strcmp0(table, BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE) == 0)
+       if ((g_strcmp0(table, BATTERY_MONITOR_APP_ID_USAGE_TABLE) == 0 || g_strcmp0(table, BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE) == 0))
                BM_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE log_time <= %ld", table, duration);
+       else
+               BM_SNPRINTF(query, sizeof(query), "DELETE FROM %s WHERE time_s <= %ld", table, duration);
 
        hstmt = bm_prepare_query(bm_db_handle, query);
-
        if (hstmt == NULL) {
                _ERR("bm_svc_query_prepare(%s) failed(%s).\n", query, bm_db_err_msg(bm_db_handle));
                error_code = BATTERY_MONITOR_ERROR_DB_FAILED;
@@ -1291,17 +1582,12 @@ static int bm_delete_table_by_time_interval(sqlite3 *bm_db_handle, const char* t
 
        hstmt =  NULL;
        EXIT;
-END:
 
+END:
        return error_code;
 }
 
-/*
-Manager Functions
->-------To be called by bm-engine & bm-server.
->-------Only these will be exposed for other files to use.
-*/
-
+/* Manager Functions */
 int bm_server_appid_insert_to_db(const char* app_id)
 {
        ENTER;
@@ -1327,13 +1613,11 @@ int bm_server_appid_insert_to_db(const char* app_id)
 
        /* Transaction Control Required */
        ret_transaction = bm_begin_transaction(g_hBatteryMonitorDB);
-
        if (bm_db_err_code(g_hBatteryMonitorDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&battery_monitor_mutex);
                _ERR("Access failed(%s)", bm_db_err_msg(g_hBatteryMonitorDB));
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
        }
-
        if (ret_transaction == BATTERY_MONITOR_ERROR_DATABASE_BUSY) {
                _ERR("AppId map table insert:bm_begin_transaction fail %d\n", ret_transaction);
                pthread_mutex_unlock(&battery_monitor_mutex);
@@ -1345,7 +1629,6 @@ int bm_server_appid_insert_to_db(const char* app_id)
        }
 
        error_code = bm_appid_map_insert_to_db(g_hBatteryMonitorDB, app_id);
-
        if (error_code != BATTERY_MONITOR_ERROR_NONE) {
                ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
                _ERR("INSERT appid fail, rollback insert query(%d)!!!!\n", ret_transaction);
@@ -1374,13 +1657,11 @@ int bm_server_resource_usage_insert_to_db(resourceid_usage_s *bm_resource_type)
 
        /* Transaction Control Required */
        ret_transaction = bm_begin_transaction(g_hBatteryMonitorDB);
-
        if (bm_db_err_code(g_hBatteryMonitorDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&battery_monitor_mutex);
                _ERR("Access failed(%s)", bm_db_err_msg(g_hBatteryMonitorDB));
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
        }
-
        if (ret_transaction == BATTERY_MONITOR_ERROR_DATABASE_BUSY) {
                _ERR("Resource Usage insert:bm_begin_transaction fail %d\n", ret_transaction);
                pthread_mutex_unlock(&battery_monitor_mutex);
@@ -1392,14 +1673,12 @@ int bm_server_resource_usage_insert_to_db(resourceid_usage_s *bm_resource_type)
        }
 
        error_code = bm_resourceid_usage_insert_to_db(g_hBatteryMonitorDB, bm_resource_type);
-
        if (error_code != BATTERY_MONITOR_ERROR_NONE) {
                ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
                _ERR("INSERT resource usage fail, rollback insert query(%d)!!!!\n", ret_transaction);
                pthread_mutex_unlock(&battery_monitor_mutex);
                return error_code;
        }
-
        pthread_mutex_unlock(&battery_monitor_mutex);
        bm_end_transaction(g_hBatteryMonitorDB, true);
 
@@ -1421,13 +1700,11 @@ int bm_server_app_usage_insert_to_db(appid_usage_s *bm_app_type)
 
        /* Transaction Control Required */
        ret_transaction = bm_begin_transaction(g_hBatteryMonitorDB);
-
        if (bm_db_err_code(g_hBatteryMonitorDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&battery_monitor_mutex);
                _ERR("Access failed(%s)", bm_db_err_msg(g_hBatteryMonitorDB));
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
        }
-
        if (ret_transaction == BATTERY_MONITOR_ERROR_DATABASE_BUSY) {
                _ERR("App Usage insert:bm_begin_transaction fail %d\n", ret_transaction);
                pthread_mutex_unlock(&battery_monitor_mutex);
@@ -1439,7 +1716,6 @@ int bm_server_app_usage_insert_to_db(appid_usage_s *bm_app_type)
        }
 
        error_code = bm_appid_usage_insert_to_db(g_hBatteryMonitorDB, bm_app_type);
-
        if (error_code != BATTERY_MONITOR_ERROR_NONE) {
                ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
                _ERR("INSERT app usage fail, rollback insert query(%d)!!!!\n", ret_transaction);
@@ -1494,10 +1770,11 @@ int bm_server_delete_table_by_appid(const char* app_id)
 
        BM_RETURN_VAL((app_id != NULL), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, ("Application Id is NULL"));
        BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), {}, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
        pthread_mutex_lock(&battery_monitor_mutex);
 
        error_code = bm_delete_table_by_app_id(g_hBatteryMonitorDB, app_id);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE)
+               _ERR("Delete of table by app_id failed");
 
        pthread_mutex_unlock(&battery_monitor_mutex);
 
@@ -1513,18 +1790,15 @@ int bm_server_delete_table_by_time_interval(void)
        int ret_transaction = 0;
 
        BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), {}, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
-
        pthread_mutex_lock(&battery_monitor_mutex);
 
        /* Transaction Control Required */
        ret_transaction = bm_begin_transaction(g_hBatteryMonitorDB);
-
        if (bm_db_err_code(g_hBatteryMonitorDB) == SQLITE_PERM) {
                pthread_mutex_unlock(&battery_monitor_mutex);
                _ERR("Access failed(%s)", bm_db_err_msg(g_hBatteryMonitorDB));
                return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
        }
-
        if (ret_transaction == BATTERY_MONITOR_ERROR_DATABASE_BUSY) {
                _ERR("Usage Delete:bm_begin_transaction fail %d\n", ret_transaction);
                pthread_mutex_unlock(&battery_monitor_mutex);
@@ -1534,24 +1808,69 @@ int bm_server_delete_table_by_time_interval(void)
                pthread_mutex_unlock(&battery_monitor_mutex);
                return ret_transaction;
        }
-
        error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_RESOURCE_ID_USAGE_TABLE);
-
        if (error_code != BATTERY_MONITOR_ERROR_NONE) {
                ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
                _ERR("Delete old resource usage fail, rollback delete query(%d)!!!!\n", ret_transaction);
                pthread_mutex_unlock(&battery_monitor_mutex);
                return error_code;
        }
-
        error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_APP_ID_USAGE_TABLE);
-
        if (error_code != BATTERY_MONITOR_ERROR_NONE) {
                ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
                _ERR("Delete old app usage fail, rollback delete query(%d)!!!!\n", ret_transaction);
                pthread_mutex_unlock(&battery_monitor_mutex);
                return error_code;
        }
+       error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_GBL_BLE_STAT_TABLE);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+               ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+               _ERR("Delete ble_stat fail, rollback delete query(%d)!!!!\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return error_code;
+       }
+       error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_GBL_WFL_STAT_TABLE);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+               ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+               _ERR("Delete wifi_stat fail, rollback delete query(%d)!!!!\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return error_code;
+       }
+       error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_GBL_NT_STAT_TABLE);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+               ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+               _ERR("Delete nt_stat fail, rollback delete query(%d)!!!!\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return error_code;
+       }
+       error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_GBL_BR_STAT_TABLE);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+               ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+               _ERR("Delete sbr_stat fail, rollback delete query(%d)!!!!\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return error_code;
+       }
+       error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_GBL_SGT_STAT_TABLE);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+               ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+               _ERR("Delete sgt_stat fail, rollback delete query(%d)!!!!\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return error_code;
+       }
+       error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_GBL_WST_STAT_TABLE);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+               ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+               _ERR("Delete wst_stat fail, rollback delete query(%d)!!!!\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return error_code;
+       }
+       error_code = bm_delete_table_by_time_interval(g_hBatteryMonitorDB, BATTERY_MONITOR_GBL_BST_STAT_TABLE);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+               ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+               _ERR("Delete bst_stat fail, rollback delete query(%d)!!!!\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return error_code;
+       }
 
        pthread_mutex_unlock(&battery_monitor_mutex);
        bm_end_transaction(g_hBatteryMonitorDB, true);
@@ -1560,6 +1879,58 @@ int bm_server_delete_table_by_time_interval(void)
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
+// Battery Dump DB Operations
+int bm_server_battery_dump_insert_to_db(void *str_data, int type)
+{
+       ENTER;
+
+       int error_code = BATTERY_MONITOR_ERROR_NONE;
+       int ret_transaction = 0;
+
+       BM_RETURN_VAL((g_hBatteryMonitorDB != NULL), {}, BATTERY_MONITOR_ERROR_DB_NOT_OPENED, ("The database isn't connected."));
+       BM_RETURN_VAL((str_data != NULL), {}, BATTERY_MONITOR_ERROR_INVALID_PARAMETER, ("The Battery Dump Data is NULL"));
+
+       pthread_mutex_lock(&battery_monitor_mutex);
+
+       /* Transaction Control Required */
+       ret_transaction = bm_begin_transaction(g_hBatteryMonitorDB);
+       if (bm_db_err_code(g_hBatteryMonitorDB) == SQLITE_PERM) {
+       pthread_mutex_unlock(&battery_monitor_mutex);
+               _ERR("Access failed(%s)", bm_db_err_msg(g_hBatteryMonitorDB));
+               return BATTERY_MONITOR_ERROR_PERMISSION_DENIED;
+       }
+       if (ret_transaction == BATTERY_MONITOR_ERROR_DATABASE_BUSY) {
+               _ERR("Resource Usage insert:bm_begin_transaction fail %d\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+       } else if (ret_transaction != BATTERY_MONITOR_ERROR_NONE) {
+               _ERR("Resource Usage insert:bm_begin_transaction fail %d\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return ret_transaction;
+       }
+       error_code = bm_battery_stat_insert_to_db(g_hBatteryMonitorDB, str_data, type);
+       if (error_code != BATTERY_MONITOR_ERROR_NONE) {
+               ret_transaction = bm_end_transaction(g_hBatteryMonitorDB, false);
+               _ERR("INSERT resource usage fail, rollback insert query(%d)!!!!\n", ret_transaction);
+               pthread_mutex_unlock(&battery_monitor_mutex);
+               return error_code;
+       }
+
+       pthread_mutex_unlock(&battery_monitor_mutex);
+       bm_end_transaction(g_hBatteryMonitorDB, true);
+
+       EXIT;
+       return BATTERY_MONITOR_ERROR_NONE;
+}
+
+int bm_server_battery_dump_query_from_db(void *str_data, int type)
+{
+       ENTER;
+
+       EXIT;
+       return BATTERY_MONITOR_ERROR_NONE;
+}
+
 int initialize_database(void)
 {
        ENTER;
@@ -1573,7 +1944,6 @@ int initialize_database(void)
        }
 
        EXIT;
-
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
@@ -1590,6 +1960,5 @@ int deinitialize_database(void)
        }
 
        EXIT;
-
        return BATTERY_MONITOR_ERROR_NONE;
 }