From a7dc5cde5d823ff400edeffa4412e40f9f62288d Mon Sep 17 00:00:00 2001 From: Dewal Agarwal Date: Tue, 15 Sep 2020 10:24:32 +0530 Subject: [PATCH] Remove use of forced indexing Change-Id: I5165e2cb41931f060fa1545e5908828e8094dcee Signed-off-by: Dewal Agarwal --- src/battery_dump/bd_history_item.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/src/battery_dump/bd_history_item.c b/src/battery_dump/bd_history_item.c index 8d79620..9c2b061 100644 --- a/src/battery_dump/bd_history_item.c +++ b/src/battery_dump/bd_history_item.c @@ -48,7 +48,7 @@ char usage_map[32][4] = {"Bu", "Wu", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""}; GHashTable *app_map = NULL; static long int lst_charge = -1; -static int front = -1, end = -1, is_full = 0; +static int front = -1, end = -1; static int bd_dump_data_item_reset(dump_data_s* old_state) { @@ -102,7 +102,6 @@ static int bd_get_index() if ((front == 0 && end == HISTORY_SIZE_MAX - 1) || (front == end + 1)) { _DBG("buffer is full"); - is_full = 1; bd_clean_circ_buffer_front(front); front = (front + 1) % HISTORY_SIZE_MAX; /* Prepare TIME Node */ @@ -128,13 +127,12 @@ static int bd_get_index() return end; } -static int bd_print_pool_entry(int fd, int idx, int pc, history_tag_s *pool_info) +static int bd_print_pool_entry(int fd, int idx, history_tag_s *pool_info) { ENTER; BM_CHECK_INPUT_PARAM(pool_info); _DBG("Value from history data %d", idx); - _DBG("Value from history data %d", pool_info->sp_idx); GString *dump_p = g_string_sized_new(30); BM_CHECK_MEM_ALLOC(dump_p, {}); @@ -143,11 +141,7 @@ static int bd_print_pool_entry(int fd, int idx, int pc, history_tag_s *pool_info g_string_append_c(dump_p, ','); g_string_append(dump_p, DUMP_DATA_TAG_1); g_string_append_c(dump_p, ','); - - if (is_full) - g_string_append_printf(dump_p, "%d,", pool_info->sp_idx); - else - g_string_append_printf(dump_p, "%d,", pc); + g_string_append_printf(dump_p, "%d,", pool_info->sp_idx); g_string_append_printf(dump_p, "%d,", pool_info->uid); g_string_append(dump_p, "\""); @@ -193,7 +187,7 @@ static int bd_get_pool_entry_from_dump(int fd) g_string_free(dump_p, TRUE); int ret = BATTERY_MONITOR_ERROR_NONE; - int pool_count = 0, index_s = front, index_e = end, i = 0; + int index_s = front, index_e = end, i = 0; if (index_s > index_e) index_e = HISTORY_SIZE_MAX + index_e; @@ -203,22 +197,19 @@ static int bd_get_pool_entry_from_dump(int fd) history_tag_s *pool_info = NULL; if (history_data[i].event_tag != NULL && (history_data[i].event_code & ET_FLAG_START)) { pool_info = history_data[i].event_tag; - ret = bd_print_pool_entry(fd, i, pool_count, pool_info); - pool_count++; + ret = bd_print_pool_entry(fd, 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(fd, i, pool_count, pool_info); - pool_count++; + ret = bd_print_pool_entry(fd, 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(fd, i, pool_count, pool_info); - pool_count++; + ret = bd_print_pool_entry(fd, i, pool_info); if (ret != BATTERY_MONITOR_ERROR_NONE) return BATTERY_MONITOR_ERROR_INTERNAL; } @@ -1385,7 +1376,7 @@ static int bd_free_history_data_memory() _ERR("Internal error %d while freeing at idx %d", ret , i); } - front = -1; end = -1; is_full = 0; + front = -1; end = -1; h_flag = true; EXIT; @@ -1522,7 +1513,7 @@ int bd_initialize_battery_dump() int ret = BATTERY_MONITOR_ERROR_NONE; - front = -1; end = -1; h_flag = true; is_full = 0; + front = -1; end = -1; h_flag = true; lst_charge = -1; #ifdef DUMP_DUMMY bd_dummy_test_fn(); -- 2.7.4