1e41f4b71Sopenharmony_ci# @ohos.hidebug (HiDebug) 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ci> **NOTE** 4e41f4b71Sopenharmony_ci> 5e41f4b71Sopenharmony_ci> 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. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ciThe **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. 8e41f4b71Sopenharmony_ci 9e41f4b71Sopenharmony_ci## Modules to Import 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci```ts 12e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 13e41f4b71Sopenharmony_ci``` 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci## hidebug.getNativeHeapSize 16e41f4b71Sopenharmony_ci 17e41f4b71Sopenharmony_cigetNativeHeapSize(): bigint 18e41f4b71Sopenharmony_ci 19e41f4b71Sopenharmony_ciObtains the size of heap memory (including the allocator metadata) held by a process, which is measured by the memory allocator. 20e41f4b71Sopenharmony_ci 21e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 22e41f4b71Sopenharmony_ci 23e41f4b71Sopenharmony_ci**Return value** 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci| Type | Description | 26e41f4b71Sopenharmony_ci| ------ | --------------------------- | 27e41f4b71Sopenharmony_ci| bigint | Size of the heap memory (including the allocator metadata) held by the process, in bytes. | 28e41f4b71Sopenharmony_ci 29e41f4b71Sopenharmony_ci**Example** 30e41f4b71Sopenharmony_ci 31e41f4b71Sopenharmony_ci```ts 32e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 33e41f4b71Sopenharmony_ci 34e41f4b71Sopenharmony_cilet nativeHeapSize: bigint = hidebug.getNativeHeapSize(); 35e41f4b71Sopenharmony_ci``` 36e41f4b71Sopenharmony_ci 37e41f4b71Sopenharmony_ci## hidebug.getNativeHeapAllocatedSize 38e41f4b71Sopenharmony_ci 39e41f4b71Sopenharmony_cigetNativeHeapAllocatedSize(): bigint 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ciObtains the size of the heap memory allocated to a process service, which is measured by the memory allocator. 42e41f4b71Sopenharmony_ci 43e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 44e41f4b71Sopenharmony_ci 45e41f4b71Sopenharmony_ci**Return value** 46e41f4b71Sopenharmony_ci 47e41f4b71Sopenharmony_ci| Type | Description | 48e41f4b71Sopenharmony_ci| ------ | --------------------------------- | 49e41f4b71Sopenharmony_ci| bigint | Size of the heap memory allocated to a process service, in bytes. | 50e41f4b71Sopenharmony_ci 51e41f4b71Sopenharmony_ci 52e41f4b71Sopenharmony_ci**Example** 53e41f4b71Sopenharmony_ci```ts 54e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_cilet nativeHeapAllocatedSize: bigint = hidebug.getNativeHeapAllocatedSize(); 57e41f4b71Sopenharmony_ci``` 58e41f4b71Sopenharmony_ci 59e41f4b71Sopenharmony_ci## hidebug.getNativeHeapFreeSize 60e41f4b71Sopenharmony_ci 61e41f4b71Sopenharmony_cigetNativeHeapFreeSize(): bigint 62e41f4b71Sopenharmony_ci 63e41f4b71Sopenharmony_ciObtains the size of the cache memory held by the memory allocator. 64e41f4b71Sopenharmony_ci 65e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 66e41f4b71Sopenharmony_ci 67e41f4b71Sopenharmony_ci**Return value** 68e41f4b71Sopenharmony_ci 69e41f4b71Sopenharmony_ci| Type | Description | 70e41f4b71Sopenharmony_ci| ------ | ------------------------------- | 71e41f4b71Sopenharmony_ci| bigint | Size of the cache memory held by the memory allocator, in bytes. | 72e41f4b71Sopenharmony_ci 73e41f4b71Sopenharmony_ci**Example** 74e41f4b71Sopenharmony_ci```ts 75e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 76e41f4b71Sopenharmony_ci 77e41f4b71Sopenharmony_cilet nativeHeapFreeSize: bigint = hidebug.getNativeHeapFreeSize(); 78e41f4b71Sopenharmony_ci``` 79e41f4b71Sopenharmony_ci 80e41f4b71Sopenharmony_ci## hidebug.getPss 81e41f4b71Sopenharmony_ci 82e41f4b71Sopenharmony_cigetPss(): bigint 83e41f4b71Sopenharmony_ci 84e41f4b71Sopenharmony_ciObtains the size of the physical memory actually used by the application process. 85e41f4b71Sopenharmony_ci 86e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 87e41f4b71Sopenharmony_ci 88e41f4b71Sopenharmony_ci**Return value** 89e41f4b71Sopenharmony_ci 90e41f4b71Sopenharmony_ci| Type | Description | 91e41f4b71Sopenharmony_ci| ------ | ------------------------- | 92e41f4b71Sopenharmony_ci| bigint | Size of the physical memory actually used by the application process, in KB. | 93e41f4b71Sopenharmony_ci 94e41f4b71Sopenharmony_ci**Example** 95e41f4b71Sopenharmony_ci```ts 96e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 97e41f4b71Sopenharmony_ci 98e41f4b71Sopenharmony_cilet pss: bigint = hidebug.getPss(); 99e41f4b71Sopenharmony_ci``` 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ci## hidebug.getVss<sup>11+<sup> 102e41f4b71Sopenharmony_ci 103e41f4b71Sopenharmony_cigetVss(): bigint 104e41f4b71Sopenharmony_ci 105e41f4b71Sopenharmony_ciObtains the virtual set size used by the application process. 106e41f4b71Sopenharmony_ci 107e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 108e41f4b71Sopenharmony_ci 109e41f4b71Sopenharmony_ci**Return value** 110e41f4b71Sopenharmony_ci 111e41f4b71Sopenharmony_ci| Type | Description | 112e41f4b71Sopenharmony_ci| ------ | ---------------------------------------- | 113e41f4b71Sopenharmony_ci| bigint | Virtual set size used by the application process, in KB. | 114e41f4b71Sopenharmony_ci 115e41f4b71Sopenharmony_ci**Example** 116e41f4b71Sopenharmony_ci 117e41f4b71Sopenharmony_ci```ts 118e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 119e41f4b71Sopenharmony_ci 120e41f4b71Sopenharmony_cilet vss: bigint = hidebug.getVss(); 121e41f4b71Sopenharmony_ci``` 122e41f4b71Sopenharmony_ci 123e41f4b71Sopenharmony_ci## hidebug.getSharedDirty 124e41f4b71Sopenharmony_ci 125e41f4b71Sopenharmony_cigetSharedDirty(): bigint 126e41f4b71Sopenharmony_ci 127e41f4b71Sopenharmony_ciObtains the size of the shared dirty memory of a process. 128e41f4b71Sopenharmony_ci 129e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 130e41f4b71Sopenharmony_ci 131e41f4b71Sopenharmony_ci**Return value** 132e41f4b71Sopenharmony_ci 133e41f4b71Sopenharmony_ci| Type | Description | 134e41f4b71Sopenharmony_ci| ------ | -------------------------- | 135e41f4b71Sopenharmony_ci| bigint | Size of the shared dirty memory of the process, in KB. | 136e41f4b71Sopenharmony_ci 137e41f4b71Sopenharmony_ci 138e41f4b71Sopenharmony_ci**Example** 139e41f4b71Sopenharmony_ci```ts 140e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 141e41f4b71Sopenharmony_ci 142e41f4b71Sopenharmony_cilet sharedDirty: bigint = hidebug.getSharedDirty(); 143e41f4b71Sopenharmony_ci``` 144e41f4b71Sopenharmony_ci 145e41f4b71Sopenharmony_ci## hidebug.getPrivateDirty<sup>9+<sup> 146e41f4b71Sopenharmony_ci 147e41f4b71Sopenharmony_cigetPrivateDirty(): bigint 148e41f4b71Sopenharmony_ci 149e41f4b71Sopenharmony_ciObtains the size of the private dirty memory of a process. 150e41f4b71Sopenharmony_ci 151e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 152e41f4b71Sopenharmony_ci 153e41f4b71Sopenharmony_ci**Return value** 154e41f4b71Sopenharmony_ci 155e41f4b71Sopenharmony_ci| Type | Description | 156e41f4b71Sopenharmony_ci| ------ | -------------------------- | 157e41f4b71Sopenharmony_ci| bigint | Size of the private dirty memory of the process, in KB. | 158e41f4b71Sopenharmony_ci 159e41f4b71Sopenharmony_ci**Example** 160e41f4b71Sopenharmony_ci```ts 161e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 162e41f4b71Sopenharmony_ci 163e41f4b71Sopenharmony_cilet privateDirty: bigint = hidebug.getPrivateDirty(); 164e41f4b71Sopenharmony_ci``` 165e41f4b71Sopenharmony_ci 166e41f4b71Sopenharmony_ci## hidebug.getCpuUsage<sup>9+<sup> 167e41f4b71Sopenharmony_ci 168e41f4b71Sopenharmony_cigetCpuUsage(): number 169e41f4b71Sopenharmony_ci 170e41f4b71Sopenharmony_ciObtains the CPU usage of a process. 171e41f4b71Sopenharmony_ci 172e41f4b71Sopenharmony_ciFor example, if the CPU usage is **50%**, **0.5** is returned. 173e41f4b71Sopenharmony_ci 174e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 175e41f4b71Sopenharmony_ci 176e41f4b71Sopenharmony_ci**Return value** 177e41f4b71Sopenharmony_ci 178e41f4b71Sopenharmony_ci| Type | Description | 179e41f4b71Sopenharmony_ci| ------ | -------------------------- | 180e41f4b71Sopenharmony_ci| number | CPU usage of the process. | 181e41f4b71Sopenharmony_ci 182e41f4b71Sopenharmony_ci 183e41f4b71Sopenharmony_ci**Example** 184e41f4b71Sopenharmony_ci```ts 185e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 186e41f4b71Sopenharmony_ci 187e41f4b71Sopenharmony_cilet cpuUsage: number = hidebug.getCpuUsage(); 188e41f4b71Sopenharmony_ci``` 189e41f4b71Sopenharmony_ci 190e41f4b71Sopenharmony_ci## hidebug.getServiceDump<sup>9+<sup> 191e41f4b71Sopenharmony_ci 192e41f4b71Sopenharmony_cigetServiceDump(serviceid : number, fd : number, args : Array\<string>) : void 193e41f4b71Sopenharmony_ci 194e41f4b71Sopenharmony_ciObtains system service information. 195e41f4b71Sopenharmony_ci 196e41f4b71Sopenharmony_ci**Required permissions**: ohos.permission.DUMP (available only for system applications) 197e41f4b71Sopenharmony_ci 198e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 199e41f4b71Sopenharmony_ci 200e41f4b71Sopenharmony_ci**Parameters** 201e41f4b71Sopenharmony_ci 202e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 203e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------------------------------ | 204e41f4b71Sopenharmony_ci| serviceid | number | Yes | Obtains the system service information based on the specified service ID.| 205e41f4b71Sopenharmony_ci| fd | number | Yes | File descriptor to which data is written by the API.| 206e41f4b71Sopenharmony_ci| args | Array\<string> | Yes | Parameter list corresponding to the **Dump** API of the system service.| 207e41f4b71Sopenharmony_ci 208e41f4b71Sopenharmony_ci**Error codes** 209e41f4b71Sopenharmony_ci 210e41f4b71Sopenharmony_ciFor details about the error codes, see [HiDebug Error Codes](errorcode-hiviewdfx-hidebug.md). 211e41f4b71Sopenharmony_ci 212e41f4b71Sopenharmony_ci| ID | Error Message | 213e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------------- | 214e41f4b71Sopenharmony_ci| 401 | The parameter check failed. Possible causes:1.The parameter type error 2.The args parameter is not string array | 215e41f4b71Sopenharmony_ci| 11400101 | ServiceId invalid. The system ability does not exist. | 216e41f4b71Sopenharmony_ci 217e41f4b71Sopenharmony_ci**Example** 218e41f4b71Sopenharmony_ci 219e41f4b71Sopenharmony_ci```ts 220e41f4b71Sopenharmony_ciimport { fileIo } from '@kit.CoreFileKit'; 221e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 222e41f4b71Sopenharmony_ciimport { common } from '@kit.AbilityKit'; 223e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_cilet applicationContext: common.Context | null = null; 226e41f4b71Sopenharmony_citry { 227e41f4b71Sopenharmony_ci let context = getContext() as common.UIAbilityContext; 228e41f4b71Sopenharmony_ci applicationContext = context.getApplicationContext(); 229e41f4b71Sopenharmony_ci} catch (error) { 230e41f4b71Sopenharmony_ci console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); 231e41f4b71Sopenharmony_ci} 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_cilet filesDir: string = applicationContext!.filesDir; 234e41f4b71Sopenharmony_cilet path: string = filesDir + "/serviceInfo.txt"; 235e41f4b71Sopenharmony_ciconsole.info("output path: " + path); 236e41f4b71Sopenharmony_cilet file = fileIo.openSync(path, fileIo.OpenMode.READ_WRITE | fileIo.OpenMode.CREATE); 237e41f4b71Sopenharmony_cilet serviceId: number = 10; 238e41f4b71Sopenharmony_cilet args: Array<string> = new Array("allInfo"); 239e41f4b71Sopenharmony_ci 240e41f4b71Sopenharmony_citry { 241e41f4b71Sopenharmony_ci hidebug.getServiceDump(serviceId, file.fd, args); 242e41f4b71Sopenharmony_ci} catch (error) { 243e41f4b71Sopenharmony_ci console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); 244e41f4b71Sopenharmony_ci} 245e41f4b71Sopenharmony_cifileIo.closeSync(file); 246e41f4b71Sopenharmony_ci``` 247e41f4b71Sopenharmony_ci 248e41f4b71Sopenharmony_ci## hidebug.startJsCpuProfiling<sup>9+</sup> 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_cistartJsCpuProfiling(filename : string) : void 251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ciStarts 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`. 253e41f4b71Sopenharmony_ci 254e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 255e41f4b71Sopenharmony_ci 256e41f4b71Sopenharmony_ci**Parameters** 257e41f4b71Sopenharmony_ci 258e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 259e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------------------------------ | 260e41f4b71Sopenharmony_ci| 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`. | 261e41f4b71Sopenharmony_ci 262e41f4b71Sopenharmony_ci**Error codes** 263e41f4b71Sopenharmony_ci 264e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 265e41f4b71Sopenharmony_ci 266e41f4b71Sopenharmony_ci| ID | Error Message | 267e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------------- | 268e41f4b71Sopenharmony_ci| 401 | the parameter check failed,Parameter type error | 269e41f4b71Sopenharmony_ci 270e41f4b71Sopenharmony_ci**Example** 271e41f4b71Sopenharmony_ci 272e41f4b71Sopenharmony_ci```ts 273e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 274e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 275e41f4b71Sopenharmony_ci 276e41f4b71Sopenharmony_citry { 277e41f4b71Sopenharmony_ci hidebug.startJsCpuProfiling("cpu_profiling"); 278e41f4b71Sopenharmony_ci // ... 279e41f4b71Sopenharmony_ci hidebug.stopJsCpuProfiling(); 280e41f4b71Sopenharmony_ci} catch (error) { 281e41f4b71Sopenharmony_ci console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); 282e41f4b71Sopenharmony_ci} 283e41f4b71Sopenharmony_ci``` 284e41f4b71Sopenharmony_ci 285e41f4b71Sopenharmony_ci## hidebug.stopJsCpuProfiling<sup>9+</sup> 286e41f4b71Sopenharmony_ci 287e41f4b71Sopenharmony_cistopJsCpuProfiling() : void 288e41f4b71Sopenharmony_ci 289e41f4b71Sopenharmony_ciStops 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`. 290e41f4b71Sopenharmony_ci 291e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 292e41f4b71Sopenharmony_ci 293e41f4b71Sopenharmony_ci**Example** 294e41f4b71Sopenharmony_ci 295e41f4b71Sopenharmony_ci```ts 296e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 297e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 298e41f4b71Sopenharmony_ci 299e41f4b71Sopenharmony_citry { 300e41f4b71Sopenharmony_ci hidebug.startJsCpuProfiling("cpu_profiling"); 301e41f4b71Sopenharmony_ci // ... 302e41f4b71Sopenharmony_ci hidebug.stopJsCpuProfiling(); 303e41f4b71Sopenharmony_ci} catch (error) { 304e41f4b71Sopenharmony_ci console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); 305e41f4b71Sopenharmony_ci} 306e41f4b71Sopenharmony_ci``` 307e41f4b71Sopenharmony_ci 308e41f4b71Sopenharmony_ci## hidebug.dumpJsHeapData<sup>9+</sup> 309e41f4b71Sopenharmony_ci 310e41f4b71Sopenharmony_cidumpJsHeapData(filename : string) : void 311e41f4b71Sopenharmony_ci 312e41f4b71Sopenharmony_ciExports the heap data. 313e41f4b71Sopenharmony_ci 314e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 315e41f4b71Sopenharmony_ci 316e41f4b71Sopenharmony_ci**Parameters** 317e41f4b71Sopenharmony_ci 318e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 319e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------------------------------ | 320e41f4b71Sopenharmony_ci| 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`. | 321e41f4b71Sopenharmony_ci 322e41f4b71Sopenharmony_ci**Error codes** 323e41f4b71Sopenharmony_ci 324e41f4b71Sopenharmony_ciFor details about the error codes, see [Universal Error Codes](../errorcode-universal.md). 325e41f4b71Sopenharmony_ci 326e41f4b71Sopenharmony_ci| ID | Error Message | 327e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------------- | 328e41f4b71Sopenharmony_ci| 401 | the parameter check failed, Parameter type error | 329e41f4b71Sopenharmony_ci 330e41f4b71Sopenharmony_ci**Example** 331e41f4b71Sopenharmony_ci 332e41f4b71Sopenharmony_ci```ts 333e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 334e41f4b71Sopenharmony_ciimport { BusinessError } from '@kit.BasicServicesKit'; 335e41f4b71Sopenharmony_ci 336e41f4b71Sopenharmony_citry { 337e41f4b71Sopenharmony_ci hidebug.dumpJsHeapData("heapData"); 338e41f4b71Sopenharmony_ci} catch (error) { 339e41f4b71Sopenharmony_ci console.info(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`); 340e41f4b71Sopenharmony_ci} 341e41f4b71Sopenharmony_ci``` 342e41f4b71Sopenharmony_ci 343e41f4b71Sopenharmony_ci## hidebug.startProfiling<sup>(deprecated)</sup> 344e41f4b71Sopenharmony_ci 345e41f4b71Sopenharmony_cistartProfiling(filename : string) : void 346e41f4b71Sopenharmony_ci 347e41f4b71Sopenharmony_ci> **NOTE** 348e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [hidebug.startJsCpuProfiling](#hidebugstartjscpuprofiling9). 349e41f4b71Sopenharmony_ci 350e41f4b71Sopenharmony_ciStarts 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`. 351e41f4b71Sopenharmony_ci 352e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 353e41f4b71Sopenharmony_ci 354e41f4b71Sopenharmony_ci**Parameters** 355e41f4b71Sopenharmony_ci 356e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 357e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------------------------------ | 358e41f4b71Sopenharmony_ci| 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`. | 359e41f4b71Sopenharmony_ci 360e41f4b71Sopenharmony_ci**Example** 361e41f4b71Sopenharmony_ci 362e41f4b71Sopenharmony_ci```ts 363e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 364e41f4b71Sopenharmony_ci 365e41f4b71Sopenharmony_cihidebug.startProfiling("cpuprofiler-20220216"); 366e41f4b71Sopenharmony_ci// code block 367e41f4b71Sopenharmony_ci// ... 368e41f4b71Sopenharmony_ci// code block 369e41f4b71Sopenharmony_cihidebug.stopProfiling(); 370e41f4b71Sopenharmony_ci``` 371e41f4b71Sopenharmony_ci 372e41f4b71Sopenharmony_ci## hidebug.stopProfiling<sup>(deprecated)</sup> 373e41f4b71Sopenharmony_ci 374e41f4b71Sopenharmony_cistopProfiling() : void 375e41f4b71Sopenharmony_ci 376e41f4b71Sopenharmony_ci> **NOTE** 377e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [hidebug.stopJsCpuProfiling](#hidebugstopjscpuprofiling9). 378e41f4b71Sopenharmony_ci 379e41f4b71Sopenharmony_ciStops 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`. 380e41f4b71Sopenharmony_ci 381e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 382e41f4b71Sopenharmony_ci 383e41f4b71Sopenharmony_ci**Example** 384e41f4b71Sopenharmony_ci 385e41f4b71Sopenharmony_ci```ts 386e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 387e41f4b71Sopenharmony_ci 388e41f4b71Sopenharmony_cihidebug.startProfiling("cpuprofiler-20220216"); 389e41f4b71Sopenharmony_ci// code block 390e41f4b71Sopenharmony_ci// ... 391e41f4b71Sopenharmony_ci// code block 392e41f4b71Sopenharmony_cihidebug.stopProfiling(); 393e41f4b71Sopenharmony_ci``` 394e41f4b71Sopenharmony_ci 395e41f4b71Sopenharmony_ci## hidebug.dumpHeapData<sup>(deprecated)</sup> 396e41f4b71Sopenharmony_ci 397e41f4b71Sopenharmony_cidumpHeapData(filename : string) : void 398e41f4b71Sopenharmony_ci 399e41f4b71Sopenharmony_ci> **NOTE** 400e41f4b71Sopenharmony_ci> This API is deprecated since API version 9. You are advised to use [hidebug.dumpJsHeapData](#hidebugdumpjsheapdata9). 401e41f4b71Sopenharmony_ci 402e41f4b71Sopenharmony_ciExports the heap data. 403e41f4b71Sopenharmony_ci 404e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 405e41f4b71Sopenharmony_ci 406e41f4b71Sopenharmony_ci**Parameters** 407e41f4b71Sopenharmony_ci 408e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 409e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------------------------------ | 410e41f4b71Sopenharmony_ci| 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`. | 411e41f4b71Sopenharmony_ci 412e41f4b71Sopenharmony_ci**Example** 413e41f4b71Sopenharmony_ci 414e41f4b71Sopenharmony_ci```ts 415e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 416e41f4b71Sopenharmony_ci 417e41f4b71Sopenharmony_cihidebug.dumpHeapData("heap-20220216"); 418e41f4b71Sopenharmony_ci``` 419e41f4b71Sopenharmony_ci 420e41f4b71Sopenharmony_ci## hidebug.getAppVMMemoryInfo<sup>12+</sup> 421e41f4b71Sopenharmony_ci 422e41f4b71Sopenharmony_cigetAppVMMemoryInfo(): VMMemoryInfo 423e41f4b71Sopenharmony_ci 424e41f4b71Sopenharmony_ciObtains VM memory information. 425e41f4b71Sopenharmony_ci 426e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 427e41f4b71Sopenharmony_ci 428e41f4b71Sopenharmony_ci**Return value** 429e41f4b71Sopenharmony_ci 430e41f4b71Sopenharmony_ci| Type | Description | 431e41f4b71Sopenharmony_ci| -------------| --------------------------------------- | 432e41f4b71Sopenharmony_ci| [VMMemoryInfo](#vmmemoryinfo12) | VM memory information. | 433e41f4b71Sopenharmony_ci 434e41f4b71Sopenharmony_ci**Example** 435e41f4b71Sopenharmony_ci 436e41f4b71Sopenharmony_ci```ts 437e41f4b71Sopenharmony_ciimport { hidebug, hilog } from '@kit.PerformanceAnalysisKit'; 438e41f4b71Sopenharmony_ci 439e41f4b71Sopenharmony_cilet vmMemory: hidebug.VMMemoryInfo = hidebug.getAppVMMemoryInfo(); 440e41f4b71Sopenharmony_cihilog.info(0x0000, "example", "totalHeap = %{public}d", vmMemory.totalHeap); 441e41f4b71Sopenharmony_cihilog.info(0x0000, "example", "heapUsed = %{public}d", vmMemory.heapUsed); 442e41f4b71Sopenharmony_cihilog.info(0x0000, "example", "allArraySize = %{public}d", vmMemory.allArraySize); 443e41f4b71Sopenharmony_ci``` 444e41f4b71Sopenharmony_ci 445e41f4b71Sopenharmony_ci## hidebug.getAppThreadCpuUsage<sup>12+</sup> 446e41f4b71Sopenharmony_ci 447e41f4b71Sopenharmony_cigetAppThreadCpuUsage(): ThreadCpuUsage[] 448e41f4b71Sopenharmony_ci 449e41f4b71Sopenharmony_ciObtains the CPU usage of application threads. 450e41f4b71Sopenharmony_ci 451e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 452e41f4b71Sopenharmony_ci 453e41f4b71Sopenharmony_ci**Return value** 454e41f4b71Sopenharmony_ci 455e41f4b71Sopenharmony_ci| Type | Description | 456e41f4b71Sopenharmony_ci| -----------------| ------------------------------------------------------------| 457e41f4b71Sopenharmony_ci| [ThreadCpuUsage](#threadcpuusage12)[] | CPU usage of all threads of the current application process. | 458e41f4b71Sopenharmony_ci 459e41f4b71Sopenharmony_ci 460e41f4b71Sopenharmony_ci 461e41f4b71Sopenharmony_ci**Example** 462e41f4b71Sopenharmony_ci 463e41f4b71Sopenharmony_ci```ts 464e41f4b71Sopenharmony_ciimport { hidebug, hilog } from '@kit.PerformanceAnalysisKit'; 465e41f4b71Sopenharmony_ci 466e41f4b71Sopenharmony_cilet appThreadCpuUsage: hidebug.ThreadCpuUsage[] = hidebug.getAppThreadCpuUsage(); 467e41f4b71Sopenharmony_cifor (let ii = 0; ii < appThreadCpuUsage.length; ii++) { 468e41f4b71Sopenharmony_ci hilog.info(0x0000, "example", "threadId=%{public}d, cpuUsage=%{public}f", appThreadCpuUsage[ii].threadId, 469e41f4b71Sopenharmony_ci appThreadCpuUsage[ii].cpuUsage); 470e41f4b71Sopenharmony_ci} 471e41f4b71Sopenharmony_ci``` 472e41f4b71Sopenharmony_ci 473e41f4b71Sopenharmony_ci## hidebug.startAppTraceCapture<sup>12+</sup> 474e41f4b71Sopenharmony_ci 475e41f4b71Sopenharmony_cistartAppTraceCapture(tags : number[], flag: TraceFlag, limitSize: number) : string 476e41f4b71Sopenharmony_ci 477e41f4b71Sopenharmony_ciStarts application trace collection. **startAppTraceCapture()** and **[stopAppTraceCapture()](#hidebugstopapptracecapture12)** must be called in pairs. 478e41f4b71Sopenharmony_ci 479e41f4b71Sopenharmony_ci**startAppTraceCapture()** always occurs before **stopAppTraceCapture()**; that is, calling the APIs in the sequence similar to the following is prohibited: start -> start -> stop, start -> stop -> stop, and start -> start -> stop -> stop. 480e41f4b71Sopenharmony_ci 481e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 482e41f4b71Sopenharmony_ci 483e41f4b71Sopenharmony_ci**Parameters** 484e41f4b71Sopenharmony_ci 485e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 486e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------------------------------------------------------- | 487e41f4b71Sopenharmony_ci| tags | number[] | Yes | For details, see [tags](#tags12). | 488e41f4b71Sopenharmony_ci| flag | TraceFlag| Yes | For details, see [TraceFlag](#traceflag12). | 489e41f4b71Sopenharmony_ci| limitSize| number | Yes | Limit on the trace file size, in bytes. The maximum size of a single file is 500 MB. | 490e41f4b71Sopenharmony_ci 491e41f4b71Sopenharmony_ci**Return value** 492e41f4b71Sopenharmony_ci 493e41f4b71Sopenharmony_ci| Type | Description | 494e41f4b71Sopenharmony_ci| -----------------| -----------------------------------------------| 495e41f4b71Sopenharmony_ci| string | Path of the trace file. | 496e41f4b71Sopenharmony_ci 497e41f4b71Sopenharmony_ci**Error codes** 498e41f4b71Sopenharmony_ci 499e41f4b71Sopenharmony_ciFor details about the error codes, see [HiDebug Error Codes](errorcode-hiviewdfx-hidebug.md). 500e41f4b71Sopenharmony_ci 501e41f4b71Sopenharmony_ci| ID | Error Message | 502e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------------- | 503e41f4b71Sopenharmony_ci| 401 | Invalid argument, Possible causes:1.The limit parameter is too small 2.The parameter is not within the enumeration type 3.The parameter type error or parameter order error| 504e41f4b71Sopenharmony_ci| 11400102 | Capture trace already enabled. | 505e41f4b71Sopenharmony_ci| 11400103 | No write permission on the file. | 506e41f4b71Sopenharmony_ci| 11400104 | Abnormal trace status. | 507e41f4b71Sopenharmony_ci 508e41f4b71Sopenharmony_ci**Example** 509e41f4b71Sopenharmony_ci 510e41f4b71Sopenharmony_ci```ts 511e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 512e41f4b71Sopenharmony_ci 513e41f4b71Sopenharmony_cilet tags: number[] = [hidebug.tags.ABILITY_MANAGER, hidebug.tags.ARKUI]; 514e41f4b71Sopenharmony_cilet flag: hidebug.TraceFlag = hidebug.TraceFlag.MAIN_THREAD; 515e41f4b71Sopenharmony_cilet limitSize: number = 1024 * 1024; 516e41f4b71Sopenharmony_cilet fileName: string = hidebug.startAppTraceCapture(tags, flag, limitSize); 517e41f4b71Sopenharmony_ci// code block 518e41f4b71Sopenharmony_ci// ... 519e41f4b71Sopenharmony_ci// code block 520e41f4b71Sopenharmony_cihidebug.stopAppTraceCapture(); 521e41f4b71Sopenharmony_ci``` 522e41f4b71Sopenharmony_ci 523e41f4b71Sopenharmony_ci## hidebug.stopAppTraceCapture<sup>12+</sup> 524e41f4b71Sopenharmony_ci 525e41f4b71Sopenharmony_cistopAppTraceCapture() : void 526e41f4b71Sopenharmony_ci 527e41f4b71Sopenharmony_ciStops application trace collection. **startAppTraceCapture()** and **[stopAppTraceCapture()](#hidebugstopapptracecapture12)** must be called in pairs. 528e41f4b71Sopenharmony_ci 529e41f4b71Sopenharmony_ci**startAppTraceCapture()** always occurs before **stopAppTraceCapture()**; that is, calling the APIs in the sequence similar to the following is prohibited: start -> start -> stop, start -> stop -> stop, and start -> start -> stop -> stop. 530e41f4b71Sopenharmony_ci 531e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 532e41f4b71Sopenharmony_ci 533e41f4b71Sopenharmony_ci**Error codes** 534e41f4b71Sopenharmony_ci 535e41f4b71Sopenharmony_ciFor details about the error codes, see [HiDebug Error Codes](errorcode-hiviewdfx-hidebug.md). 536e41f4b71Sopenharmony_ci 537e41f4b71Sopenharmony_ci| ID | Error Message | 538e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------------- | 539e41f4b71Sopenharmony_ci| 11400104 | The status of the trace is abnormal | 540e41f4b71Sopenharmony_ci| 11400105 | No capture trace running | 541e41f4b71Sopenharmony_ci 542e41f4b71Sopenharmony_ci**Example** 543e41f4b71Sopenharmony_ci 544e41f4b71Sopenharmony_ci```ts 545e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 546e41f4b71Sopenharmony_ci 547e41f4b71Sopenharmony_cilet tags: number[] = [hidebug.tags.ABILITY_MANAGER, hidebug.tags.ARKUI]; 548e41f4b71Sopenharmony_cilet flag: hidebug.TraceFlag = hidebug.TraceFlag.MAIN_THREAD; 549e41f4b71Sopenharmony_cilet limitSize: number = 1024 * 1024; 550e41f4b71Sopenharmony_cilet fileName: string = hidebug.startAppTraceCapture(tags, flag, limitSize); 551e41f4b71Sopenharmony_ci// code block 552e41f4b71Sopenharmony_ci// ... 553e41f4b71Sopenharmony_ci// code block 554e41f4b71Sopenharmony_cihidebug.stopAppTraceCapture(); 555e41f4b71Sopenharmony_ci``` 556e41f4b71Sopenharmony_ci 557e41f4b71Sopenharmony_ci## hidebug.getAppMemoryLimit<sup>12+</sup> 558e41f4b71Sopenharmony_ci 559e41f4b71Sopenharmony_cigetAppMemoryLimit() : MemoryLimit 560e41f4b71Sopenharmony_ci 561e41f4b71Sopenharmony_ciObtains the memory limit of the application process. 562e41f4b71Sopenharmony_ci 563e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 564e41f4b71Sopenharmony_ci 565e41f4b71Sopenharmony_ci**Return value** 566e41f4b71Sopenharmony_ci 567e41f4b71Sopenharmony_ci| Type | Description | 568e41f4b71Sopenharmony_ci| ------ | -------------------------- | 569e41f4b71Sopenharmony_ci| [MemoryLimit](#memorylimit12) | Memory limit of the application process.| 570e41f4b71Sopenharmony_ci 571e41f4b71Sopenharmony_ci**Example** 572e41f4b71Sopenharmony_ci 573e41f4b71Sopenharmony_ci```ts 574e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 575e41f4b71Sopenharmony_ci 576e41f4b71Sopenharmony_cilet appMemoryLimit:hidebug.MemoryLimit = hidebug.getAppMemoryLimit(); 577e41f4b71Sopenharmony_ci``` 578e41f4b71Sopenharmony_ci 579e41f4b71Sopenharmony_ci## hidebug.getSystemCpuUsage<sup>12+</sup> 580e41f4b71Sopenharmony_ci 581e41f4b71Sopenharmony_cigetSystemCpuUsage() : number 582e41f4b71Sopenharmony_ci 583e41f4b71Sopenharmony_ciObtains the CPU usage of the system. 584e41f4b71Sopenharmony_ci 585e41f4b71Sopenharmony_ciFor example, if the CPU usage of system resources is **50%**, **0.5** is returned. 586e41f4b71Sopenharmony_ci 587e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 588e41f4b71Sopenharmony_ci 589e41f4b71Sopenharmony_ci**Return value** 590e41f4b71Sopenharmony_ci 591e41f4b71Sopenharmony_ci| Type | Description | 592e41f4b71Sopenharmony_ci|--------|-------------| 593e41f4b71Sopenharmony_ci| number | CPU usage of the system.| 594e41f4b71Sopenharmony_ci 595e41f4b71Sopenharmony_ci**Error codes** 596e41f4b71Sopenharmony_ci 597e41f4b71Sopenharmony_ciFor details about the error codes, see [HiDebug CPU Usage Error Codes](errorcode-hiviewdfx-hidebug-cpuusage.md). 598e41f4b71Sopenharmony_ci 599e41f4b71Sopenharmony_ci| ID | Error Message | 600e41f4b71Sopenharmony_ci| ------- |-------------------------------------------------| 601e41f4b71Sopenharmony_ci| 11400104 | The status of the system CPU usage is abnormal. | 602e41f4b71Sopenharmony_ci 603e41f4b71Sopenharmony_ci**Example** 604e41f4b71Sopenharmony_ci```ts 605e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 606e41f4b71Sopenharmony_ci 607e41f4b71Sopenharmony_cilet cpuUsage: number = hidebug.getSystemCpuUsage(); 608e41f4b71Sopenharmony_ci``` 609e41f4b71Sopenharmony_ci 610e41f4b71Sopenharmony_ci## hidebug.setAppResourceLimit<sup>12+</sup> 611e41f4b71Sopenharmony_ci 612e41f4b71Sopenharmony_cisetAppResourceLimit(type: string, value: number, enableDebugLog: boolean) : void 613e41f4b71Sopenharmony_ci 614e41f4b71Sopenharmony_ciSets the number of FDs, number of threads, JS memory, or native memory limit of the application. 615e41f4b71Sopenharmony_ci**Note**: This function is valid only when the developer option is enabled. 616e41f4b71Sopenharmony_ci 617e41f4b71Sopenharmony_ci**Atomic service API**: This API can be used in atomic services since API version 12. 618e41f4b71Sopenharmony_ci 619e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 620e41f4b71Sopenharmony_ci 621e41f4b71Sopenharmony_ci**Parameters** 622e41f4b71Sopenharmony_ci 623e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 624e41f4b71Sopenharmony_ci| -------- | ------ | ---- | ------------------------------------------------------------ | 625e41f4b71Sopenharmony_ci| type | string | Yes | Types of resource leakage: pss_memory (native memory) leak, js_heap (js heap memory) leak, fd (file descriptor) leak, and thread (thread) leak. | 626e41f4b71Sopenharmony_ci| value | number | Yes | The maximum value of a resource leakage type. Value range: pss_memory leak **[1024, 4 * 1024 * 1024] (in KB)**, js_heap memory leak **[85, 95]** (85% to 95% of the upper limit of the JS heap memory), fd leak [10, 10000], thread leak **[1, 1000]** | 627e41f4b71Sopenharmony_ci| enableDebugLog | boolean | Yes | Whether to enable debug log. The default value is **false**. Set this parameter to **true** only in the dark version because collecting debug logs consumes too much CPU or memory. | 628e41f4b71Sopenharmony_ci 629e41f4b71Sopenharmony_ci**Error codes** 630e41f4b71Sopenharmony_ci 631e41f4b71Sopenharmony_ciFor details about the error codes, see [HiDebug Error Codes](errorcode-hiviewdfx-hidebug.md). 632e41f4b71Sopenharmony_ci 633e41f4b71Sopenharmony_ci| ID | Error Message | 634e41f4b71Sopenharmony_ci| ------- | ----------------------------------------------------------------- | 635e41f4b71Sopenharmony_ci| 401 | Invalid argument, Possible causes:1.The limit parameter is too small 2.The parameter is not in the specified type 3.The parameter type error or parameter order error | 636e41f4b71Sopenharmony_ci| 11400104 | Set limit failed due to remote exception | 637e41f4b71Sopenharmony_ci 638e41f4b71Sopenharmony_ci**Example** 639e41f4b71Sopenharmony_ci 640e41f4b71Sopenharmony_ci```ts 641e41f4b71Sopenharmony_ciimport { hidebug } from '@kit.PerformanceAnalysisKit'; 642e41f4b71Sopenharmony_ci 643e41f4b71Sopenharmony_cilet type: string = 'js_heap'; 644e41f4b71Sopenharmony_cilet value: number = 85; 645e41f4b71Sopenharmony_cilet enableDebugLog: boolean = false; 646e41f4b71Sopenharmony_cihidebug.setAppResourceLimit(type, value, enableDebugLog); 647e41f4b71Sopenharmony_ci``` 648e41f4b71Sopenharmony_ci 649e41f4b71Sopenharmony_ci## hidebug.getAppNativeMemInfo<sup>12+</sup> 650e41f4b71Sopenharmony_ci 651e41f4b71Sopenharmony_cigetAppNativeMemInfo(): NativeMemInfo 652e41f4b71Sopenharmony_ci 653e41f4b71Sopenharmony_ciObtains the memory information of the application process. 654e41f4b71Sopenharmony_ci 655e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 656e41f4b71Sopenharmony_ci 657e41f4b71Sopenharmony_ci**Return value** 658e41f4b71Sopenharmony_ci 659e41f4b71Sopenharmony_ci| Type | Description | 660e41f4b71Sopenharmony_ci| ------ | -------------------------- | 661e41f4b71Sopenharmony_ci| [NativeMemInfo](#nativememinfo12) | Memory information of the application process.| 662e41f4b71Sopenharmony_ci 663e41f4b71Sopenharmony_ci**Example** 664e41f4b71Sopenharmony_ci 665e41f4b71Sopenharmony_ci```ts 666e41f4b71Sopenharmony_ciimport { hidebug, hilog } from '@kit.PerformanceAnalysisKit'; 667e41f4b71Sopenharmony_ci 668e41f4b71Sopenharmony_cilet nativeMemInfo: hidebug.NativeMemInfo = hidebug.getAppNativeMemInfo(); 669e41f4b71Sopenharmony_ci 670e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "pss = %{public}d", nativeMemInfo.pss); 671e41f4b71Sopenharmony_ci 672e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "vss = %{public}d", nativeMemInfo.vss); 673e41f4b71Sopenharmony_ci 674e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "rss = %{public}d", nativeMemInfo.rss); 675e41f4b71Sopenharmony_ci 676e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "sharedDirty = %{public}d", nativeMemInfo.sharedDirty); 677e41f4b71Sopenharmony_ci 678e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "privateDirty = %{public}d", nativeMemInfo.privateDirty); 679e41f4b71Sopenharmony_ci 680e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "sharedClean = %{public}d", nativeMemInfo.sharedClean); 681e41f4b71Sopenharmony_ci 682e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "privateClean = %{public}d", nativeMemInfo.privateClean); 683e41f4b71Sopenharmony_ci``` 684e41f4b71Sopenharmony_ci 685e41f4b71Sopenharmony_ci## hidebug.getSystemMemInfo<sup>12+</sup> 686e41f4b71Sopenharmony_ci 687e41f4b71Sopenharmony_cigetSystemMemInfo(): SystemMemInfo 688e41f4b71Sopenharmony_ci 689e41f4b71Sopenharmony_ciObtains system memory information. 690e41f4b71Sopenharmony_ci 691e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 692e41f4b71Sopenharmony_ci 693e41f4b71Sopenharmony_ci**Return value** 694e41f4b71Sopenharmony_ci 695e41f4b71Sopenharmony_ci| Type | Description | 696e41f4b71Sopenharmony_ci| ------ | -------------------------- | 697e41f4b71Sopenharmony_ci| [SystemMemInfo](#systemmeminfo12) | System memory iInformation.| 698e41f4b71Sopenharmony_ci 699e41f4b71Sopenharmony_ci**Example** 700e41f4b71Sopenharmony_ci 701e41f4b71Sopenharmony_ci```ts 702e41f4b71Sopenharmony_ciimport { hidebug, hilog } from '@kit.PerformanceAnalysisKit'; 703e41f4b71Sopenharmony_ci 704e41f4b71Sopenharmony_cilet systemMemInfo: hidebug.SystemMemInfo = hidebug.getSystemMemInfo(); 705e41f4b71Sopenharmony_ci 706e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "totalMem = %{public}d", systemMemInfo.totalMem); 707e41f4b71Sopenharmony_ci 708e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "freeMem = %{public}d", systemMemInfo.freeMem); 709e41f4b71Sopenharmony_ci 710e41f4b71Sopenharmony_cihilog.info(0x0000, 'testTag', "availableMem = %{public}d", systemMemInfo.availableMem); 711e41f4b71Sopenharmony_ci``` 712e41f4b71Sopenharmony_ci 713e41f4b71Sopenharmony_ci## hidebug.getVMRuntimeStats<sup>12+</sup> 714e41f4b71Sopenharmony_ci 715e41f4b71Sopenharmony_cigetVMRuntimeStats(): GcStats 716e41f4b71Sopenharmony_ci 717e41f4b71Sopenharmony_ciObtains all system GC statistics. 718e41f4b71Sopenharmony_ci 719e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 720e41f4b71Sopenharmony_ci 721e41f4b71Sopenharmony_ci**Return value** 722e41f4b71Sopenharmony_ci 723e41f4b71Sopenharmony_ci| Type | Description | 724e41f4b71Sopenharmony_ci|-----------------------|----------| 725e41f4b71Sopenharmony_ci| [GcStats](#gcstats12) | System GC statistics. | 726e41f4b71Sopenharmony_ci 727e41f4b71Sopenharmony_ci**Example** 728e41f4b71Sopenharmony_ci 729e41f4b71Sopenharmony_ci```ts 730e41f4b71Sopenharmony_ciimport { hidebug, hilog } from '@kit.PerformanceAnalysisKit'; 731e41f4b71Sopenharmony_ci 732e41f4b71Sopenharmony_cilet vMRuntimeStats: hidebug.GcStats = hidebug.getVMRuntimeStats(); 733e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `gc-count: ${vMRuntimeStats['ark.gc.gc-count']}`); 734e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `gc-time: ${vMRuntimeStats['ark.gc.gc-time']}`); 735e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `gc-bytes-allocated: ${vMRuntimeStats['ark.gc.gc-bytes-allocated']}`); 736e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `gc-bytes-freed: ${vMRuntimeStats['ark.gc.gc-bytes-freed']}`); 737e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `fullgc-longtime-count: ${vMRuntimeStats['ark.gc.fullgc-longtime-count']}`); 738e41f4b71Sopenharmony_ci``` 739e41f4b71Sopenharmony_ci 740e41f4b71Sopenharmony_ci## hidebug.getVMRuntimeStat<sup>12+</sup> 741e41f4b71Sopenharmony_ci 742e41f4b71Sopenharmony_cigetVMRuntimeStat(item : string): number 743e41f4b71Sopenharmony_ci 744e41f4b71Sopenharmony_ciObtains the specified system GC statistics based on parameters. 745e41f4b71Sopenharmony_ci 746e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 747e41f4b71Sopenharmony_ci 748e41f4b71Sopenharmony_ci**Parameters** 749e41f4b71Sopenharmony_ci 750e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 751e41f4b71Sopenharmony_ci| -------- | ------ | ---- |-------------| 752e41f4b71Sopenharmony_ci| item | string | Yes | Item of the GC statistics to be obtained. | 753e41f4b71Sopenharmony_ci 754e41f4b71Sopenharmony_ci| Input Parameter | Return Value Description | 755e41f4b71Sopenharmony_ci|------------------------------|----------------| 756e41f4b71Sopenharmony_ci| ark.gc.gc-count | Count of GC of the calling thread. | 757e41f4b71Sopenharmony_ci| ark.gc.gc-time | GC time triggered by the calling thread, in milliseconds. | 758e41f4b71Sopenharmony_ci| ark.gc.gc-bytes-allocated | Memory size allocated to the Ark VM of the calling thread, in bytes.| 759e41f4b71Sopenharmony_ci| ark.gc.gc-bytes-freed | Memory freed by the GC of the calling thread, in bytes. | 760e41f4b71Sopenharmony_ci| ark.gc.fullgc-longtime-count | Count of long fullGC of the calling thread. | 761e41f4b71Sopenharmony_ci 762e41f4b71Sopenharmony_ci**Error codes** 763e41f4b71Sopenharmony_ci 764e41f4b71Sopenharmony_ci| ID | Error Message | 765e41f4b71Sopenharmony_ci| ------- |------------------------------------------------------------------------------------------------------------| 766e41f4b71Sopenharmony_ci| 401 | Possible causes:1. Invalid parameter, a string parameter required. 2. Invalid parameter, unknown property. | 767e41f4b71Sopenharmony_ci 768e41f4b71Sopenharmony_ci**Example** 769e41f4b71Sopenharmony_ci 770e41f4b71Sopenharmony_ci```ts 771e41f4b71Sopenharmony_ciimport { hidebug, hilog } from '@kit.PerformanceAnalysisKit'; 772e41f4b71Sopenharmony_ci 773e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `gc-count: ${hidebug.getVMRuntimeStat('ark.gc.gc-count')}`); 774e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `gc-time: ${hidebug.getVMRuntimeStat('ark.gc.gc-time')}`); 775e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `gc-bytes-allocated: ${hidebug.getVMRuntimeStat('ark.gc.gc-bytes-allocated')}`); 776e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `gc-bytes-freed: ${hidebug.getVMRuntimeStat('ark.gc.gc-bytes-freed')}`); 777e41f4b71Sopenharmony_cihilog.info(0x0000, "testTag", `fullgc-longtime-count: ${hidebug.getVMRuntimeStat('ark.gc.fullgc-longtime-count')}`); 778e41f4b71Sopenharmony_ci``` 779e41f4b71Sopenharmony_ci 780e41f4b71Sopenharmony_ci## MemoryLimit<sup>12+</sup> 781e41f4b71Sopenharmony_ci 782e41f4b71Sopenharmony_ciDefines the memory limit of the application process. 783e41f4b71Sopenharmony_ci 784e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 785e41f4b71Sopenharmony_ci 786e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 787e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------ | 788e41f4b71Sopenharmony_ci| rssLimit | bigint | Yes | Limit on the resident set size, in KB. | 789e41f4b71Sopenharmony_ci| vssLimit | bigint | Yes | Limit on the virtual memory size, in KB. | 790e41f4b71Sopenharmony_ci| vmHeapLimit | bigint | Yes | Limit on the JS VM heap size of the calling thread, in KB. | 791e41f4b71Sopenharmony_ci| vmTotalHeapSize | bigint | Yes | Size limit of the JS heap memory of the process, in KB. | 792e41f4b71Sopenharmony_ci 793e41f4b71Sopenharmony_ci## VMMemoryInfo<sup>12+</sup> 794e41f4b71Sopenharmony_ci 795e41f4b71Sopenharmony_ciDescribes the VM memory information. 796e41f4b71Sopenharmony_ci 797e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 798e41f4b71Sopenharmony_ci 799e41f4b71Sopenharmony_ci| Name | Type | Readable | Writable | Description | 800e41f4b71Sopenharmony_ci| -------------------| ------- | ---- | ---- | ---------------------------------- | 801e41f4b71Sopenharmony_ci| totalHeap | bigint | Yes | No | Total heap size of the current VM, in KB. | 802e41f4b71Sopenharmony_ci| heapUsed | bigint | Yes | No | Heap size used by the current VM, in KB. | 803e41f4b71Sopenharmony_ci| allArraySize | bigint | Yes | No | Size of all array objects of the current VM, in KB. | 804e41f4b71Sopenharmony_ci 805e41f4b71Sopenharmony_ci## ThreadCpuUsage<sup>12+</sup> 806e41f4b71Sopenharmony_ci 807e41f4b71Sopenharmony_ciDescribes the CPU usage of a thread. 808e41f4b71Sopenharmony_ci 809e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 810e41f4b71Sopenharmony_ci 811e41f4b71Sopenharmony_ci| Name | Type | Readable | Writable | Description | 812e41f4b71Sopenharmony_ci| -------------------| ------- | ---- | ---- | ----------------------------------- | 813e41f4b71Sopenharmony_ci| threadId | number | Yes | No | Thread ID. | 814e41f4b71Sopenharmony_ci| cpuUsage | number | Yes | No | CPU usage of the thread. | 815e41f4b71Sopenharmony_ci 816e41f4b71Sopenharmony_ci## tags<sup>12+</sup> 817e41f4b71Sopenharmony_ci 818e41f4b71Sopenharmony_ciEnumerates scenario tags. 819e41f4b71Sopenharmony_ci 820e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 821e41f4b71Sopenharmony_ci 822e41f4b71Sopenharmony_ci| Name | Type | Description | 823e41f4b71Sopenharmony_ci| -------------------------| ------- | ----------------------------------- | 824e41f4b71Sopenharmony_ci| ABILITY_MANAGER | number | Capability management. | 825e41f4b71Sopenharmony_ci| ARKUI | number | ArkUI development framework. | 826e41f4b71Sopenharmony_ci| ARK | number | JSVM VM. | 827e41f4b71Sopenharmony_ci| BLUETOOTH | number | Bluetooth. | 828e41f4b71Sopenharmony_ci| COMMON_LIBRARY | number | Common library subsystem. | 829e41f4b71Sopenharmony_ci| DISTRIBUTED_HARDWARE_DEVICE_MANAGER | number | Distributed hardware device management. | 830e41f4b71Sopenharmony_ci| DISTRIBUTED_AUDIO | number | Distributed audio. | 831e41f4b71Sopenharmony_ci| DISTRIBUTED_CAMERA | number | Distributed camera. | 832e41f4b71Sopenharmony_ci| DISTRIBUTED_DATA | number | Distributed data management. | 833e41f4b71Sopenharmony_ci| DISTRIBUTED_HARDWARE_FRAMEWORK | number | Distributed hardware framework. | 834e41f4b71Sopenharmony_ci| DISTRIBUTED_INPUT | number | Distributed input. | 835e41f4b71Sopenharmony_ci| DISTRIBUTED_SCREEN | number | Distributed screen. | 836e41f4b71Sopenharmony_ci| DISTRIBUTED_SCHEDULER | number | Distributed scheduler. | 837e41f4b71Sopenharmony_ci| FFRT | number | FFRT task. | 838e41f4b71Sopenharmony_ci| FILE_MANAGEMENT | number | File management system. | 839e41f4b71Sopenharmony_ci| GLOBAL_RESOURCE_MANAGER | number | Global resource management. | 840e41f4b71Sopenharmony_ci| GRAPHICS | number | Graphics module. | 841e41f4b71Sopenharmony_ci| HDF | number | HDF subsystem. | 842e41f4b71Sopenharmony_ci| MISC | number | MISC module. | 843e41f4b71Sopenharmony_ci| MULTIMODAL_INPUT | number | Multimodal input module. | 844e41f4b71Sopenharmony_ci| NET | number | Network. | 845e41f4b71Sopenharmony_ci| NOTIFICATION | number | Notification module. | 846e41f4b71Sopenharmony_ci| NWEB | number | Nweb. | 847e41f4b71Sopenharmony_ci| OHOS | number | OHOS. | 848e41f4b71Sopenharmony_ci| POWER_MANAGER | number | Power management. | 849e41f4b71Sopenharmony_ci| RPC | number | RPC. | 850e41f4b71Sopenharmony_ci| SAMGR | number | System capability management. | 851e41f4b71Sopenharmony_ci| WINDOW_MANAGER | number | Window management. | 852e41f4b71Sopenharmony_ci| AUDIO | number | Audio module. | 853e41f4b71Sopenharmony_ci| CAMERA | number | Camera module. | 854e41f4b71Sopenharmony_ci| IMAGE | number | Image module. | 855e41f4b71Sopenharmony_ci| MEDIA | number | Media module. | 856e41f4b71Sopenharmony_ci 857e41f4b71Sopenharmony_ci## NativeMemInfo<sup>12+</sup> 858e41f4b71Sopenharmony_ci 859e41f4b71Sopenharmony_ciDescribes memory information of the application process. 860e41f4b71Sopenharmony_ci 861e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 862e41f4b71Sopenharmony_ci 863e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 864e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------ | 865e41f4b71Sopenharmony_ci| pss | bigint | Yes | Size of the occupied physical memory (including the proportionally allocated memory occupied by the shared library), in KB. | 866e41f4b71Sopenharmony_ci| vss | bigint | Yes | Size of the occupied virtual memory (including the memory occupied by the shared library), in KB. | 867e41f4b71Sopenharmony_ci| rss | bigint | Yes | Size of the occupied physical memory (including the memory occupied by the shared library), in KB. | 868e41f4b71Sopenharmony_ci| sharedDirty | bigint | Yes | Size of the shared dirty memory, in KB. | 869e41f4b71Sopenharmony_ci| privateDirty | bigint | Yes | Size of the private dirty memory, in KB. | 870e41f4b71Sopenharmony_ci| sharedClean | bigint | Yes | Size of the shared clean memory, in KB. | 871e41f4b71Sopenharmony_ci| privateClean | bigint | Yes | Size of the private clean memory, in KB. | 872e41f4b71Sopenharmony_ci 873e41f4b71Sopenharmony_ci## SystemMemInfo<sup>12+</sup> 874e41f4b71Sopenharmony_ci 875e41f4b71Sopenharmony_ciDescribes the system memory information. 876e41f4b71Sopenharmony_ci 877e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 878e41f4b71Sopenharmony_ci 879e41f4b71Sopenharmony_ci| Name | Type | Mandatory | Description | 880e41f4b71Sopenharmony_ci| --------- | ------ | ---- | ------------ | 881e41f4b71Sopenharmony_ci| totalMem | bigint | Yes | Total memory of the system, in KB. | 882e41f4b71Sopenharmony_ci| freeMem | bigint | Yes | Free memory of the system, in KB. | 883e41f4b71Sopenharmony_ci| availableMem | bigint | Yes | Available memory of the system, in KB. | 884e41f4b71Sopenharmony_ci 885e41f4b71Sopenharmony_ci## TraceFlag<sup>12+</sup> 886e41f4b71Sopenharmony_ci 887e41f4b71Sopenharmony_ciDefines the type of the trace collection thread. 888e41f4b71Sopenharmony_ci 889e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 890e41f4b71Sopenharmony_ci 891e41f4b71Sopenharmony_ci| Name | Value | Description | 892e41f4b71Sopenharmony_ci| --------------------------- |---| ----------------------- | 893e41f4b71Sopenharmony_ci| MAIN_THREAD | 1 | The main thread of the application.| 894e41f4b71Sopenharmony_ci| ALL_THREADS | 2 | All threads of the application. | 895e41f4b71Sopenharmony_ci 896e41f4b71Sopenharmony_ci## GcStats<sup>12+</sup> 897e41f4b71Sopenharmony_ci 898e41f4b71Sopenharmony_citype GcStats = Record<string, number> 899e41f4b71Sopenharmony_ci 900e41f4b71Sopenharmony_ciKey-value pair format used to store GC statistics. This type is not multi-thread safe. If a **ValuesBucket** instance is operated by multiple threads at the same time in an application, use the lock mechanism for the instance. 901e41f4b71Sopenharmony_ci 902e41f4b71Sopenharmony_ci**System capability**: SystemCapability.HiviewDFX.HiProfiler.HiDebug 903e41f4b71Sopenharmony_ci 904e41f4b71Sopenharmony_ci| Type | Description | 905e41f4b71Sopenharmony_ci| -----------| ---------------------------- | 906e41f4b71Sopenharmony_ci| Record<string, number> | Indicates the value is in **Record** key-value pair format. | 907e41f4b71Sopenharmony_ci 908e41f4b71Sopenharmony_ci**GcStats** contain the following key values: 909e41f4b71Sopenharmony_ci 910e41f4b71Sopenharmony_ci| Name | Type | Description | 911e41f4b71Sopenharmony_ci|-------------------------| ------ |------------------------- | 912e41f4b71Sopenharmony_ci| ark.gc.gc-count | number | Count of GC of the calling thread.| 913e41f4b71Sopenharmony_ci| ark.gc.gc-time | number | GC time triggered by the calling thread, in milliseconds. | 914e41f4b71Sopenharmony_ci| ark.gc.gc-bytes-allocated | number | Memory size allocated to the Ark VM of the calling thread, in bytes. | 915e41f4b71Sopenharmony_ci| ark.gc.gc-bytes-freed | number | Memory freed by the GC of the calling thread, in bytes.| 916e41f4b71Sopenharmony_ci| ark.gc.fullgc-longtime-count | number | Count of long fullGC of the calling thread. | 917