应用运行时信息导出调用新接口

Signed-off-by: ganchuantao <ganchuantao1@huawei.com>
Change-Id: I23211200867ef25b164465619d7fe37e25c70eff
This commit is contained in:
ganchuantao 2023-11-27 19:41:35 +08:00
parent 80bce86cef
commit 44c3b15d18
2 changed files with 36 additions and 31 deletions

View File

@ -15,23 +15,8 @@ import("//build/ohos.gni")
import("//build/ohos/ace/ace.gni")
import("//developtools/profiler/hidebug/hidebug.gni")
config("napi_hidebug_config") {
visibility = [ ":*" ]
include_dirs = [
"//commonlibrary/c_utils/base/include",
"//third_party/node/src",
"//foundation/arkui/napi",
"//foundation/arkui/napi/native_engine",
"//foundation/arkui/napi/interfaces/kits",
"//base/hiviewdfx/hidumper/interfaces/innerkits/include/",
"//foundation/ability/ability_runtime/interfaces/kits/native/appkit/ability_runtime/context",
]
}
ohos_shared_library("hidebug") {
sources = [ "napi_hidebug.cpp" ]
configs = [ ":napi_hidebug_config" ]
external_deps = [
"ability_base:configuration",
@ -40,8 +25,8 @@ ohos_shared_library("hidebug") {
"bundle_framework:appexecfwk_base",
"bundle_framework:appexecfwk_core",
"c_utils:utils",
"hidumper:lib_dump_usage",
"hilog:libhilog",
"hiview:libucollection_utility",
"ipc:ipc_core",
"napi:ace_napi",
"samgr:samgr_proxy",

View File

@ -27,10 +27,11 @@
#include "application_context.h"
#include "context.h"
#include "cpu_collector.h"
#include "directory_ex.h"
#include "dump_usage.h"
#include "hilog/log.h"
#include "iservice_registry.h"
#include "memory_collector.h"
#include "napi/native_api.h"
#include "napi/native_node_api.h"
#include "native_engine/native_engine.h"
@ -355,10 +356,11 @@ napi_value DumpJsHeapData(napi_env env, napi_callback_info info)
napi_value GetPss(napi_env env, napi_callback_info info)
{
napi_value pss;
std::unique_ptr<DumpUsage> dumpUsage = std::make_unique<DumpUsage>();
if (dumpUsage) {
std::shared_ptr<UCollectUtil::MemoryCollector> collector = UCollectUtil::MemoryCollector::Create();
if (collector) {
int pid = getpid();
uint64_t pssInfo = dumpUsage->GetPss(pid);
auto collectResult = collector->CollectProcessMemory(pid);
int32_t pssInfo = collectResult.data.pss;
napi_create_bigint_uint64(env, pssInfo, &pss);
} else {
napi_create_bigint_uint64(env, 0, &pss);
@ -369,10 +371,11 @@ napi_value GetPss(napi_env env, napi_callback_info info)
napi_value GetSharedDirty(napi_env env, napi_callback_info info)
{
napi_value sharedDirty;
std::unique_ptr<DumpUsage> dumpUsage = std::make_unique<DumpUsage>();
if (dumpUsage) {
std::shared_ptr<UCollectUtil::MemoryCollector> collector = UCollectUtil::MemoryCollector::Create();
if (collector) {
int pid = getpid();
uint64_t sharedDirtyInfo = dumpUsage->GetSharedDirty(pid);
auto collectResult = collector->CollectProcessMemory(pid);
int32_t sharedDirtyInfo = collectResult.data.sharedDirty;
napi_create_bigint_uint64(env, sharedDirtyInfo, &sharedDirty);
} else {
napi_create_bigint_uint64(env, 0, &sharedDirty);
@ -383,10 +386,11 @@ napi_value GetSharedDirty(napi_env env, napi_callback_info info)
napi_value GetPrivateDirty(napi_env env, napi_callback_info info)
{
napi_value privateDirtyValue;
std::unique_ptr<DumpUsage> dumpUsage = std::make_unique<DumpUsage>();
if (dumpUsage) {
std::shared_ptr<UCollectUtil::MemoryCollector> collector = UCollectUtil::MemoryCollector::Create();
if (collector) {
pid_t pid = getpid();
uint64_t privateDirty = dumpUsage->GetPrivateDirty(pid);
auto collectResult = collector->CollectProcessMemory(pid);
int32_t privateDirty = collectResult.data.privateDirty;
napi_create_bigint_uint64(env, privateDirty, &privateDirtyValue);
} else {
napi_create_bigint_uint64(env, 0, &privateDirtyValue);
@ -397,11 +401,11 @@ napi_value GetPrivateDirty(napi_env env, napi_callback_info info)
napi_value GetCpuUsage(napi_env env, napi_callback_info info)
{
napi_value cpuUsageValue;
std::unique_ptr<DumpUsage> dumpUsage = std::make_unique<DumpUsage>();
if (dumpUsage) {
std::shared_ptr<UCollectUtil::CpuCollector> collector = UCollectUtil::CpuCollector::Create();
if (collector) {
pid_t pid = getpid();
float tmpCpuUsage = dumpUsage->GetCpuUsage(pid);
double cpuUsage = double(tmpCpuUsage);
auto collectResult = collector->CollectProcessCpuStatInfo(pid);
double cpuUsage = collectResult.data.cpuUsage;
napi_create_double(env, cpuUsage, &cpuUsageValue);
} else {
napi_create_double(env, 0, &cpuUsageValue);
@ -460,6 +464,21 @@ static napi_value GetServiceDump(napi_env env, napi_callback_info info)
return CreateUndefined(env);
}
napi_value GetVss(napi_env env, napi_callback_info info)
{
napi_value vss;
std::shared_ptr<UCollectUtil::MemoryCollector> collector = UCollectUtil::MemoryCollector::Create();
if (collector) {
pid_t pid = getpid();
auto collectResult = collector->CollectProcessVss(pid);
uint64_t vssInfo = collectResult.data;
napi_create_bigint_uint64(env, vssInfo, &vss);
} else {
napi_create_bigint_uint64(env, 0, &vss);
}
return vss;
}
napi_value DeclareHiDebugInterface(napi_env env, napi_value exports)
{
napi_property_descriptor desc[] = {
@ -476,7 +495,8 @@ napi_value DeclareHiDebugInterface(napi_env env, napi_value exports)
DECLARE_NAPI_FUNCTION("getServiceDump", GetServiceDump),
DECLARE_NAPI_FUNCTION("getNativeHeapSize", GetNativeHeapSize),
DECLARE_NAPI_FUNCTION("getNativeHeapAllocatedSize", GetNativeHeapAllocatedSize),
DECLARE_NAPI_FUNCTION("getNativeHeapFreeSize", GetNativeHeapFreeSize)
DECLARE_NAPI_FUNCTION("getNativeHeapFreeSize", GetNativeHeapFreeSize),
DECLARE_NAPI_FUNCTION("getVss", GetVss)
};
NAPI_CALL(env, napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc));
return exports;