diff --git a/BUILD.gn b/BUILD.gn index 79fb8406c3b143cdb806f625fb64c7b4862c573b..fb7fe5a81a264bea42ae8415202c4358110c8e9f 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -20,8 +20,6 @@ declare_args() { ohos_hiviewdfx_hievent_lite_event_switch = 1 ohos_hiviewdfx_hiview_lite_output_module = -1 ohos_hiviewdfx_hiview_lite_dir = "" - ohos_hiviewdfx_log_static_cache_size = 1024 - ohos_hiviewdfx_hiview_hilog_file_buf_size = 512 } config("hiview_lite_config") { @@ -49,8 +47,6 @@ static_library("hiview_lite") { "DUMP_LITE_SWITCH = $ohos_hiviewdfx_dump_lite_dump_switch", "HIEVENT_LITE_SWITCH = $ohos_hiviewdfx_hievent_lite_event_switch", "LOG_OUTPUT_MODULE = $ohos_hiviewdfx_hiview_lite_output_module", - "LOG_STATIC_CACHE_SIZE = $ohos_hiviewdfx_log_static_cache_size", - "HIVIEW_HILOG_FILE_BUF_SIZE = $ohos_hiviewdfx_hiview_hilog_file_buf_size", ] if (ohos_build_type == "debug") { defines += [ "OUTPUT_LEVEL = $ohos_hiviewdfx_hilog_lite_level" ] diff --git a/hiview_cache.c b/hiview_cache.c index c904dd339031a4d00ff01daf5d28afa2952c5f4d..9975b3cd9512cae1e81981a2b665f320efe53f63 100755 --- a/hiview_cache.c +++ b/hiview_cache.c @@ -26,7 +26,6 @@ boolean InitHiviewStaticCache(HiviewCache *cache, HiviewCacheType type, uint8 *b return FALSE; } - cache->mutex = HIVIEW_MutexInit(); cache->usedSize = 0; cache->wCursor = 0; cache->buffer = buffer; @@ -47,7 +46,6 @@ boolean InitHiviewCache(HiviewCache *cache, HiviewCacheType type, uint16 size) return FALSE; } - cache->mutex = HIVIEW_MutexInit(); cache->usedSize = 0; cache->wCursor = 0; cache->buffer = buffer; @@ -65,9 +63,9 @@ int32 WriteToCache(HiviewCache *cache, const uint8 *data, uint16 wLen) uint16 firstLen; uint16 secondLen; - HIVIEW_MutexLock(cache->mutex); + uint32 intSave = HIVIEW_IntLock(); if (cache->size < wLen + cache->usedSize) { - HIVIEW_MutexUnlock(cache->mutex); + HIVIEW_IntRestore(intSave); return -1; } // overflow @@ -78,7 +76,7 @@ int32 WriteToCache(HiviewCache *cache, const uint8 *data, uint16 wLen) cache->wCursor += firstLen; cache->usedSize += firstLen; } else { - HIVIEW_MutexUnlock(cache->mutex); + HIVIEW_IntRestore(intSave); return -1; } } @@ -89,7 +87,7 @@ int32 WriteToCache(HiviewCache *cache, const uint8 *data, uint16 wLen) cache->wCursor += secondLen; cache->usedSize += secondLen; } else { - HIVIEW_MutexUnlock(cache->mutex); + HIVIEW_IntRestore(intSave); return firstLen; } } @@ -98,11 +96,11 @@ int32 WriteToCache(HiviewCache *cache, const uint8 *data, uint16 wLen) cache->wCursor += wLen; cache->usedSize += wLen; } else { - HIVIEW_MutexUnlock(cache->mutex); + HIVIEW_IntRestore(intSave); return -1; } } - HIVIEW_MutexUnlock(cache->mutex); + HIVIEW_IntRestore(intSave); return wLen; } @@ -140,9 +138,9 @@ int32 ReadFromCache(HiviewCache *cache, uint8 *data, uint16 rLen) return -1; } } - HIVIEW_MutexLock(cache->mutex); + uint32 intSave = HIVIEW_IntLock(); cache->usedSize -= rLen; - HIVIEW_MutexUnlock(cache->mutex); + HIVIEW_IntRestore(intSave); return rLen; } @@ -212,12 +210,12 @@ static uint16 GetReadCursor(HiviewCache *cache) } uint16 readCursor; - HIVIEW_MutexLock(cache->mutex); + uint32 intSave = HIVIEW_IntLock(); if (cache->wCursor >= cache->usedSize) { readCursor = cache->wCursor - cache->usedSize; } else { readCursor = cache->size - (cache->usedSize - cache->wCursor); } - HIVIEW_MutexUnlock(cache->mutex); + HIVIEW_IntRestore(intSave); return readCursor; } diff --git a/hiview_cache.h b/hiview_cache.h index 25ee312ae1aafb4cf8128c11e27c9616b76059be..adf2e5d342af1b169f69215186665478d2774a4a 100755 --- a/hiview_cache.h +++ b/hiview_cache.h @@ -37,7 +37,6 @@ typedef enum { #pragma pack(1) typedef struct { - HiviewMutexId_t mutex; uint16 wCursor; // 0-65535 uint16 usedSize; // 0-65535 uint16 size; // cache size 0-65535 diff --git a/hiview_config.h b/hiview_config.h index 97c19f0b51ccab0e6e69c989fc1552d18118c5ce..5455b77835f9aee0f2cd35edae2f8e1f3b95c06b 100755 --- a/hiview_config.h +++ b/hiview_config.h @@ -44,10 +44,14 @@ extern "C" { #define HIVIEW_FILE_PATH_STAT_EVENT HIVIEW_FILE_OUT_PATH_STAT_EVENT".tmp" /* cache size config */ -#define LOG_STATIC_CACHE_SIZE 1024 /* Must be greater than HIVIEW_FILE_BUF_SIZE. */ -#define EVENT_CACHE_SIZE 256 /* Must be greater than HIVIEW_FILE_BUF_SIZE. */ +#ifndef LOG_STATIC_CACHE_SIZE +#define LOG_STATIC_CACHE_SIZE 1024 /* Must be greater than HIVIEW_HILOG_FILE_BUF_SIZE. */ +#endif +#define EVENT_CACHE_SIZE 256 /* Must be greater than HIVIEW_HIEVENT_FILE_BUF_SIZE. */ #define JS_LOG_CACHE_SIZE 512 +#ifndef HIVIEW_HILOG_FILE_BUF_SIZE #define HIVIEW_HILOG_FILE_BUF_SIZE 512 +#endif #define HIVIEW_HIEVENT_FILE_BUF_SIZE 128 /* RAM dump config */ @@ -60,11 +64,11 @@ extern "C" { #define HIVIEW_FEATURE_ON 1 #define HIVIEW_FEATURE_OFF 0 -#define OUT_PATH_WAIT_TIMEOUT 5 /* 5 seconds */ +#define OUT_PATH_WAIT_TIMEOUT (5 * 1000) /* 5 seconds */ #pragma pack(1) typedef struct { - const uint8 outputOption : 4; /* Control log output mode. Cannot be modified during running. */ + uint8 outputOption : 4; /* Control log output mode. */ uint8 hiviewInited : 1; /* Indicates whether the hiview service is inited. */ uint8 level : 3; /* Control log output level. HILOG_LV_XXX */ uint8 logSwitch : 1; /* Indicates whether to enable the log component. */ diff --git a/hiview_file.c b/hiview_file.c index 41fcd641bfd76d56f5d05d98c11a80d628e534c5..1237013a816dc5f59321c89a93cd57d904cbb811 100755 --- a/hiview_file.c +++ b/hiview_file.c @@ -20,8 +20,6 @@ #include "ohos_types.h" #include "securec.h" -static uint16 GetReadCursor(HiviewFile *fp); - static uint32 GetDefineFileVersion(uint8 type) { switch (type) { @@ -120,7 +118,6 @@ boolean ReadFileHeader(HiviewFile *fp) } int32 ret; - uint32 t = (uint32)(HIVIEW_GetCurrentTime() / MS_PER_SECOND); if (HIVIEW_FileSeek(fp->fhandle, 0, HIVIEW_SEEK_SET) < 0) { return FALSE; } @@ -223,20 +220,26 @@ int32 CloseHiviewFile(HiviewFile *fp) HIVIEW_MemFree(MEM_POOL_HIVIEW_ID, fp->outPath); fp->outPath = HIVIEW_FILE_OUT_PATH_STAT_EVENT; } - return HIVIEW_FileClose(fp->fhandle); + int32 ret = HIVIEW_FileClose(fp->fhandle); + fp->fhandle = -1; + return ret; } return -1; } int8 ProcFile(HiviewFile *fp, const char *dest, FileProcMode mode) { - if (fp == NULL || fp->fhandle < 0 || HIVIEW_FileClose(fp->fhandle) != 0) { + if (fp == NULL || fp->fhandle < 0) { return -1; } - HIVIEW_MutexLockOrWait(fp->mutex, OUT_PATH_WAIT_TIMEOUT); + if (HIVIEW_MutexLockOrWait(fp->mutex, OUT_PATH_WAIT_TIMEOUT) != 0) { + HIVIEW_UartPrint("Procfile failed, get lock fail"); + return -1; + } switch (mode) { case HIVIEW_FILE_COPY:{ + HIVIEW_FileClose(fp->fhandle); int32 ret = HIVIEW_FileCopy(fp->path, dest); fp->fhandle = HIVIEW_FileOpen(fp->path); if (ret != 0 || fp->fhandle < 0) { @@ -247,6 +250,7 @@ int8 ProcFile(HiviewFile *fp, const char *dest, FileProcMode mode) break; } case HIVIEW_FILE_RENAME: { + HIVIEW_FileClose(fp->fhandle); uint8 type = fp->header.common.type; uint32 size = fp->header.size - sizeof(HiviewFileHeader); int32 ret = HIVIEW_FileMove(fp->path, dest); diff --git a/hiview_service.h b/hiview_service.h index dd0fac44bd2d405094133c305371b06bb65e1b1c..d1d9ea6822db1f72b3f5624babf3cbe9514d4045 100755 --- a/hiview_service.h +++ b/hiview_service.h @@ -43,6 +43,8 @@ typedef enum { HIVIEW_MSG_MAX } HiviewInnerMessage; +#define SYNC_FILE 1 + typedef struct { INHERIT_IUNKNOWN; void (*Output)(IUnknown *iUnknown, int16 msgId, uint16 type); diff --git a/hiview_util.c b/hiview_util.c index 598392205e7dbe4f706c5d94b72bb7fbc07c81e2..2216fff667dc755d3a730446179a3b7bb6a1c49a 100755 --- a/hiview_util.c +++ b/hiview_util.c @@ -26,13 +26,21 @@ #include "cmsis_os.h" +#if defined(CHIP_VER_Hi3861) || \ + defined(CHIP_VER_Hi3861L) || \ + defined(CHIP_VER_Hi3881) +#include "los_hwi.h" +#else +#include "../../../kernel/liteos_m/kernel/arch/include/los_interrupt.h" +#endif + extern void HAL_NVIC_SystemReset(void); extern void __disable_irq(void); extern void __enable_irq(void); -#define HIVIEW_WAIT_FOREVER 0xFFFFFFFF +#define HIVIEW_WAIT_FOREVER osWaitForever #define HIVIEW_MS_PER_SECOND 1000 -#define HIVIEW_NS_PER_MILISECOND 1000000 +#define HIVIEW_NS_PER_MILLISECOND 1000000 #define BUFFER_SIZE 128 void *HIVIEW_MemAlloc(uint8 modId, uint32 size) @@ -52,7 +60,7 @@ uint64 HIVIEW_GetCurrentTime() struct timespec current = {0}; int ret = clock_gettime(CLOCK_REALTIME, ¤t); if (ret == 0) { - return (uint64)current.tv_sec * HIVIEW_MS_PER_SECOND + current.tv_nsec / HIVIEW_NS_PER_MILISECOND; + return (uint64)current.tv_sec * HIVIEW_MS_PER_SECOND + current.tv_nsec / HIVIEW_NS_PER_MILLISECOND; } else { return 0; } @@ -70,28 +78,38 @@ HiviewMutexId_t HIVIEW_MutexInit() return (HiviewMutexId_t)osMutexNew(NULL); } -void HIVIEW_MutexLock(HiviewMutexId_t mutex) +int32 HIVIEW_MutexLock(HiviewMutexId_t mutex) { if (mutex == NULL) { - return; + return -1; } - osMutexAcquire((osMutexId_t)mutex, HIVIEW_WAIT_FOREVER); + return (int32)osMutexAcquire((osMutexId_t)mutex, HIVIEW_WAIT_FOREVER); } -void HIVIEW_MutexLockOrWait(HiviewMutexId_t mutex, uint32 timeout) +int32 HIVIEW_MutexLockOrWait(HiviewMutexId_t mutex, uint32 timeout) { if (mutex == NULL) { - return; + return -1; } - osMutexAcquire((osMutexId_t)mutex, timeout); + return (int32)osMutexAcquire((osMutexId_t)mutex, timeout); } -void HIVIEW_MutexUnlock(HiviewMutexId_t mutex) +int32 HIVIEW_MutexUnlock(HiviewMutexId_t mutex) { if (mutex == NULL) { - return; + return -1; } - osMutexRelease((osMutexId_t)mutex); + return (int32)osMutexRelease((osMutexId_t)mutex); +} + +uint32 HIVIEW_IntLock() +{ + return LOS_IntLock(); +} + +void HIVIEW_IntRestore(uint32 intSave) +{ + LOS_IntRestore(intSave); } uint32 HIVIEW_GetTaskId() @@ -101,7 +119,7 @@ uint32 HIVIEW_GetTaskId() void HIVIEW_UartPrint(const char *str) { - printf("%s", str); + printf("%s\n", str); } void HIVIEW_Sleep(uint32 ms) @@ -139,6 +157,11 @@ int32 HIVIEW_FileSize(int32 handle) return lseek(handle, 0, SEEK_END); } +int32 HIVIEW_FileSync(int32 handle) +{ + return fsync(handle); +} + int32 HIVIEW_FileUnlink(const char *path) { return unlink(path); @@ -164,7 +187,7 @@ int32 HIVIEW_FileCopy(const char *src, const char *dest) boolean copyFailed = TRUE; uint8 *dataBuf = (uint8 *)HIVIEW_MemAlloc(MEM_POOL_HIVIEW_ID, BUFFER_SIZE); if (dataBuf == NULL) { - HIVIEW_UartPrint("HIVIEW_FileCopy malloc erro"); + HIVIEW_UartPrint("HIVIEW_FileCopy malloc error"); goto MALLOC_ERROR; } int32 nLen = HIVIEW_FileRead(fdSrc, dataBuf, BUFFER_SIZE); diff --git a/hiview_util.h b/hiview_util.h index 3bf05e6903b1e1d4dcfbfa782e243e353e610e31..8b092d9fc271a12c73a09338f3df05cf47a5ae39 100755 --- a/hiview_util.h +++ b/hiview_util.h @@ -65,9 +65,11 @@ int32 HIVIEW_RtcGetCurrentTime(uint64 *val, HIVIEW_RtcTime *time); void *HIVIEW_MemAlloc(uint8 modId, uint32 size); void HIVIEW_MemFree(uint8 modId, void *pMem); HiviewMutexId_t HIVIEW_MutexInit(void); -void HIVIEW_MutexLock(HiviewMutexId_t mutex); -void HIVIEW_MutexLockOrWait(HiviewMutexId_t mutex, uint32 timeout); -void HIVIEW_MutexUnlock(HiviewMutexId_t mutex); +int32 HIVIEW_MutexLock(HiviewMutexId_t mutex); +int32 HIVIEW_MutexLockOrWait(HiviewMutexId_t mutex, uint32 timeout); +int32 HIVIEW_MutexUnlock(HiviewMutexId_t mutex); +uint32 HIVIEW_IntLock(void); +void HIVIEW_IntRestore(uint32 intSave); uint32 HIVIEW_GetTaskId(void); void HIVIEW_UartPrint(const char *str); void HIVIEW_Sleep(uint32 ms); @@ -79,6 +81,7 @@ int32 HIVIEW_FileRead(int32 handle, uint8 *buf, uint32 len); int32 HIVIEW_FileWrite(int32 handle, const uint8 *buf, uint32 len); int32 HIVIEW_FileSeek(int32 handle, int32 offset, int32 whence); int32 HIVIEW_FileSize(int32 handle); +int32 HIVIEW_FileSync(int32 handle); int32 HIVIEW_FileUnlink(const char *path); int32 HIVIEW_FileCopy(const char *src, const char *dest); int32 HIVIEW_FileMove(const char *src, const char *dest);