• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# Using HiDebug APIs (ArkTS)
2
3<!--Kit: Performance Analysis Kit-->
4<!--Subsystem: HiviewDFX-->
5<!--Owner: @hello_harmony; @yu_haoqiaida-->
6<!--Designer: @kutcherzhou1-->
7<!--Tester: @gcw_KuLfPSbe-->
8<!--Adviser: @foryourself-->
9
10The HiDebug ArkTS APIs are independent. You can call them to obtain debugging information. For details about how to call the APIs, see the examples in [@ohos.hidebug (HiDebug)](../reference/apis-performance-analysis-kit/js-apis-hidebug.md).
11
12## How to Develop
13
14This topic describes how to call the HiDebug ArkTS API to obtain the system CPU usage.
15
161. Use DevEco Studio to create a project and select **Empty Ability**.
17
182. In the **Project** window, click **entry** > **src** > **main** > **ets** > **pages** to open and edit the **Index.ets** file.
19
20   ```typescript
21   import { hidebug } from '@kit.PerformanceAnalysisKit';
22   import { BusinessError } from '@kit.BasicServicesKit';
23
24   function testHiDebugArk () { // Implement the API as required.
25     try {
26       let ret = hidebug.getSystemCpuUsage();
27       console.info(`TestTag getSystemCpuUsage: ${ret}`);
28     } catch (error) {
29       console.error(`error code: ${(error as BusinessError).code}, error msg: ${(error as BusinessError).message}`);
30     }
31   }
32
33   @Entry
34   @Component
35   struct Index {
36     build() {
37       Row() {
38         Column() {
39           Button("testHiDebugArk")
40             .type(ButtonType.Capsule)
41             .margin({
42               top: 20
43             })
44             .backgroundColor('#0D9FFB')
45             .width('60%')
46             .height('5%')
47             // Add a click event.
48             .onClick(testHiDebugArk);
49         }
50         .width('100%')
51       }
52       .height('100%')
53     }
54   }
55   ```
56
573. Click **Run**, and then click the **testHiDebugArk** button on the device to trigger API calling.
58
594. If any logs are generated while the API is being called, open the **Log** window at the bottom of DevEco Studio to view them.
60
61   ```Text
62   06-02 16:53:22.538   31077-31077   A03D00/com.exa...ication/JSAPP  com.examp...lication  I     TestTag getSystemCpuUsage: 0.09963547995139732
63   ```
64