mirror of
https://gitee.com/openharmony/resourceschedule_ffrt
synced 2024-11-23 05:20:03 +00:00
log打印优化
Signed-off-by: wangyulie <wanglieyu@126.com>
This commit is contained in:
parent
0b9fc4349a
commit
773ac2db50
13
BUILD.gn
13
BUILD.gn
@ -240,9 +240,22 @@ ohos_prebuilt_etc("blacklist_cfg") {
|
||||
]
|
||||
}
|
||||
|
||||
ohos_prebuilt_etc("log_ctr_whitelist_cfg") {
|
||||
relative_install_dir = "ffrt"
|
||||
source = "log_ctr_whitelist.conf"
|
||||
part_name = "ffrt"
|
||||
subsystem_name = "resourceschedule"
|
||||
install_enable = true
|
||||
install_images = [
|
||||
"system",
|
||||
"updater",
|
||||
]
|
||||
}
|
||||
|
||||
group("ffrt_ndk") {
|
||||
deps = [
|
||||
":blacklist_cfg",
|
||||
":libffrt",
|
||||
":log_ctr_whitelist_cfg",
|
||||
]
|
||||
}
|
||||
|
3
log_ctr_whitelist.conf
Normal file
3
log_ctr_whitelist.conf
Normal file
@ -0,0 +1,3 @@
|
||||
foundation
|
||||
CameraDaemon
|
||||
com.ohos.sceneboard
|
@ -16,18 +16,31 @@
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
#include "faultloggerd_client.h"
|
||||
#endif
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <atomic>
|
||||
#include "ffrt_log_api.h"
|
||||
#include "internal_inc/osal.h"
|
||||
static int g_ffrtLogLevel = FFRT_LOG_DEBUG;
|
||||
static std::atomic<unsigned int> g_ffrtLogId(0);
|
||||
static bool g_whiteListFlag = false;
|
||||
namespace {
|
||||
constexpr int PROCESS_NAME_BUFFER_LENGTH = 1024;
|
||||
constexpr char CONF_FILEPATH[] = "/etc/ffrt/log_ctr_whitelist.conf";
|
||||
}
|
||||
|
||||
unsigned int GetLogId(void)
|
||||
{
|
||||
return ++g_ffrtLogId;
|
||||
}
|
||||
|
||||
bool IsInWhitelist(void)
|
||||
{
|
||||
return g_whiteListFlag;
|
||||
}
|
||||
|
||||
int GetFFRTLogLevel(void)
|
||||
{
|
||||
return g_ffrtLogLevel;
|
||||
@ -45,7 +58,34 @@ static void SetLogLevel(void)
|
||||
}
|
||||
}
|
||||
|
||||
void InitWhiteListFlag(void)
|
||||
{
|
||||
// 获取当前进程名称
|
||||
char processName[PROCESS_NAME_BUFFER_LENGTH] = "";
|
||||
GetProcessName(processName, PROCESS_NAME_BUFFER_LENGTH);
|
||||
if (strlen(processName) == 0) {
|
||||
g_whiteListFlag = true;
|
||||
return;
|
||||
}
|
||||
|
||||
// 从配置文件读取白名单对比
|
||||
std::string whiteProcess;
|
||||
std::ifstream file(CONF_FILEPATH);
|
||||
if (file.is_open()) {
|
||||
while (std::getline(file, whiteProcess)) {
|
||||
if (strstr(processName, whiteProcess.c_str()) != nullptr) {
|
||||
g_whiteListFlag = true;
|
||||
return;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// 当文件不存在或者无权限时默认都开
|
||||
g_whiteListFlag = true;
|
||||
}
|
||||
}
|
||||
|
||||
static __attribute__((constructor)) void LogInit(void)
|
||||
{
|
||||
SetLogLevel();
|
||||
InitWhiteListFlag();
|
||||
}
|
@ -23,6 +23,7 @@
|
||||
#endif
|
||||
#include <string_view>
|
||||
#include "hilog/log.h"
|
||||
#include "internal_inc/osal.h"
|
||||
#include "dfx/bbox/fault_logger_fd_manager.h"
|
||||
#else
|
||||
#include "log_base.h"
|
||||
@ -35,6 +36,8 @@
|
||||
#define FFRT_LOG_LEVEL_MAX (FFRT_LOG_DEBUG + 1)
|
||||
|
||||
unsigned int GetLogId(void);
|
||||
bool IsInWhitelist(void);
|
||||
void InitWhiteListFlag(void);
|
||||
|
||||
#ifdef OHOS_STANDARD_SYSTEM
|
||||
template<size_t N>
|
||||
@ -78,8 +81,10 @@ constexpr auto convertFmtToPublic(const char(&str)[N])
|
||||
#if (FFRT_LOG_LEVEL >= FFRT_LOG_DEBUG)
|
||||
#define FFRT_LOGD(format, ...) \
|
||||
do { \
|
||||
constexpr auto fmtPub = convertFmtToPublic("%u:%s:%d " format); \
|
||||
HILOG_IMPL_STD_ARRAY(LOG_CORE, LOG_DEBUG, fmtPub, GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \
|
||||
if (unlikely(IsInWhitelist())) {\
|
||||
constexpr auto fmtPub = convertFmtToPublic("%u:%s:%d " format); \
|
||||
HILOG_IMPL_STD_ARRAY(LOG_CORE, LOG_DEBUG, fmtPub, GetLogId(), __func__, __LINE__, ##__VA_ARGS__); \
|
||||
} \
|
||||
} while (0)
|
||||
#else
|
||||
#define FFRT_LOGD(format, ...)
|
||||
|
@ -57,5 +57,6 @@ FFRTFacade::FFRTFacade()
|
||||
{
|
||||
DependenceManager::Instance();
|
||||
ProcessExitManager::Instance();
|
||||
InitWhiteListFlag();
|
||||
}
|
||||
} // namespace FFRT
|
Loading…
Reference in New Issue
Block a user