# @ohos.hidebug (HiDebug) > **NOTE** > > The initial APIs of this module are supported since API version 8. Newly added APIs will be marked with a superscript to indicate their earliest API version. The **hidebug** module provides APIs for you to obtain the memory usage of an application, including the static heap memory (native heap) and proportional set size (PSS) occupied by the application process. You can also export VM memory slices and collect VM CPU profiling data. ## Modules to Import ```ts import hidebug from '@ohos.hidebug'; ``` ## hidebug.getNativeHeapSize getNativeHeapSize(): bigint Obtains the total heap memory size of this application. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** | Type | Description | | ------ | --------------------------- | | bigint | Total heap memory size of the application, in bytes.| **Example** ```ts let nativeHeapSize: bigint = hidebug.getNativeHeapSize(); ``` ## hidebug.getNativeHeapAllocatedSize getNativeHeapAllocatedSize(): bigint Obtains the allocated heap memory size of this application. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** | Type | Description | | ------ | --------------------------------- | | bigint | Allocated heap memory of the application, in bytes.| **Example** ```ts let nativeHeapAllocatedSize: bigint = hidebug.getNativeHeapAllocatedSize(); ``` ## hidebug.getNativeHeapFreeSize getNativeHeapFreeSize(): bigint Obtains the free heap memory size of this application. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** | Type | Description | | ------ | ------------------------------- | | bigint | Free heap memory size of the application, in bytes.| **Example** ```ts let nativeHeapFreeSize: bigint = hidebug.getNativeHeapFreeSize(); ``` ## hidebug.getPss getPss(): bigint Obtains the size of the physical memory actually used by the application process. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** | Type | Description | | ------ | ------------------------- | | bigint | Size of the physical memory actually used by the application process, in KB.| **Example** ```ts let pss: bigint = hidebug.getPss(); ``` ## hidebug.getSharedDirty getSharedDirty(): bigint Obtains the size of the shared dirty memory of a process. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** | Type | Description | | ------ | -------------------------- | | bigint | Size of the shared dirty memory of the process, in KB.| **Example** ```ts let sharedDirty: bigint = hidebug.getSharedDirty(); ``` ## hidebug.getPrivateDirty9+ getPrivateDirty(): bigint Obtains the size of the private dirty memory of a process. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** | Type | Description | | ------ | -------------------------- | | bigint | Size of the private dirty memory of the process, in KB.| **Example** ```ts let privateDirty: bigint = hidebug.getPrivateDirty(); ``` ## hidebug.getCpuUsage9+ getCpuUsage(): number Obtains the CPU usage of a process. For example, if the CPU usage is **50%**, **0.5** is returned. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Return value** | Type | Description | | ------ | -------------------------- | | number | CPU usage of the process.| **Example** ```ts let cpuUsage: number = hidebug.getCpuUsage(); ``` ## hidebug.getServiceDump9+ getServiceDump(serviceid : number, fd : number, args : Array\) : void Obtains system service information. **Required permissions**: ohos.permission.DUMP **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | serviceid | number | Yes | Obtains the system service information based on the specified service ID.| | fd | number | Yes | File descriptor to which data is written by the API.| | args | Array\ | Yes | Parameter list corresponding to the **Dump** API of the system service.| **Error codes** For details about the error codes, see [HiSysEvent Error Codes](../errorcodes/errorcode-hiviewdfx-hidebug.md). | ID| Error Message| | ------- | ----------------------------------------------------------------- | | 11400101 | the service id is invalid | | 401 | the parameter check failed | **Example** ```ts import fs from '@ohos.file.fs' import hidebug from '@ohos.hidebug' import common from '@ohos.app.ability.common' import { BusinessError } from '@ohos.base' let applicationContext: common.Context | null = null; try { applicationContext = this.context.getApplicationContext(); } catch (error) { console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); } let filesDir: string = applicationContext!.filesDir; let path: string = filesDir + "/serviceInfo.txt"; console.info("output path: " + path); let file = fs.openSync(path, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE); let serviceId: number = 10; let args: Array = new Array("allInfo"); try { hidebug.getServiceDump(serviceId, file.fd, args); } catch (error) { console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); } fs.closeSync(file); ``` ## hidebug.startJsCpuProfiling9+ startJsCpuProfiling(filename : string) : void Starts the profiling method. `startJsCpuProfiling()` and `stopJsCpuProfiling()` are called in pairs. `startJsCpuProfiling()` always occurs before `stopJsCpuProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | filename | string | Yes | User-defined profile name. The `filename.json` file is generated in the `files` directory of the application based on the specified `filename`.| **Error codes** For details about the error codes, see [HiSysEvent Error Codes](../errorcodes/errorcode-universal.md). | ID| Error Message| | ------- | ----------------------------------------------------------------- | | 401 | the parameter check failed | **Example** ```ts import hidebug from '@ohos.hidebug' import { BusinessError } from '@ohos.base' try { hidebug.startJsCpuProfiling("cpu_profiling"); // ... hidebug.stopJsCpuProfiling(); } catch (error) { console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); } ``` ## hidebug.stopJsCpuProfiling9+ stopJsCpuProfiling() : void Stops the profiling method. `startJsCpuProfiling()` and `stopJsCpuProfiling()` are called in pairs. `startJsCpuProfiling()` always occurs before `stopJsCpuProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | filename | string | Yes | User-defined profile name. The `filename.json` file is generated in the `files` directory of the application based on the specified `filename`.| **Example** ```ts import hidebug from '@ohos.hidebug' import { BusinessError } from '@ohos.base' try { hidebug.startJsCpuProfiling("cpu_profiling"); // ... hidebug.stopJsCpuProfiling(); } catch (error) { console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); } ``` ## hidebug.dumpJsHeapData9+ dumpJsHeapData(filename : string) : void Exports the heap data. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | filename | string | Yes | User-defined heap file name. The `filename.heapsnapshot` file is generated in the `files` directory of the application based on the specified `filename`.| **Error codes** For details about the error codes, see [HiSysEvent Error Codes](../errorcodes/errorcode-universal.md). | ID| Error Message| | ------- | ----------------------------------------------------------------- | | 401 | the parameter check failed | **Example** ```ts import hidebug from '@ohos.hidebug' import { BusinessError } from '@ohos.base' try { hidebug.dumpJsHeapData("heapData"); } catch (error) { console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); } ``` ## hidebug.startProfiling(deprecated) startProfiling(filename : string) : void > **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.startJsCpuProfiling](#hidebugstartjscpuprofiling9). Starts the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | filename | string | Yes | User-defined profile name. The `filename.json` file is generated in the `files` directory of the application based on the specified `filename`.| **Example** ```ts hidebug.startProfiling("cpuprofiler-20220216"); // code block // ... // code block hidebug.stopProfiling(); ``` ## hidebug.stopProfiling(deprecated) stopProfiling() : void > **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.stopJsCpuProfiling](#hidebugstopjscpuprofiling9). Stops the profiling method. `startProfiling()` and `stopProfiling()` are called in pairs. `startProfiling()` always occurs before `stopProfiling()`; that is, calling the functions in the sequence similar to the following is prohibited: `start->start->stop`, `start->stop->stop`, and `start->start->stop->stop`. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Example** ```ts hidebug.startProfiling("cpuprofiler-20220216"); // code block // ... // code block hidebug.stopProfiling(); ``` ## hidebug.dumpHeapData(deprecated) dumpHeapData(filename : string) : void > **NOTE**
This API is deprecated since API version 9. You are advised to use [hidebug.dumpJsHeapData](#hidebugdumpjsheapdata9). Exports the heap data. **System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug **Parameters** | Name | Type | Mandatory| Description | | -------- | ------ | ---- | ------------------------------------------------------------ | | filename | string | Yes | User-defined heap file name. The `filename.heapsnapshot` file is generated in the `files` directory of the application based on the specified `filename`.| **Example** ```ts hidebug.dumpHeapData("heap-20220216"); ```