已合并
fix: runtime 仓dfx组件代码未进行代码格式化不符合代码规范,需要整改 (#840) #4361
fix: runtime 仓dfx组件代码未进行代码格式化不符合代码规范,需要整改 (#840) #4361
已合并
GuoWenbo创建于 8月19日
298 个文件变更+17970-18662
@@ -22,27 +22,21 @@ extern "C" {
22 22 
23typedef uintptr_t acllogCallbackHandle;23typedef uintptr_t acllogCallbackHandle;
24 24 
25-typedef enum {25+typedef enum { OUTPUT_TYPE_DEBUG = 0, OUTPUT_TYPE_RUN = 1, OUTPUT_TYPE_BOTH = 2, OUTPUT_TYPE_MAX } acllogOutputLogType;
26- OUTPUT_TYPE_DEBUG = 0,
27- OUTPUT_TYPE_RUN = 1,
28- OUTPUT_TYPE_BOTH = 2,
29- OUTPUT_TYPE_MAX
30-} acllogOutputLogType;
31 26 
32-typedef int32_t (*acllogRecordCallback)(27+typedef int32_t (*acllogRecordCallback)(void* userData, uint32_t outputLogType, const char* logContent, size_t length);
33- void *userData, uint32_t outputLogType, const char *logContent, size_t length);
34 28 
35-LOG_FUNC_VISIBILITY int32_t acllogRegisterCallback(acllogRecordCallback callbackFunc, void *userData,29+LOG_FUNC_VISIBILITY int32_t acllogRegisterCallback(
36- uint32_t outputLogType, acllogCallbackHandle *callbackHandle);30+ acllogRecordCallback callbackFunc, void* userData, uint32_t outputLogType, acllogCallbackHandle* callbackHandle);
37 31 
38LOG_FUNC_VISIBILITY int32_t acllogUnregisterCallback(acllogCallbackHandle callback);32LOG_FUNC_VISIBILITY int32_t acllogUnregisterCallback(acllogCallbackHandle callback);
39 33 
40LOG_FUNC_VISIBILITY int32_t acllogCheckDebugLevel(int32_t moduleId, int32_t logLevel) __attribute((weak));34LOG_FUNC_VISIBILITY int32_t acllogCheckDebugLevel(int32_t moduleId, int32_t logLevel) __attribute((weak));
41 35 
42-LOG_FUNC_VISIBILITY void acllogRecord(int32_t moduleId, int32_t level, const char *fmt, ...)36+LOG_FUNC_VISIBILITY void acllogRecord(int32_t moduleId, int32_t level, const char* fmt, ...) __attribute((weak))
43- __attribute((weak)) __attribute__((format(printf, 3, 4)));37+__attribute__((format(printf, 3, 4)));
44 38 
45-LOG_FUNC_VISIBILITY void acllogVaList(int32_t moduleId, int32_t level, const char *fmt, va_list list)39+LOG_FUNC_VISIBILITY void acllogVaList(int32_t moduleId, int32_t level, const char* fmt, va_list list)
46 __attribute((weak));40 __attribute((weak));
47 41 
48#ifdef __cplusplus42#ifdef __cplusplus
@@ -35,10 +35,10 @@ LOG_FUNC_VISIBILITY int32_t AlogCheckDebugLevel(uint32_t moduleId, int32_t level
35 * @param [in] : level log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG35 * @param [in] : level log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
36 * @return: : 0: success, other: failed36 * @return: : 0: success, other: failed
37 */37 */
38-LOG_FUNC_VISIBILITY int32_t AlogRecord(uint32_t moduleId, uint32_t logType, int32_t level, const char *fmt, ...)38+LOG_FUNC_VISIBILITY int32_t AlogRecord(uint32_t moduleId, uint32_t logType, int32_t level, const char* fmt, ...)
39 __attribute((weak)) __attribute__((format(printf, 4, 5)));39 __attribute((weak)) __attribute__((format(printf, 4, 5)));
40 40 
41#ifdef __cplusplus41#ifdef __cplusplus
42}42}
43#endif // __cplusplus43#endif // __cplusplus
44-#endif // ALOG_PUB_H_44+#endif // ALOG_PUB_H_
@@ -7,81 +7,77 @@
7 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7 * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8 * See LICENSE in the root of the software repository for the full text of the License.8 * See LICENSE in the root of the software repository for the full text of the License.
9 */9 */
10- 10+ 
11#ifndef LOG_TYPES_H_11#ifndef LOG_TYPES_H_
12#define LOG_TYPES_H_12#define LOG_TYPES_H_
13- 13+ 
14#if defined(_MSC_VER)14#if defined(_MSC_VER)
15#define LOG_FUNC_VISIBILITY _declspec(dllexport)15#define LOG_FUNC_VISIBILITY _declspec(dllexport)
16#else16#else
17#define LOG_FUNC_VISIBILITY __attribute__((visibility("default")))17#define LOG_FUNC_VISIBILITY __attribute__((visibility("default")))
18#endif18#endif
19- 19+ 
20// log level id20// log level id
21-#define DLOG_DEBUG 0x0 // debug level id21+#define DLOG_DEBUG 0x0 // debug level id
22-#define DLOG_INFO 0x1 // info level id22+#define DLOG_INFO 0x1 // info level id
23-#define DLOG_WARN 0x2 // warning level id23+#define DLOG_WARN 0x2 // warning level id
24-#define DLOG_ERROR 0x3 // error level id24+#define DLOG_ERROR 0x3 // error level id
25-#define DLOG_NULL 0x4 // don't print log25+#define DLOG_NULL 0x4 // don't print log
26- 26+ 
27/**27/**
28 * @ingroup slog28 * @ingroup slog
29 *29 *
30 * log mask30 * log mask
31 */31 */
32-#define DEBUG_LOG_MASK (0x00010000U) // print log to directory debug32+#define DEBUG_LOG_MASK (0x00010000U) // print log to directory debug
33-#define SECURITY_LOG_MASK (0x00100000U) // print log to directory security33+#define SECURITY_LOG_MASK (0x00100000U) // print log to directory security
34-#define RUN_LOG_MASK (0x01000000U) // print log to directory run34+#define RUN_LOG_MASK (0x01000000U) // print log to directory run
35-#define STDOUT_LOG_MASK (0x10000000U) // print log to stdout35+#define STDOUT_LOG_MASK (0x10000000U) // print log to stdout
36- 36+ 
37// log type37// log type
38-enum {38+enum { DLOG_TYPE_DEBUG = 0, DLOG_TYPE_RUN = 1, DLOG_TYPE_MAX };
39- DLOG_TYPE_DEBUG = 0,39+ 
40- DLOG_TYPE_RUN = 1,
41- DLOG_TYPE_MAX
42-};
43-
44// max log length40// max log length
45#define MSG_LENGTH 102441#define MSG_LENGTH 1024
46- 42+ 
47// module id43// module id
48enum {44enum {
49- SLOG = 0, /* Slog module */45+ SLOG = 0, /* Slog module */
50- IDEDD = 1, /* IDE daemon device */46+ IDEDD = 1, /* IDE daemon device */
51- SCC = 2, /* SCC */47+ SCC = 2, /* SCC */
52- HCCL = 3, /* HCCL */48+ HCCL = 3, /* HCCL */
53- FMK = 4, /* Adapter */49+ FMK = 4, /* Adapter */
54- CCU = 5, /* CCU */50+ CCU = 5, /* CCU */
55- DVPP = 6, /* DVPP */51+ DVPP = 6, /* DVPP */
56- RUNTIME = 7, /* Runtime */52+ RUNTIME = 7, /* Runtime */
57- CCE = 8, /* CCE */53+ CCE = 8, /* CCE */
58- HDC = 9, /* HDC */54+ HDC = 9, /* HDC */
59- DRV = 10, /* Driver */55+ DRV = 10, /* Driver */
60- NET = 11, /* Network */56+ NET = 11, /* Network */
61- HIXL = 12, /* Hixl */57+ HIXL = 12, /* Hixl */
62- DEVMM = 22, /* Dlog memory managent */58+ DEVMM = 22, /* Dlog memory managent */
63- KERNEL = 23, /* Kernel */59+ KERNEL = 23, /* Kernel */
64- LIBMEDIA = 24, /* Libmedia */60+ LIBMEDIA = 24, /* Libmedia */
65- CCECPU = 25, /* aicpu shedule */61+ CCECPU = 25, /* aicpu shedule */
66- ROS = 27, /* ROS */62+ ROS = 27, /* ROS */
67 HCCP = 28,63 HCCP = 28,
68 ROCE = 29,64 ROCE = 29,
69 TEFUSION = 30,65 TEFUSION = 30,
70- PROFILING =31,66+ PROFILING = 31,
71- DP = 32, /* Data Preprocess */67+ DP = 32, /* Data Preprocess */
72- APP = 33, /* User Application */68+ APP = 33, /* User Application */
73- TS = 34, /* Task Schedule */69+ TS = 34, /* Task Schedule */
74 TSDUMP = 35,70 TSDUMP = 35,
75 AICPU = 36,71 AICPU = 36,
76- LP = 37, /* Low Power */72+ LP = 37, /* Low Power */
77- TDT = 38, /* tsdaemon or aicpu shedule */73+ TDT = 38, /* tsdaemon or aicpu shedule */
78 FE = 39,74 FE = 39,
79 MD = 40,75 MD = 40,
80 MB = 41,76 MB = 41,
81 ME = 42,77 ME = 42,
82 IMU = 43,78 IMU = 43,
83 IMP = 44,79 IMP = 44,
84- GE = 45, /* Fmk */80+ GE = 45, /* Fmk */
85 CAMERA = 47,81 CAMERA = 47,
86 ASCENDCL = 48,82 ASCENDCL = 48,
87 TEEOS = 49,83 TEEOS = 49,
@@ -89,14 +85,14 @@ enum {
89 SIS = 51,85 SIS = 51,
90 HSM = 52,86 HSM = 52,
91 DSS = 53,87 DSS = 53,
92- PROCMGR = 54, /* Process Manager, Base Platform */88+ PROCMGR = 54, /* Process Manager, Base Platform */
93 BBOX = 55,89 BBOX = 55,
94 AIVECTOR = 56,90 AIVECTOR = 56,
95 TBE = 57,91 TBE = 57,
96 FV = 58,92 FV = 58,
97 PYPTO = 59,93 PYPTO = 59,
98 TUNE = 60,94 TUNE = 60,
99- HSS = 61, /* helper */95+ HSS = 61, /* helper */
100 FFTS = 62,96 FFTS = 62,
101 OP = 63,97 OP = 63,
102 UDF = 64,98 UDF = 64,
@@ -111,25 +107,21 @@ enum {
111 SYSMONITOR = 73,107 SYSMONITOR = 73,
112 AML = 74,108 AML = 74,
113 ADETECT = 75,109 ADETECT = 75,
114- INVALID_MODULE_ID = 76 /* add new module before INVALID_MODULE_ID */110+ INVALID_MODULE_ID = 76 /* add new module before INVALID_MODULE_ID */
115};111};
116/* Backward compatibility for old misspelled name */112/* Backward compatibility for old misspelled name */
117#define INVLID_MOUDLE_ID INVALID_MODULE_ID113#define INVLID_MOUDLE_ID INVALID_MODULE_ID
118 114 
119- 115+typedef enum { APPLICATION = 0, SYSTEM } ProcessType;
120-typedef enum {116+ 
121- APPLICATION = 0,
122- SYSTEM
123-} ProcessType;
124-
125typedef struct {117typedef struct {
126- ProcessType type; // process type118+ ProcessType type; // process type
127- unsigned int pid; // pid119+ unsigned int pid; // pid
128- unsigned int deviceId; // device id120+ unsigned int deviceId; // device id
129- unsigned int mode; // log save mode121+ unsigned int mode; // log save mode
130- char reserved[48]; // reserve 48 bytes, align to 64 bytes122+ char reserved[48]; // reserve 48 bytes, align to 64 bytes
131} LogAttr;123} LogAttr;
132- 124+ 
133#define DLOG_ATTR_INIT_VALUE 0xFF125#define DLOG_ATTR_INIT_VALUE 0xFF
134- 126+ 
135-#endif // LOG_TYPES_H_127+#endif // LOG_TYPES_H_
@@ -1,62 +1,61 @@
1-/**1+/**
zhangjie
zhangjiezhangjie8月19日

级别:提示 问题:全部行重写但内容逐行一致(疑似行尾符或行尾空白变化),src/dfx/log/inc/toolchain/plog.h 同样情况。 影响:无功能影响,但造成全文件 diff、污染 blame,且行尾配置不一致时后续会反复出现整文件变更。 修复建议:通过 .gitattributes 统一行尾(如 .c/.h text eol=lf),并将行尾归一化与格式化分开提交。

likedislike
GuoWenbo
8月20日 评论:
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10- 10+ 
11-#ifndef PLOG_H_11+#ifndef PLOG_H_
12-#define PLOG_H_12+#define PLOG_H_
13- 13+ 
14-#ifdef __cplusplus14+#ifdef __cplusplus
15-#ifndef LOG_CPP15+#ifndef LOG_CPP
16-extern "C" {16+extern "C" {
17-#endif17+#endif
18-#endif // __cplusplus18+#endif // __cplusplus
19- 19+ 
20-#if defined(_MSC_VER)20+#if defined(_MSC_VER)
21-#define LOG_FUNC_VISIBILITY _declspec(dllexport)21+#define LOG_FUNC_VISIBILITY _declspec(dllexport)
22-#else22+#else
23-#define LOG_FUNC_VISIBILITY __attribute__((visibility("default")))23+#define LOG_FUNC_VISIBILITY __attribute__((visibility("default")))
24-#endif24+#endif
25- 25+ 
26-/**26+/**
27- * @ingroup plog27+ * @ingroup plog
28- * @brief DlogReportInitialize: init log in service process before all device setting.28+ * @brief DlogReportInitialize: init log in service process before all device setting.
29- * @return: 0: SUCCEED, others: FAILED29+ * @return: 0: SUCCEED, others: FAILED
30- */30+ */
31-LOG_FUNC_VISIBILITY int DlogReportInitialize(void) __attribute((weak));31+LOG_FUNC_VISIBILITY int DlogReportInitialize(void) __attribute((weak));
32- 32+ 
33-/**33+/**
34- * @ingroup plog34+ * @ingroup plog
35- * @brief DlogReportFinalize: release log resource in service process after all device reset.35+ * @brief DlogReportFinalize: release log resource in service process after all device reset.
36- * @return: 0: SUCCEED, others: FAILED36+ * @return: 0: SUCCEED, others: FAILED
37- */37+ */
38-LOG_FUNC_VISIBILITY int DlogReportFinalize(void) __attribute((weak));38+LOG_FUNC_VISIBILITY int DlogReportFinalize(void) __attribute((weak));
39- 39+ 
40-/**40+/**
41- * @ingroup : plog41+ * @ingroup : plog
42- * @brief : create thread to recv log from device42+ * @brief : create thread to recv log from device
43- * @param[in] : devId device id43+ * @param[in] : devId device id
44- * @param[in] : mode use macro LOG_SAVE_MODE_XXX in slog.h44+ * @param[in] : mode use macro LOG_SAVE_MODE_XXX in slog.h
45- * @return : 0: SUCCEED, others: FAILED45+ * @return : 0: SUCCEED, others: FAILED
46- */46+ */
47-LOG_FUNC_VISIBILITY int DlogReportStart(int devId, int mode) __attribute((weak));47+LOG_FUNC_VISIBILITY int DlogReportStart(int devId, int mode) __attribute((weak));
48- 48+ 
49-/**49+/**
50- * @ingroup : plog50+ * @ingroup : plog
51- * @brief : stop recv thread51+ * @brief : stop recv thread
52- * @param[in] : devId device id52+ * @param[in] : devId device id
53- */53+ */
54-LOG_FUNC_VISIBILITY void DlogReportStop(int devId) __attribute((weak));54+LOG_FUNC_VISIBILITY void DlogReportStop(int devId) __attribute((weak));
55- 55+ 
56- 56+#ifdef __cplusplus
57-#ifdef __cplusplus57+#ifndef LOG_CPP
58-#ifndef LOG_CPP58+}
59-}59+#endif // LOG_CPP
60-#endif // LOG_CPP60+#endif // __cplusplus
61-#endif // __cplusplus61+#endif // PLOG_H_
62-#endif // PLOG_H_
@@ -22,7 +22,7 @@ extern "C" {
22 * @param [in] objName: object name22 * @param [in] objName: object name
23 * @return atrace handle23 * @return atrace handle
24 */24 */
25-TRACE_EXPORT TraHandle AtraceCreate(TracerType tracerType, const char *objName) __attribute((weak));25+TRACE_EXPORT TraHandle AtraceCreate(TracerType tracerType, const char* objName) __attribute((weak));
26 26 
27/**27/**
28 * @brief Create trace handle.28 * @brief Create trace handle.
@@ -31,8 +31,8 @@ TRACE_EXPORT TraHandle AtraceCreate(TracerType tracerType, const char *objName)
31 * @param [in] attr: object attribute31 * @param [in] attr: object attribute
32 * @return atrace handle32 * @return atrace handle
33 */33 */
34-TRACE_EXPORT TraHandle34+TRACE_EXPORT TraHandle AtraceCreateWithAttr(TracerType tracerType, const char* objName, const TraceAttr* attr)
35- AtraceCreateWithAttr(TracerType tracerType, const char *objName, const TraceAttr *attr) __attribute((weak));35+ __attribute((weak));
36 36 
37/**37/**
38 * @brief Get trace handle38 * @brief Get trace handle
@@ -40,7 +40,7 @@ TRACE_EXPORT TraHandle
40 * @param [in] objName: object name40 * @param [in] objName: object name
41 * @return atrace handle41 * @return atrace handle
42 */42 */
43-TRACE_EXPORT TraHandle AtraceGetHandle(TracerType tracerType, const char *objName) __attribute((weak));43+TRACE_EXPORT TraHandle AtraceGetHandle(TracerType tracerType, const char* objName) __attribute((weak));
44 44 
45/**45/**
46 * @brief Submite trace info46 * @brief Submite trace info
@@ -49,7 +49,7 @@ TRACE_EXPORT TraHandle AtraceGetHandle(TracerType tracerType, const char *objNam
49 * @param [in] bufSize: size of buffer49 * @param [in] bufSize: size of buffer
50 * @return TraStatus50 * @return TraStatus
51 */51 */
52-TRACE_EXPORT TraStatus AtraceSubmit(TraHandle handle, const void *buffer, uint32_t bufSize) __attribute((weak));52+TRACE_EXPORT TraStatus AtraceSubmit(TraHandle handle, const void* buffer, uint32_t bufSize) __attribute((weak));
53 53 
54/**54/**
55 * @brief Destroy trace handle55 * @brief Destroy trace handle
@@ -74,22 +74,22 @@ TRACE_EXPORT TraStatus AtraceSave(TracerType tracerType, bool syncFlag) __attrib
74 * @param [in] bufSize: size of buffer74 * @param [in] bufSize: size of buffer
75 * @return TraStatus75 * @return TraStatus
76 */76 */
77-TRACE_EXPORT TraStatus AtraceSubmitByType(TraHandle handle, uint8_t bufferType,77+TRACE_EXPORT TraStatus AtraceSubmitByType(TraHandle handle, uint8_t bufferType, const void* buffer, uint32_t bufSize)
78- const void *buffer, uint32_t bufSize) __attribute((weak));78+ __attribute((weak));
79 79 
80/**80/**
81 * @brief create trace struct entry with name81 * @brief create trace struct entry with name
82 * @param [in] name: trace struct entry name82 * @param [in] name: trace struct entry name
83 * @return success:trace struct entry fail:null83 * @return success:trace struct entry fail:null
84 */84 */
85-TRACE_EXPORT TraceStructEntry *AtraceStructEntryCreate(const char *name) __attribute((weak));85+TRACE_EXPORT TraceStructEntry* AtraceStructEntryCreate(const char* name) __attribute((weak));
86 86 
87/**87/**
88 * @brief destroy trace struct entry88 * @brief destroy trace struct entry
89 * @param [in] name: trace struct entry name89 * @param [in] name: trace struct entry name
90 * @return NA90 * @return NA
91 */91 */
92-TRACE_EXPORT void AtraceStructEntryDestroy(TraceStructEntry *en) __attribute((weak));92+TRACE_EXPORT void AtraceStructEntryDestroy(TraceStructEntry* en) __attribute((weak));
93 93 
94/**94/**
95 * @brief define trace struct item95 * @brief define trace struct item
@@ -100,8 +100,8 @@ TRACE_EXPORT void AtraceStructEntryDestroy(TraceStructEntry *en) __attribute((we
100 * @param [in] len: bytes occupied by this item100 * @param [in] len: bytes occupied by this item
101 * @return NA101 * @return NA
102 */102 */
103-TRACE_EXPORT void AtraceStructItemFieldSet(TraceStructEntry *en, const char *item,103+TRACE_EXPORT void AtraceStructItemFieldSet(
104- uint8_t type, uint8_t mode, uint16_t len) __attribute((weak));104+ TraceStructEntry* en, const char* item, uint8_t type, uint8_t mode, uint16_t len) __attribute((weak));
105 105 
106/**106/**
107 * @brief define trace struct item if array107 * @brief define trace struct item if array
@@ -112,8 +112,8 @@ TRACE_EXPORT void AtraceStructItemFieldSet(TraceStructEntry *en, const char *ite
112 * @param [in] len: bytes occupied by this item112 * @param [in] len: bytes occupied by this item
113 * @return NA113 * @return NA
114 */114 */
115-TRACE_EXPORT void AtraceStructItemArraySet(TraceStructEntry *en, const char *item,115+TRACE_EXPORT void AtraceStructItemArraySet(
116- uint8_t type, uint8_t mode, uint16_t len) __attribute((weak));116+ TraceStructEntry* en, const char* item, uint8_t type, uint8_t mode, uint16_t len) __attribute((weak));
117 117 
118/**118/**
119 * @brief set trace struct to trace attribute119 * @brief set trace struct to trace attribute
@@ -122,21 +122,21 @@ TRACE_EXPORT void AtraceStructItemArraySet(TraceStructEntry *en, const char *ite
122 * @param [in/out] attr: object attribute122 * @param [in/out] attr: object attribute
123 * @return NA123 * @return NA
124 */124 */
125-TRACE_EXPORT void AtraceStructSetAttr(TraceStructEntry *en, uint8_t type, TraceAttr *attr) __attribute((weak));125+TRACE_EXPORT void AtraceStructSetAttr(TraceStructEntry* en, uint8_t type, TraceAttr* attr) __attribute((weak));
126 126 
127/**127/**
128 * @brief Create trace event.128 * @brief Create trace event.
129 * @param [in] eventName: event name129 * @param [in] eventName: event name
130 * @return event handle130 * @return event handle
131 */131 */
132-TRACE_EXPORT TraEventHandle AtraceEventCreate(const char *eventName) __attribute((weak));132+TRACE_EXPORT TraEventHandle AtraceEventCreate(const char* eventName) __attribute((weak));
133 133 
134/**134/**
135 * @brief Get event handle135 * @brief Get event handle
136 * @param [in] eventName: event name136 * @param [in] eventName: event name
137 * @return event handle137 * @return event handle
138 */138 */
139-TRACE_EXPORT TraEventHandle AtraceEventGetHandle(const char *eventName) __attribute((weak));139+TRACE_EXPORT TraEventHandle AtraceEventGetHandle(const char* eventName) __attribute((weak));
140 140 
141/**141/**
142 * @brief Destroy event handle142 * @brief Destroy event handle
@@ -159,7 +159,7 @@ TRACE_EXPORT TraStatus AtraceEventBindTrace(TraEventHandle eventHandle, TraHandl
159 * @param [in] attr: event attribute159 * @param [in] attr: event attribute
160 * @return TraStatus160 * @return TraStatus
161 */161 */
162-TRACE_EXPORT TraStatus AtraceEventSetAttr(TraEventHandle eventHandle, const TraceEventAttr *attr) __attribute((weak));162+TRACE_EXPORT TraStatus AtraceEventSetAttr(TraEventHandle eventHandle, const TraceEventAttr* attr) __attribute((weak));
163 163 
164/**164/**
165 * @brief Report event and save the bound trace log to disk165 * @brief Report event and save the bound trace log to disk
@@ -173,10 +173,10 @@ TRACE_EXPORT TraStatus AtraceEventReportSync(TraEventHandle eventHandle) __attri
173 * @param [in] attr: global attribute173 * @param [in] attr: global attribute
174 * @return TraStatus174 * @return TraStatus
175 */175 */
176-TRACE_EXPORT TraStatus AtraceSetGlobalAttr(const TraceGlobalAttr *attr) __attribute((weak));176+TRACE_EXPORT TraStatus AtraceSetGlobalAttr(const TraceGlobalAttr* attr) __attribute((weak));
177 177 
178#ifdef __cplusplus178#ifdef __cplusplus
179}179}
180#endif // end of the 'extern "C"' block180#endif // end of the 'extern "C"' block
181 181 
182-#endif182+#endif
@@ -14,96 +14,95 @@
14#include <stdint.h>14#include <stdint.h>
15#include <stdbool.h>15#include <stdbool.h>
16 16 
17-typedef int32_t TraStatus;17+typedef int32_t TraStatus;
18typedef intptr_t TraHandle;18typedef intptr_t TraHandle;
19typedef intptr_t TraEventHandle;19typedef intptr_t TraEventHandle;
20 20 
21#define TRACE_EXPORT __attribute__((visibility("default")))21#define TRACE_EXPORT __attribute__((visibility("default")))
22 22 
23-#define TRACE_SUCCESS 023+#define TRACE_SUCCESS 0
24-#define TRACE_FAILURE (-1)24+#define TRACE_FAILURE (-1)
25-#define TRACE_INVALID_PARAM (-2)25+#define TRACE_INVALID_PARAM (-2)
26-#define TRACE_INVALID_PTR (-3)26+#define TRACE_INVALID_PTR (-3)
27-#define TRACE_INVALID_DATA (-4)27+#define TRACE_INVALID_DATA (-4)
28-#define TRACE_UNSUPPORTED (-5)28+#define TRACE_UNSUPPORTED (-5)
29 29 
30-#define TRACE_INVALID_HANDLE (-1)30+#define TRACE_INVALID_HANDLE (-1)
31-#define TRACE_UNSUPPORTED_HANDLE (-2)31+#define TRACE_UNSUPPORTED_HANDLE (-2)
32 32 
33#define DEFAULT_ATRACE_MSG_NUM 1024U33#define DEFAULT_ATRACE_MSG_NUM 1024U
34#define DEFAULT_ATRACE_MSG_SIZE 112U34#define DEFAULT_ATRACE_MSG_SIZE 112U
35 35 
36// field type36// field type
37-#define TRACE_STRUCT_FIELD_TYPE_CHAR 037+#define TRACE_STRUCT_FIELD_TYPE_CHAR 0
38-#define TRACE_STRUCT_FIELD_TYPE_INT8 138+#define TRACE_STRUCT_FIELD_TYPE_INT8 1
39-#define TRACE_STRUCT_FIELD_TYPE_UINT8 239+#define TRACE_STRUCT_FIELD_TYPE_UINT8 2
40-#define TRACE_STRUCT_FIELD_TYPE_INT16 340+#define TRACE_STRUCT_FIELD_TYPE_INT16 3
41-#define TRACE_STRUCT_FIELD_TYPE_UINT16 441+#define TRACE_STRUCT_FIELD_TYPE_UINT16 4
42-#define TRACE_STRUCT_FIELD_TYPE_INT32 542+#define TRACE_STRUCT_FIELD_TYPE_INT32 5
43-#define TRACE_STRUCT_FIELD_TYPE_UINT32 643+#define TRACE_STRUCT_FIELD_TYPE_UINT32 6
44-#define TRACE_STRUCT_FIELD_TYPE_INT64 744+#define TRACE_STRUCT_FIELD_TYPE_INT64 7
45-#define TRACE_STRUCT_FIELD_TYPE_UINT64 845+#define TRACE_STRUCT_FIELD_TYPE_UINT64 8
46-#define TRACE_STRUCT_ARRAY_TYPE_CHAR 10046+#define TRACE_STRUCT_ARRAY_TYPE_CHAR 100
47-#define TRACE_STRUCT_ARRAY_TYPE_INT8 10147+#define TRACE_STRUCT_ARRAY_TYPE_INT8 101
48-#define TRACE_STRUCT_ARRAY_TYPE_UINT8 10248+#define TRACE_STRUCT_ARRAY_TYPE_UINT8 102
49-#define TRACE_STRUCT_ARRAY_TYPE_INT16 10349+#define TRACE_STRUCT_ARRAY_TYPE_INT16 103
50-#define TRACE_STRUCT_ARRAY_TYPE_UINT16 10450+#define TRACE_STRUCT_ARRAY_TYPE_UINT16 104
51-#define TRACE_STRUCT_ARRAY_TYPE_INT32 10551+#define TRACE_STRUCT_ARRAY_TYPE_INT32 105
52-#define TRACE_STRUCT_ARRAY_TYPE_UINT32 10652+#define TRACE_STRUCT_ARRAY_TYPE_UINT32 106
53-#define TRACE_STRUCT_ARRAY_TYPE_INT64 10753+#define TRACE_STRUCT_ARRAY_TYPE_INT64 107
54-#define TRACE_STRUCT_ARRAY_TYPE_UINT64 10854+#define TRACE_STRUCT_ARRAY_TYPE_UINT64 108
55- 55+ 
56// save mode56// save mode
57-#define TRACE_STRUCT_SHOW_MODE_DEC 0 // decimal57+#define TRACE_STRUCT_SHOW_MODE_DEC 0 // decimal
58-#define TRACE_STRUCT_SHOW_MODE_BIN 1 // binary58+#define TRACE_STRUCT_SHOW_MODE_BIN 1 // binary
59-#define TRACE_STRUCT_SHOW_MODE_HEX 2 // hexadecimal59+#define TRACE_STRUCT_SHOW_MODE_HEX 2 // hexadecimal
60-#define TRACE_STRUCT_SHOW_MODE_CHAR 3 // string60+#define TRACE_STRUCT_SHOW_MODE_CHAR 3 // string
61-
62 61 
63// evnet process type62// evnet process type
64-#define TRACE_EVENT_PROCESS_SYNC 0U // process event synchronously63+#define TRACE_EVENT_PROCESS_SYNC 0U // process event synchronously
65-#define TRACE_EVENT_PROCESS_ASYNC 1U // process event asynchronously64+#define TRACE_EVENT_PROCESS_ASYNC 1U // process event asynchronously
66-#define TRACE_EVENT_PROCESS_ASYNC_DEDUPLICATION 2U // process event asynchronously and deduplication65+#define TRACE_EVENT_PROCESS_ASYNC_DEDUPLICATION 2U // process event asynchronously and deduplication
67 66 
68-#define TRACE_NAME_LENGTH 32U67+#define TRACE_NAME_LENGTH 32U
69 68 
70-#define TRACE_STRUCT_ENTRY_MAX_NUM 10U69+#define TRACE_STRUCT_ENTRY_MAX_NUM 10U
71 70 
72// lock type71// lock type
73-#define TRACE_LOCK_BASED 0U72+#define TRACE_LOCK_BASED 0U
74-#define TRACE_LOCK_FREE 1U73+#define TRACE_LOCK_FREE 1U
75 74 
76typedef enum TracerType {75typedef enum TracerType {
77- TRACER_TYPE_SCHEDULE = 0,76+ TRACER_TYPE_SCHEDULE = 0,
78- TRACER_TYPE_PROGRESS = 1,77+ TRACER_TYPE_PROGRESS = 1,
79 TRACER_TYPE_STATISTICS = 2,78 TRACER_TYPE_STATISTICS = 2,
80 TRACER_TYPE_MAX,79 TRACER_TYPE_MAX,
81} TracerType;80} TracerType;
82- 81+ 
83typedef struct TraceStructEntry {82typedef struct TraceStructEntry {
84- char name[TRACE_NAME_LENGTH]; // entry name83+ char name[TRACE_NAME_LENGTH]; // entry name
85- void *list; // field list84+ void* list; // field list
86} TraceStructEntry;85} TraceStructEntry;
87 86 
88typedef struct TraceAttr {87typedef struct TraceAttr {
89- bool exitSave; // exec save when AtraceDestroy88+ bool exitSave; // exec save when AtraceDestroy
90- uint16_t msgNum; // 1 - 1024, msgNum * msgSize <= 128k, msgNum >= max thread num * 289+ uint16_t msgNum; // 1 - 1024, msgNum * msgSize <= 128k, msgNum >= max thread num * 2
91- uint16_t msgSize; // 64 - 102490+ uint16_t msgSize; // 64 - 1024
92- TraceStructEntry *handle[TRACE_STRUCT_ENTRY_MAX_NUM];91+ TraceStructEntry* handle[TRACE_STRUCT_ENTRY_MAX_NUM];
93- uint8_t noLock; // 0: need lock to protect concurrent scenarios; 1: no lock to protect92+ uint8_t noLock; // 0: need lock to protect concurrent scenarios; 1: no lock to protect
94 uint8_t reserve[31];93 uint8_t reserve[31];
95} TraceAttr;94} TraceAttr;
96 95 
97typedef struct TraceEventAttr {96typedef struct TraceEventAttr {
98- uint16_t limitedNum; // [0, 65535] 0 for unlimited97+ uint16_t limitedNum; // [0, 65535] 0 for unlimited
99 uint8_t reserve[30];98 uint8_t reserve[30];
100} TraceEventAttr;99} TraceEventAttr;
101 100 
102typedef struct TraceGlobalAttr {101typedef struct TraceGlobalAttr {
103- uint8_t saveMode; // 0: local save; 1: send to remote and save102+ uint8_t saveMode; // 0: local save; 1: send to remote and save
104- uint8_t deviceId; // 0: default; 32~63:vf103+ uint8_t deviceId; // 0: default; 32~63:vf
105- uint32_t pid; // 0: default; if saveMode=1, means host pid104+ uint32_t pid; // 0: default; if saveMode=1, means host pid
106 uint8_t reserve[32];105 uint8_t reserve[32];
107} TraceGlobalAttr;106} TraceGlobalAttr;
108 107 
109-#endif108+#endif
@@ -11,10 +11,10 @@
11#define AWATCHDOG_H11#define AWATCHDOG_H
12#include "awatchdog_types.h"12#include "awatchdog_types.h"
13 13 
14-#define AWD_ATOMIC_FETCH_AND_ADD(ptr, value) ((__typeof__(*(ptr)))__sync_fetch_and_add((ptr), (value)))14+#define AWD_ATOMIC_FETCH_AND_ADD(ptr, value) ((__typeof__(*(ptr)))__sync_fetch_and_add((ptr), (value)))
15-#define AWD_ATOMIC_SUB_AND_FETCH(ptr, value) ((__typeof__(*(ptr)))__sync_sub_and_fetch((ptr), (value)))15+#define AWD_ATOMIC_SUB_AND_FETCH(ptr, value) ((__typeof__(*(ptr)))__sync_sub_and_fetch((ptr), (value)))
16-#define AWD_ATOMIC_TEST_AND_SET(ptr, value) ((void)__sync_lock_test_and_set((ptr), (value)))16+#define AWD_ATOMIC_TEST_AND_SET(ptr, value) ((void)__sync_lock_test_and_set((ptr), (value)))
17-#define AWD_ATOMIC_CMP_AND_SWAP(ptr, comp, value) (__sync_bool_compare_and_swap((ptr), (comp), (value)))17+#define AWD_ATOMIC_CMP_AND_SWAP(ptr, comp, value) (__sync_bool_compare_and_swap((ptr), (comp), (value)))
18 18 
19#ifdef __cplusplus19#ifdef __cplusplus
20extern "C" {20extern "C" {
@@ -25,9 +25,9 @@ typedef enum AwdWatchdogType {
25 AWD_WATCHDOG_TYPE_MAX,25 AWD_WATCHDOG_TYPE_MAX,
26} AwdWatchdogType;26} AwdWatchdogType;
27 27 
28-#define DEFINE_THREAD_WATCHDOG(name) static __thread AwdHandle name = -128+#define DEFINE_THREAD_WATCHDOG(name) static __thread AwdHandle name = -1
29#define WATCHDOG_TYPE_BIT 16U29#define WATCHDOG_TYPE_BIT 16U
30-#define DEFINE_THREAD_WATCHDOG_ID(moduleId) \30+#define DEFINE_THREAD_WATCHDOG_ID(moduleId) \
31 ((uint32_t)moduleId) | ((uint32_t)1U << WATCHDOG_TYPE_BIT) | ((uint32_t)AWD_WATCHDOG_TYPE_THREAD)31 ((uint32_t)moduleId) | ((uint32_t)1U << WATCHDOG_TYPE_BIT) | ((uint32_t)AWD_WATCHDOG_TYPE_THREAD)
32 32 
33/*33/*
@@ -56,7 +56,7 @@ static inline AwdStatus AwdStartThreadWatchdog(const AwdHandle handle)
56 if (handle == AWD_INVALID_HANDLE) {56 if (handle == AWD_INVALID_HANDLE) {
57 return AWD_FAILURE;57 return AWD_FAILURE;
58 }58 }
59- AwdThreadWatchdog *dog = (AwdThreadWatchdog *)handle;59+ AwdThreadWatchdog* dog = (AwdThreadWatchdog*)handle;
60 AWD_ATOMIC_TEST_AND_SET(&dog->runCount, 0);60 AWD_ATOMIC_TEST_AND_SET(&dog->runCount, 0);
61 AWD_ATOMIC_TEST_AND_SET(&dog->startCount, AWD_STATUS_STARTED);61 AWD_ATOMIC_TEST_AND_SET(&dog->startCount, AWD_STATUS_STARTED);
62 return AWD_SUCCESS;62 return AWD_SUCCESS;
@@ -72,7 +72,7 @@ static inline AwdStatus AwdFeedThreadWatchdog(const AwdHandle handle)
72 if (handle == AWD_INVALID_HANDLE) {72 if (handle == AWD_INVALID_HANDLE) {
73 return AWD_FAILURE;73 return AWD_FAILURE;
74 }74 }
75- AwdThreadWatchdog *dog = (AwdThreadWatchdog *)handle;75+ AwdThreadWatchdog* dog = (AwdThreadWatchdog*)handle;
76 AWD_ATOMIC_TEST_AND_SET(&dog->startCount, AWD_ATOMIC_FETCH_AND_ADD(&dog->runCount, 0));76 AWD_ATOMIC_TEST_AND_SET(&dog->startCount, AWD_ATOMIC_FETCH_AND_ADD(&dog->runCount, 0));
77 return AWD_SUCCESS;77 return AWD_SUCCESS;
78}78}
@@ -87,7 +87,7 @@ static inline AwdStatus AwdStopThreadWatchdog(const AwdHandle handle)
87 if (handle == AWD_INVALID_HANDLE) {87 if (handle == AWD_INVALID_HANDLE) {
88 return AWD_FAILURE;88 return AWD_FAILURE;
89 }89 }
90- AwdThreadWatchdog *dog = (AwdThreadWatchdog *)handle;90+ AwdThreadWatchdog* dog = (AwdThreadWatchdog*)handle;
91 AWD_ATOMIC_TEST_AND_SET(&dog->startCount, AWD_STATUS_INIT);91 AWD_ATOMIC_TEST_AND_SET(&dog->startCount, AWD_STATUS_INIT);
92 return AWD_SUCCESS;92 return AWD_SUCCESS;
93}93}
@@ -96,4 +96,4 @@ static inline AwdStatus AwdStopThreadWatchdog(const AwdHandle handle)
96}96}
97#endif // __cplusplus97#endif // __cplusplus
98 98 
99-#endif99+#endif
@@ -12,18 +12,18 @@
12#include <stdint.h>12#include <stdint.h>
13 13 
14#define AWD_EXPORT __attribute__((visibility("default")))14#define AWD_EXPORT __attribute__((visibility("default")))
15-typedef void (*AwatchdogCallbackFunc) (void *);15+typedef void (*AwatchdogCallbackFunc)(void*);
16-typedef int32_t AwdStatus;16+typedef int32_t AwdStatus;
17typedef intptr_t AwdHandle;17typedef intptr_t AwdHandle;
18 18 
19// value of AwdStatus19// value of AwdStatus
20-#define AWD_SUCCESS 020+#define AWD_SUCCESS 0
21-#define AWD_FAILURE (-1)21+#define AWD_FAILURE (-1)
22-#define AWD_INVLIAD_PARAM (-2)22+#define AWD_INVLIAD_PARAM (-2)
23 23 
24// value of AwdHandle24// value of AwdHandle
25-#define AWD_INVALID_HANDLE (-1)25+#define AWD_INVALID_HANDLE (-1)
26-#define AWD_ALL_HANDLE (0)26+#define AWD_ALL_HANDLE (0)
27 27 
28// watchdog status28// watchdog status
29#define AWD_STATUS_DESTROYED -229#define AWD_STATUS_DESTROYED -2
@@ -31,8 +31,8 @@ typedef intptr_t AwdHandle;
31#define AWD_STATUS_STARTED 031#define AWD_STATUS_STARTED 0
32 32 
33typedef struct AwdThreadWatchdog {33typedef struct AwdThreadWatchdog {
34- uint32_t dogId; // [31:16] watchdog type, [15:0] moduleId34+ uint32_t dogId; // [31:16] watchdog type, [15:0] moduleId
35- uint32_t timeout; // timeout, s35+ uint32_t timeout; // timeout, s
36 int32_t runCount;36 int32_t runCount;
37 int32_t startCount;37 int32_t startCount;
38 int32_t tid;38 int32_t tid;
@@ -40,4 +40,4 @@ typedef struct AwdThreadWatchdog {
40 AwatchdogCallbackFunc callback;40 AwatchdogCallbackFunc callback;
41} AwdThreadWatchdog;41} AwdThreadWatchdog;
42 42 
43-#endif43+#endif
@@ -20,9 +20,9 @@ extern "C" {
20 * @param [in] : subdir subdirectory name20 * @param [in] : subdir subdirectory name
21 * @return : 0 success; -1 failed21 * @return : 0 success; -1 failed
22 */22 */
23-int StackcoreSetSubdirectory(const char *subdir);23+int StackcoreSetSubdirectory(const char* subdir);
24 24 
25#ifdef __cplusplus25#ifdef __cplusplus
26}26}
27#endif27#endif
28-#endif28+#endif
@@ -35,10 +35,10 @@ LOG_FUNC_VISIBILITY int32_t AlogCheckDebugLevel(uint32_t moduleId, int32_t level
35 * @param [in] : level log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG35 * @param [in] : level log level, eg: DLOG_ERROR/DLOG_WARN/DLOG_INFO/DLOG_DEBUG
36 * @return: : 0: success, other: failed36 * @return: : 0: success, other: failed
37 */37 */
38-LOG_FUNC_VISIBILITY int32_t AlogRecord(uint32_t moduleId, uint32_t logType, int32_t level, const char *fmt, ...)38+LOG_FUNC_VISIBILITY int32_t AlogRecord(uint32_t moduleId, uint32_t logType, int32_t level, const char* fmt, ...)
39 __attribute((weak)) __attribute__((format(printf, 4, 5)));39 __attribute((weak)) __attribute__((format(printf, 4, 5)));
40 40 
41#ifdef __cplusplus41#ifdef __cplusplus
42}42}
43#endif // __cplusplus43#endif // __cplusplus
44-#endif // ALOG_PUB_H_44+#endif // ALOG_PUB_H_
@@ -1,61 +1,60 @@
1-/**1+/**
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10-#ifndef PLOG_H_10+#ifndef PLOG_H_
11-#define PLOG_H_11+#define PLOG_H_
12- 12+ 
13-#ifdef __cplusplus13+#ifdef __cplusplus
14-#ifndef LOG_CPP14+#ifndef LOG_CPP
15-extern "C" {15+extern "C" {
16-#endif16+#endif
17-#endif // __cplusplus17+#endif // __cplusplus
18- 18+ 
19-#if defined(_MSC_VER)19+#if defined(_MSC_VER)
20-#define LOG_FUNC_VISIBILITY _declspec(dllexport)20+#define LOG_FUNC_VISIBILITY _declspec(dllexport)
21-#else21+#else
22-#define LOG_FUNC_VISIBILITY __attribute__((visibility("default")))22+#define LOG_FUNC_VISIBILITY __attribute__((visibility("default")))
23-#endif23+#endif
24- 24+ 
25-/**25+/**
26- * @ingroup plog26+ * @ingroup plog
27- * @brief DlogReportInitialize: init log in service process before all device setting.27+ * @brief DlogReportInitialize: init log in service process before all device setting.
28- * @return: 0: SUCCEED, others: FAILED28+ * @return: 0: SUCCEED, others: FAILED
29- */29+ */
30-LOG_FUNC_VISIBILITY int DlogReportInitialize(void) __attribute((weak));30+LOG_FUNC_VISIBILITY int DlogReportInitialize(void) __attribute((weak));
31- 31+ 
32-/**32+/**
33- * @ingroup plog33+ * @ingroup plog
34- * @brief DlogReportFinalize: release log resource in service process after all device reset.34+ * @brief DlogReportFinalize: release log resource in service process after all device reset.
35- * @return: 0: SUCCEED, others: FAILED35+ * @return: 0: SUCCEED, others: FAILED
36- */36+ */
37-LOG_FUNC_VISIBILITY int DlogReportFinalize(void) __attribute((weak));37+LOG_FUNC_VISIBILITY int DlogReportFinalize(void) __attribute((weak));
38- 38+ 
39-/**39+/**
40- * @ingroup : plog40+ * @ingroup : plog
41- * @brief : create thread to recv log from device41+ * @brief : create thread to recv log from device
42- * @param[in] : devId device id42+ * @param[in] : devId device id
43- * @param[in] : mode use macro LOG_SAVE_MODE_XXX in slog.h43+ * @param[in] : mode use macro LOG_SAVE_MODE_XXX in slog.h
44- * @return : 0: SUCCEED, others: FAILED44+ * @return : 0: SUCCEED, others: FAILED
45- */45+ */
46-LOG_FUNC_VISIBILITY int DlogReportStart(int devId, int mode) __attribute((weak));46+LOG_FUNC_VISIBILITY int DlogReportStart(int devId, int mode) __attribute((weak));
47- 47+ 
48-/**48+/**
49- * @ingroup : plog49+ * @ingroup : plog
50- * @brief : stop recv thread50+ * @brief : stop recv thread
51- * @param[in] : devId device id51+ * @param[in] : devId device id
52- */52+ */
53-LOG_FUNC_VISIBILITY void DlogReportStop(int devId) __attribute((weak));53+LOG_FUNC_VISIBILITY void DlogReportStop(int devId) __attribute((weak));
54- 54+ 
55- 55+#ifdef __cplusplus
56-#ifdef __cplusplus56+#ifndef LOG_CPP
57-#ifndef LOG_CPP57+}
58-}58+#endif // LOG_CPP
59-#endif // LOG_CPP59+#endif // __cplusplus
60-#endif // __cplusplus60+#endif // PLOG_H_
61-#endif // PLOG_H_
@@ -25,11 +25,11 @@ extern "C" {
25 *25 *
26 * log level id26 * log level id
27 */27 */
28-#define DLOG_EVENT 0x10 // event log print level id28+#define DLOG_EVENT 0x10 // event log print level id
29 29 
30-#define LOG_SAVE_MODE_DEF (0x0U) // default30+#define LOG_SAVE_MODE_DEF (0x0U) // default
31-#define LOG_SAVE_MODE_UNI (0xFE756E69U) // unify save mode31+#define LOG_SAVE_MODE_UNI (0xFE756E69U) // unify save mode
32-#define LOG_SAVE_MODE_SEP (0xFE736570U) // separate save mode32+#define LOG_SAVE_MODE_SEP (0xFE736570U) // separate save mode
33 33 
34/**34/**
35 * @ingroup slog35 * @ingroup slog
@@ -37,7 +37,7 @@ extern "C" {
37 * module id37 * module id
38 * if a module needs to be added, add the module at the end and before INVALID_MODULE_ID38 * if a module needs to be added, add the module at the end and before INVALID_MODULE_ID
39 */39 */
40-#define ALL_MODULE (0x0000FFFFU)40+#define ALL_MODULE (0x0000FFFFU)
41 41 
42/**42/**
43 * @ingroup slog43 * @ingroup slog
@@ -52,8 +52,8 @@ LOG_FUNC_VISIBILITY void dlog_init(void);
52 * @param [in]moduleId: module id, eg: CCE52 * @param [in]moduleId: module id, eg: CCE
53 * @param [in]fmt: log content53 * @param [in]fmt: log content
54 */54 */
55-#define dlog_event(moduleId, fmt, ...) \55+#define dlog_event(moduleId, fmt, ...) \
56- do { \56+ do { \
57 DlogRecord(moduleId, DLOG_EVENT, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__); \57 DlogRecord(moduleId, DLOG_EVENT, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__); \
58 } while (TMP_LOG != 0)58 } while (TMP_LOG != 0)
59 59 
@@ -75,7 +75,7 @@ extern "C" {
75 * @param [out]enableEvent: 1: enable; 0: disable75 * @param [out]enableEvent: 1: enable; 0: disable
76 * @return: module level(0: debug, 1: info, 2: warning, 3: error, 4: null output)76 * @return: module level(0: debug, 1: info, 2: warning, 3: error, 4: null output)
77 */77 */
78-LOG_FUNC_VISIBILITY int DlogGetlevelForC(int moduleId, int *enableEvent);78+LOG_FUNC_VISIBILITY int DlogGetlevelForC(int moduleId, int* enableEvent);
79 79 
80/**80/**
81 * @ingroup slog81 * @ingroup slog
@@ -116,11 +116,11 @@ LOG_FUNC_VISIBILITY int32_t DlogSetAttrForC(LogAttr logAttrInfo);
116 * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 16: event)116 * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 16: event)
117 * @param [in]fmt: log content117 * @param [in]fmt: log content
118 */118 */
119-#define DlogForC(moduleId, level, fmt, ...) \119+#define DlogForC(moduleId, level, fmt, ...) \
120- do { \120+ do { \
121- if (CheckLogLevelForC(moduleId, level) == 1) { \121+ if (CheckLogLevelForC(moduleId, level) == 1) { \
122- DlogRecordForC(moduleId, level, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__); \122+ DlogRecordForC(moduleId, level, "[%s:%d]" fmt, DLOG_FILE_NAME, __LINE__, ##__VA_ARGS__); \
123- } \123+ } \
124 } while (TMP_LOG != 0)124 } while (TMP_LOG != 0)
125 125 
126/**126/**
@@ -133,11 +133,11 @@ LOG_FUNC_VISIBILITY int32_t DlogSetAttrForC(LogAttr logAttrInfo);
133 * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 16: event)133 * @param [in]level(0: debug, 1: info, 2: warning, 3: error, 16: event)
134 * @param [in]fmt: log content134 * @param [in]fmt: log content
135 */135 */
136-#define DlogSubForC(moduleId, submodule, level, fmt, ...) \136+#define DlogSubForC(moduleId, submodule, level, fmt, ...) \
137- do { \137+ do { \
138- if (CheckLogLevelForC(moduleId, level) == 1) { \138+ if (CheckLogLevelForC(moduleId, level) == 1) { \
139- DlogRecordForC(moduleId, level, "[%s:%d][%s]" fmt, DLOG_FILE_NAME, __LINE__, submodule, ##__VA_ARGS__); \139+ DlogRecordForC(moduleId, level, "[%s:%d][%s]" fmt, DLOG_FILE_NAME, __LINE__, submodule, ##__VA_ARGS__); \
140- } \140+ } \
141 } while (TMP_LOG != 0)141 } while (TMP_LOG != 0)
142 142 
143/**143/**
@@ -147,7 +147,7 @@ LOG_FUNC_VISIBILITY int32_t DlogSetAttrForC(LogAttr logAttrInfo);
147LOG_FUNC_VISIBILITY void DlogFlushForC(void);147LOG_FUNC_VISIBILITY void DlogFlushForC(void);
148 148 
149// log interface149// log interface
150-LOG_FUNC_VISIBILITY void DlogRecordForC(int32_t moduleId, int32_t level, const char *fmt, ...) __attribute((weak));150+LOG_FUNC_VISIBILITY void DlogRecordForC(int32_t moduleId, int32_t level, const char* fmt, ...) __attribute((weak));
151 151 
152#ifdef __cplusplus152#ifdef __cplusplus
153}153}
@@ -1,60 +1,60 @@
1-/**1+/**
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10-#ifndef SLOG_API_H10+#ifndef SLOG_API_H
11-#define SLOG_API_H11+#define SLOG_API_H
12-#include "slog.h"12+#include "slog.h"
13-#ifdef __cplusplus13+#ifdef __cplusplus
14-#ifndef LOG_CPP14+#ifndef LOG_CPP
15-extern "C" {15+extern "C" {
16-#endif16+#endif
17-#endif // __cplusplus17+#endif // __cplusplus
18- 18+ 
19-typedef struct TagKv {19+typedef struct TagKv {
20- char *kname;20+ char* kname;
21- char *value;21+ char* value;
22-} KeyValue;22+} KeyValue;
23- 23+ 
24-/**24+/**
25- * @ingroup slog25+ * @ingroup slog
26- * @brief Internal log interface, other modules are not allowed to call this interface26+ * @brief Internal log interface, other modules are not allowed to call this interface
27- */27+ */
28-LOG_FUNC_VISIBILITY void DlogErrorInner(int32_t moduleId, const char *fmt, ...);28+LOG_FUNC_VISIBILITY void DlogErrorInner(int32_t moduleId, const char* fmt, ...);
29-LOG_FUNC_VISIBILITY void DlogWarnInner(int32_t moduleId, const char *fmt, ...);29+LOG_FUNC_VISIBILITY void DlogWarnInner(int32_t moduleId, const char* fmt, ...);
30-LOG_FUNC_VISIBILITY void DlogInfoInner(int32_t moduleId, const char *fmt, ...);30+LOG_FUNC_VISIBILITY void DlogInfoInner(int32_t moduleId, const char* fmt, ...);
31-LOG_FUNC_VISIBILITY void DlogDebugInner(int32_t moduleId, const char *fmt, ...);31+LOG_FUNC_VISIBILITY void DlogDebugInner(int32_t moduleId, const char* fmt, ...);
32-LOG_FUNC_VISIBILITY void DlogEventInner(int32_t moduleId, const char *fmt, ...);32+LOG_FUNC_VISIBILITY void DlogEventInner(int32_t moduleId, const char* fmt, ...);
33-LOG_FUNC_VISIBILITY void DlogInner(int32_t moduleId, int32_t level, const char *fmt, ...);33+LOG_FUNC_VISIBILITY void DlogInner(int32_t moduleId, int32_t level, const char* fmt, ...);
34-LOG_FUNC_VISIBILITY void DlogWithKVInner(int32_t moduleId, int32_t level,34+LOG_FUNC_VISIBILITY void DlogWithKVInner(
35- const KeyValue *pstKVArray, int32_t kvNum, const char *fmt, ...);35+ int32_t moduleId, int32_t level, const KeyValue* pstKVArray, int32_t kvNum, const char* fmt, ...);
36- 36+ 
37-#ifdef __cplusplus37+#ifdef __cplusplus
38-#ifndef LOG_CPP38+#ifndef LOG_CPP
39-}39+}
40-#endif // LOG_CPP40+#endif // LOG_CPP
41-#endif // __cplusplus41+#endif // __cplusplus
42- 42+ 
43-#ifdef LOG_CPP43+#ifdef LOG_CPP
44-#ifdef __cplusplus44+#ifdef __cplusplus
45-extern "C" {45+extern "C" {
46-#endif46+#endif
47- 47+ 
48-/**48+/**
49- * @ingroup slog49+ * @ingroup slog
50- * @brief Internal log interface, other modules are not allowed to call this interface50+ * @brief Internal log interface, other modules are not allowed to call this interface
51- */51+ */
52-LOG_FUNC_VISIBILITY void DlogInnerForC(int32_t moduleId, int32_t level, const char *fmt, ...);52+LOG_FUNC_VISIBILITY void DlogInnerForC(int32_t moduleId, int32_t level, const char* fmt, ...);
53-LOG_FUNC_VISIBILITY void DlogWithKVInnerForC(int32_t moduleId, int32_t level,53+LOG_FUNC_VISIBILITY void DlogWithKVInnerForC(
54- const KeyValue *pstKVArray, int32_t kvNum, const char *fmt, ...);54+ int32_t moduleId, int32_t level, const KeyValue* pstKVArray, int32_t kvNum, const char* fmt, ...);
55- 55+ 
56-#ifdef __cplusplus56+#ifdef __cplusplus
57-}57+}
58-#endif58+#endif
59-#endif // LOG_CPP59+#endif // LOG_CPP
60-#endif60+#endif
@@ -1,449 +1,455 @@
1-/**1+/**
zhangjie
zhangjiezhangjie8月19日

级别:一般 问题:整文件重写,diff 中部截断约 8.9KB,截断部分(DlogGetEventLogPatterns/DlogGetSelfLogPatterns/DlogGetAllLogPatterns/DlogGetConfigInfo/DlogGetLogPatterns 等)无法检视确认无逻辑变更。 影响:隐藏语义变更的风险无法排除,该文件包含路径拼接、内存分配与 ioctl 交互等敏感逻辑。 修复建议:与 dlog_socket.c 一致,用 git diff -w --ignore-cr-at-eol 验证仅格式变化后再合入;行尾归一化独立提交。

likedislike
GuoWenbo
8月20日 评论:
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10- 10+ 
11-#include "mergeslog.h"11+#include "mergeslog.h"
12-#include <stdio.h>12+#include <stdio.h>
13-#include <string.h>13+#include <string.h>
14-#include <stdbool.h>14+#include <stdbool.h>
15-#include "log_iam_pub.h"15+#include "log_iam_pub.h"
16-#include "iam.h"16+#include "iam.h"
17-#include "log_print.h"17+#include "log_print.h"
18-#include "log_platform.h"18+#include "log_platform.h"
19-#include "log_file_info.h"19+#include "log_file_info.h"
20-#include "slog.h"20+#include "slog.h"
21- 21+ 
22-#define OUTPUT_LOG_FILE "/ascendmerge.log"22+#define OUTPUT_LOG_FILE "/ascendmerge.log"
23-#define OUTPUT_GZ_LOG_FILE "/ascendmerge.log.gz"23+#define OUTPUT_GZ_LOG_FILE "/ascendmerge.log.gz"
24-#define GENERAL_LOG_NUM 3U // genenal log = deviece-os + device-app + aos-core-app24+#define GENERAL_LOG_NUM 3U // genenal log = deviece-os + device-app + aos-core-app
25-#define GROUP_MAP_SIZE (INVALID_MODULE_ID + 1)25+#define GROUP_MAP_SIZE (INVALID_MODULE_ID + 1)
26-#define GZIP_SUFFIX ".gz"26+#define GZIP_SUFFIX ".gz"
27- 27+ 
28-typedef struct {28+typedef struct {
29- char rootPath[PATH_MAX];29+ char rootPath[PATH_MAX];
30- char groupPath[PATH_MAX];30+ char groupPath[PATH_MAX];
31- char groupName[GROUP_MAP_SIZE][NAME_MAX];31+ char groupName[GROUP_MAP_SIZE][NAME_MAX];
32-} LogConfigInfo;32+} LogConfigInfo;
33- 33+ 
34-typedef struct {34+typedef struct {
35- char path[PATH_MAX];35+ char path[PATH_MAX];
36- char dirName[NAME_MAX];36+ char dirName[NAME_MAX];
37- char fileName[NAME_MAX];37+ char fileName[NAME_MAX];
38- char activeSuffix[NAME_MAX];38+ char activeSuffix[NAME_MAX];
39- char rotateSuffix[NAME_MAX];39+ char rotateSuffix[NAME_MAX];
40-} LogPathPattern;40+} LogPathPattern;
41- 41+ 
42-/**42+/**
43- * @brief : ioctl to slogd to collect log43+ * @brief : ioctl to slogd to collect log
44- * @param [in] : dir directory to save log file44+ * @param [in] : dir directory to save log file
45- * @param [in] : mode permission type45+ * @param [in] : mode permission type
46- * @return : SYS_OK success; SYS_ERROR failure46+ * @return : SYS_OK success; SYS_ERROR failure
47- */47+ */
48-STATIC int32_t MergeCheckDir(const char *dir, int32_t mode)48+STATIC int32_t MergeCheckDir(const char* dir, int32_t mode)
49-{49+{
50- if ((ToolAccessWithMode(dir, F_OK) != SYS_OK) || (ToolAccessWithMode(dir, mode) != SYS_OK)) {50+ if ((ToolAccessWithMode(dir, F_OK) != SYS_OK) || (ToolAccessWithMode(dir, mode) != SYS_OK)) {
51- SELF_LOG_ERROR("dir has no permission, dir=%s.", dir);51+ SELF_LOG_ERROR("dir has no permission, dir=%s.", dir);
52- return SYS_ERROR;52+ return SYS_ERROR;
53- }53+ }
54- return SYS_OK;54+ return SYS_OK;
55-}55+}
56- 56+ 
57-/**57+/**
58- * @brief : ioctl to slogd to collect log58+ * @brief : ioctl to slogd to collect log
59- * @param [out] : fd iam service fd59+ * @param [out] : fd iam service fd
60- * @return : SYS_OK success; SYS_ERROR failure60+ * @return : SYS_OK success; SYS_ERROR failure
61- */61+ */
62-STATIC int32_t MergeOpenIamService(int32_t *fd)62+STATIC int32_t MergeOpenIamService(int32_t* fd)
63-{63+{
64- *fd = INVALID;64+ *fd = INVALID;
65- int32_t retry = 0;65+ int32_t retry = 0;
66- while ((*fd == INVALID) && (retry < IAM_RETRY_TIMES)) {66+ while ((*fd == INVALID) && (retry < IAM_RETRY_TIMES)) {
67- *fd = open(LOGOUT_IAM_SERVICE_PATH, O_RDWR);67+ *fd = open(LOGOUT_IAM_SERVICE_PATH, O_RDWR);
68- retry++;68+ retry++;
69- }69+ }
70- return (*fd == INVALID) ? SYS_ERROR : SYS_OK;70+ return (*fd == INVALID) ? SYS_ERROR : SYS_OK;
71-}71+}
72- 72+ 
73-STATIC INLINE bool MergeIsBusy(int32_t err)73+STATIC INLINE bool MergeIsBusy(int32_t err) { return ((err) == ETIMEDOUT) || ((err) == EAGAIN) || ((err) == EBUSY); }
74-{74+ 
75- return ((err) == ETIMEDOUT) || ((err) == EAGAIN) || ((err) == EBUSY);75+/**
76-}76+ * @brief : ioctl to slogd to collect log
77- 77+ * @param [in] : fd iam service fd
78-/**78+ * @param [in] : arg ioctl argument
79- * @brief : ioctl to slogd to collect log79+ * @param [in] : cmd ioctl cmdline
80- * @param [in] : fd iam service fd80+ * @return : SYS_OK success; SYS_ERROR failure
81- * @param [in] : arg ioctl argument81+ */
82- * @param [in] : cmd ioctl cmdline82+STATIC int32_t MergeIoctlCollect(int32_t fd, struct IAMIoctlArg* arg, uint32_t cmd)
83- * @return : SYS_OK success; SYS_ERROR failure83+{
84- */84+ int32_t retry = 0;
85-STATIC int32_t MergeIoctlCollect(int32_t fd, struct IAMIoctlArg *arg, uint32_t cmd)85+ int32_t ret = 0;
86-{86+ int32_t err = 0;
87- int32_t retry = 0;87+ do {
88- int32_t ret = 0;88+ ret = ioctl(fd, cmd, arg);
89- int32_t err = 0;89+ retry++;
90- do {90+ err = ToolGetErrorCode();
91- ret = ioctl(fd, cmd, arg);91+ } while ((ret == SYS_ERROR) && (retry <= IAM_RETRY_TIMES) && (MergeIsBusy(err)));
92- retry++;92+ return ret;
93- err = ToolGetErrorCode();93+}
94- } while ((ret == SYS_ERROR) && (retry <= IAM_RETRY_TIMES) && (MergeIsBusy(err)));94+ 
95- return ret;95+STATIC int32_t MergeGetRealPath(char* dir, char* validPath, int32_t length, int32_t mode)
96-}96+{
97- 97+ if ((dir == NULL) || (validPath == NULL) || (length <= 0)) {
98-STATIC int32_t MergeGetRealPath(char *dir, char *validPath, int32_t length, int32_t mode)98+ return SYS_ERROR;
99-{99+ }
100- if ((dir == NULL) || (validPath == NULL) || (length <= 0)) {100+ if ((ToolRealPath(dir, validPath, length) != SYS_OK) && (ToolGetErrorCode() != ENOENT)) {
101- return SYS_ERROR;101+ SELF_LOG_WARN(
102- }102+ "can not get realpath, file=%s, pid = %d, strerr=%s.", dir, ToolGetPid(), strerror(ToolGetErrorCode()));
103- if ((ToolRealPath(dir, validPath, length) != SYS_OK) && (ToolGetErrorCode() != ENOENT)) {103+ return SYS_ERROR;
104- SELF_LOG_WARN("can not get realpath, file=%s, pid = %d, strerr=%s.",104+ }
105- dir, ToolGetPid(), strerror(ToolGetErrorCode()));105+ ONE_ACT_ERR_LOG(
106- return SYS_ERROR;106+ MergeCheckDir(validPath, mode) != SYS_OK, return SYS_ERROR, "dir[%s] is invalid, pid = %d.", validPath,
107- }107+ ToolGetPid());
108- ONE_ACT_ERR_LOG(MergeCheckDir(validPath, mode) != SYS_OK, return SYS_ERROR,108+ return SYS_OK;
109- "dir[%s] is invalid, pid = %d.", validPath, ToolGetPid());109+}
110- return SYS_OK;110+ 
111-}111+/**
112- 112+ * @brief : collect new log and compress to dir
113-/**113+ * @param [in] : dir directory to save log file
114- * @brief : collect new log and compress to dir114+ * @param [in] : len length of dir
115- * @param [in] : dir directory to save log file115+ * @return : MERGE_SUCCESS: success;
116- * @param [in] : len length of dir116+ * MERGE_ERROR: error;
117- * @return : MERGE_SUCCESS: success;117+ * MERGE_INVALID_ARGV: input invalid;
118- * MERGE_ERROR: error;118+ * MERGE_NO_PERMISSION: path no permission
119- * MERGE_INVALID_ARGV: input invalid;119+ */
120- * MERGE_NO_PERMISSION: path no permission120+int32_t DlogCollectLog(char* dir, uint32_t len)
121- */121+{
122-int32_t DlogCollectLog(char *dir, uint32_t len)122+ if ((dir == NULL) || (len == 0) || (len > PATH_MAX) || (strlen(dir) > len)) {
123-{123+ SELF_LOG_ERROR("collect failed, input args is invalid, pid = %d.", ToolGetPid());
124- if ((dir == NULL) || (len == 0) || (len > PATH_MAX) || (strlen(dir) > len)) {124+ return MERGE_INVALID_ARGV;
125- SELF_LOG_ERROR("collect failed, input args is invalid, pid = %d.", ToolGetPid());125+ }
126- return MERGE_INVALID_ARGV;126+ // get real path
127- }127+ char validPath[PATH_MAX] = {0};
128- // get real path128+ ONE_ACT_ERR_LOG(
129- char validPath[PATH_MAX] = { 0 };129+ MergeGetRealPath(dir, validPath, PATH_MAX, W_OK) != SYS_OK, return MERGE_NO_PERMISSION,
130- ONE_ACT_ERR_LOG(MergeGetRealPath(dir, validPath, PATH_MAX, W_OK) != SYS_OK, return MERGE_NO_PERMISSION,130+ "get dir real path failed, pid = %d.", ToolGetPid());
131- "get dir real path failed, pid = %d.", ToolGetPid());131+ errno_t err = strcat_s(validPath, (size_t)PATH_MAX - 1U, OUTPUT_GZ_LOG_FILE);
132- errno_t err = strcat_s(validPath, (size_t)PATH_MAX - 1U, OUTPUT_GZ_LOG_FILE);132+ if (err != EOK) {
133- if (err != EOK) {133+ SELF_LOG_ERROR(
134- SELF_LOG_ERROR("make log path failed, ret = %d, errno = %d, pid = %d.",134+ "make log path failed, ret = %d, errno = %d, pid = %d.", (int32_t)err, ToolGetErrorCode(), ToolGetPid());
135- (int32_t)err, ToolGetErrorCode(), ToolGetPid());135+ return MERGE_ERROR;
136- return MERGE_ERROR;136+ }
137- }137+ 
138- 138+ // open iam service
139- // open iam service139+ int32_t fd = INVALID;
140- int32_t fd = INVALID;140+ ONE_ACT_ERR_LOG(
141- ONE_ACT_ERR_LOG(MergeOpenIamService(&fd) != SYS_OK, return MERGE_ERROR,141+ MergeOpenIamService(&fd) != SYS_OK, return MERGE_ERROR, "open iam service failed, errno = %d, pid = %d.",
142- "open iam service failed, errno = %d, pid = %d.", ToolGetErrorCode(), ToolGetPid());142+ ToolGetErrorCode(), ToolGetPid());
143- SELF_LOG_INFO("open iam service succeed, pid = %d.", ToolGetPid());143+ SELF_LOG_INFO("open iam service succeed, pid = %d.", ToolGetPid());
144- struct IAMIoctlArg arg;144+ struct IAMIoctlArg arg;
145- arg.size = PATH_MAX;145+ arg.size = PATH_MAX;
146- arg.argData = (void *)validPath;146+ arg.argData = (void*)validPath;
147- int32_t ret = MergeIoctlCollect(fd, &arg, IAM_CMD_COLLECT_LOG);147+ int32_t ret = MergeIoctlCollect(fd, &arg, IAM_CMD_COLLECT_LOG);
148- if (ret != SYS_OK) {148+ if (ret != SYS_OK) {
149- SELF_LOG_ERROR("iam service ioctl failed, ret = %d, errno = %d, pid = %d.",149+ SELF_LOG_ERROR(
150- ret, ToolGetErrorCode(), ToolGetPid());150+ "iam service ioctl failed, ret = %d, errno = %d, pid = %d.", ret, ToolGetErrorCode(), ToolGetPid());
151- (void)close(fd);151+ (void)close(fd);
152- return MERGE_ERROR;152+ return MERGE_ERROR;
153- }153+ }
154- SELF_LOG_INFO("iam service ioctl collect succeed, pid = %d.", ToolGetPid());154+ SELF_LOG_INFO("iam service ioctl collect succeed, pid = %d.", ToolGetPid());
155- (void)close(fd);155+ (void)close(fd);
156- return MERGE_SUCCESS;156+ return MERGE_SUCCESS;
157-}157+}
158- 158+ 
159-/**159+/**
160- * @brief : check if new log file exist160+ * @brief : check if new log file exist
161- * @param [in] : dir directory to save log file161+ * @param [in] : dir directory to save log file
162- * @param [in] : len length of dir162+ * @param [in] : len length of dir
163- * @return : MERGE_SUCCESS: success;163+ * @return : MERGE_SUCCESS: success;
164- * MERGE_ERROR: error;164+ * MERGE_ERROR: error;
165- * MERGE_NOT_FOUND: not found;165+ * MERGE_NOT_FOUND: not found;
166- * MERGE_INVALID_ARGV: input invalid;166+ * MERGE_INVALID_ARGV: input invalid;
167- * MERGE_NO_PERMISSION: path no permission167+ * MERGE_NO_PERMISSION: path no permission
168- */168+ */
169-int32_t DlogCheckCollectStatus(char *dir, uint32_t len)169+int32_t DlogCheckCollectStatus(char* dir, uint32_t len)
170-{170+{
171- if ((dir == NULL) || (len == 0) || (len > PATH_MAX) || (strlen(dir) > len)) {171+ if ((dir == NULL) || (len == 0) || (len > PATH_MAX) || (strlen(dir) > len)) {
172- SELF_LOG_ERROR("check failed, input args is invalid, pid = %d.", ToolGetPid());172+ SELF_LOG_ERROR("check failed, input args is invalid, pid = %d.", ToolGetPid());
173- return MERGE_INVALID_ARGV;173+ return MERGE_INVALID_ARGV;
174- }174+ }
175- // get real path175+ // get real path
176- char validPath[PATH_MAX] = { 0 };176+ char validPath[PATH_MAX] = {0};
177- ONE_ACT_ERR_LOG(MergeGetRealPath(dir, validPath, PATH_MAX, R_OK) != SYS_OK, return MERGE_NO_PERMISSION,177+ ONE_ACT_ERR_LOG(
178- "get dir real path failed, pid = %d.", ToolGetPid());178+ MergeGetRealPath(dir, validPath, PATH_MAX, R_OK) != SYS_OK, return MERGE_NO_PERMISSION,
179- errno_t err = strcat_s(validPath, (size_t)PATH_MAX - 1U, OUTPUT_GZ_LOG_FILE);179+ "get dir real path failed, pid = %d.", ToolGetPid());
180- if (err != EOK) {180+ errno_t err = strcat_s(validPath, (size_t)PATH_MAX - 1U, OUTPUT_GZ_LOG_FILE);
181- SELF_LOG_ERROR("make log path failed, ret = %d, errno = %d, pid = %d.",181+ if (err != EOK) {
182- (int32_t)err, ToolGetErrorCode(), ToolGetPid());182+ SELF_LOG_ERROR(
183- return MERGE_ERROR;183+ "make log path failed, ret = %d, errno = %d, pid = %d.", (int32_t)err, ToolGetErrorCode(), ToolGetPid());
184- }184+ return MERGE_ERROR;
185- int32_t ret = ToolAccess(validPath);185+ }
186- if (ret != 0) {186+ int32_t ret = ToolAccess(validPath);
187- return MERGE_NOT_FOUND;187+ if (ret != 0) {
188- }188+ return MERGE_NOT_FOUND;
189- return MERGE_SUCCESS;189+ }
190-}190+ return MERGE_SUCCESS;
191- 191+}
192-/**192+ 
193- * @brief : get group log name pattern's num193+/**
194- * @return : group log nums194+ * @brief : get group log name pattern's num
195- */195+ * @return : group log nums
196-STATIC uint32_t DlogGetGroupFilePatternsNum(const LogConfigInfo *info)196+ */
197-{197+STATIC uint32_t DlogGetGroupFilePatternsNum(const LogConfigInfo* info)
198- int32_t num = 0;198+{
199- for (; num < GROUP_MAP_SIZE; num++) {199+ int32_t num = 0;
200- if (strlen(info->groupName[num]) == 0U) {200+ for (; num < GROUP_MAP_SIZE; num++) {
201- break;201+ if (strlen(info->groupName[num]) == 0U) {
202- }202+ break;
203- }203+ }
204- return (uint32_t)num;204+ }
205-}205+ return (uint32_t)num;
206- 206+}
207-/**207+ 
208- * @brief : construct log name patterns208+/**
209- * @param [out] : pattern log name patterns209+ * @brief : construct log name patterns
210- * @param [in/out] : num log index210+ * @param [out] : pattern log name patterns
211- * @param [in] : path log path pattern211+ * @param [in/out] : num log index
212- */212+ * @param [in] : path log path pattern
213-STATIC void DlogConstructPatterns(struct DlogPattern *pattern, int32_t *num, LogPathPattern *path)213+ */
214-{214+STATIC void DlogConstructPatterns(struct DlogPattern* pattern, int32_t* num, LogPathPattern* path)
215- int32_t ret, retActive, retRotate;215+{
216- ret = snprintf_s(pattern[*num].path, PATH_MAX, (size_t)PATH_MAX - 1U, "%s/%s/",216+ int32_t ret, retActive, retRotate;
217- path->path, path->dirName);217+ ret = snprintf_s(pattern[*num].path, PATH_MAX, (size_t)PATH_MAX - 1U, "%s/%s/", path->path, path->dirName);
218- retActive = snprintf_s(pattern[*num].active, NAME_MAX, (size_t)NAME_MAX - 1U, "%s%s",218+ retActive =
219- path->fileName, path->activeSuffix);219+ snprintf_s(pattern[*num].active, NAME_MAX, (size_t)NAME_MAX - 1U, "%s%s", path->fileName, path->activeSuffix);
220- retRotate = snprintf_s(pattern[*num].rotate, NAME_MAX, (size_t)NAME_MAX - 1U, "%s%s",220+ retRotate =
221- path->fileName, path->rotateSuffix);221+ snprintf_s(pattern[*num].rotate, NAME_MAX, (size_t)NAME_MAX - 1U, "%s%s", path->fileName, path->rotateSuffix);
222- if ((ret != -1) && (retActive != -1) && (retRotate != -1)) {222+ if ((ret != -1) && (retActive != -1) && (retRotate != -1)) {
223- (*num)++;223+ (*num)++;
224- } else {224+ } else {
225- SELF_LOG_ERROR("snprintf failed, construct log dir[%s/%s] failed, pid = %d.",225+ SELF_LOG_ERROR(
226- path->dirName, path->fileName, ToolGetPid());226+ "snprintf failed, construct log dir[%s/%s] failed, pid = %d.", path->dirName, path->fileName, ToolGetPid());
227- (void)memset_s(&(pattern[*num]), sizeof(struct DlogPattern), 0, sizeof(struct DlogPattern));227+ (void)memset_s(&(pattern[*num]), sizeof(struct DlogPattern), 0, sizeof(struct DlogPattern));
228- }228+ }
229-}229+}
230- 230+ 
231-/**231+/**
232- * @brief : get group log name patterns232+ * @brief : get group log name patterns
233- * @param [out] : pattern log name patterns233+ * @param [out] : pattern log name patterns
234- * @param [in/out] : num log index234+ * @param [in/out] : num log index
235- * @param [in] : rootPath log root path235+ * @param [in] : rootPath log root path
236- */236+ */
237-STATIC void DlogGetGroupLogPatterns(struct DlogPattern *pattern, int32_t *num,237+STATIC void DlogGetGroupLogPatterns(
238- LogPathPattern *pathPattern, const LogConfigInfo *info)238+ struct DlogPattern* pattern, int32_t* num, LogPathPattern* pathPattern, const LogConfigInfo* info)
239-{239+{
240- (void)memset_s(pathPattern->path, PATH_MAX, 0, PATH_MAX);240+ (void)memset_s(pathPattern->path, PATH_MAX, 0, PATH_MAX);
241- errno_t err = strncpy_s(pathPattern->path, PATH_MAX, info->groupPath, PATH_MAX);241+ errno_t err = strncpy_s(pathPattern->path, PATH_MAX, info->groupPath, PATH_MAX);
242- if (err != EOK) {242+ if (err != EOK) {
243- SELF_LOG_ERROR("strncpy_s failed, get group path failed, path = %s.", info->groupPath);243+ SELF_LOG_ERROR("strncpy_s failed, get group path failed, path = %s.", info->groupPath);
244- return;244+ return;
245- }245+ }
246- for (int32_t groupId = 0; groupId < GROUP_MAP_SIZE; groupId++) {246+ for (int32_t groupId = 0; groupId < GROUP_MAP_SIZE; groupId++) {
247- if (strlen(info->groupName[groupId]) == 0U) {247+ if (strlen(info->groupName[groupId]) == 0U) {
248- break;248+ break;
249- }249+ }
250- (void)memset_s(pathPattern->dirName, NAME_MAX, 0, NAME_MAX);250+ (void)memset_s(pathPattern->dirName, NAME_MAX, 0, NAME_MAX);
251- (void)memset_s(pathPattern->fileName, NAME_MAX, 0, NAME_MAX);251+ (void)memset_s(pathPattern->fileName, NAME_MAX, 0, NAME_MAX);
252- // device-0 has different directory suructure252+ // device-0 has different directory suructure
253- if (strncmp(info->groupName[groupId], "device-0", strlen(info->groupName[groupId])) == 0) {253+ if (strncmp(info->groupName[groupId], "device-0", strlen(info->groupName[groupId])) == 0) {
254- int32_t ret = snprintf_s(pathPattern->dirName, NAME_MAX, (size_t)NAME_MAX - 1U, "%s/%s",254+ int32_t ret = snprintf_s(
255- DEBUG_DIR_NAME, info->groupName[groupId]);255+ pathPattern->dirName, NAME_MAX, (size_t)NAME_MAX - 1U, "%s/%s", DEBUG_DIR_NAME,
256- if (ret == -1) {256+ info->groupName[groupId]);
257- SELF_LOG_ERROR("snprintf failed, construct dirName[%s/%s] failed, pid = %d.",257+ if (ret == -1) {
258- DEBUG_DIR_NAME, info->groupName[groupId], ToolGetPid());258+ SELF_LOG_ERROR(
259- continue;259+ "snprintf failed, construct dirName[%s/%s] failed, pid = %d.", DEBUG_DIR_NAME,
260- }260+ info->groupName[groupId], ToolGetPid());
261- } else {261+ continue;
262- int32_t ret = snprintf_s(pathPattern->dirName, NAME_MAX, (size_t)NAME_MAX - 1U, "%s", DEBUG_DIR_NAME);262+ }
263- if (ret == -1) {263+ } else {
264- SELF_LOG_ERROR("snprintf failed, construct dirName[%s] failed, pid = %d.",264+ int32_t ret = snprintf_s(pathPattern->dirName, NAME_MAX, (size_t)NAME_MAX - 1U, "%s", DEBUG_DIR_NAME);
265- DEBUG_DIR_NAME, ToolGetPid());265+ if (ret == -1) {
266- continue;266+ SELF_LOG_ERROR(
267- }267+ "snprintf failed, construct dirName[%s] failed, pid = %d.", DEBUG_DIR_NAME, ToolGetPid());
268- }268+ continue;
269- err = memcpy_s(pathPattern->fileName, NAME_MAX, info->groupName[groupId], NAME_MAX);269+ }
270- if (err != EOK) {270+ }
271- SELF_LOG_ERROR("memcpy failed, get group filename failed, filename = %s, pid = %d.",271+ err = memcpy_s(pathPattern->fileName, NAME_MAX, info->groupName[groupId], NAME_MAX);
272- info->groupName[groupId], ToolGetPid());272+ if (err != EOK) {
273- }273+ SELF_LOG_ERROR(
274- 274+ "memcpy failed, get group filename failed, filename = %s, pid = %d.", info->groupName[groupId],
275- DlogConstructPatterns(pattern, num, pathPattern);275+ ToolGetPid());
276- }276+ }
277-}277+ 
278- 278+ DlogConstructPatterns(pattern, num, pathPattern);
279-/**279+ }
280- * @brief : get general log name patterns280+}
281- * @param [out] : pattern log name patterns281+ 
282- * @param [in/out] : num log index282+/**
283- * @param [in] : rootPath log root path283+ * @brief : get general log name patterns
284- */284+ * @param [out] : pattern log name patterns
285-STATIC void DlogGetGeneralLogPatterns(struct DlogPattern *pattern, int32_t *num,285+ * @param [in/out] : num log index
286- LogPathPattern *pathPattern, const LogConfigInfo *info)286+ * @param [in] : rootPath log root path
287-{287+ */
288- (void)memset_s(pathPattern->path, PATH_MAX, 0, PATH_MAX);288+STATIC void DlogGetGeneralLogPatterns(
289- errno_t err = strncpy_s(pathPattern->path, PATH_MAX, info->rootPath, PATH_MAX);289+ struct DlogPattern* pattern, int32_t* num, LogPathPattern* pathPattern, const LogConfigInfo* info)
290- if (err != EOK) {290+{
291- SELF_LOG_ERROR("strncpy_s failed, get group path failed, path = %s.", info->rootPath);291+ (void)memset_s(pathPattern->path, PATH_MAX, 0, PATH_MAX);
292- return;292+ errno_t err = strncpy_s(pathPattern->path, PATH_MAX, info->rootPath, PATH_MAX);
293- }293+ if (err != EOK) {
294- char *sortDirName[(int32_t)LOG_TYPE_NUM] = { DEBUG_DIR_NAME, SECURITY_DIR_NAME, RUN_DIR_NAME };294+ SELF_LOG_ERROR("strncpy_s failed, get group path failed, path = %s.", info->rootPath);
295- const char *logDir[GENERAL_LOG_NUM] = { DEVICE_OS_HEAD, DEVICE_APP_HEAD, AOS_CORE_DEVICE_APP_HEAD };295+ return;
296- const char *logName[GENERAL_LOG_NUM] = { DEVICE_OS_HEAD, DEVICE_APP_HEAD, AOS_CORE_DEVICE_APP_HEAD };296+ }
297- for (uint32_t type = (uint32_t)DEBUG_LOG; type < (uint32_t)LOG_TYPE_NUM; type++) {297+ char* sortDirName[(int32_t)LOG_TYPE_NUM] = {DEBUG_DIR_NAME, SECURITY_DIR_NAME, RUN_DIR_NAME};
298- for (uint32_t i = 0; i < GENERAL_LOG_NUM; i++) {298+ const char* logDir[GENERAL_LOG_NUM] = {DEVICE_OS_HEAD, DEVICE_APP_HEAD, AOS_CORE_DEVICE_APP_HEAD};
299- (void)memset_s(pathPattern->dirName, NAME_MAX, 0, NAME_MAX);299+ const char* logName[GENERAL_LOG_NUM] = {DEVICE_OS_HEAD, DEVICE_APP_HEAD, AOS_CORE_DEVICE_APP_HEAD};
300- int32_t ret = snprintf_s(pathPattern->dirName, NAME_MAX, (size_t)NAME_MAX - 1U, "%s/%s*",300+ for (uint32_t type = (uint32_t)DEBUG_LOG; type < (uint32_t)LOG_TYPE_NUM; type++) {
301- sortDirName[type], logDir[i]);301+ for (uint32_t i = 0; i < GENERAL_LOG_NUM; i++) {
302- if (ret == -1) {302+ (void)memset_s(pathPattern->dirName, NAME_MAX, 0, NAME_MAX);
303- SELF_LOG_ERROR("snprintf failed, construct dirName[%s/%s] failed, pid = %d.",303+ int32_t ret = snprintf_s(
304- sortDirName[type], logDir[i], ToolGetPid());304+ pathPattern->dirName, NAME_MAX, (size_t)NAME_MAX - 1U, "%s/%s*", sortDirName[type], logDir[i]);
305- continue;305+ if (ret == -1) {
306- }306+ SELF_LOG_ERROR(
307- (void)memset_s(pathPattern->fileName, NAME_MAX, 0, NAME_MAX);307+ "snprintf failed, construct dirName[%s/%s] failed, pid = %d.", sortDirName[type], logDir[i],
308- err = memcpy_s(pathPattern->fileName, (size_t)NAME_MAX - 1U, logName[i], strlen(logName[i]));308+ ToolGetPid());
309- if (err != EOK) {309+ continue;
310- SELF_LOG_ERROR("memcpy failed, get filename failed, filename = %s, pid = %d.",310+ }
311- logName[i], ToolGetPid());311+ (void)memset_s(pathPattern->fileName, NAME_MAX, 0, NAME_MAX);
312- }312+ err = memcpy_s(pathPattern->fileName, (size_t)NAME_MAX - 1U, logName[i], strlen(logName[i]));
313- DlogConstructPatterns(pattern, num, pathPattern);313+ if (err != EOK) {
314- }314+ SELF_LOG_ERROR(
315- }315+ "memcpy failed, get filename failed, filename = %s, pid = %d.", logName[i], ToolGetPid());
316-}316+ }
317- 317+ DlogConstructPatterns(pattern, num, pathPattern);
318-/**318+ }
319- * @brief : get event log name patterns319+ }
320- * @param [out] : pattern log name patterns320+}
321- * @param [in/out] : num log index321+ 
322- * @param [in] : rootPath log root path322+/**
323- */323+ * @brief : get event log name patterns
324-STATIC void DlogGetEventLogPatterns(struct DlogPattern *pattern, int32_t *num,324+ * @param [out] : pattern log name patterns
325- LogPathPattern *pathPattern, const LogConfigInfo *info)325+ * @param [in/out] : num log index
326-{326+ * @param [in] : rootPath log root path
327- (void)memset_s(pathPattern->path, PATH_MAX, 0, PATH_MAX);327+ */
328- errno_t err = strncpy_s(pathPattern->path, PATH_MAX, info->rootPath, PATH_MAX);328+STATIC void DlogGetEventLogPatterns(
329- if (err != EOK) {329+ struct DlogPattern* pattern, int32_t* num, LogPathPattern* pathPattern, const LogConfigInfo* info)
330- SELF_LOG_ERROR("strncpy_s failed, get group path failed, path = %s.", info->rootPath);330+{
331- return;331+ (void)memset_s(pathPattern->path, PATH_MAX, 0, PATH_MAX);
332- }332+ errno_t err = strncpy_s(pathPattern->path, PATH_MAX, info->rootPath, PATH_MAX);
333- (void)memset_s(pathPattern->dirName, NAME_MAX, 0, NAME_MAX);333+ if (err != EOK) {
334- int32_t ret = snprintf_s(pathPattern->dirName, NAME_MAX, (size_t)NAME_MAX - 1U, "%s/%s",334+ SELF_LOG_ERROR("strncpy_s failed, get group path failed, path = %s.", info->rootPath);
335- RUN_DIR_NAME, EVENT_DIR_NAME);335+ return;
336- if (ret == -1) {336+ }
337- SELF_LOG_ERROR("snprintf failed, construct dirName[%s/%s] failed, pid = %d.",337+ (void)memset_s(pathPattern->dirName, NAME_MAX, 0, NAME_MAX);
338- RUN_DIR_NAME, EVENT_DIR_NAME, ToolGetPid());338+ int32_t ret =
339- }339+ snprintf_s(pathPattern->dirName, NAME_MAX, (size_t)NAME_MAX - 1U, "%s/%s", RUN_DIR_NAME, EVENT_DIR_NAME);
340- (void)memset_s(pathPattern->fileName, NAME_MAX, 0, NAME_MAX);340+ if (ret == -1) {
341- err = memcpy_s(pathPattern->fileName, (size_t)NAME_MAX - 1U, EVENT_HEAD, strlen(EVENT_HEAD));341+ SELF_LOG_ERROR(
342- if (err != EOK) {342+ "snprintf failed, construct dirName[%s/%s] failed, pid = %d.", RUN_DIR_NAME, EVENT_DIR_NAME, ToolGetPid());
343- SELF_LOG_ERROR("memcpy failed, get filename failed, filename = %s, pid = %d.",343+ }
344- EVENT_HEAD, ToolGetPid());344+ (void)memset_s(pathPattern->fileName, NAME_MAX, 0, NAME_MAX);
345- }345+ err = memcpy_s(pathPattern->fileName, (size_t)NAME_MAX - 1U, EVENT_HEAD, strlen(EVENT_HEAD));
346- DlogConstructPatterns(pattern, num, pathPattern);346+ if (err != EOK) {
347-}347+ SELF_LOG_ERROR("memcpy failed, get filename failed, filename = %s, pid = %d.", EVENT_HEAD, ToolGetPid());
348- 348+ }
349-/**349+ DlogConstructPatterns(pattern, num, pathPattern);
350- * @brief : get self log name patterns350+}
351- * @param [out] : pattern log name patterns351+ 
352- * @param [in/out] : num log index352+/**
353- * @param [in] : rootPath log root path353+ * @brief : get self log name patterns
354- */354+ * @param [out] : pattern log name patterns
355-STATIC void DlogGetSelfLogPatterns(struct DlogPattern *pattern, int32_t *num, const char *rootPath, uint32_t pathLen)355+ * @param [in/out] : num log index
356-{356+ * @param [in] : rootPath log root path
357- (void)pathLen;357+ */
358- int32_t ret = snprintf_s(pattern[*num].path, PATH_MAX, (size_t)PATH_MAX - 1U,358+STATIC void DlogGetSelfLogPatterns(struct DlogPattern* pattern, int32_t* num, const char* rootPath, uint32_t pathLen)
359- "%s%s/", rootPath, LOG_DIR_FOR_SELF_LOG);359+{
360- int32_t retActive = snprintf_s(pattern[*num].active, NAME_MAX, (size_t)NAME_MAX - 1U, "slogdlog");360+ (void)pathLen;
361- int32_t retRotate = snprintf_s(pattern[*num].rotate, NAME_MAX, (size_t)NAME_MAX - 1U, "slogdlog.old");361+ int32_t ret =
362- if ((ret != -1) && (retActive != -1) && (retRotate != -1)) {362+ snprintf_s(pattern[*num].path, PATH_MAX, (size_t)PATH_MAX - 1U, "%s%s/", rootPath, LOG_DIR_FOR_SELF_LOG);
363- (*num)++;363+ int32_t retActive = snprintf_s(pattern[*num].active, NAME_MAX, (size_t)NAME_MAX - 1U, "slogdlog");
364- } else {364+ int32_t retRotate = snprintf_s(pattern[*num].rotate, NAME_MAX, (size_t)NAME_MAX - 1U, "slogdlog.old");
365- SELF_LOG_ERROR("snprintf failed, construct log dir[slogd] failed, pid = %d.", ToolGetPid());365+ if ((ret != -1) && (retActive != -1) && (retRotate != -1)) {
366- (void)memset_s(&(pattern[*num]), sizeof(struct DlogPattern), 0, sizeof(struct DlogPattern));366+ (*num)++;
367- }367+ } else {
368-}368+ SELF_LOG_ERROR("snprintf failed, construct log dir[slogd] failed, pid = %d.", ToolGetPid());
369- 369+ (void)memset_s(&(pattern[*num]), sizeof(struct DlogPattern), 0, sizeof(struct DlogPattern));
370-/**370+ }
371- * @brief : get log name patterns371+}
372- * @param [out] : logs log name patterns372+ 
373- * @param [in] : info log config info373+/**
374- * @return : MERGE_SUCCESS: success; MERGE_ERROR: failed374+ * @brief : get log name patterns
375- */375+ * @param [out] : logs log name patterns
376-STATIC int32_t DlogGetAllLogPatterns(struct DlogNamePatterns *logs, const LogConfigInfo *info)376+ * @param [in] : info log config info
377-{377+ * @return : MERGE_SUCCESS: success; MERGE_ERROR: failed
378- int32_t logNum = 0;378+ */
379- LogPathPattern pathPattern;379+STATIC int32_t DlogGetAllLogPatterns(struct DlogNamePatterns* logs, const LogConfigInfo* info)
380- (void)memset_s(&pathPattern, sizeof(LogPathPattern), 0, sizeof(LogPathPattern));380+{
381- int32_t retActive = snprintf_s(pathPattern.activeSuffix, NAME_MAX, (size_t)NAME_MAX - 1U, ".*%s",381+ int32_t logNum = 0;
382- LOG_ACTIVE_FILE_GZ_SUFFIX);382+ LogPathPattern pathPattern;
383- int32_t retRotate = snprintf_s(pathPattern.rotateSuffix, NAME_MAX, (size_t)NAME_MAX - 1U, "(?!.*%s).*%s",383+ (void)memset_s(&pathPattern, sizeof(LogPathPattern), 0, sizeof(LogPathPattern));
384- LOG_ACTIVE_STR, GZIP_SUFFIX);384+ int32_t retActive =
385- if ((retActive == -1) || (retRotate == -1)) {385+ snprintf_s(pathPattern.activeSuffix, NAME_MAX, (size_t)NAME_MAX - 1U, ".*%s", LOG_ACTIVE_FILE_GZ_SUFFIX);
386- SELF_LOG_ERROR("get log patterns failed, pid = %d.", ToolGetPid());386+ int32_t retRotate = snprintf_s(
387- return MERGE_ERROR;387+ pathPattern.rotateSuffix, NAME_MAX, (size_t)NAME_MAX - 1U, "(?!.*%s).*%s", LOG_ACTIVE_STR, GZIP_SUFFIX);
388- }388+ if ((retActive == -1) || (retRotate == -1)) {
389- // group389+ SELF_LOG_ERROR("get log patterns failed, pid = %d.", ToolGetPid());
390- DlogGetGroupLogPatterns(logs->patterns, &logNum, &pathPattern, info);390+ return MERGE_ERROR;
391- // device-os + device-app + aos-core-app391+ }
392- DlogGetGeneralLogPatterns(logs->patterns, &logNum, &pathPattern, info);392+ // group
393- // event393+ DlogGetGroupLogPatterns(logs->patterns, &logNum, &pathPattern, info);
394- DlogGetEventLogPatterns(logs->patterns, &logNum, &pathPattern, info);394+ // device-os + device-app + aos-core-app
395- // slogdlog395+ DlogGetGeneralLogPatterns(logs->patterns, &logNum, &pathPattern, info);
396- DlogGetSelfLogPatterns(logs->patterns, &logNum, info->rootPath, LogStrlen(info->rootPath));396+ // event
397- return MERGE_SUCCESS;397+ DlogGetEventLogPatterns(logs->patterns, &logNum, &pathPattern, info);
398-}398+ // slogdlog
399- 399+ DlogGetSelfLogPatterns(logs->patterns, &logNum, info->rootPath, LogStrlen(info->rootPath));
400-STATIC int32_t DlogGetConfigInfo(LogConfigInfo *info)400+ return MERGE_SUCCESS;
401-{401+}
402- // open iam service402+ 
403- int32_t fd = INVALID;403+STATIC int32_t DlogGetConfigInfo(LogConfigInfo* info)
404- ONE_ACT_ERR_LOG(MergeOpenIamService(&fd) != SYS_OK, return SYS_ERROR,404+{
405- "open iam service failed, errno = %d, pid = %d.", ToolGetErrorCode(), ToolGetPid());405+ // open iam service
406- SELF_LOG_INFO("open iam service succeed, pid = %d.", ToolGetPid());406+ int32_t fd = INVALID;
407- struct IAMIoctlArg arg;407+ ONE_ACT_ERR_LOG(
408- arg.size = sizeof(LogConfigInfo);408+ MergeOpenIamService(&fd) != SYS_OK, return SYS_ERROR, "open iam service failed, errno = %d, pid = %d.",
409- arg.argData = (void *)info;409+ ToolGetErrorCode(), ToolGetPid());
410- int32_t ret = MergeIoctlCollect(fd, &arg, IAM_CMD_COLLECT_LOG_PATTERN);410+ SELF_LOG_INFO("open iam service succeed, pid = %d.", ToolGetPid());
411- if (ret != SYS_OK) {411+ struct IAMIoctlArg arg;
412- SELF_LOG_ERROR("iam service ioctl failed, ret = %d, errno = %d, pid = %d.",412+ arg.size = sizeof(LogConfigInfo);
413- ret, ToolGetErrorCode(), ToolGetPid());413+ arg.argData = (void*)info;
414- (void)close(fd);414+ int32_t ret = MergeIoctlCollect(fd, &arg, IAM_CMD_COLLECT_LOG_PATTERN);
415- return SYS_ERROR;415+ if (ret != SYS_OK) {
416- }416+ SELF_LOG_ERROR(
417- SELF_LOG_INFO("iam service ioctl collect succeed, pid = %d.", ToolGetPid());417+ "iam service ioctl failed, ret = %d, errno = %d, pid = %d.", ret, ToolGetErrorCode(), ToolGetPid());
418- (void)close(fd);418+ (void)close(fd);
419- LogStrTrimEnd(info->rootPath, PATH_MAX);419+ return SYS_ERROR;
420- LogStrTrimEnd(info->groupPath, PATH_MAX);420+ }
421- return SYS_OK;421+ SELF_LOG_INFO("iam service ioctl collect succeed, pid = %d.", ToolGetPid());
422-}422+ (void)close(fd);
423- 423+ LogStrTrimEnd(info->rootPath, PATH_MAX);
424-/**424+ LogStrTrimEnd(info->groupPath, PATH_MAX);
425- * @brief : get hisi log configuration log name patterns, free patterns dynamic buffer by caller is required425+ return SYS_OK;
426- * @param [out] : logs log name patterns426+}
427- * @return : 0: success; others: failed427+ 
428- */428+/**
429-int32_t DlogGetLogPatterns(struct DlogNamePatterns *logs)429+ * @brief : get hisi log configuration log name patterns, free patterns dynamic buffer by caller is required
430-{430+ * @param [out] : logs log name patterns
431- ONE_ACT_ERR_LOG(logs == NULL, return MERGE_INVALID_ARGV, "input logs is null, pid = %d.", ToolGetPid());431+ * @return : 0: success; others: failed
432- // get config file432+ */
433- LogConfigInfo *info = (LogConfigInfo *)LogMalloc(sizeof(LogConfigInfo));433+int32_t DlogGetLogPatterns(struct DlogNamePatterns* logs)
434- ONE_ACT_ERR_LOG(info == NULL, return MERGE_ERROR,434+{
435- "malloc log config info failed, errno = %d, pid = %d.", ToolGetErrorCode(), ToolGetPid());435+ ONE_ACT_ERR_LOG(logs == NULL, return MERGE_INVALID_ARGV, "input logs is null, pid = %d.", ToolGetPid());
436- int32_t ret = DlogGetConfigInfo(info);436+ // get config file
437- TWO_ACT_ERR_LOG(ret != SYS_OK, LogFree(info), return MERGE_ERROR,437+ LogConfigInfo* info = (LogConfigInfo*)LogMalloc(sizeof(LogConfigInfo));
438- "get log config info failed, pid = %d.", ToolGetPid());438+ ONE_ACT_ERR_LOG(
439- 439+ info == NULL, return MERGE_ERROR, "malloc log config info failed, errno = %d, pid = %d.", ToolGetErrorCode(),
440- // construct log patterns440+ ToolGetPid());
441- // get log num, GROUP + (genenal log) * LOG_TYPE_NUM + event + slogdlog441+ int32_t ret = DlogGetConfigInfo(info);
442- logs->logNum = DlogGetGroupFilePatternsNum(info) + GENERAL_LOG_NUM * (uint32_t)LOG_TYPE_NUM + 1U + 1U;442+ TWO_ACT_ERR_LOG(
443- logs->patterns = (struct DlogPattern *)LogMalloc(sizeof(struct DlogPattern) * logs->logNum);443+ ret != SYS_OK, LogFree(info), return MERGE_ERROR, "get log config info failed, pid = %d.", ToolGetPid());
444- TWO_ACT_ERR_LOG(logs->patterns == NULL, LogFree(info), return MERGE_ERROR,444+ 
445- "malloc log patterns failed, errno = %d, pid = %d.", ToolGetErrorCode(), ToolGetPid());445+ // construct log patterns
446- ret = DlogGetAllLogPatterns(logs, info);446+ // get log num, GROUP + (genenal log) * LOG_TYPE_NUM + event + slogdlog
447- LogFree(info);447+ logs->logNum = DlogGetGroupFilePatternsNum(info) + GENERAL_LOG_NUM * (uint32_t)LOG_TYPE_NUM + 1U + 1U;
448- return ret;448+ logs->patterns = (struct DlogPattern*)LogMalloc(sizeof(struct DlogPattern) * logs->logNum);
449-}449+ TWO_ACT_ERR_LOG(
450+ logs->patterns == NULL, LogFree(info), return MERGE_ERROR, "malloc log patterns failed, errno = %d, pid = %d.",
451+ ToolGetErrorCode(), ToolGetPid());
452+ ret = DlogGetAllLogPatterns(logs, info);
453+ LogFree(info);
454+ return ret;
455+}
@@ -1,65 +1,65 @@
1-/**1+/**
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10-#ifndef MERGESLOG_H10+#ifndef MERGESLOG_H
11-#define MERGESLOG_H11+#define MERGESLOG_H
12- 12+ 
13-#include <limits.h>13+#include <limits.h>
14-#include <stdint.h>14+#include <stdint.h>
15- 15+ 
16-#ifdef __cplusplus16+#ifdef __cplusplus
17-extern "C" {17+extern "C" {
18-#endif // __cplusplus18+#endif // __cplusplus
19- 19+ 
20-#define MERGE_SUCCESS 020+#define MERGE_SUCCESS 0
21-#define MERGE_NOT_FOUND (-1) /* file not found */21+#define MERGE_NOT_FOUND (-1) /* file not found */
22-#define MERGE_ERROR (-2)22+#define MERGE_ERROR (-2)
23-#define MERGE_INVALID_ARGV (-3) /* input argv is null */23+#define MERGE_INVALID_ARGV (-3) /* input argv is null */
24-#define MERGE_NO_PERMISSION (-4) /* input path no permission */24+#define MERGE_NO_PERMISSION (-4) /* input path no permission */
25- 25+ 
26-struct DlogPattern {26+struct DlogPattern {
27- char active[NAME_MAX]; // current logging file name, for example: DRV*.log27+ char active[NAME_MAX]; // current logging file name, for example: DRV*.log
28- char rotate[NAME_MAX]; // rotate log file name pattern, for example: DRV*.gz28+ char rotate[NAME_MAX]; // rotate log file name pattern, for example: DRV*.gz
29- char path[PATH_MAX]; // realpath to collect.29+ char path[PATH_MAX]; // realpath to collect.
30-};30+};
31- 31+ 
32-struct DlogNamePatterns {32+struct DlogNamePatterns {
33- uint32_t logNum; // num of logs name pattern.33+ uint32_t logNum; // num of logs name pattern.
34- struct DlogPattern *patterns; // patterns info, dynamic buffer.34+ struct DlogPattern* patterns; // patterns info, dynamic buffer.
35-};35+};
36- 36+ 
37-#define DLL_EXPORT __attribute__((visibility("default")))37+#define DLL_EXPORT __attribute__((visibility("default")))
38- 38+ 
39-/**39+/**
40- * @brief : collect new log and compress to dir40+ * @brief : collect new log and compress to dir
41- * @param [in] : dir directory to save log file41+ * @param [in] : dir directory to save log file
42- * @param [in] : len length of dir42+ * @param [in] : len length of dir
43- * @return : 0: success; -2: error; -3: input invalid; -4: path no permission43+ * @return : 0: success; -2: error; -3: input invalid; -4: path no permission
44- */44+ */
45-DLL_EXPORT int32_t DlogCollectLog(char *dir, uint32_t len);45+DLL_EXPORT int32_t DlogCollectLog(char* dir, uint32_t len);
46- 46+ 
47-/**47+/**
48- * @brief : check if new log file exist48+ * @brief : check if new log file exist
49- * @param [in] : dir directory to save log file49+ * @param [in] : dir directory to save log file
50- * @param [in] : len length of dir50+ * @param [in] : len length of dir
51- * @return : 0: success; -1: not found; -2: error; -3: input invalid; -4: path no permission51+ * @return : 0: success; -1: not found; -2: error; -3: input invalid; -4: path no permission
52- */52+ */
53-DLL_EXPORT int32_t DlogCheckCollectStatus(char *dir, uint32_t len);53+DLL_EXPORT int32_t DlogCheckCollectStatus(char* dir, uint32_t len);
54- 54+ 
55-/**55+/**
56- * @brief : get hisi log configuration log name patterns, free patterns dynamic buffer by caller is required56+ * @brief : get hisi log configuration log name patterns, free patterns dynamic buffer by caller is required
57- * @param [out] : logs log name patterns57+ * @param [out] : logs log name patterns
58- * @return : 0: success; others: failed58+ * @return : 0: success; others: failed
59- */59+ */
60-DLL_EXPORT int32_t DlogGetLogPatterns(struct DlogNamePatterns *logs);60+DLL_EXPORT int32_t DlogGetLogPatterns(struct DlogNamePatterns* logs);
61- 61+ 
62-#ifdef __cplusplus62+#ifdef __cplusplus
63-}63+}
64-#endif // __cplusplus64+#endif // __cplusplus
65-#endif65+#endif
@@ -14,14 +14,11 @@
14 14 
15#define DRV_HDC_LIBRARY_NAME "libascend_hal.so"15#define DRV_HDC_LIBRARY_NAME "libascend_hal.so"
16#define DRV_GET_PLATFORM_INFO "drvGetPlatformInfo"16#define DRV_GET_PLATFORM_INFO "drvGetPlatformInfo"
17-typedef drvError_t (*DrvGetPlatformInfoFunc)(uint32_t *);17+typedef drvError_t (*DrvGetPlatformInfoFunc)(uint32_t*);
18static ArgPtr g_drvLibHandle = NULL;18static ArgPtr g_drvLibHandle = NULL;
19 19 
20#ifdef PROCESS_LOG20#ifdef PROCESS_LOG
21-int32_t AlogTryUseSlog(void)21+int32_t AlogTryUseSlog(void) { return AlogTransferToUnifiedlog(); }
22-{
23- return AlogTransferToUnifiedlog();
24-}
25#else22#else
26static bool IsAtDeviceSide(void)23static bool IsAtDeviceSide(void)
27{24{
@@ -55,7 +52,4 @@ int32_t AlogTryUseSlog(void)
55}52}
56#endif53#endif
57 54 
58-void AlogCloseDrvLib(void)55+void AlogCloseDrvLib(void) { (void)UnloadRuntimeDll(g_drvLibHandle); }
59-{
60- (void)UnloadRuntimeDll(g_drvLibHandle);
61-}
@@ -21,65 +21,67 @@
21 21 
22#ifdef __cplusplus22#ifdef __cplusplus
23extern "C" {23extern "C" {
24-#endif // __cplusplus24+#endif // __cplusplus
25 25 
26-#define LOG_TIMER_PERIOD 1000U // 1s26+#define LOG_TIMER_PERIOD 1000U // 1s
27-#define LOG_TIMER_TRIGER_COST_MAX_TIME 2U * LOG_TIMER_PERIOD * US_TO_MS27+#define LOG_TIMER_TRIGER_COST_MAX_TIME (2U * LOG_TIMER_PERIOD * US_TO_MS)
28-#define LOG_SEND_COST_MAX_TIME 150000U // 150ms28+#define LOG_SEND_COST_MAX_TIME 150000U // 150ms
29-#define LOG_LOCK_COST_MAX_TIME 50000U //50ms29+#define LOG_LOCK_COST_MAX_TIME 50000U // 50ms
30-#define LOG_LOST_PRINT_PERIOD_TIME 900000000UL // 15min30+#define LOG_LOST_PRINT_PERIOD_TIME 900000000UL // 15min
31-#define LOG_MAX_COVERED_LOSS_NUM 10000UL31+#define LOG_MAX_COVERED_LOSS_NUM 10000UL
32-#define LOG_SYNC_PERIOD 1 // unified_timer minimum period: 100ms32+#define LOG_SYNC_PERIOD 1 // unified_timer minimum period: 100ms
33-#define LOG_BUF_NUM 4U33+#define LOG_BUF_NUM 4U
34 34 
35-#define LOG_MONITOR_TIME_OUT_PRINT(cost, threshold, format, ...) \35+#define LOG_MONITOR_TIME_OUT_PRINT(cost, threshold, format, ...) \
36- NO_ACT_WARN_LOG((cost) / LogGetCpuFrequency() * TICK_TO_US >= (threshold), \36+ NO_ACT_WARN_LOG( \
37- format " timeout, cost time = %llu us", ##__VA_ARGS__, (cost) / LogGetCpuFrequency() * TICK_TO_US)37+ (cost) / LogGetCpuFrequency() * TICK_TO_US >= (threshold), format " timeout, cost time = %llu us", \
38+ ##__VA_ARGS__, (cost) / LogGetCpuFrequency() * TICK_TO_US)
38 39 
39-#define LOG_MONITOR_TIME_OUT(action, threshold, format, ...) \40+#define LOG_MONITOR_TIME_OUT(action, threshold, format, ...) \
40- do { \41+ do { \
41- uint64_t start = LogGetCpuCycleCounter(); \42+ uint64_t start = LogGetCpuCycleCounter(); \
42- action; \43+ action; \
43- uint64_t end = LogGetCpuCycleCounter(); \44+ uint64_t end = LogGetCpuCycleCounter(); \
44- uint64_t cost = end - start; \45+ uint64_t cost = end - start; \
45- LOG_MONITOR_TIME_OUT_PRINT(cost, threshold, format, ##__VA_ARGS__); \46+ LOG_MONITOR_TIME_OUT_PRINT(cost, threshold, format, ##__VA_ARGS__); \
46 } while (0)47 } while (0)
47 48 
48// timer name49// timer name
49#if defined LOG_CPP || defined APP_LOG50#if defined LOG_CPP || defined APP_LOG
50-#define DLOG_TIMER_NAME "alog_send_task_timer"51+#define DLOG_TIMER_NAME "alog_send_task_timer"
51-#define DLOG_SYNC_TIMER_NAME "alog_sync_task_timer"52+#define DLOG_SYNC_TIMER_NAME "alog_sync_task_timer"
52#else53#else
53-#define DLOG_TIMER_NAME "slog_send_task_timer"54+#define DLOG_TIMER_NAME "slog_send_task_timer"
54-#define DLOG_SYNC_TIMER_NAME "slog_sync_task_timer"55+#define DLOG_SYNC_TIMER_NAME "slog_sync_task_timer"
55#endif56#endif
56 57 
57typedef struct DlogBufferMgr {58typedef struct DlogBufferMgr {
58- RingBufferStat *dlogBuf[LOG_BUF_NUM];59+ RingBufferStat* dlogBuf[LOG_BUF_NUM];
59- uint64_t lossCount; // covered log loss count60+ uint64_t lossCount; // covered log loss count
60 uint64_t lastPrintTime; // record log loss print time61 uint64_t lastPrintTime; // record log loss print time
61 uint32_t writeBufIndex; // current buffer index to write62 uint32_t writeBufIndex; // current buffer index to write
62- uint32_t sendBufIndex; // current buffer index to send63+ uint32_t sendBufIndex; // current buffer index to send
63} DlogBufferMgr;64} DlogBufferMgr;
64 65 
65typedef struct DlogLevelCtrlMgr {66typedef struct DlogLevelCtrlMgr {
66 bool ctrlSwitch;67 bool ctrlSwitch;
67 int32_t ctrlLevel;68 int32_t ctrlLevel;
68- uint64_t lossCount; // level ctrl log loss count69+ uint64_t lossCount; // level ctrl log loss count
69 struct timespec ctrlLastTv; // record level ctrl trigger time70 struct timespec ctrlLastTv; // record level ctrl trigger time
70} DlogLevelCtrlMgr;71} DlogLevelCtrlMgr;
71 72 
72typedef struct DlogNsycMgr {73typedef struct DlogNsycMgr {
73- bool initFlag; // init flag, indicates whether async module is initialized74+ bool initFlag; // init flag, indicates whether async module is initialized
74 bool syncFlag; // sync flag, indicates whether sync task is registered75 bool syncFlag; // sync flag, indicates whether sync task is registered
75 DlogBufferMgr bufMgr;76 DlogBufferMgr bufMgr;
76 ToolMutex mutex;77 ToolMutex mutex;
77 DlogLevelCtrlMgr levelCtrl; // traffic limiting mechanism level control78 DlogLevelCtrlMgr levelCtrl; // traffic limiting mechanism level control
78- int32_t himemFd; // high memory fd79+ int32_t himemFd; // high memory fd
79} DlogNsycMgr;80} DlogNsycMgr;
80 81 
81-STATIC DlogNsycMgr g_dlogAsyncMgr = {false, false, {{NULL, NULL, NULL, NULL}, 0, 0, 0, 0}, PTHREAD_MUTEX_INITIALIZER,82+STATIC DlogNsycMgr g_dlogAsyncMgr = {
82- {false, DLOG_DEBUG, 0, {0, 0}}, -1};83+ false, false, {{NULL, NULL, NULL, NULL}, 0, 0, 0, 0}, PTHREAD_MUTEX_INITIALIZER, {false, DLOG_DEBUG, 0, {0, 0}},
84+ -1};
83 85 
84/**86/**
85 * @brief : init mutex, set robust87 * @brief : init mutex, set robust
@@ -108,10 +110,7 @@ STATIC void DlogLock(void)
108 }110 }
109}111}
110 112 
111-STATIC void DlogUnLock(void)113+STATIC void DlogUnLock(void) { UNLOCK_WARN_LOG(&g_dlogAsyncMgr.mutex); }
112-{
113- UNLOCK_WARN_LOG(&g_dlogAsyncMgr.mutex);
114-}
115 114 
116/**115/**
117 * @brief : exec this function in child process after fork116 * @brief : exec this function in child process after fork
@@ -131,13 +130,13 @@ STATIC void DlogChildUnLock(void)
131 * @brief : get log num in buffer130 * @brief : get log num in buffer
132 * @return : log count131 * @return : log count
133 */132 */
134-STATIC uint64_t DlogGetBufNodeCount(RingBufferStat *ringBuffer)133+STATIC uint64_t DlogGetBufNodeCount(RingBufferStat* ringBuffer)
135{134{
136 if ((ringBuffer == NULL) || (ringBuffer->ringBufferCtrl == NULL)) {135 if ((ringBuffer == NULL) || (ringBuffer->ringBufferCtrl == NULL)) {
137 return 0;136 return 0;
138 }137 }
139 uint64_t nodeCount;138 uint64_t nodeCount;
140- RingBufferCtrl *ringBufferCtrl = ringBuffer->ringBufferCtrl;139+ RingBufferCtrl* ringBufferCtrl = ringBuffer->ringBufferCtrl;
141 if (ringBufferCtrl->logNextSeq < ringBufferCtrl->lastSeq) {140 if (ringBufferCtrl->logNextSeq < ringBufferCtrl->lastSeq) {
142 ringBufferCtrl->lastSeq = ringBufferCtrl->logNextSeq;141 ringBufferCtrl->lastSeq = ringBufferCtrl->logNextSeq;
143 nodeCount = 0;142 nodeCount = 0;
@@ -154,23 +153,26 @@ STATIC void LogCtrlDecLogic(void)
154 if (timeValue < LOG_INFO_INTERVAL) {153 if (timeValue < LOG_INFO_INTERVAL) {
155 if (g_dlogAsyncMgr.levelCtrl.ctrlLevel != DLOG_WARN) {154 if (g_dlogAsyncMgr.levelCtrl.ctrlLevel != DLOG_WARN) {
156 g_dlogAsyncMgr.levelCtrl.ctrlLevel = DLOG_WARN;155 g_dlogAsyncMgr.levelCtrl.ctrlLevel = DLOG_WARN;
157- SELF_LOG_WARN("log control down to level=WARNING, pid=%d, pid_name=%s,"156+ SELF_LOG_WARN(
158- "log level control loss num is %lu",157+ "log control down to level=WARNING, pid=%d, pid_name=%s,"
159- DlogGetCurrPid(), DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);158+ "log level control loss num is %lu",
159+ DlogGetCurrPid(), DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);
160 }160 }
161 } else if (timeValue < LOG_CTRL_TOTAL_INTERVAL) {161 } else if (timeValue < LOG_CTRL_TOTAL_INTERVAL) {
162 if (g_dlogAsyncMgr.levelCtrl.ctrlLevel != DLOG_INFO) {162 if (g_dlogAsyncMgr.levelCtrl.ctrlLevel != DLOG_INFO) {
163 g_dlogAsyncMgr.levelCtrl.ctrlLevel = DLOG_INFO;163 g_dlogAsyncMgr.levelCtrl.ctrlLevel = DLOG_INFO;
164- SELF_LOG_WARN("log control down to level=INFO, pid=%d, pid_name=%s, log level control loss num is %lu",164+ SELF_LOG_WARN(
165- DlogGetCurrPid(), DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);165+ "log control down to level=INFO, pid=%d, pid_name=%s, log level control loss num is %lu",
166+ DlogGetCurrPid(), DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);
166 }167 }
167 } else {168 } else {
168 g_dlogAsyncMgr.levelCtrl.ctrlSwitch = false;169 g_dlogAsyncMgr.levelCtrl.ctrlSwitch = false;
169 g_dlogAsyncMgr.levelCtrl.ctrlLevel = DLOG_DEBUG;170 g_dlogAsyncMgr.levelCtrl.ctrlLevel = DLOG_DEBUG;
170 g_dlogAsyncMgr.levelCtrl.ctrlLastTv.tv_sec = 0;171 g_dlogAsyncMgr.levelCtrl.ctrlLastTv.tv_sec = 0;
171 g_dlogAsyncMgr.levelCtrl.ctrlLastTv.tv_nsec = 0;172 g_dlogAsyncMgr.levelCtrl.ctrlLastTv.tv_nsec = 0;
172- SELF_LOG_WARN("clear log control switch, pid=%d, pid_name=%s, log level control loss num is %lu",173+ SELF_LOG_WARN(
173- DlogGetCurrPid(), DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);174+ "clear log control switch, pid=%d, pid_name=%s, log level control loss num is %lu", DlogGetCurrPid(),
175+ DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);
174 g_dlogAsyncMgr.levelCtrl.lossCount = 0;176 g_dlogAsyncMgr.levelCtrl.lossCount = 0;
175 }177 }
176 }178 }
@@ -181,17 +183,20 @@ STATIC void LogCtrlIncLogic(void)
181 if (!g_dlogAsyncMgr.levelCtrl.ctrlSwitch) {183 if (!g_dlogAsyncMgr.levelCtrl.ctrlSwitch) {
182 g_dlogAsyncMgr.levelCtrl.ctrlSwitch = true;184 g_dlogAsyncMgr.levelCtrl.ctrlSwitch = true;
183 g_dlogAsyncMgr.levelCtrl.ctrlLevel = DLOG_ERROR;185 g_dlogAsyncMgr.levelCtrl.ctrlLevel = DLOG_ERROR;
184- SELF_LOG_WARN("set log control switch to level=ERROR, pid=%d, pid_name=%s, log loss num=%lu.",186+ SELF_LOG_WARN(
185- DlogGetCurrPid(), DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);187+ "set log control switch to level=ERROR, pid=%d, pid_name=%s, log loss num=%lu.", DlogGetCurrPid(),
188+ DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);
186 } else {189 } else {
187 if (g_dlogAsyncMgr.levelCtrl.ctrlLevel < DLOG_ERROR) {190 if (g_dlogAsyncMgr.levelCtrl.ctrlLevel < DLOG_ERROR) {
188 g_dlogAsyncMgr.levelCtrl.ctrlLevel++;191 g_dlogAsyncMgr.levelCtrl.ctrlLevel++;
189 if (g_dlogAsyncMgr.levelCtrl.ctrlLevel == DLOG_ERROR) {192 if (g_dlogAsyncMgr.levelCtrl.ctrlLevel == DLOG_ERROR) {
190- SELF_LOG_WARN("log control up to level=ERROR, pid=%d, pid_name=%s, log loss num=%lu.",193+ SELF_LOG_WARN(
191- DlogGetCurrPid(), DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);194+ "log control up to level=ERROR, pid=%d, pid_name=%s, log loss num=%lu.", DlogGetCurrPid(),
195+ DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);
192 } else {196 } else {
193- SELF_LOG_WARN("log control up to level=WARNING, pid=%d, pid_name=%s, log loss num=%lu.",197+ SELF_LOG_WARN(
194- DlogGetCurrPid(), DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);198+ "log control up to level=WARNING, pid=%d, pid_name=%s, log loss num=%lu.", DlogGetCurrPid(),
199+ DlogGetPidName(), g_dlogAsyncMgr.levelCtrl.lossCount);
195 }200 }
196 }201 }
197 }202 }
@@ -202,16 +207,16 @@ STATIC void LogCtrlIncLogic(void)
202 * @brief : write log from buffer to iam207 * @brief : write log from buffer to iam
203 * @return : >= 0 success; < 0 failure208 * @return : >= 0 success; < 0 failure
204 */209 */
205-STATIC int32_t DlogWriteBufToIam(RingBufferStat *ringBuffer)210+STATIC int32_t DlogWriteBufToIam(RingBufferStat* ringBuffer)
206{211{
207- return DlogIamWrite((void *)(ringBuffer->ringBufferCtrl), ringBuffer->logBufSize);212+ return DlogIamWrite((void*)(ringBuffer->ringBufferCtrl), ringBuffer->logBufSize);
208}213}
209 214 
210/**215/**
211 * @brief : write log from buffer to himem216 * @brief : write log from buffer to himem
212 * @return : >= 0 success; < 0 failure217 * @return : >= 0 success; < 0 failure
213 */218 */
214-STATIC int32_t DlogWriteBufToHiMem(RingBufferStat *ringBuffer)219+STATIC int32_t DlogWriteBufToHiMem(RingBufferStat* ringBuffer)
215{220{
216 return HiMemWriteIamLog(g_dlogAsyncMgr.himemFd, ringBuffer);221 return HiMemWriteIamLog(g_dlogAsyncMgr.himemFd, ringBuffer);
217}222}
@@ -226,20 +231,17 @@ STATIC void CountLogLoss(void)
226/**231/**
227 * @brief : reinit log buffer to 0232 * @brief : reinit log buffer to 0
228 */233 */
229-STATIC void DlogBufReInit(RingBufferStat *ringBuffer)234+STATIC void DlogBufReInit(RingBufferStat* ringBuffer) { LogBufReInit(ringBuffer); }
230-{
231- LogBufReInit(ringBuffer);
232-}
233 235 
234/**236/**
235 * @brief : if level is already sync, refresh level filter status once237 * @brief : if level is already sync, refresh level filter status once
236 */238 */
237-STATIC void DlogFilterStatus(RingBufferStat *ringBuffer)239+STATIC void DlogFilterStatus(RingBufferStat* ringBuffer)
238{240{
239 LogBufSetLevelFilter(ringBuffer->ringBufferCtrl, LEVEL_FILTER_CLOSE);241 LogBufSetLevelFilter(ringBuffer->ringBufferCtrl, LEVEL_FILTER_CLOSE);
240}242}
241 243 
242-STATIC void SafeWritesByIam(RingBufferStat *ringBuffer)244+STATIC void SafeWritesByIam(RingBufferStat* ringBuffer)
243{245{
244 int32_t n = -1;246 int32_t n = -1;
245 int32_t err = 0;247 int32_t err = 0;
@@ -268,9 +270,10 @@ STATIC void SafeWritesByIam(RingBufferStat *ringBuffer)
268 DlogFilterStatus(ringBuffer); // if level is setted, no more check270 DlogFilterStatus(ringBuffer); // if level is setted, no more check
269 DlogBufReInit(ringBuffer);271 DlogBufReInit(ringBuffer);
270 } else {272 } else {
271- SELF_LOG_WARN_N_AO(&printNum, WRITE_E_PRINT_NUM,273+ SELF_LOG_WARN_N_AO(
272- "can not write to server, print every %d times, result=%d, strerr=%s, pid=%d, pid_name=%s.",274+ &printNum, WRITE_E_PRINT_NUM,
273- WRITE_E_PRINT_NUM, n, strerror(err), DlogGetCurrPid(), DlogGetPidName());275+ "can not write to server, print every %d times, result=%d, strerr=%s, pid=%d, pid_name=%s.",
276+ WRITE_E_PRINT_NUM, n, strerror(err), DlogGetCurrPid(), DlogGetPidName());
274 if (DlogIsAosCore()) {277 if (DlogIsAosCore()) {
275 // no need to reinit buffer, to avoid log loss when slogd not ready rather than linux faults278 // no need to reinit buffer, to avoid log loss when slogd not ready rather than linux faults
276 (void)DlogWriteBufToHiMem(ringBuffer);279 (void)DlogWriteBufToHiMem(ringBuffer);
@@ -286,7 +289,7 @@ static inline void DlogModifySendBuf(uint32_t sendIdx)
286 }289 }
287}290}
288 291 
289-STATIC void DlogSyncAllSendBuf(uint32_t *sendIdx, uint32_t writeIdx)292+STATIC void DlogSyncAllSendBuf(uint32_t* sendIdx, uint32_t writeIdx)
290{293{
291 while (*sendIdx != writeIdx) {294 while (*sendIdx != writeIdx) {
292 DlogModifySendBuf(*sendIdx);295 DlogModifySendBuf(*sendIdx);
@@ -326,15 +329,17 @@ static void DlogUnifiedTimerCb(void)
326 }329 }
327 // if write buffer is not empty and service is ready, exchange buffer and send data330 // if write buffer is not empty and service is ready, exchange buffer and send data
328 uint32_t writeBufIndex = g_dlogAsyncMgr.bufMgr.writeBufIndex;331 uint32_t writeBufIndex = g_dlogAsyncMgr.bufMgr.writeBufIndex;
329- LOG_MONITOR_TIME_OUT(DlogSyncAllSendBuf(&g_dlogAsyncMgr.bufMgr.sendBufIndex, writeBufIndex), LOG_SEND_COST_MAX_TIME,332+ LOG_MONITOR_TIME_OUT(
333+ DlogSyncAllSendBuf(&g_dlogAsyncMgr.bufMgr.sendBufIndex, writeBufIndex), LOG_SEND_COST_MAX_TIME,
330 "%s send all buffer", DLOG_TIMER_NAME);334 "%s send all buffer", DLOG_TIMER_NAME);
331 335 
332 bool ret = false;336 bool ret = false;
333- LOG_MONITOR_TIME_OUT(ret = DlogCheckWriteBufModify(writeBufIndex), LOG_LOCK_COST_MAX_TIME,337+ LOG_MONITOR_TIME_OUT(
334- "%s buffer switch get lock", DLOG_TIMER_NAME);338+ ret = DlogCheckWriteBufModify(writeBufIndex), LOG_LOCK_COST_MAX_TIME, "%s buffer switch get lock",
339+ DLOG_TIMER_NAME);
335 if (ret) {340 if (ret) {
336- LOG_MONITOR_TIME_OUT(DlogModifySendBuf(writeBufIndex), LOG_SEND_COST_MAX_TIME,341+ LOG_MONITOR_TIME_OUT(
337- "%s send newest buffer", DLOG_TIMER_NAME);342+ DlogModifySendBuf(writeBufIndex), LOG_SEND_COST_MAX_TIME, "%s send newest buffer", DLOG_TIMER_NAME);
338 g_dlogAsyncMgr.bufMgr.sendBufIndex = (writeBufIndex + 1U) % LOG_BUF_NUM;343 g_dlogAsyncMgr.bufMgr.sendBufIndex = (writeBufIndex + 1U) % LOG_BUF_NUM;
339 }344 }
340 return;345 return;
@@ -353,15 +358,17 @@ static void DlogAddSyncTask(void)
353 return;358 return;
354 }359 }
355 if (DlogLoadTimerDll() != LOG_SUCCESS) {360 if (DlogLoadTimerDll() != LOG_SUCCESS) {
356- SELF_LOG_ERROR("dlog load unified_timer library failed, pid = %d, strerr = %s.",361+ SELF_LOG_ERROR(
357- ToolGetPid(), strerror(ToolGetErrorCode()));362+ "dlog load unified_timer library failed, pid = %d, strerr = %s.", ToolGetPid(),
363+ strerror(ToolGetErrorCode()));
358 (void)__sync_lock_test_and_set(&g_dlogAsyncMgr.syncFlag, false);364 (void)__sync_lock_test_and_set(&g_dlogAsyncMgr.syncFlag, false);
359 return;365 return;
360 }366 }
361 uint32_t ret = DlogAddUnifiedTimer(DLOG_SYNC_TIMER_NAME, DlogSyncUnifiedTimerCb, LOG_SYNC_PERIOD, ONESHOT_TIMER);367 uint32_t ret = DlogAddUnifiedTimer(DLOG_SYNC_TIMER_NAME, DlogSyncUnifiedTimerCb, LOG_SYNC_PERIOD, ONESHOT_TIMER);
362 if ((ret != 0) && (ret != UNIFIED_TIMER_NAME_DUPLICATE)) {368 if ((ret != 0) && (ret != UNIFIED_TIMER_NAME_DUPLICATE)) {
363- SELF_LOG_ERROR("add unified timer failed, ret = %u, errno = %d, pid = %d, timerName = %s.",369+ SELF_LOG_ERROR(
364- ret, ToolGetErrorCode(), ToolGetPid(), DLOG_SYNC_TIMER_NAME);370+ "add unified timer failed, ret = %u, errno = %d, pid = %d, timerName = %s.", ret, ToolGetErrorCode(),
371+ ToolGetPid(), DLOG_SYNC_TIMER_NAME);
365 (void)__sync_lock_test_and_set(&g_dlogAsyncMgr.syncFlag, false);372 (void)__sync_lock_test_and_set(&g_dlogAsyncMgr.syncFlag, false);
366 }373 }
367 return;374 return;
@@ -370,14 +377,16 @@ static void DlogAddSyncTask(void)
370static LogStatus DlogStartSendTask(void)377static LogStatus DlogStartSendTask(void)
371{378{
372 if (DlogLoadTimerDll() != LOG_SUCCESS) {379 if (DlogLoadTimerDll() != LOG_SUCCESS) {
373- SELF_LOG_ERROR("dlog load unified_timer library failed, pid = %d, strerr = %s.",380+ SELF_LOG_ERROR(
374- ToolGetPid(), strerror(ToolGetErrorCode()));381+ "dlog load unified_timer library failed, pid = %d, strerr = %s.", ToolGetPid(),
382+ strerror(ToolGetErrorCode()));
375 return LOG_FAILURE;383 return LOG_FAILURE;
376 }384 }
377 uint32_t ret = DlogAddUnifiedTimer(DLOG_TIMER_NAME, DlogUnifiedTimerCb, LOG_TIMER_PERIOD, PERIODIC_TIMER);385 uint32_t ret = DlogAddUnifiedTimer(DLOG_TIMER_NAME, DlogUnifiedTimerCb, LOG_TIMER_PERIOD, PERIODIC_TIMER);
378 if (ret != 0) {386 if (ret != 0) {
379- SELF_LOG_ERROR("add unified timer failed, ret = %u, errno = %d, pid = %d, timerName = %s.",387+ SELF_LOG_ERROR(
380- ret, ToolGetErrorCode(), ToolGetPid(), DLOG_TIMER_NAME);388+ "add unified timer failed, ret = %u, errno = %d, pid = %d, timerName = %s.", ret, ToolGetErrorCode(),
389+ ToolGetPid(), DLOG_TIMER_NAME);
381 return LOG_FAILURE;390 return LOG_FAILURE;
382 }391 }
383 SELF_LOG_INFO("add unified timer success, pid = %d, timerName = %s.", ToolGetPid(), DLOG_TIMER_NAME);392 SELF_LOG_INFO("add unified timer success, pid = %d, timerName = %s.", ToolGetPid(), DLOG_TIMER_NAME);
@@ -454,11 +463,11 @@ void DlogFlushBuf(void)
454 info.appPid = INVALID;463 info.appPid = INVALID;
455#endif464#endif
456 arg.size = sizeof(FlushInfo);465 arg.size = sizeof(FlushInfo);
457- arg.argData = (void *)&info;466+ arg.argData = (void*)&info;
458 const int32_t ret = DlogIamIoctlFlushLog(&arg);467 const int32_t ret = DlogIamIoctlFlushLog(&arg);
459 if (ret != SYS_OK) {468 if (ret != SYS_OK) {
460- SELF_LOG_ERROR("log flush failed, ret=%d, strerr=%s, pid=%d.",469+ SELF_LOG_ERROR(
461- ret, strerror(ToolGetErrorCode()), DlogGetCurrPid());470+ "log flush failed, ret=%d, strerr=%s, pid=%d.", ret, strerror(ToolGetErrorCode()), DlogGetCurrPid());
462 return;471 return;
463 }472 }
464}473}
@@ -477,7 +486,7 @@ void DlogUpdateFlierLevelStatus(void)
477 if (LogBufCheckEmpty(g_dlogAsyncMgr.bufMgr.dlogBuf[nextIdx])) {486 if (LogBufCheckEmpty(g_dlogAsyncMgr.bufMgr.dlogBuf[nextIdx])) {
478 g_dlogAsyncMgr.bufMgr.writeBufIndex = nextIdx;487 g_dlogAsyncMgr.bufMgr.writeBufIndex = nextIdx;
479 DlogFilterStatus(g_dlogAsyncMgr.bufMgr.dlogBuf[nextIdx]);488 DlogFilterStatus(g_dlogAsyncMgr.bufMgr.dlogBuf[nextIdx]);
480- } else { // if next buf is not empty, means buf is full, clear current buf to save new log489+ } else { // if next buf is not empty, means buf is full, clear current buf to save new log
481 LogBufReInit(g_dlogAsyncMgr.bufMgr.dlogBuf[curIdx]);490 LogBufReInit(g_dlogAsyncMgr.bufMgr.dlogBuf[curIdx]);
482 DlogFilterStatus(g_dlogAsyncMgr.bufMgr.dlogBuf[curIdx]);491 DlogFilterStatus(g_dlogAsyncMgr.bufMgr.dlogBuf[curIdx]);
483 }492 }
@@ -492,15 +501,15 @@ void DlogUpdateFlierLevelStatus(void)
492 DlogUnLock();501 DlogUnLock();
493}502}
494 503 
495-STATIC void DlogInitHead(LogHead *head, const LogMsg *logMsg)504+STATIC void DlogInitHead(LogHead* head, const LogMsg* logMsg)
496{505{
497 (void)memset_s(head, sizeof(LogHead), 0, sizeof(LogHead));506 (void)memset_s(head, sizeof(LogHead), 0, sizeof(LogHead));
498 head->magic = HEAD_MAGIC;507 head->magic = HEAD_MAGIC;
499 head->version = HEAD_VERSION;508 head->version = HEAD_VERSION;
500- head->aosType = (uint8_t)DlogGetAosType(); // AOS_GEA/AOS_SEA509+ head->aosType = (uint8_t)DlogGetAosType(); // AOS_GEA/AOS_SEA
501- head->processType = (uint8_t)DlogGetProcessType(); // APPLICATION/SYSTEM510+ head->processType = (uint8_t)DlogGetProcessType(); // APPLICATION/SYSTEM
502- head->logType = (uint8_t)logMsg->type; // debug/run/security511+ head->logType = (uint8_t)logMsg->type; // debug/run/security
503- head->logLevel = (uint8_t)logMsg->level; // debug/info/warning/error/event512+ head->logLevel = (uint8_t)logMsg->level; // debug/info/warning/error/event
504 head->hostPid = DlogGetHostPid();513 head->hostPid = DlogGetHostPid();
505 head->devicePid = (uint32_t)DlogGetCurrPid();514 head->devicePid = (uint32_t)DlogGetCurrPid();
506 head->deviceId = (uint16_t)DlogGetAttrDeviceId();515 head->deviceId = (uint16_t)DlogGetAttrDeviceId();
@@ -525,18 +534,19 @@ STATIC void DlogPrintLogLoss(void)
525 costTime = currTime - g_dlogAsyncMgr.bufMgr.lastPrintTime;534 costTime = currTime - g_dlogAsyncMgr.bufMgr.lastPrintTime;
526 }535 }
527 if (costTime >= periodTime) {536 if (costTime >= periodTime) {
528- SELF_LOG_WARN("dlog buffer covered log loss num = %lu, print every %lu seconds.",537+ SELF_LOG_WARN(
529- g_dlogAsyncMgr.bufMgr.lossCount, LOG_LOST_PRINT_PERIOD_TIME / (uint64_t)S_TO_MS);538+ "dlog buffer covered log loss num = %lu, print every %lu seconds.", g_dlogAsyncMgr.bufMgr.lossCount,
539+ LOG_LOST_PRINT_PERIOD_TIME / (uint64_t)S_TO_MS);
530 g_dlogAsyncMgr.bufMgr.lastPrintTime = currTime;540 g_dlogAsyncMgr.bufMgr.lastPrintTime = currTime;
531 g_dlogAsyncMgr.bufMgr.lossCount = 0;541 g_dlogAsyncMgr.bufMgr.lossCount = 0;
532 }542 }
533}543}
534 544 
535-STATIC RingBufferStat *DlogGetWriteBuf(bool *isBufSwitch, uint32_t msgLen)545+STATIC RingBufferStat* DlogGetWriteBuf(bool* isBufSwitch, uint32_t msgLen)
536{546{
537 uint32_t curIdx = g_dlogAsyncMgr.bufMgr.writeBufIndex;547 uint32_t curIdx = g_dlogAsyncMgr.bufMgr.writeBufIndex;
538 uint32_t nextIdx = (curIdx + 1U) % LOG_BUF_NUM;548 uint32_t nextIdx = (curIdx + 1U) % LOG_BUF_NUM;
539- RingBufferStat *bufMgr = g_dlogAsyncMgr.bufMgr.dlogBuf[curIdx];549+ RingBufferStat* bufMgr = g_dlogAsyncMgr.bufMgr.dlogBuf[curIdx];
540 if (!LogBufCheckEnough(bufMgr, msgLen)) {550 if (!LogBufCheckEnough(bufMgr, msgLen)) {
541 if (LogBufCheckEmpty(g_dlogAsyncMgr.bufMgr.dlogBuf[nextIdx])) {551 if (LogBufCheckEmpty(g_dlogAsyncMgr.bufMgr.dlogBuf[nextIdx])) {
542 g_dlogAsyncMgr.bufMgr.writeBufIndex = nextIdx;552 g_dlogAsyncMgr.bufMgr.writeBufIndex = nextIdx;
@@ -555,7 +565,7 @@ STATIC RingBufferStat *DlogGetWriteBuf(bool *isBufSwitch, uint32_t msgLen)
555 * @brief : write log to buffer565 * @brief : write log to buffer
556 * @param [in] : logMsg log messages566 * @param [in] : logMsg log messages
557 */567 */
558-void DlogWriteToBuf(const LogMsg *logMsg)568+void DlogWriteToBuf(const LogMsg* logMsg)
559{569{
560 if (!g_dlogAsyncMgr.initFlag) {570 if (!g_dlogAsyncMgr.initFlag) {
561 return;571 return;
@@ -566,17 +576,17 @@ void DlogWriteToBuf(const LogMsg *logMsg)
566 }576 }
567 DlogLock();577 DlogLock();
568 bool isBufSwitch = false;578 bool isBufSwitch = false;
569- RingBufferStat *bufMgr = DlogGetWriteBuf(&isBufSwitch, logMsg->msgLength);579+ RingBufferStat* bufMgr = DlogGetWriteBuf(&isBufSwitch, logMsg->msgLength);
570 TWO_ACT_NO_LOG(bufMgr == NULL, DlogUnLock(), return);580 TWO_ACT_NO_LOG(bufMgr == NULL, DlogUnLock(), return);
571 581 
572- if (g_dlogAsyncMgr.levelCtrl.ctrlSwitch && (logMsg->type == DEBUG_LOG)582+ if (g_dlogAsyncMgr.levelCtrl.ctrlSwitch && (logMsg->type == DEBUG_LOG) &&
573- && (logMsg->level < g_dlogAsyncMgr.levelCtrl.ctrlLevel)) {583+ (logMsg->level < g_dlogAsyncMgr.levelCtrl.ctrlLevel)) {
574 g_dlogAsyncMgr.levelCtrl.lossCount++;584 g_dlogAsyncMgr.levelCtrl.lossCount++;
575 DlogUnLock();585 DlogUnLock();
576 return;586 return;
577 }587 }
578 588 
579- LogHead head = { 0 };589+ LogHead head = {0};
580 DlogInitHead(&head, logMsg);590 DlogInitHead(&head, logMsg);
581 uint64_t coverCount = 0;591 uint64_t coverCount = 0;
582 int32_t res = LogBufWrite(bufMgr->ringBufferCtrl, logMsg->msg, &head, &coverCount);592 int32_t res = LogBufWrite(bufMgr->ringBufferCtrl, logMsg->msg, &head, &coverCount);
@@ -601,18 +611,20 @@ STATIC void DlogStopSendTask(void)
601 if (g_dlogAsyncMgr.initFlag && (DlogCheckCurrPid())) {611 if (g_dlogAsyncMgr.initFlag && (DlogCheckCurrPid())) {
602 uint32_t ret = DlogRemoveUnifiedTimer(DLOG_TIMER_NAME);612 uint32_t ret = DlogRemoveUnifiedTimer(DLOG_TIMER_NAME);
603 (void)DlogRemoveUnifiedTimer(DLOG_SYNC_TIMER_NAME); // remove one shot unified timer, if it not exist, ignore it613 (void)DlogRemoveUnifiedTimer(DLOG_SYNC_TIMER_NAME); // remove one shot unified timer, if it not exist, ignore it
604- NO_ACT_ERR_LOG(DlogCloseTimerDll() != LOG_SUCCESS,614+ NO_ACT_ERR_LOG(
605- "close unified_timer library failed, pid = %d, timer name = %s.", ToolGetPid(), DLOG_TIMER_NAME);615+ DlogCloseTimerDll() != LOG_SUCCESS, "close unified_timer library failed, pid = %d, timer name = %s.",
616+ ToolGetPid(), DLOG_TIMER_NAME);
606 if (ret != 0) {617 if (ret != 0) {
607- SELF_LOG_ERROR("remove unified timer failed, ret = %u, errno = %d, pid = %d, timer name = %s.",618+ SELF_LOG_ERROR(
608- ret, ToolGetErrorCode(), ToolGetPid(), DLOG_TIMER_NAME);619+ "remove unified timer failed, ret = %u, errno = %d, pid = %d, timer name = %s.", ret,
620+ ToolGetErrorCode(), ToolGetPid(), DLOG_TIMER_NAME);
609 return;621 return;
610 }622 }
611 SELF_LOG_INFO("remove unified timer success, pid = %d, timer name = %s.", ToolGetPid(), DLOG_TIMER_NAME);623 SELF_LOG_INFO("remove unified timer success, pid = %d, timer name = %s.", ToolGetPid(), DLOG_TIMER_NAME);
612 }624 }
613}625}
614 626 
615-STATIC void DlogRingBufExit(RingBufferStat **ringBuffer)627+STATIC void DlogRingBufExit(RingBufferStat** ringBuffer)
616{628{
617 if (*ringBuffer != NULL) {629 if (*ringBuffer != NULL) {
618 XFREE((*ringBuffer)->ringBufferCtrl);630 XFREE((*ringBuffer)->ringBufferCtrl);
@@ -630,16 +642,16 @@ STATIC void DlogBufExit(void)
630 }642 }
631}643}
632 644 
633-STATIC int32_t DlogRingBufInit(RingBufferStat **ringBuffer, uint32_t size)645+STATIC int32_t DlogRingBufInit(RingBufferStat** ringBuffer, uint32_t size)
634{646{
635- *ringBuffer = (RingBufferStat *)LogMalloc(sizeof(RingBufferStat));647+ *ringBuffer = (RingBufferStat*)LogMalloc(sizeof(RingBufferStat));
636 if (*ringBuffer == NULL) {648 if (*ringBuffer == NULL) {
637 SELF_LOG_ERROR("malloc for log buffer failed, strerr = %s.", strerror(ToolGetErrorCode()));649 SELF_LOG_ERROR("malloc for log buffer failed, strerr = %s.", strerror(ToolGetErrorCode()));
638 return LOG_FAILURE;650 return LOG_FAILURE;
639 }651 }
640 (*ringBuffer)->logBufSize = size;652 (*ringBuffer)->logBufSize = size;
641 // malloc but not memset, memory is not actually occupied, to ensure memory baseline is met653 // malloc but not memset, memory is not actually occupied, to ensure memory baseline is met
642- (*ringBuffer)->ringBufferCtrl = (RingBufferCtrl *)malloc((*ringBuffer)->logBufSize);654+ (*ringBuffer)->ringBufferCtrl = (RingBufferCtrl*)malloc((*ringBuffer)->logBufSize);
643 if ((*ringBuffer)->ringBufferCtrl == NULL) {655 if ((*ringBuffer)->ringBufferCtrl == NULL) {
644 SELF_LOG_ERROR("malloc for log buffer ctrl failed, strerr = %s.", strerror(ToolGetErrorCode()));656 SELF_LOG_ERROR("malloc for log buffer ctrl failed, strerr = %s.", strerror(ToolGetErrorCode()));
645 XFREE(*ringBuffer);657 XFREE(*ringBuffer);
@@ -647,8 +659,9 @@ STATIC int32_t DlogRingBufInit(RingBufferStat **ringBuffer, uint32_t size)
647 }659 }
648 int32_t err = LogBufInitHead((*ringBuffer)->ringBufferCtrl, (*ringBuffer)->logBufSize, 0);660 int32_t err = LogBufInitHead((*ringBuffer)->ringBufferCtrl, (*ringBuffer)->logBufSize, 0);
649 if (err != LOG_SUCCESS) {661 if (err != LOG_SUCCESS) {
650- SELF_LOG_ERROR("init log buffer head failed, err = %d, strerr = %s, pid = %d.",662+ SELF_LOG_ERROR(
651- err, strerror(ToolGetErrorCode()), ToolGetPid());663+ "init log buffer head failed, err = %d, strerr = %s, pid = %d.", err, strerror(ToolGetErrorCode()),
664+ ToolGetPid());
652 DlogRingBufExit(ringBuffer);665 DlogRingBufExit(ringBuffer);
653 return LOG_FAILURE;666 return LOG_FAILURE;
654 }667 }
@@ -715,9 +728,9 @@ void DlogAsyncExit(void)
715 DlogLock();728 DlogLock();
716 CountLogLoss();729 CountLogLoss();
717 // log loss selflog print730 // log loss selflog print
718- SELF_LOG_INFO("pid=%d, pid_name=%s quit, log covered loss num is %lu, log level control loss num is %lu.",731+ SELF_LOG_INFO(
719- DlogGetCurrPid(), DlogGetPidName(),732+ "pid=%d, pid_name=%s quit, log covered loss num is %lu, log level control loss num is %lu.", DlogGetCurrPid(),
720- g_dlogAsyncMgr.bufMgr.lossCount, g_dlogAsyncMgr.levelCtrl.lossCount);733+ DlogGetPidName(), g_dlogAsyncMgr.bufMgr.lossCount, g_dlogAsyncMgr.levelCtrl.lossCount);
721 DlogBufExit();734 DlogBufExit();
722 DlogUnLock();735 DlogUnLock();
723 if (DlogIsAosCore()) {736 if (DlogIsAosCore()) {
@@ -1,35 +1,35 @@
1-/**1+/**
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10-#ifndef DLOG_NSYC_PROCESS_H10+#ifndef DLOG_NSYC_PROCESS_H
11-#define DLOG_NSYC_PROCESS_H11+#define DLOG_NSYC_PROCESS_H
12- 12+ 
13-#include "high_mem.h"13+#include "high_mem.h"
14-#include "dlog_iam.h"14+#include "dlog_iam.h"
15-#include "dlog_attr.h"15+#include "dlog_attr.h"
16-#include "dlog_message.h"16+#include "dlog_message.h"
17- 17+ 
18-#ifdef __cplusplus18+#ifdef __cplusplus
19-extern "C" {19+extern "C" {
20-#endif // __cplusplus20+#endif // __cplusplus
21- 21+ 
22-void DlogWriteToBuf(const LogMsg *logMsg);22+void DlogWriteToBuf(const LogMsg* logMsg);
23-void DlogFlushBuf(void);23+void DlogFlushBuf(void);
24-void DlogUpdateFlierLevelStatus(void);24+void DlogUpdateFlierLevelStatus(void);
25- 25+ 
26-int32_t DlogAsyncInit(void);26+int32_t DlogAsyncInit(void);
27-void DlogAsyncExit(void);27+void DlogAsyncExit(void);
28- 28+ 
29-void CheckPid(void);29+void CheckPid(void);
30- 30+ 
31-#ifdef __cplusplus31+#ifdef __cplusplus
32-}32+}
33-#endif // __cplusplus33+#endif // __cplusplus
34- 34+ 
35-#endif // DLOG_NSYC_PROCESS_H35+#endif // DLOG_NSYC_PROCESS_H
@@ -1,71 +1,71 @@
1-/**1+/**
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10-#ifndef DLOG_ATTR_H10+#ifndef DLOG_ATTR_H
11-#define DLOG_ATTR_H11+#define DLOG_ATTR_H
12- 12+ 
13-#include <stdint.h>13+#include <stdint.h>
14-#include <stdbool.h>14+#include <stdbool.h>
15-#include "slog.h"15+#include "slog.h"
16-#include "log_error_code.h"16+#include "log_error_code.h"
17- 17+ 
18-#ifdef __cplusplus18+#ifdef __cplusplus
19-extern "C" {19+extern "C" {
20-#endif // __cplusplus20+#endif // __cplusplus
21-#ifndef DEFAULT_LOG_WORKSPACE21+#ifndef DEFAULT_LOG_WORKSPACE
22-#define DEFAULT_LOG_WORKSPACE "/usr/slog"22+#define DEFAULT_LOG_WORKSPACE "/usr/slog"
23-#endif23+#endif
24- 24+ 
25-typedef enum {25+typedef enum {
26- AOS_GEA = 0,26+ AOS_GEA = 0,
27- AOS_SEA,27+ AOS_SEA,
28-} AosType;28+} AosType;
29- 29+ 
30-void DlogGetUserAttr(LogAttr *attr);30+void DlogGetUserAttr(LogAttr* attr);
31-void DlogSetUserAttr(const LogAttr *logAttr);31+void DlogSetUserAttr(const LogAttr* logAttr);
32-bool DlogCheckAttrSystem(void);32+bool DlogCheckAttrSystem(void);
33-ProcessType DlogGetProcessType(void);33+ProcessType DlogGetProcessType(void);
34-uint32_t DlogGetAttrDeviceId(void);34+uint32_t DlogGetAttrDeviceId(void);
35- 35+ 
36-bool DlogIsAosCore(void);36+bool DlogIsAosCore(void);
37-AosType DlogGetAosType(void);37+AosType DlogGetAosType(void);
38-bool DlogIsPoolingDevice(void);38+bool DlogIsPoolingDevice(void);
39- 39+ 
40-int32_t DlogGetCurrPid(void);40+int32_t DlogGetCurrPid(void);
41-void DlogSetCurrPid(void);41+void DlogSetCurrPid(void);
42-bool DlogCheckCurrPid(void);42+bool DlogCheckCurrPid(void);
43-uint32_t DlogGetHostPid(void);43+uint32_t DlogGetHostPid(void);
44-uint32_t DlogGetUid(void);44+uint32_t DlogGetUid(void);
45-uint32_t DlogGetGid(void);45+uint32_t DlogGetGid(void);
46- 46+ 
47-void DlogInitGlobalAttr(void);47+void DlogInitGlobalAttr(void);
48- 48+ 
49-#ifdef __cplusplus49+#ifdef __cplusplus
50-}50+}
51-#endif // __cplusplus51+#endif // __cplusplus
52- 52+ 
53-#ifdef __cplusplus53+#ifdef __cplusplus
54-#ifndef LOG_CPP54+#ifndef LOG_CPP
55-extern "C" {55+extern "C" {
56-#endif56+#endif
57-#endif // __cplusplus57+#endif // __cplusplus
58-/**58+/**
59- * @ingroup : slog59+ * @ingroup : slog
60- * @brief : get log attr60+ * @brief : get log attr
61- * @param [out] : logAttrInfo struct LogAttr pointer61+ * @param [out] : logAttrInfo struct LogAttr pointer
62- * @return : 0: SUCCEED, others: FAILED62+ * @return : 0: SUCCEED, others: FAILED
63- */63+ */
64-LOG_FUNC_VISIBILITY int32_t DlogGetAttr(LogAttr *logAttrInfo);64+LOG_FUNC_VISIBILITY int32_t DlogGetAttr(LogAttr* logAttrInfo);
65-#ifdef __cplusplus65+#ifdef __cplusplus
66-#ifndef LOG_CPP66+#ifndef LOG_CPP
67-}67+}
68-#endif // LOG_CPP68+#endif // LOG_CPP
69-#endif // __cplusplus69+#endif // __cplusplus
70- 70+ 
71-#endif // DLOG_ATTR_H71+#endif // DLOG_ATTR_H
@@ -1,86 +1,75 @@
1-/**1+/**
2- * Copyright (c) 2025 Huawei Technologies Co., Ltd.2+ * Copyright (c) 2025 Huawei Technologies Co., Ltd.
3- * This program is free software, you can redistribute it and/or modify it under the terms and conditions of3+ * This program is free software, you can redistribute it and/or modify it under the terms and conditions of
4- * CANN Open Software License Agreement Version 2.0 (the "License").4+ * CANN Open Software License Agreement Version 2.0 (the "License").
5- * Please refer to the License for details. You may not use this file except in compliance with the License.5+ * Please refer to the License for details. You may not use this file except in compliance with the License.
6- * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,6+ * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR IMPLIED,
7- * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.7+ * INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR A PARTICULAR PURPOSE.
8- * See LICENSE in the root of the software repository for the full text of the License.8+ * See LICENSE in the root of the software repository for the full text of the License.
9- */9+ */
10-#ifndef DLOG_COMMON_H10+#ifndef DLOG_COMMON_H
11-#define DLOG_COMMON_H11+#define DLOG_COMMON_H
12-#include "log_system_api.h"12+#include "log_system_api.h"
13-#include "log_file_util.h"13+#include "log_file_util.h"
14-#include "share_mem.h"14+#include "share_mem.h"
15-#include "log_print.h"15+#include "log_print.h"
16-#include "slog_api.h"16+#include "slog_api.h"
17- 17+ 
18-#ifdef __cplusplus18+#ifdef __cplusplus
19-extern "C" {19+extern "C" {
20-#endif20+#endif
21- 21+ 
22-#define WRITE_E_PRINT_NUM 1000022+#define WRITE_E_PRINT_NUM 10000
23-#define FSTAT_E_PRINT_NUM 200023+#define FSTAT_E_PRINT_NUM 2000
24-#define CONN_W_PRINT_NUM 5000024+#define CONN_W_PRINT_NUM 50000
25-#define EVENT_ENABLE_VALUE 125+#define EVENT_ENABLE_VALUE 1
26-#define EVENT_DISABLE_VALUE 026+#define EVENT_DISABLE_VALUE 0
27-#define TIME_LOOP_READ_CONFIG 100027+#define TIME_LOOP_READ_CONFIG 1000
28-#define TIMESTAMP_LEN 12828+#define TIMESTAMP_LEN 128
29-#define TIME_ONE_THOUSAND_MS 100029+#define TIME_ONE_THOUSAND_MS 1000
30-#define LOG_WARN_INTERVAL (2 * 1000) // 2s30+#define LOG_WARN_INTERVAL (2 * 1000) // 2s
31-#define LOG_INFO_INTERVAL (4 * 1000) // 4s31+#define LOG_INFO_INTERVAL (4 * 1000) // 4s
32-#define LOG_CTRL_TOTAL_INTERVAL (8 * 1000) // 8s32+#define LOG_CTRL_TOTAL_INTERVAL (8 * 1000) // 8s
33-#define WRITE_MAX_RETRY_TIMES 333+#define WRITE_MAX_RETRY_TIMES 3
34-#define SIZE_TWO_MB (2 * 1024 * 1024) // 2MB34+#define SIZE_TWO_MB (2 * 1024 * 1024) // 2MB
35-#define MAX_MODULE_LOG_LEVEL_OPTION_LEN (MAX_MODULE_NAME_LEN + MAX_MODULE_VALUE_LEN + 2)35+#define MAX_MODULE_LOG_LEVEL_OPTION_LEN (MAX_MODULE_NAME_LEN + MAX_MODULE_VALUE_LEN + 2)
36-#define MAX_ASCEND_MODULE_LOG_ENV_LEN ((MAX_MODULE_LOG_LEVEL_OPTION_LEN) * 64)36+#define MAX_ASCEND_MODULE_LOG_ENV_LEN ((MAX_MODULE_LOG_LEVEL_OPTION_LEN)*64)
37-#define MAX_MODULE_NUM 6437+#define MAX_MODULE_NUM 64
38- 38+ 
39-typedef struct {39+typedef struct {
40- const KeyValue *pstKVArray;40+ const KeyValue* pstKVArray;
41- int kvNum;41+ int kvNum;
42-} KeyValueArg;42+} KeyValueArg;
43- 43+ 
44-typedef enum {44+typedef enum { LOG_WRITE, LOG_FLUSH, LOG_FORK, LOG_ATFORK } CallbackType;
45- LOG_WRITE,45+ 
46- LOG_FLUSH,46+#define ATFORK_PREPARE 0
47- LOG_FORK,47+#define ATFORK_PARENT 1
48- LOG_ATFORK48+#define ATFORK_CHILD 2
49-} CallbackType;49+ 
50- 50+typedef void (*ThreadAtFork)(void);
51-#define ATFORK_PREPARE 051+typedef int32_t (*DlogWriteCallback)(const char*, uint32_t, int32_t);
52-#define ATFORK_PARENT 152+typedef void (*DlogFlushCallback)(void);
53-#define ATFORK_CHILD 253+typedef void (*DlogForkCallback)(void);
54- 54+typedef void (*DlogAtForkCallback)(int32_t);
55-typedef void (*ThreadAtFork)(void);55+ 
56-typedef int32_t (*DlogWriteCallback) (const char *, uint32_t, int32_t);56+typedef struct {
57-typedef void (*DlogFlushCallback) (void);57+ DlogWriteCallback funcWrite;
58-typedef void (*DlogForkCallback) (void);58+ DlogFlushCallback funcFlush;
59-typedef void (*DlogAtForkCallback) (int32_t);59+ DlogForkCallback funcFork;
60- 60+ DlogAtForkCallback funcAtFork;
61-typedef struct {61+} DlogCallback;
62- DlogWriteCallback funcWrite;62+ 
63- DlogFlushCallback funcFlush;63+int32_t RegisterCallback(const ArgPtr callback, const CallbackType funcType);
64- DlogForkCallback funcFork;64+ 
65- DlogAtForkCallback funcAtFork;65+#if (OS_TYPE_DEF == LINUX)
66-} DlogCallback;66+extern char* __progname;
67- 67+static inline const char* DlogGetPidName(void) { return (__progname != NULL) ? __progname : "None"; }
68-int32_t RegisterCallback(const ArgPtr callback, const CallbackType funcType);68+#else
69- 69+static inline const char* DlogGetPidName(void) { return "None"; }
70-#if (OS_TYPE_DEF == LINUX)70+#endif
71-extern char *__progname;71+ 
72-static inline const char *DlogGetPidName(void)72+#ifdef __cplusplus
73-{73+}
74- return (__progname != NULL) ? __progname : "None";74+#endif
75-}75+#endif
76-#else
77-static inline const char *DlogGetPidName(void)
78-{
79- return "None";
80-}
81-#endif
82- 
83-#ifdef __cplusplus
84-}
85-#endif
86-#endif
@@ -15,7 +15,7 @@
15STATIC int8_t g_msgType = MSGTYPE_TAG;15STATIC int8_t g_msgType = MSGTYPE_TAG;
16 16 
17#if defined LOG_CPP || defined APP_LOG17#if defined LOG_CPP || defined APP_LOG
18-STATIC LogStatus DlogReadMsgTypeFormShmem(int8_t *msgType)18+STATIC LogStatus DlogReadMsgTypeFormShmem(int8_t* msgType)
19{19{
20 int32_t shmId = -1;20 int32_t shmId = -1;
21 ShmErr ret = ShMemOpen(&shmId);21 ShmErr ret = ShMemOpen(&shmId);
@@ -24,7 +24,7 @@ STATIC LogStatus DlogReadMsgTypeFormShmem(int8_t *msgType)
24 return LOG_FAILURE;24 return LOG_FAILURE;
25 }25 }
26 26 
27- char *tmpBuf = (char *)LogMalloc(GLOBAL_ARR_LEN);27+ char* tmpBuf = (char*)LogMalloc(GLOBAL_ARR_LEN);
28 if (tmpBuf == NULL) {28 if (tmpBuf == NULL) {
29 SELF_LOG_ERROR("malloc failed, pid=%d, strerr=%s.", ToolGetPid(), strerror(ToolGetErrorCode()));29 SELF_LOG_ERROR("malloc failed, pid=%d, strerr=%s.", ToolGetPid(), strerror(ToolGetErrorCode()));
30 return LOG_FAILURE;30 return LOG_FAILURE;
@@ -37,7 +37,7 @@ STATIC LogStatus DlogReadMsgTypeFormShmem(int8_t *msgType)
37 return LOG_FAILURE;37 return LOG_FAILURE;
38 }38 }
39 39 
40- GloablArr *global = (GloablArr *)tmpBuf;40+ GloablArr* global = (GloablArr*)tmpBuf;
41 *msgType = global->msgType;41 *msgType = global->msgType;
42 XFREE(tmpBuf);42 XFREE(tmpBuf);
43 return LOG_SUCCESS;43 return LOG_SUCCESS;
@@ -61,7 +61,4 @@ void DlogInitMsgType(void)
61#endif61#endif
62}62}
63 63 
64-int8_t DlogGetMsgType(void)64+int8_t DlogGetMsgType(void) { return g_msgType; }
65-{
66- return g_msgType;
67-}
Msrc/dfx/log/utils/log_compress/log_hardware_zip.c+332-328文件内容审核中,请稍后刷新重试