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

Merge pull request !771 from shenchenkai/N/A
This commit is contained in:
openharmony_ci 2022-01-11 06:29:13 +00:00 committed by Gitee
commit 48f5481c65
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
1 changed files with 14 additions and 5 deletions

View File

@ -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);