Log 4k write to file function
Change-Id: Ic297ce4aa25dce9e86395a26fae92e0530988255
diff --git a/mbtk/mbtk_logd/alog_read.c b/mbtk/mbtk_logd/alog_read.c
index b7303b7..a907662 100755
--- a/mbtk/mbtk_logd/alog_read.c
+++ b/mbtk/mbtk_logd/alog_read.c
@@ -14,6 +14,9 @@
#define ALOG_DEV "/dev/log_radio"
#define LOG_CONFIG_LEN 50
+#define RADIOLOG_BUFF_SIZE (4*1024)
+#define MAX_BUFFER_SIZE (8*1024)
+
typedef enum android_LogPriority {
ANDROID_LOG_UNKNOWN = 0,
ANDROID_LOG_DEFAULT, /* only for SetMinPriority() */
@@ -46,6 +49,7 @@
static int fd_radio = 0;
+
void hex_print(char* buf, int len)
{
int i;
@@ -193,12 +197,15 @@
{
char priChar;
char timeBuf[32];
- char defaultBuffer[512];
+ char defaultBuffer[512] = {0};
size_t totalLen;
int index = 0;
int len = 0;
struct stat s;
- char * ret = NULL;
+
+
+ static char buffer[MAX_BUFFER_SIZE] = {0};
+ static int buffer_index = 0;
if(access(tmp_log, W_OK) != 0)
{
@@ -210,7 +217,8 @@
}
}
-
+
+
if (log_size && (!stat(tmp_log, &s)) && (s.st_size > log_size))
{
fd_radio = get_rotate_file(fd_radio, log_file, _file_list);
@@ -219,6 +227,7 @@
fprintf(stderr, "failed to open %s: %s\n", log_file, strerror(errno));
exit(-1);
}
+
}
if(fileter_log(entry->priority, entry->tag, config->filter_list))
@@ -242,9 +251,32 @@
defaultBuffer[index] ^= 1;
}
}
- ret = write(fd_radio, defaultBuffer, totalLen);
- return ret;
+
+ if(buffer_index >= RADIOLOG_BUFF_SIZE)
+ {
+ // Flush the buffer if it's full
+ if (write(fd_radio, buffer, buffer_index) < 0)
+ {
+ perror("write error");
+ return -1;
+ }
+ buffer_index = 0; // Reset buffer index after flushing
+ }
+
+ if(totalLen < RADIOLOG_BUFF_SIZE)
+ {
+ //copy buf to buffer
+ memcpy(buffer + buffer_index, defaultBuffer, totalLen);
+ buffer_index += totalLen;
+ }
+ else
+ {
+ write(fd_radio, defaultBuffer, totalLen);
+ }
+
+
+ return 0;
}
void* alog_thread(void* argv)