Yangjianwei is a senior engineer at huawei

HarmonyOS is dedicated to providing a 1+8+N smart, all-scenario solution that enables device flow and distributed experience, enabling multiple deployments at once, making distributed application development easier.

For debugging problems of distributed applications, DevEco Studio provides distributed debugging and tuning capabilities solutions to solve the pain points faced by developers such as discontinuous debugging, cumbersome operation, and difficulty in locating abnormal functions and performance. Here’s a sneak peek.

Note: Some of the capabilities of DevEco Studio for distributed debugging and tuning covered in this article rely on the OS interface and will not be available until HarmonyOS 3.0 Beta is released.

First, distributed debugging ability

DevEco Studio will provide distributed debugging capability solutions for developers. The Debug Agent Agent is responsible for converting the Debug commands in the Debug plug-in in DevEco Studio into requests for different debuggers by connecting the debuggers in different languages on each device. Including single-step debugging Step Into/Step Out/Step Over, Step across modules, recovery and other debugging functions, the Debugger plug-in is responsible for all the debugging information to meet the needs of the developer to display.

Figure 1 DevEco Studio's distributed debugging capabilitiesCopy the code

Below, we’ll take a look at DevEco Studio’s new distributed debugging capabilities.

1. Distributed cross-device cross-language debugging

DevEco Studio will allow developers to debug on multiple devices and seamlessly switch between multiple devices and languages. Click “Step Into” on the cross-device and cross-language interface to activate the debugging of the called device, interrupt the response of the calling interface, and continue debugging. At the same time, the IDE also shows the stack list of multi-device and multi-language debugging, to achieve unified management of breakpoints, unified view of variables, so that developers locate problems more efficient and convenient.

2. Automatic distributed fault capture

In the process of distributed application development, developers rely most on logs, and the number of logs is too large to miss key information. HiTrace’s new automatic exception catching and diagnostic capabilities automatically report application running exceptions to the Events view, including Java/C++/JS crash exceptions. You can locate the source code directly from the stack information in the exception event. In addition, you can view common service event information and associate logs associated with this event. These functions greatly reduce the time for collecting, viewing, and analyzing logs in distributed scenarios.

Figure 2. Automatic capture of abnormal faultsCopy the code

3. Visualization of cross-device state flow and distributed stack

Currently, developers usually locate trace code problems by looking at the debugged stack list, and the distributed application stack list is often fragmented and discontinuous, which makes it difficult for developers to track the distributed scheduled code. Therefore, DevEco Studio will introduce cross-device flow, distributed stack visualization.

(1) State flow across devices

The Device Transfer view presents the networking relationship and connection state between devices in a vivid and concise form. Devices are grouped in different networking classification forms. Devices within the group can display their specific information and dynamic flow relationship of atomized service. As shown in the figure, each ball represents a device, blue represents devices connected to the IDE, and yellow represents devices not connected to the IDE within the network. The arrows between them represent the invocation of atomized service capabilities between devices, helping developers quickly understand the flow and interaction between devices.

Figure 3 Device Transfer viewCopy the code

(2) Distributed stack visualization

Distributed Stack wilfulness visual function, the function between the invocation of the relationship with intuitive visual structure graphics, and keep the Call history, overcame the language Stack across different devices list the disadvantages of discontinuous segmentation, as shown in figure, the Call Stack view presents different equipment debugging module, said they use a different color, Clicking the function node in the diagram automatically locates the function in the code. Make it easier and faster for developers to trace their source code.

Figure 4 Call Stack viewCopy the code

4. Time debugging: support reverse debugging on JS

In the debugging process, if the developer misses checking the key variable value, or wants to debug the branch that the function has finished, it often needs to restart the debugging and locate a bug, which often needs debugging for many times to solve, time-consuming and laborious. How do I go back in time to execute the code I need to debug?

DevEco Studio will provide time-debugging capabilities to help you go back to key code locations and find code problems once. Time debugging allows you To move forward or Back inside a function, Step Back, Run Back To Breakpoint, Run Back To Active Line, Step Back Into the last line of the previous function and Step Back Out of the method call. All variable values, all debugging state are restored to the state you did not execute the subsequent code, to help you debug once can find the code problem.

FIG. 5 Reverse debugging is added on the basis of JS debuggingCopy the code

Second, distributed tuning ability

How to locate cross-device service performance bottlenecks in distributed collaborative scenarios? JS application performance analysis and memory analysis how to do? Is the data collected during performance collection reasonable? These performance tuning issues also plague many developers.

DevEco Studio will also add HarmonyOS’s overall distributed performance Profiler solution, which automatically deploys a Profiler agent on each device that interacts with modules such as the JS execution engine, Java execution engine, and C++ performance collector. Obtain performance data during code execution and generate various performance and memory analysis views for developers through clock synchronization. Next, we will discuss the new performance tracking for multi-device collaboration in DevEco Studio, the running performance of JS-BASED applications and the analysis of memory, as well as the automatic auxiliary analysis of performance data.

Figure 6 Distributed performance tuning capabilitiesCopy the code

1. Multi-device collaborative performance tracking

DevEco Studio will provide system tracking capabilities for collaboration across devices. Mainly include:

● Frame loss statistics

Statistics frame loss during debugging, display frame loss serial number and frame loss rate;

● Distributed delay

In the process of a distributed service running, the system call tracing across devices is completed at the same time. The delay across device call stack is provided. System calls on different devices are distinguished by different colors. The time consuming of each call process and the delay between calls are displayed separately. In addition, the Timeline and call stack view can be linked bidirectionally to improve debugging efficiency.

Figure 7 System tracking capabilityCopy the code

2. Analyze the running performance of JS applications

JS is the primary HarmonyOS application development language. Javascript performance analysis is usually done in Chrome development tools when we develop web pages. Now DevEco Studio has added support for JS application performance analysis. You can use Call Chart, Flame Chat, Top Down, and Bottomup to view the Call relationship between methods and the Call consumption time to identify time-consuming methods.

Figure 8. Call Chart and Flame Chat viewCopy the code

JS applies heap memory analysis

DevEco Studio will add support for analyzing THE memory of THE JS application heap when JavaScript memory cannot be recovered. By viewing the memory usage and trend of applications in real time, you can quickly discover possible problems such as memory jitter and memory leakage. By capturing, importing, and exporting the JS heap memory snapshot, you can further view the memory allocation, invocation, and reference of THE JS object. You can also compare and analyze multiple memory snapshots to observe the detailed memory changes of each object, helping you quickly locate objects that may cause memory bottlenecks or leaks.

Figure 9. Heap memory analysisCopy the code

4. Automatic analysis of performance data

During performance analysis, common performance analysis tools only provide basic statistics on performance data. For startup and UI experience issues, DevEco Studio automatically provides hints and suggestions for possible problems that can be further identified and optimized.

When you select an installed application package from the drop-down list, the IDE automatically starts the selected application and captures resource information such as CPU usage, I/O read/write amount, memory usage, and function call information of the process during application startup. After the capture, click the record icon to automatically analyze and obtain information. If too many resources are occupied or the function is called for a long time, detailed information will be displayed on the performance analysis report page, and optimization suggestions will be provided for some common problems to help developers quickly find performance shortcomings and improve application performance experience.

Figure 10 Automatic auxiliary analysis of performance dataCopy the code

DevEco Studio also provides developers with power analysis and power tuning capabilities for applications, including:

● The power consumption of the whole machine is decomposed

It provides the power consumption of the whole machine, and performs power decomposition for CPU, screen, GPU, Modem, WIFI, Audio, BT, GPS and other TOP power consumption devices, and records the status details of each component that affects the power consumption of the device. At the same time, it supports the display of information that affects the power consumption of the system dimension. It is convenient for developers to have an overall grasp of the power consumption of the whole machine and analyze the power consumption.

● Application decomposition

The power consumption of a single application is decomposed according to the dimension of the device. In the future, the application thread can be dismounted to facilitate the identification of application power problems and quickly lock the faulty thread. At the same time, the application CPU load rate is displayed in real time, so that developers can easily see the application CPU load.

With that in mind, the latest features in DevEco Studio will help you solve the problems of distributed tuning and debugging that used to drive developers crazy.