!1623 需求,【hidebug】获取应用进程的jsheap内存上限接口

Merge pull request !1623 from zhou_xq/master
This commit is contained in:
openharmony_ci 2024-05-29 00:40:32 +00:00 committed by Gitee
commit fafced73b1
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F
2 changed files with 10 additions and 0 deletions

View File

@ -710,12 +710,21 @@ napi_value GetAppMemoryLimit(napi_env env, napi_callback_info info)
napi_set_named_property(env, appMemoryLimit, "vssLimit", vssLimit);
NativeEngine *engine = reinterpret_cast<NativeEngine *>(env);
if (engine == nullptr) {
return CreateUndefined(env);
}
napi_value vmHeapLimit;
uint64_t vmHeapLimitValue = engine->GetHeapLimitSize();
vmHeapLimitValue = vmHeapLimitValue >> BYTE_2_KB_SHIFT_BITS;
napi_create_bigint_uint64(env, vmHeapLimitValue, &vmHeapLimit);
napi_set_named_property(env, appMemoryLimit, "vmHeapLimit", vmHeapLimit);
napi_value vmTotalHeapSize;
uint64_t vmTotalHeapSizeValue = engine->GetProcessHeapLimitSize();
vmTotalHeapSizeValue = vmTotalHeapSizeValue >> BYTE_2_KB_SHIFT_BITS;
napi_create_bigint_uint64(env, vmTotalHeapSizeValue, &vmTotalHeapSize);
napi_set_named_property(env, appMemoryLimit, "vmTotalHeapSize", vmTotalHeapSize);
return appMemoryLimit;
}

View File

@ -323,6 +323,7 @@ describe("HidebugJsTest", function () {
expect(temp.rssLimit >= BigInt(0)).assertTrue();
expect(temp.vssLimit >= BigInt(0)).assertTrue();
expect(temp.vmHeapLimit >= BigInt(0)).assertTrue();
expect(temp.vmTotalHeapSize >= BigInt(0)).assertTrue();
} catch (error) {
expect().assertFail();
}