1# Using HiDebug (ArkTS) 2 3HiDebug provides APIs for system debugging, which allow you to obtain the information of static heap memory (native heap) and proportional set size (PSS) occupied by the application process, export VM memory slices, and collect VM CPU profiling data. 4 5## Available APIs 6 7| API | Description | 8| ---------------------------------- | ------------------------------------------------------------ | 9| hidebug.getNativeHeapSize | Obtains the size of heap memory (including the allocator metadata) held by a process, which is measured by the memory allocator.| 10| hidebug.getNativeHeapAllocatedSize | Obtains the size of the heap memory allocated to a process service, which is measured by the memory allocator. | 11| hidebug.getNativeHeapFreeSize | Obtains the size of the cache memory held by the memory allocator. | 12| hidebug.getPss | Obtains the size of the physical memory actually used by the application process. | 13| hidebug.getVss | Obtains the virtual set size used by the application process. | 14| hidebug.getSharedDirty | Obtains the size of the shared dirty memory of a process. | 15| hidebug.getPrivateDirty | Obtains the size of the private dirty memory of a process. | 16| hidebug.getCpuUsage | Obtains the CPU usage of a process. | 17| hidebug.dumpJsHeapData | Exports the heap data. | 18| hidebug.startJsCpuProfiling | Starts the VM profiling method. | 19| hidebug.stopJsCpuProfiling | Stops the VM profiling method. | 20| hidebug.getAppVMMemoryInfo | Obtains VM memory information. | 21| hidebug.getAppThreadCpuUsage | Obtains the CPU usage of application threads. | 22| hidebug.startAppTraceCapture | Starts application trace collection. | 23| hidebug.stopAppTraceCapture | Stops application trace collection. | 24| hidebug.getAppMemoryLimit | Obtains the memory limit of the application process. | 25| hidebug.getSystemCpuUsage | Obtains the CPU usage of the system. | 26| hidebug.setAppResourceLimit | Sets the number of FDs, number of threads, JS memory, or native memory limit of the application. | 27| hidebug.getAppNativeMemInfo | Obtains the memory information of the application process. | 28| hidebug.getSystemMemInfo | Obtains system memory information. | 29| hidebug.getVMRuntimeStats | Obtains all system GC statistics. | 30| hidebug.getVMRuntimeStat | Obtains the specified system GC statistics based on parameters. | 31| hidebug.getGraphicsMemory | Obtains the size of the GPU memory asynchronously. | 32| hidebug.getGraphicsMemorySync | Obtains the size of the GPU memory synchronously. | 33 34For details about how to use HiDebug, see the API Reference (../reference/apis-performance-analysis-kit/js-apis-hidebug.md). 35 36## How to Develop 37 38The following describes how to add a button in the application and click the button to call the hidebug APIs. 39 401. Create a project, with **Empty Ability** as the template. 41 422. On the project configuration page, set **Model** to **Stage**. 43 443. In the **Project** window, click **entry > src > main > ets > pages** to open the **Index.ets** file. 45 46 The following shows how to add **hidebug.getSystemCpuUsage()** to call the hidebug APIs. For details about how to use other APIs, see [API Reference](../reference/apis-performance-analysis-kit/js-apis-hidebug.md). 47 48 ```ts 49 import { hidebug, hilog } from '@kit.PerformanceAnalysisKit'; 50 function testHidebug(event?: ClickEvent) { 51 hilog.info(0x0000, "testTag", `getCurrentCpuUsage ${hidebug.getSystemCpuUsage()}`); 52 } 53 ``` 54 55 Add a click event to the **Text** component. The sample code is as follows: 56 57 ```ts 58 @Entry 59 @Component 60 struct Index { 61 @State message: string = 'Hello World' 62 63 build() { 64 Row() { 65 Column() { 66 Text(this.message) 67 .fontSize(50) 68 .fontWeight(FontWeight.Bold) 69 .onClick(testHidebug);// Add a click event. 70 } 71 .width('100%') 72 } 73 .height('100%') 74 } 75 } 76 ``` 77 784. Run the project on a real device and click "Hello World" on the app/service. 79 805. At the bottom of DevEco Studio, switch to the **Log** tab and set the filter criteria to **testTag**. 81 Then, the CPU usage logs obtained using **hidebug.getSystemCpuUsage()** are displayed in the window. 82 ```Text 83 06-25 19:50:27.485 24645-24645/com.example.myapplication I A00000/testTag: getCurrentCpuUsage 0.10164512338425381 84 ``` 85 86<!--RP1--> 87<!--RP1End--> 88