目录

Case: Analyzing the First Frame Completion Delay During Cold Start

The first frame completion delay of an app during cold start is the period from the time when a user touches the app icon on the home screen to the time when the first frame of the app process is drawn. This case describes how to find the start and end points of the first frame completion delay of an app during cold start, and how to analyze the app runtime logic based on the call stack and trace information to locate the cause of the unexpected first frame completion delay.

For details about the basic operations related to app cold start analysis, see Basic Operations with Launch Analysis.

Analysis Steps

To analyze the first frame completion delay during cold start, perform the following steps:

  1. Determine the start and end points of the first frame completion delay during cold start.
  2. Select the start and end points of the first frame completion delay during cold start, and check whether the delay exceeds the expected value.
  3. If the delay exceeds the expected value, troubleshoot based on the call stack and trace information.

Recording Launch Data

  1. Connect the device and click the app selection box to select the target app. Select the Launch template, and click Create Session or double-click the Launch icon to create a launch session.
  2. After the template is created, click to switch the launch mode to manual launch.
  3. On the toolbar, click and select HiTrace > multimodalinput to collect trace information of the multimodal subsystem. The information includes the finger-off signal transferred by the hardware, that is, the touch release event received by the multimodal subsystem.

  4. Click to start recording. After the dialog box is displayed, click the app icon on the device to launch the app.

  5. Once all the lanes on the right side show "recording," it indicates that the recording is in progress. After the cold start is complete, you can end the recording by clicking the square button shown in the figure or the pause button on the left.

Analyzing Launch Data

[h2]Determining the Start and End Points of the First Frame Completion Delay

Determining the start point of the first frame completion delay during cold start

The start point of the first frame completion delay is the moment when the user releases the touch on the app icon on the home screen, that is, the moment when the multimodal subsystem receives the finger-off signal from the hardware.

Since the trace point corresponding to the off-screen signal has a short duration and is difficult to remember, you should first locate the trace point (H:DispatchTouchEvent) at which the launcher process receives the touch-up event, to help identify the start point of the first-frame completion latency. The procedure is as follows:

  1. Locate the H:DispatchTouchEvent trace point where the launcher process receives the touch release event. Specifically, in the Profiler panel, select Search Unit Data from the search box options to search for lane data. Enter H:DispatchTouchEvent in the search box and press Enter. Navigate through results using the or button to find the H:DispatchTouchEvent point within the launcher process lane (ohos.sceneboard) where type is 1 (0: finger down; 1: finger up; 2: move). Add a marker to this point. Double-click the marker and edit its description to "Touch release event" in the property dialog for future reference. This trace point marks the moment the launcher process receives the touch release event.

  2. Search for the multimode subsystem lane (mmi_service). Specifically, click Search Units from the search box options. Enter mmi_service in the search box and press Enter. If multiple lanes match, navigate through results using the or button to identify the mmi_service lane containing the target trace segment.

  3. By using the previously marked touch release event trace point in the launcher process, locate the corresponding trace point in the multimodal subsystem.

    Specifically, within the mmi_service lane, identify the CPU Running slice positioned prior to the touch release marker (indicating subsystem activity during this period). Below this slice, find the trace point labeled H:service report touchId:{id}, type: up or H:service report pointerId:{id}, type: button-up. Add a marker to this trace point. Modify the marker's description to "Start point of first frame completion latency." This trace point marks the multimodal subsystem receiving the touch release event, that is, the start point of the first frame completion latency during cold start.

Determining the end point of the first frame completion delay during cold start

The end point of the first frame completion delay is the time when the first hardware vertical sync signal is received after the application process starts, that is, the end point when the Render Service (unified rendering service process) displays the rendering result of the application's first frame on the screen. To locate the end point of the first frame completion delay, perform the following steps:

  1. Identify the first vertical sync signal trace point H:ReceiveVsync after the application process starts. This trace point indicates the beginning of the first frame rendering for the application. Select the application process sub-lane, and select Search Unit Data from the search box options to search for lane data. Enter H:ReceiveVsync and press Enter to locate the first H:ReceiveVsync point.
  2. After the application process starts, upon receiving the first vertical sync signal, it notifies the Render Service process to perform graphics rendering. Therefore, the first step is to locate the following three traces related to this notification: H:FlushMessages > H:SendCommands > H:MarshRSTransactionData. Since these three traces have short durations and are difficult to visually identify, use the search function to locate them: (1) Select the H:ReceiveVsync trace point. (2) Select Search Unit Data from the search box options to search for lane data. (3) Enter FlushMessages and press Enter.

  3. After locating the trace point H:FlushMessages (indicating the flushing of drawing messages), continue analyzing the layers below this trace point. First, find H:SendCommands (indicating the transmission of drawing commands to the Render Service process for graphic rendering). Then, locate H:MarshRSTransactionData (indicating the transmission of drawing commands). These three trace points together represent the workflow of the application process notifying the Render Service process to perform graphic rendering.

  4. Locate the trace point where the Render Service process receives the first frame rendering notification from the application process. Specifically, click on the H:MarshRSTransactionData slice. In the Slice Detail panel, you can view details of this trace, including the trace name and the process it belongs to. Click the jump button next to Name in the Slice Detail panel to navigate to the H:RSMainThread::ProcessCommandUni trace point in the render_service lane. Add a marker to this point and modify its description to "Rendering callback received." This trace point indicates that the Render Service process has received the first frame rendering notification from the application process.

  5. Locate the trace point where the Render Service commits the app's first frame to hardware display, which is completed in the Render Service's hardware display thread (CompThread). Specifically, click Search Units from the search box options. Enter CompThread and press Enter. Locate the first H:CommitLayers trace point after the "rendering callback received" marker, and add a marker to it. Modify the marker description to "FrameBuffer submission to display hardware." This trace point indicates that the Render Service has committed the application's first frame to hardware display.

  6. Locate the trace point where the Render Service presents the app's first frame rendering result on the screen, which is completed in PresentFence. Specifically, click Search Units from the search box options. Enter PresentFence and press Enter. Locate the first H:Waiting for PresentFence trace point after the "FrameBuffer submission to display hardware" marker. This trace point indicates that the Render Service has presented the first frame to the screen. The end position of this trace point is the end point of the first frame completion delay. Add a marker here and modify its description to "End point of first frame completion latency."

[h2]Case: First Frame Completion Delay During Cold Start Exceeds the Expected Value Due to Prolonged App Home Page Loading

  • This case is based on the assumption that time-consuming operations are performed in the lifecycle callback function of the ability during application process startup.
  • The expected first frame completion delay during cold start is less than or equal to 600 ms.

Select the start and end points of the first frame completion delay during cold start of the application. The duration within the selected range reveals that the actual delay exceeds 800 ms, surpassing the expected 600 ms.

Switch to the Process lane and view the trace of the main thread (whose thread ID is the same as the process ID).

The Details area displays the trace name, start time, and duration. Sort the durations in descending order to identify that the main time consumption occurs in H:void OHOS::AbilityRuntime::UIAbilityThread::HandleAbilityTransaction. This phase primarily involves the execution of callback functions during the launch lifecycle of AbilityStage/Ability. From this, it can be inferred that the prolonged execution of AbilityStage/Ability launch lifecycle callbacks is the root cause. Next, analyze the call stack to determine why these callbacks take excessive time.

Switch to the ArkTS Callstack lane to analyze the time-consuming functions on the ArkTS side. First, check the ArkVM sub-lane whose thread ID matches the process ID (this sub-lane represents the main thread call stack) to view the execution time of ArkTS methods. As shown in the figure below, no ArkTS functions are executed, so you need to switch to the Callstack lane to view the mixed ArkTS-Native function call stack.

Finally, switch to the Callstack lane, check the main thread sub-lane (whose thread ID matches the process ID), and view the Heaviest Stack section below. Scroll to observe the function call stack with the highest weight percentage, and identify that the main time consumption is caused by the code on line 79 of the EntryAbility.ets file. Double-clicking this stack frame will directly navigate to the corresponding position in the source code file.

By examining the service code, it is found that time-consuming operations are performed in the onCreate() method in the EntryAbility.ets file. You are advised to handle time-consuming operations through asynchronous tasks with delayed processing or execute them on separate threads to reduce main thread load and shorten the first frame completion delay during cold start.