1e41f4b71Sopenharmony_ci 2e41f4b71Sopenharmony_ci# Using HiDumper to Improve Performance 3e41f4b71Sopenharmony_ci 4e41f4b71Sopenharmony_ci## Introduction 5e41f4b71Sopenharmony_ci 6e41f4b71Sopenharmony_ciHiDumper is a command line tool that developers, testers, and IDE tool engineers can use to obtain system information necessary for analyzing and locating faults. During application development, you can use HiDumper to obtain the UI component tree information, which can be used with a graphical tool such as ArkUI Inspector to locate layout performance issues. You can also use HiDumper to obtain system data such as memory and CPU usage to evaluate application performance. 7e41f4b71Sopenharmony_ci 8e41f4b71Sopenharmony_ciThis document provides a walkthrough of using HiDumper to analyze application performance. For more details about HiDumper, see [HiDumper](../../device-dev/subsystems/subsys-dfx-hidumper.md) 9e41f4b71Sopenharmony_ci 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci## Viewing Component Information 12e41f4b71Sopenharmony_ci 13e41f4b71Sopenharmony_ciCompared with ArkUI Inspector, HiDumper allows you to obtain fine-grained component information more flexibly. 14e41f4b71Sopenharmony_ci 15e41f4b71Sopenharmony_ci1. Enable the debug mode of ArkUI. 16e41f4b71Sopenharmony_ci ``` 17e41f4b71Sopenharmony_ci hdc shell param set persist.ace.debug.enabled 1 18e41f4b71Sopenharmony_ci ``` 19e41f4b71Sopenharmony_ci2. Restart the application. 20e41f4b71Sopenharmony_ci3. Obtain the window ID of the current page. 21e41f4b71Sopenharmony_ci ``` 22e41f4b71Sopenharmony_ci hdc shell hidumper -s WindowManagerService -a '-a' 23e41f4b71Sopenharmony_ci ``` 24e41f4b71Sopenharmony_ci 25e41f4b71Sopenharmony_ci  26e41f4b71Sopenharmony_ci 27e41f4b71Sopenharmony_ci 28e41f4b71Sopenharmony_ci * **hidumper -s**: exports all ability information of the system. 29e41f4b71Sopenharmony_ci * **idumper -s WindowManagerService -a ['-a']**: exports the ability information of the open window. **-a** indicates that the information is printed, and **['-a']** indicates the detailed information to be printed. 30e41f4b71Sopenharmony_ci * **WindowName**: name of the open window. **demo0** is the default window name of the sample application. 31e41f4b71Sopenharmony_ci * The table below lists the mapping between **WindowName** values and built-in application windows. 32e41f4b71Sopenharmony_ci 33e41f4b71Sopenharmony_ci | WindowName | Description | 34e41f4b71Sopenharmony_ci |----------------------|------| 35e41f4b71Sopenharmony_ci | EntryView | Home screen | 36e41f4b71Sopenharmony_ci | RecentView | Recent Tasks screen| 37e41f4b71Sopenharmony_ci | SystemUi_NavigationB | Three-button navigation| 38e41f4b71Sopenharmony_ci | SystemUi_StatusBar | Status bar | 39e41f4b71Sopenharmony_ci | ScreenLockWindow | Magazine unlock | 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci4. Obtain the component tree file of the target page based on **WinId** (window ID). 42e41f4b71Sopenharmony_ci ``` 43e41f4b71Sopenharmony_ci hdc shell hidumper -s WindowManagerService -a '-w 28 -element -c' // 28 is the obtained window ID. 44e41f4b71Sopenharmony_ci ``` 45e41f4b71Sopenharmony_ci 46e41f4b71Sopenharmony_ci  47e41f4b71Sopenharmony_ci 48e41f4b71Sopenharmony_ci 49e41f4b71Sopenharmony_ci5. Download the component tree file to the local device. Due to the security mechanism, the path obtained is not a real path. You need to run the **find** command to search for the file. 50e41f4b71Sopenharmony_ci ``` 51e41f4b71Sopenharmony_ci hdc shell find /data/ -name arkui.dump 52e41f4b71Sopenharmony_ci ``` 53e41f4b71Sopenharmony_ci 54e41f4b71Sopenharmony_ci  55e41f4b71Sopenharmony_ci 56e41f4b71Sopenharmony_ci ``` 57e41f4b71Sopenharmony_ci hdc file recv /data/app/el2/100/base/com.example.demo/haps/entry/files/arkui.dump . // Obtain the file and save it to the local device. 58e41f4b71Sopenharmony_ci ``` 59e41f4b71Sopenharmony_ci6. Open the component tree file, which lists the properties of each component, such as the number of child components (**childSize**), component ID, and background color (**BackgroundColor**). 60e41f4b71Sopenharmony_ci ``` 61e41f4b71Sopenharmony_ci // Fragment of the arkui.dump file 62e41f4b71Sopenharmony_ci |-> GridItem childSize:1 63e41f4b71Sopenharmony_ci | ID: 22 64e41f4b71Sopenharmony_ci | Depth: 9 65e41f4b71Sopenharmony_ci | IsDisappearing: 0 66e41f4b71Sopenharmony_ci | FrameRect: RectT (360.00, 0.00) - [180.00 x 29.00] 67e41f4b71Sopenharmony_ci | BackgroundColor: #00000000 68e41f4b71Sopenharmony_ci ... 69e41f4b71Sopenharmony_ci |-> Stack childSize:1 70e41f4b71Sopenharmony_ci | ID: 23 71e41f4b71Sopenharmony_ci | Depth: 10 72e41f4b71Sopenharmony_ci | IsDisappearing: 0 73e41f4b71Sopenharmony_ci | FrameRect: RectT (0.00, 0.00) - [180.00 x 29.00] 74e41f4b71Sopenharmony_ci | BackgroundColor: #FFFFFF00 75e41f4b71Sopenharmony_ci ... 76e41f4b71Sopenharmony_ci |-> Stack childSize:1 77e41f4b71Sopenharmony_ci | ID: 24 78e41f4b71Sopenharmony_ci | Depth: 11 79e41f4b71Sopenharmony_ci | IsDisappearing: 0 80e41f4b71Sopenharmony_ci | FrameRect: RectT (0.00, 0.00) - [180.00 x 29.00] 81e41f4b71Sopenharmony_ci | BackgroundColor: #FF0000FF 82e41f4b71Sopenharmony_ci ... 83e41f4b71Sopenharmony_ci |-> Stack childSize:1 84e41f4b71Sopenharmony_ci | ID: 25 85e41f4b71Sopenharmony_ci | Depth: 12 86e41f4b71Sopenharmony_ci | IsDisappearing: 0 87e41f4b71Sopenharmony_ci | FrameRect: RectT (0.00, 0.00) - [180.00 x 29.00] 88e41f4b71Sopenharmony_ci | BackgroundColor: #00000000 89e41f4b71Sopenharmony_ci ... 90e41f4b71Sopenharmony_ci |-> Text childSize:0 91e41f4b71Sopenharmony_ci ID: 26 92e41f4b71Sopenharmony_ci Depth: 13 93e41f4b71Sopenharmony_ci IsDisappearing: 0 94e41f4b71Sopenharmony_ci FrameRect: RectT (83.00, 0.00) - [14.00 x 29.00] 95e41f4b71Sopenharmony_ci BackgroundColor: #00000000 96e41f4b71Sopenharmony_ci ... 97e41f4b71Sopenharmony_ci ``` 98e41f4b71Sopenharmony_ci 99e41f4b71Sopenharmony_ci### Viewing the if/else Component 100e41f4b71Sopenharmony_ci 101e41f4b71Sopenharmony_ciWhen **if/else** is used, the **if/else** statement is regarded as a component and exists in the component tree as a node. When you run HiDumper commands, the printed component tree contains the **if/else** component information. (On contrast, in ArkUI Inspector, the **if/else** component is not displayed as a node in the component tree.) In the following code, the **if(this.isShow)** statement is used to create and destroy a **\<Row>** component. 102e41f4b71Sopenharmony_ci``` 103e41f4b71Sopenharmony_ci@Entry 104e41f4b71Sopenharmony_ci@Component 105e41f4b71Sopenharmony_cistruct ConditionComponent { 106e41f4b71Sopenharmony_ci @State isShow: boolean = true; 107e41f4b71Sopenharmony_ci 108e41f4b71Sopenharmony_ci build() { 109e41f4b71Sopenharmony_ci Column() { 110e41f4b71Sopenharmony_ci Button ("Show/Hide") 111e41f4b71Sopenharmony_ci .onClick(() => { 112e41f4b71Sopenharmony_ci this.isShow = !this.isShow 113e41f4b71Sopenharmony_ci }) 114e41f4b71Sopenharmony_ci if (this.isShow) { 115e41f4b71Sopenharmony_ci Row() 116e41f4b71Sopenharmony_ci .width(300).height(300).backgroundColor(Color.Pink) 117e41f4b71Sopenharmony_ci } 118e41f4b71Sopenharmony_ci }.width('100%') 119e41f4b71Sopenharmony_ci } 120e41f4b71Sopenharmony_ci} 121e41f4b71Sopenharmony_ci``` 122e41f4b71Sopenharmony_ciWhen **isShow** is set to **true**, the **\<Row>** component is shown. At this time, in the component tree file from HiDumper, you can find that the **if/else** component is created as a node, and the **\<Row>** component is nested as a child component. 123e41f4b71Sopenharmony_ci``` 124e41f4b71Sopenharmony_ci|-> IfElse childSize:1 125e41f4b71Sopenharmony_ci | ID: 9 126e41f4b71Sopenharmony_ci | Depth: 6 127e41f4b71Sopenharmony_ci | IsDisappearing: 0 128e41f4b71Sopenharmony_ci |-> Row childSize:0 129e41f4b71Sopenharmony_ci ID: 12 130e41f4b71Sopenharmony_ci Depth: 7 131e41f4b71Sopenharmony_ci IsDisappearing: 0 132e41f4b71Sopenharmony_ci FrameRect: RectT (135.00, 60.00) - [450.00 x 450.00] 133e41f4b71Sopenharmony_ci BackgroundColor: #FFFFC0CB 134e41f4b71Sopenharmony_ci ParentLayoutConstraint: minSize: [[0.00 x 0.00]]maxSize: [[720.00 x 1136.00]]percentReference: [[720.00 x 1136.00]]parentIdealSize: [[720.00 x NA]]selfIdealSize: [[NA x NA]] 135e41f4b71Sopenharmony_ci top: 60.000000 left: 135.000000 136e41f4b71Sopenharmony_ci Active: 1 137e41f4b71Sopenharmony_ci Visible: 0 138e41f4b71Sopenharmony_ci ... 139e41f4b71Sopenharmony_ci``` 140e41f4b71Sopenharmony_ciWhen **isShow** is set to **false**, the **\<Row>** component is hidden. At this time, in the component tree file from HiDumper, you can find that the **if/else** component is created as a node, but the **\<Row>** component is not loaded. 141e41f4b71Sopenharmony_ci``` 142e41f4b71Sopenharmony_ci|-> IfElse childSize:0 143e41f4b71Sopenharmony_ci ID: 9 144e41f4b71Sopenharmony_ci Depth: 6 145e41f4b71Sopenharmony_ci IsDisappearing: 0 146e41f4b71Sopenharmony_ci``` 147e41f4b71Sopenharmony_ci 148e41f4b71Sopenharmony_ci### Viewing the visibility Attribute 149e41f4b71Sopenharmony_ci 150e41f4b71Sopenharmony_ciYou can use the **visibility** attribute to control the visibility of components. In the following code, the **visibility(this.isVisible)** attribute is used to show and hide the **\<Row>** component. 151e41f4b71Sopenharmony_ci``` 152e41f4b71Sopenharmony_ci@Entry 153e41f4b71Sopenharmony_ci@Component 154e41f4b71Sopenharmony_cistruct VisibilityComponent { 155e41f4b71Sopenharmony_ci @State isVisible: Visibility = Visibility.Visible; 156e41f4b71Sopenharmony_ci 157e41f4b71Sopenharmony_ci build() { 158e41f4b71Sopenharmony_ci Column() { 159e41f4b71Sopenharmony_ci Button("Visible") 160e41f4b71Sopenharmony_ci .onClick(() => { 161e41f4b71Sopenharmony_ci this.isVisible = Visibility.Visible 162e41f4b71Sopenharmony_ci }) 163e41f4b71Sopenharmony_ci Button("Hidden") 164e41f4b71Sopenharmony_ci .onClick(() => { 165e41f4b71Sopenharmony_ci this.isVisible = Visibility.Hidden 166e41f4b71Sopenharmony_ci }) 167e41f4b71Sopenharmony_ci Button("None") 168e41f4b71Sopenharmony_ci .onClick(() => { 169e41f4b71Sopenharmony_ci this.isVisible = Visibility.None 170e41f4b71Sopenharmony_ci }) 171e41f4b71Sopenharmony_ci Row().visibility(this.isVisible) 172e41f4b71Sopenharmony_ci .width(720).height(300).backgroundColor(Color.Pink) 173e41f4b71Sopenharmony_ci }.width('100%') 174e41f4b71Sopenharmony_ci } 175e41f4b71Sopenharmony_ci} 176e41f4b71Sopenharmony_ci``` 177e41f4b71Sopenharmony_ciWhen **isVisible** is set to **Visible**, the **\<Row>** component is shown. At this time, in the component tree file from HiDumper, you can find that the value of **Visible** is **0**, and the width and height of the component in the **FrameRect** attribute are **450**. 178e41f4b71Sopenharmony_ci``` 179e41f4b71Sopenharmony_ci|-> Row childSize:0 180e41f4b71Sopenharmony_ci ID: 13 181e41f4b71Sopenharmony_ci Depth: 6 182e41f4b71Sopenharmony_ci IsDisappearing: 0 183e41f4b71Sopenharmony_ci FrameRect: RectT (135.00, 180.00) - [450.00 x 450.00] 184e41f4b71Sopenharmony_ci BackgroundColor: #FFFFC0CB 185e41f4b71Sopenharmony_ci ParentLayoutConstraint: minSize: [[0.00 x 0.00]]maxSize: [[720.00 x 1136.00]]percentReference: [[720.00 x 1136.00]]parentIdealSize: [[720.00 x NA]]selfIdealSize: [[NA x NA]] 186e41f4b71Sopenharmony_ci top: 180.000000 left: 135.000000 187e41f4b71Sopenharmony_ci Active: 1 188e41f4b71Sopenharmony_ci Visible: 0 189e41f4b71Sopenharmony_ci ... 190e41f4b71Sopenharmony_ci``` 191e41f4b71Sopenharmony_ciWhen **isVisible** is set to **Hidden**, the **\<Row>** component is hidden. At this time, in the component tree file from HiDumper, you can find that the value of **Visible** is **1**, and the width and height of the component in the **FrameRect** attribute are **450**. 192e41f4b71Sopenharmony_ci``` 193e41f4b71Sopenharmony_ci|-> Row childSize:0 194e41f4b71Sopenharmony_ci ID: 13 195e41f4b71Sopenharmony_ci Depth: 6 196e41f4b71Sopenharmony_ci IsDisappearing: 0 197e41f4b71Sopenharmony_ci FrameRect: RectT (135.00, 180.00) - [450.00 x 450.00] 198e41f4b71Sopenharmony_ci BackgroundColor: #FFFFC0CB 199e41f4b71Sopenharmony_ci ParentLayoutConstraint: minSize: [[0.00 x 0.00]]maxSize: [[720.00 x 1136.00]]percentReference: [[720.00 x 1136.00]]parentIdealSize: [[720.00 x NA]]selfIdealSize: [[NA x NA]] 200e41f4b71Sopenharmony_ci top: 180.000000 left: 135.000000 201e41f4b71Sopenharmony_ci Active: 1 202e41f4b71Sopenharmony_ci Visible: 1 203e41f4b71Sopenharmony_ci ... 204e41f4b71Sopenharmony_ci``` 205e41f4b71Sopenharmony_ciWhen **isVisible** is set to **None**, the **\<Row>** component is hidden. At this time, in the component tree file from HiDumper, you can find that the value of **Visible** is **2**, and the width and height of the component in the **FrameRect** attribute are **0**. 206e41f4b71Sopenharmony_ci``` 207e41f4b71Sopenharmony_ci|-> Row childSize:0 208e41f4b71Sopenharmony_ci ID: 13 209e41f4b71Sopenharmony_ci Depth: 6 210e41f4b71Sopenharmony_ci IsDisappearing: 0 211e41f4b71Sopenharmony_ci FrameRect: RectT (135.00, 180.00) - [0.00 x 0.00] 212e41f4b71Sopenharmony_ci BackgroundColor: #FFFFC0CB 213e41f4b71Sopenharmony_ci ParentLayoutConstraint: minSize: [[0.00 x 0.00]]maxSize: [[720.00 x 1136.00]]percentReference: [[720.00 x 1136.00]]parentIdealSize: [[720.00 x NA]]selfIdealSize: [[NA x NA]] 214e41f4b71Sopenharmony_ci top: 180.000000 left: 135.000000 215e41f4b71Sopenharmony_ci Active: 1 216e41f4b71Sopenharmony_ci Visible: 2 217e41f4b71Sopenharmony_ci ... 218e41f4b71Sopenharmony_ci``` 219e41f4b71Sopenharmony_ciBy comparing the number of components in preceding cases, we can find that: 220e41f4b71Sopenharmony_ci* When the **visibility** attribute is used to control the visibility of a component, the component's **Visible** attribute changes based on the settings, but its other structures are created regardless of the settings. 221e41f4b71Sopenharmony_ci* When the **visibility** attribute is set to **Hidden**, the component is hidden, but still takes up space on the page. 222e41f4b71Sopenharmony_ci 223e41f4b71Sopenharmony_ci## Viewing Memory Information 224e41f4b71Sopenharmony_ci 225e41f4b71Sopenharmony_ciTo obtain the memory information of an application: 226e41f4b71Sopenharmony_ci 227e41f4b71Sopenharmony_ci1. Open the application and run **hdc shell hidumper -s WindowManagerService -a '-a'** to obtain the PID of the application. 228e41f4b71Sopenharmony_ci2. Run **hidumper --mem [pid]**, replacing **[pid]** with the actual PID of the application, to obtain the memory information, as shown in the following figure. 229e41f4b71Sopenharmony_ci``` 230e41f4b71Sopenharmony_cihdc shell hidumper --mem [pid] 231e41f4b71Sopenharmony_ci``` 232e41f4b71Sopenharmony_ci 233e41f4b71Sopenharmony_ci 234e41f4b71Sopenharmony_ci 235e41f4b71Sopenharmony_ciIn general cases, you only need to pay attention to the data in the **Pss Total** column, which provides the physical memory actually used by the application. In this example, the application occupies 53395 KB of memory, including 3411 KB of the ArkUI heap memory (**ark ts heap**) and 45846 KB of the native heap memory. 236e41f4b71Sopenharmony_ci 237e41f4b71Sopenharmony_ci## Viewing CPU Information 238e41f4b71Sopenharmony_ci 239e41f4b71Sopenharmony_ciWith CPU information from HiDumper, you can identify performance issues regarding CPU usage, which is especially useful when your application involves large computing scenarios. The following example shows how to check the CPU information of the Chat application. 240e41f4b71Sopenharmony_ci 241e41f4b71Sopenharmony_ci1. Compile the project, install and open the Chat application, and run the following HiDumper command to obtain the PID of the application. 242e41f4b71Sopenharmony_ci ``` 243e41f4b71Sopenharmony_ci hdc shell hidumper -s WindowManagerService -a '-a' 244e41f4b71Sopenharmony_ci ``` 245e41f4b71Sopenharmony_ci2. Run **hidumper --cpuusage [pid]** to obtain the CPU information of the Chat application. 246e41f4b71Sopenharmony_ci ``` 247e41f4b71Sopenharmony_ci hdc shell hidumper --cpuusage [pid] 248e41f4b71Sopenharmony_ci ``` 249e41f4b71Sopenharmony_ci 250e41f4b71Sopenharmony_ci  251e41f4b71Sopenharmony_ci 252e41f4b71Sopenharmony_ci Your primary concern would be **Total Usage**, **User Space**, and **Kernel Space**. **Total Usage** shows the total CPU usage of applications, **User Space** shows the CPU usage for simple calculation, and **Kernel Space** shows CPU usage for calling system resources. As shown in the preceding figure, the values of these three items are 11%, 11%, and 0%, indicating that the application does not call system resources. In this case, you only need to check the user space of the application. To view the CPU usage for a specific period of time, run the **hdc shell hidumper --cpuusage [pid]** command multiple times through the shell script, and then export the result to the **/data/log/hidumper** directory of the local device through **hdc shell hidumper --zip --cpuusage**. 253