[ADDING]Battery Dump: Str Pool Support 29/220829/2
authorDewal Agarwal <d1.agarwal@samsung.com>
Mon, 23 Dec 2019 13:31:49 +0000 (19:01 +0530)
committerKichan Kwon <k_c.kwon@samsung.com>
Thu, 26 Dec 2019 01:03:49 +0000 (10:03 +0900)
Change-Id: Idfacad52ba1bf6f47189759fbc88fe26bba1d083
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
include/bd_history_item.h
src/battery_dump/bd_history_item.c

index e7b2ca7..dfadbb1 100644 (file)
@@ -30,7 +30,7 @@ extern "C" {
 typedef struct _history_tag_s {
        GString* string_info;
        int uid;
-       int hsp_idx;
+       int sp_idx;
 } history_tag_s;
 
 typedef struct _history_item_s {
@@ -79,8 +79,10 @@ typedef struct _encoding_map_s {
 */
 
 #define HISTORY_SIZE_MAX 1000000 // Maximum Allowed History
+#define S_POOL_SIZE_MAX 10000
 #define TIZEN_DUMP_VERSION "9"
 #define DUMP_DATA_TAG "h"
+#define DUMP_DATA_TAG_1 "hsp"
 
 #define CM_UPD 0
 #define CM_NULL -1
index af972bd..1077a79 100644 (file)
 #include <stdlib.h>
 #include <time.h>
 #include <glib/gprintf.h>
-
+#include <stdio.h>
 #include <bd_history_item.h>
 #include <bm_dbg.h>
 #include <bm_common.h>
 
 dump_data_s history_data[HISTORY_SIZE_MAX];
-int counter = 0;
+int h_count = 0; int h_flag = false;
 char state1_map[32][4] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Wm",
        "", "Sd", "BP", "S", "Psc", "a", "s", "", "Pr", "Wr", "Ws", "Wl", "g", "w", "r"};
-char state2_map[32][5] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
-       "Ud", "Chtp", "bles", "ca", "b", "Pcl", "ch", "", "", "fl", "W", "Ww", "v", "ps"};
+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"};
+//FILE *fp = NULL;
+
+static int bd_print_pool_entry(int idx, history_tag_s *pool_info)
+{
+       ENTER;
+
+       _DBG("Value from history data %d", idx);
+
+       GString *dump_p = g_string_sized_new(30);
+
+       dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       dump_p = g_string_append_c(dump_p, ',');
+       dump_p = g_string_append(dump_p, DUMP_DATA_TAG_1);
+       dump_p = g_string_append_c(dump_p, ',');
+       g_string_append_printf(dump_p, "%d,", pool_info->sp_idx);
+       g_string_append_printf(dump_p, "%d,", pool_info->uid);
+       dump_p = g_string_append(dump_p, "\"");
+
+       if (pool_info->string_info != NULL) {
+               gchar *temp = g_strdup(pool_info->string_info->str);
+               dump_p = g_string_append(dump_p, temp);
+               g_free(temp);
+       }
+
+       dump_p = g_string_append(dump_p, "\"");
+       dump_p = g_string_append(dump_p, "\n");
+       _DBG("%s", dump_p->str);
+//     fputs(dump_p->str, fp);//TEMP
+
+       EXIT;
+       return BATTERY_MONITOR_ERROR_NONE;
+}
+
+static int bd_get_pool_entry_from_dump(void)
+{
+       ENTER;
+
+       GString *dump_p = g_string_sized_new(30);
+       dump_p = g_string_append(dump_p, TIZEN_DUMP_VERSION);
+       dump_p = g_string_append(dump_p, ",0");
+       dump_p = g_string_append(dump_p, ",i");
+       dump_p = g_string_append(dump_p, ",vers");
+       dump_p = g_string_append(dump_p, ",19,150,NMF26V,NMF26V");
+       dump_p = g_string_append(dump_p, "\n");
+       _DBG("%s", dump_p->str);
+//     fputs(dump_p->str, fp);//TEMP
+       g_free(dump_p->str);
+       int ret = BATTERY_MONITOR_ERROR_NONE;
+       int log_count = h_count;
+       for (int i = 0; i < log_count; i++) {
+               history_tag_s *pool_info = NULL;
+               if (history_data[i].event_tag != NULL) {
+                       pool_info = history_data[i].event_tag;
+                       ret = bd_print_pool_entry(i, pool_info);
+                       if (ret != BATTERY_MONITOR_ERROR_NONE)
+                               return BATTERY_MONITOR_ERROR_INTERNAL;
+               }
+               if (history_data[i].wakelock_tag != NULL) {
+                       pool_info = history_data[i].wakelock_tag;
+                       ret = bd_print_pool_entry(i, pool_info);
+                       if (ret != BATTERY_MONITOR_ERROR_NONE)
+                               return BATTERY_MONITOR_ERROR_INTERNAL;
+               }
+               if (history_data[i].wakereason_tag != NULL) {
+                       pool_info = history_data[i].wakereason_tag;
+                       ret = bd_print_pool_entry(i, pool_info);
+                       if (ret != BATTERY_MONITOR_ERROR_NONE)
+                               return BATTERY_MONITOR_ERROR_INTERNAL;
+               }
+       }
+
+       EXIT;
+       return BATTERY_MONITOR_ERROR_NONE;
+}
 
 // The index passed in the fn should be preferrably continuous,
 // Other things should be implemented at dumping function.
@@ -38,15 +112,13 @@ static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
 {
        ENTER;
 
-       if (counter >= HISTORY_SIZE_MAX || index > counter) {
-               // This assumes that counter is always greater
-               // and old data should be dumped.
+       if (h_count >= HISTORY_SIZE_MAX || index > h_count) {
                _ERR("Some Error occured with global index");
                return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
        }
 
        _DBG("Value of index %d", index);
-       _DBG("Value of counter %d", counter);
+       _DBG("Value of h_count %d", h_count);
        // Print time if required
        int dvar1 = 0, dvar2 = 0;
        dvar1 = history_data[index].dump_1;
@@ -80,10 +152,14 @@ static int bd_get_history_detail_from_dump(int index, history_item_s* dump_node)
        dump_node->event_tag = history_data[index].event_tag;
        if (dump_node->event_tag == NULL)
                _DBG("Event_Tag_NULL");
+       else//Remove
+               _DBG("%d %d %s", dump_node->event_tag->uid, dump_node->event_tag->sp_idx,
+               dump_node->event_tag->string_info->str);
        dump_node->wakelock_tag = history_data[index].wakelock_tag;
        if (dump_node->wakelock_tag == NULL)
                _DBG("Wakelock_Tag_NULL");
        dump_node->wakereason_tag = history_data[index].wakereason_tag;
+       //:Not supported
        if (dump_node->wakereason_tag == NULL)
                _DBG("Wakereason_Tag_NULL");
        dump_node->time_s = history_data[index].time_s;
@@ -118,12 +194,13 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
 {
        ENTER;
 
-       if (counter >= HISTORY_SIZE_MAX) {
+       if (h_count >= HISTORY_SIZE_MAX) {
                _ERR("Some Error occured with global index");
                return BATTERY_MONITOR_ERROR_OUT_OF_MEMORY;
        }
 
        int ret = BATTERY_MONITOR_ERROR_NONE;
+       h_flag = false; //Lock
 
        history_item_s new_state;
        history_item_s old_state;
@@ -134,7 +211,13 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                return ret;
        }
 
-       int log_count = counter;
+//     fp = fopen("/tmp/test.txt", "w+");//TEMP
+
+       ret = bd_get_pool_entry_from_dump();
+       if (ret != BATTERY_MONITOR_ERROR_NONE)
+               _ERR("S pool data dump failed");
+
+       int log_count = h_count;
        for (int i = 0; i < log_count; i++) {
 
                ret = bd_get_history_detail_from_dump(i, &new_state);
@@ -316,7 +399,7 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                                                        //_DBG("value %s", dump_p->str);
                                                        if (chkin)
                                                                g_string_append_printf(dump_p, "%d",
-                                                               new_state.wakelock_tag->hsp_idx);
+                                                               new_state.wakelock_tag->sp_idx);
                                                        else{
                                                                //: NC
                                                        }
@@ -332,8 +415,8 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                                dump_p = g_string_append(dump_p, ",w=");
                                if (chkin) {
                                        g_string_append_printf(dump_p, "%d",
-                                       new_state.wakelock_tag->hsp_idx);
-                                       //_DBG("value %s", dump_p->str);
+                                       new_state.wakelock_tag->sp_idx);
+                                       _DBG("value %s", dump_p->str);
                                } else {
                                }
                        }
@@ -366,7 +449,7 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                                dump_p = g_string_append(dump_p, ",wr=");
                                _DBG("value %s", dump_p->str);
                                g_string_append_printf(dump_p, "%d",
-                               new_state.wakereason_tag->hsp_idx);
+                               new_state.wakereason_tag->sp_idx);
                                _DBG("value %s", dump_p->str);
                        }
                } else {
@@ -385,6 +468,7 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                                gchar* temp = g_strdup(event_map[k]);
                                g_string_append(dump_p, temp);
                                _DBG("value %s", dump_p->str);
+                               g_free(temp);
                        } else {
                                dump_p = g_string_append(dump_p, "Ev");
                                g_string_append_printf(dump_p, "%d", k);
@@ -394,7 +478,8 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                        _DBG("value %s", dump_p->str);
                        if (chkin) {
                                g_string_append_printf(dump_p, "%d",
-                                       new_state.event_tag->hsp_idx);
+                                       new_state.event_tag->sp_idx);
+                               //:Free sp memory.
                        } else {
                                //: for NC
                        }
@@ -405,8 +490,11 @@ int bd_print_history_item_main(int num_h_items, long base_time, bool chkin)
                old_state.state_2 = new_state.state_2;
                _DBG("State assigned");
                _DBG("%s", dump_p->str);
+//             fputs(dump_p->str, fp);//TEMP
                g_free(dump_p->str);
        }
+       h_flag = true;
+//     fclose(fp);//TEMP
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
@@ -419,7 +507,7 @@ static int bd_set_history_from_listener(history_item_s* nrec)
        time_t current_time;
        time(&current_time); //This time needs to be changed to MT
 
-       history_data[counter].time_s = current_time;
+       history_data[h_count].time_s = current_time;
 
        dvar1 = ((nrec->cmd_s) & 0xff) | ((nrec->battery_level << 8) & 0xff00) |
                ((nrec->battery_status << 16) & 0xf0000) |
@@ -435,36 +523,36 @@ static int bd_set_history_from_listener(history_item_s* nrec)
        _DBG("Value of encoded value 1 %d", dvar1);
        _DBG("Value of encoded value 2 %d", dvar2);
 
-       history_data[counter].dump_1 = dvar1;
-       history_data[counter].dump_2 = dvar2;
-       history_data[counter].battery_chargeUAh = nrec->battery_charge;
+       history_data[h_count].dump_1 = dvar1;
+       history_data[h_count].dump_2 = dvar2;
+       history_data[h_count].battery_chargeUAh = nrec->battery_charge;
 
        if (nrec->wakelock_tag != NULL)
-               history_data[counter].wakelock_tag = nrec->wakelock_tag;
+               history_data[h_count].wakelock_tag = nrec->wakelock_tag;
 
        if (nrec->wakereason_tag != NULL)
-               history_data[counter].wakereason_tag = nrec->wakereason_tag;
+               history_data[h_count].wakereason_tag = nrec->wakereason_tag;
 
        if (nrec->event_code != ET_NONE) {
-               history_data[counter].event_code = nrec->event_code;
-               history_data[counter].event_tag = nrec->event_tag;
+               history_data[h_count].event_code = nrec->event_code;
+               history_data[h_count].event_tag = nrec->event_tag;
        }
 
        if (nrec->cmd_s == CM_CRR_TIME || nrec->cmd_s == CM_RST)
-               history_data[counter].time_current = current_time;
+               history_data[h_count].time_current = current_time;
 
-       history_data[counter].state_1 = nrec->state_1;
-       history_data[counter].state_2 = nrec->state_2;
+       history_data[h_count].state_1 = nrec->state_1;
+       history_data[h_count].state_2 = nrec->state_2;
 
-       if (counter < HISTORY_SIZE_MAX)
-               counter++;
+       if (h_count < HISTORY_SIZE_MAX)
+               h_count++;
        else {
                //: Give some buffer
                int ret = bd_print_history_item_main(0, current_time, 1);
                if (ret != BATTERY_MONITOR_ERROR_NONE)
                        return ret;
 
-               counter = 0;
+               h_count = 0;
        }
 
        EXIT;
@@ -480,6 +568,11 @@ int bd_store_history_item(history_item_s* nrec)
                return BATTERY_MONITOR_ERROR_INVALID_PARAMETER;
        }
 
+       if (!h_flag) {
+               _ERR("Data Dump in progress");
+               return BATTERY_MONITOR_ERROR_DATABASE_BUSY;
+       }
+
        int ret = BATTERY_MONITOR_ERROR_NONE;
        ret = bd_set_history_from_listener(nrec);
        if (ret != BATTERY_MONITOR_ERROR_NONE) {
@@ -491,6 +584,7 @@ int bd_store_history_item(history_item_s* nrec)
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
+/*
 //: remove this
 static int bd_test_fn()
 {
@@ -513,13 +607,27 @@ static int bd_test_fn()
        ts.battery_temperature = 226;
        ts.battery_voltage = 400;
        ts.battery_charge = 0;
-       ts.event_code = ET_NONE;
-       ts.event_tag = NULL;
+       ts.event_code = ET_PROC; //Dummy Event
+       ts.event_tag = (history_tag_s *)calloc(1, sizeof(history_tag_s));
+       if (ts.event_tag != NULL) {
+               _DBG("Memory created successfully");
+               GString *temp = ts.event_tag->string_info;
+               temp = g_string_sized_new(30);
+               ts.event_tag->uid = 40;
+               ts.event_tag->sp_idx = 1;
+               temp = g_string_append(temp, "test-app");
+               ts.event_tag->string_info = temp;
+               _DBG("%s _1", ts.event_tag->string_info->str);
+       }
        ts.wakelock_tag = NULL;
        ts.wakereason_tag = NULL;
+       // Node 1
        bd_set_history_from_listener(&ts);
 
+       ts.event_code = ET_NONE;
+       ts.event_tag = NULL;
        ts.state_1 &= ~(ST1_WIFI_SCAN_FLAG);
+       // Node 2
        bd_set_history_from_listener(&ts);
 
        EXIT;
@@ -539,15 +647,16 @@ static int bd_make_string_maps()
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
+*/
 
 int bd_initialize_battery_dump()
 {
        ENTER;
 
-       counter = 0;
-       _DBG("Battery Dump Init Successful");
-       bd_make_string_maps(); //add  return integer check.
-
+       h_count = 0; h_flag = true;
+       _INFO("Battery Dump Init Successful");
+       //Remove
+//     bd_make_string_maps();
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
@@ -561,5 +670,4 @@ int bd_deinitialize_battery_dump()
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }
-
-//Remove all DBG statements
+//Remove all DBG statements in final patch