summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAbhishek Vijay <abhishek.v@samsung.com>2020-09-14 05:15:49 +0000
committerGerrit Code Review <gerrit@review>2020-09-14 05:15:49 +0000
commite8c5c03d79baae8776714144bb2517e927d6e3a1 (patch)
tree522e96506ee6e2c09032931c1cb24031d343141c
parent476d4faf3c9a0f977d6900338f18aa4234858a2d (diff)
parent851cca85fefb12d04822ffe5a50df00f8083f266 (diff)
downloadbatterymonitor-e8c5c03d79baae8776714144bb2517e927d6e3a1.tar.gz
batterymonitor-e8c5c03d79baae8776714144bb2517e927d6e3a1.tar.bz2
batterymonitor-e8c5c03d79baae8776714144bb2517e927d6e3a1.zip
Merge "Reduce function calls" into tizen
-rw-r--r--include/bd_history_item.h3
-rw-r--r--src/battery_dump/bd_history_item.c193
2 files changed, 70 insertions, 126 deletions
diff --git a/include/bd_history_item.h b/include/bd_history_item.h
index 2b80004..2d4e296 100644
--- a/include/bd_history_item.h
+++ b/include/bd_history_item.h
@@ -72,10 +72,11 @@ typedef struct _dump_data_s {
history_tag_s* wakereason_tag;
} dump_data_s;
-#define HISTORY_SIZE_MAX 1000000 // Maximum Allowed History
+#define HISTORY_SIZE_MAX 100000 // Maximum Allowed History
#define TIZEN_DUMP_VERSION "9"
#define DUMP_DATA_TAG "h"
#define DUMP_DATA_TAG_1 "hsp"
+#define DUMP_PARSER_STR "19,150,NMF26V,NMF26V"
#define CM_UPD 0 // Differential from last Update Entry
#define CM_ST 4 // History Start
diff --git a/src/battery_dump/bd_history_item.c b/src/battery_dump/bd_history_item.c
index 14f8d39..b61cc56 100644
--- a/src/battery_dump/bd_history_item.c
+++ b/src/battery_dump/bd_history_item.c
@@ -36,18 +36,20 @@
#include "bd_history_item_dummy.h"
#endif
-dump_data_s history_data[HISTORY_SIZE_MAX];
-int h_count = 0; int h_flag = false;
-char state1_map[32][4] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Wm",
+static dump_data_s history_data[HISTORY_SIZE_MAX];
+static int h_count = 0, h_flag = false;
+
+/*Bit and string map*/
+static char state1_map[32][4] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "Wm",
"", "Sd", "BP", "S", "Psc", "a", "s", "", "Pr", "Wr", "Ws", "Wl", "g", "w", "r"};
-char state2_map[32][5] = {"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+static 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",
+static 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", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
+static char usage_map[32][4] = {"Bu", "Wu", "", "", "", "", "", "", "", "", "", "", "", "", "", "",
"", "", "", "", "", "", "", "", "", "", "", "", "", "", "", ""};
-GHashTable *app_map = NULL;
+static GHashTable *app_map = NULL;
static long int lst_charge = -1;
static long int rst_time = -1;
@@ -62,15 +64,11 @@ static int bd_print_pool_entry(int fd, int idx, int pc, history_tag_s *pool_info
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {});
+ g_string_append_printf(dump_p, "%s,%s,%d,%d,",
+ TIZEN_DUMP_VERSION, DUMP_DATA_TAG_1,
+ pc, pool_info->uid);
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append_c(dump_p, ',');
- g_string_append(dump_p, DUMP_DATA_TAG_1);
- g_string_append_c(dump_p, ',');
- g_string_append_printf(dump_p, "%d,", pc);
- g_string_append_printf(dump_p, "%d,", pool_info->uid);
g_string_append(dump_p, "\"");
-
if (pool_info->string_info != NULL) {
gchar *temp = g_strdup(pool_info->string_info->str);
g_string_append(dump_p, temp);
@@ -97,13 +95,8 @@ static int bd_get_pool_entry_from_dump(int fd)
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {});
-
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0");
- g_string_append(dump_p, ",i");
- g_string_append(dump_p, ",vers");
- g_string_append(dump_p, ",19,150,NMF26V,NMF26V");
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,i,vers,%s\n",
+ TIZEN_DUMP_VERSION,DUMP_PARSER_STR);
_DBG("%s", dump_p->str);
@@ -171,10 +164,9 @@ static int bd_get_and_print_system_base_battery_usage_from_dump(int fd, long int
GString *dump_p = NULL;
dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {});
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append_printf(dump_p, ",%d,l,pwi,uid,", uid_n);
- g_string_append_printf(dump_p, "%0.2f", usage_mah);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,%d,l,pwi,uid,%0.2f\n",
+ TIZEN_DUMP_VERSION, uid_n, usage_mah);
+
_DBG("%s", dump_p->str);
if (write(fd, dump_p->str, dump_p->len) < 0)
_WARN("write error");
@@ -204,11 +196,9 @@ 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, {});
-
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
// Power Capacity
- g_string_append_printf(dump_p, ",0,l,pws,%d,0,0,0", battery_capacity);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,pws,%d,0,0,0\n",
+ TIZEN_DUMP_VERSION, battery_capacity);
_DBG("%s", dump_p->str);
@@ -235,10 +225,9 @@ static int bd_get_and_print_battery_usage_from_dump(int fd, long int duration)
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);
- g_string_append_printf(dump_p, ",%d,l,pwi,uid,", *uid_n);
- g_string_append_printf(dump_p, "%0.2f", usageMAh);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,%d,l,pwi,uid,%0.2f\n",
+ TIZEN_DUMP_VERSION, *uid_n, usageMAh);
+
bm_appid_usage_free(app_use);
_DBG("%s", dump_p->str);
if (write(fd, dump_p->str, dump_p->len) < 0)
@@ -320,15 +309,11 @@ static int bd_get_and_print_gbr_stat_entry_from_dump(int fd, long int duration)
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gbr_stat); });
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "br,");
- g_string_append_printf(dump_p, "%ld,", gbr_stat->dark); //OFF
- g_string_append_printf(dump_p, "%ld,", gbr_stat->dim); // All are time values
- g_string_append_printf(dump_p, "%ld,", gbr_stat->medium);
- g_string_append_printf(dump_p, "%ld,", gbr_stat->light); //DEF: 0
- g_string_append_printf(dump_p, "%ld", gbr_stat->bright);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,br,%ld,%ld,%ld,%ld,%ld\n",
+ TIZEN_DUMP_VERSION, gbr_stat->dark,
+ gbr_stat->dim, gbr_stat->medium,
+ gbr_stat->light, gbr_stat->bright);
+
_DBG("%s", dump_p->str);//write
if (write(fd, dump_p->str, dump_p->len) < 0)
_WARN("write error");
@@ -357,14 +342,10 @@ static int bd_get_and_print_misc_stat_entry_from_dump(int fd, long int duration)
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gbr_stat); });
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "m,");
long int off_time = gbr_stat->dark;
long int on_time = (gbr_stat->dim + gbr_stat->medium + gbr_stat->bright);
- g_string_append_printf(dump_p, "%ld,", on_time);
- g_string_append_printf(dump_p, "%ld", off_time);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,m,%ld,%ld\n",
+ TIZEN_DUMP_VERSION, on_time, off_time);
_DBG("%s", dump_p->str);
if (write(fd, dump_p->str, dump_p->len) < 0)
@@ -393,21 +374,12 @@ static int bd_get_and_print_gn_stat_entry_from_dump(int fd, long int duration)
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gn_stat); });
-
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "gn,");
- g_string_append_printf(dump_p, "%ld,", gn_stat->dn_rx_byt);
- g_string_append_printf(dump_p, "%ld,", gn_stat->dn_tx_byt);
- g_string_append_printf(dump_p, "%ld,", gn_stat->wifi_rx_byt);
- g_string_append_printf(dump_p, "%ld,", gn_stat->wifi_tx_byt);
- g_string_append_printf(dump_p, "%ld,", gn_stat->dn_rx_pkt);
- g_string_append_printf(dump_p, "%ld,", gn_stat->dn_tx_pkt);
- g_string_append_printf(dump_p, "%ld,", gn_stat->wifi_rx_pkt);
- g_string_append_printf(dump_p, "%ld,", gn_stat->wifi_tx_pkt);
- g_string_append_printf(dump_p, "%d,", 0); //add this to struct as well
- g_string_append_printf(dump_p, "%d", 0);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,gn,%ld,%ld,%ld,%ld,%ld,%ld,%ld,%ld,0,0\n",
+ TIZEN_DUMP_VERSION, gn_stat->dn_rx_byt,
+ gn_stat->dn_tx_byt, gn_stat->wifi_rx_byt,
+ gn_stat->wifi_tx_byt, gn_stat->dn_rx_pkt,
+ gn_stat->dn_tx_pkt, gn_stat->wifi_rx_pkt,
+ gn_stat->wifi_tx_pkt);
/*_DBG("%s", dump_p->str);//write
if (write(fd, dump_p->str, dump_p->len) < 0)
@@ -436,31 +408,24 @@ static int bd_get_and_print_gwf_stat_entry_from_dump(int fd, long int duration)
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gwfl_stat); });
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "gwfl,");
- g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_on_time);
- g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_conn_time);
- g_string_append(dump_p, "0,0,0");//legacy
+ g_string_append_printf(dump_p, "%s,0,l,gwfl,%ld,%ld,0,0,0\n",
+ TIZEN_DUMP_VERSION,
+ gwfl_stat->wifi_on_time, gwfl_stat->wifi_conn_time);
- g_string_append(dump_p, "\n");
_DBG("%s", dump_p->str);//write
if (write(fd, dump_p->str, dump_p->len) < 0)
_WARN("write error");
g_string_free(dump_p, TRUE);
+ float usage_mah = (float)gwfl_stat->wifi_pwi_val/3600;
+
dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gwfl_stat); });
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "gwfcd,");
- //idle rx pwi tx
- float usage_mah = (float)gwfl_stat->wifi_pwi_val/3600;
- g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_idle_time);
- g_string_append_printf(dump_p, "%ld,", gwfl_stat->wifi_rx_time);
- g_string_append_printf(dump_p, "%0.2f,", usage_mah);
- g_string_append_printf(dump_p, "%ld", gwfl_stat->wifi_tx_time);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,gwfcd,%ld,%ld,%0.2f,%ld\n",
+ TIZEN_DUMP_VERSION, gwfl_stat->wifi_idle_time,
+ gwfl_stat->wifi_rx_time, usage_mah,
+ gwfl_stat->wifi_tx_time);
+
_DBG("%s", dump_p->str);//write
if (write(fd, dump_p->str, dump_p->len) < 0)
_WARN("write error");
@@ -486,17 +451,14 @@ static int bd_get_and_print_gble_stat_entry_from_dump(int fd, long int duration)
return ret;
}
+ float usage_mah = (float)gble_stat->ble_pwi_val/3600;
+
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gble_stat); });
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "gble,");
- float usage_mah = (float)gble_stat->ble_pwi_val/3600;
- g_string_append_printf(dump_p, "%ld,", gble_stat->ble_idle_time);
- g_string_append_printf(dump_p, "%ld,", gble_stat->ble_rx_time);
- g_string_append_printf(dump_p, "%ld,", gble_stat->ble_tx_time);
- g_string_append_printf(dump_p, "%0.2f", usage_mah);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,gble,%ld,%ld,%ld,%0.2f\n",
+ TIZEN_DUMP_VERSION, gble_stat->ble_idle_time,
+ gble_stat->ble_rx_time, gble_stat->ble_tx_time,
+ usage_mah);
_DBG("%s", dump_p->str);//write
if (write(fd, dump_p->str, dump_p->len) < 0)
@@ -526,16 +488,10 @@ static int bd_get_and_print_gst_stat_entry_from_dump(int fd, long int duration)
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gst_stat); });
-
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "sgt,");
- g_string_append_printf(dump_p, "%ld,", gst_stat->none_time);
- g_string_append_printf(dump_p, "%ld,", gst_stat->poor_time);
- g_string_append_printf(dump_p, "%ld,", gst_stat->med_time);
- g_string_append_printf(dump_p, "%ld,", gst_stat->good_time);
- g_string_append_printf(dump_p, "%ld", gst_stat->grt_time);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,sgt,%ld,%ld,%ld,%ld,%ld\n",
+ TIZEN_DUMP_VERSION, gst_stat->none_time,
+ gst_stat->poor_time, gst_stat->med_time,
+ gst_stat->good_time, gst_stat->grt_time);
_DBG("%s", dump_p->str);//write
@@ -545,13 +501,9 @@ static int bd_get_and_print_gst_stat_entry_from_dump(int fd, long int duration)
dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gst_stat); });
+ g_string_append_printf(dump_p, "%s,0,l,sst,%ld\n",
+ TIZEN_DUMP_VERSION, gst_stat->scan_time);
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "sst,");
- g_string_append_printf(dump_p, "%ld", gst_stat->scan_time);
-
- g_string_append(dump_p, "\n");
_DBG("%s", dump_p->str);//write
if (write(fd, dump_p->str, dump_p->len) < 0)
_WARN("write error");
@@ -579,16 +531,12 @@ static int bd_get_and_print_gwst_stat_entry_from_dump(int fd, long int duration)
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gwst_stat); });
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "wsgt,");
// g_string_append_printf(dump_p, "%ld,", gwst_stat->wscan_time);
- g_string_append_printf(dump_p, "%ld,", gwst_stat->wnone_time);
- g_string_append_printf(dump_p, "%ld,", gwst_stat->wpoor_time);
- g_string_append_printf(dump_p, "%ld,", gwst_stat->wmed_time);
- g_string_append_printf(dump_p, "%ld,", gwst_stat->wgood_time);
- g_string_append_printf(dump_p, "%ld", gwst_stat->wgrt_time);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,wsgt,%ld,%ld,%ld,%ld,%ld\n",
+ TIZEN_DUMP_VERSION, gwst_stat->wnone_time,
+ gwst_stat->wpoor_time, gwst_stat->wmed_time,
+ gwst_stat->wgood_time, gwst_stat->wgrt_time);
+
_DBG("%s", dump_p->str);//write
if (write(fd, dump_p->str, dump_p->len) < 0)
_WARN("write error");
@@ -628,13 +576,10 @@ static int bd_get_and_print_gcpu_stat_entry_from_dump(int fd, long int duration)
GString *dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {BM_FREE(gcpu_stat); BM_FREE(res_use); });
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0,l,");
- g_string_append(dump_p, "cpu,");
- g_string_append_printf(dump_p, "%ld,", gcpu_stat->usr_time);
- g_string_append_printf(dump_p, "%ld,", gcpu_stat->sys_time);
- g_string_append_printf(dump_p, "%0.2f", usagemah);
- g_string_append(dump_p, "\n");
+ g_string_append_printf(dump_p, "%s,0,l,cpu,%ld,%ld,%0.2f\n",
+ TIZEN_DUMP_VERSION, gcpu_stat->usr_time,
+ gcpu_stat->sys_time, usagemah);
+
bm_resourceid_usage_free(res_use);
_DBG("%s", dump_p->str);
if (write(fd, dump_p->str, dump_p->len) < 0)
@@ -670,10 +615,8 @@ static int bd_get_and_print_uid_info_entry_from_dump(int fd)
for (iter = list; iter != NULL; iter = g_slist_next(iter)) {
dump_p = g_string_sized_new(30);
BM_CHECK_MEM_ALLOC(dump_p, {bm_set_free_gslist_appid_map(list); });
- g_string_append(dump_p, TIZEN_DUMP_VERSION);
- g_string_append(dump_p, ",0");
- g_string_append(dump_p, ",i");
- g_string_append(dump_p, ",uid,");
+ g_string_append_printf(dump_p, "%s,0,i,uid,",
+ TIZEN_DUMP_VERSION);
appid_map_s *amap_data = (appid_map_s *)iter->data;
g_string_append_printf(dump_p, "%d,", (amap_data->id+10000));
gchar *temp_str = g_strdup(amap_data->AppId);