1e41f4b71Sopenharmony_ci# Using HiDebug (C/C++)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciHiDebug provides APIs for application debugging.
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci## Available APIs
6e41f4b71Sopenharmony_ci| API                         | Description                             |
7e41f4b71Sopenharmony_ci| ------------------------------- | --------------------------------- |
8e41f4b71Sopenharmony_ci| OH_HiDebug_GetSystemCpuUsage    | Obtains the CPU usage of the system.|
9e41f4b71Sopenharmony_ci| OH_HiDebug_GetAppCpuUsage       | Obtains the CPU usage of an application.      |
10e41f4b71Sopenharmony_ci| OH_HiDebug_GetAppThreadCpuUsage | Obtains the CPU usage of all threads of an application.    |
11e41f4b71Sopenharmony_ci| OH_HiDebug_FreeThreadCpuUsage   | Releases the thread data structure.               |
12e41f4b71Sopenharmony_ci| OH_HiDebug_GetSystemMemInfo     | Obtains system memory information.               |
13e41f4b71Sopenharmony_ci| OH_HiDebug_GetAppNativeMemInfo  | Obtains the memory information of an application.     |
14e41f4b71Sopenharmony_ci| OH_HiDebug_GetAppMemoryLimit    | Obtains the memory limit of an application.     |
15e41f4b71Sopenharmony_ci| OH_HiDebug_StartAppTraceCapture | Starts application trace collection.              |
16e41f4b71Sopenharmony_ci| OH_HiDebug_StopAppTraceCapture  | Stops application trace collection.              |
17e41f4b71Sopenharmony_ci| OH_HiDebug_GetGraphicsMemory    | Obtains the size of the GPU memory.         |
18e41f4b71Sopenharmony_ci
19e41f4b71Sopenharmony_ciFor details about how to use the APIs (such as parameter usage restrictions and value ranges), see [HiDebug](../reference/apis-performance-analysis-kit/_hi_debug.md).
20e41f4b71Sopenharmony_ci
21e41f4b71Sopenharmony_ci## How to Develop
22e41f4b71Sopenharmony_ciThe following describes how to add a button in the application and click the button to call the HiDebug APIs.
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci1. Create a native C++ project. The directory structure is as follows:
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci   ```yml
27e41f4b71Sopenharmony_ci   entry:
28e41f4b71Sopenharmony_ci     src:
29e41f4b71Sopenharmony_ci       main:
30e41f4b71Sopenharmony_ci         cpp:
31e41f4b71Sopenharmony_ci           - types:
32e41f4b71Sopenharmony_ci               libentry:
33e41f4b71Sopenharmony_ci                 - index.d.ts
34e41f4b71Sopenharmony_ci           - CMakeLists.txt
35e41f4b71Sopenharmony_ci           - napi_init.cpp
36e41f4b71Sopenharmony_ci         ets:
37e41f4b71Sopenharmony_ci           - entryability:
38e41f4b71Sopenharmony_ci               - EntryAbility.ts
39e41f4b71Sopenharmony_ci           - pages:
40e41f4b71Sopenharmony_ci               - Index.ets
41e41f4b71Sopenharmony_ci   ```
42e41f4b71Sopenharmony_ci
43e41f4b71Sopenharmony_ci2. In the **CMakeLists.txt** file, add the dependencies.
44e41f4b71Sopenharmony_ci
45e41f4b71Sopenharmony_ci   ```cmake
46e41f4b71Sopenharmony_ci   # Add libhiappevent_ndk.z.so and libhilog_ndk.z.so (log output). 
47e41f4b71Sopenharmony_ci   target_link_libraries(entry PUBLIC libace_napi.z.so libhilog_ndk.z.so libohhidebug.so)
48e41f4b71Sopenharmony_ci   ```
49e41f4b71Sopenharmony_ci
50e41f4b71Sopenharmony_ci3. Import the dependencies to the **napi_init.cpp** file, and define **LOG_TAG** and the test method.
51e41f4b71Sopenharmony_ci
52e41f4b71Sopenharmony_ci   The following calls **OH_HiDebug_GetSystemCpuUsage()** and outputs the return value. For details about how to use other APIs, see [HiDebug](../reference/apis-performance-analysis-kit/_hi_debug.md).
53e41f4b71Sopenharmony_ci
54e41f4b71Sopenharmony_ci   ```c++
55e41f4b71Sopenharmony_ci   # include "napi/native_api.h"
56e41f4b71Sopenharmony_ci   # include "hilog/log.h"
57e41f4b71Sopenharmony_ci   # include "hidebug/hidebug.h"
58e41f4b71Sopenharmony_ci   
59e41f4b71Sopenharmony_ci   # undef LOG_TAG
60e41f4b71Sopenharmony_ci   # define LOG_TAG "testTag"
61e41f4b71Sopenharmony_ci   
62e41f4b71Sopenharmony_ci   static napi_value TestHidebugNdk(napi_env env, napi_callback_info info)
63e41f4b71Sopenharmony_ci   {
64e41f4b71Sopenharmony_ci       double cpuUsage = OH_HiDebug_GetSystemCpuUsage();
65e41f4b71Sopenharmony_ci       OH_LOG_INFO(LogType::LOG_APP, "GetSystemCpuUsage: %{public}f", cpuUsage);
66e41f4b71Sopenharmony_ci       return 0;
67e41f4b71Sopenharmony_ci   }
68e41f4b71Sopenharmony_ci   ```
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci4. Register **TestHidebugNdk** as an ArkTS API.
71e41f4b71Sopenharmony_ci
72e41f4b71Sopenharmony_ci   In the **napi_init.cpp** file, register **TestHidebugNdk** as an ArkTS API.
73e41f4b71Sopenharmony_ci
74e41f4b71Sopenharmony_ci   ```c++
75e41f4b71Sopenharmony_ci   static napi_value Init(napi_env env, napi_value exports)
76e41f4b71Sopenharmony_ci   {
77e41f4b71Sopenharmony_ci       napi_property_descriptor desc[] = {
78e41f4b71Sopenharmony_ci           { "testHidebugNdk", nullptr, TestHidebugNdk, nullptr, nullptr, nullptr, napi_default, nullptr }
79e41f4b71Sopenharmony_ci       };
80e41f4b71Sopenharmony_ci       napi_define_properties(env, exports, sizeof(desc) / sizeof(desc[0]), desc);
81e41f4b71Sopenharmony_ci       return exports;
82e41f4b71Sopenharmony_ci   }
83e41f4b71Sopenharmony_ci   ```
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci   In the **index.d.ts** file, define the ArkTS API.
86e41f4b71Sopenharmony_ci
87e41f4b71Sopenharmony_ci   ```typescript
88e41f4b71Sopenharmony_ci   export const testHidebugNdk: () => void;
89e41f4b71Sopenharmony_ci   ```
90e41f4b71Sopenharmony_ci
91e41f4b71Sopenharmony_ci5. In the **Index.ets** file, add a click event to the **Text** component. The sample code is as follows:
92e41f4b71Sopenharmony_ci
93e41f4b71Sopenharmony_ci   ```ts
94e41f4b71Sopenharmony_ci   import testNapi from 'libentry.so'
95e41f4b71Sopenharmony_ci   
96e41f4b71Sopenharmony_ci   @Entry
97e41f4b71Sopenharmony_ci   @Component
98e41f4b71Sopenharmony_ci   struct Index {
99e41f4b71Sopenharmony_ci     @State message: string = 'Hello World'
100e41f4b71Sopenharmony_ci   
101e41f4b71Sopenharmony_ci     build() {
102e41f4b71Sopenharmony_ci       Row() {
103e41f4b71Sopenharmony_ci         Column() {
104e41f4b71Sopenharmony_ci           Text(this.message)
105e41f4b71Sopenharmony_ci             .fontSize(50)
106e41f4b71Sopenharmony_ci             .fontWeight(FontWeight.Bold)
107e41f4b71Sopenharmony_ci             .onClick(testNapi.testHidebugNdk);// Add a click event to trigger testHidebugNdk().
108e41f4b71Sopenharmony_ci         }
109e41f4b71Sopenharmony_ci         .width('100%')
110e41f4b71Sopenharmony_ci       }
111e41f4b71Sopenharmony_ci       .height('100%')
112e41f4b71Sopenharmony_ci     }
113e41f4b71Sopenharmony_ci   }
114e41f4b71Sopenharmony_ci   ```
115e41f4b71Sopenharmony_ci
116e41f4b71Sopenharmony_ci6. Click the **Run** button in DevEco Studio to run the project, and click "Hello world".
117e41f4b71Sopenharmony_ci
118e41f4b71Sopenharmony_ci7. At the bottom of DevEco Studio, switch to the **Log** tab and set the filter criteria to **testTag**.
119e41f4b71Sopenharmony_ci   Then, the CPU usage logs obtained using **OH_HiDebug_GetSystemCpuUsage()** are displayed in the window.
120e41f4b71Sopenharmony_ci
121e41f4b71Sopenharmony_ci   ```Text
122e41f4b71Sopenharmony_ci   09-10 09:40:26.755 17221-17221/com.example.myapplication I A00000/testTag: GetSystemCpuUsage: 0.083904
123e41f4b71Sopenharmony_ci   ```
124e41f4b71Sopenharmony_ci
125e41f4b71Sopenharmony_ci<!--no_check-->