目录

UI Profiling

This topic describes tools for inspecting the UI hierarchy and profiling performance, designed to enhance development efficiency and optimize the developer experience.

State Management: hidumper, Profiler, and Inspector

To improve the efficiency of diagnosing state management issues, the framework provides hidumper, Profiler, and Inspector capabilities for state variables. These tools offer insights into the internal state of variables, enabling you to better understand the relationship between state variables and UI components, which facilitates the development of high-performance applications.

[h2]State Management: hidumper

The state management framework integrates with hidumper. You can use the -jsdump command to inspect information such as components associated with state variables and custom component trees.

The following describes the meaning of each -jsdump parameter:

In addition to the commands above, you can enter the following commands to enable recursive printing or to print information for a specific component ID. If not specified, only the root node information of the page is printed by default.

The following is a specific example:

Example:

The following example demonstrates a typical two-layer nested component structure using @State and @Link decorators. The commands above can be combined to display information such as the frontend component tree, state variables, and components affected by state variables.

@Entry
@Component
struct Page {
  @State message: string = 'hello world';

  build() {
    Column() {
      Text('Parent:' + this.message).fontSize(20).onClick(() => {
        this.message += '1';
      })
      Child({ message: this.message })
    }
  }
}

@Component
struct Child {
  @Link message: string;

  build() {
    Column() {
      Text('Child:' + this.message).fontSize(20)
      GrandChild({ message: this.message })
    }
  }
}

@Component
struct GrandChild {
  @Link message: string;

  build() {
    Column() {
      Text('GrandChild: ' + this.message).fontSize(20)
    }
  }
}

Step 1: Obtain the ID of the currently active window.

hdc shell hidumper -s WindowManagerService -a '-a'

Step 2: Execute the command to dump state variable information.

Assuming that the active window ID is 90, use the following commands:

[h2]State Management: Profiler

DevEco Studio's Profiler captures trace points for state variable changes. Select the ArkUI State lane in Profiler to track which state variables change during recording and which components they trigger to re-render. This helps analyze update loads based on the number of components associated with state variables.

The Profiler displays the following state management information.

Name Description
Start Time Time when the state variable is modified.
Attributes Attribute name of the state variable.
Owned by Component Custom component owning the state variable.
Owned by Class Class name owning the state variable.
Property Type Decorator name of the state variable.
Current Values Current value of the state variable.

Recording steps:

Step 1: Click the ArkUI template to create a session and start recording. During recording, modify the @State message variable to hello world1 to trigger re-rendering.

Step 2: After recording, the ArkUI State lane shows trace points for state variable changes.

Figure 1 ArkUI State lane recording process

Step 3: Select a trace point to view triggering of component re-rendering and the time consumed for creation, measurement, and layout.

Figure 2 ArkUI State lane details

Due to privacy and security policies, the ArkUI State lane is not available for applications that have been released on AppGallery.

[h2]State Management: ArkUI Inspector

DevEco Studio's ArkUI Inspector displays detailed state variable information within custom components, including the following.

Name Description
decorator Decorator of the state variable, for example, @State and @Link.
name Attribute name of the state variable, for example, message in @State message: string = 'hello world'.
value Current value of the state variable. Truncation is applied for overly long or deeply nested complex types.
mode

Observation mode of the state variable, including:

Compatible Mode: state management V1 state variables, where the decorated variable types have no properties decorated with @Track.

Track Mode: state management V1 variables, where the decorated types have properties decorated with @Track.

V2: state management V2 state variables.

elmtIds

Components associated with the state variable. In declarative UI syntax, UI re-rendering is triggered by state changes.

Currently, state management supports component-level updates, which means only components that use the state variable will be triggered to re-render when the variable changes.

syncPeers Synchronization objects of the state variable (limited to state management V1 variables). For example, the synchronization object of @State is @Link.

When you open ArkUI Inspector, it displays information related to state variables in the @Component Page custom component, as shown below.

Figure 3 ArkUI Inspector displaying state variable–related information

Due to privacy and security policies, ArkUI Inspector is not available for applications that have been released on AppGallery.

The above content mainly introduces the hidumper tool, Profiler, and ArkUI Inspector features for state management. These tools facilitate debugging and testing, helping improve the efficiency of developing high-performance applications.

Trace Debugging Capability

ArkUI internally embeds trace information for key UI processing flows. This allows you to observe the UI time consumption of applications using the trace tool and assist in issue localization. For details about the trace descriptions and use cases, see Trace Data Description.

Inspector Debugging Capability

ArkUI Inspector is a built-in page layout inspection tool in DevEco Studio for viewing UI hierarchies, component attributes, and layout effects. For details about how to use ArkUI Inspector, see Layout Analysis.