Modify usage output and overflow check 38/227038/1 submit/tizen_5.5/20200311.113804
authorDewal Agarwal <d1.agarwal@samsung.com>
Wed, 26 Feb 2020 11:12:58 +0000 (16:42 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Mon, 9 Mar 2020 07:45:06 +0000 (07:45 +0000)
Change-Id: Iecffd54045b3d51e53e5a93d177d675f68f90555
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
(cherry picked from commit 527fe3a86d95c18de6a8dde826001842f26c37b9)

config/bm_power_profile_params.json
src/battery_dump/bd_history_item.c
src/bm_power_engine.c
src/bm_util.c

index 7301a53..932eae9 100644 (file)
@@ -44,6 +44,6 @@
                "p_cpu_system": 61
        },
        "battery": {
-               "p_battery": 500000
+               "p_battery": 500
        }
 }
index 9968094..4dfbf84 100644 (file)
@@ -221,8 +221,8 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
                usageMAh = (app_use->rId_ble + app_use->rId_wifi + app_use->rId_cpu +
                                app_use->rId_display + app_use->rId_device_network +
                                app_use->rId_gps + app_use->rId_hrm);
-               //ret = bm_engine_get_total_usage_by_app_id(appid, 1, &usage);
-               usageMAh = (usageMAh/1000);
+               // usage stored as mAs changed to mAh
+               usageMAh = (usageMAh/3600);
                dump_p = g_string_sized_new(30);
                BM_CHECK_MEM_ALLOC(dump_p, { BM_FREE(app_use); });
                g_string_append(dump_p, TIZEN_DUMP_VERSION);
@@ -239,7 +239,6 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
        const char *rid_str = NULL;
        for (int i = 0; i < 6; i++) {
                int usage = 0;
-               //ret = bm_engine_get_total_usage_by_resource_id(i, 1, &usage);
                rid_str = bm_get_resource_id_string(i);
                if (g_strcmp0(rid_str, "UNKNOWN RESOURCE-ID") == 0) {
                        _ERR("invalid resource-id");
@@ -254,7 +253,8 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
                dump_p = g_string_sized_new(30);
                BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(res_use); });
                usage = res_use->usage;
-               usageMAh = (float)usage/1000;
+               // usage stored as mAs changed to mAh
+               usageMAh = (float)usage/3600;
                g_string_append(dump_p, TIZEN_DUMP_VERSION);
                switch (i) {
                case 0://BT
@@ -1170,7 +1170,7 @@ static int bd_free_history_data_memory()
        for (int i = 0; i < h_count; i++) {
                if (history_data[i].wakelock_tag != NULL) {
                        _DBG("WL str");
-                       g_string_free (history_data[i].wakelock_tag->string_info, TRUE);
+                       g_string_free(history_data[i].wakelock_tag->string_info, TRUE);
                        _DBG("WL");
                        free(history_data[i].wakelock_tag);
                }
index 33a0959..ff1a494 100644 (file)
@@ -34,6 +34,7 @@
 bm_feature_data_h bm_data_handle = NULL;
 GHashTable *gl_hash = NULL;
 static struct bm_req_feature_data_handle_flag_s *bm_req_flag_h = NULL;
+const int mahp = 3600;
 int battery_capacity = 500;
 int gtimeo_id[2];
 
@@ -318,6 +319,8 @@ static int bm_appid_session_usage_map(char *app_id, int app_usage, bm_plugin_id_
 #endif /* DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN */
 
                _DBG("update - app_usage for app_id(%s), for resource(%d), by usage(%d)", app_id, resource_id, app_usage);
+               //_DBG("session usage bt %d, wifi %d, cpu %d, dsp %d, dn %d", temp->rId_ble, temp->rId_wifi, temp->rId_cpu,
+               //temp->rId_display, temp->rId_device_network);
        } else {
                appid_usage_s *temp = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
                if (temp == NULL) {
@@ -409,7 +412,8 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
        GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st2_free);
 
        long int edTime = 0, stTime = 0;
-       int sesTime = 0, scTime = 0, conTime = 0, RX = 0, TX = 0, onTime = 0;
+       long int sesTime = 0, scTime = 0, conTime = 0, RX = 0, TX = 0;
+       double 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);
@@ -459,20 +463,21 @@ 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;
+       long 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);
+       _DBG("Calculated Power for Bluetooth P_power_bt(%ld),  P_power_conn (%ld), P_power_data(%ld)", 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;
+       long 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 apprx = 0, apptx = 0;
+       double apptime = 0;
        long int rx_t = 0, tx_t = 0;
        long int ret_time = bm_get_log_time();
 
@@ -499,7 +504,7 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
                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)",
+               _DBG("Calculated Power for Appid(%s) -  P_power_app_bt(%ld), P_power_app_conn(%ld), P_power_app_data(%ld)",
                                        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);
@@ -565,7 +570,7 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
        g_hash_table_destroy(hash);
 
        /* Dump resource usage */
-       _DBG("BLE usage : %d", RX + TX);
+       _DBG("BLE usage : %ld", RX + TX);
        if (RX > 0 || TX > 0) {
                history_item_s hi;
                bd_print_history_item_reset(&hi);
@@ -602,8 +607,9 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
        GHashTable *hash = g_hash_table_new_full(g_str_hash, g_str_equal, bm_data_free, bm_atm_st2_free);
 
        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;
+       long int sesTime = 0, scTime = 0, tl_total = 0;
+       long int tl0 = 0, tl1 = 0, tl2 = 0, tl3 = 0, tl4 = 0;
+       double 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) {
@@ -661,9 +667,11 @@ 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);
 
+       tl0 /= 1000; tl1 /= 1000; tl2 /= 1000; tl3 /= 1000;  tl4 /= 1000;
+       scTime /= 1000; sesTime /= 1000; onTime /= 1000;
        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;
+       long int P_power_wifi = 0, P_power_data = 0, 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) +
@@ -671,15 +679,16 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
        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);
+       _DBG("Calculated Power for Wifi P_power_wifi(%ld),  P_power_conn (%ld), P_power_data(%ld)", 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;
+       long 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 apprx = 0, apptx = 0;
+       double apptime = 0;
        long int rx_t = 0, tx_t = 0;
        long int ret_time = bm_get_log_time();
 
@@ -697,6 +706,7 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
                apprx = temp->rx; rx_t += apprx;
                apptx = temp->tx; tx_t += apptx;
                apptime = temp->time;
+               apptime /= 1000;
                P_power_app_data = ((sP_power_wf_tx) * apptx) + ((sP_power_wf_rx) * apprx);
 
                if (onTime != 0)
@@ -707,7 +717,7 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
                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)",
+               _DBG("Calculated Power for Appid(%s) -  P_power_app_wifi(%ld), P_power_app_conn(%ld), P_power_app_data(%ld)",
                                        appid, P_power_app_wifi, P_power_app_conn, P_power_app_data);
 
                if (mode) {
@@ -816,9 +826,8 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
        /* 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_st1_free);
 
-       int uTime = 0;
-       int sTime = 0;
-       int onTime = 0;
+       long int uTime = 0, sTime = 0; 
+       double 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);
@@ -856,20 +865,22 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
 
        _DBG("received cpu power params - user[%d]\n, system[%d]\n", sP_power_cpu_user, sP_power_cpu_system);
        /* CPU power consumption Level - 1 at the Resource Level */
-       int P_power_cpu = 0, P_power_user = 0, P_power_system = 0;
+       long int P_power_cpu = 0, P_power_user = 0, P_power_system = 0;
+       _DBG("%ld %ld %lf", uTime, sTime, onTime);
+       uTime /= 1000; sTime /= 1000; onTime /= 1000;
        P_power_user = ((sP_power_cpu_user * uTime));
        P_power_system = ((sP_power_cpu_system * sTime));
        P_power_cpu = P_power_user + P_power_system;
 
-       _DBG("Calculated Power for CPU P_power_cpu (%d),  P_power_user (%d), P_power_system (%d)", P_power_cpu, P_power_user, P_power_system);
+       _DBG("Calculated Power for CPU P_power_cpu (%ld),  P_power_user (%ld), P_power_system (%ld)", P_power_cpu, P_power_user, P_power_system);
        /* 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;
+       long int P_power_app_cpu = 0, P_power_app_use = 0;
+       double apptime = 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));
@@ -883,7 +894,8 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
                apptime = 0;
                app_time_map_st1 *temp = (app_time_map_st1 *)value;
                appid = temp->app_id;
-               apptime = temp->time;
+               apptime = (temp->time);
+               apptime /= 1000;
                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;
@@ -892,7 +904,7 @@ int bm_cpu_calc_power_and_commit(bm_cpu_st *handle, bool mode)
                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);
+               _DBG("Calculated Power for Appid (%s) P_power_app_cpu (%ld),  P_power_app_use (%ld)", appid, P_power_app_cpu, P_power_app_use);
 
                if (mode) {
                        ret_val = bm_server_appid_insert_to_db(app_usage->AppId);
@@ -948,10 +960,9 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
        /* 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_st1_free);
 
-       long int edTime = 0;
-       long int stTime = 0;
-       int sesTime = 0, onTime = 0;
-       int highTime = 0, medTime = 0, lowTime = 0;
+       long int edTime = 0, stTime = 0, sesTime = 0;
+       long int highTime = 0, medTime = 0, lowTime = 0;
+       double 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);
@@ -994,18 +1005,20 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
 
        _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));
+       lowTime /= 1000; medTime /= 1000; highTime /= 1000; onTime /= 1000;
+       long int P_power_disp = 0, P_power_on = 0;
+       _DBG("Total Time in s low %ld med %ld high %ld session %ld onTime %lf", lowTime, medTime, highTime, sesTime, onTime);
+       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);
+       _DBG("Calculated Power for Display P_power_disp (%ld),  P_power_on (%ld)", 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;
+       long int P_power_app_disp = 0, P_power_app_on = 0;
        char *appid = NULL;
-       int apptime = 0;
+       double apptime = 0;
        long int ret_time = bm_get_log_time();
 
        appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
@@ -1020,7 +1033,7 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
                app_time_map_st1 *temp = (app_time_map_st1 *)value;
                appid = temp->app_id;
                apptime = temp->time;
-
+               apptime /= 1000;
                if (onTime != 0)
                        P_power_app_on = (P_power_on * apptime)/onTime; //check for 0 denominator & same units
                P_power_app_disp = P_power_app_on;
@@ -1029,7 +1042,7 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
                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);
+               _DBG("Calculated Power for Appid (%s) P_power_app_disp(%ld),  P_power_app_on (%ld)", appid, P_power_app_disp, P_power_app_on);
                if (mode) {
                        ret_val = bm_server_appid_insert_to_db(app_usage->AppId);
                        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
@@ -1071,7 +1084,7 @@ int bm_display_calc_power_and_commit(bm_display_st *handle, bool mode)
                return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
        }
 
-       gbr_st->time_s = ret_time; gbr_st->dark = BATTERY_MONITOR_GET_DATA_JOB_PERIOD;
+       gbr_st->time_s = ret_time; gbr_st->dark = (BATTERY_MONITOR_GET_DATA_JOB_PERIOD/1000);
        gbr_st->dark -= sesTime; gbr_st->dim = lowTime; gbr_st->medium = medTime;
        gbr_st->bright = highTime;
 
@@ -1103,8 +1116,9 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
        /* 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);
 
-       int tl0 = 0, tl1 = 0, tl2 = 0, tl3 = 0, tl4 = 0, tl5 = 0, tl6 = 0;
-       long int RX = 0, TX = 0, tl_total = 0;
+       long int tl0 = 0, tl1 = 0, tl2 = 0, tl3 = 0, tl4 = 0, tl5 = 0, tl6 = 0;
+       long int RX = 0, TX = 0;
+       double 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);
@@ -1157,22 +1171,24 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
                        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);
 
+       tl0 /= 1000; tl1 /= 1000; tl2 /= 1000; tl3 /= 1000; tl4 /= 1000; tl5 /= 1000; tl6 /= 1000;
        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;
+       long 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);
+       _DBG("Calculated Power for Device Network P_power_ntw(%ld),  P_power_conn (%ld), P_power_data(%ld)", 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;
+       long 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 apprx = 0, apptx = 0;
+       double apptime = 0;
        long int ret_time = bm_get_log_time();
 
        appid_usage_s *app_usage = (appid_usage_s *)calloc(1, sizeof(appid_usage_s));
@@ -1186,9 +1202,8 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
                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;
+               apprx = temp->rx; apptx = temp->tx;
+               apptime = temp->time; apptime /= 1000;
                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
@@ -1198,7 +1213,7 @@ int bm_device_network_calc_power_and_commit(bm_device_network_st *handle, bool m
                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);
+               _DBG("Calculated Power for Appid (%s) P_power_app_dntw(%ld),  P_power_app_conn (%ld), P_power_app_data(%ld)", appid, P_power_app_dntw, 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)
@@ -1540,127 +1555,88 @@ int bm_get_data_from_handles(void)
                _ERR("Global Hash creation failed");
 
        /* parsing ble data */
-       if (bm_data_handle->bm_ble_handle != NULL &&
-                       bm_req_flag_h->req_ble_data) {
-
+       if (bm_data_handle->bm_ble_handle != NULL && bm_req_flag_h->req_ble_data) {
                _DBG("parsing ble data");
-
                ret_val = bm_ble_calc_power_and_commit(bm_data_handle->bm_ble_handle, mode);
-
                BM_CHECK_VAL((ret_val == BATTERY_MONITOR_ERROR_NONE), "ble power cal failure");
-
        } else {
                _DBG("set ble flag - true");
                bm_engine_set_req_flag_handle(BM_PLUGIN_ID_BLE, true);
        }
-
        _DBG("completed ble data request");
 
        /* parsing wifi data */
-       if (bm_data_handle->bm_wifi_handle != NULL &&
-                       bm_req_flag_h->req_wifi_data) {
-
+       if (bm_data_handle->bm_wifi_handle != NULL && bm_req_flag_h->req_wifi_data) {
                _DBG("parsing wifi data");
-
                ret_val = bm_wifi_calc_power_and_commit(bm_data_handle->bm_wifi_handle, mode);
-
                BM_CHECK_VAL((ret_val == BATTERY_MONITOR_ERROR_NONE), "wifi power calc failure");
        } else {
                _DBG("set wifi flag - true");
                bm_engine_set_req_flag_handle(BM_PLUGIN_ID_WIFI, true);
        }
-
        _DBG("completed wifi data request");
 
        /* parsing cpu data */
-       if (bm_data_handle->bm_cpu_handle != NULL &&
-                       bm_req_flag_h->req_cpu_data) {
-
+       if (bm_data_handle->bm_cpu_handle != NULL && bm_req_flag_h->req_cpu_data) {
                _DBG("parsing cpu data");
-
                ret_val = bm_cpu_calc_power_and_commit(bm_data_handle->bm_cpu_handle, mode);
-
                BM_CHECK_VAL((ret_val == BATTERY_MONITOR_ERROR_NONE), "cpu power calc failure");
        } else {
                _DBG("set cpu flag - true");
                bm_engine_set_req_flag_handle(BM_PLUGIN_ID_CPU, true);
        }
-
        _DBG("completed cpu data request");
 
        /* parsing display data */
-       if (bm_data_handle->bm_display_handle != NULL &&
-                       bm_req_flag_h->req_dp_data) {
-
+       if (bm_data_handle->bm_display_handle != NULL && bm_req_flag_h->req_dp_data) {
                _DBG("parsing display data");
-
                ret_val = bm_display_calc_power_and_commit(bm_data_handle->bm_display_handle, mode);
-
                BM_CHECK_VAL((ret_val == BATTERY_MONITOR_ERROR_NONE), "display power calc failure");
        } else {
                _DBG("set display flag - true");
                bm_engine_set_req_flag_handle(BM_PLUGIN_ID_DISPLAY, true);
        }
-
        _DBG("completed display data request");
 
        /* parsing device-network data */
-       if (bm_data_handle->bm_dn_handle != NULL &&
-                       bm_req_flag_h->req_dn_data) {
-
+       if (bm_data_handle->bm_dn_handle != NULL && bm_req_flag_h->req_dn_data) {
                _DBG("parsing device-network data");
-
                ret_val = bm_device_network_calc_power_and_commit(bm_data_handle->bm_dn_handle, mode);
-
                BM_CHECK_VAL((ret_val == BATTERY_MONITOR_ERROR_NONE), "device-network power calc failure");
        } else {
                _DBG("set device-network flag - true");
                bm_engine_set_req_flag_handle(BM_PLUGIN_ID_DEVICE_NETWORK, true);
        }
-
        _DBG("completed device-network data request");
 
 #ifdef DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN
        /* parsing gps data */
-       if (bm_data_handle->bm_gps_handle != NULL &&
-                       bm_req_flag_h->req_gps_data) {
-
+       if (bm_data_handle->bm_gps_handle != NULL && bm_req_flag_h->req_gps_data) {
                _DBG("parsing gps data");
-
                ret_val = bm_gps_calc_power_and_commit(bm_data_handle->bm_gps_handle);
-
                BM_CHECK_VAL((ret_val == BATTERY_MONITOR_ERROR_NONE), "gps-sensor power calc failure");
        } else {
                _DBG("set gps-sensor flag - true");
                bm_engine_set_req_flag_handle(BM_PLUGIN_ID_GPS_SENSOR, true);
        }
-
        _DBG("completed gps data request");
 
        /* parsing hrm data */
-       if (bm_data_handle->bm_hrm_handle != NULL &&
-                       bm_req_flag_h->req_hrm_data) {
-
+       if (bm_data_handle->bm_hrm_handle != NULL && bm_req_flag_h->req_hrm_data) {
                _DBG("parsing hrm data");
-
                ret_val = bm_hrm_calc_power_and_commit(bm_data_handle->bm_hrm_handle);
-
                BM_CHECK_VAL((ret_val == BATTERY_MONITOR_ERROR_NONE), "hrm-sensor power calc failure");
        } else {
                _DBG("set hrm-sensor flag - true");
                bm_engine_set_req_flag_handle(BM_PLUGIN_ID_HRM_SENSOR, true);
        }
-#endif /* DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN */
        _DBG("completed hrm data request");
+#endif /* DISABLE_FEATURE_DATA_FROM_GPS_HRM_PLUGIN */
 
        /* parsing battery data */
-
        _DBG("parsing battery data");
-
        ret_val = bm_battery_calc_power_and_commit();
-
        BM_CHECK_VAL((ret_val == BATTERY_MONITOR_ERROR_NONE), "battery power calc failure");
-
        _DBG("completed battery data request");
 
        ret_val = bm_insert_appid_session_usage_to_db();
@@ -1878,6 +1854,7 @@ int initialize_power_engine(void)
        ret_val = bm_get_battery_power_params(&battery_capacity);
        if (ret_val != BATTERY_MONITOR_ERROR_NONE)
                _ERR("unable ro read battery capacity");
+       battery_capacity *= mahp; //Battery Capacity in mAs
 
        EXIT;
        return ret_val;
index c8340b3..8ef6fff 100644 (file)
@@ -242,7 +242,7 @@ int bm_calc_individual_consumption(int resource_val, int total_consumption)
                return 0;
        }
 
-       return ((resource_val * 100)/total_consumption);
+       return (((long)resource_val*100)/total_consumption);
 }
 
 GVariant* bm_marshal_serialized_data(const bm_total_consumption_h data)