From 607f3c44dc3b5432c21ff8aaffb5c447e5401173 Mon Sep 17 00:00:00 2001 From: j30012456 Date: Wed, 16 Feb 2022 15:12:25 +0800 Subject: [PATCH 1/3] add hidebug js api Signed-off-by: j30012456 --- .../reference/apis/js-apis-hidebug.md | 169 ++++++++++++++++++ 1 file changed, 169 insertions(+) create mode 100644 zh-cn/application-dev/reference/apis/js-apis-hidebug.md diff --git a/zh-cn/application-dev/reference/apis/js-apis-hidebug.md b/zh-cn/application-dev/reference/apis/js-apis-hidebug.md new file mode 100644 index 00000000000..3ed44a48795 --- /dev/null +++ b/zh-cn/application-dev/reference/apis/js-apis-hidebug.md @@ -0,0 +1,169 @@ +# Debug调试模块 + +> ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** +> 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 + + +## 导入模块 + +``` +import hidebug from '@ohos.hidebug'; +``` + + +## 系统能力 +SystemCapability.HiviewDFX.HiProfiler.HiDebug + + +## hidebug.getNativeHeapSize + +getNativeHeapSize(): bigint + +通过musl提供的mallinfo接口计算native内存使用情况,使用此方法可获取native heap内存的总大小。 + + +- **返回值**: + | 类型 | 说明 | + | -------- | -------- | + | bigint | 返回native heap内存总大小。 | + + +- 示例: + ``` + let nativeHeapSize = BigInt(hidebug.getNativeHeapSize()); + ``` + + +## hidebug.getNativeHeapAllocatedSize + +getNativeHeapAllocatedSize(): bigint + +通过musl提供的mallinfo接口计算native内存使用情况,使用此方法可获取native heap内存的已分配内存大小。 + + +- **返回值**: + | 类型 | 说明 | + | -------- | -------- | + | bigint | 返回native heap内存的已分配内存。 | + + +- 示例: + ``` + let nativeHeapAllocatedSize = BigInt(hidebug.getNativeHeapAllocatedSize()); + ``` + + +## hidebug.getNativeHeapFreeSize + +getNativeHeapFreeSize(): bigint + +通过musl提供mallinfo接口计算native内存使用情况,使用此方法可获取native heap内存的空闲内存大小。 + + +- **返回值**: + | 类型 | 说明 | + | -------- | -------- | + | bigint | 返回native heap内存的空闲内存。 | + + +- 示例: + ``` + let nativeHeapFreeSize = BigInt(hidebug.getNativeHeapFreeSize()); + ``` + + +## hidebug.getPss + +getPss(): bigint + +基于smaps内存信息获取应用进程PSS内存大小。 + + +- **返回值**: + | 类型 | 说明 | + | -------- | -------- | + | bigint | 返回应用进程PSS内存大小。 | + + +- 示例: + ``` + let pss = BigInt(hidebug.getPss()); + ``` + + +## hidebug.getSharedDirty + +getSharedDirty(): bigint + +基于smaps内存信息获取进程的共享脏内存大小。 + + +- **返回值**: + | 类型 | 说明 | + | -------- | -------- | + | bigint | 返回进程的共享脏内存大小。 | + + +- 示例: + ``` + let sharedDirty = BigInt(hidebug.getSharedDirty()); + ``` + + +## hidebug.startProfiling + +startProfiling(filename : string) : void + +启动虚拟机Profiling方法跟踪,`startProfiling()`方法的调用需要与`stopProfiling()`方法的调用一一对应,先开启后关闭,严禁`start->start->stop`,`start->stop->stop`,`start->start->stop->stop`等使用方式。 + +* **参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| filename | string | 是 | 用户自定义的profiling文件名,根据传入的`filename`,将在应用的`files`目录生成`filename.json`文件。 | + +* **示例**: + +```js +hidebug.startProfiling("cpuprofiler-20220216"); +// code block +// ... +// code block +hidebug.stopProfiling(); +``` + + + +## hidebug.stopProfiling + +stopProfiling() : void + +停止虚拟机Profiling方法跟踪,`stopProfiling()`方法的调用需要与`startProfiling()`方法的调用一一对应,先开启后关闭,严禁`start->start->stop`,`start->stop->stop`,`start->start->stop->stop`等使用方式。 + +* **示例**: + +```js +hidebug.startProfiling("cpuprofiler-20220216"); +// code block +// ... +// code block +hidebug.stopProfiling(); +``` + +## hidebug.dumpHeapData + +dumpHeapData(filename : string) : void + +虚拟机堆导出 + +* **参数**: + +| 参数名 | 类型 | 必填 | 说明 | +| -------- | ------ | ---- | ------------------------------------------------------------ | +| filename | string | 是 | 用户自定义的虚拟机堆文件名,根据传入的`filename`,将在应用的`files`目录生成`filename.heapsnapshot`文件。 | + +* **示例**: + +```js +hidebug.dumpHeapData("heap-20220216"); +``` \ No newline at end of file -- Gitee From 7b8d07c7a2905928ae1871f6e788c2731b62c3ea Mon Sep 17 00:00:00 2001 From: jiangyuan0000 Date: Wed, 16 Feb 2022 16:56:57 +0800 Subject: [PATCH 2/3] . --- .../reference/apis/js-apis-hidebug.md | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-hidebug.md b/zh-cn/application-dev/reference/apis/js-apis-hidebug.md index 3ed44a48795..6df004732b0 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-hidebug.md +++ b/zh-cn/application-dev/reference/apis/js-apis-hidebug.md @@ -19,7 +19,7 @@ SystemCapability.HiviewDFX.HiProfiler.HiDebug getNativeHeapSize(): bigint -通过musl提供的mallinfo接口计算native内存使用情况,使用此方法可获取native heap内存的总大小。 +获取native heap内存的总大小。 - **返回值**: @@ -30,7 +30,7 @@ getNativeHeapSize(): bigint - 示例: ``` - let nativeHeapSize = BigInt(hidebug.getNativeHeapSize()); + let nativeHeapSize = hidebug.getNativeHeapSize(); ``` @@ -38,7 +38,7 @@ getNativeHeapSize(): bigint getNativeHeapAllocatedSize(): bigint -通过musl提供的mallinfo接口计算native内存使用情况,使用此方法可获取native heap内存的已分配内存大小。 +获取native heap内存的已分配内存大小。 - **返回值**: @@ -49,7 +49,7 @@ getNativeHeapAllocatedSize(): bigint - 示例: ``` - let nativeHeapAllocatedSize = BigInt(hidebug.getNativeHeapAllocatedSize()); + let nativeHeapAllocatedSize = hidebug.getNativeHeapAllocatedSize(); ``` @@ -57,7 +57,7 @@ getNativeHeapAllocatedSize(): bigint getNativeHeapFreeSize(): bigint -通过musl提供mallinfo接口计算native内存使用情况,使用此方法可获取native heap内存的空闲内存大小。 +获取native heap内存的空闲内存大小。 - **返回值**: @@ -68,7 +68,7 @@ getNativeHeapFreeSize(): bigint - 示例: ``` - let nativeHeapFreeSize = BigInt(hidebug.getNativeHeapFreeSize()); + let nativeHeapFreeSize = hidebug.getNativeHeapFreeSize(); ``` @@ -76,7 +76,7 @@ getNativeHeapFreeSize(): bigint getPss(): bigint -基于smaps内存信息获取应用进程PSS内存大小。 +获取应用进程PSS内存大小。 - **返回值**: @@ -87,7 +87,7 @@ getPss(): bigint - 示例: ``` - let pss = BigInt(hidebug.getPss()); + let pss = hidebug.getPss(); ``` @@ -95,7 +95,7 @@ getPss(): bigint getSharedDirty(): bigint -基于smaps内存信息获取进程的共享脏内存大小。 +获取进程的共享脏内存大小。 - **返回值**: @@ -106,7 +106,7 @@ getSharedDirty(): bigint - 示例: ``` - let sharedDirty = BigInt(hidebug.getSharedDirty()); + let sharedDirty = hidebug.getSharedDirty()); ``` @@ -114,7 +114,7 @@ getSharedDirty(): bigint startProfiling(filename : string) : void -启动虚拟机Profiling方法跟踪,`startProfiling()`方法的调用需要与`stopProfiling()`方法的调用一一对应,先开启后关闭,严禁`start->start->stop`,`start->stop->stop`,`start->start->stop->stop`等使用方式。 +启动虚拟机Profiling方法跟踪,`startProfiling()`方法的调用需要与`stopProfiling()`方法的调用一一对应,先开启后关闭,严禁使用`start->start->stop`,`start->stop->stop`,`start->start->stop->stop`等顺序的调用方式。 * **参数**: @@ -138,7 +138,7 @@ hidebug.stopProfiling(); stopProfiling() : void -停止虚拟机Profiling方法跟踪,`stopProfiling()`方法的调用需要与`startProfiling()`方法的调用一一对应,先开启后关闭,严禁`start->start->stop`,`start->stop->stop`,`start->start->stop->stop`等使用方式。 +停止虚拟机Profiling方法跟踪,`stopProfiling()`方法的调用需要与`startProfiling()`方法的调用一一对应,先开启后关闭,严禁使用`start->start->stop`,`start->stop->stop`,`start->start->stop->stop`等顺序的调用方式。 * **示例**: @@ -154,7 +154,7 @@ hidebug.stopProfiling(); dumpHeapData(filename : string) : void -虚拟机堆导出 +虚拟机堆导出。 * **参数**: @@ -166,4 +166,5 @@ dumpHeapData(filename : string) : void ```js hidebug.dumpHeapData("heap-20220216"); -``` \ No newline at end of file +``` + -- Gitee From 2879ac3abe3fb789486fae2245854ed5aef38b15 Mon Sep 17 00:00:00 2001 From: jiangyuan0000 Date: Wed, 16 Feb 2022 17:01:43 +0800 Subject: [PATCH 3/3] . Signed-off-by: jiangyuan0000 --- zh-cn/application-dev/reference/apis/js-apis-hidebug.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/zh-cn/application-dev/reference/apis/js-apis-hidebug.md b/zh-cn/application-dev/reference/apis/js-apis-hidebug.md index 6df004732b0..8ae59b38475 100644 --- a/zh-cn/application-dev/reference/apis/js-apis-hidebug.md +++ b/zh-cn/application-dev/reference/apis/js-apis-hidebug.md @@ -1,8 +1,9 @@ -# Debug调试模块 +# Debug调试 > ![icon-note.gif](public_sys-resources/icon-note.gif) **说明:** > 本模块首批接口从API version 8开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。 +使用hidebug,可以获取应用内存的使用情况,包括应用进程的静态堆内存(native heap)信息、应用进程内存占用PSS(Proportional Set Size)信息等。 ## 导入模块 -- Gitee