diff --git a/adapter/plugins/eventservice/service/idl/src/event_query_wrapper_builder.cpp b/adapter/plugins/eventservice/service/idl/src/event_query_wrapper_builder.cpp index c78179f6..b391040b 100644 --- a/adapter/plugins/eventservice/service/idl/src/event_query_wrapper_builder.cpp +++ b/adapter/plugins/eventservice/service/idl/src/event_query_wrapper_builder.cpp @@ -70,7 +70,7 @@ bool ConditionParser::ParseJsonString(const Json::Value& root, const std::string EventStore::Op ConditionParser::GetOpEnum(const std::string& op) { - const std::unordered_map opMap = { + const std::map opMap = { { "=", EventStore::Op::EQ }, { "<", EventStore::Op::LT }, { ">", EventStore::Op::GT }, diff --git a/adapter/service/server/include/hiview_service_ability_stub.h b/adapter/service/server/include/hiview_service_ability_stub.h index 3e87c009..19023af2 100644 --- a/adapter/service/server/include/hiview_service_ability_stub.h +++ b/adapter/service/server/include/hiview_service_ability_stub.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2023 Huawei Device Co., Ltd. + * Copyright (c) 2021-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,6 +16,8 @@ #ifndef HIVIEW_SERVICE_ABILITY_STUB_H #define HIVIEW_SERVICE_ABILITY_STUB_H +#include + #include "ihiview_service_ability.h" #include "iremote_stub.h" #include "message_parcel.h" @@ -58,10 +60,10 @@ private: bool IsPermissionGranted(uint32_t code); RequestHandler GetRequestHandler(uint32_t code); - std::unordered_map GetRequestHandlers(); - std::unordered_map GetTraceRequestHandlers(); - std::unordered_map GetCpuRequestHandlers(); - std::unordered_map GetMemoryRequestHandlers(); + std::map GetRequestHandlers(); + std::map GetTraceRequestHandlers(); + std::map GetCpuRequestHandlers(); + std::map GetMemoryRequestHandlers(); }; } // namespace HiviewDFX } // namespace OHOS diff --git a/adapter/service/server/src/hiview_service_ability_stub.cpp b/adapter/service/server/src/hiview_service_ability_stub.cpp index 219065e8..91e726f0 100644 --- a/adapter/service/server/src/hiview_service_ability_stub.cpp +++ b/adapter/service/server/src/hiview_service_ability_stub.cpp @@ -15,7 +15,6 @@ #include "hiview_service_ability_stub.h" -#include #include #include "accesstoken_kit.h" @@ -35,7 +34,7 @@ DEFINE_LOG_TAG("HiViewSA-HiViewServiceAbilityStub"); const std::string ASH_MEM_NAME = "HiviewLogLibrary SharedMemory"; constexpr uint32_t ASH_MEM_SIZE = 107 * 5000; // 535k -const std::unordered_map ALL_PERMISSION_MAP = { +const std::map ALL_PERMISSION_MAP = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_LIST), "ohos.permission.READ_HIVIEW_SYSTEM"}, {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_COPY), @@ -60,7 +59,7 @@ const std::unordered_map ALL_PERMISSION_MAP = { "ohos.permission.WRITE_HIVIEW_SYSTEM"} }; -const std::unordered_map TRACE_PERMISSION_MAP = { +const std::map TRACE_PERMISSION_MAP = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_OPEN_SNAPSHOT_TRACE), "ohos.permission.DUMP"}, {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_DUMP_SNAPSHOT_TRACE), @@ -78,16 +77,16 @@ const std::unordered_map TRACE_PERMISSION_MAP = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_GET_APP_TRACE), ""}, }; -const std::unordered_map CPU_PERMISSION_MAP = { +const std::map CPU_PERMISSION_MAP = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_GET_SYSTEM_CPU_USAGE), ""} }; -const std::unordered_map MEMORY_PERMISSION_MAP = { +const std::map MEMORY_PERMISSION_MAP = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_SET_APPRESOURCE_LIMIT), ""}, {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_GET_GRAPHIC_USAGE), ""} }; -bool HasAccessPermission(uint32_t code, const std::unordered_map& permissions) +bool HasAccessPermission(uint32_t code, const std::map& permissions) { using namespace Security::AccessToken; auto iter = permissions.find(code); @@ -141,9 +140,9 @@ bool HiviewServiceAbilityStub::IsPermissionGranted(uint32_t code) HasAccessPermission(code, CPU_PERMISSION_MAP) || HasAccessPermission(code, MEMORY_PERMISSION_MAP); } -std::unordered_map HiviewServiceAbilityStub::GetRequestHandlers() +std::map HiviewServiceAbilityStub::GetRequestHandlers() { - static std::unordered_map requestHandlers = { + static std::map requestHandlers = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_LIST), [this] (MessageParcel& data, MessageParcel& reply, MessageOption& option) { return this->HandleListRequest(data, reply, option); @@ -168,9 +167,9 @@ std::unordered_map HiviewServiceAbilityStub::GetReques return requestHandlers; } -std::unordered_map HiviewServiceAbilityStub::GetTraceRequestHandlers() +std::map HiviewServiceAbilityStub::GetTraceRequestHandlers() { - static std::unordered_map requestHandlers = { + static std::map requestHandlers = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_OPEN_SNAPSHOT_TRACE), [this] (MessageParcel& data, MessageParcel& reply, MessageOption& option) { return this->HandleOpenSnapshotTraceRequest(data, reply, option); @@ -215,9 +214,9 @@ std::unordered_map HiviewServiceAbilityStub::GetTraceR return requestHandlers; } -std::unordered_map HiviewServiceAbilityStub::GetCpuRequestHandlers() +std::map HiviewServiceAbilityStub::GetCpuRequestHandlers() { - static std::unordered_map cpuRequestHandlers = { + static std::map cpuRequestHandlers = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_GET_SYSTEM_CPU_USAGE), [this] (MessageParcel& data, MessageParcel& reply, MessageOption& option) { return HandleGetSysCpuUsageRequest(data, reply, option); @@ -227,9 +226,9 @@ std::unordered_map HiviewServiceAbilityStub::GetCpuReq return cpuRequestHandlers; } -std::unordered_map HiviewServiceAbilityStub::GetMemoryRequestHandlers() +std::map HiviewServiceAbilityStub::GetMemoryRequestHandlers() { - static std::unordered_map memoryRequestHandlers = { + static std::map memoryRequestHandlers = { {static_cast(HiviewServiceInterfaceCode::HIVIEW_SERVICE_ID_SET_APPRESOURCE_LIMIT), [this] (MessageParcel& data, MessageParcel& reply, MessageOption& option) { return HandleSetAppResourceLimitRequest(data, reply, option); @@ -246,7 +245,7 @@ std::unordered_map HiviewServiceAbilityStub::GetMemory RequestHandler HiviewServiceAbilityStub::GetRequestHandler(uint32_t code) { - std::vector> allHandlerMaps = { + std::vector> allHandlerMaps = { GetRequestHandlers(), GetTraceRequestHandlers(), GetCpuRequestHandlers(), diff --git a/base/event_publish/event_publish.cpp b/base/event_publish/event_publish.cpp index 65216575..aa02cfd3 100644 --- a/base/event_publish/event_publish.cpp +++ b/base/event_publish/event_publish.cpp @@ -30,24 +30,24 @@ namespace { DEFINE_LOG_TAG("HiView-EventPublish"); constexpr int VALUE_MOD = 200000; constexpr int DELAY_TIME = 30; -const std::string PATH_DIR = "/data/log/hiview/system_event_db/events/temp"; -const std::string SANDBOX_DIR = "/data/storage/el2/log"; -const std::string FILE_PREFIX = "/hiappevent_"; -const std::string FILE_SUFFIX = ".evt"; -const std::string DOMAIN_PROPERTY = "domain"; -const std::string NAME_PROPERTY = "name"; -const std::string EVENT_TYPE_PROPERTY = "eventType"; -const std::string PARAM_PROPERTY = "params"; -const std::string LOG_OVER_LIMIT = "log_over_limit"; -const std::string EXTERNAL_LOG = "external_log"; -const std::string PID = "pid"; -const std::string IS_BUSINESS_JANK = "is_business_jank"; +constexpr const char* const PATH_DIR = "/data/log/hiview/system_event_db/events/temp"; +constexpr const char* const SANDBOX_DIR = "/data/storage/el2/log"; +constexpr const char* const FILE_PREFIX = "/hiappevent_"; +constexpr const char* const FILE_SUFFIX = ".evt"; +constexpr const char* const DOMAIN_PROPERTY = "domain"; +constexpr const char* const NAME_PROPERTY = "name"; +constexpr const char* const EVENT_TYPE_PROPERTY = "eventType"; +constexpr const char* const PARAM_PROPERTY = "params"; +constexpr const char* const LOG_OVER_LIMIT = "log_over_limit"; +constexpr const char* const EXTERNAL_LOG = "external_log"; +constexpr const char* const PID = "pid"; +constexpr const char* const IS_BUSINESS_JANK = "is_business_jank"; constexpr uint64_t MAX_FILE_SIZE = 5 * 1024 * 1024; // 5M constexpr uint64_t WATCHDOG_MAX_FILE_SIZE = 10 * 1024 * 1024; // 10M constexpr uint64_t RESOURCE_OVERLIMIT_MAX_FILE_SIZE = 2048ull * 1024 * 1024; // 2G -const std::string XATTR_NAME = "user.appevent"; +constexpr const char* const XATTR_NAME = "user.appevent"; constexpr uint64_t BIT_MASK = 1; -const std::unordered_map OS_EVENT_POS_INFOS = { +const std::map OS_EVENT_POS_INFOS = { { EVENT_APP_CRASH, 0 }, { EVENT_APP_FREEZE, 1 }, { EVENT_APP_LAUNCH, 2 }, @@ -400,8 +400,8 @@ void EventPublish::PushEvent(int32_t uid, const std::string& eventName, HiSysEve return; } eventJson[PARAM_PROPERTY] = params; - const std::unordered_set immediateEvents = {"APP_CRASH", "APP_FREEZE", "ADDRESS_SANITIZER", - "APP_LAUNCH", "CPU_USAGE_HIGH", EVENT_MAIN_THREAD_JANK}; + const std::set immediateEvents = {EVENT_APP_CRASH, EVENT_APP_FREEZE, EVENT_ADDRESS_SANITIZER, + EVENT_APP_LAUNCH, EVENT_CPU_USAGE_HIGH, EVENT_MAIN_THREAD_JANK}; if (immediateEvents.find(eventName) != immediateEvents.end()) { SaveEventAndLogToSandBox(uid, eventName, bundleName, eventJson); } else if (eventName == EVENT_RESOURCE_OVERLIMIT) { diff --git a/base/event_publish/include/event_publish.h b/base/event_publish/include/event_publish.h index 4b373725..1d38d596 100644 --- a/base/event_publish/include/event_publish.h +++ b/base/event_publish/include/event_publish.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -27,18 +27,18 @@ namespace OHOS { namespace HiviewDFX { namespace HiAppEvent { -const std::string DOMAIN_OS = "OS"; -const std::string EVENT_APP_CRASH = "APP_CRASH"; -const std::string EVENT_APP_FREEZE = "APP_FREEZE"; -const std::string EVENT_APP_LAUNCH = "APP_LAUNCH"; -const std::string EVENT_SCROLL_JANK = "SCROLL_JANK"; -const std::string EVENT_CPU_USAGE_HIGH = "CPU_USAGE_HIGH"; -const std::string EVENT_BATTERY_USAGE = "BATTERY_USAGE"; -const std::string EVENT_RESOURCE_OVERLIMIT = "RESOURCE_OVERLIMIT"; -const std::string EVENT_ADDRESS_SANITIZER = "ADDRESS_SANITIZER"; -const std::string EVENT_MAIN_THREAD_JANK = "MAIN_THREAD_JANK"; -const std::string EVENT_APP_START = "APP_START"; -} // namespace HiAppEvent +constexpr const char* const DOMAIN_OS = "OS"; +constexpr const char* const EVENT_APP_CRASH = "APP_CRASH"; +constexpr const char* const EVENT_APP_FREEZE = "APP_FREEZE"; +constexpr const char* const EVENT_APP_LAUNCH = "APP_LAUNCH"; +constexpr const char* const EVENT_SCROLL_JANK = "SCROLL_JANK"; +constexpr const char* const EVENT_CPU_USAGE_HIGH = "CPU_USAGE_HIGH"; +constexpr const char* const EVENT_BATTERY_USAGE = "BATTERY_USAGE"; +constexpr const char* const EVENT_RESOURCE_OVERLIMIT = "RESOURCE_OVERLIMIT"; +constexpr const char* const EVENT_ADDRESS_SANITIZER = "ADDRESS_SANITIZER"; +constexpr const char* const EVENT_MAIN_THREAD_JANK = "MAIN_THREAD_JANK"; +constexpr const char* const EVENT_APP_START = "APP_START"; +} class EventPublish : public OHOS::DelayedRefSingleton { public: EventPublish() {}; diff --git a/base/event_store/config/src/event_store_config.cpp b/base/event_store/config/src/event_store_config.cpp index 4bde9d4a..7a44c26e 100644 --- a/base/event_store/config/src/event_store_config.cpp +++ b/base/event_store/config/src/event_store_config.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -28,7 +28,7 @@ const char KEY_PAGE_SIZE[] = "PageSize"; const char KEY_MAX_SIZE[] = "MaxSize"; const char KEY_MAX_FILE_NUM[] = "MaxFileNum"; const char KEY_MAX_FILE_SIZE[] = "MaxFileSize"; -const std::unordered_map EVENT_TYPE_MAP = { +const std::map EVENT_TYPE_MAP = { {"FAULT", 1}, {"STATISTIC", 2}, {"SECURITY", 3}, {"BEHAVIOR", 4} }; diff --git a/base/event_store/dao/doc_query.cpp b/base/event_store/dao/doc_query.cpp index 38895efd..1191033e 100644 --- a/base/event_store/dao/doc_query.cpp +++ b/base/event_store/dao/doc_query.cpp @@ -14,7 +14,7 @@ */ #include "doc_query.h" -#include +#include #include "decoded/decoded_event.h" #include "hiview_logger.h" @@ -40,7 +40,7 @@ void DocQuery::And(const Cond& cond) bool DocQuery::IsInnerCond(const Cond& cond) const { - const std::unordered_set innerFields = { + const std::set innerFields = { EventCol::SEQ, EventCol::TS, EventCol::TZ, EventCol::PID, EventCol::TID, EventCol::UID, }; diff --git a/base/utility/focused_event_util.cpp b/base/utility/focused_event_util.cpp index 668854a6..2e8b2c0a 100644 --- a/base/utility/focused_event_util.cpp +++ b/base/utility/focused_event_util.cpp @@ -16,13 +16,13 @@ #include "focused_event_util.h" #include -#include +#include namespace OHOS { namespace HiviewDFX { namespace FocusedEventUtil { namespace { -const std::unordered_map> FOCUSED_EVENT_MAP { +const std::map> FOCUSED_EVENT_MAP { {"HMOS_SVC_BROKER", {"CONTAINER_LIFECYCLE_EVENT"}}, }; } diff --git a/core/param_update/include/param_const_common.h b/core/param_update/include/param_const_common.h index 975fa67e..4a9175f3 100644 --- a/core/param_update/include/param_const_common.h +++ b/core/param_update/include/param_const_common.h @@ -21,12 +21,13 @@ namespace OHOS { namespace HiviewDFX { - const std::string CONFIG_TYPE = "HIVIEWPARA"; - const std::string CONFIG_UPDATED_ACTION = "usual.event.DUE_SA_CFG_UPDATED"; - const std::string CFG_PATH = "/data/service/el1/public/update/param_service/install/system/etc/HIVIEWPARA/DEFAULT/"; - const std::string PUBKEY_PATH = "/system/etc/hiview/hwkey_param_upgrade_hiviewdfx_v1.pem"; - const std::string LOCAL_CFG_PATH = "/system/etc/hiview/"; - const std::string CLOUD_CFG_PATH = "/data/system/hiview/"; + constexpr const char* const CONFIG_TYPE = "HIVIEWPARA"; + constexpr const char* const CONFIG_UPDATED_ACTION = "usual.event.DUE_SA_CFG_UPDATED"; + constexpr const char* const CFG_PATH = + "/data/service/el1/public/update/param_service/install/system/etc/HIVIEWPARA/DEFAULT/"; + constexpr const char* const PUBKEY_PATH = "/system/etc/hiview/hwkey_param_upgrade_hiviewdfx_v1.pem"; + constexpr const char* const LOCAL_CFG_PATH = "/system/etc/hiview/"; + constexpr const char* const CLOUD_CFG_PATH = "/data/system/hiview/"; } } #endif diff --git a/core/param_update/src/param_manager.cpp b/core/param_update/src/param_manager.cpp index a6badf62..591814a9 100644 --- a/core/param_update/src/param_manager.cpp +++ b/core/param_update/src/param_manager.cpp @@ -74,7 +74,7 @@ bool ParamManager::CopyConfigFiles(const std::vector& files) { for (const std::string& file : files) { std::string dstFile(file); - dstFile.replace(0, CFG_PATH.length(), CLOUD_CFG_PATH); + dstFile.replace(0, strlen(CFG_PATH), CLOUD_CFG_PATH); if (!CopyFile(file, dstFile)) { HIVIEW_LOGI("copy file failed: %{public}s", file.c_str()); } @@ -91,7 +91,7 @@ void ParamManager::GetValidFiles(std::vector& validFiles) if (IsFileNeedIgnore(fileName)) { continue; } - std::string relativedPath(file.substr(CFG_PATH.length())); + std::string relativedPath(file.substr(strlen(CFG_PATH))); if (!ParamReader::VerifyParamFile(relativedPath)) { HIVIEW_LOGE("verify file failed: %{public}s", fileName.c_str()); validFiles.clear(); diff --git a/core/param_update/src/param_reader.cpp b/core/param_update/src/param_reader.cpp index 56237d4f..5d999af4 100644 --- a/core/param_update/src/param_reader.cpp +++ b/core/param_update/src/param_reader.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023-2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -34,15 +34,15 @@ namespace { bool ParamReader::VerifyCertFile() { - std::string certFile = CFG_PATH + "CERT.ENC"; - std::string verifyFile = CFG_PATH + "CERT.SF"; + std::string certFile = std::string(CFG_PATH) + "CERT.ENC"; + std::string verifyFile = std::string(CFG_PATH) + "CERT.SF"; if (!LogSignTools::VerifyFileSign(PUBKEY_PATH, certFile, verifyFile)) { - HIVIEW_LOGE("verify failed %{public}s,%{public}s, %{public}s", PUBKEY_PATH.c_str(), + HIVIEW_LOGE("verify failed %{public}s,%{public}s, %{public}s", PUBKEY_PATH, certFile.c_str(), verifyFile.c_str()); return false; } - std::string manifestFile = CFG_PATH + "MANIFEST.MF"; + std::string manifestFile = std::string(CFG_PATH) + "MANIFEST.MF"; std::ifstream file(verifyFile); if (!file.good()) { HIVIEW_LOGE("Verify is not good"); @@ -72,7 +72,7 @@ bool ParamReader::VerifyCertFile() bool ParamReader::VerifyParamFile(const std::string &filePathStr) { - std::string manifestFile = CFG_PATH + "MANIFEST.MF"; + std::string manifestFile = std::string(CFG_PATH) + "MANIFEST.MF"; std::ifstream file(manifestFile); if (!file.good()) { HIVIEW_LOGE("manifestFile is not good"); diff --git a/framework/native/unified_collection/collector/common_util.cpp b/framework/native/unified_collection/collector/common_util.cpp index cb477150..922466bc 100644 --- a/framework/native/unified_collection/collector/common_util.cpp +++ b/framework/native/unified_collection/collector/common_util.cpp @@ -30,6 +30,7 @@ DEFINE_LOG_TAG("UCollectUtil-CommonUtil"); const std::string EXPORT_FILE_REGEX = "[0-9]{14}(.*)"; const std::string UNDERLINE = "_"; } + template bool CommonUtil::StrToNum(const std::string &sString, T &tX) { std::istringstream iStream(sString); diff --git a/framework/native/unified_collection/collector/io_collector_impl.cpp b/framework/native/unified_collection/collector/io_collector_impl.cpp index f2385a4d..9bc593b7 100644 --- a/framework/native/unified_collection/collector/io_collector_impl.cpp +++ b/framework/native/unified_collection/collector/io_collector_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,7 +16,6 @@ #include "io_collector_impl.h" #include -#include #include #include @@ -501,9 +500,9 @@ void IoCollectorImpl::GetProcIoStats(std::vector& allProcIoStats void IoCollectorImpl::CalculateAllProcIoStats(uint64_t period, bool isUpdate) { - DIR *dir = opendir(PROC.c_str()); + DIR *dir = opendir(PROC); if (dir == nullptr) { - HIVIEW_LOGE("open dir=%{public}s failed.", PROC.c_str()); + HIVIEW_LOGE("open dir=%{public}s failed.", PROC); return; } diff --git a/framework/native/unified_collection/collector/memory_collector_impl.cpp b/framework/native/unified_collection/collector/memory_collector_impl.cpp index c6d49dbe..b5ece0e6 100644 --- a/framework/native/unified_collection/collector/memory_collector_impl.cpp +++ b/framework/native/unified_collection/collector/memory_collector_impl.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -18,7 +18,6 @@ #include #include #include -#include #include #include #include @@ -65,15 +64,15 @@ static std::string GetSavePath(const std::string& preFix, const std::string& ext std::lock_guard lock(g_memMutex); // lock when get save path if ((!FileUtil::FileExists(MEMINFO_SAVE_DIR)) && (!FileUtil::ForceCreateDirectory(MEMINFO_SAVE_DIR, FileUtil::FILE_PERM_755))) { - HIVIEW_LOGE("create %{public}s dir failed.", MEMINFO_SAVE_DIR.c_str()); + HIVIEW_LOGE("create %{public}s dir failed.", MEMINFO_SAVE_DIR); return ""; } std::string timeStamp = GetCurrTimestamp(); - std::string savePath = MEMINFO_SAVE_DIR + "/" + preFix + timeStamp + ext; + std::string savePath = std::string(MEMINFO_SAVE_DIR) + "/" + preFix + timeStamp + ext; int suffix = 0; while (FileUtil::FileExists(savePath)) { std::stringstream ss; - ss << MEMINFO_SAVE_DIR << "/" << preFix << timeStamp << "_" << suffix << ext; + ss << std::string(MEMINFO_SAVE_DIR) << "/" << preFix << timeStamp << "_" << suffix << ext; suffix++; savePath = ss.str(); } @@ -88,22 +87,18 @@ static std::string GetSavePath(const std::string& preFix, const std::string& ext static bool WriteProcessMemoryToFile(std::string& filePath, const std::vector& processMems) { - std::ofstream file; - file.open(filePath.c_str(), std::ios::out | std::ios::trunc); - if (!file.is_open()) { - HIVIEW_LOGE("open %{public}s failed.", filePath.c_str()); + FILE* fp = fopen(filePath.c_str(), "w"); + if (fp == nullptr) { + HIVIEW_LOGE("open %{public}s failed.", FileUtil::ExtractFileName(filePath).c_str()); return false; } + (void)fprintf(fp, "pid\tpname\trss(KB)\tpss(KB)\tswapPss(KB)\tadj\tprocState\n"); - file << "pid" << '\t' << "pname" << '\t' << "rss(KB)" << '\t' << - "pss(KB)" << '\t' << "swapPss(KB)"<< '\t' << "adj" << '\t' << - "procState" << std::endl; for (auto& processMem : processMems) { - file << processMem.pid << '\t' << processMem.name << '\t' << processMem.rss << '\t' << - processMem.pss << '\t' << processMem.swapPss << '\t' << processMem.adj << '\t' << - processMem.procState << std::endl; + (void)fprintf(fp, "%d\t%s\t%d\t%d\t%d\t%d\t%d\n", processMem.pid, processMem.name.c_str(), processMem.rss, + processMem.pss, processMem.swapPss, processMem.adj, processMem.procState); } - file.close(); + (void)fclose(fp); return true; } @@ -244,7 +239,7 @@ static CollectResult CollectRawInfo(const std::string& filePath, co static void SetValueOfProcessMemory(ProcessMemory& processMemory, const std::string& attrName, int32_t value) { - static std::unordered_map> assignFuncMap = { + static std::map> assignFuncMap = { {"Rss", [] (ProcessMemory& memory, int32_t value) { memory.rss = value; }}, @@ -332,7 +327,7 @@ static bool InitProcessMemory(int32_t pid, ProcessMemory& memory) static void SetValueOfSysMemory(SysMemory& sysMemory, const std::string& attrName, int32_t value) { - static std::unordered_map> assignFuncMap = { + static std::map> assignFuncMap = { {"MemTotal", [] (SysMemory& memory, int32_t value) { memory.memTotal = value; }}, diff --git a/framework/native/unified_collection/collector/process_collector_impl.cpp b/framework/native/unified_collection/collector/process_collector_impl.cpp index 693e9d89..66933945 100644 --- a/framework/native/unified_collection/collector/process_collector_impl.cpp +++ b/framework/native/unified_collection/collector/process_collector_impl.cpp @@ -16,7 +16,6 @@ #include "process_collector_impl.h" #include -#include #include "common_util.h" #include "file_util.h" @@ -115,17 +114,16 @@ CollectResult ProcessCollectorImpl::ExportMemCgProcesses() filePath = CommonUtil::CreateExportFile(PROCESS_COLLECTOT_DIR, MAX_FILE_NUM, PREFIX, SUFFIX); } - std::ofstream file; - file.open(filePath.c_str(), std::ios::out | std::ios::trunc); - if (!file.is_open()) { + FILE* fp = fopen(filePath.c_str(), "w"); + if (fp == nullptr) { HIVIEW_LOGW("open %{public}s failed.", FileUtil::ExtractFileName(filePath).c_str()); result.retCode = UcError::WRITE_FAILED; return result; } for (const auto& proc : memCgProcsResult.data) { - file << proc << std::endl; + (void)fprintf(fp, "%d\n", proc); } - file.close(); + (void)fclose(fp); result.data = filePath; result.retCode = UcError::SUCCESS; diff --git a/framework/native/unified_collection/collector/thermal_collector_impl.cpp b/framework/native/unified_collection/collector/thermal_collector_impl.cpp index d4ff56e6..f4d26994 100644 --- a/framework/native/unified_collection/collector/thermal_collector_impl.cpp +++ b/framework/native/unified_collection/collector/thermal_collector_impl.cpp @@ -16,7 +16,7 @@ #include "thermal_collector_impl.h" #include -#include +#include #include "common_util.h" #include "file_util.h" @@ -55,7 +55,7 @@ int32_t GetThermalValue(const std::string& thermalZone) std::string GetZoneTypeStr(ThermalZone thermalZone) { - const std::unordered_map thermalZoneMap = { + const std::map thermalZoneMap = { {SHELL_FRONT, "shell_front"}, {SHELL_FRAME, "shell_frame"}, {SHELL_BACK, "shell_back"}, diff --git a/framework/native/unified_collection/collector/utils/trace_flow_controller.cpp b/framework/native/unified_collection/collector/utils/trace_flow_controller.cpp index ffade475..796f2940 100644 --- a/framework/native/unified_collection/collector/utils/trace_flow_controller.cpp +++ b/framework/native/unified_collection/collector/utils/trace_flow_controller.cpp @@ -16,7 +16,7 @@ #include #include #include -#include +#include #include #include "app_caller_event.h" @@ -50,7 +50,7 @@ int64_t GetActualReliabilitySize() return Parameter::IsLaboratoryMode() ? RELIABILITY_SIZE * 5 : RELIABILITY_SIZE; // 5 : laboratory largen 5 times } -const std::unordered_map> TRACE_QUOTA = { +const std::map> TRACE_QUOTA = { {UCollect::TraceCaller::XPERF, {"xperf", XPERF_SIZE}}, {UCollect::TraceCaller::XPOWER, {"xpower", XPOWER_SIZE}}, {UCollect::TraceCaller::RELIABILITY, {"reliability", GetActualReliabilitySize()}}, diff --git a/framework/native/unified_collection/decorator/cpu_decorator.cpp b/framework/native/unified_collection/decorator/cpu_decorator.cpp index 0d454bb6..8414a582 100644 --- a/framework/native/unified_collection/decorator/cpu_decorator.cpp +++ b/framework/native/unified_collection/decorator/cpu_decorator.cpp @@ -109,7 +109,7 @@ int CpuDecorator::GetCollectPid() void CpuDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/decorator.cpp b/framework/native/unified_collection/decorator/decorator.cpp index fc970b75..0638c91d 100644 --- a/framework/native/unified_collection/decorator/decorator.cpp +++ b/framework/native/unified_collection/decorator/decorator.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -13,13 +13,14 @@ * limitations under the License. */ -#include - #include "decorator.h" namespace OHOS { namespace HiviewDFX { namespace UCollectUtil { +const std::string UC_STAT_LOG_PATH = "/data/log/hiview/unified_collection/ucollection_stat_detail.log"; +const std::string UC_SEPARATOR = "::"; + void StatInfoWrapper::UpdateStatInfo(uint64_t startTime, uint64_t endTime, const std::string& funcName, bool isCallSucc) { std::lock_guard lock(mutex_); @@ -59,20 +60,19 @@ void StatInfoWrapper::ResetStatInfo() statInfos_.clear(); } -void UCDecorator::WriteLinesToFile(const std::vector& stats, bool addBlankLine) +void UCDecorator::WriteLinesToFile(const std::list& stats, bool addBlankLine) { - std::ofstream statFilesStream; - statFilesStream.open(UC_STAT_LOG_PATH, std::ios::app); - if (!statFilesStream.is_open()) { + FILE* fp = fopen(UC_STAT_LOG_PATH.c_str(), "a"); + if (fp == nullptr) { return; } for (const auto& record : stats) { - statFilesStream << record << std::endl; + (void)fprintf(fp, "%s\n", record.c_str()); } if (addBlankLine) { - statFilesStream << std::endl; // write a blank line to separate content + (void)fprintf(fp, "\n"); // write a blank line to separate content } - statFilesStream.close(); + (void)fclose(fp); } } // namespace UCollectUtil } // namespace HiviewDFX diff --git a/framework/native/unified_collection/decorator/gpu_decorator.cpp b/framework/native/unified_collection/decorator/gpu_decorator.cpp index 754ef499..d80fa6b6 100644 --- a/framework/native/unified_collection/decorator/gpu_decorator.cpp +++ b/framework/native/unified_collection/decorator/gpu_decorator.cpp @@ -35,7 +35,7 @@ CollectResult GpuDecorator::CollectSysGpuLoad() void GpuDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/graphic_memory_decorator.cpp b/framework/native/unified_collection/decorator/graphic_memory_decorator.cpp index 5f00f354..11247475 100644 --- a/framework/native/unified_collection/decorator/graphic_memory_decorator.cpp +++ b/framework/native/unified_collection/decorator/graphic_memory_decorator.cpp @@ -30,7 +30,7 @@ CollectResult GraphicMemoryDecorator::GetGraphicUsage(int32_t pid, Grap void GraphicMemoryDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/hiebpf_decorator.cpp b/framework/native/unified_collection/decorator/hiebpf_decorator.cpp index 6ba43325..b3178ab0 100644 --- a/framework/native/unified_collection/decorator/hiebpf_decorator.cpp +++ b/framework/native/unified_collection/decorator/hiebpf_decorator.cpp @@ -39,7 +39,7 @@ CollectResult HiebpfDecorator::StopHiebpf() void HiebpfDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/hilog_decorator.cpp b/framework/native/unified_collection/decorator/hilog_decorator.cpp index 16fdda14..2271d267 100644 --- a/framework/native/unified_collection/decorator/hilog_decorator.cpp +++ b/framework/native/unified_collection/decorator/hilog_decorator.cpp @@ -29,7 +29,7 @@ CollectResult HilogDecorator::CollectLastLog(uint32_t pid, uint32_t void HilogDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/include/decorator.h b/framework/native/unified_collection/decorator/include/decorator.h index d71b5bed..02cfa92d 100644 --- a/framework/native/unified_collection/decorator/include/decorator.h +++ b/framework/native/unified_collection/decorator/include/decorator.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -16,10 +16,10 @@ #ifndef HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_DECORATOR_H #define HIVIEW_FRAMEWORK_NATIVE_UNIFIED_COLLECTION_DECORATOR_H +#include #include #include #include -#include #include "collect_result.h" #include "time_util.h" @@ -27,8 +27,8 @@ namespace OHOS { namespace HiviewDFX { namespace UCollectUtil { -const std::string UC_STAT_LOG_PATH = "/data/log/hiview/unified_collection/ucollection_stat_detail.log"; -const std::string UC_SEPARATOR = "::"; +extern const std::string UC_STAT_LOG_PATH; +extern const std::string UC_SEPARATOR; struct StatInfo { std::string name; @@ -83,7 +83,7 @@ public: } public: - static void WriteLinesToFile(const std::vector& stats, bool addBlankLine); + static void WriteLinesToFile(const std::list& stats, bool addBlankLine); }; } // namespace UCollectUtil } // namespace HiviewDFX diff --git a/framework/native/unified_collection/decorator/include/trace_decorator.h b/framework/native/unified_collection/decorator/include/trace_decorator.h index 0bd0546e..5c8f56b2 100644 --- a/framework/native/unified_collection/decorator/include/trace_decorator.h +++ b/framework/native/unified_collection/decorator/include/trace_decorator.h @@ -32,7 +32,7 @@ struct TraceStatItem { uint32_t latency = 0; }; -const std::unordered_map CallerMap { +const std::map CallerMap { {UCollect::RELIABILITY, "RELIABILITY"}, {UCollect::XPERF, "XPERF"}, {UCollect::XPOWER, "XPOWER"}, diff --git a/framework/native/unified_collection/decorator/io_decorator.cpp b/framework/native/unified_collection/decorator/io_decorator.cpp index 9c6950c6..7df246ef 100644 --- a/framework/native/unified_collection/decorator/io_decorator.cpp +++ b/framework/native/unified_collection/decorator/io_decorator.cpp @@ -85,7 +85,7 @@ CollectResult IoDecorator::ExportSysIoStats() void IoDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/mem_profiler_decorator.cpp b/framework/native/unified_collection/decorator/mem_profiler_decorator.cpp index 1aa66b70..ad6603b1 100644 --- a/framework/native/unified_collection/decorator/mem_profiler_decorator.cpp +++ b/framework/native/unified_collection/decorator/mem_profiler_decorator.cpp @@ -78,7 +78,7 @@ int MemProfilerDecorator::Start(int fd, ProfilerType type, std::string processNa void MemProfilerDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/memory_decorator.cpp b/framework/native/unified_collection/decorator/memory_decorator.cpp index 4cf163b1..8ac3ea02 100644 --- a/framework/native/unified_collection/decorator/memory_decorator.cpp +++ b/framework/native/unified_collection/decorator/memory_decorator.cpp @@ -119,7 +119,7 @@ CollectResult MemoryDecorator::CollectDdrFreq() void MemoryDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/network_decorator.cpp b/framework/native/unified_collection/decorator/network_decorator.cpp index 1c11f32d..3050d0ff 100644 --- a/framework/native/unified_collection/decorator/network_decorator.cpp +++ b/framework/native/unified_collection/decorator/network_decorator.cpp @@ -30,7 +30,7 @@ CollectResult NetworkDecorator::CollectRate() void NetworkDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/perf_decorator.cpp b/framework/native/unified_collection/decorator/perf_decorator.cpp index 8394c290..30f66634 100644 --- a/framework/native/unified_collection/decorator/perf_decorator.cpp +++ b/framework/native/unified_collection/decorator/perf_decorator.cpp @@ -80,7 +80,7 @@ void PerfDecorator::SetReport(bool enable) void PerfDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/process_decorator.cpp b/framework/native/unified_collection/decorator/process_decorator.cpp index 381f6a0f..c8e11970 100644 --- a/framework/native/unified_collection/decorator/process_decorator.cpp +++ b/framework/native/unified_collection/decorator/process_decorator.cpp @@ -42,7 +42,7 @@ CollectResult ProcessDecorator::ExportMemCgProcesses() void ProcessDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/thermal_decorator.cpp b/framework/native/unified_collection/decorator/thermal_decorator.cpp index f635a705..96d5ddb8 100644 --- a/framework/native/unified_collection/decorator/thermal_decorator.cpp +++ b/framework/native/unified_collection/decorator/thermal_decorator.cpp @@ -35,7 +35,7 @@ CollectResult ThermalDecorator::CollectThermaLevel() void ThermalDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/trace_decorator.cpp b/framework/native/unified_collection/decorator/trace_decorator.cpp index 75d02921..8487781a 100644 --- a/framework/native/unified_collection/decorator/trace_decorator.cpp +++ b/framework/native/unified_collection/decorator/trace_decorator.cpp @@ -63,17 +63,17 @@ void TraceDecorator::SaveStatSpecialInfo() { WriteLinesToFile({""}, false); // a blank line after common stat info std::map traceStatInfo = traceStatWrapper_.GetTraceStatInfo(); - std::vector traceFormattedStatInfo = {UC_HITRACE_API_STAT_TITLE, UC_HITRACE_API_STAT_ITEM}; + std::list traceFormattedStatInfo = {UC_HITRACE_API_STAT_TITLE, UC_HITRACE_API_STAT_ITEM}; for (const auto& record : traceStatInfo) { traceFormattedStatInfo.push_back(record.second.ToString()); } WriteLinesToFile(traceFormattedStatInfo, true); - std::vector compressRatio = {UC_HITRACE_COMPRESS_RATIO, std::to_string(TRACE_COMPRESS_RATIO)}; + std::list compressRatio = {UC_HITRACE_COMPRESS_RATIO, std::to_string(TRACE_COMPRESS_RATIO)}; WriteLinesToFile(compressRatio, true); std::map> traceTrafficInfo = traceStatWrapper_.GetTrafficStatInfo(); - std::vector trafficFormattedInfo = {UC_HITRACE_TRAFFIC_STAT_TITLE, UC_HITRACE_TRAFFIC_STAT_ITEM}; + std::list trafficFormattedInfo = {UC_HITRACE_TRAFFIC_STAT_TITLE, UC_HITRACE_TRAFFIC_STAT_ITEM}; for (const auto& record : traceTrafficInfo) { trafficFormattedInfo.insert(trafficFormattedInfo.end(), record.second.begin(), record.second.end()); } @@ -83,7 +83,7 @@ void TraceDecorator::SaveStatSpecialInfo() void TraceDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/decorator/unified_collection_stat.cpp b/framework/native/unified_collection/decorator/unified_collection_stat.cpp index bb131cc9..50e1fd30 100644 --- a/framework/native/unified_collection/decorator/unified_collection_stat.cpp +++ b/framework/native/unified_collection/decorator/unified_collection_stat.cpp @@ -43,9 +43,9 @@ namespace OHOS { namespace HiviewDFX { namespace UCollectUtil { DEFINE_LOG_TAG("UCollectUtil-UCStat"); -const std::string UC_STAT_DATE = "Date:"; -const std::string UC_API_STAT_TITLE = "API statistics:"; -const std::string UC_API_STAT_ITEM = +constexpr const char* const UC_STAT_DATE = "Date:"; +constexpr const char* const UC_API_STAT_TITLE = "API statistics:"; +constexpr const char* const UC_API_STAT_ITEM = "API TotalCall FailCall AvgLatency(us) MaxLatency(us) TotalTimeSpent(us)"; namespace { diff --git a/framework/native/unified_collection/decorator/wm_decorator.cpp b/framework/native/unified_collection/decorator/wm_decorator.cpp index a7aa4ffe..e963cea2 100644 --- a/framework/native/unified_collection/decorator/wm_decorator.cpp +++ b/framework/native/unified_collection/decorator/wm_decorator.cpp @@ -42,7 +42,7 @@ CollectResult WmDecorator::ExportGpuMemory() void WmDecorator::SaveStatCommonInfo() { std::map statInfo = statInfoWrapper_.GetStatInfo(); - std::vector formattedStatInfo; + std::list formattedStatInfo; for (const auto& record : statInfo) { formattedStatInfo.push_back(record.second.ToString()); } diff --git a/framework/native/unified_collection/process/process_status.cpp b/framework/native/unified_collection/process/process_status.cpp index 84fae9e8..a321bdc4 100644 --- a/framework/native/unified_collection/process/process_status.cpp +++ b/framework/native/unified_collection/process/process_status.cpp @@ -14,8 +14,6 @@ */ #include "process_status.h" -#include - #include "common_utils.h" #include "file_util.h" #include "hiview_logger.h" diff --git a/interfaces/inner_api/unified_collection/utility/common_util.h b/interfaces/inner_api/unified_collection/utility/common_util.h index 4a69d37a..e3b241e9 100644 --- a/interfaces/inner_api/unified_collection/utility/common_util.h +++ b/interfaces/inner_api/unified_collection/utility/common_util.h @@ -21,16 +21,16 @@ namespace OHOS { namespace HiviewDFX { namespace UCollectUtil { -const std::string PROC = "/proc/"; -const std::string IO = "/io"; -const std::string SMAPS_ROLLUP = "/smaps_rollup"; -const std::string STATM = "/statm"; -const std::string MEM_INFO = "/proc/meminfo"; -const std::string GPU_CUR_FREQ = "/sys/class/devfreq/gpufreq/cur_freq"; -const std::string GPU_MAX_FREQ = "/sys/class/devfreq/gpufreq/max_freq"; -const std::string GPU_MIN_FREQ = "/sys/class/devfreq/gpufreq/min_freq"; -const std::string GPU_LOAD = "/sys/class/devfreq/gpufreq/gpu_scene_aware/utilisation"; -const std::string MEMINFO_SAVE_DIR = "/data/log/hiview/unified_collection/memory"; +constexpr const char* const PROC = "/proc/"; +constexpr const char* const IO = "/io"; +constexpr const char* const SMAPS_ROLLUP = "/smaps_rollup"; +constexpr const char* const STATM = "/statm"; +constexpr const char* const MEM_INFO = "/proc/meminfo"; +constexpr const char* const GPU_CUR_FREQ = "/sys/class/devfreq/gpufreq/cur_freq"; +constexpr const char* const GPU_MAX_FREQ = "/sys/class/devfreq/gpufreq/max_freq"; +constexpr const char* const GPU_MIN_FREQ = "/sys/class/devfreq/gpufreq/min_freq"; +constexpr const char* const GPU_LOAD = "/sys/class/devfreq/gpufreq/gpu_scene_aware/utilisation"; +constexpr const char* const MEMINFO_SAVE_DIR = "/data/log/hiview/unified_collection/memory"; const static int VSS_BIT = 4; class CommonUtil { diff --git a/interfaces/inner_api/unified_collection/utility/libucollectionutility.map b/interfaces/inner_api/unified_collection/utility/libucollectionutility.map index e892ca24..ae220fd7 100644 --- a/interfaces/inner_api/unified_collection/utility/libucollectionutility.map +++ b/interfaces/inner_api/unified_collection/utility/libucollectionutility.map @@ -64,7 +64,7 @@ "OHOS::HiviewDFX::UCollectUtil::TraceDecorator::SaveStatCommonInfo()"; "OHOS::HiviewDFX::UCollectUtil::WmDecorator::SaveStatCommonInfo()"; "OHOS::HiviewDFX::UCollectUtil::TraceDecorator::SaveStatSpecialInfo()"; - "OHOS::HiviewDFX::UCollectUtil::UCDecorator::WriteLinesToFile(std::__h::vector, std::__h::allocator>, std::__h::allocator, std::__h::allocator>>> const&, bool)"; + "OHOS::HiviewDFX::UCollectUtil::UCDecorator::WriteLinesToFile(std::__h::list, std::__h::allocator>, std::__h::allocator, std::__h::allocator>>> const&, bool)"; }; local: *; diff --git a/interfaces/js/napi/src/hiview_napi_util.cpp b/interfaces/js/napi/src/hiview_napi_util.cpp index 0a79999a..f40d3f4d 100644 --- a/interfaces/js/napi/src/hiview_napi_util.cpp +++ b/interfaces/js/napi/src/hiview_napi_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2023 Huawei Device Co., Ltd. + * Copyright (c) 2023-2024 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -15,6 +15,8 @@ #include "hiview_napi_util.h" +#include + #include "hiview_err_code.h" #include "hiview_logger.h" #include "ipc_skeleton.h" @@ -73,7 +75,7 @@ void HiviewNapiUtil::CreateErrorByRet(napi_env env, const int32_t retCode, napi_ std::pair HiviewNapiUtil::GetErrorDetailByRet(napi_env env, const int32_t retCode) { HIVIEW_LOGI("origin result code is %{public}d.", retCode); - const std::unordered_map> errMap = { + const std::map> errMap = { {HiviewNapiErrCode::ERR_PERMISSION_CHECK, {HiviewNapiErrCode::ERR_PERMISSION_CHECK, "Permission denied. The app does not have the necessary permissions."}}, {HiviewNapiErrCode::ERR_INNER_INVALID_LOGTYPE, diff --git a/plugins/privacy_controller/config/area_policy.cpp b/plugins/privacy_controller/config/area_policy.cpp index c015d511..cd832263 100644 --- a/plugins/privacy_controller/config/area_policy.cpp +++ b/plugins/privacy_controller/config/area_policy.cpp @@ -14,7 +14,7 @@ */ #include "area_policy.h" -#include +#include #include "hiview_logger.h" #include "parameter_ex.h" @@ -24,7 +24,7 @@ namespace OHOS { namespace HiviewDFX { DEFINE_LOG_TAG("AreaPolicy"); namespace { -const std::unordered_map EVENT_LEVELS = { +const std::map EVENT_LEVELS = { {"DEBUG", 1}, {"INFO", 2}, {"MINOR", 3}, {"MAJOR", 4}, {"CRITICAL", 5} }; } diff --git a/plugins/sysevent_source/control/config/daily_config.cpp b/plugins/sysevent_source/control/config/daily_config.cpp index 94720f84..8e0ac1f7 100644 --- a/plugins/sysevent_source/control/config/daily_config.cpp +++ b/plugins/sysevent_source/control/config/daily_config.cpp @@ -62,7 +62,7 @@ bool DailyConfig::ParseCommonThreshold(const cJSON* config) return false; } - const std::unordered_map configMap = { + const std::map configMap = { {"FAULT", TYPE_FAULT}, {"STATISTIC", TYPE_STATISTIC}, {"SECURITY", TYPE_SECURITY}, {"BEHAVIOR", TYPE_BEHAVIOR} }; diff --git a/plugins/sysevent_source/control/config/include/daily_config.h b/plugins/sysevent_source/control/config/include/daily_config.h index 17381b4a..06e2ceaf 100644 --- a/plugins/sysevent_source/control/config/include/daily_config.h +++ b/plugins/sysevent_source/control/config/include/daily_config.h @@ -15,6 +15,7 @@ #ifndef HIVIEW_PLUGINS_SYS_EVENT_SOURCE_CONTROL_CONFIG_INCLUDE_DAILY_CONFIG_H #define HIVIEW_PLUGINS_SYS_EVENT_SOURCE_CONTROL_CONFIG_INCLUDE_DAILY_CONFIG_H +#include #include #include "cjson_util.h" @@ -47,7 +48,7 @@ private: bool isValid_ = false; /* */ - std::unordered_map commonThresholds_; + std::map commonThresholds_; /* <, threshold> */ std::unordered_map, int32_t, EventPairHash> customThresholds_; }; diff --git a/plugins/unified_collector/observer/uc_render_state_observer.cpp b/plugins/unified_collector/observer/uc_render_state_observer.cpp index e5c16d26..c862716e 100644 --- a/plugins/unified_collector/observer/uc_render_state_observer.cpp +++ b/plugins/unified_collector/observer/uc_render_state_observer.cpp @@ -25,7 +25,7 @@ using namespace OHOS::HiviewDFX::UCollectUtil; ProcessState GetProcessState(int32_t state) { - const std::unordered_map renderStates = { + const std::map renderStates = { {0, FOREGROUND}, {1, BACKGROUND}, }; diff --git a/plugins/usage_event_report/include/usage_event_common.h b/plugins/usage_event_report/include/usage_event_common.h index 9fe46955..bfd9cd8b 100644 --- a/plugins/usage_event_report/include/usage_event_common.h +++ b/plugins/usage_event_report/include/usage_event_common.h @@ -71,21 +71,13 @@ namespace FoldEventId { namespace AppEventSpace { const std::string FOREGROUND_EVENT_NAME = "APP_FOREGROUND"; const std::string BACKGROUND_EVENT_NAME = "APP_BACKGROUND"; - const std::string KEY_OF_PROCESS_NAME = "PROCESS_NAME"; const std::string KEY_OF_VERSION_NAME = "VERSION_NAME"; - const std::string KEY_OF_CALLER_BUNDLENAME = "CALLER_BUNDLENAME"; - const std::string KEY_OF_BUNDLE_TYPE = "BUNDLE_TYPE"; - const std::string KEY_OF_VERSION_CODE = "VERSION_CODE"; const std::string KEY_OF_BUNDLE_NAME = "BUNDLE_NAME"; - const std::string KEY_OF_APP_PID = "APP_PID"; - const std::string KEY_OF_PROCESS_TYPE = "PROCESS_TYPE"; } namespace FoldStateChangeEventSpace { const std::string EVENT_NAME = "NOTIFY_FOLD_STATE_CHANGE"; - const std::string KEY_OF_CURRENT_STATUS = "CURRENT_FOLD_STATUS"; const std::string KEY_OF_NEXT_STATUS = "NEXT_FOLD_STATUS"; - const std::string KEY_OF_SENSOR_POSTURE = "SENSOR_POSTURE"; } namespace VhModeChangeEventSpace {