mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2025-02-17 01:09:22 +00:00
!1841 memory plugin修改为仅debug应用可用,不安全数据过滤
Merge pull request !1841 from zhangyixin/master
This commit is contained in:
commit
054fc01fb8
@ -47,6 +47,7 @@ std::string GetClockStr(const int32_t clockId);
|
||||
void AdaptSandboxPath(std::string& filePath, int pid);
|
||||
int32_t GetPackageUid(const std::string &name);
|
||||
bool GetCurrentUserId(int32_t &userId);
|
||||
bool IsUserMode();
|
||||
bool GetDeveloperMode();
|
||||
bool IsBetaVersion();
|
||||
std::pair<bool, std::string> CheckNotExistsFilePath(const std::string& filePath);
|
||||
|
@ -543,6 +543,16 @@ bool ReadFile(const std::string &filePath, const std::vector<std::string>& valid
|
||||
return true;
|
||||
}
|
||||
|
||||
bool IsUserMode()
|
||||
{
|
||||
std::string debugMode = "0";
|
||||
debugMode = OHOS::system::GetParameter("const.debuggable", debugMode);
|
||||
if (debugMode != "0") {
|
||||
PROFILER_LOG_INFO(LOG_CORE, "It is not user mode!");
|
||||
}
|
||||
return debugMode == "0";
|
||||
}
|
||||
|
||||
std::string GetErrorMsg()
|
||||
{
|
||||
const int bufSize = 256;
|
||||
|
@ -30,6 +30,7 @@ ohos_source_set("memdataplugin_source") {
|
||||
"${OHOS_PROFILER_DIR}/device/base/include",
|
||||
]
|
||||
deps = [
|
||||
"${OHOS_PROFILER_DIR}/device/base:hiprofiler_base",
|
||||
"${OHOS_PROFILER_DIR}/proto_encoder:proto_encoder_source",
|
||||
"${OHOS_PROFILER_DIR}/protos/types/plugins/memory_data:memory_data_cpp",
|
||||
"${OHOS_PROFILER_DIR}/protos/types/plugins/memory_data:memory_data_encoder",
|
||||
|
@ -26,7 +26,7 @@
|
||||
#include <memory>
|
||||
#include <string>
|
||||
#include <sys/mman.h>
|
||||
|
||||
#include "common.h"
|
||||
#include "logging.h"
|
||||
#include "memory_plugin_result.pb.h"
|
||||
|
||||
@ -331,8 +331,13 @@ private:
|
||||
findMapHead = true;
|
||||
if (isReportSmaps) {
|
||||
smapsInfo = processMemoryInfo.add_smapinfo();
|
||||
smapsInfo->set_start_addr(smapsHeadInfo.startAddrStr);
|
||||
smapsInfo->set_end_addr(smapsHeadInfo.endAddrStr);
|
||||
if (!COMMON::IsUserMode()) {
|
||||
smapsInfo->set_start_addr(smapsHeadInfo.startAddrStr);
|
||||
smapsInfo->set_end_addr(smapsHeadInfo.endAddrStr);
|
||||
} else {
|
||||
smapsInfo->set_start_addr("");
|
||||
smapsInfo->set_end_addr("");
|
||||
}
|
||||
smapsInfo->set_permission(smapsHeadInfo.permission);
|
||||
smapsInfo->set_path(smapsHeadInfo.path);
|
||||
smapsInfo->set_category(ParseCategory(smapsHeadInfo));
|
||||
|
@ -194,6 +194,9 @@ int MemoryDataPlugin::Start(const uint8_t* configData, uint32_t configSize)
|
||||
if (protoConfig_.pid().size() > 0) {
|
||||
for (int i = 0; i < protoConfig_.pid().size(); i++) {
|
||||
int32_t pid = protoConfig_.pid(i);
|
||||
if (COMMON::IsUserMode() && (!COMMON::CheckApplicationPermission(pid, ""))) {
|
||||
continue;
|
||||
}
|
||||
pidFds_.emplace(pid, OpenProcPidFiles(pid));
|
||||
}
|
||||
}
|
||||
@ -344,6 +347,9 @@ template <typename T, typename S> void MemoryDataPlugin::WriteMemoryData(T& memo
|
||||
|
||||
for (int i = 0; i < protoConfig_.pid().size(); i++) {
|
||||
int32_t pid = protoConfig_.pid(i);
|
||||
if (COMMON::IsUserMode() && (!COMMON::CheckApplicationPermission(pid, ""))) {
|
||||
continue;
|
||||
}
|
||||
auto* processinfo = memoryDataProto.add_processesinfo();
|
||||
if (protoConfig_.report_process_mem_info()) {
|
||||
WriteProcinfoByPidfds(*processinfo, pid);
|
||||
@ -431,6 +437,9 @@ int MemoryDataPlugin::Stop()
|
||||
|
||||
template <typename T> void MemoryDataPlugin::WriteProcinfoByPidfds(T& processMemoryInfo, int32_t pid)
|
||||
{
|
||||
if (COMMON::IsUserMode() && (!COMMON::CheckApplicationPermission(pid, ""))) {
|
||||
return;
|
||||
}
|
||||
char* end = nullptr;
|
||||
int32_t readSize;
|
||||
|
||||
@ -1286,6 +1295,9 @@ template <typename T> void MemoryDataPlugin::WriteDumpProcessInfo(T& dataProto)
|
||||
{
|
||||
for (int i = 0; i < protoConfig_.pid().size(); i++) {
|
||||
int32_t pid = protoConfig_.pid(i);
|
||||
if (COMMON::IsUserMode() && (!COMMON::CheckApplicationPermission(pid, ""))) {
|
||||
continue;
|
||||
}
|
||||
auto* processesInfo = dataProto.add_processesinfo();
|
||||
processesInfo->set_pid(pid);
|
||||
|
||||
@ -1361,6 +1373,10 @@ template <typename T> void MemoryDataPlugin::WriteManagerServiceInfo(T& dataProt
|
||||
template <typename T> void MemoryDataPlugin::WriteProfileMemInfo(T& dataProto)
|
||||
{
|
||||
for (int i = 0; i < protoConfig_.pid().size(); i++) {
|
||||
int32_t pid = protoConfig_.pid(i);
|
||||
if (COMMON::IsUserMode() && (!COMMON::CheckApplicationPermission(pid, ""))) {
|
||||
continue;
|
||||
}
|
||||
std::string file = "";
|
||||
if (!protoConfig_.report_fake_data()) {
|
||||
if (strcmp(testpath_, "/proc") == 0) {
|
||||
|
@ -29,6 +29,7 @@ ohos_unittest("memdataplugin_ut") {
|
||||
"unittest/memory_data_plugin_unittest.cpp",
|
||||
]
|
||||
deps = [
|
||||
"${OHOS_PROFILER_DIR}/device/base:hiprofiler_base",
|
||||
"${OHOS_PROFILER_DIR}/device/plugins/memory_plugin:memdataplugin_source",
|
||||
"${OHOS_PROFILER_DIR}/device/plugins/memory_plugin:memorytest",
|
||||
"${OHOS_PROFILER_DIR}/protos/types/plugins/memory_data:memory_data_cpp",
|
||||
|
@ -25,6 +25,7 @@ config("module_private_config") {
|
||||
ohos_unittest("plugin_module_api_ut") {
|
||||
module_out_path = module_output_path
|
||||
deps = [
|
||||
"${OHOS_PROFILER_DIR}/device/base:hiprofiler_base",
|
||||
"${OHOS_PROFILER_DIR}/proto_encoder:proto_encoder_source",
|
||||
"${OHOS_PROFILER_DIR}/protos/types/plugins/memory_data:memory_data_cpp",
|
||||
"${OHOS_PROFILER_DIR}/protos/types/plugins/sample_data:sample_data_cpp",
|
||||
|
Loading…
x
Reference in New Issue
Block a user