Make new states about resource usage 27/223627/4
authorKichan Kwon <k_c.kwon@samsung.com>
Thu, 30 Jan 2020 09:56:09 +0000 (18:56 +0900)
committerKichan Kwon <k_c.kwon@samsung.com>
Wed, 19 Feb 2020 05:17:57 +0000 (14:17 +0900)
- Bu(BLE usage) and Wu(Wi-Fi usage)
- To store usage, add a new field in the history item

Change-Id: I72f0c7bed623df53806b8238377166317fce9009
Signed-off-by: Kichan Kwon <k_c.kwon@samsung.com>
include/bd_history_item.h
src/battery_dump/bd_history_item.c
src/bm_power_engine.c

index af4ca0c..e287f0d 100644 (file)
@@ -46,6 +46,8 @@ typedef struct _history_item_s {
        int battery_temperature;
        int battery_voltage;
        int battery_charge;//UAh
+       int usage_type;
+       int usage;
        // SPool related fields
        int event_code;
        history_tag_s* event_tag;
@@ -62,6 +64,8 @@ typedef struct _dump_data_s {
        int state_1;
        int state_2;
        int battery_chargeUAh;
+       int usage_type;
+       int usage;
        int event_code;
        history_tag_s* event_tag;
        history_tag_s* wakelock_tag;
@@ -90,6 +94,7 @@ typedef struct _encoding_map_s {
 #define CM_RST 7
 #define CM_SHTDN 8
 #define CM_OVRFL 6 //:Used in NC
+#define CM_USAGE 9
 
 // Functions for the other part of the service
 int bd_initialize_battery_dump(void);
@@ -187,6 +192,7 @@ static const int ET_SCREEN_WAKE_UP = 0x0012;
 static const int ET_WAKEUP_AP = 0x0013;
 static const int ET_LONG_WAKE_LOCK = 0x0014;
 static const int ET_COUNT = 0x0016;
+
 /*
 static const int ET_TYPE_MASK = ~(ET_FLAG_START|ET_FLAG_FINISH);
 static const int ET_PROC_START = ET_PROC | ET_FLAG_START;
@@ -213,6 +219,9 @@ static const int ET_LONG_WAKE_LOCK_START = ET_LONG_WAKE_LOCK | ET_FLAG_START;
 static const int ET_LONG_WAKE_LOCK_FINISH = ET_LONG_WAKE_LOCK | ET_FLAG_FINISH;
 */
 
+static const int USAGE_BLUETOOTH = 1 << 0;
+static const int USAGE_WIFI = 1 << 1;
+
 #ifdef __cplusplus
 }
 #endif
index b285c99..805354b 100644 (file)
@@ -42,6 +42,8 @@ char state2_map[32][5] = {"", "", "", "", "", "", "", "", "", "", "", "", "", ""
        "", "Ud", "Chtp", "bles", "ca", "b", "Pcl", "ch", "", "", "fl", "W", "Ww", "v", "ps"};
 char event_map[32][4] = {"Enl", "Epr", "Efg", "Etp", "Esy", "Ewl", "Ejb", "Eur", "Euf", "Ecn",
        "Eac", "Epi", "Epu", "Eal", "Est", "Eai", "Eaa", "Etw", "Esw", "Ewa", "Elw", "Eec"};
+char usage_map[32][4] = {"Bu", "Wu", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+       "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
 GHashTable *app_map = NULL;
 
 static int bd_print_pool_entry(int fd, int idx, history_tag_s *pool_info)
@@ -641,6 +643,12 @@ static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
        dump_node->time_current = history_data[index].time_current;
        _DBG("C TIME is %lld", dump_node->time_current);
 
+       dump_node->usage_type = history_data[index].usage_type;
+       _DBG("Usage type is %d", dump_node->usage_type);
+
+       dump_node->usage = history_data[index].usage;
+       _DBG("Usage is %d", dump_node->usage);
+
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
@@ -653,6 +661,8 @@ int bd_print_history_item_reset(history_item_s* old_state)
        old_state->time_s = -1;
        old_state->state_1 = 0;
        old_state->state_2 = 0;
+       old_state->usage_type = 0;
+       old_state->usage = 0;
        //TEMP: Change to 0;
        old_state->battery_level = -1;
        old_state->battery_status = -1;
@@ -662,6 +672,10 @@ int bd_print_history_item_reset(history_item_s* old_state)
        old_state->battery_voltage = -1;
        old_state->battery_charge = -1;
 
+       old_state->event_tag = NULL;
+       old_state->wakelock_tag = NULL;
+       old_state->wakereason_tag = NULL;
+
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
@@ -771,6 +785,17 @@ int bd_print_history_item_main(int fd, int num_h_items, long base_time, bool chk
                        }
                        dump_p = g_string_append(dump_p, "*OVERFLOW*\n");
                        _DBG("value %s", dump_p->str);
+               } else if (new_state.cmd_s == CM_USAGE) {
+                       for (int i = 0; i < 32; i++) {
+                               if (new_state.usage_type == (1 << i)) {
+                                       dump_p = g_string_append(dump_p, ",");
+                                       g_string_append_printf(dump_p, "%s", usage_map[i]);
+                                       dump_p = g_string_append(dump_p, "=");
+                                       g_string_append_printf(dump_p, "%d", new_state.usage);
+                                       dump_p = g_string_append(dump_p, "\n");
+                                       _DBG("value %d", new_state.usage);
+                               }
+                       }
                } else {
                        if (!chkin) {
                                //NC
@@ -1132,6 +1157,9 @@ static int bd_set_history_from_listener(history_item_s* nrec)
        history_data[h_count].state_1 = nrec->state_1;
        history_data[h_count].state_2 = nrec->state_2;
 
+       history_data[h_count].usage_type = nrec->usage_type;
+       history_data[h_count].usage = nrec->usage;
+
        if (h_count < HISTORY_SIZE_MAX)
                h_count++;
        else {
index 9344d28..1adb21c 100644 (file)
@@ -15,6 +15,8 @@
  *
  */
 
+#include <sys/time.h>
+
 #include <device/battery.h>
 #include <device/callback.h>
 
@@ -27,6 +29,7 @@
 #include "bm_private.h"
 #include "bd_private.h"
 #include "bm_util.h"
+#include "bd_history_item.h"
 
 bm_feature_data_h bm_data_handle = NULL;
 GHashTable *gl_hash = NULL;
@@ -560,6 +563,24 @@ int bm_ble_calc_power_and_commit(bm_bluetooth_st *handle, bool mode)
        /* Free the hash map */
        g_hash_table_destroy(hash);
 
+       /* Dump resource usage */
+       _DBG("BLE usage : %d", RX + TX);
+       if (RX > 0 || TX > 0) {
+               history_item_s hi;
+               bd_print_history_item_reset(&hi);
+
+               struct timeval tv;
+               gettimeofday(&tv, NULL);
+
+               hi.time_s = ((long long)tv.tv_sec * 1000) + ((long long)tv.tv_usec / 1000);
+
+               hi.cmd_s = CM_USAGE;
+               hi.usage_type = USAGE_BLUETOOTH;
+               hi.usage = RX + TX;
+
+               bd_store_history_item(&hi);
+       }
+
        EXIT;
        return ret_val;
 }
@@ -757,6 +778,24 @@ int bm_wifi_calc_power_and_commit(bm_wifi_st *handle, bool mode)
        /* Free the Hash Map */
        g_hash_table_destroy(hash);
 
+       /* Dump resource usage */
+       _DBG("Wi-Fi usage : %ld", RX + TX);
+       if (RX > 0 || TX > 0) {
+               history_item_s hi;
+               bd_print_history_item_reset(&hi);
+
+               struct timeval tv;
+               gettimeofday(&tv, NULL);
+
+               hi.time_s = ((long long)tv.tv_sec * 1000) + ((long long)tv.tv_usec / 1000);
+
+               hi.cmd_s = CM_USAGE;
+               hi.usage_type = USAGE_WIFI;
+               hi.usage = RX + TX;
+
+               bd_store_history_item(&hi);
+       }
+
        EXIT;
        return ret_val;
 }