Application unresponsive analysis method and apparatus, electronic device, and storage medium

By obtaining the iowait difference and duration relationship of the target process of the application, the cause of ANR can be quickly identified, which solves the problem of time-consuming ANR analysis in the existing technology and realizes efficient ANR cause determination.

CN115437816BActive Publication Date: 2026-04-24BEIJING CO WHEELS TECH CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
BEIJING CO WHEELS TECH CO LTD
Filing Date
2022-03-25
Publication Date
2026-04-24

AI Technical Summary

Technical Problem

Existing technologies rely on experience and log inference when analyzing the causes of application unresponsiveness (ANR), which is time-consuming and inefficient, and makes it difficult to quickly distinguish between the application's own business time consumption and the responsibility of system resource pressure.

Method used

By obtaining the difference and duration of iowait in different locations of the application's target process, the cause of ANR can be quickly determined, including whether the difference is greater than a multiple of the duration threshold, indicating business time consumption, or whether system resource constraints are present.

Benefits of technology

It simplifies the ANR cause analysis process, reduces development time, and improves analysis efficiency, especially when ANR is caused by system resource constraints, it can reduce analysis time by 99%.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN115437816B_ABST
    Figure CN115437816B_ABST
Patent Text Reader

Abstract

The application relates to an application program non-response analysis method and device, electronic equipment and a storage medium. The method comprises the following steps: obtaining a first iowait when a target process of an application program runs to a first position and a second iowait when the target process runs to a second position; in the case that an ANR occurs in the running process of the target process, the cause of the ANR is determined to be self business time consumption of the application program or system resource shortage based on the relationship between a first difference value and a first time length; wherein the difference between the time when the ANR occurs and the time corresponding to the second position is less than or equal to a time length threshold value, the first difference value is the difference between the second iowait and the first iowait, and the first time length is the actual time length consumed by the target process from running to the first position to running to the second position. The method can simplify the analysis process of the ANR cause, reduce the research and development analysis time, and improve the analysis efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This application relates to the field of terminal technology, and in particular to a method, apparatus, electronic device, and storage medium for analyzing application unresponsiveness. Background Technology

[0002] An Application Not Responding (ANR) occurs when an application is blocked on the User Interface (UI) thread for too long. When an ANR occurs, the system typically displays a message informing the user that the application is blocked and asking whether to continue waiting for a response or close the application.

[0003] Currently, when an application process experiences an ANR (Application Not Responding) error during runtime, the system server dumps a snapshot of that process. This snapshot includes information such as CPU usage at the time of the ANR, Unified Threat Management (UTM) information, and thread stacks. However, the snapshot only provides the process's running state at the time of the ANR; it doesn't determine whether the failure was due to application-specific business logic or system resource constraints. Further analysis using ANR logs and code troubleshooting is necessary to pinpoint the exact cause. Therefore, current methods for analyzing ANR causes rely heavily on experience or speculation. This requires significant experience in handling ANR issues, a deep understanding of the business logic, and the time-consuming verification process involved in confirming these speculations.

[0004] Therefore, existing solutions for analyzing the causes of ANR (Application Not Responding) place high demands on business personnel, and the analysis process is time-consuming and inefficient. Summary of the Invention

[0005] This application provides a method, apparatus, electronic device, and storage medium for analyzing application unresponsiveness.

[0006] In a first aspect, this application provides a method for analyzing application non-response, comprising: obtaining a first iowait when the target process of the application runs to a first position and a second iowait when the target process runs to a second position; in the event of an ANR during the operation of the target process, determining, based on the relationship between a first difference and a first duration, that the cause of the ANR is the application's own business time consumption or system resource shortage; wherein, the difference between the time when the ANR occurs and the time corresponding to the second position is less than or equal to a duration threshold, the first difference is the difference between the second iowait and the first iowait, and the first duration is the actual time consumed by the target process from running to the first position to running to the second position.

[0007] Optionally, when an ANR occurs during the operation of the target process, the cause of the ANR is determined based on the relationship between the first difference and the first duration, including: when the first difference is greater than a preset multiple of the first duration, the cause of the ANR is determined to be the service time consumption of the application itself, where the preset multiple is greater than 0 and less than 1; when the first difference is less than or equal to the preset multiple of the first duration, the cause of the ANR is determined to be system resource shortage.

[0008] Optionally, the preset multiple is greater than or equal to one-tenth and less than or equal to one-third.

[0009] Optionally, the application's own business time consumption includes any of the following situations: the application's main thread frequently performs time-consuming read and write file operations; deadlock in multi-threaded operations, including the main thread; the main thread is blocked by the client-server communication tool; system resource shortage includes any of the following situations: the watchdog timer in the system server experiences an ANR; the connection limit of the server-side client-server communication tool is reached, causing the client to be unable to communicate with the system server; system resources are exhausted.

[0010] Optionally, obtaining the first iowait when the target process of the application runs to the first position and the second iowait when the target process runs to the second position includes: during the operation of the target process, obtaining the iowait at the corresponding position once at a preset time interval, the preset time interval being less than or equal to the time threshold; obtaining the first iowait and the second iowait from the plurality of iowaits, wherein the second iowait is the largest one among the plurality of iowaits.

[0011] Optionally, obtaining the first iowait when the target process of the application runs to the first position includes: obtaining a first snapshot of the first position, the first snapshot including the first iowait; and obtaining the first iowait from the first snapshot.

[0012] Optionally, obtaining the second iowait when the target process runs to the second position includes: obtaining a second snapshot of the second position, the second snapshot including the second iowait; and obtaining the second iowait from the second snapshot.

[0013] Optionally, the first position is the position when the target process starts; the second position is the position of the target process when the ANR occurs.

[0014] Optionally, the target process includes any of the following: a broadcast message processing process, a touch and click process, a system service startup process, or a content provider process.

[0015] Secondly, this application provides an application non-response analysis device, including: an acquisition module and a determination module; the acquisition module is used to acquire a first iowait when the target process of the application runs to a first position and a second iowait when the target process runs to a second position; the determination module is used to determine, in the event of an ANR during the operation of the target process, based on the relationship between a first difference and a first duration, that the cause of the ANR is the application's own business time consumption or system resource shortage; wherein, the difference between the time when the ANR occurs and the time corresponding to the second position is less than or equal to a duration threshold, the first difference is the difference between the second iowait acquired by the acquisition module and the first iowait acquired by the acquisition module, and the first duration is the actual time consumed by the target process from running to the first position to running to the second position.

[0016] Optionally, the determining modulus is specifically used to determine the cause of the ANR as the application's own business time consumption when the first difference is greater than a preset multiple of the first duration, where the preset multiple is greater than 0 and less than 1; and to determine the cause of the ANR as system resource shortage when the first difference is less than or equal to the preset multiple of the first duration.

[0017] Optionally, the preset multiple is greater than or equal to one-tenth and less than or equal to one-third.

[0018] Optionally, the application's own business time consumption includes any of the following situations: the application's main thread frequently performs time-consuming read and write file operations; deadlock in multi-threaded operations, including the main thread; the main thread is blocked by the client-server communication tool; system resource shortage includes any of the following situations: the watchdog timer in the system server experiences an ANR; the connection limit of the server-side client-server communication tool is reached, causing the client to be unable to communicate with the system server; system resources are exhausted.

[0019] Optionally, the acquisition module is specifically used to acquire the iowait at the corresponding position once at a preset time interval during the operation of the target process, the preset time interval being less than or equal to the time threshold; and to acquire the first iowait and the second iowait from the plurality of iowaits, wherein the second iowait is the largest one among the plurality of iowaits.

[0020] Optionally, the acquisition module is specifically used to acquire a first snapshot of a first location, the first snapshot including a first iowait; and to acquire the first iowait from the first snapshot.

[0021] Optionally, the acquisition module is specifically used to acquire a second snapshot of the second location, the second snapshot including the second iowait; and to acquire the second iowait from the second snapshot.

[0022] Optionally, the first position is the position when the target process starts; the second position is the position of the target process when the ANR occurs.

[0023] Optionally, the target process includes any of the following: a broadcast message processing process, a touch and click process, a system service startup process, or a content provider process.

[0024] Thirdly, this application provides an electronic device, including: a processor, the processor being configured to execute a computer program stored in a memory, the computer program being executed by the processor to implement the steps of any of the application unresponsive analysis methods provided in the first aspect.

[0025] Fourthly, this application provides a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of any of the application unresponsiveness analysis methods provided in the first aspect.

[0026] A fifth aspect of this application provides a computer program product, wherein the computer program product includes a computer program or instructions, and when the computer program product is run on a processor, the processor executes the computer program or instructions to implement the steps of the application unresponsive analysis method as described in the first aspect.

[0027] A sixth aspect of this application provides a chip including a processor, a memory, and a communication interface coupled to the processor. The memory stores a program or instructions that can run on the processor, and the processor executes the program or instructions to implement the steps of the application unresponsive analysis method as described in the first aspect.

[0028] Compared with the prior art, the technical solution provided in this application has the following advantages: In this application embodiment, by obtaining the first iowait when the target process of the application runs to the first position and the second iowait when the target process runs to the second position; in the case of ANR during the operation of the target process, based on the relationship between the first difference (the difference between the second iowait and the first iowait) and the first duration (the actual time consumed by the target process from running to the second position), the cause of the ANR is determined to be either the application's own business time consumption or system resource constraints, wherein the difference between the time of ANR occurrence and the time corresponding to the second position is less than or equal to the duration threshold. Therefore, this solution can further analyze the specific cause of ANR from the perspective of the application's own business time consumption, without first excluding various reasons due to system resource constraints, and then further analyze the specific cause of ANR from the perspective of the application's own business time consumption; or, this solution can further analyze the specific cause of ANR from the perspective of system resource constraints, without first excluding various reasons due to the application's own business time consumption, and then further analyze the specific cause of ANR from the perspective of system resource constraints. Compared to existing technologies, this solution directly analyzes and eliminates specific causes of ANR (various reasons related to system resource constraints and various reasons related to application business time consumption) through logs and code, which simplifies the analysis process, reduces development analysis time, and improves analysis efficiency. Attached Figure Description

[0029] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this application and, together with the description, serve to explain the principles of this application.

[0030] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, for those skilled in the art, other drawings can be obtained based on these drawings without creative effort.

[0031] Figure 1 A flowchart illustrating an application non-response analysis method provided in this application;

[0032] Figure 2 A flowchart illustrating another application non-response analysis method provided in this application;

[0033] Figure 3 A schematic diagram illustrating a deadlock in a multi-threaded operation provided in this application;

[0034] Figure 4A schematic diagram illustrating how to handle an ANR (Application Not Responding) event in a broadcast process and obtain iowait, as provided in this application;

[0035] Figure 5 A schematic diagram of the structure of an application no-response analysis device provided in this application;

[0036] Figure 6 This is a schematic diagram of the hardware structure of an electronic device provided in this application. Detailed Implementation

[0037] To better understand the above-mentioned objectives, features, and advantages of this application, the solution of this application will be further described below. It should be noted that, unless otherwise specified, the embodiments and features described in these embodiments can be combined with each other.

[0038] Many specific details are set forth in the following description in order to provide a full understanding of this application, but this application may also be implemented in other ways different from those described herein; obviously, the embodiments in the specification are only some embodiments of this application, and not all embodiments.

[0039] The terms "first," "second," etc., used in the specification and claims of this application are used to distinguish similar objects and are not used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that embodiments of this application can be implemented in orders other than those illustrated or described herein, and the objects distinguished by "first," "second," etc., are generally of the same class and are not limited in number; for example, a first object can be one or more.

[0040] The following is an explanation of some of the terms or concepts used in the claims and description of this invention.

[0041] Io: refers to file read and write operations.

[0042] iowait: Cumulative file read / write operation time. This refers to the time the system spends reading and writing files, resulting in no other processes being active and the CPU running idle processes (process 0).

[0043] System_server: System service, responsible for display, application installation, application scheduling, etc., can be simply understood as the system.

[0044] Broadcast: A communication method of the system. After an application sends a broadcast, it is processed by the system_server and then forwarded to the receiving application.

[0045] Snapshot: Refers to the state data of an application when an ANR occurs, including information such as the runtime stack and system resource usage.

[0046] Binder is a general inter-process communication technology provided by the Android system. It is a tool used by clients and services in Android to communicate.

[0047] ContentProvider is one of the four major components in Android, a class used to store or retrieve data.

[0048] Most existing solutions for analyzing ANR causes suffer from poor stability and consistently face challenges such as unclear responsibility for application-specific business logic delays and system resource constraints, making it difficult to pinpoint system problems. While adding logs can quickly identify whether ANR is caused by application-specific business logic delays or system resource constraints, this approach is problematic because systems handle numerous functions (making system problem localization difficult) and are affected by various factors. Different applications can also influence each other due to system resource issues. Dumping all information would not only consume log resources but also significantly impact performance.

[0049] The following example illustrates the process of analyzing the causes of ANR after it occurs:

[0050] First, examine the event log (events_log) under the mobile log folder. Search for the keyword "am_anr" in the event_log to find the time point of the ANR occurrence, the process identifier (PID), and the ANR type. Let's assume we can see from the event_log that the ANR occurred at 07-2015:36:36.472, the process PID is 1480, the process name is com.xxxx.mobile, and the ANR type is KeyDispatchTimeout. We know that KeyDispatchTimeout ANRs occur because input events are not processed within 5 seconds. So, what did the program do in the 5 seconds before 07-20 15:36:36, that is, between 15:36:30 and 15:36:35? Since we already know the process PID, we can further search the logs for PID = 1480. These logs represent the process's execution path. Assuming the logs for PID 1480 show that the program received an action message at 15:36:29 on 07-20, we can conclude that the blocking was caused by the application com.xxxx.moblie receiving a push message (com.ttt.push.RECEIVE_MESSAGE). Connecting the dots: at 15:36:29 on 07-20, the application com.xxxx.moblie received a push message (action=com.ttt.push.RECEIVE_MESSAGE), causing the blocking, and a KeyDispatchTimeout ANR occurred 5 seconds later. While we know how it started, the specific cause is still unknown. Could it be due to CPU strain or application developers competing for resources? Therefore, we search for the keyword "ANR IN" to examine CPU information. Assuming com.xxxx.moblie is using 11% of the CPU, given that most modern electronic devices use multi-core CPUs... If your electronic device has a 4-core CPU, the limit is 400%, and so on. Therefore, using 11% of the CPU is not much, so it is not due to CPU strain or application programmers competing for resources that caused the ANR.Since it's not due to CPU load, what could be the cause? Next, we need to analyze the traces.txt logs. When an application becomes unresponsive, responds slowly, or the watchdog timer doesn't respond, the system dumps a traces.txt file located in the directory: / data / anr / traces.txt. Through the traces file, we can obtain information such as the thread name, stack trace, current thread state, and Binder call details. This traces file can be obtained using the adb command. The stack trace is of most interest to us, as it can pinpoint the exact location. From the traces file, we can determine that ttt.push.InterceptorProxy.addMiuiApplicationInterceptorProxy.java:77 caused com.xxxx.mobile to experience an ANR. We can then examine the source code to find the problem and resolve it.

[0051] To summarize the above analysis process for identifying ANR causes: First, search for `am_anr` to find the time point when the ANR occurred, the process PID, and the ANR type. Then, search for the PID again, looking for logs from approximately the previous 5 seconds. Filter for ANR IN messages to examine CPU information. Next, check `traces.txt` to find the Java stack trace to locate the code location. Finally, examine the source code to analyze and resolve the issue. This process can generally reveal the cause and effect of the ANR. Therefore, the above process requires examining logs and code, using experience or inference to rule out other causes, and finally determining the cause. This process is complex and time-consuming, resulting in low efficiency in analyzing ANR causes.

[0052] To address the aforementioned issues, this application provides a method for analyzing application non-responsiveness (ANR). This method obtains the first iowait time (IOWAT) when the target process of the application reaches a first position and the second iowait time (IOWAT) when the target process reaches a second position. If an ANR occurs during the execution of the target process, based on the relationship between a first difference (the difference between the second iowait and the first iowait) and a first duration (the actual time consumed by the target process from reaching the first position to the second position), the method determines that the cause of the ANR is either the application's own business processing time or system resource constraints. The difference between the time of the ANR occurrence and the time corresponding to the second position is less than or equal to a duration threshold. Therefore, this solution can further analyze the specific cause of the ANR from the perspective of the application's own business processing time, without first eliminating various causes related to system resource constraints; or, this solution can further analyze the specific cause of the ANR from the perspective of system resource constraints, without first eliminating various causes related to the application's own business processing time, and then further analyze the specific cause of the ANR from the perspective of system resource constraints. Compared to existing technologies, this solution directly analyzes and eliminates specific causes of ANR (various reasons related to system resource constraints and various reasons related to application business time consumption) through logs and code, which simplifies the analysis process, reduces development analysis time, and improves analysis efficiency.

[0053] This solution can use minimal resource consumption by simply obtaining the iowait values ​​at two points during the target process's execution. Then, based on the difference between the two iowait values ​​and the relationship between the actual duration of those two points, it can quickly determine whether the application's own business logic is causing the delay or whether the application is in a state of waiting for io due to system resource constraints (high io). This greatly simplifies the ANR problem analysis and resolution process.

[0054] This application is applied to scenarios where ANR occurs and the cause of ANR is analyzed. The electronic devices in the embodiments of this application can be mobile phones, tablets, laptops, handheld computers, in-vehicle electronic devices, wearable devices, personal computers (PCs), televisions (TVs), ATMs, or self-service machines, etc. The specific devices can be determined according to the actual situation and are not limited here.

[0055] The application unresponsiveness analysis method provided in this embodiment of the invention can be applied to electronic devices with an operating system. This operating system can be Android, iOS, or other possible operating systems; this embodiment of the invention does not specifically limit the application's functionality.

[0056] The technical solution of this application will be explained in detail below through several specific embodiments.

[0057] Figure 1 This application provides a flowchart illustrating an application unresponsiveness analysis method. This method can be executed by an application unresponsiveness analysis device, which can be implemented in software and / or hardware and integrated into any computing-capable electronic device or server. Figure 1 As shown, the application's non-response analysis method may include the following steps 101 to 102:

[0058] 101. Obtain the first iowait when the target process of the application reaches the first position and the second iowait when the target process reaches the second position.

[0059] Specifically, the difference between the time when ANR occurs and the time corresponding to the second position is less than or equal to the duration threshold. The duration threshold is a statistically determined maximum duration that ensures the accuracy of ANR cause analysis when an application experiences ANR. The duration threshold can be determined based on actual circumstances and is not limited here.

[0060] It is understood that in the embodiments of this application, the specific positions of the first position and the second position in the running process of the target process are not limited. The specific positions can be determined according to the actual situation, and are not limited here.

[0061] Optionally, the first position is the position at which the target process starts.

[0062] Optionally, the second position is the position of the target process when the ANR occurs.

[0063] In this embodiment, the first position is the position when the target process starts, and the second position is the position of the target process when the ANR occurs. This reduces the software modification and development pressure, and allows for better control over the time of obtaining the first iowait and the second iowait. It also ensures the accuracy of analyzing the cause of ANR when the application experiences an ANR.

[0064] Optionally, step 101 above can be implemented through steps 11 and 12 below.

[0065] 11. During the execution of the target process, the iowait at the corresponding position is obtained once at a preset time interval, so as to obtain multiple iowaits before the ANR.

[0066] 12. Obtain the first iowait and the second iowait from the multiple iowaits.

[0067] The preset duration is less than or equal to the duration threshold. The preset duration can be determined according to the actual situation, and this application embodiment does not limit it.

[0068] in,

[0069] The second iowait is the largest among the multiple iowait values. The first iowait can be any one of the multiple values ​​except the largest one; the specific value can be determined based on the actual situation and is not limited here.

[0070] For example, the first iowait can be the smallest of the plurality of iowaits.

[0071] It is understandable that during the execution of the target process, the iowait at the corresponding position can be obtained periodically (at a preset interval). Then, when an ANR occurs, the first iowait and the second iowait are obtained from these multiple iowaits. Usually, the last iowait obtained (i.e. the largest iowait) is determined as the second iowait. This can ensure the accuracy of the analysis of the cause of ANR when the application experiences an ANR as much as possible.

[0072] 102. In the event of an ANR during the execution of the target process, based on the relationship between the first difference and the first duration, the cause of the ANR is determined to be either the application's own business time consumption or system resource shortage.

[0073] The first difference is the difference between the second iowait and the first iowait, and the first duration is the actual duration (i.e., the total duration) consumed by the target process from running to the first position to running to the second position.

[0074] The duration threshold can be determined based on the actual situation and is not limited here.

[0075] It can be understood that the first difference is the time required for I / O (read and write file operations) during the process of the target process running from the first position to the second position, and the first duration is the total time consumed by the target process running from the first position to the second position. Combining the relationship between the first difference and the first duration, it can be determined whether the cause of the ANR is the application's own business time consumption or the cause of the ANR is the system resource shortage.

[0076] In this embodiment, the specific causes of ANR can be further analyzed from the perspective of the application's own business processing time, without first eliminating various reasons related to system resource constraints before further analyzing the specific causes of ANR from the perspective of the application's own business processing time; or, the specific causes of ANR can be further analyzed from the perspective of system resource constraints, without first eliminating various reasons related to the application's own business processing time before further analyzing the specific causes of ANR from the perspective of system resource constraints. Compared with the prior art, which directly eliminates and analyzes the specific causes of ANR (various reasons related to system resource constraints and various reasons related to the application's own business processing time) one by one through logs and code, this solution simplifies the analysis process, reduces development analysis time, and improves analysis efficiency.

[0077] Optionally, the target process may include any of the following: a broadcast message processing process, a touch and click process, a system service startup process, or a content provider process. The target process may also include other processes, which can be determined based on the actual situation and are not limited here.

[0078] The ANR handling mechanism for broadcast messages is BroadcastTimeout. An ANR can occur if the foreground BroadcastonReceiver fails to complete processing within 10 seconds, or if the background BroadcastonReceiver fails to complete processing within 60 seconds.

[0079] Among them, the ANR in touch and click processes is KeyDispatchTimeout (common), which specifically occurs when an input event is not processed within 5 seconds.

[0080] The ANR (Application Not Responding) for system service startup processes is ServiceTimeout. This can occur if a foreground service's onCreate, onStart, or onBind lifecycle events fail to complete within 20 seconds; or if a background service's onCreate, onStart, or onBind lifecycle events fail to complete within 200 seconds.

[0081] Among them, the content provider process can be ContentProviderTimeout, specifically, if the ContentProvider fails to complete processing within 10 seconds and an ANR occurs.

[0082] The content provider, also known as the data storage or retrieval component, can be the content provider in Android or a component with similar functionality in other systems. The specific choice depends on the actual situation and is not limited here.

[0083] This application provides various scenarios for ANR (Application Not Responding) of target processes. The application non-response analysis method provided in this application can be applied to scenarios where ANR causes of various target processes are analyzed, which can simplify the analysis process and improve analysis efficiency.

[0084] Optionally, obtaining the first iowait in step 101 above can be achieved through steps 101a and 101b below.

[0085] 101a. Obtain the first snapshot of the first position, which includes the first iowait.

[0086] 101b. Get the first iowait from the first snapshot.

[0087] It should be noted that the snapshots in the prior art do not include iowait information. In the embodiments of this application, iowait information is added to the snapshot, so that when the application experiences ANR, it is convenient to quickly obtain iowait information from the snapshot and improve the efficiency of ANR cause analysis.

[0088] It is understood that in the embodiments of this application, the first iowait can be obtained directly at the first position; alternatively, a first snapshot including the first iowait can be obtained at the first position (and the first snapshot can be saved), and then the first iowait can be obtained from the first snapshot when the application experiences ANR; the specific method can be determined according to the actual situation, and is not limited here.

[0089] In this embodiment, adding iowait information to the snapshot requires minimal modification to the software. When an ANR occurs in the application, it is convenient to quickly obtain iowait information from the snapshot, thereby improving the efficiency of ANR cause analysis.

[0090] Optionally, obtaining the second iowait in step 101 above can be achieved through steps 101c and 101d below.

[0091] 101c, Get the second snapshot at the second location.

[0092] The second snapshot includes the second iowait.

[0093] 101d. Obtain the second iowait from the second snapshot.

[0094] It is understood that in the embodiments of this application, the second iowait can be obtained directly at the second location; alternatively, a second snapshot including the second iowait can be obtained at the second location (and the second snapshot can be saved), and then the first iowait can be obtained from the second snapshot when the application experiences ANR; the specific method can be determined according to the actual situation, and is not limited here.

[0095] In this embodiment, adding iowait information to the snapshot requires minimal modification to the software. When an ANR occurs in the application, it is convenient to quickly obtain iowait information from the snapshot, thereby improving the efficiency of ANR cause analysis.

[0096] Figure 2 This application provides a flowchart illustrating an application unresponsiveness analysis method. This method can be executed by an application unresponsiveness analysis device, which can be implemented in software and / or hardware and integrated into any computing-capable electronic device or server. Figure 2 As shown, the application's unresponsiveness analysis method may include the following steps 201 to 203:

[0097] 201. Obtain the first iowait when the target process of the application reaches the first position and the second iowait when the target process reaches the second position.

[0098] 202. When the first difference is greater than a preset multiple of the first duration, the cause of the ANR is determined to be the application's own business time consumption.

[0099] 203. When the first difference is less than or equal to the preset multiple of the first duration, the cause of the ANR is determined to be system resource shortage.

[0100] The first difference is the difference between the second iowait and the first iowait, and the first duration is the actual duration (i.e., the total duration) consumed by the target process from running to the first position to running to the second position. The preset multiplier is greater than 0 and less than 1.

[0101] It is understood that in the embodiments of this application, the first duration is the actual duration between the first position and the second position, and the preset multiple is determined based on the relationship between the first difference and the first duration, which are the causes of ANR in actual statistics, and the relationship between the first difference and the first duration when the cause of ANR is system resource shortage.

[0102] The descriptions of steps 201 to 203 above can refer to the relevant descriptions of steps 101 to 102 above, and are not limited here.

[0103] In this embodiment of the application, when the first difference is greater than a preset multiple of the first duration, the cause of the ANR is determined to be the application's own service time consumption; when the first difference is less than or equal to the preset multiple of the first duration, the cause of the ANR is determined to be system resource shortage. Thus, based on the relationship between the first difference and the preset multiple of the first duration, the cause of the ANR can be quickly determined to be the application's own service time consumption or system resource shortage, thereby improving the efficiency of ANR cause analysis.

[0104] Optionally, the preset multiplier is greater than or equal to one-tenth and less than or equal to one-third. The preset multiplier can be any value greater than or equal to one-tenth and less than or equal to one-third, and can be determined based on actual circumstances; no limitation is made here. Furthermore, the corresponding preset multiplier can be the same or different for different application processes.

[0105] In this embodiment of the application, by statistically analyzing the relationship between the first difference and the first duration when ANR actually occurs for different applications, it is determined that the preset multiple is greater than or equal to one-tenth and less than or equal to one-third, which can well ensure the accuracy of ANR cause analysis.

[0106] It should be noted that the preset multiplier can also be any value other than one-tenth or greater than one-third or less than one-third. The specific value can be determined according to the actual situation and is not limited here.

[0107] Optionally, the application's own business time consumption may include any of the following situations: the application's main thread frequently performs time-consuming read and write file operations; deadlock in multi-threaded operations, including the main thread; the main thread being blocked by the client-service communication tool; and other situations may also be included, which are not limited here.

[0108] Optionally, system resource shortage includes any of the following situations: the watchdog timer on the system server experiences an ANR (Application Not Responding); the connection limit between the server client and the service communication tool is reached, causing the client to be unable to communicate with the system server; system resources are exhausted; and other situations may also be included, which are not limited here.

[0109] Among them, the application's main thread frequently performs time-consuming file read and write operations, which may include a large number of data read and write operations, database read and write operations, and other operations. The specifics can be determined based on the actual situation and are not limited here.

[0110] For example, such as Figure 3 As shown, thread 1 owns object 1 and attempts to own object 2, while thread 2 owns object 2 and attempts to own object 1. This is a deadlock in multi-threaded operations, where one of the threads, thread 1 or thread 2, is the master thread. In this case, an ANR may occur.

[0111] Among them, the ANR in the watchdog of the system server is the ANR in the WatchDog of System Server.

[0112] The client-service communication tool can be Binder in Android, or a tool with similar functionality in other systems. The specific tool can be determined based on the actual situation and is not limited here.

[0113] In the case of an Android system, the main thread being blocked by the client-service communication tool can be interpreted as the main thread being blocked by the Binder.

[0114] In the case of an Android system, if the connection between the server-side client and the service communication tool reaches its limit, the client will be unable to communicate with the system server. In other words, if the connection between the service binder and the system server reaches its limit, the client will be unable to communicate with the system server.

[0115] When a client communicates with a service, it may encounter two situations that prevent the client from communicating with the service: 1. The service fails to return any messages to the client; 2. The binder is exhausted. Therefore, if a service binder connection reaches its limit and cannot communicate with the System Server, it can be understood as the service binder being exhausted (connection limit reached), causing the client to be unable to communicate with the service.

[0116] In this context, "system resources exhausted" refers to the depletion of resources such as pipes, CPU, and I / O. Pipes are a means of inter-process communication in Linux, CPU refers to CPU resources, and I / O refers to reading and writing to disk.

[0117] This application provides various scenarios where ANR is caused by the time consumed by the application's own business processes, as well as various scenarios where ANR is caused by the shortage of system resources. The specific scenarios can be determined according to the actual situation and are not limited here.

[0118] For example, such as Figure 4As shown, when the application starts processing broadcasts (i.e., when the broadcast processing process starts, corresponding to point A in the diagram), it directly acquires an iowait (denoted as iowait 1; acquiring iowait 1 only does not consume CPU resources). Then, when an ANR occurs (corresponding to point B in the diagram), the system service automatically saves a snapshot, acquires iowait 2 from the snapshot, and subtracts iowait 1 from iowait 2 to obtain an iowait diff (the first difference). The iowait diff is compared with the actual time difference T (T is the first duration). If iowait diff > T / 3, it indicates that the application's own business is taking time, thus excluding system resource constraints; if iowait diff ≤ T / 3, it indicates that the system I / O is high (i.e., system resource constraints), thus excluding application's own business from taking time.

[0119] In this embodiment, maximum benefit can be obtained in analyzing ANR issues with minimal resource consumption. Specifically, the iowait time of the current process is acquired every time the application process starts, and again when an ANR occurs. The iowait diff (the difference between the two iowait times) is compared with the diff between the application process startup time and the time when the ANR occurs. This allows determination of whether the ANR is caused by application-specific I / O latency or system resource constraints. If the iowait diff is too high, it confirms that the ANR is caused by application-specific I / O latency (i.e., the cause of the ANR is determined to be application-specific I / O latency). If the iowait diff is low, it confirms that the ANR is caused by system I / O constraints. Therefore, it is unnecessary to rely on extensive log and code analysis to determine whether the ANR is caused by application-specific I / O latency or system resource constraints.

[0120] Multiple tests have shown that the application unresponsiveness analysis method provided in this application embodiment can reduce the analysis time by 99%, especially for ANR problems caused by system resource shortage (high I / O).

[0121] This disclosure also provides an application unresponsive analysis device. Figure 5 This is a schematic diagram of the structure of an application unresponsive analysis device provided in this disclosure, such as... Figure 5As shown, the application no-response analysis device includes: an acquisition module 501 and a determination module 502; the acquisition module 501 is used to acquire the first iowait when the target process of the application runs to the first position and the second iowait when the target process runs to the second position; the determination module 502 is used to determine, in the event of an ANR during the operation of the target process, the cause of the ANR is the application's own business time consumption or system resource shortage based on the relationship between the first difference and the first duration; wherein, the difference between the time when the ANR occurs and the time corresponding to the second position is less than or equal to the duration threshold, the first difference is the difference between the second iowait acquired by the acquisition module 501 and the first iowait acquired by the acquisition module 501, and the first duration is the actual time consumed by the target process from running to the first position to running to the second position.

[0122] Optionally, the determining module 502 is specifically used to determine that the cause of the ANR is the application's own business time consumption when the first difference is greater than a preset multiple of the first duration, and the preset multiple is greater than 0 and less than 1; and to determine that the cause of the ANR is system resource shortage when the first difference is less than or equal to the preset multiple of the first duration.

[0123] Optionally, the preset multiple is greater than or equal to one-tenth and less than or equal to one-third.

[0124] Optionally, the application's own business time consumption includes any of the following situations: the application's main thread frequently performs time-consuming read and write file operations; deadlock in multi-threaded operations, including the main thread; the main thread is blocked by the client-server communication tool; system resource shortage includes any of the following situations: the watchdog timer in the system server experiences an ANR; the connection limit of the server-side client-server communication tool is reached, causing the client to be unable to communicate with the system server; system resources are exhausted.

[0125] Optionally, the acquisition module 501 is specifically used to acquire the iowait at the corresponding position once at a preset time interval during the operation of the target process, wherein the preset time interval is less than or equal to the time threshold; and to acquire the first iowait and the second iowait from the plurality of iowaits, wherein the second iowait is the largest one among the plurality of iowaits.

[0126] Optionally, the acquisition module 501 is specifically used to acquire a first snapshot of a first location, the first snapshot including a first iowait; and to acquire the first iowait from the first snapshot.

[0127] Optionally, the acquisition module 501 is specifically used to acquire a second snapshot of the second location, the second snapshot including a second iowait; and to acquire the second iowait from the second snapshot.

[0128] Optionally, the first position is the position when the target process starts; the second position is the position of the target process when the ANR occurs.

[0129] Optionally, the target process includes any of the following: a broadcast message processing process, a touch and click process, a system service startup process, or a content provider process.

[0130] It should be noted that the above-mentioned application unresponsive analysis device can be the electronic device in the above method embodiment of this application, or it can be a functional module and / or functional entity in the electronic device that can realize the function of the device embodiment. This application embodiment does not limit it.

[0131] In this embodiment, each module can implement the application non-responsive analysis method provided in the above method embodiments and achieve the same technical effect. To avoid repetition, it will not be described again here.

[0132] Figure 6 To illustrate the hardware structure of an electronic device according to various embodiments of this application, as shown in the following diagram... Figure 6 As shown, the electronic device includes, but is not limited to, components such as: a radio frequency (RF) circuit 601, a memory 602, an input unit 603, a display unit 604, a sensor 605, an audio circuit 606, a wireless fidelity (WiFi) module 607, a processor 608, a power supply 609, and a camera 310. The RF circuit 601 includes a receiver 6011 and a transmitter 6012. Those skilled in the art will understand that... Figure 6 The electronic device structure shown does not constitute a limitation on the electronic device and may include more or fewer components than shown, or combine certain components, or have different component arrangements.

[0133] RF circuit 601 can be used for receiving and transmitting signals during information transmission or calls. Specifically, it receives downlink information from the base station and processes it with processor 608; additionally, it transmits uplink data to the base station. Typically, RF circuit 601 includes, but is not limited to, an antenna, at least one amplifier, a transceiver, a coupler, a low-noise amplifier (LNA), and a duplexer. Furthermore, RF circuit 601 can also communicate wirelessly with networks and other devices. The aforementioned wireless communication can use any communication standard or protocol, including but not limited to Global System for Mobile Communication (GSM), General Packet Radio Service (GPRS), Code Division Multiple Access (CDMA), Wideband Code Division Multiple Access (WCDMA), Long Term Evolution (LTE), email, and Short Message Service (SMS).

[0134] The memory 602 can be used to store software programs and modules. The processor 608 executes various functional applications and data processing of the electronic device by running the software programs and modules stored in the memory 602. The memory 602 may mainly include a program storage area and a data storage area. The program storage area may store the operating system, application programs required for at least one function (such as sound playback function, image playback function, etc.), etc.; the data storage area may store data created according to the use of the electronic device (such as audio data, telephone directory, etc.). In addition, the memory 602 may include high-speed random access memory, and may also include non-volatile memory, such as at least one disk storage device, flash memory device, or other volatile solid-state storage device.

[0135] The input unit 603 can be used to receive input digital or character information, and to generate key signal inputs related to user settings and function control of the electronic device. Specifically, the input unit 603 may include a touch panel 6031 and other input devices 6032. The touch panel 6031, also known as a touch screen, can collect touch operations performed by the user on or near it (such as operations performed by the user using a finger, stylus, or any suitable object or accessory on or near the touch panel 6031), and drive the corresponding connection devices according to a pre-set program. Optionally, the touch panel 6031 may include two parts: a touch detection device and a touch controller. The touch detection device detects the user's touch position and the signal generated by the touch operation, and transmits the signal to the touch controller; the touch controller receives touch information from the touch detection device, converts it into touch point coordinates, sends it to the processor 608, and can receive and execute commands sent by the processor 608. In addition, the touch panel 6031 can be implemented using various methods such as resistive, capacitive, infrared, and surface acoustic wave. In addition to the touch panel 6031, the input unit 603 may also include other input devices 6032. Specifically, other input devices 6032 may include, but are not limited to, one or more of the following: physical keyboard, function keys (such as volume control buttons, power buttons, etc.), trackball, mouse, joystick, etc.

[0136] Display unit 604 can be used to display information input by the user or information provided to the user, as well as various menus of the electronic device. Display unit 604 may include a display panel 6041, optionally configured as a liquid crystal display (LCD), organic light-emitting diode (OLED), or similar form. Further, touch panel 6031 may cover display panel 6041. When touch panel 6031 detects a touch operation on or near it, it transmits the information to processor 608 to determine the touch event. Subsequently, processor 608 provides corresponding visual output on display panel 6041 based on the touch event. Although in Figure 6 In this embodiment, the touch panel 6031 and the display panel 6041 are two separate components to realize the input and output functions of the electronic device. However, in some embodiments, the touch panel 6031 and the display panel 6041 can be integrated to realize the input and output functions of the electronic device.

[0137] The electronic device may also include at least one sensor 605, such as a light sensor, a motion sensor, and other sensors. Specifically, the light sensor may include an ambient light sensor and a proximity sensor. The ambient light sensor can adjust the brightness of the display panel 6041 according to the ambient light level, and the proximity sensor can deactivate the display panel 6041 and / or backlight when the electronic device is moved to the ear. As a type of motion sensor, an accelerometer sensor can detect the magnitude of acceleration in various directions (generally three axes). When stationary, it can detect the magnitude and direction of gravity, and can be used for applications that identify the posture of the electronic device (such as landscape / portrait switching, related games, magnetometer posture calibration), vibration recognition related functions (such as pedometers, taps), etc. Other sensors that may be configured in the electronic device, such as gyroscopes, geomagnetic sensors, barometers, hygrometers, thermometers, and infrared sensors, will not be described in detail here. In the embodiments of this application, the electronic device may include an accelerometer, a depth sensor, or a distance sensor, etc.

[0138] Audio circuit 606, speaker 6061, and microphone 6062 provide an audio interface between the user and electronic device. Audio circuit 606 converts received audio data into electrical signals and transmits them to speaker 6061, where speaker 6061 converts them into sound signals for output. On the other hand, microphone 6062 converts collected sound signals into electrical signals, which are received by audio circuit 606, converted into audio data, and then output to processor 608 for processing. The audio data is then transmitted via RF circuit 601 to, for example, another electronic device, or output to memory 602 for further processing.

[0139] WiFi is a short-range wireless transmission technology. Electronic devices using the WiFi module 607 can help users send and receive emails, browse web pages, and access streaming media, providing users with wireless broadband internet access. Although Figure 6 WiFi module 607 is shown, but it is understood that it is not a necessary component of an electronic device and can be omitted as needed without changing the nature of the invention.

[0140] The processor 608 is the control center of the electronic device. It connects various parts of the electronic device via various interfaces and lines. By running or executing software programs and / or modules stored in the memory 602, and by calling data stored in the memory 602, it performs various functions and processes data, thereby providing overall monitoring of the electronic device. Optionally, the processor 608 may include one or more processing units; preferably, the processor 608 may integrate an application processor and a modem processor, wherein the application processor mainly handles the operating system, user interface, and applications, and the modem processor mainly handles wireless communication. It is understood that the modem processor may also not be integrated into the processor 608.

[0141] The electronic device also includes a power supply 609 (such as a battery) that supplies power to various components. Preferably, the power supply can be logically connected to the processor 608 through a power management system, thereby enabling functions such as charging, discharging, and power consumption management through the power management system. Although not shown, the electronic device may also include a Bluetooth module, etc., which will not be described in detail here.

[0142] In this embodiment, the processor 608 is configured to obtain the first iowait when the target process of the application reaches the first position and the second iowait when the target process reaches the second position; in the event of an ANR during the operation of the target process, based on the relationship between the first difference and the first duration, determine that the cause of the ANR is the application's own business time consumption or system resource shortage; wherein, the difference between the time when the ANR occurs and the time corresponding to the second position is less than or equal to the duration threshold, the first difference is the difference between the second iowait and the first iowait, and the first duration is the actual time consumed by the target process from running to the first position to running to the second position.

[0143] For details on the beneficial effects of the various implementation methods in this embodiment, please refer to the beneficial effects of the corresponding implementation methods in the above-mentioned application non-response analysis method embodiment. To avoid repetition, these will not be repeated here.

[0144] This application provides a computer-readable storage medium storing a program or instructions. When the program or instructions are executed by a processor, they implement the various processes of the application unresponsiveness analysis method provided in the above-described method embodiments and achieve the same technical effect. To avoid repetition, further details are omitted here.

[0145] This application also provides a computer program product, which includes a computer program or instructions. When the computer program product is run on a processor, the processor executes the computer program or instructions to implement the various processes of the application unresponsive analysis method provided in the above method embodiments, and can achieve the same technical effect. To avoid repetition, it will not be described again here.

[0146] This application embodiment also provides a chip, which includes a processor, a memory, and a communication interface. The communication interface is coupled to the processor. The memory is used to store programs or instructions that can run on the processor. The processor is used to execute the programs or instructions to implement the various processes of the above-described application unresponsive analysis method embodiment and achieve the same technical effect. To avoid repetition, it will not be described again here.

[0147] The processor may be, for example, a central processing unit (CPU), an application-specific integrated circuit (ASIC), or one or more integrated circuits configured to implement the embodiments of this application. The memory may be a single storage device or a collective term for multiple storage elements, and may include random access memory (RAM) or non-volatile memory, such as disk storage or flash memory.

[0148] It should be understood that the chip mentioned in the embodiments of this application may also be referred to as a system-on-a-chip, system chip, chip system, or system-on-a-chip, etc.

[0149] In the several embodiments provided in this application, it should be understood that the disclosed systems, devices, servers, and methods can be implemented in other ways. For example, the device embodiments described above are merely illustrative; for instance, the division of units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be an indirect coupling or communication connection between devices or units through some interfaces, and may be electrical, mechanical, or other forms.

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

[0151] Furthermore, the functional units in the various embodiments of this application can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.

[0152] If the integrated unit is implemented as 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 technical solution of this application, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of this application. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, portable hard drives, read-only memory (ROM), random access memory (RAM), magnetic disks, or optical disks.

[0153] The above-described embodiments are only used to illustrate the technical solutions of this application, and are not intended to limit them. Although this application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that modifications can still be made to the technical solutions described in the foregoing embodiments, or equivalent substitutions can be made to some of the technical features. Such modifications or substitutions do not cause the essence of the corresponding technical solutions to deviate from the spirit and scope of the technical solutions of the embodiments of this application.

Claims

1. A method for analyzing unresponsive applications, characterized in that, The method includes: Obtain the first cumulative file read / write operation time (iowait) when the target process of the application reaches the first position and the second iowait when the target process reaches the second position; If an Application Not Responding (ANR) occurs during the execution of the target process, and the first difference is greater than a preset multiple of the first duration, the cause of the ANR is determined to be the application's own business time consumption; if the first difference is less than or equal to the preset multiple of the first duration, the cause of the ANR is determined to be system resource shortage. Wherein, the difference between the time when the ANR occurs and the time corresponding to the second position is less than or equal to the duration threshold, the first difference is the difference between the second iowait and the first iowait, and the first duration is the actual duration consumed by the target process from running to the first position to running to the second position.

2. The method according to claim 1, characterized in that, The preset multiple is greater than 0 and less than 1.

3. The method according to claim 2, characterized in that, The preset multiple is greater than or equal to one-tenth and less than or equal to one-third.

4. The method according to claim 1, characterized in that, The acquisition of the first iowait when the target process of the application reaches the first position and the second iowait when the target process reaches the second position includes: During the execution of the target process, the iowait at the corresponding position is obtained once at a preset time interval, so as to obtain multiple iowaits before the ANR. The preset time interval is less than or equal to the time threshold. Obtain the first iowait and the second iowait from the plurality of iowaits, wherein the second iowait is the largest among the plurality of iowaits.

5. The method according to claim 1, characterized in that, The step of obtaining the first iowait when the target process of the application reaches the first position includes: Obtain a first snapshot of the first location, wherein the first snapshot includes the first iowait; Obtain the first iowait from the first snapshot.

6. The method according to claim 1, characterized in that, The step of obtaining the second iowait when the target process reaches the second position includes: Obtain a second snapshot of the second location, wherein the second snapshot includes the second iowait; Obtain the second iowait from the second snapshot.

7. The method according to claim 1, characterized in that, The first position is the position at which the target process starts; The second position is the position of the target process when the ANR occurs.

8. An application unresponsive analysis device, characterized in that, include: Get the module and determine the module; The acquisition module is used to acquire the first cumulative file read / write operation time iowait when the target process of the application runs to the first position; The acquisition module is also used to acquire the second iowait when the target process runs to the second position; The determining module is configured to, when an application fails to respond (ANR) during the execution of the target process, determine that the cause of the ANR is the application's own business time consumption when the first difference is greater than a preset multiple of the first duration; and determine that the cause of the ANR is system resource shortage when the first difference is less than or equal to the preset multiple of the first duration. Wherein, the first difference is the difference between the second iowait obtained by the acquisition module and the first iowait obtained by the acquisition module, and the first duration is the actual duration consumed by the target process from running to the first position to running to the second position.

9. An electronic device, characterized in that, include: A processor for executing a computer program stored in a memory, wherein the computer program, when executed by the processor, implements the steps of the application unresponsive analysis method according to any one of claims 1-7.

10. A computer-readable storage medium having a computer program stored thereon, characterized in that, When the computer program is executed by the processor, it implements the steps of the application unresponsive analysis method according to any one of claims 1-7.

Citation Information

Patent Citations

  • Abnormal log analysis method, apparatus, storage medium, and server

    CN109284269A

  • Data processing method, abnormal condition prediction method and related product

    CN112905399A