From babcd1b865f5a9d205c6018182f48224708f2182 Mon Sep 17 00:00:00 2001 From: chenraozhong Date: Thu, 6 Jun 2024 17:57:52 +0800 Subject: [PATCH 1/2] Add ReportData in JSVM Signed-off-by: chenraozhong --- node.gyp | 9 +++++++++ src/js_native_api_v8.cc | 6 ++++++ src/js_native_api_v8.h | 40 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+) diff --git a/node.gyp b/node.gyp index 2b125de0..6cbb8c40 100644 --- a/node.gyp +++ b/node.gyp @@ -29,6 +29,7 @@ 'node_lib_target_name%': 'libjsvm', 'node_intermediate_lib_type%': 'static_library', 'node_builtin_modules_path%': '', + 'NDK_SYS_ROOT': '<(PRODUCT_DIR)/../../../../../../../../../../out/generic_generic_arm_64only/general_all_phone_standard', 'linked_module_files': [ ], # We list the deps/ files out instead of globbing them in js2c.py since we @@ -717,12 +718,16 @@ # Warn when using deprecated V8 APIs. 'V8_DEPRECATION_WARNINGS=1', 'NODE_OPENSSL_SYSTEM_CERT_PATH="<(openssl_system_ca_path)"', + 'TARGET_OHOS', ], # - "C4244: conversion from 'type1' to 'type2', possible loss of data" # Ususaly safe. Disable for `dep`, enable for `src` 'msvs_disabled_warnings!': [4244], + 'ldflags' : [ + '<(NDK_SYS_ROOT)/resourceschedule/resource_schedule_service/libressched_client.z.so', + ], 'conditions': [ [ 'openssl_default_cipher_list!=""', { 'defines': [ @@ -1431,6 +1436,10 @@ ], 'defines': [ 'NODE_WANT_INTERNALS=1' ], + + 'ldflags' : [ + '<(NDK_SYS_ROOT)/resourceschedule/resource_schedule_service/libressched_client.z.so' + ], 'sources': [ 'src/node_snapshot_stub.cc', diff --git a/src/js_native_api_v8.cc b/src/js_native_api_v8.cc index 8e08c808..5e604f05 100644 --- a/src/js_native_api_v8.cc +++ b/src/js_native_api_v8.cc @@ -1315,6 +1315,9 @@ v8::Platform* JSVM_Env__::platform() { JSVM_Status JSVM_CDECL OH_JSVM_Init(const JSVM_InitOptions* options) { +#ifdef TARGET_OHOS + v8impl::ResourceSchedule::ReportKeyThread(getuid(), getprocpid(), getproctid()); +#endif v8::V8::InitializePlatform(v8impl::g_platform.get()); if (options && options->argc && options->argv) { @@ -1341,6 +1344,9 @@ JSVM_Status JSVM_CDECL OH_JSVM_GetVM(JSVM_Env env, JSVM_Status JSVM_CDECL OH_JSVM_CreateVM(const JSVM_CreateVMOptions* options, JSVM_VM* result) { +#ifdef TARGET_OHOS + v8impl::ResourceSchedule::ReportKeyThread(getuid(), getprocpid(), getproctid()); +#endif v8::Isolate::CreateParams create_params; auto externalReferences = v8impl::externalReferenceRegistry.data(); create_params.external_references = externalReferences; diff --git a/src/js_native_api_v8.h b/src/js_native_api_v8.h index 9d463629..5d5b7b78 100644 --- a/src/js_native_api_v8.h +++ b/src/js_native_api_v8.h @@ -4,6 +4,12 @@ #include "jsvm_types.h" #include "js_native_api_v8_internals.h" +#ifdef TARGET_OHOS +#include +extern "C" void ReportData(uint32_t resType, int64_t value, + const std::unordered_map& mapPayLoad); +#endif + inline JSVM_Status jsvm_clear_last_error(JSVM_Env env); namespace v8impl { @@ -543,6 +549,40 @@ inline void CfgFinalizedCallback(JSVM_Env env, void* finalizeData, void* finaliz } delete cfg; } + +#ifdef TARGET_OHOS +namespace ResourceSchedule { +namespace ResType { +enum : uint32_t { + RES_TYPE_REPORT_KEY_THREAD = 39 +}; + +enum ReportChangeStatus : int64_t { + CREATE = 0, + REMOVE = 1, +}; + +enum ThreadRole : int64_t { + USER_INTERACT = 0, + NORMAL_DISPLAY = 1, + IMPORTANT_DISPLAY = 2, + NORMAL_AUDIO = 3, + IMPORTANT_AUDIO = 4, + IMAGE_DECODE = 5, +}; +} + +static inline void ReportKeyThread(uid_t uid, pid_t pid, pid_t tid) +{ + std::unordered_map payLoad = { + {"uid", std::to_string(uid)}, + {"pid", std::to_string(pid)}, + {"tid", std::to_string(tid)}, + {"role", std::to_string(v8impl::ResourceSchedule::ResType::ThreadRole::IMPORTANT_DISPLAY)}}; + ReportData(v8impl::ResourceSchedule::ResType::RES_TYPE_REPORT_KEY_THREAD, v8impl::ResourceSchedule::ResType::ReportChangeStatus::CREATE, payLoad); +} +} +#endif } // end of namespace v8impl #endif // SRC_JS_NATIVE_API_V8_H_ -- Gitee From 98896a375b1f6f6e3146ffdf5d88d0547f0afd53 Mon Sep 17 00:00:00 2001 From: chenraozhong Date: Sat, 8 Jun 2024 19:36:55 +0800 Subject: [PATCH 2/2] Add ReportData in JSVM Signed-off-by: chenraozhong --- node.gyp | 3 ++- src/js_native_api_v8.h | 7 ++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/node.gyp b/node.gyp index 6cbb8c40..d04a7e47 100644 --- a/node.gyp +++ b/node.gyp @@ -29,7 +29,8 @@ 'node_lib_target_name%': 'libjsvm', 'node_intermediate_lib_type%': 'static_library', 'node_builtin_modules_path%': '', - 'NDK_SYS_ROOT': '<(PRODUCT_DIR)/../../../../../../../../../../out/generic_generic_arm_64only/general_all_phone_standard', + 'TARGET_DIR': '$(TARGET_GEN_DIR)', + 'NDK_SYS_ROOT': '<(TARGET_DIR)/../../../../..', 'linked_module_files': [ ], # We list the deps/ files out instead of globbing them in js2c.py since we diff --git a/src/js_native_api_v8.h b/src/js_native_api_v8.h index 5d5b7b78..37b14104 100644 --- a/src/js_native_api_v8.h +++ b/src/js_native_api_v8.h @@ -559,7 +559,7 @@ enum : uint32_t { enum ReportChangeStatus : int64_t { CREATE = 0, - REMOVE = 1, + REMOVE = 1 }; enum ThreadRole : int64_t { @@ -568,7 +568,7 @@ enum ThreadRole : int64_t { IMPORTANT_DISPLAY = 2, NORMAL_AUDIO = 3, IMPORTANT_AUDIO = 4, - IMAGE_DECODE = 5, + IMAGE_DECODE = 5 }; } @@ -579,7 +579,8 @@ static inline void ReportKeyThread(uid_t uid, pid_t pid, pid_t tid) {"pid", std::to_string(pid)}, {"tid", std::to_string(tid)}, {"role", std::to_string(v8impl::ResourceSchedule::ResType::ThreadRole::IMPORTANT_DISPLAY)}}; - ReportData(v8impl::ResourceSchedule::ResType::RES_TYPE_REPORT_KEY_THREAD, v8impl::ResourceSchedule::ResType::ReportChangeStatus::CREATE, payLoad); + ReportData(v8impl::ResourceSchedule::ResType::RES_TYPE_REPORT_KEY_THREAD, + v8impl::ResourceSchedule::ResType::ReportChangeStatus::CREATE, payLoad); } } #endif -- Gitee