mirror of
https://github.com/openharmony/window_window_manager.git
synced 2026-08-24 15:55:05 -04:00
!19296 merge master into master
Rename info to tlogInfo_ in PRINT_TLOG macro to avoid symbol conflict
Created-by: liuyue961220
Commit-by: liuyue137
Merged-by: openharmony_ci
Description: **Description:**
**Issue number:**
**Test & Result:**
**CodeCheck:**
<table>
<tr>
<th>类型</th><th>自检项</th><th>自检结果</th>
</tr>
<tr>
<td rowspan="2">多线程相关</td><td>在类的成员变量中定义了vector/map/list等容器类型,且在多个成员函数中有操作时,需要加锁保护</td><td>自检结果:pass</td>
</tr>
<tr>
<td>定义全局变量,在多个函数中都有操作时,需要加锁保护</td><td>自检结果:pass</td>
</tr>
<tr>
<td rowspan="4">内存相关</td><td>调用外部接口时,确认是否对返回值做了判断,尤其外部接口返回了nullptr的情况,避免进程崩溃</td><td>自检结果:pass</td>
</tr>
<tr>
<td>调用安全函数时,如memcpy_s等,是否检查其返回值</td><td>自检结果:pass</td>
</tr>
<tr>
<td>检查函数中是否涉及了内存或资源申请(如文件句柄),注意每个异常退出流程,是否都已经将资源释放(推荐使用RAII)</td><td>自检结果:pass</td>
</tr>
</tr>
<tr>
<td>隐式内存分配场景:realpath、ReadParcelable序列化、cJSON相关函数时等,需主动释放或使用智能指针</td><td>自检结果:pass</td>
</tr>
<tr>
<td rowspan="4">校验外部输入</td><td>使用nlohmann:json解析外部输入时,需判断参数类型是否符合预期</td><td>自检结果:pass</td>
</tr>
<tr>
<td>所有外部输入均不可信,需判断外部输入是否直接作为内存分配的大小,数组下标、循环条件、SQL查询等</td><td>自检结果:pass</td>
</tr>
<tr>
<td>外部输入的路径不可信,需使用realpath做标准化处理,并判断路径的合法性</td><td>自检结果:pass</td>
</tr>
<tr>
<td>外部输入包括对外提供的接口,IPC的proxy/stub接口,序列化/反序列化接口等</td><td>自检结果:pass</td>
</tr>
</tr>
<tr>
<td rowspan="3">数学运算</td><td>代码中是否混合了加减乘除等运算,需检查是否可能导致整数溢出或符号翻转</td><td>自检结果:pass</td>
</tr>
<tr>
<td>需检查代码是否有高精度数字转换为低精度的操作,如果必须,建议使用C++安全类型转换接口</td><td>自检结果:pass</td>
</tr>
<tr>
<td>检查代码在计算时是否有除零操作(包括除数是计算出来的结果可能为0的情况)</td><td>自检结果:</td>
</tr>
</tr>
<tr>
<td rowspan="2">权限相关</td><td>作为系统服务对外提供了接口,是否做了权限保护和校验(如需要),只允许申请了权限的应用访问</td><td>自检结果:pass</td>
</tr>
<tr>
<td>提供给其他系统服务的接口默认需要做SA服务校验</td><td>自检结果:pass</td>
</tr>
<tr>
<td rowspan="2">跨进程通信</td><td>优先使用异步IPC,若必须使用同步IPC需要考虑对端卡死或高延时影响</td><td>自检结果:pass</td>
</tr>
<tr>
<td>序列化/反序列化中数据读写顺序要严格对齐</td><td>自检结果:pass</td>
</tr>
</table>
See merge request: openharmony/window_window_manager!19296
This commit is contained in:
@@ -16,6 +16,7 @@
|
||||
#ifndef OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H
|
||||
#define OHOS_WM_INCLUDE_WINDOW_MANAGER_HILOG_H
|
||||
|
||||
#include <chrono>
|
||||
#include <cstdint>
|
||||
#include <unordered_map>
|
||||
#include "hilog/log.h"
|
||||
@@ -80,6 +81,45 @@ enum class WmsLogTag : uint8_t {
|
||||
};
|
||||
|
||||
extern const char* g_domainContents[static_cast<uint32_t>(WmsLogTag::END)];
|
||||
|
||||
struct TLogInfo {
|
||||
uint32_t domain;
|
||||
const char* content;
|
||||
};
|
||||
|
||||
TLogInfo GetTLogInfo(WmsLogTag tag);
|
||||
|
||||
struct WinPrintLimitState {
|
||||
std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds> last{};
|
||||
uint32_t supressed = 0;
|
||||
int printCount = 0;
|
||||
};
|
||||
|
||||
struct WinPrintLimitConfig {
|
||||
WmsLogTag logTag;
|
||||
LogLevel logLevel;
|
||||
uint32_t timeIntervals;
|
||||
uint32_t printFrequency;
|
||||
const char* functionName;
|
||||
|
||||
WinPrintLimitConfig()
|
||||
: logTag(WmsLogTag::DEFAULT),
|
||||
logLevel(LOG_INFO),
|
||||
timeIntervals(WIN_LOG_LIMIT_MINUTE),
|
||||
printFrequency(TEN_TIMES),
|
||||
functionName("") {}
|
||||
|
||||
WinPrintLimitConfig(WmsLogTag tag, LogLevel level, uint32_t intervals,
|
||||
uint32_t frequency, const char* funcName)
|
||||
: logTag(tag),
|
||||
logLevel(level),
|
||||
timeIntervals(intervals),
|
||||
printFrequency(frequency),
|
||||
functionName(funcName) {}
|
||||
};
|
||||
|
||||
bool WinPrintLimit(const WinPrintLimitConfig& config, WinPrintLimitState& state);
|
||||
|
||||
#ifdef IS_RELEASE_VERSION
|
||||
#define WMS_FILE_NAME ""
|
||||
#define FMT_PREFIX "%{public}s%{public}s: "
|
||||
@@ -92,12 +132,10 @@ extern const char* g_domainContents[static_cast<uint32_t>(WmsLogTag::END)];
|
||||
#endif
|
||||
#define WMS_NO_FILE_NAME ""
|
||||
|
||||
#define PRINT_TLOG(level, tag, ...) \
|
||||
do { \
|
||||
uint32_t hilogDomain = HILOG_DOMAIN_WINDOW + static_cast<uint32_t>(tag); \
|
||||
const char *domainContent = (tag >= WmsLogTag::DEFAULT && tag < WmsLogTag::END) ? \
|
||||
g_domainContents[static_cast<uint32_t>(tag)] : ""; \
|
||||
HILOG_IMPL(LOG_CORE, level, hilogDomain, domainContent, ##__VA_ARGS__); \
|
||||
#define PRINT_TLOG(level, tag, fmt, ...) \
|
||||
do { \
|
||||
auto tlogInfo_ = GetTLogInfo(tag); \
|
||||
HiLogPrint(LOG_CORE, level, tlogInfo_.domain, tlogInfo_.content, fmt, ##__VA_ARGS__); \
|
||||
} while (0)
|
||||
|
||||
#define TLOGD(tag, fmt, ...) \
|
||||
@@ -131,34 +169,11 @@ PRINT_TLOG(LOG_WARN, tag, FMT_PREFIX fmt, WMS_NO_FILE_NAME, C_W_FUNC, ##__VA_ARG
|
||||
#define TLOGNFE(tag, fmt, ...) \
|
||||
PRINT_TLOG(LOG_ERROR, tag, FMT_PREFIX fmt, WMS_NO_FILE_NAME, C_W_FUNC, ##__VA_ARGS__)
|
||||
|
||||
#define WIN_PRINT_LIMIT(tag, level, intervals, canPrint, frequency) \
|
||||
do { \
|
||||
uint32_t hilogDomain = HILOG_DOMAIN_WINDOW + static_cast<uint32_t>(tag); \
|
||||
const char *domainContent = ((tag) >= WmsLogTag::DEFAULT && (tag) < WmsLogTag::END) ? \
|
||||
g_domainContents[static_cast<uint32_t>(tag)] : ""; \
|
||||
static auto last = std::chrono::time_point<std::chrono::system_clock, std::chrono::seconds>(); \
|
||||
static uint32_t supressed = 0; \
|
||||
static int printCount = 0; \
|
||||
auto now = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now()); \
|
||||
auto duration = now - last; \
|
||||
if (duration.count() >= (intervals)) { \
|
||||
last = now; \
|
||||
uint32_t supressedCnt = supressed; \
|
||||
supressed = 0; \
|
||||
printCount = 1; \
|
||||
if (supressedCnt != 0) { \
|
||||
((void)HILOG_IMPL(LOG_CORE, (level), hilogDomain, domainContent, \
|
||||
"%{public}s log suppressed cnt %{public}u", __func__, supressedCnt)); \
|
||||
} \
|
||||
(canPrint) = true; \
|
||||
} else { \
|
||||
if ((printCount++) < (frequency)) { \
|
||||
(canPrint) = true; \
|
||||
} else { \
|
||||
supressed++; \
|
||||
(canPrint) = false; \
|
||||
} \
|
||||
} \
|
||||
#define WIN_PRINT_LIMIT(tag, level, intervals, canPrint, frequency) \
|
||||
do { \
|
||||
static WinPrintLimitState state; \
|
||||
WinPrintLimitConfig config(tag, level, intervals, frequency, __func__); \
|
||||
(canPrint) = WinPrintLimit(config, state); \
|
||||
} while (0)
|
||||
|
||||
#define TLOGI_LIMITN_HOUR(tag, freq, fmt, ...) \
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
*/
|
||||
|
||||
#include "window_manager_hilog.h"
|
||||
#include <chrono>
|
||||
|
||||
namespace OHOS {
|
||||
namespace Rosen {
|
||||
@@ -50,5 +51,38 @@ const char* g_domainContents[static_cast<uint32_t>(WmsLogTag::END)] = {
|
||||
"WMSRotation",
|
||||
"WMSAnimation",
|
||||
};
|
||||
|
||||
TLogInfo GetTLogInfo(WmsLogTag tag)
|
||||
{
|
||||
uint32_t domain = HILOG_DOMAIN_WINDOW + static_cast<uint32_t>(tag);
|
||||
const char* content = (tag >= WmsLogTag::DEFAULT && tag < WmsLogTag::END) ?
|
||||
g_domainContents[static_cast<uint32_t>(tag)] : "";
|
||||
return {domain, content};
|
||||
}
|
||||
|
||||
bool WinPrintLimit(const WinPrintLimitConfig& config, WinPrintLimitState& state)
|
||||
{
|
||||
auto info = GetTLogInfo(config.logTag);
|
||||
auto now = std::chrono::time_point_cast<std::chrono::seconds>(std::chrono::system_clock::now());
|
||||
auto duration = now - state.last;
|
||||
if (duration.count() >= config.timeIntervals) {
|
||||
state.last = now;
|
||||
uint32_t supressedCnt = state.supressed;
|
||||
state.supressed = 0;
|
||||
state.printCount = 1;
|
||||
if (supressedCnt != 0) {
|
||||
HiLogPrint(LOG_CORE, config.logLevel, info.domain, info.content,
|
||||
"%{public}s log suppressed cnt %{public}u", config.functionName, supressedCnt);
|
||||
}
|
||||
return true;
|
||||
} else {
|
||||
if (state.printCount++ < config.printFrequency) {
|
||||
return true;
|
||||
} else {
|
||||
state.supressed++;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} // namespace OHOS
|
||||
}
|
||||
Reference in New Issue
Block a user