Log recording method and device for fault location

By creating a running status monitoring thread in the application, periodically obtaining process status information and writing to log files, the problem of difficulty in locating business failures in the existing technology is solved, and rapid positioning and analysis of application failures is realized, and development efficiency is improved.

CN119917333AInactive Publication Date: 2025-05-02CLOUD ATTACK NETWORK TECH HEBEI CO LTD
View PDF 5 Cites 0 Cited by

Patent Information

Application Number
CN202510405573.0
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2025-04-02
Publication Date
2025-05-02
Estimated Expiration
Not applicable · inactive patent

AI Technical Summary

Technical Problem

It is difficult for the prior art to locate business failures in programs that do not generate fault signals, such as dead loops, blocking and suspending.

Method used

By creating a running status monitoring thread, the application's process status information, including CPU usage, is periodically obtained. If the CPU usage is greater than the threshold, it is judged that the application has a failure and write the process ID, process status information and stack information to the business log file.

Benefits of technology

The rapid and accurate location of application failures can help developers analyze and improve applications, thereby improving development efficiency and reducing costs.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119917333A_ABST
    Figure CN119917333A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of information processing, in particular to a log recording method and device for fault positioning. The method comprises the steps that a main thread of an application program is started; creating a business log file of the application program; creating and starting a service execution thread used for executing the application program service; obtaining a process ID of the application program; a running state monitoring thread of the application program is created and started, and the running state monitoring thread is used for periodically obtaining process state information corresponding to the application program; and writing the process ID, the process state information and the process stack information of the application program into the business log file according to the process state information. When the application runs, the root of the fault problem can be quickly and accurately positioned, and a developer can further analyze and improve the defects of the application, so that the application development efficiency is improved, and the development cost is reduced.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present application relates to the field of information processing technology, and in particular to a log recording method and device for fault location. Background Art

[0002] In the actual program development process, there will inevitably be some unexpected fault scenarios that cause program failure problems, such as deadlock, infinite loop, memory access failure, slow IO, etc.; in order to locate and solve various program failure problems, the prior art usually adopts a stack backtracking method, that is, when the program starts, registers and takes over the key system signal. When the fault signal is triggered, the call stack information of the current thread is output to the log file through the stack backtracking function, so that subsequent relevant personnel can analyze the fault stack information of the log file to locate the cause of the program crash.

[0003] However, the stack backtracking method used in the prior art can only locate the fault problem that causes the program to crash, but cannot locate some business faults that are easy to exist in the program and do not generate fault signals, such as dead loops, blocking and hanging, etc. Summary of the invention

[0004] To achieve the above objectives, this application provides the following technical solutions: According to a first aspect of the present invention, the present invention claims a logging method for fault location, the method comprising the following steps: Step S1, start the main thread of the application; Step S2, creating a business log file of the application; Step S3, creating and starting a service execution thread for executing the application service; Step S4, obtaining the process ID of the application; Step S5, create and start the running status monitoring thread of the application, the running status monitoring thread is used to periodically obtain the process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application into the business log file according to the process status information.

[0005] Furthermore, the step S5 comprises the following steps: Enter a loop that includes the following steps: Step S501, obtaining process status information corresponding to the application; Step S502, obtaining the CPU usage in the process status information. If the CPU usage is greater than a first threshold, it is determined that the application has a fault, and step S503 is executed. If the CPU usage is less than or equal to the first threshold, it is determined that the application has no fault, and step S504 is executed. Step S503, writing the process ID, the process status information and the process stack information of the application into the business log file, and exiting the loop; Step S504, wait for a clock cycle, the clock cycle is 1 millisecond or 1 second, and return to step S501.

[0006] Furthermore, the step S503 further includes: Obtaining, according to the process ID, a thread number corresponding to a thread in the process of the application program whose CPU usage is greater than a second threshold; Acquire thread stack information corresponding to the thread number according to the thread number; The thread stack information is written into the business log file.

[0007] Furthermore, in the step S503, the process ID, the process status information, the process stack information of the application, and the thread stack information are written into the business log file, including: The process status information includes: process ID, user, virtual memory size, physical memory size, shared memory size, process status, CPU usage, memory usage, and running time; The process stack information of the application includes: thread information, call stack, lock information, class loading information, fault information, system information, and java virtual machine information; The thread stack information includes: thread name, thread ID, thread status, lock status, and function call relationship.

[0008] According to a second aspect of the present invention, the present invention claims protection for a logging device for fault location, the device comprising: An initialization unit, used to start the main thread of the application, create a business log file of the application, create and start a business execution thread for executing the business of the application, and obtain the process ID of the application; An execution unit is used to create and start a running status monitoring thread of the application, wherein the running status monitoring thread is used to periodically obtain process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application into the business log file according to the process status information.

[0009] Further, the execution unit is used to create and start a running status monitoring thread of the application, the running status monitoring thread is used to periodically obtain process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application to the business log file according to the process status information, specifically for: Enter a loop that includes the following steps: Step S501, obtaining process status information corresponding to the application; Step S502, obtaining the CPU usage in the process status information. If the CPU usage is greater than a first threshold, it is determined that the application has a fault, and step S503 is executed. If the CPU usage is less than or equal to the first threshold, it is determined that the application has no fault, and step S504 is executed. Step S503, writing the process ID, the process status information and the process stack information of the application into the business log file, and exiting the loop; Step S504, wait for a clock cycle, the clock cycle is 1 millisecond or 1 second, and return to step S501.

[0010] Further, the execution unit, when used to write the process ID, the process status information, and the process stack information of the application program into the business log file, is further used to: Obtaining, according to the process ID, a thread number corresponding to a thread in the process of the application program whose CPU usage is greater than a second threshold; Acquire thread stack information corresponding to the thread number according to the thread number; The thread stack information is written into the business log file.

[0011] Further, the execution unit, when used to write the process ID, the process status information, the process stack information of the application, and the thread stack information into the business log file, specifically includes: The process status information includes: process ID, user, virtual memory size, physical memory size, shared memory size, process status, CPU usage, memory usage, and running time; The process stack information of the application includes: thread information, call stack, lock information, class loading information, fault information, system information, and java virtual machine information; The thread stack information includes: thread name, thread ID, thread status, lock status, and function call relationship.

[0012] The present application relates to the field of information processing technology, and in particular to a log recording method and device for fault location, which starts the main thread of an application; creates a business log file of the application; creates and starts a business execution thread for executing the business of the application; obtains the process ID of the application; creates and starts the running status monitoring thread of the application, and the running status monitoring thread is used to periodically obtain the process status information corresponding to the application, and writes the process ID, the process status information and the process stack information of the application to the business log file according to the process status information. The present invention can quickly and accurately locate the root cause of the fault problem when the application is running, which is conducive to the developer to further analyze and improve the defects of the application, thereby improving the efficiency of application development and reducing development costs. BRIEF DESCRIPTION OF THE DRAWINGS

[0013] Figure 1 A workflow diagram of a log recording method for fault location claimed in an embodiment of the present application; Figure 2 This is a structural module diagram of a log recording device for fault location as claimed in an embodiment of the present application. DETAILED DESCRIPTION

[0014] The following will be combined with the drawings in the embodiments of the present application to clearly and completely describe the technical solutions in the embodiments of the present application. Obviously, the described embodiments are only part of the embodiments of the present application, not all of the embodiments. Based on the embodiments in the present application, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of this application.

[0015] The terms "first", "second" and "third" in this application are only used for descriptive purposes and cannot be understood as indicating or implying relative importance or implicitly indicating the number of indicated technical features. Therefore, the features defined as "first", "second" and "third" can explicitly or implicitly include at least one of the features. In the description of this application, the meaning of "multiple" is at least two, such as two, three, etc., unless otherwise clearly and specifically defined. All directional indications (such as up, down, left, right, front, back...) in the embodiments of this application are only used to explain the relative position relationship, movement, etc. between the components under a certain specific posture (as shown in the accompanying drawings). If the specific posture changes, the directional indication also changes accordingly. In addition, the terms "including" and "having" and any of their variations are intended to cover non-exclusive inclusions. For example, a process, method, system, product or device that includes a series of steps or units is not limited to the listed steps or units, but optionally also includes steps or units that are not listed, or optionally also includes other steps or units inherent to these processes, methods, products or devices.

[0016] Reference to "embodiments" herein means that a particular feature, structure, or characteristic described in conjunction with the embodiments may be included in at least one embodiment of the present application. The appearance of the phrase in various locations in the specification does not necessarily refer to the same embodiment, nor is it an independent or alternative embodiment that is mutually exclusive with other embodiments. It is explicitly and implicitly understood by those skilled in the art that the embodiments described herein may be combined with other embodiments.

[0017] According to a first embodiment of the present invention, the present invention claims a logging method for fault location, referring to Figure 1 , the method comprises the following steps: Step S1, start the main thread of the application; Step S2, creating a business log file of the application; Step S3, creating and starting a service execution thread for executing the application service; Step S4, obtaining the process ID of the application; Step S5, create and start the running status monitoring thread of the application, the running status monitoring thread is used to periodically obtain the process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application into the business log file according to the process status information.

[0018] Furthermore, the step S5 comprises the following steps: Enter a loop that includes the following steps: Step S501, obtaining process status information corresponding to the application; Step S502, obtaining the CPU usage in the process status information. If the CPU usage is greater than a first threshold, it is determined that the application has a fault, and step S503 is executed. If the CPU usage is less than or equal to the first threshold, it is determined that the application has no fault, and step S504 is executed. Step S503, writing the process ID, the process status information and the process stack information of the application into the business log file, and exiting the loop; Step S504, wait for a clock cycle, the clock cycle is 1 millisecond or 1 second, and return to step S501.

[0019] Among them, in this embodiment, the time threshold is first set to a relatively small value. When the page response time exceeds this value, the local generated fault log can be used to see whether the positioning is effective. The shorter the time threshold, the more obvious the effect. Since the page response time of Android applications is usually 1 to 2 seconds, the time threshold value can be set to 500 milliseconds. After the packaged and compiled apk is started, you can perform any number of operations to see the fault logs collected in the directory in the SIM card partition of the mobile phone. If there is a fault log, it indicates that the positioning is successful, otherwise it is unsuccessful and prompts a positioning error.

[0020] Check whether the currently running application meets the standard, that is, whether the CPU usage continues to rise and does not decrease, and whether the variables in the application stack are expired. The detection method can be to set the CPU threshold to 60%, give the current CPU usage every 1 second, and compare it. When the threshold is exceeded, a fault warning is issued; The fault location tool monitors the page refresh time when the application is running. If it exceeds the preset time threshold, a fault warning is issued. If it does not exceed the preset time threshold, the fault location tool monitors the CPU usage and application stack. When the CPU usage exceeds the set threshold and variables are saved in the application stack, a fault warning is issued and the relevant operation records of the application and mobile client within a certain time before the fault warning is issued are recorded.

[0021] Furthermore, the step S503 further includes: Obtaining, according to the process ID, a thread number corresponding to a thread in the process of the application program whose CPU usage is greater than a second threshold; Acquire thread stack information corresponding to the thread number according to the thread number; The thread stack information is written into the business log file.

[0022] Among them, in this embodiment, the average CPU usage of the application server is periodically obtained; whether the CPU usage of the CPU where each application thread in all application processes is located is greater than the average CPU usage is determined one by one; if it is greater and the difference between the two is greater than a preset threshold, the application thread is migrated to other CPUs on the application server.

[0023] When receiving a creation request for a target application task, starting an application process of the target application task, and adding a process number corresponding to the application process and thread numbers corresponding to all application threads included in the application process to a preset application process table; When a deletion request of a target application task is received, the application process of the target application task is terminated, and the process number corresponding to the application process and the thread numbers corresponding to all application threads included in the application process are deleted from a preset application process table.

[0024] Determine the application processes on the application server one by one according to the application process table; For each application thread in the application process, obtaining the CPU usage rate of the CPU where the application thread is located one by one; It is determined whether the CPU usage of the CPU where the application thread is located is greater than the average CPU usage.

[0025] If it is greater than, and the difference between the two is greater than a preset threshold, determining the target CPU with the lowest CPU usage on the application server and the CPU usage of the application thread; If the sum of the CPU usage of the application thread and the CPU usage of the target CPU is less than or equal to the sum of the average CPU usage and a preset threshold, the application thread is migrated to the target CPU.

[0026] Furthermore, in the step S503, the process ID, the process status information, the process stack information of the application, and the thread stack information are written into the business log file, including: The process status information includes: process ID, user, virtual memory size, physical memory size, shared memory size, process status, CPU usage, memory usage, and running time; The process stack information of the application includes: thread information, call stack, lock information, class loading information, fault information, system information, and java virtual machine information; The thread stack information includes: thread name, thread ID, thread status, lock status, and function call relationship.

[0027] Among them, in this embodiment, the JAVA capture unit that can generate JAVA files, of course, other units can also be selected, for example, the monitor unit (captures the situation of threads when competing for shared resources, including waiting for locks, holding locks, waiting conditions, etc.), the thread unit (captures thread-related situations, including thread status, thread call stack, thread lock information, etc.), the compilation unit (captures the compilation situation of the Java program, including compiled classes, compilation time, etc.), the system unit System (captures system-related situations, including system configuration information, system environment variables, system properties, etc.), Deadlock: detects and captures deadlock situations, that is, the situation where multiple threads wait for each other to release resources, resulting in the inability to continue executing the program.

[0028] According to a second embodiment of the present invention, the present invention claims a log recording device for fault location, referring to Figure 2 , the device comprises: An initialization unit, used to start the main thread of the application, create a business log file of the application, create and start a business execution thread for executing the business of the application, and obtain the process ID of the application; An execution unit is used to create and start a running status monitoring thread of the application, wherein the running status monitoring thread is used to periodically obtain process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application into the business log file according to the process status information.

[0029] Further, the execution unit is used to create and start a running status monitoring thread of the application, the running status monitoring thread is used to periodically obtain process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application to the business log file according to the process status information, specifically for: Enter a loop that includes the following steps: Step S501, obtaining process status information corresponding to the application; Step S502, obtaining the CPU usage in the process status information. If the CPU usage is greater than a first threshold, it is determined that the application has a fault, and step S503 is executed. If the CPU usage is less than or equal to the first threshold, it is determined that the application has no fault, and step S504 is executed. Step S503, writing the process ID, the process status information and the process stack information of the application into the business log file, and exiting the loop; Step S504, wait for a clock cycle, the clock cycle is 1 millisecond or 1 second, and return to step S501.

[0030] Further, the execution unit, when used to write the process ID, the process status information, and the process stack information of the application program into the business log file, is further used to: Obtaining, according to the process ID, a thread number corresponding to a thread in the process of the application program whose CPU usage is greater than a second threshold; Acquire thread stack information corresponding to the thread number according to the thread number; The thread stack information is written into the business log file.

[0031] Further, the execution unit, when used to write the process ID, the process status information, the process stack information of the application, and the thread stack information into the business log file, specifically includes: The process status information includes: process ID, user, virtual memory size, physical memory size, shared memory size, process status, CPU usage, memory usage, and running time; The process stack information of the application includes: thread information, call stack, lock information, class loading information, fault information, system information, and java virtual machine information; The thread stack information includes: thread name, thread ID, thread status, lock status, and function call relationship.

[0032] In the several embodiments provided in the present application, it should be understood that the disclosed systems, devices and methods can be implemented in other ways. For example, the device embodiments described above are only schematic. For example, the division of units is only a logical function division. There may be other division methods in actual implementation, such as multiple units or components can be combined or integrated into another system, or some features can be ignored or not executed. Another point is that the mutual coupling or direct coupling or communication connection shown or discussed can be an indirect coupling or communication connection through some interfaces, devices or units, which can be electrical, mechanical or other forms.

[0033] In addition, each functional unit in each embodiment of the present 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 above integrated unit can be implemented in the form of hardware or in the form of software functional units. The above is only an implementation method of the present application, and does not limit the patent scope of the present application. Any equivalent structure or equivalent process transformation made using the contents of the specification and drawings of this application, or directly or indirectly used in other related technical fields, is also included in the patent protection scope of the present application.

[0034] The specific implementation methods of the invention are described in detail above, but they are only examples, and the present application is not limited to the specific implementation methods described above. For those skilled in the art, any equivalent modification or substitution of the invention is also within the scope of the present application, and therefore, the equalization, modification, and improvement made without departing from the spirit and principle of the present application should be included in the scope of the present application.

Claims

1. A log recording method for fault location, characterized in that: The method comprises the following steps: Step S1, start the main thread of the application; Step S2, creating a business log file of the application; Step S3, creating and starting a service execution thread for executing the application service; Step S4, obtaining the process ID of the application; Step S5, create and start the running status monitoring thread of the application, the running status monitoring thread is used to periodically obtain the process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application into the business log file according to the process status information.

2. The log recording method for fault location according to claim 1, characterized in that: The step S5 comprises the following steps: Enter a loop that includes the following steps: Step S501, obtaining process status information corresponding to the application; Step S502, obtaining the CPU usage in the process status information. If the CPU usage is greater than a first threshold, it is determined that the application has a fault, and step S503 is executed. If the CPU usage is less than or equal to the first threshold, it is determined that the application has no fault, and step S504 is executed. Step S503, writing the process ID, the process status information and the process stack information of the application into the business log file, and exiting the loop; Step S504, wait for a clock cycle, the clock cycle is 1 millisecond or 1 second, and return to step S501.

3. The log recording method for fault location according to claim 2, characterized in that: The step S503 further includes: Obtaining, according to the process ID, a thread number corresponding to a thread in the process of the application program whose CPU usage is greater than a second threshold; Acquire thread stack information corresponding to the thread number according to the thread number; The thread stack information is written into the business log file.

4. The log recording method for fault location according to claim 3, characterized in that: In the step S503, the process ID, the process status information, the process stack information of the application, and the thread stack information are written into the business log file, including: The process status information includes: process ID, user, virtual memory size, physical memory size, shared memory size, process status, CPU usage, memory usage, and running time; The process stack information of the application includes: thread information, call stack, lock information, class loading information, fault information, system information, and java virtual machine information; The thread stack information includes: thread name, thread ID, thread status, lock status, and function call relationship.

5. A log recording device for fault location, characterized in that: The device comprises: An initialization unit, used to start the main thread of the application, create a business log file of the application, create and start a business execution thread for executing the business of the application, and obtain the process ID of the application; An execution unit is used to create and start a running status monitoring thread of the application, wherein the running status monitoring thread is used to periodically obtain process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application into the business log file according to the process status information.

6. The log recording device for fault location according to claim 5, characterized in that: The execution unit is used to create and start a running status monitoring thread of the application, the running status monitoring thread is used to periodically obtain process status information corresponding to the application, and write the process ID, the process status information and the process stack information of the application into the business log file according to the process status information, specifically for: Enter a loop that includes the following steps: Step S501, obtaining process status information corresponding to the application; Step S502, obtaining the CPU usage in the process status information. If the CPU usage is greater than a first threshold, it is determined that the application has a fault, and step S503 is executed. If the CPU usage is less than or equal to the first threshold, it is determined that the application has no fault, and step S504 is executed. Step S503, writing the process ID, the process status information and the process stack information of the application into the business log file, and exiting the loop; Step S504, wait for a clock cycle, the clock cycle is 1 millisecond or 1 second, and return to step S501.

7. The log recording device for fault location according to claim 6, characterized in that: The execution unit, when used to write the process ID, the process status information, and the process stack information of the application program into the business log file, is further used to: Obtaining, according to the process ID, a thread number corresponding to a thread in the process of the application program whose CPU usage is greater than a second threshold; Acquire thread stack information corresponding to the thread number according to the thread number; The thread stack information is written into the business log file.

8. The log recording device for fault location according to claim 7, characterized in that: The execution unit, when used to write the process ID, the process status information, the process stack information of the application, and the thread stack information into the business log file, specifically includes: The process status information includes: process ID, user, virtual memory size, physical memory size, shared memory size, process status, CPU usage, memory usage, and running time; The process stack information of the application includes: thread information, call stack, lock information, class loading information, fault information, system information, and java virtual machine information; The thread stack information includes: thread name, thread ID, thread status, lock status, and function call relationship.

Citation Information

Patent Citations

  • System restarting reason detection method, device and terminal equipment

    CN103942113A

  • Application program monitoring method and device

    CN108345524A

  • Cross-node application performance monitoring method and device and high-performance computing system

    CN109976989A

  • Method and device for detecting abnormal utilization rate of central processing unit and storage medium

    CN115658475A

  • Method and system for adaptively generating process chain detection rule

    CN118468280A