Method and device for processing dead loop, electronic equipment and storage medium
By monitoring the number of instructions and function call stacks of script functions, the system automatically detects and interrupts infinite loops, thus solving the infinite loop problem, achieving efficient fault location and resolution, and improving the server's processing capacity.
Patent Information
- Application Number
- CN202411505079.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2024-10-25
- Publication Date
- 2026-02-13
- Estimated Expiration
- 2044-10-25
AI Technical Summary
In existing technologies, dead loop problems are difficult to locate and troubleshoot accurately, resulting in low location efficiency, low accuracy, and long resolution cycles, and may even lead to major project accidents.
By monitoring the number of instructions and function call stacks of preset script functions, setting preset thresholds and conditions, the system can automatically detect and interrupt infinite loop stacks, thus breaking the infinite loop.
It achieves fault location accurate to the function point level, greatly shortens the dead loop location time, improves the efficiency of server dead loop troubleshooting, automatically breaks dead loops, and avoids server shutdown.
Smart Images

Figure CN119883691B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of program control, and in particular to a dead loop processing method and device, electronic equipment and storage medium. BACKGROUND
[0002] In the development and maintenance process of a game server, a dead loop problem is often encountered. Such a problem is generally difficult to reproduce in a native or test internal environment, and is difficult to locate and troubleshoot. Two ways of troubleshooting the dead loop problem are provided in the related art. One is to manually analyze the static code to propose code that may cause the dead loop. The other is to add log information to the code part that may have a problem, and then observe after testing and going online. However, the above-mentioned way not only has low dead loop positioning efficiency and accuracy, but also has a long dead loop problem solving period. SUMMARY
[0003] The present application aims to provide a dead loop processing method and device, electronic equipment and storage medium to accurately locate the dead loop in a program and timely solve the dead loop problem.
[0004] In a first aspect, the present application provides a dead loop processing method, which comprises: running a preset script function and monitoring the number of instructions executed when the preset script function is running; if the number of instructions is greater than a preset number threshold, acquiring and recording the function call stack when the preset script function executes the instructions; determining the number of times the function call stack is recorded within a preset time period, and if the number of times meets a preset condition, determining that the function call stack is a dead loop stack; and interrupting the execution of the dead loop stack to resolve the current dead loop.
[0005] In a second aspect, the present application provides a dead loop processing device, which comprises: a number monitoring module configured to run a preset script function and monitor the number of instructions executed when the preset script function is running; a stack acquisition module configured to acquire and record the function call stack when the preset script function executes the instructions if the number of instructions is greater than a preset number threshold; a dead loop determination module configured to determine the number of times the function call stack is recorded within a preset time period, and if the number of times meets a preset condition, determine that the function call stack is a dead loop stack; and a dead loop resolution module configured to interrupt the execution of the dead loop stack to resolve the current dead loop.
[0006] In a third aspect, the present application provides an electronic device comprising a processor and a memory, the memory storing machine executable instructions executable by the processor, and the processor executes the machine executable instructions to implement the above-mentioned dead loop processing method.
[0007] In a fourth aspect, the present disclosure provides a computer-readable storage medium storing computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the method for processing a dead loop.
[0008] The embodiments of the present application bring the following beneficial effects:
[0009] The method for processing a dead loop, the device, the electronic equipment and the storage medium provided by the present application firstly run a preset script function, and monitor the number of instructions executed when the preset script function is running; if the number of instructions is greater than a preset number threshold, the function call stack when the preset script function executes the instructions is acquired and recorded; then the number of times of recording of the function call stack within a preset time period is determined, and if the number of times of recording meets a preset condition, the function call stack is determined as a dead loop stack; then the execution of the dead loop stack is interrupted to eliminate the current dead loop. The method can realize fault positioning to the function point level by monitoring the number of instruction executions and the number of times of recording of the function call stack, greatly shortens the dead loop positioning time; at the same time, the method automatically eliminates the dead loop after finding the problem of the dead loop, and improves the server dead loop troubleshooting efficiency.
[0010] Other features and advantages of the present application will be described in the following description, or can be known from the description, or can be determined without doubt, or can be known by implementing the above-mentioned technologies of the present application.
[0011] In order to make the above-mentioned purposes, features and advantages of the present application more obvious and easy to understand, the following preferred embodiments are specifically described in detail below, and the accompanying drawings are described as follows. BRIEF DESCRIPTION OF DRAWINGS
[0012] In order to more clearly illustrate the specific embodiments of the present application or the technical solutions in the prior art, the following will briefly introduce the drawings needed to be used in the specific embodiments or the prior art description. Obviously, the drawings in the following description are some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor on the basis of these drawings.
[0013] Figure 1 A flow chart of a method for processing a dead loop provided by an embodiment of the present application;
[0014] Figure 2 A structure schematic diagram of a dead loop processing device provided by an embodiment of the present application;
[0015] Figure 3 A structure schematic diagram of an electronic equipment provided by an embodiment of the present application. DETAILED DESCRIPTION
[0016] In order to make the objects, technical solutions and advantages of the embodiments of the present application clearer, the following will clearly and completely describe the technical solutions in the embodiments of the present application with reference to the drawings in the embodiments of the present application. Obviously, the described embodiments are only some but not all of the embodiments of the present application. The components of the embodiments of the present application described and shown in the drawings can be arranged and designed in various different configurations.
[0017] Therefore, the following detailed description of the embodiments of the present application provided in the drawings is not intended to limit the scope of the claimed application, but only represents selected embodiments of the present application. Based on the embodiments in the present application, all other embodiments obtained by those of ordinary skill in the art without creative labor fall within the scope of protection of the present application.
[0018] In the development and maintenance process of a game server, a dead loop problem is often encountered. Such a problem is generally difficult to reproduce in a native or test internal environment, and is difficult to locate and troubleshoot. The related art provides two ways to troubleshoot the dead loop problem. One is to manually analyze the static code to propose code that may cause the dead loop. The other is to add log information to the code part that may have a problem, and then observe after testing and going online. However, the above-mentioned way not only has low dead loop positioning efficiency and accuracy, but also has a long dead loop problem solving period, and may even cause a major project accident when encountering a severe problem.
[0019] In the related art, the processing method of the network game server falling into the dead loop first detects the dead loop. When it is determined that the main thread falls into the dead loop, the guardian thread suspends the main thread to temporarily stop its running. After the Lua language program of the main thread falls into the dead loop, through the processing of the guardian thread, the Lua runtime error is triggered actively to make it stop running, and then jump back to C / C++, so as to get rid of the dead loop. Then, through some subsequent processing, the same code is avoided to run again, so as to avoid falling into the dead loop again. However, the method involves multiple threads, the main thread and the monitoring thread, and needs to interact data of the main thread and the monitoring thread, which has a large implementation difficulty. Moreover, the thread data interaction involves thread communication, data consistency, thread safety, and deadlock, which needs to be handled very carefully.
[0020] Based on the above problems, the embodiments of the present application provide a dead loop processing method, device, electronic equipment and storage medium, which can be applied to the scene of dead loop discovery, detection and removal of a program.
[0021] In order to facilitate the understanding of the embodiments of the present application, first, a dead loop processing method disclosed by the embodiments of the present application is introduced in detail, such as Figure 1As shown, the method comprises the following specific steps:
[0022] In step S102, a preset script function is run, and the number of instructions executed when the preset script function is run is monitored.
[0023] In a specific implementation, the preset script function described above can be any script function currently running on the server. The programming language corresponding to the code of the preset script function can be determined according to research and development requirements. For example, the programming language can be C, C++, Python, or Lua. Specifically, when the preset script function is run, the code in the preset script function is parsed, compiled, and finally converted into a series of operation codes called instructions. These instructions control the flow and logic of the program, and each instruction corresponds to a specific operation, such as assignment, conditional judgment, function call, etc. When these instructions are executed, the code in the preset script function is interpreted and executed line by line, thereby realizing the functions of the entire program.
[0024] In actual application, while the preset script function is running, the number of instructions executed by the preset script function needs to be counted in real time, and the number of instructions needs to be monitored in real time. Monitoring the number of executed instructions can timely discover possible function calls with dead loops.
[0025] In step S104, if the number of instructions is greater than a preset number threshold, the function call stack when the preset script function executes instructions is obtained and recorded.
[0026] When monitoring the number of instructions executed while the preset script function is running, it is necessary to determine in real time whether the number of instructions is greater than a preset number threshold. If the number of instructions is greater than the preset number threshold, the function call stack called when the preset script function executes instructions needs to be obtained, and the obtained function call stack needs to be recorded for subsequent statistical analysis of the recorded function call stack. The specific number value corresponding to the preset number threshold can be determined according to research and development requirements. For example, since a dead loop usually has a large number of instructions executed in a short time, the preset number threshold can be set to a large value, such as 100 million or 80 million.
[0027] It should be noted that the function call stack is used to store temporary data during function calling and returning. The function call stack is managed by the operating system and is used to maintain the context of function calling to ensure the smooth progress of each function calling and returning. The function call stack mainly consists of two parts: stack (Stack) and heap (Heap). The stack is a memory area automatically allocated and released by the compiler and is used to store the parameter values and local variable values of functions. Its operation mode is similar to that of the stack in data structures and is used to maintain the context of function calling. The heap is a memory area allocated and released by the programmer and is usually used for dynamic memory allocation. The allocation mode of the heap is similar to that of a linked list and is a non-continuous memory area.
[0028] In step S106, it is determined whether the recorded number of function call stacks in the preset time period meets a preset condition. If the recorded number of function call stacks meets the preset condition, it is determined that the function call stack is a dead loop stack.
[0029] In a specific implementation, the specific time period corresponding to the preset time period can be determined according to a research and development requirement. For example, the preset time period can be 5 minutes or 3 minutes, etc. While recording the function call stacks, the recorded number of the same function call stacks in the preset time period is also counted. If the recorded number of the same function call stacks meets the preset condition, it is determined that the function call stack meeting the preset condition is a dead loop stack, that is, it is determined that the current server has a dead loop phenomenon.
[0030] The preset condition can be determined according to a research and development requirement. For example, the preset condition can be that the recorded number of function call stacks is within a preset number range, or the recorded number of function call stacks is greater than or equal to a preset number threshold. The preset number range and the preset number threshold can be determined according to a research and development requirement. For example, the preset number range can be (10, 20) or (20, 30), etc., and the preset number threshold can be 15 or 20, etc.
[0031] In step S108, the execution of the dead loop stack is interrupted to eliminate the current dead loop.
[0032] When it is determined that the function call stack is a dead loop stack, the execution of the dead loop stack is interrupted, so as to eliminate the current dead loop and make the server jump out of the current dead loop. The dead loop refers to a loop in which a program enters and repeatedly executes the same code.
[0033] The method for processing a dead loop provided by the embodiment of the application can realize fault positioning at a function point level by monitoring the number of instruction executions and the recorded number of function call stacks, greatly shortening the dead loop positioning time. Meanwhile, after the existence of a dead loop problem is found, the dead loop is automatically eliminated, improving the server dead loop troubleshooting efficiency.
[0034] The following embodiments are used to describe a method for determining the recorded number of function call stacks.
[0035] Specifically, the specific process of determining the recorded number of function call stacks in the preset time period can be implemented through the following steps 10-13.
[0036] In step 10, it is determined whether the function call stack is the same as the last recorded call stack. If the function call stack is the same as the last recorded call stack, step 11 is performed, otherwise, no operation is performed.
[0037] In a specific implementation, after recording the function call stack, it is necessary to detect whether the currently recorded function call stack is the same as the last recorded function call stack. If they are the same, it means that the server may have a dead loop. If they are not the same, it means that the server does not have a dead loop. Since the feature of a dead loop is always executing in the same function call stack, if it is found that the same function call stack is always alarmed or recorded each time, it means that there is a dead loop in the function call stack.
[0038] Step 11, determining the time interval of the function call stack and the recording time of the last recorded call stack.
[0039] Since a dead loop is always executing in the same function call stack, the function call stack will be called frequently in a short time. After it is determined that the currently recorded function call stack is the same as the last recorded call stack, it is further necessary to determine the time interval of the function call stack and the recording time of the last recorded call stack. Only when the time interval is small, it can be determined that a certain function call stack is continuously executed in a short time.
[0040] Step 12, judging whether the time interval is less than a preset time threshold. If yes, executing step 13; otherwise, executing step 14.
[0041] The specific duration corresponding to the above-mentioned preset time threshold can be determined according to the research and development needs. For example, the preset time threshold can be 10 seconds or 8 seconds, etc.
[0042] Step 13, adding 1 to the recorded number of times corresponding to the function call stack to update the recorded number of times corresponding to the function call stack.
[0043] Step 14, not updating the recorded number of times corresponding to the function call stack.
[0044] In a specific implementation, if the time interval of the function call stack and the recording time of the last recorded call stack is less than the preset time threshold, the recorded number of times corresponding to the function call stack is added once to obtain the updated recorded number of times. For example, the recorded number of times corresponding to the current function call stack is 5 times, and the updated recorded number of times obtained after the recorded number of times is added once is 6 times. If the time interval of the function call stack and the recording time of the last recorded call stack is not less than the preset time threshold, it means that the calling time interval of the two function call stacks is long, which does not meet the feature of continuously executing a certain function call stack in a dead loop, so the recorded number of times of the function call stack will not be updated.
[0045] The above-mentioned method can accurately obtain the recorded number of times of a certain function call stack, which is helpful for subsequent accurate positioning of the dead loop problem.
[0046] The following embodiments are used to describe the way of performing the loop detection.
[0047] Specifically, the specific process of monitoring the number of instructions executed when the preset script function is running can include: monitoring the number of instructions executed when the preset script function is running through the hook interface; and the monitoring event of the hook interface is set when the number of instructions executed when the preset script function is running is greater than the preset number threshold.
[0048] In a specific implementation, the preset script function can be written using the lua script language, and the lua script language provides a debug library containing a hook interface. The monitoring event of the hook interface can be set to listen to the monitoring event in real time through the hook interface when the preset script is running, and the subsequent loop detection judgment is performed after the hook interface listens to the monitoring event. The lua script language is a lightweight, efficient and embeddable script programming language.
[0049] The hook interface in the debug library is a programming technique that allows users or developers to extend or modify the functions of a program without changing the original program code. This technique registers specific hook points so that when a monitoring event occurs, the operating system or other software can notify the programs that have registered the corresponding hook. In this way, new functions or existing behaviors can be added or modified without modifying the original code, thereby achieving the extensibility and customizability of the program.
[0050] The monitoring event is a count event provided by a debug library, debug.sethook ([thread,] hook, mask [, count]). When setting the debug hook, the string parameter mask and the number parameter count indicate the timing of triggering the hook. The mask can be composed of the following characters, and each character has the following meaning: 'c' indicates that the hook is triggered every time a function call occurs; 'r' indicates that the hook is triggered every time a function returns;'s' indicates that the hook is triggered every time the next line of code is executed. In addition, when count is not zero, the hook is triggered after every count instructions are executed. When the function is called without parameters, the hook is closed. Whenever the hook is triggered, the first parameter passed in is a string describing the triggering event: "call", "tail call", "return", "line", and "count". For line events, the line number of the new line is also passed in as the second parameter of the hook. Inside the hook, getinfo can be called to get more information about the current function (level 2). (Level 0 is the getinfo function itself, and level 1 is the hook function.)
[0051] Based on the above description, if the number of instructions is greater than the preset number threshold, the specific process of obtaining and recording the function call stack when the preset script function executes instructions can include: if the monitoring event corresponding to the hook interface occurs, the handler interface registered by the hook interface is called back; the execution information of the preset script function is obtained through the handler interface, and the function call stack when the preset script function executes instructions is recorded in the execution information.
[0052] In specific implementation, the handler interface registers the hook interface in the debug library, so that when the preset script function is running, if the monitoring event monitored by the hook interface occurs, the registered handler interface will be triggered to obtain the execution information of the preset script function through the handler interface. The execution information includes the function call stack obtained by debug.getinfo and the variable information in the function call stack obtained by debug.getlocal. After obtaining the execution information, the function call stack can be obtained and recorded from the execution information.
[0053] It should be noted that the handler interface is an asynchronous processing interface, and the registered handler interface is called back when the monitoring event of the hook interface occurs. The above preset script function is triggered to run when receiving a protocol request from a client or executing a timer task.
[0054] Further, if the number of instructions is greater than a preset number threshold, a function call stack when the preset script function executes instructions is recorded in a log file, and alarm information is sent to a preset platform through a log monitoring system, the alarm information being used to indicate that the function call stack in the log file has a high probability of a dead loop. The preset platform can be a chat tool or a push platform.
[0055] In a specific implementation, the function call stack of the alarm is recorded in a log file, and a message of the log file is pushed to a chat tool through a log monitoring system, so that a user using the chat tool can receive the alarm information.
[0056] In order to facilitate understanding of the embodiments of the present application, it is assumed that the preset number threshold is 1 billion, and the preset condition is that the recorded number of times is greater than or equal to 20 times. Based on this, the present disclosure can be divided into the following three steps:
[0057] Step one, dead loop discovery. When the number of instructions executed by a certain Lua script function (equivalent to the preset script function) exceeds 1 billion, an alarm is given and a function call stack is output through a deug.hook interface provided by Lua. When the function call stack is output, the function call stack is recorded.
[0058] Step two, dead loop detection. Through a self-defined traceback interface, the time interval between the last record and the current record of the same function call stack is detected. If the interval time is less than 10 seconds, the recorded number of times of the function call stack is increased by 1. When the recorded number of times of the same function call stack exceeds 20 times, it means that the same function call stack executes more than 20 billion instructions, which is far more than a normal function call, and thus is determined as a dead loop stack. It can also be understood that the same function call stack appears frequently in a short time, and it is determined that there is a dead loop call.
[0059] Step three, dead loop automatic release. The dead loop stack is asserted to interrupt the execution of the current dead loop stack, so that the current dead loop can be released.
[0060] The above assertion is a technical means in programming, which is used to verify whether certain conditions are met during program execution, and if the conditions are met, the program continues to execute; otherwise, the program throws an exception or directly terminates. In specific implementation, the dead loop is always jumping in the same call stack, and the error will interrupt this call stack, and the dead loop can be exited. When the program encounters an error during execution, the principle of interrupting the current execution flow is due to the existence of an exception handling mechanism. In most programming languages, including Lua, an exception handling mechanism is provided to handle error conditions during program execution. When an error occurs during program execution, an exception is thrown, which is passed up the call stack until it is caught and handled by the appropriate exception handling mechanism. If there is no appropriate exception handling mechanism, the exception will be passed to the top of the program, causing the program to interrupt execution.
[0061] The above method can alarm the server dead loop at runtime; at the same time, the method can automatically resolve the dead loop problem at runtime, avoiding the server dead loop from being unable to provide services.
[0062] Corresponding to the above method embodiment, the embodiment of the application also provides a dead loop processing device, as shown in Figure 2 The device comprises:
[0063] The number monitoring module 20 is configured to run a preset script function and monitor the number of instructions executed when the preset script function is running.
[0064] The stack acquisition module 21 is configured to acquire and record the function call stack when the preset script function executes instructions if the number of instructions is greater than a preset number threshold.
[0065] The dead loop determination module 22 is configured to determine the number of times the function call stack is recorded within a preset time period, and determine that the function call stack is a dead loop stack if the number of times recorded satisfies a preset condition.
[0066] The dead loop resolution module 23 is configured to interrupt the execution of the dead loop stack to resolve the current dead loop.
[0067] The above dead loop processing device can realize fault positioning to the function point level by monitoring the number of instruction executions and the number of times the function call stack is recorded, greatly shortening the dead loop positioning time; at the same time, the method automatically resolves the dead loop after discovering the existence of the dead loop problem, improving the server dead loop troubleshooting efficiency.
[0068] Specifically, the aforementioned infinite loop determination module 22 is used to: determine whether the function call stack is the same as the previously recorded call stack; if they are the same, determine the time interval between the recording time of the function call stack and the previously recorded call stack; determine whether the time interval is less than a preset time threshold; if so, increment the number of times the function call stack is recorded by 1 to update the number of times the function call stack is recorded.
[0069] Furthermore, the aforementioned infinite loop determination module 22 is also used to: if the time interval is not greater than a preset time threshold, not update the number of times the function call stack is recorded.
[0070] Furthermore, the aforementioned preset conditions include: the number of times recorded is greater than or equal to a preset threshold number of times.
[0071] Furthermore, the aforementioned quantity monitoring module 20 is used to: monitor the number of instructions executed when a preset script function is run through a hook interface; wherein, a monitoring event of the hook interface is when the number of instructions executed when the preset script function is run exceeds a preset quantity threshold.
[0072] Furthermore, the stack acquisition module 21 described above is used to: if a monitoring event corresponding to the hook interface occurs, call back the handler interface of the registered hook interface; obtain the execution information of the preset script function through the handler interface, and record the function call stack of the preset script function execution instructions contained in the execution information.
[0073] Furthermore, the above-mentioned device also includes an alarm module, which is used to: if the number of instructions exceeds a preset threshold, record the function call stack when the preset script function executes the instructions in a log file, so as to send alarm information to the preset platform through the log monitoring system. The alarm information is used to indicate that there is a high probability that the function call stack in the log file contains an infinite loop.
[0074] The infinite loop processing device provided in this disclosure has the same implementation principle and technical effect as the aforementioned method embodiment. For the sake of brevity, any parts not mentioned in the device embodiment can be referred to the corresponding content in the aforementioned method embodiment.
[0075] This invention also provides an electronic device, such as... Figure 3 As shown, the electronic device includes a processor and a memory. The memory stores machine-executable instructions that can be executed by the processor, which executes the machine-executable instructions to implement the aforementioned infinite loop processing method.
[0076] Specifically, the method comprises: running a preset script function, and monitoring a number of instructions executed when the preset script function is running; if the number of instructions is greater than a preset number threshold, acquiring and recording a function call stack when the preset script function executes the instructions; determining a number of times the function call stack is recorded within a preset time period, and if the number of times meets a preset condition, determining the function call stack as a dead loop stack; and interrupting execution of the dead loop stack to resolve the current dead loop.
[0077] The method can realize fault positioning at a function point level, greatly shortening the dead loop positioning time, and automatically resolve the dead loop after discovering the dead loop problem, thereby improving the server dead loop troubleshooting efficiency.
[0078] In an optional embodiment, the step of determining the number of times the function call stack is recorded within the preset time period comprises: determining whether the function call stack is the same as a last recorded call stack; if so, determining a time interval between a recording time of the function call stack and a recording time of the last recorded call stack; determining whether the time interval is less than a preset time threshold; and if so, adding 1 to the number of times the function call stack is recorded to update the number of times the function call stack is recorded.
[0079] In an optional embodiment, the method further comprises: if the time interval is not greater than the preset time threshold, not updating the number of times the function call stack is recorded.
[0080] In an optional embodiment, the preset condition comprises: the number of times is greater than or equal to a preset number threshold.
[0081] In an optional embodiment, the step of monitoring the number of instructions executed when the preset script function is running comprises: monitoring the number of instructions executed when the preset script function is running through a hook interface; and the number of instructions executed when the preset script function is running is greater than a preset number threshold, which is a monitoring event of the hook interface.
[0082] In an optional embodiment, the step of acquiring and recording the function call stack when the preset script function executes the instructions if the number of instructions is greater than the preset number threshold comprises: if the monitoring event corresponding to the hook interface occurs, calling a handler interface registered to the hook interface; acquiring execution information of the preset script function through the handler interface, and recording the function call stack when the preset script function executes the instructions in the execution information.
[0083] In an optional embodiment, the method further comprises: if the number of instructions is greater than a preset number threshold, recording the function call stack at the time of executing the preset script function instruction in a log file, and sending an alarm information to a preset platform through a log monitoring system, the alarm information being used to indicate that the function call stack in the log file has a relatively high probability of a dead loop.
[0084] Further, Figure 3 The electronic device shown further includes a bus 102 and a communication interface 103, and the processor 101, the communication interface 103, and the memory 100 are connected through the bus 102.
[0085] The memory 100 can include a high-speed random access memory (RAM) and can further include a non-volatile memory such as at least one disk memory. The communication connection between the system network element and at least one other network element is realized through at least one communication interface 103 (which can be wired or wireless), and the Internet, a wide area network, a local area network, a metropolitan area network, etc. can be used. The bus 102 can be an ISA bus, a PCI bus, or an EISA bus, etc. The bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, Figure 3 Only one bidirectional arrow is used in the figure to represent the bus, but it does not mean that there is only one bus or only one type of bus.
[0086] The processor 101 can be an integrated circuit chip with signal processing capability. In the implementation process, each step of the above method can be completed by the integrated logic circuit of hardware in the processor 101 or the instruction in the form of software. The processor 101 described above can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field-programmable gate array (FPGA) or other programmable logic devices, discrete gates or transistor logic devices, discrete hardware components. Each method, step and logic block disclosed in the embodiment of the present application can be implemented or executed. The general-purpose processor can be a microprocessor or the processor can also be any conventional processor. The steps of the method disclosed in combination with the embodiment of the present application can be directly embodied as a hardware decoding processor for execution, or a combination of hardware and software modules in the decoding processor for execution. The software module can be located in a random access memory, a flash memory, a read-only memory, a programmable read-only memory or an electrically erasable programmable memory, a register, etc. The storage medium in the art. The storage medium is located in the memory 100, and the processor 101 reads the information in the memory 100, and combines the hardware to complete the steps of the method of the above embodiment.
[0087] The embodiment of the present application also provides a computer readable storage medium, the computer readable storage medium stores computer executable instructions, when the computer executable instructions are called and executed by the processor, the computer executable instructions cause the processor to implement the above dead loop processing method, for specific implementation, please refer to the method embodiment, and here is no longer tedious.
[0088] Specifically, the above dead loop processing method comprises: running a preset script function, and monitoring the number of instructions executed when the preset script function is running; if the number of instructions is greater than a preset number threshold, acquiring and recording the function call stack when the preset script function executes the instructions; determining the number of times the function call stack is recorded within a preset time period, and if the number of times satisfies a preset condition, determining that the function call stack is a dead loop stack; interrupting the execution of the dead loop stack to resolve the current dead loop.
[0089] The method can realize fault positioning at a function point level, greatly shortens the positioning time of the dead loop, and automatically removes the dead loop after finding the dead loop problem, thereby improving the server dead loop troubleshooting efficiency.
[0090] In an optional embodiment, the step of determining the recorded number of the function call stack in the preset time period comprises: determining whether the function call stack is the same as the last recorded call stack; if the function call stack is the same as the last recorded call stack, determining a time interval between the recording time of the function call stack and the last recorded call stack; determining whether the time interval is less than a preset time threshold; and if the time interval is less than the preset time threshold, adding 1 to the recorded number corresponding to the function call stack to update the recorded number corresponding to the function call stack.
[0091] In an optional embodiment, the method further comprises: if the time interval is not greater than the preset time threshold, not updating the recorded number corresponding to the function call stack.
[0092] In an optional embodiment, the preset condition comprises: the recorded number is greater than or equal to a preset number threshold.
[0093] In an optional embodiment, the step of monitoring the number of instructions executed when the preset script function is run comprises: monitoring the number of instructions executed when the preset script function is run through a hook interface; and the number of instructions executed when the preset script function is run is greater than a preset number threshold, which is a monitoring event of the hook interface.
[0094] In an optional embodiment, the step of, if the number of instructions is greater than the preset number threshold, acquiring and recording the function call stack when the preset script function executes instructions comprises: if the monitoring event corresponding to the hook interface occurs, calling a handler interface registered for the hook interface; acquiring execution information of the preset script function through the handler interface, and recording the function call stack when the preset script function executes instructions, which is contained in the execution information.
[0095] In an optional embodiment, the method further comprises: if the number of instructions is greater than the preset number threshold, recording the function call stack when the preset script function executes instructions in a log file, so as to send alarm information to a preset platform through a log monitoring system, and the alarm information is used to indicate that the function call stack in the log file has a relatively high probability of dead loop.
[0096] If the functions are implemented in the form of software function units and sold or used as independent products, they can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the parts that contribute to the prior art or parts of the technical solutions can be embodied in the form of a software product, which is stored in a storage medium and includes a number of instructions for causing a computer device (which can be a personal computer, a terminal device, or a network device, etc.) to execute all or part of the steps of the embodiments of the present application. The aforementioned storage medium includes: a U disk, a mobile hard disk, a read-only memory (ROM, Read-Only Memory), a random access memory (RAM, Random Access Memory), a magnetic disk or an optical disk, and various media that can store program codes.
[0097] In the description of the present application, it should be noted that the terms "center", "upper", "lower", "left", "right", "vertical", "horizontal", "inner", "outer" and the like indicate the orientation or positional relationship based on the orientation or positional relationship shown in the drawings, and are only for the convenience of describing the present application and simplifying the description, and do not indicate or imply that the devices or elements referred to must have a particular orientation, be constructed and operated in a particular orientation, and therefore cannot be understood as limiting the present application. In addition, the terms "first", "second", "third" are only for the purpose of description, and cannot be understood as indicating or implying relative importance.
[0098] Finally, it should be noted that: the above embodiments are only specific embodiments of the present application, used to illustrate the technical solutions of the present application, and are not limited thereto, the protection scope of the present application is not limited thereto, although the present application has been described in detail with reference to the foregoing embodiments, those skilled in the art should understand that any person skilled in the art within the technical range disclosed by the present application can still modify or easily think of changes to the technical solutions recorded in the foregoing embodiments, or make equivalent replacement to part of the technical features; and these modifications, changes or replacements do not make the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application, and should be covered within the protection scope of the present application. Therefore, the protection scope of the present application should be subject to the protection scope of the claims.
Claims
1. A method for handling infinite loops, characterized in that, The method includes: Run a preset script function and monitor the number of instructions executed when running the preset script function; If the number of instructions exceeds a preset threshold, obtain and record the function call stack when the preset script function is executed; Determine the number of times the function call stack is recorded within a preset time period. If the number of recorded times meets a preset condition, determine that the function call stack is an infinite loop stack. Interrupt the execution of the infinite loop stack to break the current infinite loop; The step of monitoring the number of instructions executed when the preset script function is run includes: monitoring the number of instructions executed when the preset script function is run through a hook interface; wherein, the number of instructions executed when the preset script function is run is greater than the preset number threshold as a monitoring event of the hook interface; The step of obtaining and recording the function call stack when the preset script function executes instructions if the number of instructions is greater than a preset threshold includes: if a monitoring event corresponding to the hook interface occurs, calling back the handler interface of the registered hook interface; obtaining the execution information of the preset script function through the handler interface, and recording the function call stack when the preset script function executes instructions contained in the execution information.
2. The method according to claim 1, characterized in that, The step of determining the number of times the function call stack is recorded within a preset time period includes: Determine whether the function call stack is the same as the previously recorded call stack; If they are the same, determine the time interval between the recording time of the function call stack and the recording time of the last recorded call stack; Determine whether the time interval is less than a preset time threshold. If so, increment the number of records corresponding to the function call stack by 1 to update the number of records corresponding to the function call stack.
3. The method according to claim 2, characterized in that, The method further includes: If the time interval is not greater than the preset time threshold, the number of times the function call stack is recorded will not be updated.
4. The method according to claim 1, characterized in that, The preset conditions include: the number of times recorded is greater than or equal to a preset number threshold.
5. The method according to claim 1, characterized in that, The method further includes: If the number of instructions exceeds a preset threshold, the function call stack of the preset script function execution instructions is recorded in a log file, so as to send an alarm message to the preset platform through the log monitoring system. The alarm message is used to indicate that there is a high probability of an infinite loop in the function call stack in the log file.
6. A processing device for an infinite loop, characterized in that, The device includes: The quantity monitoring module is used to run a preset script function and monitor the number of instructions executed when the preset script function is run; The stack acquisition module is used to acquire and record the function call stack when the preset script function is executed if the number of instructions is greater than a preset number threshold. The infinite loop determination module is used to determine the number of times the function call stack is recorded within a preset time period. If the number of recorded times meets a preset condition, the function call stack is determined to be an infinite loop stack. The infinite loop unblocking module is used to interrupt the execution of the infinite loop stack to unblock the current infinite loop; The quantity monitoring module is used to: monitor the number of instructions executed when the preset script function is run through a hook interface; wherein, the number of instructions executed when the preset script function is run is greater than the preset quantity threshold as a monitoring event of the hook interface; The stack acquisition module is used to: if a monitoring event corresponding to the hook interface occurs, call back the handler interface of the registered hook interface; obtain the execution information of the preset script function through the handler interface, and record the function call stack of the preset script function execution instructions contained in the execution information.
7. An electronic device, characterized in that, The system includes a processor and a memory, the memory storing machine-executable instructions that can be executed by the processor, the processor executing the machine-executable instructions to implement the infinite loop processing method according to any one of claims 1 to 5.
8. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores computer-executable instructions, which, when invoked and executed by a processor, cause the processor to implement the method for processing an infinite loop as described in any one of claims 1 to 5.
Citation Information
Patent Citations
Random test program generation method and device
CN106325827A
Software endless loop positioning method, device and system and storage medium
CN110750450A