A fault detection method and device, electronic equipment and storage medium
By establishing a monitoring thread in electronic devices to acquire and analyze the application's thread stack and system symbols, the problem of inaccurate lag detection in existing technologies is solved, enabling comprehensive identification and rapid location of various lag causes.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-05-06
- Publication Date
- 2026-03-31
AI Technical Summary
In existing technologies, when electronic devices experience lag, only the lag caused by a specific underlying cause can be identified, resulting in low detection accuracy and an inability to comprehensively identify lag caused by multiple factors.
By establishing a monitoring thread after the target application starts, terminating the operation of multiple threads, obtaining the stack of each thread, and using target system symbols to detect from the main thread, fault information can be determined, including the thread that failed, the fault type, and the waiting relationships between threads.
It enables rapid and comprehensive location of fault causes in electronic device applications, improving the accuracy and comprehensiveness of lag detection.
Smart Images

Figure CN115048234B_ABST
Abstract
Description
Technical Field
[0001] This disclosure relates to the field of computer technology, and in particular to a fault detection method, apparatus, electronic device, and storage medium. Background Technology
[0002] Electronic devices may experience lag or stuttering during operation due to various issues. When the lag duration reaches a threshold, the electronic device stops running the application, resulting in a poor user experience. Therefore, when an application lags, the electronic device needs to quickly and comprehensively pinpoint the cause and upload it to the server so that staff can optimize the application and reduce the occurrence of lag. However, current technologies can only identify lag issues caused by a single, fixed reason, which is insufficient and leads to low accuracy in lag detection. Summary of the Invention
[0003] This disclosure provides a fault detection method, apparatus, electronic device, and storage medium that can quickly locate lag issues during application operation and improve the comprehensiveness and accuracy of problem detection.
[0004] The technical solution disclosed herein is as follows:
[0005] According to a first aspect of this disclosure, a fault detection method is provided, the method comprising:
[0006] After the target application starts, a monitoring thread for the target application is established;
[0007] When the monitoring thread determines that the main thread of the target application has failed, the execution of multiple threads is terminated. These multiple threads include the main thread and other child threads of the target application other than the monitoring thread.
[0008] Get the stack trace of each of the multiple threads;
[0009] Based on the stack trace of each thread and the target system symbol corresponding to the target application, the detection starts from the main thread to determine the fault information. The fault information includes the thread that failed, the fault type of the thread, and the waiting relationship between the failed threads.
[0010] Optionally, based on the stack trace of each thread and the target system symbols corresponding to the target application, fault information is determined starting from the main thread, including:
[0011] Determine the fault type of the main thread based on the main thread's stack and the target system symbols;
[0012] The fault information is determined based on the main thread and the fault type of the main thread.
[0013] Optionally, determining the fault information based on the main thread and the fault type of the main thread includes:
[0014] If the main thread's fault type includes the first type, then the fault information is determined based on the main thread and the main thread's fault type. The first type is used to indicate that the fault is not related to the target application's child thread.
[0015] And / or,
[0016] If the main thread's fault type includes the second type, then the target child thread related to the main thread's fault is obtained based on the main thread's stack trace. The second type is used to indicate that the fault is related to the target application's child thread. Based on the target child thread's stack trace and target system symbols, the fault type of the target child thread is determined. Fault information is determined based on the main thread, the main thread's fault type, the target child thread, and the target child thread's fault type.
[0017] Optionally, fault information can be determined based on the main thread, the fault type of the main thread, the target child thread, and the fault type of the target child thread, including:
[0018] If the fault type of the target sub-thread includes the first type, then the fault information is determined based on the main thread, the fault type of the main thread, the target sub-thread, and the fault type of the target sub-thread.
[0019] And / or,
[0020] If the fault type of the target sub-thread includes the second type, then the sub-threads related to the fault of the target sub-thread are determined based on the stack of the target sub-thread. This process is repeated until the fault information is determined.
[0021] Optionally, based on the main thread's stack and target system symbols, determine the main thread's fault type, including:
[0022] Obtain multiple pre-stored fault types and multiple preset positions corresponding to each fault type. The multiple fault types include a first type and a second type. The preset positions are used to indicate the position of the stack frame in the stack.
[0023] Based on the target system symbols, the stack frames at each preset position of the main thread's stack are symbolized to obtain the function identifier corresponding to each preset position of the stack frame;
[0024] Based on the function identifier corresponding to each stack frame at a preset location, determine whether the main thread has encountered a fault of the type corresponding to the preset location.
[0025] Optionally, after the target application starts, a monitoring thread for the target application is established, including:
[0026] After the target application starts, obtain the switch configuration information corresponding to the target application. The switch configuration information is used to indicate whether to enable fault detection of the target application.
[0027] If the switch configuration information is used to indicate the activation of fault detection, then the monitoring thread is established.
[0028] Optionally, if the switch configuration information is used to indicate enabling fault detection, then the monitoring thread is established, including:
[0029] If the switch configuration information is used to indicate the activation of fault detection, and the target system symbol is stored locally, then a monitoring thread is established;
[0030] or,
[0031] If the switch configuration information is used to indicate the activation of fault detection, and the target system symbol is not stored locally, then multiple initial system symbols are obtained from the server. After resolving the start and end addresses of each initial system symbol, a monitoring thread is established.
[0032] Optionally, the fault detection method also includes:
[0033] Based on each initial system symbol and its corresponding offset, determine the target system symbol corresponding to each initial system symbol;
[0034] Store the target system symbols.
[0035] Optionally, the main thread of the target application may fail by monitoring the thread, including:
[0036] By monitoring the thread, obtain the state information of the main thread's event loop mechanism;
[0037] If the status information does not change within a preset time period, it is determined that the main thread has failed. The preset time period is less than the stuttering threshold.
[0038] According to a second aspect of this disclosure, a fault detection device is provided, comprising:
[0039] The module is configured to create a monitoring thread for the target application after it starts.
[0040] The termination module is configured to terminate the operation of multiple threads when the monitoring thread established by the establishment module determines that the main thread of the target application has failed. These multiple threads include the main thread and other child threads of the target application other than the monitoring thread.
[0041] The fetch module is configured to fetch the stack of each of multiple threads.
[0042] The determination module is configured to perform a detection process starting from the main thread, based on the stack trace of each thread and the target system symbol corresponding to the target application. The fault information includes the thread that failed, the type of fault in the thread, and the waiting relationships between the failed threads.
[0043] Optionally, specify the module to be executed:
[0044] Determine the fault type of the main thread based on the main thread's stack and the target system symbols;
[0045] The fault information is determined based on the main thread and the fault type of the main thread.
[0046] Optionally, specify the module to be executed:
[0047] If the main thread's fault type includes the first type, then the fault information is determined based on the main thread and the main thread's fault type. The first type is used to indicate that the fault is not related to the target application's child thread.
[0048] And / or,
[0049] If the main thread's fault type includes the second type, then the target child thread related to the main thread's fault is obtained based on the main thread's stack trace. The second type is used to indicate that the fault is related to the target application's child thread. Based on the target child thread's stack trace and target system symbols, the fault type of the target child thread is determined. Fault information is determined based on the main thread, the main thread's fault type, the target child thread, and the target child thread's fault type.
[0050] Optionally, specify the module to be executed:
[0051] If the fault type of the target sub-thread includes the first type, then the fault information is determined based on the main thread, the fault type of the main thread, the target sub-thread, and the fault type of the target sub-thread.
[0052] And / or,
[0053] If the fault type of the target sub-thread includes the second type, then the sub-threads related to the fault of the target sub-thread are determined based on the stack of the target sub-thread. This process is repeated until the fault information is determined.
[0054] Optionally, specify the module to be executed:
[0055] Obtain multiple pre-stored fault types and multiple preset positions corresponding to each fault type. The multiple fault types include a first type and a second type. The preset positions are used to indicate the position of the stack frame in the stack.
[0056] Based on the target system symbols, the stack frames at each preset position of the main thread's stack are symbolized to obtain the function identifier corresponding to each preset position of the stack frame;
[0057] Based on the function identifier corresponding to each stack frame at a preset location, determine whether the main thread has encountered a fault of the type corresponding to the preset location.
[0058] Optionally, a module is created, specifically configured to execute:
[0059] After the target application starts, obtain the switch configuration information corresponding to the target application. The switch configuration information is used to indicate whether to enable fault detection of the target application.
[0060] If the switch configuration information is used to indicate the activation of fault detection, then the monitoring thread is established.
[0061] Optionally, a module is created, specifically configured to execute:
[0062] If the switch configuration information is used to indicate the activation of fault detection, and the target system symbol is stored locally, then a monitoring thread is established;
[0063] or,
[0064] If the switch configuration information is used to indicate the activation of fault detection, and the target system symbol is not stored locally, then multiple initial system symbols are obtained from the server. After resolving the start and end addresses of each initial system symbol, a monitoring thread is established.
[0065] Optionally, the fault detection device may also include a storage module;
[0066] The determination module is also configured to perform the task of determining the target system symbol corresponding to each initial system symbol based on each initial system symbol and the offset corresponding to each initial system symbol.
[0067] The storage module is configured to execute the target system symbols determined by the storage determination module.
[0068] Optionally, specify the module to be executed:
[0069] By monitoring the thread, obtain the state information of the main thread's event loop mechanism;
[0070] If the status information does not change within a preset time period, it is determined that the main thread has failed. The preset time period is less than the stuttering threshold.
[0071] According to a third aspect of this disclosure, an electronic device is provided, comprising:
[0072] processor;
[0073] A memory for storing processor-executable instructions; wherein the processor is configured to execute instructions to implement any of the optional fault detection methods in the first aspect described above.
[0074] According to a fourth aspect of this disclosure, a computer-readable storage medium is provided, on which instructions are stored, such that when the instructions in the computer-readable storage medium are executed by a processor of an electronic device, the electronic device is able to perform any of the optional fault detection methods of the first aspect described above.
[0075] According to a fifth aspect of this disclosure, a computer program product is provided, comprising instructions that, when executed on an electronic device, cause the electronic device to perform any of the optional fault detection methods of the first aspect.
[0076] The technical solution provided in this disclosure offers at least the following advantages: After the target application starts, the fault detection device establishes a monitoring thread to perform fault detection on the target application. When the monitoring thread determines that the main thread of the target application has failed, it terminates the execution of multiple threads, including the main thread and all child threads of the target application except for the monitoring thread. The fault detection device acquires the stack of each thread and, based on the stack of each thread and the target system symbol corresponding to the target application, starts detection from the main thread to determine the thread that failed, the type of failure, and the waiting relationships between the failed threads. Thus, by using the monitoring thread to detect from the main thread based on the stack and target system symbol, the root cause of the target application's failure can be quickly located. Compared to related technologies that can only pinpoint a fixed cause for the failure, the fault cause located in this application is more comprehensive and accurate.
[0077] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit this disclosure. Attached Figure Description
[0078] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with this disclosure and, together with the description, serve to explain the principles of this disclosure, and are not intended to unduly limit this disclosure.
[0079] Figure 1 This is a schematic diagram of a fault detection system according to an exemplary embodiment.
[0080] Figure 2 This is one of the flowcharts illustrating a fault detection method according to an exemplary embodiment.
[0081] Figure 3 This is a second flowchart illustrating a fault detection method according to an exemplary embodiment.
[0082] Figure 4 This is the third flowchart illustrating a fault detection method according to an exemplary embodiment.
[0083] Figure 5 This is one of the logic structure block diagrams of a fault detection device according to an exemplary embodiment.
[0084] Figure 6 This is a second logical structure block diagram of a fault detection device according to an exemplary embodiment.
[0085] Figure 7 This is a structural block diagram of an electronic device according to an exemplary embodiment. Detailed Implementation
[0086] To enable those skilled in the art to better understand the technical solutions of this disclosure, the technical solutions in the embodiments of this disclosure will be clearly and completely described below with reference to the accompanying drawings.
[0087] It should be noted that the embodiments described in the following exemplary embodiments do not represent all embodiments consistent with this disclosure. Rather, they are merely examples of apparatuses and methods consistent with some aspects of this disclosure as detailed in the appended claims.
[0088] It should be noted that the user information (including but not limited to user device information, user personal information, etc.) involved in the embodiments of this disclosure are all information authorized by the user or fully authorized by all parties.
[0089] The fault detection method provided in this disclosure can be applied to scenarios where faults in applications are located online in electronic devices. Information during application runtime is much richer than information offline, and some fault information is difficult to locate when the application is offline. For example, related technologies can only locate lag problems caused by a certain fixed reason. This approach is not comprehensive enough, resulting in low accuracy in lag detection. For instance, related technologies can only locate lag problems caused by deadlocks, and cannot locate lag problems caused by single problems or combinations of problems such as lock waiting, XPC calls, and greatest common divisor (GCD) synchronization waiting.
[0090] Deadlock refers to a situation where two or more threads are blocked during execution due to competition for resources or communication with each other. Without external intervention, they will be unable to proceed. These threads that are perpetually waiting for each other are called deadlocked threads.
[0091] Lock waiting refers to the phenomenon where one thread must wait for another thread to finish executing before it can begin executing.
[0092] XPC calls refer to using XPC technology to call other services on electronic devices.
[0093] To quickly locate application lag issues during operation and improve the comprehensiveness and accuracy of problem detection, this disclosure provides a fault detection method. Based on the stack and target system symbols, the method uses a monitoring thread to detect issues starting from the main thread, determining the faulty thread, the fault type of the faulty thread, and the waiting relationships between the faulty threads. This method can quickly locate the root cause of the target application's failure. Compared with related technologies that can only locate faults caused by a certain fixed reason, the fault causes located in this application are more comprehensive and accurate.
[0094] Figure 1 This is a schematic diagram illustrating a fault detection system according to an exemplary embodiment. The fault detection method provided in this disclosure can be applied to this fault detection system. Figure 1 As shown, the fault detection system may include an electronic device 101 and a server 102. The electronic device 101 communicates with the server 102 via wired or wireless communication.
[0095] Electronic device 101 has multiple applications installed. Taking the target application as an example, during the target application's operation, electronic device 101 creates a main thread and multiple child threads for the target application. These threads are not completely independent and may communicate with each other. Electronic device 101 is primarily used to terminate the execution of multiple threads when a fault occurs after the target application starts. Based on the stack trace of each thread and the target system symbol corresponding to the target application, it detects fault information starting from the main thread, determines the fault information, and sends this fault information to server 102. This fault information includes the thread that failed, the fault type of the thread, and the waiting relationships between the failed threads. The multiple threads include the main thread and all child threads of the target application except for the monitoring thread.
[0096] In some embodiments, the electronic device 101 may be a mobile phone, tablet computer, desktop computer, laptop computer, handheld computer, notebook computer, in-vehicle device, ultra-mobile personal computer (UMPC), netbook, as well as cellular phone, personal digital assistant (PDA), augmented reality (AR) / virtual reality (VR) device, etc. Figure 1 The example shown is a mobile phone, which is an electronic device 101.
[0097] Server 102 is used to receive fault information sent by electronic device 101 so that back-end staff can analyze it, and is also used to provide system symbols to electronic device 101.
[0098] In some embodiments, server 102 may be a single server, a server cluster consisting of multiple servers, or a cloud computing platform; the embodiments disclosed herein do not limit the scope of the invention. Figure 1 The example shown is a single server.
[0099] Of course, the fault detection method provided in this disclosure can also be applied to Figure 1 This disclosure is not limited to other systems, or to scenarios that only contain electronic devices.
[0100] Figure 2 This is a flowchart illustrating a fault detection method according to an exemplary embodiment, such as... Figure 2 As shown, the method may include the following steps 201-204.
[0101] 201. After the target application starts, a monitoring thread for the target application is established.
[0102] In some embodiments, after the target application is started, the electronic device can directly establish a monitoring thread for the target application, which is used to perform fault detection on the target application.
[0103] 202. When it is determined through monitoring threads that the main thread of the target application has failed, terminate the execution of multiple threads.
[0104] After establishing a monitoring thread, the electronic device can monitor the status information of the target application's main thread's runloop in real time. If the electronic device determines that the status information has not changed within a preset time period, it considers the main thread to have malfunctioned. If the electronic device determines that the status information has changed within the preset time period, it considers the main thread not to have malfunctioned and continues monitoring. The preset time period is less than a stuttering threshold. Since the electronic device will stop the target application if the stuttering duration is greater than or equal to the stuttering threshold, a duration less than the stuttering threshold is set to determine whether the main thread has malfunctioned, allowing for the detection of the cause of the target application's malfunction after the main thread malfunctions but before the application stops running.
[0105] When an electronic device determines that the main thread of the target application has failed, it can terminate (suspend) the operation of multiple threads, which may include the main thread and other child threads of the target application other than the monitoring thread.
[0106] 203. Obtain the stack of each thread in multiple threads.
[0107] 204. Based on the stack of each thread and the target system symbol corresponding to the target application, start the detection from the main thread to determine the fault information.
[0108] The fault information includes the threads that failed, the fault type of each thread, and the waiting relationships between the failed threads.
[0109] The technical solution provided by the above embodiments brings at least the following beneficial effects: After the target application starts, the fault detection device establishes a monitoring thread to perform fault detection on the target application. When the monitoring thread determines that the main thread of the target application has failed, it terminates the operation of multiple threads, that is, it terminates the operation of the main thread and other child threads of the target application except for the monitoring thread. The fault detection device obtains the stack of each thread in the multiple threads, and based on the stack of each thread and the target system symbol corresponding to the target application, it starts detecting from the main thread to determine the thread that has failed, the type of failure of that thread, and the waiting relationship between the failed threads. In this way, by using the monitoring thread to detect from the main thread based on the stack and the target system symbol, the root cause of the failure of the target application can be quickly located. Compared with related technologies that can only locate the cause of failure due to a certain fixed reason, the fault cause located by this application is more comprehensive and accurate.
[0110] Optionally, after the target application is launched, the electronic device can determine whether to establish a monitoring thread by obtaining the switch configuration information corresponding to the target application. This switch configuration information is used to indicate whether fault detection of the target application should be enabled. If the switch configuration information indicates that fault detection should be enabled, then a monitoring thread is established.
[0111] Further optionally, in this embodiment of the disclosure, when the switch configuration information is used to indicate the activation of fault detection, it can be determined whether to establish a monitoring thread by determining whether the target system symbol corresponding to the target application is stored locally.
[0112] In the specific implementation, if the obtained switch configuration information is used to indicate the activation of fault detection, and the target system symbol is stored locally, the electronic device establishes a monitoring thread. If the obtained switch configuration information is used to indicate the activation of fault detection, but the target system symbol is not stored locally, the electronic device obtains multiple initial system symbols corresponding to the target application from the server, and establishes a monitoring thread after successfully resolving the start and end addresses of each initial system symbol. Successful resolution of the initial system symbol means that both the start and end addresses of the initial system symbol are present, and the address format is correct.
[0113] If the obtained switch configuration information is used to indicate that fault detection is not enabled, or if the obtained switch configuration information is used to indicate that fault detection is enabled, and the initial system symbol is obtained from the server but resolution fails, then no monitoring thread will be established. Here, initial system symbol resolution failure refers to the initial system symbol's start or end address being missing, or the address format being incorrect.
[0114] Optionally, after successfully resolving multiple initial system symbols, the electronic device can determine the target system symbol corresponding to each initial system symbol based on each initial system symbol and its corresponding offset, and store the target system symbol locally. This not only prepares for subsequent fault detection, but also eliminates the need to retrieve system symbols from the server when the target application is restarted, thus improving the efficiency of fault detection.
[0115] It is understood that the aforementioned switch configuration information or initial system symbol can be transmitted to the electronic device by the server in the download or upgrade installation package of the target application, or it can be obtained by the electronic device from the server in real time after the target application starts, or it can be obtained from the server in an offline state. This embodiment of the present disclosure does not impose specific limitations. Since the switch configuration information and system symbol are pre-configured by the server, the server decides whether to enable fault detection, resulting in greater flexibility. Furthermore, compared to directly establishing a monitoring thread after the application starts, establishing a monitoring thread when the fault detection conditions are met is more reasonable and can reduce the processing pressure on the electronic device.
[0116] It should be noted that, in the embodiments of this disclosure, the execution of the two steps of obtaining switch configuration information and determining whether the target system symbol is stored locally is not sequential, and is not limited here.
[0117] For example, such as Figure 3As shown, after the target application starts, it first obtains the switch configuration information, and then determines whether the target system symbol is stored locally. If the switch configuration information indicates that fault detection is not enabled, no monitoring thread is established. If the switch configuration information indicates that fault detection is enabled, it determines whether the target system symbol is stored. If it is stored locally, a monitoring thread is established. If it is not stored locally, the initial system symbol is obtained from the server. If the initial system symbol is successfully parsed, a monitoring thread is established; if parsing fails, no monitoring thread is established.
[0118] Optionally, in embodiments of this disclosure, combined with Figure 2 ,like Figure 4 As shown, step 204 above may specifically include steps 205-206.
[0119] 205. Determine the fault type of the main thread based on the main thread's stack and the target system symbols.
[0120] Optionally, in this embodiment, the electronic device can first acquire multiple pre-stored fault types and multiple preset positions corresponding one-to-one with each fault type. The preset positions are used to indicate the position of the stack frame in the stack. Then, the electronic device symbolizes the stack frame at each preset position of the main thread's stack according to the start and end addresses of each target system symbol, obtaining the function identifier corresponding to each preset position's stack frame. Afterward, the electronic device can determine whether the main thread has experienced a fault of the fault type corresponding to the preset position based on the function identifier corresponding to each preset position's stack frame. If it is determined that the main thread has experienced a fault of a certain type, then it is determined that the main thread's fault type includes that type. In this way, since the storage position of each fault type in the stack is relatively fixed, by pre-stored the correspondence between fault types and preset positions, and sequentially symbolizing the stack frame at each preset position of the main thread, it is possible to determine whether the main thread has experienced a fault of the fault type corresponding to the preset position, without needing to inspect each stack frame of the main thread, thus quickly determining the main thread's fault type.
[0121] It is understandable that multiple fault types can include a first type and a second type. The first type indicates that the fault is unrelated to a sub-thread of the target application, while the second type indicates that the fault is related to a sub-thread of the target application. For example, the first type could be an XPC call, and the second type could be a lock wait, deadlock, GCD call, etc. Furthermore, the mapping relationship between the above multiple fault types and multiple preset locations can be pre-configured in the electronic device. The preset location corresponding to each fault type can be determined by backend staff based on practical experience, or it can be adjusted according to the actual scenario.
[0122] For example, suppose an electronic device pre-stores a fault type: deadlock, with the default location corresponding to the top of the stack. The electronic device can then determine the system symbol corresponding to the top of the main thread's stack from multiple target system symbols. Using this determined system symbol, the top of the main thread's stack is symbolized to obtain the symbol identifier corresponding to the top of the main thread's stack. The electronic device can determine whether the symbol identifier corresponding to the top of the main thread's stack indicates deadlock. If so, the fault type of the main thread includes deadlock. If not, the fault type of the main thread does not include deadlock.
[0123] 206. Determine the fault information based on the main thread and the fault type of the main thread.
[0124] If the fault type of the main thread includes the first type, the electronic device determines the fault information based on the main thread and the fault type of the main thread being the first type.
[0125] If the main thread's fault type includes the second type, the electronic device can obtain the target child thread related to the main thread's fault based on the main thread's stack trace. For example, assuming the second type is lock waiting, the electronic device can obtain the target child thread for the main thread's lock waiting based on the main thread's stack trace. Then, the electronic device can determine the fault type of the target child thread based on the target child thread's stack trace and target system symbol. A detailed description of how the electronic device determines the fault type of the target child thread based on the target child thread's stack trace and target system symbol can be found in step 205 above, which describes determining the main thread's fault type based on the main thread's stack trace and target system symbol; it will not be repeated here. Afterward, the electronic device can determine the fault information based on the main thread, the main thread's fault type, the target child thread, and the target child thread's fault type.
[0126] It should be noted that, in the embodiments of this disclosure, the main thread may be faulted by a single problem or by a combination of multiple problems. Therefore, the fault type of the main thread can be the first type, the second type, or both. Of course, the fault type of the main thread can also be other types besides the first and second types, and this embodiment of the disclosure does not limit this.
[0127] After determining the fault type of the target sub-thread, if the fault type of the target sub-thread includes the first type, the electronic device determines the fault information based on the main thread, the fault type of the main thread, the target sub-thread, and the fault type of the target sub-thread. If the fault type of the target sub-thread includes the second type, the electronic device determines the sub-threads related to the fault of the target sub-thread based on the stack trace of the target sub-thread. This process is repeated until the fault information is determined. It is understandable that the fault type of the target sub-thread can be the first type, the second type, or both, or other types depending on the specific circumstances.
[0128] The technical solution provided by the above embodiments brings at least the following beneficial effects: by first determining the fault type of the main thread, if the fault type of the main thread includes the second type, the fault-related child thread is found, and the found child thread is detected until the problematic thread is found. This not only enables rapid fault location, but also enables comprehensive and accurate detection of the cause of application faults. The embodiments of this disclosure enhance the ability to detect online problems.
[0129] Figure 5 This is a logic structure block diagram of a fault detection device according to an exemplary embodiment. (Refer to...) Figure 5 The fault detection device is applied to electronic equipment and includes: an establishment module 51, an termination module 52, an acquisition module 53, and a determination module 54.
[0130] Module 51 is configured to establish a monitoring thread for the target application after the target application starts.
[0131] The termination module 52 is configured to terminate the operation of multiple threads when the monitoring thread established by the establishment module 51 determines that the main thread of the target application has failed. The multiple threads include the main thread and other sub-threads of the target application other than the monitoring thread.
[0132] The acquisition module 53 is configured to acquire the stack of each of the plurality of threads;
[0133] The determination module 54 is configured to perform a detection based on the stack of each thread and the target system symbol corresponding to the target application, starting from the main thread, to determine fault information. The fault information includes the thread that has failed among the multiple threads, the fault type of the thread, and the waiting relationship between the failed threads.
[0134] Optionally, module 54 is determined and specifically configured to execute:
[0135] Determine the fault type of the main thread based on the main thread's stack and the target system symbols;
[0136] The fault information is determined based on the main thread and the fault type of the main thread.
[0137] Optionally, module 54 is determined and specifically configured to execute:
[0138] If the main thread's fault type includes the first type, then the fault information is determined based on the main thread and the main thread's fault type. The first type is used to indicate that the fault is not related to the target application's child thread.
[0139] And / or,
[0140] If the main thread's fault type includes the second type, then the target child thread related to the main thread's fault is obtained based on the main thread's stack trace. The second type is used to indicate that the fault is related to the target application's child thread. Based on the target child thread's stack trace and target system symbols, the fault type of the target child thread is determined. Fault information is determined based on the main thread, the main thread's fault type, the target child thread, and the target child thread's fault type.
[0141] Optionally, module 54 is determined and specifically configured to execute:
[0142] If the fault type of the target sub-thread includes the first type, then the fault information is determined based on the main thread, the fault type of the main thread, the target sub-thread, and the fault type of the target sub-thread.
[0143] And / or,
[0144] If the fault type of the target sub-thread includes the second type, then the sub-threads related to the fault of the target sub-thread are determined based on the stack of the target sub-thread. This process is repeated until the fault information is determined.
[0145] Optionally, module 54 is determined and specifically configured to execute:
[0146] Obtain multiple pre-stored fault types and multiple preset positions corresponding to each fault type. The multiple fault types include a first type and a second type. The preset positions are used to indicate the position of the stack frame in the stack.
[0147] Based on the target system symbols, the stack frames at each preset position of the main thread's stack are symbolized to obtain the function identifier corresponding to each preset position of the stack frame;
[0148] Based on the function identifier corresponding to each stack frame at a preset location, determine whether the main thread has encountered a fault of the type corresponding to the preset location.
[0149] Optionally, module 51 is created and specifically configured to execute:
[0150] After the target application starts, obtain the switch configuration information corresponding to the target application. The switch configuration information is used to indicate whether to enable fault detection of the target application.
[0151] If the switch configuration information is used to indicate the activation of fault detection, then the monitoring thread is established.
[0152] Optionally, module 51 is created and specifically configured to execute:
[0153] If the switch configuration information is used to indicate the activation of fault detection, and the target system symbol is stored locally, then a monitoring thread is established;
[0154] or,
[0155] If the switch configuration information is used to indicate the activation of fault detection, and the target system symbol is not stored locally, then multiple initial system symbols are obtained from the server. After resolving the start and end addresses of each initial system symbol, a monitoring thread is established.
[0156] Optional, such as Figure 6 As shown, the fault detection device also includes a storage module 55;
[0157] The determination module 54 is also configured to perform the task of determining the target system symbol corresponding to each initial system symbol based on each initial system symbol and the offset corresponding to each initial system symbol.
[0158] Storage module 55 is configured to execute the target system symbol determined by storage determination module 54.
[0159] Optionally, module 54 is determined and specifically configured to execute:
[0160] By monitoring the thread, obtain the state information of the main thread's event loop mechanism;
[0161] If the status information does not change within a preset time period, it is determined that the main thread has failed. The preset time period is less than the stuttering threshold.
[0162] Regarding the apparatus in the above embodiments, the specific manner in which each module performs its operation has been described in detail in the embodiments related to the method, and will not be elaborated upon here.
[0163] Figure 7 This is a structural block diagram of an electronic device according to an exemplary embodiment. The electronic device may be a fault detection device, which may be a smartphone, tablet computer, laptop computer, or desktop computer.
[0164] The fault detection device may include at least one processor 71, a communication bus 72, a memory 73, and at least one communication interface 74.
[0165] Processor 71 may be a processor (central processing unit, CPU), a microprocessor unit, or one or more integrated circuits for controlling the execution of programs according to the present disclosure.
[0166] The communication bus 72 may include a path for transmitting information between the aforementioned components.
[0167] Communication interface 74 uses any transceiver-like device for communicating with other devices or communication networks, such as Ethernet, radio access network (RAN), wireless local area networks (WLAN), etc.
[0168] The memory 73 may be a read-only memory (ROM) or other type of static storage device capable of storing static information and instructions, random access memory (RAM) or other type of dynamic storage device capable of storing information and instructions, or electrically erasable programmable read-only memory (EEPROM), compact disc read-only memory (CD-ROM) or other optical disc storage, optical disc storage (including compressed optical discs, laser discs, optical discs, digital versatile optical discs, Blu-ray discs, etc.), magnetic disk storage media or other magnetic storage devices, or any other medium capable of carrying or storing desired program code in the form of instructions or data structures and accessible by a computer, but not limited thereto. The memory may exist independently and be connected to the processing unit via a bus. The memory may also be integrated with the processing unit.
[0169] The memory 73 stores the application code that executes the present invention, and its execution is controlled by the processor 71. The processor 71 executes the application code stored in the memory 73 to implement the functions of the method of the present invention.
[0170] In a specific implementation, as one example, processor 71 may include one or more CPUs, for example... Figure 7 CPU0 and CPU1 in the CPU.
[0171] In a specific implementation, as one example, the fault detection device may include multiple processors, for example... Figure 7Processors 71 and 75 are included. Each of these processors can be a single-core (single-CPU) processor or a multi-core (multi-CPU) processor.
[0172] In a specific implementation, as one embodiment, the fault detection device may further include an input device 76 and an output device 77. The input device 76 communicates with the processor 71 and can accept user input in various ways. For example, the input device 76 may be a mouse, keyboard, touchscreen device, or sensing device. The output device 77 communicates with the processor 71 and can display information in various ways. For example, the output device 77 may be a liquid crystal display (LCD), a light-emitting diode (LED) display device, etc.
[0173] Those skilled in the art will understand that Figure 7 The 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 use different component arrangements.
[0174] This disclosure also provides a computer-readable storage medium including instructions stored thereon, which, when executed by a computer's processor, enables the computer to perform the fault detection method provided in the embodiments shown above. For example, the computer-readable storage medium may be a memory 73 including instructions, which may be executed by a processor 71 of an electronic device to complete the above method. Optionally, the computer-readable storage medium may be a ROM, RAM, CD-ROM, magnetic tape, floppy disk, or optical data storage device, etc.
[0175] This disclosure also provides a computer program product containing instructions that, when run on an electronic device, cause the electronic device to perform the fault detection method provided in the embodiments described above.
[0176] Other embodiments of this disclosure will readily occur to those skilled in the art upon consideration of the specification and practice of the invention disclosed herein. This disclosure is intended to cover any variations, uses, or adaptations of this disclosure that follow the general principles of this disclosure and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of this disclosure are indicated by the following claims.
[0177] It should be understood that this disclosure is not limited to the precise structures described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of this disclosure is limited only by the appended claims.
Claims
1. A fault detection method characterized by, The method comprises: starting a monitoring thread of the target application after the target application is started; terminating the running of a plurality of threads when it is determined through the monitoring thread that a main thread of the target application has failed, the plurality of threads comprising the main thread and other sub-threads of the target application except the monitoring thread; obtaining a stack of each thread in the plurality of threads; determining failure information from the main thread based on the stack of each thread and target system symbols corresponding to the target application, the failure information comprising the threads in the plurality of threads that have failed, the failure type of the threads, and the waiting relationship between the threads that have failed; the determining of the failure information from the main thread based on the stack of each thread and target system symbols corresponding to the target application comprises: determining the failure type of the main thread based on the stack of the main thread and the target system symbols; determining the failure information based on the main thread and the failure type of the main thread; the determining of the failure type of the main thread based on the stack of the main thread and the target system symbols comprises: obtaining a plurality of pre-stored failure types and a plurality of pre-set positions corresponding to the plurality of failure types, the plurality of failure types comprising a first type and a second type, the pre-set positions being used to indicate the position of a stack frame in a stack; symbolizing the stack frame at each pre-set position of the stack of the main thread based on the target system symbols to obtain the function identifier corresponding to the stack frame at each pre-set position; determining whether the main thread has failed in the failure type corresponding to the pre-set position based on the function identifier corresponding to the stack frame at each pre-set position.
2. The fault detection method according to claim 1, characterized in that, the determining of the failure information based on the main thread and the failure type of the main thread comprises: if the failure type of the main thread comprises the first type, determining the failure information based on the main thread and the failure type of the main thread, the first type being used to indicate that the failure is irrelevant to the sub-threads of the target application; and / or if the failure type of the main thread comprises the second type, determining a target sub-thread related to the failure of the main thread based on the stack of the main thread, the second type being used to indicate that the failure is related to the sub-threads of the target application; determining the failure type of the target sub-thread based on the stack of the target sub-thread and the target system symbols; and determining the failure information based on the main thread, the failure type of the main thread, the target sub-thread, and the failure type of the target sub-thread. the determining of the failure information based on the main thread, the failure type of the main thread, the target sub-thread, and the failure type of the target sub-thread comprises:
3. The fault detection method according to claim 2, characterized in that, if the failure type of the target sub-thread comprises the first type, determining the failure information based on the main thread, the failure type of the main thread, the target sub-thread, and the failure type of the target sub-thread; and / or if the failure type of the target sub-thread comprises the second type, determining the failure information based on the main thread, the failure type of the main thread, the target sub-thread, and the failure type of the target sub-thread. If the fault type of the target sub-thread includes the second type, a sub-thread related to the fault of the target sub-thread is determined according to the stack of the target sub-thread, and the cycle is performed until the fault information is determined.
4. The fault detection method according to any one of claims 1 to 3, characterized in that, After the target application is started, a monitoring thread of the target application is established, including: After the target application is started, switch configuration information corresponding to the target application is acquired, the switch configuration information being used to indicate whether to start fault detection of the target application. If the switch configuration information is used to indicate that the fault detection is started, the monitoring thread is established.
5. The fault detection method of claim 4, wherein, The establishment of the monitoring thread if the switch configuration information is used to indicate that the fault detection is started includes: If the switch configuration information is used to indicate that the fault detection is started, and the target system symbol is locally stored, the monitoring thread is established. Or, If the switch configuration information is used to indicate that the fault detection is started, and the target system symbol is not locally stored, a plurality of initial system symbols are acquired from a server, and after the start address and the end address of each initial system symbol in the plurality of initial system symbols are parsed, the monitoring thread is established.
6. The fault detection method of claim 5, wherein, The fault detection method further includes: According to each initial system symbol and the offset corresponding to each initial system symbol, a target system symbol corresponding to each initial system symbol is determined. The target system symbol is locally stored.
7. The fault detection method according to any one of claims 1 to 3, characterized in that, The determination of the fault of the main thread of the target application by the monitoring thread includes: The state information of the event loop mechanism of the main thread is acquired by the monitoring thread. When it is determined that the state information does not change within a preset time period, it is determined that the main thread has a fault, and the preset time period is less than a stall threshold.
8. A fault detection apparatus characterized by comprising: It includes: The establishment module is configured to execute the establishment of the monitoring thread of the target application after the target application is started. The end module is configured to execute the ending of the running of a plurality of threads when it is determined by the monitoring thread established by the establishment module that the main thread of the target application has a fault, the plurality of threads including the main thread and other sub-threads of the target application except the monitoring thread. The acquisition module is configured to acquire the stack of each thread in the plurality of threads. The determination module is configured to determine fault information including the thread having a fault in the plurality of threads, the fault type of the thread, and the waiting relationship between the threads having a fault, starting from the main thread, according to the stack of each thread and the target system symbol corresponding to the target application. The determination module is specifically configured to: According to the stack of the main thread and the target system symbol, the fault type of the main thread is determined. According to the main thread and the fault type of the main thread, the fault information is determined. The determination module is specifically configured to: A plurality of fault types and a plurality of preset positions corresponding to the plurality of fault types are acquired, the plurality of fault types including a first type and a second type, and the preset position being used to indicate the position of a stack frame in a stack. According to the target system symbol, symbolize the stack frame of each preset position of the stack of the main thread to obtain a function identifier corresponding to the stack frame of each preset position; According to the function identifier corresponding to the stack frame of each preset position, determine whether the main thread has a fault of a fault type corresponding to the preset position.
9. An electronic device, comprising: Comprise: A processor; A memory for storing instructions executable by the processor; Wherein the processor is configured to execute the instructions to implement the fault detection method of any one of claims 1-7.
10. A computer-readable storage medium having stored thereon instructions, the computer-readable storage medium comprising: When the instructions in the computer readable storage medium are executed by the processor of the electronic device, the electronic device can execute the fault detection method of any one of claims 1-7.
Citation Information
Patent Citations
Method and system for detecting abnormal threading
CN103839007A
Jamming positioning method and device
CN111625456A