Add first entry for TIME 03/225803/1 accepted/tizen/unified/20200226.124247 submit/tizen/20200226.045722
authorDewal Agarwal <d1.agarwal@samsung.com>
Mon, 24 Feb 2020 11:39:15 +0000 (17:09 +0530)
committerDewal Agarwal <d1.agarwal@samsung.com>
Mon, 24 Feb 2020 11:41:23 +0000 (17:11 +0530)
- Update base_time for first entry
- Make first node record conditional

Change-Id: Ib93042a7df321267f8280b535cbf4166ca511adb
Signed-off-by: Dewal Agarwal <d1.agarwal@samsung.com>
src/battery_dump/bd_history_item.c

index 2283516..9968094 100644 (file)
@@ -30,6 +30,7 @@
 #include "bm_private.h"
 #include "bd_private.h"
 
+//#define DUMP_DUMMY 1
 #ifdef DUMP_DUMMY
 #include "bd_history_item_dummy.h"
 #endif
@@ -685,7 +686,7 @@ int bd_print_history_item_reset(history_item_s* old_state)
        old_state->battery_temperature = -1;
        old_state->battery_voltage = -1;
        old_state->battery_charge = -1;
-
+       old_state->event_code = 0;
        old_state->event_tag = NULL;
        old_state->wakelock_tag = NULL;
        old_state->wakereason_tag = NULL;
@@ -694,6 +695,16 @@ int bd_print_history_item_reset(history_item_s* old_state)
        return BATTERY_MONITOR_ERROR_NONE;
 }
 
+int bd_get_base_time_from_dump(long long *base_time)
+{
+       ENTER;
+
+       *base_time = history_data[0].time_s;
+
+       EXIT;
+       return BATTERY_MONITOR_ERROR_NONE;
+}
+
 int bd_print_history_item_main(int fd, int num_h_items, long long base_time, bool chkin)
 {
        ENTER;
@@ -724,6 +735,10 @@ int bd_print_history_item_main(int fd, int num_h_items, long long base_time, boo
        if (ret != BATTERY_MONITOR_ERROR_NONE)
                _ERR("S pool data dump failed");
 
+       ret = bd_get_base_time_from_dump(&base_time);
+       if (ret != BATTERY_MONITOR_ERROR_NONE)
+               _ERR("Base time error");
+
        int log_count = h_count; GString *dump_p = NULL;
        for (int i = 0; i < log_count; i++) {
                ret = bd_get_history_detail_from_dump(i, &new_state);
@@ -1057,11 +1072,11 @@ int bd_print_history_item_main(int fd, int num_h_items, long long base_time, boo
                        old_state.state_1 = new_state.state_1;
                        old_state.state_2 = new_state.state_2;
                }
-                       _DBG("State assigned");
-                       _DBG("%s", dump_p->str);
-                       if (write(fd, dump_p->str, dump_p->len) < 0)
-                               _WARN("write error");
-                       g_free(dump_p->str);
+               _DBG("State assigned");
+               _DBG("%s", dump_p->str);
+               if (write(fd, dump_p->str, dump_p->len) < 0)
+                       _WARN("write error");
+               g_free(dump_p->str);
        }
 
        // Dump the elapsed time from last event
@@ -1326,19 +1341,29 @@ int bd_initialize_battery_dump()
 
        int ret = BATTERY_MONITOR_ERROR_NONE;
 
+       h_count = 0; h_flag = true;
+
+#ifdef DUMP_DUMMY
+       bd_dummy_test_fn();
+#else
+       history_item_s ts;
+       ret = bd_print_history_item_reset(&ts);
+       if (ret == BATTERY_MONITOR_ERROR_NONE) {
+               ts.cmd_s = CM_CRR_TIME;
+               ret = bd_store_history_item(&ts);
+               if (ret != BATTERY_MONITOR_ERROR_NONE)
+                       _WARN("Init Node addition failed");
+       }
+#endif
+
        ret = dumpsys_system_register_dump_cb(bd_callback, "batterystats", (void **)&dumpsys_handler);
        if (ret != TIZEN_ERROR_NONE) {
                _ERR("dumpsys_system_register_dump_cb failed (%x)", ret);
                return BATTERY_MONITOR_ERROR_NOT_INITIALIZED;
        }
 
-       h_count = 0; h_flag = true;
        _INFO("Battery Dump Init Successful");
 
-#ifdef DUMP_DUMMY
-       bd_dummy_test_fn();
-#endif
-
        EXIT;
        return BATTERY_MONITOR_ERROR_NONE;
 }