未验证 提交 48f5481c 编写于 作者: O openharmony_ci 提交者: Gitee

!771 【轻量级 PR】:reduce print log if hilog ringbuffer is full

Merge pull request !771 from shenchenkai/N/A
......@@ -238,7 +238,7 @@ static void HiLogHeadInit(struct HiLogEntry *header, size_t len)
ret = clock_gettime(CLOCK_REALTIME, &now);
if (ret != 0) {
dprintf("In %s line %d,clock_gettime fail", __FUNCTION__, __LINE__);
dprintf("In %s line %d,clock_gettime fail\n", __FUNCTION__, __LINE__);
return;
}
......@@ -255,7 +255,9 @@ static void HiLogCoverOldLog(size_t bufLen)
int retval;
struct HiLogEntry header;
size_t totalSize = bufLen + sizeof(struct HiLogEntry);
int dropLogLines = 0;
static int dropLogLines = 0;
static int isLastTimeFull = 0;
int isThisTimeFull = 0;
while (totalSize + g_hiLogDev.size > HILOG_BUFFER) {
retval = HiLogReadRingBuffer((unsigned char *)&header, sizeof(header));
......@@ -264,11 +266,18 @@ static void HiLogCoverOldLog(size_t bufLen)
}
dropLogLines++;
isThisTimeFull = 1;
isLastTimeFull = 1;
HiLogBufferDec(sizeof(header));
HiLogBufferDec(header.len);
}
if (dropLogLines > 0) {
dprintf("hilog ringbuffer full, drop %d line(s) log", dropLogLines);
if (isLastTimeFull == 1 && isThisTimeFull == 0) {
/* so we can only print one log if hilog ring buffer is full in a short time */
if (dropLogLines > 0) {
dprintf("hilog ringbuffer full, drop %d line(s) log\n", dropLogLines);
}
isLastTimeFull = 0;
dropLogLines = 0;
}
}
......@@ -330,7 +339,7 @@ static void HiLogDeviceInit(void)
{
g_hiLogDev.buffer = LOS_MemAlloc((VOID *)OS_SYS_MEM_ADDR, HILOG_BUFFER);
if (g_hiLogDev.buffer == NULL) {
dprintf("In %s line %d,LOS_MemAlloc fail", __FUNCTION__, __LINE__);
dprintf("In %s line %d,LOS_MemAlloc fail\n", __FUNCTION__, __LINE__);
}
init_waitqueue_head(&g_hiLogDev.wq);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册