Customized log capturing method and device for ANR problem of Android system and readable storage medium

By instrumenting and caching messages in the Android system, grouping and marking the processing time of message, forming an environment state information cache queue, the problem of insufficient information in the existing ANR exception capture mechanism is solved, and more effective and real-time exception capture and problem location are achieved.

CN119718933APending Publication Date: 2025-03-28FAW VOLKSWAGEN AUTOMOTIVE CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411826162.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-12
Publication Date
2025-03-28

AI Technical Summary

Technical Problem

The ANR exception capture mechanism of the existing Android system captures less information and cannot effectively perform systematic analysis. Moreover, the native exception capture mechanism has been a period of time after the problem occurs at the capture time, and cannot completely save and reproduce the environment when the problem occurs.

Method used

When caching messages through instrumentation processing, the messages are grouped according to their attributes and marked according to the processing time to form an environment state information cache queue. When ANR occurs, the cache queue information is printed out to quickly trace the environment when the problem occurs, and reduce the startup of new threads and processes through thread pool optimization.

Benefits of technology

It realizes that the current system environment and the process stack that really causes exceptions can be captured in a timely manner when ANR occurs, with higher effectiveness and real-time performance, and can identify key exception information more quickly and locate problems.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119718933A_ABST
    Figure CN119718933A_ABST
Patent Text Reader

Abstract

The invention provides a customized log capture method and device for an ANR problem of an Android system and a machine readable storage medium, and the method comprises the steps: caching a current message mirror image into a processing service after receiving a message to form an environment state information buffer queue, and recording the corresponding attribute and message processing duration; grouping the messages by taking the target object and the callback attribute as classification standards; marking the message according to the processing duration; dynamically modifying a current environment state information cache queue according to the CPU consumption proportion of the system; and when the ANR occurs, the currently stored cache queue information is printed, so that the environment when the problem occurs can be quickly backtracked and reproduced through the printed environment state information cache queue information when the ANR occurs.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention belongs to the technical field of application exception handling, and in particular relates to a customized log capture method, device and machine-readable storage medium for the ANR problem of an Android system. Background Art

[0002] Due to the complexity of the current Android system, with many processes and a relatively complex framework, when an ANR occurs in the system or application, the native framework captures less information, which is insufficient for further systematic analysis. Therefore, a log capture framework customized for the ANR problem is needed.

[0003] The current native exception capture mechanism prints the stack of the currently blocked thread after the ANR occurs. However, in most cases, the current thread or stack printed is not the thread or stack that causes the ANR, but the ANR phenomenon occurs in the current thread due to other threads blocking the message channel, causing the entire machine to freeze or low memory, and the message blocking of the current thread is caused by other threads or the entire machine freezing. In addition, since the problem is captured some time after the problem occurs, it is impossible to completely save and reproduce the environment when the problem occurs.

[0004] Invention patent content

[0005] In view of the above problems, the present invention provides a customized log capture method, device and machine-readable storage medium for the ANR problem of the Android system. When caching messages through instrumentation processing, the messages are grouped according to their attributes and marked according to the processing time, so that when ANR occurs, the environment when the problem occurs can be quickly traced back through the printed environment status information cache queue information. The technical purpose of the present invention is achieved through the following technical solutions:

[0006] The present invention first provides a customized log capture method for the ANR problem of the Android system, which includes:

[0007] After receiving the message, the current message image is cached in the processing service to form an environment status information cache queue, and its corresponding attributes and message processing time are recorded; preferably, a new service is created in the system, and plugging is performed in the message and handler base classes. After receiving the message, the current message is cached as an image in the processing service, and its corresponding attributes are recorded;

[0008] Messages are grouped based on the target and callback attributes. Messages with the same target and callback attributes belong to the same group.

[0009] Mark the message according to the processing time; preferably, when marking the message, the message that will directly cause the ANR time is marked separately as the first mark, such as marking it as high; a set of multiple repeated types of messages are marked as the second mark, such as marking it as middle; the message processing time can be calculated by the time difference between the message sending and processing, which is used to determine whether the current message is blocked. By marking the message, it is convenient to quickly identify key abnormal information when ANR occurs later;

[0010] Based on the system CPU consumption ratio as the judgment standard, the current environment status information cache queue is dynamically modified to ensure that abnormal information can be effectively captured under different system loads;

[0011] When an ANR occurs, the currently saved cache queue information is printed. Preferably, the cache queue information includes the target and package name information of the message that currently causes the exception, so that the problem can be quickly located later.

[0012] Furthermore, when ANR occurs, the startup of new threads and processes is reduced. To prevent new ANRs caused by additional printing, the startup of new threads and processes is optimized, and the internal thread management is optimized using a thread pool.

[0013] The present invention further provides a customized log capture device for the ANR problem of the Android system, which includes:

[0014] The instrumentation processing module is used to instrument the message and handler base classes and record the message processing time.

[0015] Message classification and caching module, used to group and cache messages;

[0016] A marking module is used to mark messages according to the processing time of the messages;

[0017] The cache queue adjustment module is used to dynamically adjust the size of the environment status information cache queue according to the CPU consumption ratio;

[0018] The log printing module is used to print the environment status information and cache queue information when ANR occurs.

[0019] Furthermore, the device also includes a thread optimization module for reducing the startup of new threads and processes when ANR occurs.

[0020] The present invention also provides a machine-readable storage medium having a computer program stored thereon, wherein when the computer program is run, the aforementioned method is executed to realize customized log capture.

[0021] The beneficial effect of the present invention is that compared with the exception capture solution in the native field, the method of the present invention can timely capture the current system environment when the exception occurs, as well as the process stack that actually causes the exception, and can monitor the messages of the current abnormal process and obtain information, which is more effective and real-time than the native solution. BRIEF DESCRIPTION OF THE DRAWINGS

[0022] Figure 1 Shown is a schematic diagram of the process of the customized log capture method of the present invention;

[0023] Figure 2 The figure shows a schematic diagram of the message grouping mechanism and the dynamic modification of the cache queue of the present invention;

[0024] Figure 3 The diagram shows the process leading to ANR problem and exception capture;

[0025] Figure 4 Shown is a schematic diagram of a customized log capturing device of the present invention. DETAILED DESCRIPTION

[0026] The technical scheme of the preferred embodiment of the present invention will be clearly and completely described below in conjunction with the accompanying drawings. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.

[0027] This embodiment provides a customized log capture method for the ANR problem of the Android system. The specific implementation process of this method is to start a new service in the system and perform instrumentation processing in the message and handler base classes:

[0028] Step S1: After receiving the message, cache the current message as a mirror in the processing service and record its corresponding attributes;

[0029] Step S2: Group messages using the same target and callback attributes as classification criteria, such as Figure 2 As shown;

[0030] Step S3: Marking according to the message processing time. For example, marking the message that directly causes the ANR time as high, and marking a set of multiple repeated message types as middle.

[0031] Step S4: dynamically modify the current environment status information cache queue based on the system CPU consumption ratio as a judgment standard,

[0032] Step S5: When an exception such as ANR occurs in the system, the currently saved cache queue information is printed, and the target, package name and other related information of the message that currently causes the exception are printed, such as Figure 3 This provides information support for the subsequent analysis.

[0033] In a preferred embodiment, when ANR occurs, the startup of new threads and processes is reduced. To prevent new ANRs caused by additional printing, the startup of new threads and processes is optimized and reduced, and the internal thread management is optimized using a thread pool.

[0034] This embodiment also provides a customized log capture device for the ANR problem of the Android system, such as Figure 4 As shown, the device comprises:

[0035] The instrumentation processing module 10 is used to perform instrumentation processing on the message and the handler base class and record the processing time of the message;

[0036] A message classification and caching module 20, for grouping and caching messages;

[0037] A marking module 30, used to mark messages according to the processing time of the messages;

[0038] The cache queue adjustment module 40 is used to dynamically adjust the environment status information cache queue according to the CPU consumption ratio;

[0039] The log printing module 50 is used to print the environment status information and cache queue information when ANR occurs.

[0040] In a preferred embodiment, the device further includes a thread optimization module 60 for reducing the startup of new threads and processes when an ANR occurs.

[0041] This embodiment also provides a machine-readable storage medium, on which a computer program is stored. When the computer program is run, the aforementioned method is executed to achieve customized log capture.

[0042] Finally, it should be noted that the above preferred embodiments are only used to illustrate the technical solutions of the present invention rather than to limit it. Although the present invention has been described in detail through the above preferred embodiments, those skilled in the art should understand that various changes can be made in form and details without departing from the scope defined by the claims of the present invention. The dimensions described in the drawings and embodiments are not related to the specific objects and are not used to limit the protection scope of the present invention. The dimensions of the objects can be selected and changed according to actual needs.

Claims

1. A customized log capture method for the ANR problem of the Android system, comprising: After receiving the message, the current message image is cached in the processing service to form an environment status information cache queue, and its corresponding attributes and message processing time are recorded; Group messages based on target objects and callback attributes as classification criteria; Mark messages based on processing time; Dynamically modify the current environment status information cache queue according to the system CPU consumption ratio; Print the currently saved cache queue information when an ANR occurs.

2. According to claim 1, a customized log capture method for the ANR problem of the Android system is characterized in that: When marking messages, the messages that will directly cause the ANR duration are marked separately as the first message.

3. According to claim 2, a customized log capture method for the ANR problem of the Android system is characterized in that: When marking the messages, a plurality of message sets of repeated types are marked second.

4. According to claim 1, a customized log capture method for the ANR problem of the Android system is characterized in that: Reduce the startup of new threads and processes when ANR occurs.

5. According to claim 1, a customized log capture method for the ANR problem of the Android system is characterized in that: When the cache queue information includes the target object and package name information of the message that currently causes the exception.

6. A customized log capture device for the ANR problem of the Android system, comprising: The instrumentation processing module is used to instrument messages and handle base classes and record the processing time of messages; Message classification and caching module, used to group and cache messages; A marking module is used to mark messages according to the processing time of the messages; The cache queue adjustment module is used to dynamically adjust the size of the environment status information cache queue according to the CPU consumption ratio; The log printing module is used to print the environment status information and cache queue information when ANR occurs.

7. A customized log capture device for the ANR problem of the Android system according to claim 6, characterized in that: Also included is a thread optimization module to reduce the launching of new threads and processes when ANR occurs.

8. A machine-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed, the method according to any one of claims 1 to 5 is executed.