Data collection method and electronic device

By detecting the processing time of software program tasks in electronic devices in real time and collecting log data, the problem of non-responsiveness of software programs in the existing technology is solved, the problem of non-response is accurately located and solved, and the performance of the software is improved. and user experience.

CN118245331BActive Publication Date: 2024-10-25HONOR DEVICE CO LTD
View PDF 4 Cites 0 Cited by

Patent Information

Application Number
CN202410660635.8
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-05-27
Publication Date
2024-10-25
Estimated Expiration
2044-05-27

AI Technical Summary

Technical Problem

It is difficult for the existing technology to effectively deal with unresponsiveness problems that occur during the operation of software programs, and it is difficult to accurately locate and solve these problems through public log collection methods.

Method used

A data collection method is adopted to detect the processing time of the task by the software program in real time, and collect relevant log data when the preset timeout condition is reached, so as to more accurately locate the root cause of the response timeout problem. The method includes setting a first detection duration and a second detection duration in an electronic device, detecting the processing duration in real time, and starting log collection when the second detection duration is reached.

Benefits of technology

It achieves accurate collection and analysis of unresponsive software program problems, helps R&D personnel solve these problems in a timely and effective manner, and improves software performance and user experience.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118245331B_ABST
    Figure CN118245331B_ABST
Patent Text Reader

Abstract

The embodiment of the present application discloses a data collection method and an electronic device, which are applicable to the field of computer technology, wherein the data collection method includes: the electronic device detects in real time the processing time of the first software program for the first task, and determines the first detection time corresponding to the first task based on the second detection time, wherein the second detection time is the timeout response time corresponding to the first task, and the first detection time is less than the second detection time; when the processing time meets the preset conditions, the data is collected from the first moment until the second moment, and a first type of log is obtained, and the first type of log is the log of the first software program from the first moment to the second moment. The embodiment of the present application can accurately collect log data when a problem occurs in the software program, which is helpful to realize accurate and effective processing of the unresponsiveness problem that occurs during the operation of the software program.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of computer technology, and in particular to a data acquisition method and electronic equipment. Background Art

[0002] With the development of computer technology, electronic devices are being updated and replaced at an increasingly rapid pace, and users' performance requirements for software programs running in electronic devices are also increasing. Performance indicators such as system fluency, low memory consumption, low lag, and fast startup of software programs have become an important part of high-quality products.

[0003] In the related art, software programs may not respond when they are running, such as Application Not Responding (ANR) and system service unresponsiveness. Software program unresponsiveness means that the software program does not respond normally within the specified time. Software program unresponsiveness may cause the program or interface to freeze, stop working, or fail to complete the expected task.

[0004] In order to ensure the performance requirements of the software program, it is necessary to collect logs and analyze the logs to effectively deal with problems that occur during the operation of the software program. However, the logs collected by the method disclosed in the relevant technology are difficult to effectively deal with the unresponsiveness problem that occurs during the operation of the software program. Summary of the invention

[0005] In view of this, the embodiments of the present application provide a data collection method and an electronic device, which can accurately collect valid log data when problems occur in software programs, thereby helping to accurately and effectively handle unresponsiveness problems that occur during the operation of software programs.

[0006] In a first aspect, an embodiment of the present application provides a data collection method, the method comprising: the electronic device can determine the first detection duration corresponding to the first task based on the second detection duration. The electronic device can also detect in real time the processing duration of the first task by the first software program. Then, when it is detected that the processing duration of the first task by the first software program meets a preset condition, the electronic device can collect a first type of log of the first software program from the first moment to the second moment.

[0007] The first detection duration is shorter than the second detection duration, and the second detection duration is the timeout response duration corresponding to the first task. The second detection duration is a preset duration value.

[0008] In practice, for different first tasks, the electronic device can pre-set the corresponding timeout response duration, or the second detection duration. When the processing duration of the first software program for the first task reaches the second detection duration, it means that the first software program has timed out in responding to the first task. On the contrary, if the first software program completes processing of the first task before the second detection duration, that is, the processing duration of the first software program for the first task is shorter than the second detection duration, it means that the first software program has not timed out in responding to the first task.

[0009] In practice, the timeout response duration corresponding to the first task is usually related to the specific unresponsive scenario. For example, for the scenario in which the system service process detected by the watchdog is unresponsive, the timeout response duration may be 60 seconds, for the ANR scenario of the input event, the timeout response duration may be 5 seconds, for the ANR scenario of service startup, the timeout response duration may be 30 seconds, and for the ANR scenario of broadcast transmission and reception, the timeout response duration may be 10 seconds. It can be understood that the embodiments of the present application do not specifically limit the specific values ​​of the timeout response duration in various scenarios.

[0010] The first moment is the moment when the processing time of the first task by the first software program reaches the first detection time. The second moment is the moment when the processing time of the first task by the first software program reaches the second detection time.

[0011] Since the electronic device detects the processing time of the first task by the first software program in real time, the processing time obtained by the electronic device can be continuously growing. The embodiment of the present application will start log collection when it is detected that the processing time meets the preset conditions. In other words, the above preset conditions are introduced to start log collection. The embodiment of the present application does not limit the specific form of the preset conditions. Optionally, the processing time meets the preset conditions, including: the processing time is equal to the above-mentioned first detection time; or, the end time of the processing time is the first time.

[0012] The first software program is usually a software program that may time out in response to the task being processed. The first software program may be a system service process of the application framework layer of the electronic device, or may be an application program of the application layer of the electronic device. The application program may be various applications on the electronic device, such as WeChat.

[0013] The first task is usually the task currently processed by the first software program. As an example, the first task may be a task of broadcasting a certain message, a task of starting a certain service component, etc.

[0014] In an embodiment of the present application, the electronic device can collect the first type of log of the software program within a period of time before the software program has a response timeout problem. Since the first type of log within a period of time can reflect the continuous operation changes of the software program within the period of time, the cause of the response timeout problem (or the root cause of the problem) can be more effectively located by analyzing the first type of log within a period of time. That is, the data collection method of the present application can accurately collect valid log data when a problem occurs in the software program, which helps to more accurately locate the root cause of the software program's unresponsiveness problem, thereby assisting R&D personnel to promptly and effectively solve the unresponsiveness problem of the software program.

[0015] It can be understood that the operation of the electronic device detecting the processing time of the first software program on the first task and the operation of the electronic device determining the first detection time of the first task can be performed simultaneously or one after another. The embodiment of the present application does not specifically limit the execution order of these two operations.

[0016] As an embodiment of the present application, the electronic device may determine a detection subject for detecting the first software program in combination with the first software program and the first task processed by the first software program.

[0017] In the embodiment of the present application, the electronic device can detect the processing of the first task by the first software program through the above detection subject, and start collecting the first type of log of the first software program when the first software program is about to time out in response. This helps to obtain accurate and effective log data for handling the response timeout problem.

[0018] As an embodiment of the present application, when the first software program is a system service process, the detection subject is a watchdog service running in the system service process.

[0019] As an embodiment of the present application, when the first software program is an application program and the first task is an input event, the detection subject is an input distribution module in an input system of an application program framework layer.

[0020] As an embodiment of the present application, when the first software program is an application program and the first task is to start a service component, the detection subject is an active service management module in an activity manager of an application program framework layer.

[0021] As an embodiment of the present application, when the first software program is an application program and the first task is a broadcast message, the detection subject is a broadcast message management module in an activity manager of an application program framework layer.

[0022] In a first possible implementation manner of the first aspect, the electronic device may also analyze the first problem based on the first type of log, where the first problem is a problem of a timeout in response of the first software program to the first task.

[0023] In an embodiment of the present application, the electronic device can accurately and effectively handle unresponsiveness problems that occur during the operation of the software program based on valid log data when problems occur in the software program.

[0024] In a second possible implementation of the first aspect, when the first software program is a system service process, the electronic device can detect whether the processing time of the first task by the first software program meets a preset condition through a watchdog service, wherein the watchdog service runs in the system service process.

[0025] Specifically, the detection process of the watchdog service may include the following steps:

[0026] First, the watchdog service traverses the task processing status of each first thread to be detected in the system service process. Among them, the first thread is a thread running in the system service process, and the first thread is the thread to be detected. As an example, the first thread may include a main thread, an input and output thread, a user interaction thread, etc. It can be understood that the embodiment of the present application does not specifically limit which threads are to be detected.

[0027] Then, when the watchdog service detects that the task processing state is the first thread of the first state, it determines that the processing time of the first software program on the first task meets the preset condition. The task processing state includes the first state, and the first state indicates the collection of the first type of log. The task processing state can indicate the stage of processing the task.

[0028] In an embodiment of the present application, a plurality of first threads are usually running in the system service process, and the plurality of first threads can work together to complete a task. At different times, the task processing status of each first thread may be different. The watchdog service determines whether there is a response timeout in the system service process by continuously traversing the task processing status of each first thread, and can promptly discover the response timeout of the system service process, thereby promptly handling the timeout response problem of the system service process. In addition, by collecting the first type of log of the system service process within a period of time before the timeout response problem occurs in the system service process, it is possible to accurately collect valid log data when a problem occurs in the software program, which helps to more accurately locate the root cause of the problem of the software program's unresponsiveness.

[0029] In a third possible implementation manner of the first aspect, the electronic device may update the task processing status of each first thread in the system service process. Specifically, the updating process may include:

[0030] When the electronic device detects that the first thread starts to execute the first task, the electronic device determines the task processing state of the first thread to be a third state;

[0031] When the electronic device detects that the execution time of the first thread for the first task reaches half of the timeout response time (that is, the second detection time), the task processing state of the first thread is updated to the fourth state;

[0032] When the electronic device detects that the execution time of the first thread for the first task reaches a first detection time, the electronic device updates the task processing state of the first thread to a first state;

[0033] When the electronic device detects that the execution time of the first thread for the first task reaches the timeout response time (that is, the second detection time), the task processing state of the first thread is updated to the fifth state;

[0034] When the electronic device detects that the first thread completes processing of the first task, the electronic device updates the task processing state of the first thread to the second state.

[0035] In the embodiment of the present application, the electronic device can timely update the task processing status of the first thread in combination with the processing status of the first task by each first thread in the system service process. In this way, the watchdog service can quickly and accurately determine whether the system service process has a response timeout by traversing the task processing status of each first thread.

[0036] As an embodiment of the present application, the task processing state may include a first state, and may also include at least one of the following states: a second state, a third state, a fourth state, and a fifth state.

[0037] Among them, the second state indicates that the task is executed successfully, the third state indicates that the task is executed normally, the fourth state indicates that the processing time of the task reaches half of the timeout response time, and the fifth state indicates that the response has timed out.

[0038] In a fourth possible implementation of the first aspect, when the first software program is a first application and the first task is to respond to a first input event for the first application, the electronic device detects, through an input distribution module, whether the processing time of the first task by the first software program meets a preset condition. The input distribution module is included in an input system of an application framework layer of the electronic device.

[0039] The first application may be any application on the electronic device. It will be appreciated that the embodiment of the present application does not specifically limit the first application.

[0040] Specifically, the detection process of the input distribution module may include:

[0041] First, upon receiving instruction information instructing to distribute the first input event, the input distribution module may distribute the first input event to the first application corresponding to the first input event.

[0042] Then, the input distribution module can determine a first duration without receiving first feedback information returned by the first application in response to the first input event, where the first duration is used to characterize the time interval between the issuance of the first input event and the current time, wherein the first feedback information indicates that the first application has completed responding to the input event.

[0043] Finally, the input distribution module may determine that the processing duration satisfies a preset condition when the first duration is equal to the first detection duration.

[0044] In an embodiment of the present application, the electronic device can detect the above-mentioned first input event through the input system of the application framework layer, and when the above-mentioned first input event is detected, the input distribution module in the input system can receive instruction information indicating the distribution of the first input event. In this way, the input distribution module can distribute the first input event. When the input distribution module distributes the first input event to the first application, it can detect the first duration in real time, and the input distribution module can determine that the processing duration of the first task by the first software program meets the preset condition when the first duration reaches the first detection duration. When the processing duration of the first software program for the first task reaches the first detection duration, it can trigger the collection of the first type of log of the first software program.

[0045] In a fifth possible implementation of the first aspect, when the first software program is a second application and the first task is to start a first service component called by the second application, the electronic device detects through an active service management module whether the processing time of the first task by the first software program meets a preset condition. The active service management module is included in an activity manager of an application framework layer of the electronic device. The second application can be any application on the electronic device. It can be understood that the embodiment of the present application does not specifically limit the second application.

[0046] Specifically, the detection process of the active service management module may include:

[0047] First, upon receiving instruction information instructing to start a first service component, the active service management module may start the first service component, wherein the first service component is a service component to be started.

[0048] Then, the active service management module can write a first timed message to the target message queue, wherein the first timed message includes the first message content and the first detection duration. When the timing of the first timed message reaches the first detection duration, the target message queue can send a second feedback message to the active service management module. The second feedback message indicates that the first detection duration has been reached. The target message queue is a message queue of the Handler mechanism.

[0049] Finally, the active service management module may determine that the processing time of the first task by the first software program meets a preset condition upon receiving the second feedback information returned by the target message queue.

[0050] In an embodiment of the present application, the electronic device can detect the request information for requesting to start the first service component through the activity manager of the application framework layer, and when the above request information is detected, the active service management module in the activity manager can receive the instruction information for instructing to start the first service component. In this way, the active service management module can start the first service component. After the active service management module triggers the start of the first service component, in the process of starting the first service component, the active service management module determines the time taken to start the first service component by sending a timed message to the target message queue. Specifically, if the maintenance time of the timed message in the target message queue reaches the time set in the timed message, such as the first detection time, the target message queue will be triggered to send feedback information to the source of the timed message, and the feedback information can indicate that the timed message has reached the set time. It should be pointed out that the timing is realized through the target message queue, which can share the data processing capacity of the active service management module and help improve the overall data processing performance of the electronic device.

[0051] In a sixth possible implementation manner of the first aspect, writing the first scheduled message to the target message queue may include: simultaneously writing the first scheduled message and the second scheduled message to the target message queue.

[0052] Among them, the second timed message includes the second message content and the second detection duration. When the timing of the second timed message reaches the second detection duration, the target message queue sends a third feedback information to the active service management module, and the third feedback information indicates that the startup timeout of the first service component has occurred.

[0053] In an embodiment of the present application, during the process of starting the first service component, the active service management module can write two timed messages to the target message queue, namely a first timed message and a second timed message. The first timed message is used to determine whether the time taken to start the first service component exceeds the first detection duration, and the second timed message is used to determine whether the time taken to start the first service component exceeds the second detection duration.

[0054] Optionally, the active service management module may collect a first type of log from the first moment to the second moment when the time taken to start the first service component reaches the first detection duration. The active service management module may also collect a second type of log at the second moment when the time taken to start the first service component reaches the second detection duration. In this way, accurate and effective log data can be further collected when the response timeout problem occurs in the first software program.

[0055] In a seventh possible implementation manner of the first aspect, the detection process of the active service management module may further include the following steps: when the second feedback information is not received and it is detected that the first service component is successfully started, removing the first scheduled message and the second scheduled message in the target message queue.

[0056] In an embodiment of the present application, the active service management module can remove the scheduled messages in the target message queue in a timely manner when the first service component is started in a timely manner. In this way, the target message queue can stop timing the first scheduled message and / or the second scheduled message in a timely manner, which helps to save unnecessary computing resource loss.

[0057] In an eighth possible implementation of the first aspect, when the first software program is a third application and the first task is to broadcast a first broadcast message of the third application, the electronic device detects through a broadcast message management module whether the processing time of the first task by the first software program meets a preset condition, wherein the broadcast message management module is included in an activity manager of an application framework layer of the electronic device. The third application can be any application on the electronic device. It can be understood that the embodiment of the present application does not specifically limit the third application. The first application, the second application, and the third application listed in the present application may be the same application or may not be the same application.

[0058] Specifically, the detection process of the broadcast message management module may include the following steps:

[0059] First, upon receiving instruction information instructing to send the first broadcast message, the broadcast message management module may send the first broadcast message to broadcast receivers of the first broadcast message.

[0060] Then, the broadcast message management module can write a third timed message to the target message queue, wherein the third timed message includes the third message content and the first detection duration. When the timing of the third timed message reaches the first detection duration, the target message queue sends a fourth feedback message to the broadcast message management module, wherein the fourth feedback message indicates that the first detection duration has been reached.

[0061] Finally, upon receiving the fourth feedback information sent by the target message queue, the broadcast message management module may determine that the processing time of the first task by the first software program meets a preset condition.

[0062] In an embodiment of the present application, the electronic device can detect the request information for requesting to broadcast the first broadcast message through the activity manager of the application framework layer, and when the above request information is detected, the broadcast message management module in the activity manager can receive the instruction information for instructing to broadcast the above first broadcast message. In this way, the broadcast message management module can send the first broadcast message to the broadcast receiver. It can be understood that there can be one or more broadcast receivers. The electronic device can determine the broadcast receiver by using the method of determining the broadcast receiver in the related art, and this application does not make specific limitations.

[0063] After the broadcast message management module sends the first broadcast message to the broadcast receiver, the broadcast message management module determines the time taken to broadcast the first broadcast message by sending a timed message to the target message queue. Specifically, if the duration of the timed message in the target message queue reaches the duration set in the timed message, such as the first detection duration, the target message queue will be triggered to send feedback information to the source of the timed message (such as the broadcast message management module), and the feedback information can indicate that the timed message has reached the set duration. It should be pointed out that realizing timing through the target message queue can share the data processing capacity of the broadcast message management module, which helps to improve the overall data processing performance of the electronic device.

[0064] In a ninth possible implementation manner of the first aspect, writing the third scheduled message to the target message queue may include: writing the third scheduled message and the fourth scheduled message to the target message queue.

[0065] Among them, the fourth scheduled message includes the fourth message content and the second detection duration. When the timing of the fourth scheduled message reaches the second detection duration, the target message queue sends fifth feedback information to the broadcast message management module, and the fifth feedback information indicates that the broadcast of the first broadcast message has timed out.

[0066] In an embodiment of the present application, during the process of broadcasting the first broadcast message, the broadcast message management module can write two timed messages into the target message queue, namely the third timed message and the fourth timed message, the third timed message is used to determine whether the time taken to broadcast the first broadcast message exceeds the first detection duration, and the fourth timed message is used to determine whether the time taken to broadcast the first broadcast message exceeds the second detection duration.

[0067] Optionally, the broadcast message management module may collect a first type of log from the first moment to the second moment when the time taken to broadcast the first broadcast message reaches the first detection duration. The broadcast message management module may also collect a second type of log at the second moment when the time taken to broadcast the first broadcast message reaches the second detection duration. In this way, accurate and effective log data can be further collected when the response timeout problem occurs in the first software program.

[0068] In a tenth possible implementation manner of the first aspect, the detection process of the broadcast message management module further includes:

[0069] When the fourth feedback information is not received and the sixth feedback information sent by the broadcast receiver is received, the third scheduled message and the fourth scheduled message in the target message queue are removed, and the sixth feedback information indicates that the broadcast receiver successfully receives the first broadcast message.

[0070] In an embodiment of the present application, the broadcast message management module can remove the scheduled messages in the target message queue in a timely manner when the first broadcast message is broadcast in a timely manner. In this way, the target message queue can stop timing the third scheduled message and / or the fourth scheduled message in a timely manner, which helps to save unnecessary computing resource loss.

[0071] In an eleventh possible implementation manner of the first aspect, the first detection duration is positively correlated with the second detection duration.

[0072] Optionally, the first detection duration is the product of the second detection duration and the first coefficient. The first coefficient is a pre-set coefficient. The value range of the first coefficient is usually 0.5-1.

[0073] Optionally, the value of the first coefficient is 0.8.

[0074] It should be noted that, as the value of the first coefficient is smaller, the amount of data of the first type of log collected is larger, that is, the storage space used to store the first type of log is larger. And the larger the value of the first coefficient is, the shorter the duration of the first type of log collected is, that is, the amount of first type of log data available for analysis is smaller.

[0075] When the first coefficient is 0.8, it is possible to ensure that the storage space is better saved while accurately and effectively analyzing the software program response timeout problem based on the first type of log.

[0076] It should be pointed out that when the first coefficient is 0.8, the first detection time is close to the second detection time. When the first detection time has been reached, but the software program has not completed the task, there is a high possibility of a response timeout. That is, starting to collect the first type of log when the first detection time has been reached can achieve targeted log data collection, and is less likely to cause storage resource consumption due to blind collection.

[0077] In a twelfth possible implementation manner of the first aspect, the electronic device may collect a second type of log of the first software program when detecting that a processing time duration of the first task by the first software program reaches a second detection time duration.

[0078] The first type of log is different from the second type of log. The second type of log is running snapshot data of the first software program, and the first type of log is running process data of the first software program.

[0079] In a thirteenth possible implementation manner of the first aspect, the first type of log is a SimplePerf log, and the second type of log is a Trace log.

[0080] In the embodiment of the present application, different types of logs have different functions. Collecting the first type of log and the second type of log at the same time can more accurately collect valid log data when problems occur in the software program, which helps to further accurately and effectively handle unresponsiveness problems that occur during the operation of the software program.

[0081] In a fourteenth possible implementation manner of the first aspect, the application framework layer of the electronic device includes a first management module and a first service, the first service is used to collect a first type of log, and the first management module is used to manage the first service.

[0082] The electronic device collecting a first type of log of the first software program from the first moment to the second moment may include:

[0083] First, the target module in the electronic device sends a first indication message to the first management module, and the first indication message indicates to collect the first type of log from the first moment to the second moment, wherein the target module can be any one of the watchdog service, the input distribution module, the active service management module, and the broadcast message management module. The target module can also be called the detection subject of the timeout response problem.

[0084] Then, the first management module in the electronic device sends second indication information to the first service, where the second indication information indicates to collect the first type of log from the first moment to the second moment;

[0085] Finally, the first service in the electronic device collects the first type of log based on the second indication information.

[0086] In an embodiment of the present application, in response to response timeout problems in different situations, the electronic device can send instruction information for collecting first type logs to the first management module through the detection subject corresponding to the response timeout problem, so that the first management module can start the first service, and the first service collects the first type log of the first software program.

[0087] In practice, when the first type of log is a SimplePerf log, the first service is a SimplePerf service, and the first management module is a SimplePerf service management module that manages the SimplePerf service.

[0088] In the embodiment of the present application, when the conditions for collecting the first type of log are met, the target module in the electronic device can start the first service to collect the first type of log through the first management module. It should be pointed out that the first service is started only when it is determined that the first type of log needs to be collected, which can save unnecessary loss of operating resources and help further improve the data processing performance of the electronic device.

[0089] In some optional implementations of the embodiments of the present application, the first management module usually sends a message to the first service instructing to collect the first type of logs when the first type of logs collected by the electronic device does not exceed the quota. This can prevent the first type of logs from occupying too much storage resources in the electronic device, which helps to ensure the overall performance of the electronic device.

[0090] The above quota is used to indicate the upper limit of the amount of the first type of logs collected every day.

[0091] In practice, the above quota usually refers to the number of times the first type of logs are collected. In some application scenarios, the above quota may also refer to the data volume of the first type of logs.

[0092] In a second aspect, an embodiment of the present application provides an electronic device, the electronic device comprising a memory and a processor, the memory storing a computer program executable on the processor, and the processor implementing any method of the first aspect when executing the computer program.

[0093] In a third aspect, an embodiment of the present application provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, it implements any method as described in the first aspect above.

[0094] In a fourth aspect, an embodiment of the present application provides a chip system, the chip system includes a processor, the processor is coupled to a memory, and the processor executes a computer program stored in the memory to implement any method of the first aspect. The chip system can be a single chip, or a chip module composed of multiple chips.

[0095] In a fifth aspect, an embodiment of the present application provides a computer program product. When the computer program product is run on an electronic device, the electronic device executes any one of the methods of the first aspect above.

[0096] It can be understood that the beneficial effects of the second to fifth aspects mentioned above can be found in the relevant description of the first aspect mentioned above, and will not be repeated here. BRIEF DESCRIPTION OF THE DRAWINGS

[0097] Figure 1 A schematic diagram of an interface showing an ANR problem in an application program in a mobile phone provided in an embodiment of the present application;

[0098] Figure 2 A schematic diagram of a software system of an electronic device according to an embodiment of the present application;

[0099] Figure 3A A schematic diagram of a data collection interaction process for input events provided in an embodiment of the present application;

[0100] Figure 3B A schematic diagram of another data collection interaction process for input events provided in an embodiment of the present application;

[0101] Figure 3C A schematic diagram of a data collection process for input events provided in an embodiment of the present application;

[0102] Figure 4A A schematic diagram of a data collection interaction process for service startup provided in an embodiment of the present application;

[0103] Figure 4B A schematic diagram of another data collection interaction process for service startup provided in an embodiment of the present application;

[0104] Figure 4C A schematic diagram of a data collection process for service startup provided in an embodiment of the present application;

[0105] Figure 5A A schematic diagram of a data collection interaction process for broadcast transmission and reception provided in an embodiment of the present application;

[0106] Figure 5B A schematic diagram of another data collection interaction process for broadcast transmission and reception provided in an embodiment of the present application;

[0107] Figure 5C A schematic diagram of a data collection process for broadcast transmission and reception provided in an embodiment of the present application;

[0108] Fig. 6A A schematic diagram of a data collection interaction process for system unresponsiveness provided in an embodiment of the present application;

[0109] Figure 6B A schematic diagram of another data collection interaction process for system unresponsiveness provided in an embodiment of the present application;

[0110] Figure 6C A schematic diagram of a data collection process for system unresponsiveness provided in an embodiment of the present application;

[0111] Figure 7 A schematic diagram of the structure of a data acquisition device provided in an embodiment of the present application;

[0112] Figure 8 A schematic diagram of the hardware structure of an electronic device provided in an embodiment of the present application. DETAILED DESCRIPTION

[0113] In the following description, specific details such as specific system structures, technologies, etc. are provided for the purpose of illustration rather than limitation, so as to provide a thorough understanding of the embodiments of the present application. However, it should be clear to those skilled in the art that the present application may also be implemented in other embodiments without these specific details. In other cases, detailed descriptions of well-known systems, devices, circuits, and methods are omitted to prevent unnecessary details from obstructing the description of the present application.

[0114] The following are some concepts that may be involved in the embodiments of the present application:

[0115] (1) Multiple: Unless otherwise specified, in the embodiments of the present application, multiple refers to two or more.

[0116] (2) Trace log: In the embodiment of the present application, the trace log is used to record instantaneous information during program execution, such as the instantaneous information of the stack called by the system service process, the instantaneous load information of the CPU, etc.

[0117] In actual Android development, you can use performance analysis tools, such as SysTrace, to record and analyze Trace logs. SysTrace is a powerful performance analysis tool that can display the performance data of applications (APPs) at different levels, including CPU usage, memory usage, thread processing, etc., which is very helpful for performance optimization.

[0118] (3) SimplePerf: In the embodiments of the present application, SimplePerf is a performance analysis tool for the Android platform, which is designed to help developers and engineers conduct in-depth analysis and optimization of application performance. Through the SimplePerf tool, users can collect and analyze application performance data, identify bottlenecks and optimization space, and thus improve the response speed, power efficiency, and overall performance of the application.

[0119] In practice, the SimplePerf tool may include a SimplePerf service management module and a SimplePerf service. The SimplePerf service management module may be implemented as a process of the application framework layer, and the SimplePerf service may be implemented as another process of the application framework layer.

[0120] The SimplePerf service management module is mainly responsible for managing the life cycle of the SimplePerf service and configuring the working parameters of the SimplePerf service, such as sampling frequency, monitored event type, output format, etc.

[0121] When it is necessary to collect SimplePerf logs, a detection entity in the electronic device for detecting timeout responses, such as a watchdog service, can send instruction information for collecting SimplePerf logs to the SimplePerf service management module, so that the SimplePerf service management module can start the SimplePerf service, and the SimplePerf service will collect SimplePerf logs.

[0122] The SimplePerf log is used to record the trace of method calls in a process or thread, that is, the SimplePerf log can record the running process data of the program. In some scenarios, the SimplePerf log can also be referred to as the Perf log.

[0123] (4) Input Dispatcher: In the embodiment of the present application, the Input Dispatcher module is an important component in the Android system, responsible for processing user input events and distributing them to corresponding applications or system components. It plays a key role in the Android system to ensure that the user's input operations such as touch and keystrokes can be correctly received and responded to by the application.

[0124] (5) System Service Process (SystemServer): In the embodiment of the present application, the system service process is an important process in the Android system, and it is the core service process of the entire system. The system service process is responsible for starting and managing various system services in the system, including the window manager (WindowManagerServer, WMS), the activity manager (ActivityManagerService, AMS), the application manager (PackageManagerServer, PMS), etc. These system services provide the core functions of the Android system, such as application management, interface display, notification management, etc. In other words, the stable operation of the system service process is crucial to the normal operation of the entire system.

[0125] (6) Watchdog service: In the embodiments of the present application, the watchdog service is a tool in the Android system for detecting the running status of the system service process. The watchdog service (or watchdog) runs in the system service process. The setting of the watchdog service is mainly to ensure the stability and reliability of the system service. When the watchdog service is running, it can continuously monitor the running status of the system service process and perform corresponding processing when the system service process is abnormal or deadlocked, such as restarting the system service process to prevent the system service process from being unavailable for a long time.

[0126] (7) Application Not Responding (ANR): In the present embodiment of the application, the Android system needs to complete some events within a certain time range. If no effective response is obtained after the predetermined time or the response time is too long, ANR will occur.

[0127] For example, when a user is using an application on an electronic device, if the application is not responsive enough for a period of time, or is stuck, the electronic device can determine that an ANR has occurred in the application. When an ANR occurs in an application on an electronic device, the electronic device can display an ANR prompt window. The user can choose to wait for the application to respond through the ANR prompt window, or the user can choose to close the application through the ANR prompt window.

[0128] ANR is further explained by taking a mobile phone as an example. Figure 1When the mobile phone detects that the application "MyApplication" has an ANR, the mobile phone can display an ANR prompt window 101. Among them, the ANR prompt window 101 includes a "close application" control 102 and a "wait" control 103. The mobile phone can respond to the user's operation of clicking the "wait" control 103 and wait for the application to respond. The mobile phone can also respond to the user's operation of clicking the "close application" control 102 and close the application. Among them, Figure 1 This is a schematic diagram of the interface of an ANR problem occurring in an application in a mobile phone provided in an embodiment of the present application.

[0129] In practice, all ANR-related messages are dispatched by the system service and then sent to the application to complete the actual processing of the message. Once the application processes the message for a timeout, the ANR problem may be triggered.

[0130] (8) Software program unresponsiveness: In the present embodiment, software program unresponsiveness may refer to the unresponsiveness of the system service process, referred to as system unresponsiveness, or the unresponsiveness of the application program, also known as ANR. In the present embodiment, unresponsiveness may also be referred to as response timeout.

[0131] (9) ANR scenario: In the embodiments of the present application, the ANR scenario refers to a scenario where ANR may occur. The ANR scenario may include the following ANR scenario 1-ANR scenario 4.

[0132] Among them, ANR scenario 1: input event (Input) triggers ANR. In ANR scenario 1, if the application does not respond to input events in time, such as key events and touch events, ANR can be triggered.

[0133] ANR scenario 2: Service plug-in startup triggers ANR. In ANR scenario 2, when the service component (or service) that needs to be started does not complete the startup in time, ANR can be triggered.

[0134] ANR scenario 3: Broadcast system (BroadcastReceiver) triggers ANR. In ANR scenario 1, ANR can be triggered when the application fails to complete the sending and receiving of broadcast messages in time.

[0135] ANR scenario 4: Content Provider startup triggers ANR. In ANR scenario 4, when the application requests to start the content provider, if the application provider is not started in time, ANR can be triggered.

[0136] It can be understood that the above four scenarios listed in the embodiments of the present application where the ANR problem may occur are only examples. In actual applications, there may be other scenarios where the ANR problem may occur, and the embodiments of the present application do not make specific limitations.

[0137] With the development of computer technology, electronic devices are being updated and replaced at an increasingly rapid pace, and users' performance requirements for software programs running in electronic devices are also increasing. Performance indicators such as system fluency, low memory consumption, low lag, and fast startup of software programs have become an important part of high-quality products.

[0138] In the related art, software programs, such as system service processes, applications, etc., may have unresponsiveness problems (or response timeout problems) during operation, such as system unresponsiveness and application unresponsiveness. Therefore, in order to ensure the performance requirements of software programs, the related art needs to effectively analyze and solve the unresponsiveness problems that occur during the operation of software programs. Among them, system unresponsiveness refers to the watchdog timeout in the system service process.

[0139] In the related art, when a software program becomes unresponsive, the electronic device usually uses a system tracking tool to collect snapshot information at the time when the software program has a problem, or called a Trace log, and then locates the root cause of the problem through the collected Trace log.

[0140] In actual applications, R&D personnel have found that in some cases, when a software program is unresponsive, for example, the main thread of the software program is continuously in the Running state, causing other threads to be unscheduled for a long time. If only the Trace log is used, it is often difficult to locate the root cause. The root cause can also be called the cause of the response timeout problem. In practice, it is also found that these problems that are difficult to locate the root cause through the Trace log are often complex problems that are not caused by a single reason.

[0141] In actual applications, it is also found that the system overhead of collecting Trace logs is relatively large. When collecting Trace logs, the software program needs to be suspended, which means that it is difficult to continuously collect Trace logs of software programs. In addition, it is also found in practice that SimplePerf logs can record the running process data of the program, and the data is detailed and comprehensive, and the system overhead of collecting SimplePerf logs is relatively small. When collecting SimplePerf logs, there is no need to suspend the running of the software program, which means that it is also easier to continuously collect SimplePerf logs of software programs.

[0142] Based on the above analysis, in order to solve the above technical problems, an embodiment of the present application provides a data collection method, and the electronic device can collect the SimplePerf log of the software program within a period of time before the software program has a response timeout problem. Since the SimplePerf log within a period of time can reflect the continuous operation changes of the software program during the period of time, through the analysis of the SimplePerf log within a period of time, the root cause of the response timeout problem can be more effectively located, especially the root cause of the above-mentioned complex problems can be more effectively located. That is, the data collection method provided by the embodiment of the present application can accurately collect valid log data when a problem occurs in the software program, which helps to more accurately locate the root cause of the software program's unresponsiveness problem, thereby assisting R&D personnel to promptly and effectively solve the unresponsiveness problem of the software program.

[0143] The following describes the usage scenarios of the embodiments of the present application:

[0144] The embodiments of the present application may be applicable to scenarios where a system service process or an application in an electronic device becomes unresponsive.

[0145] The data collection method provided in the embodiments of the present application can be applied to electronic devices, and the electronic devices can be mobile phones, tablet computers, wearable devices, vehicle-mounted devices, augmented reality (AR) / virtual reality (VR) devices, laptop computers, ultra-mobile personal computers (UMPC), netbooks, personal digital assistants (PDA) and other devices, and the embodiments of the present application are not limited to this.

[0146] Figure 2 A schematic diagram of a software system for an electronic device provided in an embodiment of the present application. Figure 2 ,The software system of the electronic device may include an application layer, an application framework layer, a system layer, a kernel layer and a hardware layer.

[0147] like Figure 2 As shown, the application layer may include a series of application packages, such as phone, message, calendar, gallery, and other applications.

[0148] The application framework layer provides an application programming interface (API) and programming framework for applications in the application layer. The application framework layer includes some predefined functions.

[0149] like Figure 2As shown, the application framework layer may include a window manager, a view system, a phone manager, a resource manager, an input system, a broadcast system, a service, a content provider, an activity manager (Activity Manager Service, AMS), a watchdog, a simple performance analysis tool (SimplePerf), etc.

[0150] The window manager is used to manage window programs. The window manager can obtain the display screen size, determine whether there is a status bar, lock the screen, capture the screen, etc.

[0151] The view system includes visual controls, such as controls for displaying text, controls for displaying images, etc. The view system can be used to build applications. A display interface can be composed of one or more views. For example, a display interface including a text notification icon can include a view for displaying text and a view for displaying images.

[0152] The phone manager is used to provide communication functions for electronic devices, such as the management of call status (including answering, hanging up, etc.).

[0153] The resource manager provides various resources for applications, such as localized strings, icons, images, layout files, video files, and so on.

[0154] Content providers are used to store and retrieve data and make it accessible to applications. The data can include videos, images, audio, calls made and received, browsing history and bookmarks, phone books, etc.

[0155] The input system is used to obtain touch information acting on the electronic screen. The touch information can be information triggered by the user's fingers, knuckles, etc., or information triggered by a stylus.

[0156] The input system may include an input distribution module (InputDispatcher). When the input system obtains touch information, the InputDispatcher module can distribute the input events corresponding to the touch information to the corresponding application. At the same time, the InputDispatcher module can check whether the application can respond to the input event within the timeout response duration (or called the second detection duration). If the application can respond to the input event within the timeout response duration, ANR will not be triggered. If the application cannot respond to the input event within the timeout response duration, ANR will be triggered. Figure 1For example, when the application fails to respond to the input event within the timeout response duration, the electronic device triggers ANR and displays the ANR prompt window 101. The timeout response duration is a preset duration value, such as 30 seconds. The value of the timeout response duration is related to the unresponsive scenario. For example, for the unresponsive scenario of the input event, the timeout response duration may be 30 seconds; and for the unresponsive scenario of the broadcast message, the timeout response duration may be 10 seconds.

[0157] AMS is responsible for managing the four major components in the Android system, namely, activities in applications at the application layer, broadcast systems, services, and content providers at the application framework layer.

[0158] Among them, Activity represents the display layer of an application. Each Activity usually corresponds to a screen, which is used to display the user interface and handle user interaction. Activities can communicate with each other.

[0159] The broadcast system is used to receive broadcast messages sent by the system or other applications and respond as needed. It is suitable for processing system events or application events.

[0160] Services are used to perform long-running operations in the background, such as playing music, downloading files, etc. It does not provide a user interface, but can communicate with the Activity in the background.

[0161] Content providers are used to share data between different applications, such as information in a database, allowing other applications to access and operate on the shared data.

[0162] AMS includes the active service management module (ActiveServices) and the broadcast message management module (BroadcastQueuelmpl). AMS can manage running services through ActiveServices, and AMS can also manage broadcast messages in the broadcast system through BroadcastQueuelmpl.

[0163] SimplePerf is a tool for performance analysis and debugging in the Android system. The SimplePerf service management module is a component of the SimplePerf tool, responsible for managing the life cycle and configuration of the SimplePerf service to ensure that users can easily perform performance analysis and tuning. The SimplePerf service is used to implement the functions of the SimplePerf tool.

[0164] In practice, users can start the SimplePerf service, stop the SimplePerf service, or configure the parameters of the SimplePerf service through the SimplePerf service management module.

[0165] The system layer includes the Android runtime and system libraries.

[0166] Android Runtime includes core libraries and virtual machines. Android Runtime is responsible for the scheduling and management of the Android system.

[0167] The core library consists of two parts: one part is the function that needs to be called by the Java language, and the other part is the Android core library.

[0168] The application layer and the application framework layer run in a virtual machine. The virtual machine executes the Java files of the application layer and the application framework layer as binary files. The virtual machine is used to perform functions such as object life cycle management, stack management, thread management, security and exception management, and garbage collection.

[0169] The system library can include multiple functional modules, such as surface manager, media library, 3D graphics processing library (such as OpenGL ES), 2D graphics engine (such as SGL), etc.

[0170] The surface manager is used to manage the display subsystem and provide the fusion of two-dimensional and three-dimensional layers for multiple applications.

[0171] The media library supports playback and recording of a variety of commonly used audio and video formats, as well as static image files, etc. The media library can support a variety of audio and video encoding formats, such as: MPEG4, H.164, MP3, AAC, AMR, JPG, PNG, etc.

[0172] The 3D graphics processing library is used to implement 3D graphics drawing, image rendering, synthesis and layer processing.

[0173] A 2D graphics engine is a drawing engine for 2D drawings.

[0174] The kernel layer is the layer between hardware and software. The kernel layer includes at least display driver, sensor driver, etc. Among them, display driver is used to drive the display screen; sensor driver is used to drive the sensor.

[0175] The hardware layer includes at least physical devices such as display screens and sensors. Among them, the sensors may include: pressure sensors, gyroscope sensors, acceleration sensors, distance sensors, proximity light sensors, fingerprint sensors, etc. The functions of each sensor are not described in detail in the embodiments of the present application.

[0176] It is understandable that the SimplePerf log is only used as an example, and it is not limited to collect only SimplePerf logs.

[0177] The following takes the first type of log as SimplePerf log as an example to explain the data collection method for the software program unresponsiveness problem in the embodiment of the present application from the two aspects of system unresponsiveness and ANR. When the first type of log is SimplePerf log, the first service for collecting SimplePerf log is SimplePerf service, and the first management module for managing SimplePerf service is SimplePerf service management module.

[0178] It should be noted that in this application, the software program being detected can be a system service process in the Android system or an application. When the software program being detected is a system service process, the unresponsiveness problem that occurs is usually the system unresponsiveness. When the software program being detected is an application, the unresponsiveness problem that occurs is usually ANR.

[0179] 1. Regarding ANR

[0180] Based on the above Figure 2 The system framework of the electronic device shown in the figure is described in detail below in conjunction with the interactive flow diagram. Figure 2 The illustrated electronic device shows a specific interaction process between various structures in the system of the electronic device during the process of implementing the data collection method of the present application for the ANR problem.

[0181] In the embodiment of the present application, since there may be multiple ANR scenarios, as an example, the ANR scenarios may include the following ANR scenarios 1-ANR scenarios 4.

[0182] Among them, ANR scenario 1, input events trigger ANR. In ANR scenario 1, if the application does not respond to input events in time, such as key events and touch events, ANR can be triggered.

[0183] ANR scenario 2, service startup triggers ANR. In ANR scenario 2, when the service that needs to be started does not complete the startup in time, ANR can be triggered.

[0184] ANR scenario 3, the broadcast system triggers ANR. In ANR scenario 1, when the application fails to complete the sending and receiving of the broadcast message in time, ANR may be triggered.

[0185] ANR scenario 4, content provider startup triggers ANR. In ANR scenario 4, when an application requests to start a content provider, if the application provider is not started in time, ANR may be triggered.

[0186] Taking into account that the detected software programs involved in each ANR scenario are different, for example, the detected software program corresponding to ANR scenario 1 is the application targeted by the input event, while the detected software program corresponding to ANR scenario 2 is an application that wants to start a service component (or called a service), that is, the data collection process of the electronic device for each ANR scenario may be different.

[0187] In addition, not every ANR scenario may present complex problems that are difficult to locate the root cause, that is, in some ANR scenarios, the root cause can be located only through the Trace log. Therefore, in some application scenarios, in order to save the computing resources and storage resources of the electronic device, the electronic device can directly collect the Trace log at the time when the ANR occurs, for example, ANR scenario 4, where the root cause can be located only through the Trace log, without collecting the SimplePerf log for a period of time before the ANR occurs.

[0188] Therefore, the following describes the corresponding data collection process for each ANR scenario where complex problems may occur. Among them, the ANR scenarios where complex problems may occur may include the above-mentioned ANR scenario 1, ANR scenario 2 and ANR scenario 3.

[0189] (1) Data collection process for ANR scenario 1.

[0190] Combine the following Figure 3A-3C This chapter describes the data collection process for ANR scenario 1. Figure 3A A schematic diagram of a data collection interaction process for input events provided in an embodiment of the present application. Figure 3B A schematic diagram of another data collection interaction process for input events provided in an embodiment of the present application. Figure 3C A schematic diagram of the data collection process for input events provided in an embodiment of the present application.

[0191] Figure 3A The method flow shown includes at least the following steps:

[0192] S3011, InputDispatcher receives a distribution instruction to distribute the input event, and distributes the input event to the corresponding target application.

[0193] The distribution instruction is instruction information used to instruct the distribution of input events.

[0194] Among them, InputDispatcher is Figure 2 FIG. 4 is an event dispatching module in the input system of the application framework layer shown in FIG.

[0195] Here, for the convenience of description, the application targeted by the input event may be recorded as the target application. For example, if the user clicks the application icon of application A, the application targeted by the input event is application A.

[0196] As an example, InputDispatcher can dispatch input events to target applications when the dispatchOnce function is called. The dispatchOnce function is a function used in the Android system to instruct the dispatch of input events.

[0197] Combination Figure 3B , electronic devices can be input through the system (combined with Figure 2 An input event is detected by the input system in the application framework layer in .

[0198] Afterwards, when the electronic device detects an input event, the electronic device can further distribute the input event to the target application through the InputDispatcher module in the input system. Figure 3B The InputDispatcher module includes an ANR monitoring module, which can detect the response of the target application to the input event. Specifically, if the target application can respond to the input event within the timeout response duration (or the second detection duration), ANR will not be triggered. If the target application cannot respond to the input event within the timeout response duration, ANR will be triggered. Figure 1 For example, when the application fails to respond to the input event within the timeout response period, the electronic device triggers ANR and displays the ANR prompt window 101 .

[0199] Among them, the above timeout response duration is a pre-set duration value. In practice, the above timeout response duration is usually related to the specific ANR scenario. For example, for the ANR scenario of input events, the timeout response duration can be 5 seconds, for the ANR scenario of service startup, the timeout response duration can be 30 seconds, and for the ANR scenario of broadcast transmission and reception, the timeout response duration can be 10 seconds.

[0200] Continue to combine Figure 3BWhen the electronic device detects that the target application does not respond to the input event within the first detection time, the electronic device can send a data collection message to the SimplePerf service management module through the InputDispatcher. The SimplePerf service management module can start the SimplePerf service, and the SimplePerf service collects the SimplePerf log of the target application.

[0201] It can be understood that the SimplePerf service can save the collected SimplePerf logs in a preset path, so that users can obtain the SimplePerf logs from the path, and thus effectively and accurately analyze the ANR problems of the target application in combination with the SimplePerf logs.

[0202] S3012, InputDispatcher performs timeout check.

[0203] Here, the InputDispatcher can check whether the application responds to the input event within the timeout response period.

[0204] In practice, InputDispatcher can check whether the application responds to the input event within the specified time by calling the processAnrsLocked method. The processAnrsLocked method is a method used in the Android system to check whether the application responds to the input event within the timeout response period.

[0205] S3013: When the application's response time to the input event exceeds 80% of the ANR timeout threshold, the InputDispatcher sends a data collection message to the SimplePerf service management module.

[0206] The ANR timeout duration threshold may also be referred to as the second detection duration, and 80% of the ANR timeout duration threshold may be referred to as the first detection duration, wherein 80% is the first coefficient.

[0207] In practice, the data collection message may be: start(args), where start(args) is used to indicate the start of data collection, and args is a collection parameter. The collection parameter may include collection duration, collection frequency, etc. It is understandable that the embodiments of the present application do not specifically limit the collection parameters.

[0208] Optionally, the first detection duration may be a preset duration value.

[0209] Optionally, the first detection duration is positively correlated with the timeout response duration (or referred to as the second detection duration). For the same ANR scenario, the first detection duration is shorter than the timeout response duration.

[0210] Optionally, the first detection duration is the product of the timeout response duration and the first coefficient, wherein the first coefficient is a positive number less than 1. For example, if the timeout response duration is 5 seconds and the first coefficient is 0.8, the first detection duration may be 4 seconds.

[0211] In practice, the smaller the value of the first coefficient, the larger the amount of data in the collected SimplePerf logs, that is, the larger the storage space used to store SimplePerf logs. The larger the value of the first coefficient, the shorter the duration of the collected SimplePerf logs, that is, the smaller the amount of SimplePerf log data available for analysis. In order to achieve accurate and effective analysis of unresponsiveness issues based on SimplePerf logs while saving storage space, the value of the first coefficient is usually between 0.5-1. Specifically, the first coefficient can be 0.8.

[0212] It should be pointed out that when the first coefficient is 0.8, the first detection duration is close to the second detection duration. When the first detection duration has been reached, but the software program has not completed the task, there is a high possibility of a response timeout. That is, starting to collect SimplePerf logs when the first detection duration is reached can achieve targeted log data collection, and is less likely to cause storage resource consumption due to blind collection.

[0213] S3014, the SimplePerf service management module sends a message to the SimplePerf service to instruct it to collect SimplePerf logs.

[0214] In practice, the SimplePerf service management module may start the SimplePerf service upon receiving the above data collection message, and the SimplePerf service may collect the SimplePerf logs of the application.

[0215] It should be pointed out that the SimplePerf service should be started only when it is determined that SimplePerf logs need to be collected. This can save unnecessary loss of operating resources and help further improve the data processing performance of electronic devices.

[0216] In some optional implementations of the embodiments of the present application, the SimplePerf service management module usually sends a message instructing the SimplePerf service to collect SimplePerf logs when the SimplePerf logs already collected by the electronic device do not exceed the quota.

[0217] The above quota is used to indicate the upper limit of the amount of SimplePerf logs collected every day.

[0218] In practice, the above quota usually refers to the number of times SimplePerf logs are collected. In some application scenarios, the above quota can also refer to the amount of data in SimplePerf logs.

[0219] S3015, the SimplePerf service collects and saves SimplePerf logs.

[0220] Here, the SimplePerf service can collect the SimplePerf log of the application targeted by the input event according to the above collection parameters, and save the collected SimplePerf log in a specified path. The above specified path is usually a pre-set storage path of the SimplePerf log in the electronic device. It can be understood that the embodiment of the present application does not specifically limit the storage path.

[0221] The following further combines Figure 3C The data collection process for input events in the embodiments of the present application is described. Figure 3C The method flow shown includes at least the following steps:

[0222] S3021, the electronic device may detect a user input event.

[0223] Here, the user input event may also be referred to as an input event for short.

[0224] Electronic devices can be connected through the input system (combined with Figure 2 The input system in the application framework layer in detects input events.

[0225] S3022, the electronic device can distribute the input event to the application through the InputDispatcher module in the input system, and detect whether the application can respond to the input event within the timeout response period through the ANR monitoring module.

[0226] It can be understood that the InputDispatcher module distributes input events to the application programs to which the input events are directed.

[0227] S3023, the electronic device may determine whether the current time reaches the Perf threshold. If so, S3024 is executed. If the Perf threshold has not been reached when the application completes responding to the input event, S3026 is executed.

[0228] The above-mentioned Perf threshold value may also be referred to as a first detection duration. The Perf threshold value is smaller than the timeout response duration of the input event.

[0229] Here, the electronic device can record a time when the InputDispatcher module distributes the input event to the application, and this time can be called the sending time. When the application completes the response to the input event, it can send a feedback message to the InputDispatcher. The electronic device can record a time again when the InputDispatcher module receives the feedback message from the application, and this time can be called the receiving time.

[0230] Afterwards, the InputDispatcher module can detect the time interval between the current time and the sending time in real time, and determine whether the time interval reaches the above Perf threshold.

[0231] Specifically, if the above time interval does not reach the Perf threshold when the InputDispatcher module receives the feedback information, the process ends. That is, the application responds to the input event in a timely manner, and there is no need to collect SimplePerf logs.

[0232] If the time interval between the current time and the sending time reaches the Perf threshold and the InputDispatcher module does not receive the above feedback information, the electronic device can further analyze whether the SimplePerf logs collected on that day exceed the preset quota.

[0233] S3024, the electronic device may further analyze whether the SimplePerf logs collected on that day exceed a preset quota, and if so, execute S3026; if not, execute S3025.

[0234] Here, if the quota has been exceeded, the electronic device will not further collect the SimplePerf log of the application for the input event. If the quota has not been exceeded, the electronic device can collect and store the SimplePerf log for the input event.

[0235] S3025, the electronic device collects and saves the SimplePerf log of the application.

[0236] S3026, the electronic device ends the data collection operation.

[0237] Combination FIG. 3A to FIG. 3C It can be found that in the embodiment of the present application, the electronic device can collect the SimplePerf log of the application over a period of time before the ANR problem occurs in the application, so as to more accurately locate the root cause of the ANR problem when responding to input events, and assist R&D personnel to promptly and effectively solve the problem of the application's unresponsiveness to input events.

[0238] (2) Data collection process for ANR scenario 2.

[0239] Combine the following Figure 4A-4C This chapter describes the data collection process for ANR scenario 2. Figure 4A A schematic diagram of a data collection interaction process for service startup provided in an embodiment of the present application. Figure 4B A schematic diagram of another data collection interaction process for service startup provided in an embodiment of the present application. Figure 4C A schematic diagram of the data collection process for service startup provided in an embodiment of the present application.

[0240] Figure 4A The method flow shown includes at least the following steps:

[0241] S4011, ActiveServices receives the service startup information and starts the corresponding service.

[0242] The service startup information is instruction information for requesting to start a service.

[0243] Among them, ActiveServices is Figure 2 Active Service Management Module in AMS of the Application Framework Layer. AMS can manage running services through ActiveServices.

[0244] Here, when an application triggers the start of a service (or service component), the realStartServiceLocked function in ActiveServices will be called. In this way, ActiveServices can determine that an application needs to start a service when the realStartServiceLocked function is called. Among them, the realStartServiceLocked function is a function used in the Android system to indicate the start of a service.

[0245] It should be noted that the Android system can provide many service components. Applications running on the Android system can call the service components to implement corresponding functions.

[0246] It should be noted that a service component called by an application may or may not be run in the application. For example, application A may call service component 1, and service component 1 may be run in application A or application B.

[0247] Combination Figure 4B , AMS in electronic devices (combined with Figure 2 The Service in the AMS of the application framework layer, that is, ActiveServices, includes an ANR monitoring module. When an electronic device starts a service in an application, the electronic device can detect the startup status of the service through the ANR monitoring module in the AMS. Specifically, if the service is started within the timeout response period, ANR will not be triggered. If the service cannot be started within the timeout response period, ANR will be triggered.

[0248] The timeout response duration is a preset duration value, for example, 30 seconds.

[0249] In practice, the above timeout response duration is usually related to the specific ANR scenario. For example, for the ANR scenario of input events, the timeout response duration can be 5 seconds, for the ANR scenario of service startup, the timeout response duration can be 30 seconds, and for the ANR scenario of broadcast transmission and reception, the timeout response duration can be 10 seconds.

[0250] Continue to combine Figure 4B When the electronic device detects that the service has not been started within the first detection time, the electronic device can send a data collection message to the SimplePerf service management module through the Service in the AMS, that is, ActiveServices. The SimplePerf service management module can start the SimplePerf service, and the SimplePerf service collects the SimplePerf logs of the application.

[0251] S4012, ActiveServices adds the service as a timeout check object.

[0252] As an example, ActiveServices can add the service to be started as a timeout check object by executing the bumpServiceExecutingLocked operation, wherein bumpServiceExecutingLocked is a function in the Android system for adding a service as a timeout check object.

[0253] S4013, ActiveServices performs a timeout check on the service.

[0254] As an example, ActiveServices can perform a timeout check on a service by executing the scheduleServiceTimeoutLocked operation, where scheduleServiceTimeoutLocked is a function used in the Android system to perform a timeout check on a service.

[0255] S4014, ActiveServices sends a scheduled message to the Handler.

[0256] Among them, Handler can also be called target message queue.

[0257] As an example, ActiveServices can send a timed message to Handler by executing the sendMessageDelayed operation, where sendMessageDelayed is a function in the Android system for sending messages for timed processing.

[0258] Among them, the scheduled message is a message that is processed at a scheduled time. The scheduled message may include the message content and the scheduled duration of the message.

[0259] Among them, Handler is the message queue provided by the Android system. Handler can process messages sequentially. Handler can also support timed processing of messages.

[0260] In the embodiment of the present application, the Handler can receive a timed message for timed processing, and when the waiting time reaches the timed duration of the timed message, such as the first detection duration and the second detection duration, the timed message is processed. For example, if the timed duration set for timed message 1 is 30 seconds, then the Handler can start timing when receiving the timed message, and when the timing reaches 30 seconds, the timed message is processed. Before the timing reaches 30 seconds, the Handler will not process the timed message.

[0261] Here, ActiveServices can send two timing messages to the Handler, one of which is an ANR timeout message and the other is a Perf timeout message. In some embodiments, for ease of distinction, the Perf timeout message for ANR scenario 2 can also be referred to as the first timing message, and the ANR timeout message for ANR scenario 2 can also be referred to as the second timing message.

[0262] ANR timeout message is a message that triggers ANR. When the timer of ANR timeout message is reached, ANR is triggered. Perf timeout message is a message that triggers capturing Perf log. When the timer of Perf timeout message is reached, Perf log (or SimplePerf log) is triggered.

[0263] Here, the timing duration of the Perf timeout message is shorter than the timing duration of the ANR timeout message. In this way, the Perf log can be collected before the ANR problem occurs, thereby assisting in more accurately and effectively locating the root cause of the ANR problem.

[0264] Combination Figure 4A , the ANR timeout message can be: SERVICE_FOREGROUND_TIMEOUT_MSG, 30s. SERVICE_FOREGROUND_TIMEOUT_MSG is the message content, and 30 seconds is the timing duration for the timed message. The Perf timeout message can be: SERVICE_FOREGROUND_PERF_TIMEOUT_MSG, 24S. SERVICE_FOREGROUND_PERF_TIMEOUT_MSG is the message content, and 24 seconds is the timing duration.

[0265] S4015, when the service is started in time, ActiveServices removes the scheduled message in the Handler.

[0266] Here, ActiveServices can notify the Handler to remove the corresponding scheduled message in the Handler by calling the removeMessage function, where removeMessage is a function used to remove messages in the Android system.

[0267] like Figure 4A As shown, when the service is started in time, the electronic device can remove the timed message from the Handler before the timed duration is reached, so that the operation corresponding to the timed message will not be triggered.

[0268] S4016, the Perf timeout message in the Handler reaches the corresponding timing duration, and the Handler sends the corresponding first timeout indication information to ActiveServices.

[0269] The first timeout indication information is used to indicate that the timing duration of the Perf timeout message has been reached. In some embodiments, the first timeout indication information may also be referred to as second feedback information.

[0270] The timeout indication information is used to indicate that the timeout message timing duration is reached. In practice, when the timeout message timing duration of the ANR timeout message is reached, the Handler can send a corresponding second timeout indication information to ActiveServices. The second timeout indication information is used to indicate that the timeout message timing duration of the ANR timeout message is reached. In some embodiments, the second timeout indication information can also be referred to as the third feedback information.

[0271] Here, the first timeout indication information may be serviceForegroundPerfTimeout. The second timeout indication information may be serviceForegroundTimeout. It can be understood that the embodiment of the present application does not limit the specific implementation form of the timeout indication information (eg, the first timeout indication information, the second timeout indication information).

[0272] S4017, ActiveServices sends a data collection message to the SimplePerf service management module.

[0273] In practice, the data collection message may be: start(args), where start(args) is used to indicate the start of data collection, and args is a collection parameter, which may include collection duration, collection frequency, and the like.

[0274] S4018, the SimplePerf service management module sends a message to the SimplePerf service to instruct it to collect SimplePerf logs.

[0275] In practice, the SimplePerf service management module may start the SimplePerf service upon receiving the above data collection message, and the SimplePerf service may collect the SimplePerf logs of the application.

[0276] S4019, the SimplePerf service collects and saves SimplePerf logs.

[0277] Here, the SimplePerf service can collect the SimplePerf logs of the application according to the above collection parameters, and save the collected SimplePerf logs in a specified path. The above specified path is usually a pre-set storage path of the SimplePerf log in the electronic device. It can be understood that the embodiment of the present application does not specifically limit the storage path.

[0278] The following further combines Figure 4C The data collection process for service startup in the embodiment of the present application is explained. Figure 4C The method flow shown includes at least the following steps:

[0279] S4021, electronic equipment can be AMS (combined with Figure 2 ActiveServices in the AMS in the application framework layer in the application detects that a service is started.

[0280] S4022, the electronic device can detect whether the service can be started within the timeout response period through the ANR monitoring module in the AMS.

[0281] S4023, the electronic device may set a Perf timeout message for the service to be started.

[0282] Combination Figure 4A , the Perf timeout message can be: SERVICE_FOREGROUND_PERF_TIMEOUT_MSG, 24S. Among them, SERVICE_FOREGROUND_PERF_TIMEOUT_MSG is the message content, and 24 seconds is the timing length of the Perf timeout message.

[0283] S4024, the electronic device can determine whether the current time reaches the timing duration of the Perf timeout message. If it reaches the timing duration, execute S4025. If the service startup is completed but the timing duration of the Perf timeout message has not yet been reached, execute S4027.

[0284] Here, if the service startup is completed before the timer duration of the Perf timeout message is reached, the Perf timeout message is removed and the electronic device can end the processing flow. That is, the service to be started is started in time without collecting SimplePerf logs.

[0285] If the service is not started when the timer duration of the Perf timeout message is reached, SimplePerf logs need to be collected now, and the electronic device can further analyze whether the SimplePerf logs collected on that day exceed the preset quota.

[0286] S4025, the electronic device may further analyze whether the SimplePerf logs collected on that day exceed a preset quota, and if so, execute S4027, and if not, execute S4026.

[0287] Here, if the quota has been exceeded, the electronic device will not further collect the SimplePerf log of the application for the service that is about to start the timeout. If the quota has not been exceeded, the electronic device can collect and store the SimplePerf log for the service that is about to start the timeout.

[0288] S4026, the electronic device collects and saves the SimplePerf log of the application.

[0289] S4027, the electronic device ends the data collection operation.

[0290] Combination FIG. 4A to FIG. 4C It can be found that in the embodiment of the present application, the electronic device can collect the SimplePerf log of the application over a period of time before the ANR problem occurs in the application, so as to more accurately locate the root cause of the unresponsiveness problem at service startup, and assist R&D personnel to promptly and effectively solve the unresponsiveness problem of the application when the service is started.

[0291] (3) Data collection process for ANR scenario 3.

[0292] Combine the following Figure 5A-5C This chapter describes the data collection process for ANR scenario 3. Figure 5A A schematic diagram of a data collection interaction process for broadcast transmission and reception provided in an embodiment of the present application. Figure 5B A schematic diagram of another data collection interaction process for broadcast reception and transmission provided in an embodiment of the present application. Figure 5C A schematic diagram of the data collection process for broadcast reception and transmission provided in an embodiment of the present application.

[0293] Figure 5A The method flow shown includes at least the following steps:

[0294] S5011, BroadcastQueuelmpl receives the broadcast indication information and broadcasts the broadcast message.

[0295] The broadcast indication information is used to indicate that the message to be broadcast needs to be broadcast.

[0296] Among them, BroadcastQueuelmpl is Figure 2 The broadcast message management module in the AMS of the application architecture layer shown. The AMS can manage the broadcast messages in the broadcast system through BroadcastQueuelmpl.

[0297] In practice, when the system or application needs to broadcast a message, the processNextBroadcast function in BroadcastQueuelmpl will be called. In this way, BroadcastQueuelmpl can determine that a broadcast message needs to be broadcast when the processNextBroadcast function is called. Among them, the processNextBroadcast function is a function used in the Android system to instruct the broadcast of a message.

[0298] Combination Figure 5B , AMS in electronic devices (combined with Figure 2 The Broadcast in the AMS of the application framework layer in the application, that is, the BroadcastQueue11, includes an ANR monitoring module. When the electronic device needs to send or receive a broadcast message in the application, the electronic device can detect whether the broadcast message is successfully broadcast through the ANR monitoring module in the AMS. Specifically, if the broadcast message is successfully broadcast within the timeout response duration, the ANR will not be triggered. If the broadcast message is not successfully broadcast within the timeout response duration, the ANR will be triggered.

[0299] Among them, the above timeout response duration is a pre-set duration value. In practice, the above timeout response duration is usually related to the specific ANR scenario. For example, for the ANR scenario of input events, the timeout response duration can be 5 seconds, for the ANR scenario of service startup, the timeout response duration can be 30 seconds, and for the ANR scenario of broadcast transmission and reception, the timeout response duration can be 10 seconds.

[0300] Continue to combine Figure 5B When the electronic device detects that the broadcast message has not been broadcasted within the first detection time, the electronic device can send a data collection message to the SimplePerf service management module through Broadcast in AMS, that is, BroadcastQueueImpl. The SimplePerf service management module can start the SimplePerf service, and the SimplePerf service collects the SimplePerf logs of the application.

[0301] S5012, BroadcastQueuelmpl sets the broadcast timing duration.

[0302] As an example, BroadcastQueuelmpl can set the timer duration for the broadcast message to be broadcast by executing the setBroadcastTimeoutLocked operation, where setBroadcastTimeoutLocked is a function used to set the timer duration in the Android system.

[0303] S5013, BroadcastQueuelmpl sends a scheduled message to Handler.

[0304] As an example, BroadcastQueuelmpl can send a timed message to Handler by executing the sendMessageAtTime operation, where sendMessageAtTime is a function in the Android system for sending messages for timed processing.

[0305] Here, BroadcastQueuelmpl can send two scheduled messages to Handler, one of which is an ANR timeout message and the other is a Perf timeout message. The ANR timeout message is a message that triggers ANR. When the timer duration of the ANR timeout message is reached, ANR is triggered. The Perf timeout message is a message that triggers the capture of Perf logs. When the timer duration of the Perf timeout message is reached, the capture of Perf logs is triggered.

[0306] In some embodiments, for ease of distinction, the Perf timeout message for ANR scenario 3 may also be referred to as a third timing message, and the ANR timeout message for ANR scenario 2 may also be referred to as a fourth timing message.

[0307] Here, the timing duration of the Perf timeout message is shorter than the timing duration of the ANR timeout message. In this way, the Perf log can be collected before the ANR problem occurs, thereby assisting in more accurately and effectively locating the root cause of the ANR problem.

[0308] Combination Figure 5A , the ANR timeout message for a broadcast message may be: BROADCAST_TIMEOUT_MSG,10S, where BROADCAST_TIMEOUT_MSG is the message content and 10 seconds is the timer duration for the message.

[0309] The Perf timeout message for the broadcast message may be: BROADCAST_PERF_TIMEOUT_MSG,8S, where BROADCAST_PERF_TIMEOUT_MSG is the message content and 8 seconds is the timeout duration.

[0310] S5014, when the message is broadcast in time, BroadcastQueuelmpl removes the scheduled message in the Handler.

[0311] Here, BroadcastQueuelmpl can notify Handler to remove the corresponding timed message in Handler by calling removeMessage function, where removeMessage is a function used to remove messages in the Android system.

[0312] like Figure 5AAs shown, in the case where the message is broadcast in time, the electronic device can remove the scheduled message from the Handler before the scheduled duration is reached, so that the operation corresponding to the scheduled message will not be triggered.

[0313] S5015, the Perf timeout message in the Handler reaches the corresponding timing duration, and the Handler sends the corresponding third timeout indication information to the BroadcastQueuelmpl.

[0314] The third timeout indication information is used to indicate that the timing duration of the Perf timeout message has been reached. The third timeout indication information may also be referred to as fourth feedback information.

[0315] The timeout indication information is used to indicate that the timeout message timing duration has been reached. In practice, when the timeout message timing duration of the ANR timeout message is reached, the Handler may send the corresponding fourth timeout indication information to ActiveServices. The fourth timeout indication information is used to indicate that the timeout message timing duration of the ANR timeout message has been reached. The fourth timeout indication information may also be referred to as the fifth feedback information.

[0316] Here, the third timeout indication information may be broadcastPerfTimeout. The fourth timeout indication information may be broadcastTimeout. It is understandable that the embodiment of the present application does not limit the specific implementation form of the timeout indication information (eg, the third timeout indication information, the fourth timeout indication information).

[0317] S5016, BroadcastQueuelmpl sends a data collection message to the SimplePerf service management module.

[0318] In practice, the data collection message may be: start(args), where start(args) is used to indicate the start of data collection, and args is a collection parameter, which may include collection duration, collection frequency, and the like.

[0319] S5017, the SimplePerf service management module sends a message to the SimplePerf service to instruct it to collect SimplePerf logs.

[0320] In practice, the SimplePerf service management module may start the SimplePerf service upon receiving the above data collection message, and the SimplePerf service may collect the SimplePerf logs of the application.

[0321] In some optional implementations of the embodiments of the present application, the SimplePerf service management module usually sends a message instructing the SimplePerf service to collect SimplePerf logs when the SimplePerf logs already collected by the electronic device do not exceed the quota.

[0322] S5018, the SimplePerf service collects and saves SimplePerf logs.

[0323] Here, the SimplePerf service can collect the SimplePerf log of the application targeted by the input event according to the above collection parameters, and save the collected SimplePerf log in a specified path. The above specified path is usually a pre-set storage path of the SimplePerf log in the electronic device. It can be understood that the embodiment of the present application does not specifically limit the storage path.

[0324] The following further combines Figure 5C The data collection process for broadcast reception and transmission in the embodiments of the present application is described. Figure 5C The method flow shown includes at least the following steps:

[0325] S5021, electronic devices can be connected through AMS (combined with Figure 2 The BroadcastQueuelmpl in the AMS in the application framework layer in the application framework layer detects that the message to be broadcast needs to be broadcast.

[0326] S5022, the electronic device can detect whether the message to be broadcast can be broadcast within the timeout response duration through the ANR monitoring module in the AMS.

[0327] S5023, the electronic device may set a Perf timeout message for the message to be broadcast.

[0328] Combination Figure 5A , the Perf timeout message can be: BROADCAST_PERF_TIMEOUT_MSG,8S, where BROADCAST_PERF_TIMEOUT_MSG is the message content and 8 seconds is the timing duration.

[0329] S5024, the electronic device can determine whether the current time reaches the timing duration of the Perf timeout message. If it reaches the timing duration, execute S5025. If the timing duration of the Perf timeout message has not been reached when the broadcast message is broadcasted, execute S5027.

[0330] Here, if the message is successfully broadcast before the timing of the Perf timeout message is reached, the Perf timeout message is removed and the electronic device can end the processing flow. That is, the message to be broadcast is broadcast in time without collecting SimplePerf logs.

[0331] If the message to be broadcast has not been broadcasted when the timing duration of the Perf timeout message is reached, SimplePerf logs need to be collected now, and the electronic device can further analyze whether the SimplePerf logs collected on that day exceed the preset quota.

[0332] S5025, the electronic device may further analyze whether the SimplePerf logs collected on the day exceed the preset quota. If so, S5027 is executed; if not, S5026 is executed.

[0333] Here, if the quota has been exceeded, the electronic device will not further collect the SimplePerf log of the application for the broadcast message that is about to time out. If the quota has not been exceeded, the electronic device can collect and store the SimplePerf log for the broadcast message that is about to time out.

[0334] S5026, the electronic device collects and saves the SimplePerf log of the application.

[0335] S5027, the electronic device ends the data collection operation.

[0336] Combination FIG. 5A to FIG. 5C It can be found that in an embodiment of the present application, the electronic device can collect the SimplePerf log of the application over a period of time before the ANR problem occurs in the application, so as to more accurately locate the root cause of the unresponsiveness problem when broadcasting messages, and assist R&D personnel to promptly and effectively solve the unresponsiveness problem of the application in the broadcast sending and receiving process.

[0337] 2. System unresponsiveness

[0338] Based on the above Figure 2 The system framework of the electronic device shown in the figure is described in detail below in conjunction with the interactive flow diagram. Figure 2 The electronic device shown in the figure shows a specific interaction process between various structures in the system of the electronic device during the process of implementing the data collection method of the present application for the problem of system unresponsiveness.

[0339] Combine the following Figure 6A-6C This paper describes the data collection process for scenarios where the system does not respond. Fig. 6A A schematic diagram of a data collection interaction process for system unresponsiveness provided in an embodiment of the present application. Figure 6B Another data collection interaction process diagram for system unresponsiveness provided in an embodiment of the present application. Figure 6C A schematic diagram of a data collection process for system unresponsiveness provided in an embodiment of the present application.

[0340] Fig. 6A The method flow shown includes at least the following steps:

[0341] S6011, Watchdog starts running and performs cyclic detection on system services.

[0342] In practice, Watchdog runs in the system service process of the Android system. When the run function of Watchdog is called, Watchdog starts running. Watchdog can be a thread in the system service process, and Watchdog is used to detect the status of other threads in the system service process.

[0343] During the running of Watchdog, Watchdog can continuously detect the running status of system service processes.

[0344] Combination Figure 6B In the system service process of the electronic device, multiple first threads that need to be monitored can be run, such as the main thread, the user interaction thread (ui thread), the input and output thread (i / o thread), etc. Watchdog can poll the status of these threads in the system service process in real time. The status of the thread can also be called the task processing status.

[0345] In an embodiment of the present application, the above-mentioned states may include: a second state (or COMPLETED state), a third state (or WATING state), a fourth state (or WAITED_HALF state), a fifth state (or OVERDUE state), and a first state (or WAITED_PERF state).

[0346] When the watchdog polls the status of each thread, for any thread, if the thread is in the COMPLETED state, it means that the thread responds to the task in a timely manner. If the thread is in the WATING state, it means that the thread is processing the task normally. If the thread is in the WAITED_HALF state, it means that the processing time of the current task by the thread exceeds half of the timeout period (or the second detection period). For example, if the preset timeout period is 30 seconds, when the processing time of the current task reaches 15 seconds, the thread enters the WAITED_HALF state. If the thread is in the OVERDUE state, it means that the thread has timed out for task processing. If the thread is in the WAITED_PERF state, it means that the thread is about to time out for the current task processing.

[0347] When the electronic device detects that the state of any thread in the system service process is the WAITED_PERF state, the electronic device may collect SimplePerf logs for the system service process.

[0348] In practice, when Watchdog detects that a thread is in the OVERDUE state, it triggers the system to become unresponsive. If Watchdog does not detect that any thread is in the OVERDUE state, it does not trigger the system to become unresponsive.

[0349] Continue to combine Figure 6B When the electronic device detects that the state of any thread in the system service process is WAITED_PERF, it can send a data collection message to the SimplePerf service management module through Watchdog. The SimplePerf service management module can start the SimplePerf service, and the SimplePerf service collects the SimplePerf log of the application.

[0350] It is understandable that the SimplePerf service can save the collected SimplePerf logs in a preset path, so that users can obtain the SimplePerf logs from the path, and thus effectively and accurately analyze the system unresponsiveness problem in combination with the SimplePerf logs.

[0351] S6012, Watchdog checks the status of the system service process.

[0352] Here, Watchdog can traverse the status of each thread in the system service process.

[0353] As an example, Watchdog can traverse the status of each thread by executing the evaluateCheckerCompletionLocked operation.

[0354] Among them, evaluateCheckerCompletionLocked is a function used to traverse the status of each thread in the Android system.

[0355] S6013, Watchdog obtains the status of the system service process.

[0356] As an example, Watchdog can obtain the status of each thread running in the system service process by executing the getCompletionStateLocked operation.

[0357] In practice, if a thread in a system service process is in the WAITED_PERF state, the system service process is in the WAITED_PERF state.

[0358] If a thread in the system service process is in the OVERDUE state, the system service process is in the OVERDUE state.

[0359] It is understandable that the system service process first appears in the WAITED_PERF state, and then the OVERDUE state may appear.

[0360] S6014: Watchdog sends a data collection message to the SimplePerf service management module when the system service is in the WAITED_PERF state.

[0361] In practice, the data collection message may be: start(args), where start(args) is used to indicate the start of data collection, and args is a collection parameter, which may include collection duration, collection frequency, and the like.

[0362] S6015, the SimplePerf service management module sends a message to the SimplePerf service to instruct it to collect SimplePerf logs.

[0363] In practice, the SimplePerf service management module may start the SimplePerf service upon receiving the above data collection message, and the SimplePerf service may collect the SimplePerf logs of the system service.

[0364] In some optional implementations of the embodiments of the present application, the SimplePerf service management module usually sends a message instructing the SimplePerf service to collect SimplePerf logs when the SimplePerf logs already collected by the electronic device do not exceed the quota.

[0365] S6016, SimplePerf service collects and saves SimplePerf logs.

[0366] Here, the SimplePerf service can collect the SimplePerf log of the application targeted by the input event according to the collection parameters, and save the collected SimplePerf log in a specified path. The above-mentioned specified path is usually a pre-set storage path of the SimplePerf log in the electronic device. It can be understood that the embodiment of the present application does not specifically limit the storage path.

[0367] The following further combines Figure 6C The data collection process for system unresponsiveness in the embodiments of the present application is described. Figure 6C The method flow shown includes at least the following steps:

[0368] S6021, the electronic device starts to execute the data collection process.

[0369] S6022, the electronic device turns on Watchdog and starts detecting the system service process.

[0370] Here, Watchdog detects the status of each thread in the system service process to detect the system service process.

[0371] S6023, the electronic device detects the status of each thread in a polling manner.

[0372] S6024, the electronic device obtains the status of each thread in the system service process.

[0373] Here, the electronic device, specifically the Watchdog in the electronic device, can obtain the status of each detected thread in real time.

[0374] Combination Figure 6C For any thread, the following five situations may occur during the state change of the thread.

[0375] In case 1, if the thread completes the execution of the current task within the timeout period (or referred to as the second detection period), the state of the thread may be switched to the COMPLETED state.

[0376] Scenario 2: If the time difference between the current time and the start processing time of the current task is less than half of the timeout period, the thread is in the WATING state, that is, the thread is in the normal processing of the task. In the embodiment of the present application, the time difference between the current time and the start processing time of the current task can be recorded as the target time difference.

[0377] Case 3: If the target time difference reaches half of the timeout period, the thread state changes from the WATING state to the WAITED_HALF state.

[0378] In case 4, if the target time difference reaches the Perf threshold (or referred to as the first detection duration), the state of the thread is switched from the WAITED_HALF state to the WAITED_PERF state.

[0379] In case 5, if the target time difference reaches the timeout period, the thread state switches from the WAITED_PERF state to the OVERDUE state.

[0380] In an embodiment of the present application, if the state of a thread is COMPLETED, it means that the thread has completed the current task, and the electronic device can continue to detect the processing status of the next task by the thread.

[0381] If the thread state is WATING, it means that the thread is processing the task normally. At this time, the electronic device can continue to detect the processing status of the task by the thread.

[0382] If the thread is in the WAITED_HALF state, it means that the processing time of the thread for the current task exceeds half of the timeout period. At this time, the electronic device can continue to detect the processing status of the thread for the task.

[0383] If the thread is in the WAITED_PERF state, it means that the thread is about to time out for the current task processing. At this time, the electronic device can start collecting the SimplePerf log of the system service process.

[0384] If the thread is in the OVERDUE state, it means that the thread has timed out from processing the task, and the data collection process can be terminated at this time.

[0385] In practice, when a thread in the system service process is in the OVERDUE state, a system response timeout may be triggered, and the electronic device may collect the Trace log of the system service and enter S6026.

[0386] In some application scenarios, when a thread in a system service process is in the OVERDUE state, Watchdog can control the restart of the system service process.

[0387] S6026, the electronic device ends the data collection process.

[0388] Combination FIG. 6A to FIG. 6CIt can be found that in the embodiment of the present application, the electronic device can collect the SimplePerf log of the system service over a period of time before the system service process of the Android system has a system unresponsiveness problem, so as to more accurately locate the root cause of the system unresponsiveness problem and assist R&D personnel to solve the unresponsiveness problem of the system service process in a timely and effective manner.

[0389] Corresponding to the data collection method of the above embodiment, Figure 7 A schematic diagram of the structure of a data acquisition device provided in an embodiment of the present application is shown. For ease of explanation, only the parts related to the embodiment of the present application are shown.

[0390] Reference Figure 7 , the data acquisition device comprises:

[0391] The first determining unit 701 is used to detect the processing time of the first task by the first software program; based on the second detection time, determine the first detection time corresponding to the first task, wherein the second detection time is the timeout response time corresponding to the first task, and the first detection time is less than the second detection time;

[0392] The second determining unit 702 is used to collect data from the first moment to the second moment when the processing duration meets the preset condition, and obtain a first type of log, where the first type of log is a log of the first software program from the first moment to the second moment;

[0393] The first moment is the moment when the processing time is equal to the first detection time, and the second moment is the moment when the processing time is equal to the second detection time.

[0394] As an embodiment of the present application, the data acquisition device can implement the following Figure 1-6C The illustrated embodiments and other related method embodiments.

[0395] The process of each module in the data acquisition device provided in the embodiment of the present application realizing its own function can be specifically referred to the aforementioned Figure 1-6C The description of the illustrated embodiment and other related method embodiments will not be repeated here.

[0396] It should be noted that the information interaction, execution process, etc. between the above-mentioned devices / units are based on the same concept as the method embodiment of the present application. Their specific functions and technical effects can be found in the method embodiment part and will not be repeated here.

[0397] It should be understood that the size of the serial numbers of the steps in the above embodiments does not mean the order of execution. The execution order of each process should be determined by its function and internal logic, and should not constitute any limitation on the implementation process of the embodiments of the present application.

[0398] It should be understood that when used in the present specification and the appended claims, the term "comprising" indicates the presence of described features, wholes, steps, operations, elements and / or components, but does not exclude the presence or addition of one or more other features, wholes, steps, operations, elements, components and / or combinations thereof.

[0399] It should also be understood that the term “and / or” used in the specification and appended claims refers to any and all possible combinations of one or more of the associated listed items, and includes these combinations.

[0400] As used in the specification and appended claims of this application, the term "if" can be interpreted as "when" or "uponce" or "in response to determining" or "in response to detecting", depending on the context. Similarly, the phrase "if it is determined" or "if [described condition or event] is detected" can be interpreted as meaning "uponce it is determined" or "in response to determining" or "uponce [described condition or event] is detected" or "in response to detecting [described condition or event]", depending on the context.

[0401] In addition, in the description of the present specification and the appended claims, the terms "first", "second", "third", etc. are only used to distinguish descriptions and should not be understood as indicating or implying relative importance. It should also be understood that although the terms "first", "second", etc. are used in the text to describe various elements in some embodiments of the present application, these elements should not be limited by these terms. These terms are only used to distinguish one element from another element.

[0402] References to "one embodiment" or "some embodiments" etc. described in the specification of this application mean that one or more embodiments of the present application include specific features, structures or characteristics described in conjunction with the embodiment. Therefore, the statements "in one embodiment", "in some embodiments", "in some other embodiments", "in some other embodiments", etc. that appear in different places in this specification do not necessarily refer to the same embodiment, but mean "one or more but not all embodiments", unless otherwise specifically emphasized in other ways. The terms "including", "comprising", "having" and their variations all mean "including but not limited to", unless otherwise specifically emphasized in other ways.

[0403] The data collection method provided in the embodiment of the present application can be applied to electronic devices, such as tablet computers, mobile phones, wearable devices, laptop computers, ultra-mobile personal computers (UMPCs), netbooks, personal digital assistants (PDAs), etc. The embodiment of the present application does not limit the specific type of electronic devices.

[0404] The hardware structure of the electronic device is described in detail below with reference to the accompanying drawings.

[0405] Figure 8 It is a schematic diagram of the hardware structure of an electronic device provided in one embodiment of the present application.

[0406] The electronic device may include a processor 110, an external memory interface 120, an internal memory 121, a universal serial bus (USB) interface 130, a charging management module 140, a power management module 141, a battery 142, an antenna 1, an antenna 2, a mobile communication module 150, a wireless communication module 160, an audio module 170, a sensor module 180, a button 190, a camera 193, a touch screen 194, and a SIM card interface 195, etc.

[0407] The audio module 170 may include a speaker and a microphone, etc.

[0408] Among them, the sensor module 180 may include a pressure sensor, an inertial sensor, a distance sensor, a proximity light sensor, a fingerprint sensor, a touch sensor, and an ambient light sensor (of course, the electronic device may also include other sensors, such as a temperature sensor, a bone conduction sensor, etc., which are not shown in the figure).

[0409] The processor 110 may include one or more processing units, for example, the processor 110 may include an application processor (application processor, AP), a modem processor, a graphics processor (graphics processing unit, GPU), an image signal processor (image signal processor, ISP), a controller, a memory, a video codec, a digital signal processor (digital signal processor, DSP), a baseband processor, and / or a neural network processor (Neural-network Processing Unit, NPU), etc. Among them, different processing units can be independent devices or integrated in one or more processors. Among them, the controller can be the nerve center and command center of the electronic device. The controller can generate an operation control signal according to the instruction operation code and the timing signal to complete the control of fetching and executing instructions.

[0410] The processor 110 may also be provided with a memory for storing instructions and data. In some embodiments, the memory in the processor 110 is a cache memory. The memory may store instructions or data that the processor 110 has just used or cyclically used. If the processor 110 needs to use the instruction or data again, it may be directly called from the memory. This avoids repeated access, reduces the waiting time of the processor 110, and thus improves the efficiency of the system.

[0411] The processor 110 can run the data acquisition method provided in the embodiment of the present application. The processor 110 can include different devices. For example, when a CPU and a GPU are integrated, the CPU and the GPU can cooperate to execute the data acquisition method provided in the embodiment of the present application. For example, part of the algorithm in the data acquisition method is executed by the CPU, and another part of the algorithm is executed by the GPU to obtain faster processing efficiency.

[0412] It should be understood that the illustrated electronic device is merely an example, and the electronic device may have more or fewer components than shown in the figures, may combine two or more components, or may have a different configuration of components.

[0413] In addition, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0414] An embodiment of the present application also provides an electronic device, which includes at least one memory, at least one processor, and a computer program stored in the at least one memory and executable on the at least one processor. When the processor executes the computer program, the electronic device implements the steps of any of the above-mentioned method embodiments.

[0415] In addition, those skilled in the art can clearly understand that for the convenience and simplicity of description, only the division of the above-mentioned functional units and modules is used as an example. In actual applications, the above-mentioned functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units in each embodiment of the present application can be integrated into a processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The above-mentioned integrated unit can be implemented in the form of hardware or in the form of software functional units.

[0416] The embodiment of the present application further provides a computer-readable storage medium, which stores a computer program. When the computer program is executed by a processor, the steps in the above-mentioned method embodiments can be implemented.

[0417] An embodiment of the present application provides a computer program product. When the computer program product runs on an electronic device, the electronic device can implement the steps in the above-mentioned method embodiments when executing the computer program product.

[0418] An embodiment of the present application also provides a chip system, which includes a processor, the processor is coupled to a memory, and the processor executes a computer program stored in the memory to implement the steps in the above-mentioned method embodiments.

[0419] If the integrated module / unit is implemented in the form of a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the present application implements all or part of the processes in the above-mentioned embodiment method, and can also be completed by instructing the relevant hardware through a computer program. The computer program can be stored in a computer-readable storage medium, and the computer program can implement the steps of the above-mentioned various method embodiments when executed by the processor. Among them, the computer program includes computer program code, and the computer program code can be in source code form, object code form, executable file or some intermediate form. Computer-readable storage media may include: any entity or device that can carry computer program code, recording medium, U disk, mobile hard disk, disk, optical disk, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signal, telecommunication signal and software distribution medium, etc.

[0420] In the above embodiments, the description of each embodiment has its own emphasis. For parts that are not described or recorded in detail in a certain embodiment, reference can be made to the relevant descriptions of other embodiments.

[0421] Those of ordinary skill in the art will appreciate that the units and algorithm steps of each example described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are performed in hardware or software depends on the specific application and design constraints of the technical solution. Professional and technical personnel can use different methods to implement the described functions for each specific application, but such implementation should not be considered to be beyond the scope of this application.

[0422] The units described as separate components may or may not be physically separated, and the components shown as units may or may not be physical units, that is, they may be located in one place or distributed on multiple network units. Some or all of the units may be selected according to actual needs to achieve the purpose of the solution of this embodiment.

[0423] The above embodiments are only used to illustrate the technical solutions of the present application, rather than to limit them. Although the present application has been described in detail with reference to the aforementioned embodiments, those skilled in the art should understand that they can still modify the technical solutions described in the aforementioned embodiments, or make equivalent replacements for some of the technical features therein. These modifications or replacements do not deviate the essence of the corresponding technical solutions from the spirit and scope of the technical solutions of the embodiments of the present application, and should all be included in the protection scope of the present application.

Claims

1. A data collection method, It is characterized in that Applied to electronic equipment, the method comprises: The electronic device detects a processing time of the first task by the first software program; Based on the second detection duration, determining a first detection duration corresponding to the first task, wherein the second detection duration is a timeout response duration corresponding to the first task, and the first detection duration is less than the second detection duration; When the first software program is a system service process, and the execution time of the first task by any first thread to be detected in the system service process is equal to the first detection time, updating the task processing state of the first thread to a first state, wherein the first state indicates collecting a first type of log; The electronic device detects whether the processing duration meets a preset condition through a watchdog service, and the watchdog service runs in the system service process; wherein the detection process of the watchdog service includes: traversing the task processing status of each first thread to be detected in the system service process; when a first thread whose task processing status is a first state is detected, determining that the processing duration meets the preset condition; When the processing time meets a preset condition, starting collection from the first moment to the second moment, obtaining a first type of log, wherein the first type of log is a log of the first software program from the first moment to the second moment; The first moment is the moment when the processing duration is equal to the first detection duration, and the second moment is the moment when the processing duration is equal to the second detection duration.

2. The data collection method according to claim 1, It is characterized in that The method further comprises: When the first thread starts to execute the first task, determining the task processing state of the first thread as a third state, wherein the third state indicates that the task is executed normally; When the execution time of the first task by the first thread is equal to half of the second detection time, updating the task processing state of the first thread to a fourth state, wherein the fourth state indicates that the processing time of the task reaches half of the timeout response time; When the execution time of the first task by the first thread is equal to the second detection time, updating the task processing state of the first thread to a fifth state, wherein the fifth state indicates a response timeout; When the first thread completes processing the first task, the task processing state of the first thread is updated to a second state, where the second state indicates that the task execution is completed.

3. The data collection method according to claim 1, It is characterized in that When the first software program is a first application program and the first task is to respond to a first input event for the first application program, the electronic device detects, through an input distribution module, whether the processing duration meets a preset condition; The detection process of the input distribution module includes: When instruction information for instructing to distribute the first input event is received, distributing the first input event to the first application corresponding to the first input event; In the case where first feedback information returned by the first application program in response to the first input event is not received, determining a first duration, where the first duration is used to represent a time interval between the issuance of the first input event and the current time, wherein the first feedback information indicates that the first application program has completed responding to the input event; When the first duration is equal to the first detection duration, it is determined that the processing duration meets a preset condition.

4. The data collection method according to claim 1, It is characterized in that When the first software program is a second application program and the first task is to start a first service component called by the second application program, the electronic device detects, through an active service management module, whether the processing duration meets a preset condition; The detection process of the active service management module includes: When receiving instruction information for instructing to start the first service component, starting the first service component; Writing a first scheduled message to a target message queue, wherein the first scheduled message includes a first message content and the first detection duration, wherein the target message queue sends a second feedback message to the active service management module when the timing of the first scheduled message reaches the first detection duration, wherein the second feedback message indicates that the first detection duration has been reached; When the second feedback information returned by the target message queue is received, it is determined that the processing duration meets a preset condition.

5. The data collection method according to claim 4, It is characterized in that Writing the first timed message to the target message queue includes: Write the first scheduled message and the second scheduled message to the target message queue; The second timed message includes the second message content and the second detection duration. When the timing of the second timed message reaches the second detection duration, the target message queue sends a third feedback message to the active service management module, and the third feedback message indicates that a timeout has been initiated for the first service component.

6. The data collection method according to claim 5, It is characterized in that The detection process of the active service management module further includes: In a case where the second feedback information is not received and it is detected that the first service component is successfully started, the first scheduled message and the second scheduled message in the target message queue are removed.

7. The data collection method according to claim 1, It is characterized in that When the first software program is a third application program and the first task is to broadcast a first broadcast message of the third application program, the electronic device detects, through a broadcast message management module, whether the processing duration meets a preset condition; The detection process of the broadcast message management module includes: When receiving instruction information indicating sending the first broadcast message, sending the first broadcast message to broadcast receivers of the first broadcast message; Writing a third timed message to a target message queue, wherein the third timed message includes a third message content and the first detection duration, wherein when the timing of the third timed message reaches the first detection duration, the target message queue sends fourth feedback information to the broadcast message management module, wherein the fourth feedback information indicates that the first detection duration has been reached; When the fourth feedback information sent by the target message queue is received, it is determined that the processing duration meets a preset condition.

8. The data collection method according to claim 7, It is characterized in that Writing the third timing message to the target message queue includes: Writing the third scheduled message and the fourth scheduled message into the target message queue; Among them, the fourth timed message includes the fourth message content and the second detection duration. When the timing of the fourth timed message reaches the second detection duration, the target message queue sends fifth feedback information to the broadcast message management module, and the fifth feedback information indicates that the broadcast of the first broadcast message has timed out.

9. The data collection method according to claim 8, It is characterized in that The detection process of the broadcast message management module also includes: In the case where the fourth feedback information is not received and the sixth feedback information sent by the broadcast receiver is received, the third scheduled message and the fourth scheduled message in the target message queue are removed, and the sixth feedback information indicates that the broadcast receiver successfully receives the first broadcast message.

10. The data collection method according to claim 1, It is characterized in that The first detection duration is positively correlated with the second detection duration.

11. The data collection method according to claim 1, It is characterized in that The method further comprises: When the processing time of the first software program on the first task is equal to the second detection time, collecting a second type of log of the first software program; The first type of log is different from the second type of log. The second type of log is running snapshot data of the first software program, and the first type of log is running process data of the first software program.

12. The data collection method according to claim 1, It is characterized in that The application framework layer of the electronic device includes a first management module and a first service; When the processing time meets the preset condition, the first type of log is obtained from the first moment to the second moment, including: When the processing duration meets the preset condition, the target module sends first indication information to the first management module, wherein the first indication information indicates to collect the first type of log from the first moment to the second moment, wherein the target module includes any one of the following: a watchdog service, an input distribution module, an active service management module, and a broadcast message management module; The first management module sends second indication information to the first service, where the second indication information indicates to collect the first type of logs from the first moment to the second moment; The first service collects the first type of log based on the second indication information.

13. The data collection method according to any one of claims 1 to 12, It is characterized in that The first type of log is a SimplePerf log, and the second type of log is a Trace log.

14. The data collection method according to any one of claims 1 to 12, It is characterized in that The method further comprises: A first problem is analyzed based on the first type of log, where the first problem is a timeout in response of the first software program to the first task.

15. An electronic device, It is characterized in that The electronic device includes a memory and a processor. The memory stores a computer program that can be run on the processor. When the processor executes the computer program, the data collection method according to any one of claims 1 to 14 is implemented.

Citation Information

Patent Citations

  • Method and device for monitoring interface jamming

    CN106776253A

  • Method and device for detecting blocking

    CN109074303A

  • Log data acquisition management method and system, storage medium and electronic equipment

    CN115269516A

  • Application program monitoring method and device and readable storage medium

    CN117271260A