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