diff --git a/node.gyp b/node.gyp index 2b125de0d4e58e721124f228af730a14235a5893..d04a7e4721100c7a9fff639e1fe593eff90a0a88 100644 --- a/node.gyp +++ b/node.gyp @@ -29,6 +29,8 @@ 'node_lib_target_name%': 'libjsvm', 'node_intermediate_lib_type%': 'static_library', 'node_builtin_modules_path%': '', + '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 @@ -717,12 +719,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 +1437,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 8e08c808c6ec1689cf293fbb098d7d8a7540d4e8..5e604f05fcf1c457335ea9a455ecc87e890dd97b 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 9d4636298959dcbc273ea78a8f21e96dfa17e8a2..37b14104e65fd6610a27a8ab16dadacc5c797f67 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,41 @@ 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_