目录

Basic Time Analysis: Time

Function Description

During app/atomic service development, if performance issues such as janky frames and slow loading occur, check the execution time of functions. Time analysis tasks provided by DevEco Profiler can display call stacks based on CPU and process duration analysis within hotspot areas and supports redirection to the code line.

The Time template supports the following lanes: User Trace, ArkTS Callstack, Callstack, and Energy. This section describes the User Trace, ArkTS Callstack, and Callstack lanes. For details about the Energy lane, see Energy Consumption Diagnosis: Energy.

Function Execution Time Analysis and Optimization

After device connection is complete, perform the following steps to carry out time analysis:

  1. Build the app with symbol information. In the module-level build-profile.json5 file, add the strip field and set it to false. (This setting ensures that the symbol table and debugging information in the .so file of the module are preserved. Without the symbol table and debugging information, function names may be missing in the captured data, and the ArkTS Callstack lane may fail to be associated with the native call stack.)

  2. Create a time analysis task, and capture related data. For details, see In-depth Capture for Problem Locating. For the time analysis task, click to specify the lane to capture.

    • User Trace: custom trace lane, which displays the running status of trace tasks that you have customized using the hiTraceMeter interface in the current period based on the timeline.
    • ArkTS Callstack: lane for ARK Runtime function calls, which displays the CPU usage, VM execution status, current call stack name, and call type based on the timeline. Due to privacy and security policies, this lane is not available for apps that have been released on AppGallery.

      In terms of programming language, call stacks are classified into ArkTS, Node-API, and native. In terms of ownership, call stacks are classified into developer code and system code. DevEco Profiler provides the following call stack types:

      • ArkTS: The app is running the ArkTS code.
      • Node-API: The app is running the Node-API code.
      • Native: The app is running the native code.

        For each type, the bright color indicates that the code belongs to the developer, and the gray color indicates that the code belongs to the system.

    • Callstack: lane for ArkTS and native hybrid calls, which displays the CPU usage of each thread and the hybrid call stack in the current period based on the timeline. The native call stacks are further classified into developer native code and system ArkTS or native code. Due to privacy and security policies, this lane is not available for apps released on AppGallery with profileable set to false in the app.json5 file.

      The Callstack lane collects data based on the sampling mode. The default sampling interval is 500 microseconds. For functions with an execution time of less than 500 microseconds, the timing data in the Details area may exhibit measurement inaccuracies. To obtain more reliable data, trigger the function multiple times during profiling. If it consistently accounts for a significant portion of the total execution time (high time percentage), it can be identified as a hot spot function.

    • You can click next to a lane name to pin it on top.
    • To build .so libraries for the release version, the default optimization level is -O2. The compiler performs optimizations such as function inlining, register allocation, and instruction reordering, which may result in missing function call stacks, optimized-out local variables, and runtime execution order inconsistent with the source code, leading to incomplete captured data. You can set the optimization level to -O0 in CMakeLists.txt to capture complete data.

  3. On the ArkTS Callstack lane and its sub-lanes, hold down the left mouse button and drag to select a time range. The Details panel displays the execution time distribution of the function stack within the selected range. The Heaviest Stack area displays the complete call stack with the longest duration of the selected node on the Details panel. The function stack duration distribution can be displayed in three modes: call tree (default), flame chart, and ice cone chart.

    1. Call tree (default): This mode provides a hierarchical view of function calls with detailed metrics. Weight indicates the total execution time of the current function (including the time spent in subfunctions). Self indicates the execution time of the function itself (excluding the time spent in subfunctions). Average Duration indicates the average execution time of the function itself per call. Category indicates the type of the function call.
    2. Flame chart: This mode can be enabled via the Flame Chart switch at the bottom of the page, which displays the function call stack as a flame chart. The horizontal axis indicates function execution time, and the vertical axis indicates call stack depth.
      • The bar blocks of the flame chart support search. Bar blocks that do not match the search criteria are dimmed.
      • You can hold Ctrl and scroll the mouse wheel, or click or in the upper-right corner of the area to zoom the timeline of the flame chart. Clicking restores the timeline to the initial scale.
      • You can hold Shift and scroll the mouse wheel to adjust the visible area horizontally, and scroll the mouse wheel alone to adjust the visible area vertically.
      • You can select a node and click in the upper-right corner to add a breadcrumb. Once the breadcrumb is added, the selected node becomes the new root node with its time consumption ratio set to 100%, and the time consumption ratios of its child nodes are recalculated relative to this new root node.
      • You can hold Alt and left-click a node in the frame chart to move the node to the left bottom and zoom in to 100%. The subordinate nodes on the node are zoomed in accordingly.

    3. Ice cone chart: This mode displays the function call stack as an ice cone chart within the lane chart area and can be enabled via the Unfold CallStack button on the ArkTS Callstack or Callstack sub-lane. The order of call entries matches the actual execution chronological order.

  4. On the Callstack lane, hold down the left mouse button and drag the mouse to select a time range.

    • The Summary tab displays the maximum, minimum, and average CPU usage of all native threads within the selected time range.
    • The Callstack tab displays the function hotspots of all native threads within the selected time range.

    • Hover over a node to display the option to set it as the root node. Click this option to add a breadcrumb. Once the breadcrumb is added, the selected node becomes the new root node with its time consumption ratio set to 100%, and the time consumption ratios of its child nodes are recalculated relative to this new root node.

  5. On the Callstack sub-lane, hold down the left mouse button and drag the mouse to select a time period.

    • The Top Down tab displays the execution time distribution of the function stack in the selected time range. The Heaviest Stack area displays the complete call stack with the longest duration of the selected node on the Details panel.
    • The Bottom UP tab displays the function list. Expanding any function node allows you to view its callers and the execution time of each caller.

  6. (Optional) In the Details panel, double-click the target node (for example, a time-consuming node) to quickly jump to the corresponding source code. This frees you from locating the code by path.

    • Currently, DevEco Profiler does not support redirection to the native code on the user side for a release app.
    • Statically linked system libraries do not support source code redirection. For example, libunwind.a is integrated through static linking, which means that while its symbols may appear in the call stack as if they were defined by the user, navigating to the source code is not available.

Hotspot Analysis of Multi-Instance Functions

During app development, you may use the Worker thread or TaskPool to process time-consuming operations. Like the main thread, these threads may encounter performance problems and require profiling. The main thread, along with every Work thread or TaskPool worker thread, corresponds to an Ark instance. By connecting to these Ark instances, you can enable performance sampling and obtain more comprehensive sampling information.

Offline Symbol Parsing

DevEco Profiler offers offline symbol parsing, which parses the symbol addresses in a .so library into specific function names to make function locating easier.

For the sampled data with the .so library path and offset address, as shown in the figure below, import the so. library that carries symbols for parsing to supplement the missing symbols in the release .so library (including the system .so libraries, user-compiled .so libraries, and third-party libraries).

You can click on the toolbar to import a .so library that contains debugging information.

  • For offline import of .so libraries with symbol table information, their optimization levels (such as -O1, -O2, and -O3) must strictly match those of release-version .so libraries. You can view or configure the optimization level in the CMakeLists.txt file.
  • To prevent start address mismatches from affecting the resolution accuracy, ensure that the offline-imported .so library with symbol table information uses the same compilation options as the release-version .so library.

User Trace Query

The time analysis task based on sampling analysis is better than asynchronous scheduling in analyzing synchronization performance issues. To analyze issues such as asynchronous scheduling delays, you can add custom trace points in ArkTS code. When an app or atomic service triggers these trace points during time analysis, DevEco Profiler parses the trace data and presents it as task blocks in the User Trace lane.

You can also click options in the User Trace lane to open the drop-down list, and select Task Name or Thread ID to set the sub-lane display dimension.