mirror of
https://gitee.com/openharmony/developtools_profiler
synced 2024-11-27 00:51:47 +00:00
Merge branch 'master' of gitee.com:openharmony/developtools_profiler into master
Signed-off-by: 卢韬 <lutao31@huawei.com>
This commit is contained in:
commit
22db6bb18b
@ -68,6 +68,7 @@
|
||||
"//developtools/profiler/device:hiprofiler_targets",
|
||||
"//developtools/profiler/hidebug/interfaces/js/kits:profiler_jsapi_module",
|
||||
"//developtools/profiler/hidebug/frameworks/hidebug_ndk:ohhidebug",
|
||||
"//developtools/profiler/hidebug/frameworks/native:hidebug_native",
|
||||
"//developtools/profiler/host/smartperf/client/client_command/:SP_daemon",
|
||||
"//developtools/profiler/host/smartperf/client/:SmartPerf",
|
||||
"//developtools/profiler/host/smartperf/client/client_command_fps/:GP_daemon_fps",
|
||||
|
@ -14,7 +14,8 @@
|
||||
"ohos.permission.READ_DFX_SYSEVENT",
|
||||
"ohos.permission.WRITE_HIVIEW_SYSTEM",
|
||||
"ohos.permission.READ_HIVIEW_SYSTEM",
|
||||
"ohos.permission.GET_BUNDLE_INFO"
|
||||
"ohos.permission.GET_BUNDLE_INFO",
|
||||
"ohos.permission.GET_BUNDLE_INFO_PRIVILEGED"
|
||||
]
|
||||
}
|
||||
]
|
||||
|
@ -136,12 +136,14 @@ ohos_executable("native_daemon") {
|
||||
"samgr:samgr_proxy",
|
||||
]
|
||||
|
||||
defines = [ "ENABLE_HAP_EXTRACTOR" ]
|
||||
|
||||
if (hiprofiler_use_libunwinder) {
|
||||
external_deps += [ "faultloggerd:libunwinder_static" ]
|
||||
}
|
||||
|
||||
if (current_toolchain != host_toolchain) {
|
||||
defines = [ "HAVE_HILOG" ]
|
||||
defines += [ "HAVE_HILOG" ]
|
||||
external_deps += [ "hilog:libhilog" ]
|
||||
}
|
||||
use_exceptions = true
|
||||
|
@ -126,6 +126,7 @@ void NativeMemoryProfilerSaService::StopHook(uint32_t pid, std::string name, boo
|
||||
{
|
||||
if (!HasProfilingPermission()) {
|
||||
PROFILER_LOG_ERROR(LOG_CORE, "StopHook failed, no profiling permission!");
|
||||
return;
|
||||
}
|
||||
std::lock_guard<std::mutex> guard(mtx_);
|
||||
std::shared_ptr<TaskConfig> config = nullptr;
|
||||
|
@ -96,8 +96,10 @@ ohos_unittest("native_memory_profiler_sa_ut") {
|
||||
"unittest/native_memory_profiler_sa_service_test.cpp",
|
||||
]
|
||||
|
||||
defines = [ "ENABLE_HAP_EXTRACTOR" ]
|
||||
|
||||
if (current_toolchain != host_toolchain) {
|
||||
defines = [ "HAVE_HILOG" ]
|
||||
defines += [ "HAVE_HILOG" ]
|
||||
external_deps = [ "hilog:libhilog" ]
|
||||
}
|
||||
|
||||
|
@ -26,12 +26,14 @@
|
||||
#include "init_param.h"
|
||||
#include "native_memory_profiler_sa_client_manager.h"
|
||||
#include "utilities.h"
|
||||
#include "token_setproc.h"
|
||||
#include "accesstoken_kit.h"
|
||||
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace {
|
||||
const std::string NATIVE_PARAM = "hiviewdfx.hiprofiler.native_memoryd.start";
|
||||
const std::string TEST_HAP_NAME = "cn.openharmony.rebound_project";
|
||||
const std::string TEST_PROC_NAME = "hiview";
|
||||
}
|
||||
|
||||
class NativeMemoryProfilerSaClientManagerTest : public testing::Test {
|
||||
@ -53,6 +55,9 @@ public:
|
||||
HWTEST_F(NativeMemoryProfilerSaClientManagerTest, NativeMemoryProfilerSaClientManagerTest001, TestSize.Level3)
|
||||
{
|
||||
using namespace OHOS::Developtools::NativeDaemon;
|
||||
using namespace OHOS::Security::AccessToken;
|
||||
AccessTokenID tokenID = AccessTokenKit::GetNativeTokenId(TEST_PROC_NAME);
|
||||
SetSelfTokenID(tokenID);
|
||||
std::shared_ptr<NativeMemoryProfilerSaConfig> config = std::make_shared<NativeMemoryProfilerSaConfig>();
|
||||
EXPECT_NE(config, nullptr);
|
||||
|
||||
@ -80,7 +85,7 @@ HWTEST_F(NativeMemoryProfilerSaClientManagerTest, NativeMemoryProfilerSaClientMa
|
||||
sleep(1);
|
||||
|
||||
using namespace OHOS::Developtools::NativeDaemon;
|
||||
int32_t pid = GetProcessPid(TEST_HAP_NAME);
|
||||
int32_t pid = GetProcessPid(TEST_PROC_NAME);
|
||||
EXPECT_NE(pid, 0);
|
||||
std::shared_ptr<NativeMemoryProfilerSaConfig> config = std::make_shared<NativeMemoryProfilerSaConfig>();
|
||||
EXPECT_NE(config, nullptr);
|
||||
@ -92,20 +97,28 @@ HWTEST_F(NativeMemoryProfilerSaClientManagerTest, NativeMemoryProfilerSaClientMa
|
||||
|
||||
EXPECT_EQ(NativeMemoryProfilerSaClientManager::Start(config), RET_OK);
|
||||
sleep(2);
|
||||
EXPECT_EQ(NativeMemoryProfilerSaClientManager::Stop(TEST_HAP_NAME), RET_OK);
|
||||
|
||||
EXPECT_EQ(NativeMemoryProfilerSaClientManager::Stop(TEST_PROC_NAME), RET_OK);
|
||||
EXPECT_GE(SystemSetParameter(NATIVE_PARAM.c_str(), "0"), 0);
|
||||
sleep(1);
|
||||
EXPECT_GE(SystemSetParameter(NATIVE_PARAM.c_str(), "2"), 0);
|
||||
sleep(1);
|
||||
EXPECT_EQ(NativeMemoryProfilerSaClientManager::Start(
|
||||
NativeMemoryProfilerSaClientManager::NativeMemProfilerType::MEM_PROFILER_CALL_STACK,
|
||||
pid, 10, 0), RET_OK);
|
||||
sleep(2);
|
||||
EXPECT_EQ(NativeMemoryProfilerSaClientManager::Stop(pid), RET_OK);
|
||||
|
||||
EXPECT_GE(SystemSetParameter(NATIVE_PARAM.c_str(), "0"), 0);
|
||||
sleep(1);
|
||||
EXPECT_GE(SystemSetParameter(NATIVE_PARAM.c_str(), "2"), 0);
|
||||
sleep(1);
|
||||
uint32_t fd = open("/data/local/tmp/test_dump_data.htrace",
|
||||
O_CREAT | O_RDWR, S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
|
||||
EXPECT_GT(fd, 0);
|
||||
EXPECT_EQ(NativeMemoryProfilerSaClientManager::DumpData(fd, config), RET_OK);
|
||||
sleep(2);
|
||||
EXPECT_EQ(NativeMemoryProfilerSaClientManager::Stop(pid), RET_OK);
|
||||
EXPECT_GE(SystemSetParameter(NATIVE_PARAM.c_str(), "0"), 0);
|
||||
sleep(1);
|
||||
}
|
||||
|
||||
#endif // NATIVE_MEMORY_PROFILER_SA_CLINET_MANAGER_TEST_H
|
@ -26,7 +26,7 @@
|
||||
using namespace testing::ext;
|
||||
|
||||
namespace {
|
||||
const std::string TEST_HAP_NAME = "cn.openharmony.rebound_project";
|
||||
const std::string TEST_PROC_NAME = "hiview";
|
||||
const std::string NATIVE_PARAM = "hiviewdfx.hiprofiler.native_memoryd.start";
|
||||
constexpr uint32_t TEST_DURATION = 10;
|
||||
constexpr uint32_t TEST_SHARE_MEMORY_SIZE = 4096;
|
||||
@ -54,7 +54,7 @@ HWTEST_F(NativeMemoryProfilerSaServiceTest, NativeMemoryProfilerSaServiceTest001
|
||||
std::shared_ptr<NativeMemoryProfilerSaConfig> config = std::make_shared<NativeMemoryProfilerSaConfig>();
|
||||
EXPECT_NE(config, nullptr);
|
||||
|
||||
int32_t pid = GetProcessPid(TEST_HAP_NAME);
|
||||
int32_t pid = GetProcessPid(TEST_PROC_NAME);
|
||||
EXPECT_NE(pid, 0);
|
||||
config->pid_ = pid;
|
||||
config->duration_ = TEST_DURATION;
|
||||
@ -86,7 +86,7 @@ HWTEST_F(NativeMemoryProfilerSaServiceTest, NativeMemoryProfilerSaServiceTest002
|
||||
std::shared_ptr<NativeMemoryProfilerSaConfig> config = std::make_shared<NativeMemoryProfilerSaConfig>();
|
||||
EXPECT_NE(config, nullptr);
|
||||
|
||||
int32_t pid = GetProcessPid(TEST_HAP_NAME);
|
||||
int32_t pid = GetProcessPid(TEST_PROC_NAME);
|
||||
EXPECT_NE(pid, 0);
|
||||
config->pid_ = pid;
|
||||
config->duration_ = TEST_DURATION;
|
||||
|
@ -481,8 +481,6 @@ bool HookManager::DestroyPluginSession(const std::vector<uint32_t>& pluginIds)
|
||||
bool HookManager::StartPluginSession(const std::vector<uint32_t>& pluginIds,
|
||||
const std::vector<ProfilerPluginConfig>& config, PluginResult& result)
|
||||
{
|
||||
std::string cmd = "rm -rf /data/local/tmp/*-malloc-stats*";
|
||||
system(cmd.c_str());
|
||||
UNUSED_PARAMETER(config);
|
||||
if (hookCtx_.empty()) {
|
||||
return false;
|
||||
|
@ -127,8 +127,9 @@ ohos_unittest("native_daemon_ut") {
|
||||
"faultloggerd:libunwinder_static",
|
||||
"init:libbegetutil",
|
||||
]
|
||||
defines = [ "ENABLE_HAP_EXTRACTOR" ]
|
||||
if (current_toolchain != host_toolchain) {
|
||||
defines = [ "HAVE_HILOG" ]
|
||||
defines += [ "HAVE_HILOG" ]
|
||||
external_deps += [ "hilog:libhilog" ]
|
||||
}
|
||||
}
|
||||
|
@ -21,7 +21,7 @@ ohos_shared_library("ohhidebug") {
|
||||
|
||||
sources = [ "hidebug_ndk.cpp" ]
|
||||
|
||||
deps = [ "../native:libhidebug_source" ]
|
||||
deps = [ "../native:hidebug_native" ]
|
||||
|
||||
external_deps = [
|
||||
"hilog:libhilog",
|
||||
|
@ -17,25 +17,14 @@ import("//developtools/profiler/hidebug/hidebug.gni")
|
||||
ohos_source_set("libhidebug_source") {
|
||||
part_name = "${OHOS_PROFILER_PART_NAME}"
|
||||
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
|
||||
include_dirs = [
|
||||
"../../interfaces/native/innerkits/include",
|
||||
"include",
|
||||
]
|
||||
include_dirs = [ "../../interfaces/native/innerkits/include" ]
|
||||
|
||||
sources = [
|
||||
"hidebug_base.c",
|
||||
"src/hidebug_app_thread_cpu.cpp",
|
||||
"src/hidebug_native_interface_impl.cpp",
|
||||
]
|
||||
sources = [ "hidebug_base.c" ]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hichecker:libhichecker",
|
||||
"hidumper:lib_dump_usage",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"hiview:libucollection_client",
|
||||
"hiview:libucollection_utility",
|
||||
"init:libbegetutil",
|
||||
]
|
||||
}
|
||||
@ -51,3 +40,23 @@ ohos_source_set("libhidebug_init_source") {
|
||||
sources = [ "hidebug_base.c" ]
|
||||
deps = [ "//third_party/bounds_checking_function:libsec_static" ]
|
||||
}
|
||||
|
||||
ohos_shared_library("hidebug_native") {
|
||||
part_name = "${OHOS_PROFILER_PART_NAME}"
|
||||
subsystem_name = "${OHOS_PROFILER_SUBSYS_NAME}"
|
||||
include_dirs = [ "include" ]
|
||||
|
||||
sources = [
|
||||
"src/hidebug_app_thread_cpu.cpp",
|
||||
"src/hidebug_native_interface_impl.cpp",
|
||||
]
|
||||
|
||||
external_deps = [
|
||||
"c_utils:utils",
|
||||
"hidumper:lib_dump_usage",
|
||||
"hilog:libhilog",
|
||||
"hitrace:hitrace_meter",
|
||||
"hiview:libucollection_client",
|
||||
"hiview:libucollection_utility",
|
||||
]
|
||||
}
|
||||
|
@ -26,7 +26,7 @@ ohos_shared_library("hidebug") {
|
||||
"napi_hidebug_init.cpp",
|
||||
]
|
||||
|
||||
deps = [ "$hidebug_path/frameworks/native:libhidebug_source" ]
|
||||
deps = [ "$hidebug_path/frameworks/native:hidebug_native" ]
|
||||
|
||||
external_deps = [
|
||||
"ability_base:configuration",
|
||||
|
@ -83,7 +83,7 @@ int GpuCounter::Init(std::string packageName, std::map<std::string, std::string>
|
||||
}
|
||||
if ((!SPUtils::FileAccess(constV2File)) || (!SPUtils::FileAccess(constExecFile)) ||
|
||||
(!SPUtils::FileAccess(constConfigFile)) || (!SPUtils::FileAccess(constLibFile))) {
|
||||
errorInfo = "Missing dependency files such as XX counters_collector";
|
||||
errorInfo = "Missing dependency files such as counters_collector";
|
||||
ret = -1;
|
||||
break;
|
||||
}
|
||||
@ -141,17 +141,14 @@ int GpuCounter::Start()
|
||||
LOGW("read config duration failed,load default(%ll)", captureDuration);
|
||||
}
|
||||
|
||||
ThreadCapture();
|
||||
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(WAIT_EXIT_TIME));
|
||||
std::vector<std::string> pidList;
|
||||
GetCounterId(pidList);
|
||||
|
||||
if (!pidList.empty()) {
|
||||
ret = 0;
|
||||
startCaptureTime = SPUtils::GetCurTime();
|
||||
ret = Capture();
|
||||
if (ret) {
|
||||
LOGW("counters_collector run failed ret(%d)", ret);
|
||||
return -1;
|
||||
}
|
||||
|
||||
startCaptureTime = SPUtils::GetCurTime();
|
||||
|
||||
LOGI("GpuCounter Started ret(%d)", ret);
|
||||
return ret;
|
||||
}
|
||||
@ -267,19 +264,10 @@ long long GpuCounter::GetCounterDuration()
|
||||
return ret;
|
||||
}
|
||||
|
||||
void GpuCounter::ThreadCapture()
|
||||
{
|
||||
std::thread t(&GpuCounter::Capture, this);
|
||||
t.detach();
|
||||
}
|
||||
|
||||
void GpuCounter::Capture()
|
||||
int GpuCounter::Capture()
|
||||
{
|
||||
std::string result;
|
||||
|
||||
std::cout << " Start GPU time=" << SPUtils::GetCurTime() << std::endl;
|
||||
SPUtils::LoadCmd(constCmd, result);
|
||||
std::cout << "End GPU result=" << result << " time=" << SPUtils::GetCurTime() << std::endl;
|
||||
return system(constCmd.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -45,8 +45,7 @@ public:
|
||||
private:
|
||||
void GetCounterId(std::vector<std::string> &pidList);
|
||||
void KillCounter();
|
||||
void ThreadCapture();
|
||||
void Capture();
|
||||
int Capture();
|
||||
|
||||
private:
|
||||
bool isStop = false;
|
||||
@ -62,19 +61,19 @@ private:
|
||||
const std::string constKillProcess = "kill -9 ";
|
||||
const std::string constGetCounterId = "pidof counters_collector";
|
||||
const std::string constRmCsv = "rm /data/local/tmp/gpu_conter.csv";
|
||||
const std::string constAddPermissionsCounter = "chmod 777 /data/local/tmp/counters_collector";
|
||||
const std::string constAddPermissionsCounter = "chmod 777 /bin/counters_collector";
|
||||
const std::string constCmd =
|
||||
"LD_LIBRARY_PATH=/data/local/tmp/ /data/local/tmp/counters_collector /data/local/tmp/config.txt &";
|
||||
"LD_LIBRARY_PATH=/bin/ /bin/counters_collector /bin/config.txt &";
|
||||
|
||||
const std::string constSandBoxFile = "/files/";
|
||||
const std::string constSandBoxPath = "/data/app/el2/100/base/";
|
||||
const std::string constOutDestCVSPrefix = "gpu_counter";
|
||||
const std::string constOutSourCVSFile = "/data/local/tmp/gpu_counter.csv";
|
||||
|
||||
const std::string constConfigFile = "/data/local/tmp/config.txt";
|
||||
const std::string constExecFile = "/data/local/tmp/counters_collector";
|
||||
const std::string constLibFile = "/data/local/tmp/libGPU_PCM.so";
|
||||
const std::string constV2File = "/data/local/tmp/counters_collector_v2.txt";
|
||||
const std::string constConfigFile = "/bin/config.txt";
|
||||
const std::string constExecFile = "/bin/counters_collector";
|
||||
const std::string constLibFile = "/bin/libGPU_PCM.so";
|
||||
const std::string constV2File = "/bin/counters_collector_v2.txt";
|
||||
const std::string constCheckProductInfo = "param get const.product.name";
|
||||
const std::string constProductInfo = "Mate 60 Pro";
|
||||
|
||||
|
@ -88,9 +88,15 @@ int SpServerSocket::Send(std::string sendBuf)
|
||||
|
||||
void SpServerSocket::Close()
|
||||
{
|
||||
shutdown(sock, SHUT_RD);
|
||||
close(sock);
|
||||
sock = -1;
|
||||
int optval = 1;
|
||||
setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, &optval, sizeof(optval));
|
||||
local.sin_family = AF_INET;
|
||||
local.sin_port = htons(sockPort);
|
||||
local.sin_addr.s_addr = htonl(INADDR_ANY);
|
||||
if (::bind(sock, reinterpret_cast<struct sockaddr *>(&local), sizeof(local)) < 0) {
|
||||
std::cout << "Socket Bind failed:" << sock << std::endl;
|
||||
LOGI("SpServerSocket::Init Socket Bind failed");
|
||||
}
|
||||
}
|
||||
|
||||
int SpServerSocket::Recvfrom()
|
||||
|
Loading…
Reference in New Issue
Block a user