A program thread stall monitoring method, device, equipment and medium
By creating process communication pipes and connection monitoring services in the Windows system, the problem of missing information when threads are stuck is solved, and effective monitoring and anomaly analysis of thread stucks are achieved.
Patent Information
- Application Number
- CN202311568632.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-11-22
- Publication Date
- 2025-12-19
- Estimated Expiration
- 2043-11-22
AI Technical Summary
Existing thread monitoring methods are prone to information loss when thread stalls occur, making it impossible to perform effective anomaly analysis and accurately locate the location of the anomaly.
In Windows systems, a process communication pipe is created by calling the mapping component and connecting to the monitoring service. A detection command is sent to the mapping component to locate the target program thread and perform thread checks. If no acknowledgment command is received within the preset response timeout interval, a process snapshot of the target program thread is saved and a timeout acknowledgment message is output.
Effectively storing process snapshots of threads and saving thread information in a timely manner improves the accuracy of anomaly analysis and facilitates subsequent location of anomalies.
Smart Images

Figure CN117591365B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application relates to the technical field of thread blocking monitoring, and in particular to a program thread blocking monitoring method, device, equipment and medium. BACKGROUND
[0002] With the continuous complication of application program functions, efficient and reliable exception handling mechanisms become increasingly important for the development of application programs, especially for the development of multi-threaded environments.
[0003] In actual business development, many resident work threads are often involved, and as the complexity of the business increases, a large number of multi-threaded technologies are required to be enabled between business modules to process the business. When multi-threading processes business exceptions in high concurrency, it may cause thread blocking, and thus cause business interruption, making it difficult to troubleshoot specific problems in a short period of time.
[0004] Among the thread exception types, thread blocking is a relatively common exception type, and the existing thread monitoring means is prone to information loss when thread blocking occurs, making it difficult to perform effective exception analysis and accurately locate the exception occurrence position. SUMMARY
[0005] The present application provides a program thread blocking monitoring method, device, equipment and medium, which solves the technical problem that the existing thread monitoring means is prone to information loss when thread blocking occurs, making it difficult to perform effective exception analysis and accurately locate the exception occurrence position.
[0006] The program thread blocking monitoring method provided by the present application is applied to a Windows system, and the method comprises:
[0007] When a host program is accessed, a mapping component is called to create a process communication pipeline and connect a monitoring service;
[0008] The monitoring service sends a detection instruction to the mapping component through the process communication pipeline;
[0009] The mapping component responds to the detection instruction, locates a target program thread corresponding to the detection instruction from the host program, and performs thread checking;
[0010] If no confirmation instruction of the thread checking is received within a preset reply timeout interval, the monitoring service saves a process snapshot of the target program thread and outputs a timeout confirmation information.
[0011] Optionally, the step of calling the mapping component to create the process communication pipeline and connecting the monitoring service when the host program is accessed comprises:
[0012] When the access host program, call mapping components registered callback interface;
[0013] Through the call component with a preset programming library to create process communication pipeline;
[0014] Through the call component to start the monitoring service, and the monitoring service is connected to the process communication pipeline.
[0015] Optionally, the monitoring service is provided with a built-in timer; the step of sending a detection instruction to the mapping component through the monitoring service via the process communication pipeline, comprising:
[0016] Through the monitoring service using the built-in timer set reply timeout interval, and generate corresponding detection instruction;
[0017] Through the monitoring service via the process communication pipeline sends the detection instruction to the mapping component.
[0018] Optionally, if the preset reply timeout interval is not received within the thread check confirmation instruction, the step of saving the process snapshot of the target program thread through the monitoring service, and output timeout confirmation information, comprising:
[0019] If the preset reply timeout interval is not received within the thread check confirmation instruction, the monitoring service saves the process snapshot of the target program thread at the current time;
[0020] Through the monitoring service via the process communication pipeline sends timeout instruction to the mapping component;
[0021] Through the mapping component via the callback interface output timeout confirmation information.
[0022] Optionally, the method further comprises:
[0023] If the preset reply timeout interval is received within the thread check confirmation instruction, the step of returning the reply instruction to the monitoring service through the process communication pipeline by the mapping component.
[0024] Optionally, the method further comprises:
[0025] When the monitoring service receives a reply instruction, reset the built-in timer;
[0026] Jump to execute the step of setting the reply timeout interval through the monitoring service using the built-in timer, and generate corresponding detection instruction.
[0027] Optionally, the method further comprises:
[0028] When the host program exits the access, the process communication pipe is interrupted to stop the monitoring service.
[0029] The application provides a program thread jam monitoring device applied to a Windows system, and the device comprises:
[0030] An initialization module is configured to call a mapping component to create a process communication pipe and connect a monitoring service when the host program accesses.
[0031] A detection instruction sending module is configured to send a detection instruction to the mapping component through the monitoring service via the process communication pipe.
[0032] A thread checking module is configured to locate a target program thread corresponding to the detection instruction from the host program and perform thread checking through the mapping component in response to the detection instruction.
[0033] A timeout execution module is configured to save a process snapshot of the target program thread through the monitoring service and output timeout confirmation information if no confirmation instruction of the thread checking is received within a preset reply timeout interval.
[0034] The application further provides an electronic device comprising a memory and a processor, wherein the memory stores a computer program, and the computer program is executed by the processor to enable the processor to perform the steps of the program thread jam monitoring method according to any one of the above.
[0035] The application further provides a computer readable storage medium storing a computer program, and the computer program is executed to implement the program thread jam monitoring method according to any one of the above.
[0036] As can be seen from the above technical solutions, the application has the following advantages:
[0037] When the Windows system accesses the host program, a mapping component is called to create a process communication pipe and connect a monitoring service; a detection instruction is sent to the mapping component through the monitoring service via the process communication pipe; a target program thread corresponding to the detection instruction is located from the host program and thread checking is performed through the mapping component in response to the detection instruction; when no confirmation instruction of the thread checking is received within a preset reply timeout interval, a process snapshot of the target program thread is saved through the monitoring service, and timeout confirmation information is returned to the host program, so that the process snapshot of the thread can be effectively stored in the case of thread jam or death, and the thread information is timely saved, and effective abnormal analysis is facilitated, and the positioning accuracy of the abnormal position is improved. BRIEF DESCRIPTION OF DRAWINGS
[0038] In order to more clearly illustrate the technical solutions in the embodiments of the present application or the prior art, the drawings needed to be used in the embodiments or prior art description will be briefly introduced. Obviously, the drawings in the following description only constitute some embodiments of the present application, and for those skilled in the art, other drawings can also be obtained without creative labor.
[0039] Figure 1 A step flow chart of a program thread jam monitoring method provided by an embodiment of the present application.
[0040] Figure 2 A step flow chart of a program thread jam monitoring method provided by another embodiment of the present application.
[0041] Figure 3 An execution logic diagram of a thread checking process provided by an embodiment of the present application.
[0042] Figure 4 An execution logic diagram of a thread checking timeout process provided by an embodiment of the present application.
[0043] Figure 5 A structural block diagram of a program thread jam monitoring device provided by an embodiment of the present application. DETAILED DESCRIPTION
[0044] The embodiments of the present application provide a program thread jam monitoring method, device, equipment and medium, which are used to solve the technical problem that the existing thread monitoring means is prone to information loss when thread jam occurs, which leads to the fact that subsequent effective abnormal analysis cannot be performed and the abnormal position cannot be accurately located.
[0045] In order to make the purposes, features and advantages of the present application more obvious and easy to understand, the technical solutions in the embodiments of the present application will be described clearly and completely in combination with the drawings in the embodiments of the present application. Obviously, the embodiments described below only constitute some of the embodiments of the present application, rather than all the embodiments. Based on the embodiments in the present application, all other embodiments obtained by those skilled in the art without creative labor fall within the scope of the present application.
[0046] Please refer to Figure 1 , Figure 1 A step flow chart of a program thread jam monitoring method provided by an embodiment of the present application.
[0047] The program thread jam monitoring method provided by the present application is applied to a Windows system, and comprises the following steps.
[0048] In step 101, when a host program is accessed, a mapping component is called to create a process communication pipe and connect a monitoring service.
[0049] The host program refers to a functional program applied in the Windows system, which includes multiple resident threads.
[0050] The mapping component refers to a host interface exported by host.dll.
[0051] The process communication pipe refers to a communication pipe created by ASIO to realize network communication. ASIO is a set of asynchronous IO frameworks implemented by c++, especially under Windows, because the IOCP of the Windows system is highly consistent with the proactor design pattern of ASIO, and can achieve better performance. The main purpose of using ASIO is to achieve process isolation, provide an IPC framework, and prevent the monitoring program from affecting the performance of the host program.
[0052] The monitoring service refers to a service type component loaded with multiple tasks related to monitoring logic, which can be monitor.
[0053] In the embodiment of the application, when the user accesses the host program in the Windows system, the Windows system initializes the monitoring service by calling the mapping component such as the host interface, registering the callback interface, creating the process communication pipe through ASIO, and connecting it to the monitoring service.
[0054] Step 102, sending a detection instruction to the mapping component through the process communication pipe by the monitoring service;
[0055] After the connection between the monitoring service and the process communication pipe is completed, because the monitoring logic of the monitoring service has been preloaded on the monitoring service, the monitoring service can communicate with the mapping component through the process communication pipe, send the corresponding detection instruction to the mapping component, and trigger the stall detection of the host program.
[0056] Step 103, responding to the detection instruction through the mapping component, locating the target program thread corresponding to the detection instruction from the host program, and performing thread checking;
[0057] In this embodiment, the mapping component responds to the detection instruction, triggers the stall detection of the host program, locates the target program thread specified by the detection instruction from the host program, and performs thread checking according to the predetermined checking logic.
[0058] It should be noted that the checking logic of thread checking can be various. For example, by remotely calling thread injection, the Windows system displays prompt information or waits for a click instruction, etc., responds to the user trigger to generate a confirmation instruction, and returns a reply instruction to the monitoring service through the mapping component to inform that the current program thread responds normally and there is no stall situation.
[0059] If the confirmation instruction of the thread check is not received within the preset reply timeout interval, the monitoring service saves the process snapshot of the target program thread and outputs the timeout confirmation information.
[0060] In the embodiment, after the target program thread performs the thread check, the target program thread displays the check completion or other prompt information. If the confirmation instruction for the thread check is not received within the preset reply timeout interval, it indicates that the target program thread may be in a situation of freezing or being deadlocked, and cannot display the prompt information or respond to the confirmation instruction. At this time, to prevent the target program thread from being lost, the monitoring service can call the system API of the Windows system to save the process snapshot of the target program thread. At the same time, the monitoring service returns the timeout confirmation information to the host program through the callback interface, so as to inform the user that the target program thread is in a situation of freezing or being deadlocked.
[0061] In the embodiment of the application, when the Windows system accesses the host program, the mapping component is called to create a process communication pipe and connect the monitoring service. The monitoring service sends a detection instruction to the mapping component through the process communication pipe. The mapping component responds to the detection instruction, locates the target program thread corresponding to the detection instruction from the host program, and performs thread check. When the confirmation instruction of the thread check is not received within the preset reply timeout interval, the monitoring service saves the process snapshot of the target program thread and returns the timeout confirmation information to the host program, so that in the case of freezing or being deadlocked of the thread, the process snapshot of the thread can be effectively stored, the thread information is saved in time, and the positioning accuracy of the abnormal position is improved.
[0062] Please refer to Figure 2 , Figure 2 A flowchart of a program thread freezing monitoring method provided by the embodiment of the application.
[0063] The program thread freezing monitoring method provided by the application is applied to the Windows system and includes the following steps.
[0064] In step 201, when accessing the host program, the mapping component is called to create a process communication pipe and connect the monitoring service.
[0065] In one example of the application, step 201 can include the following substeps.
[0066] When accessing the host program, the mapping component is called to register the callback interface.
[0067] The process communication pipe is created by calling the component using a preset programming library.
[0068] The monitoring service is started by calling the component and connected to the process communication pipeline.
[0069] In the embodiment of the present application, when the host program is accessed, it indicates that the monitoring service is needed to monitor the stall of some threads in the host program at this time. At this time, the callback interface can be registered by calling the mapping component in response to the calling instruction or calling operation of the user. Specifically, the callback function can be specified through the interface exported by the host.dll, so as to complete the registration of the callback interface.
[0070] After the registration of the callback interface is completed, the process communication pipeline can be created by the calling component using a preset programming library such as ASIO, and at the same time, the monitoring service is started by the calling component. The monitoring service is connected to the monitoring communication pipeline, so as to complete the establishment of the communication connection between the calling component and the monitoring service, and complete the preparation before the thread monitoring is started.
[0071] In a specific implementation, the host establishes a named pipe to receive the connection of the monitor, and the system API has a corresponding notification, that is, the connection is considered to be successful.
[0072] Optionally, the monitoring service is provided with a built-in timer;
[0073] In step 202, the reply timeout interval is set by the monitoring service using the built-in timer, and the corresponding detection instruction is generated;
[0074] The reply timeout interval refers to the maximum time interval from the sending of the detection instruction to the receiving of the reply instruction by the monitoring service, which can be set together when the timeout task of the monitoring service is set.
[0075] In the embodiment, the reply timeout interval is set by the monitoring service using the built-in timer, which is used as the judgment standard for the thread stall or death. At the same time, since different program threads can have different judgment standards, different reply timeout intervals can be set when different program threads are monitored, and the detection instruction corresponding to the reply timeout interval is generated.
[0076] The detection instruction is a special signaling data format data instruction, which is used to trigger the mapping component to perform thread checking, for example, a check instruction.
[0077] In step 203, the detection instruction is sent to the mapping component by the monitoring service through the process communication pipeline.
[0078] After the detection instruction is generated, it is sent to the mapping component by the monitoring server through the process communication pipeline, so as to inform the mapping component that the thread checking of a program thread is needed.
[0079] Step 204, locating the target program thread corresponding to the detection instruction from the host program and performing thread checking through the mapping component in response to the detection instruction;
[0080] In the embodiment, after the mapping component receives the detection instruction, the target program thread specified by the detection instruction can be located from the multiple program threads of the host program, and thread checking is performed on the target program thread, for example, the thread state is checked through thread injection.
[0081] It should be noted that thread injection can be code injection, which is a technology of inserting independent running code into a target process and making it run, and generally calls the CreateRemoteThread() API to run the inserted code in the form of a remote thread, also known as thread injection. The code is inserted in the form of a thread procedure (ThreadProcedure), and the data used in the code is inserted in the form of a thread parameter, that is, the code and data are inserted separately. DLL injection is suitable for cases where the code amount is large and complex, and code injection is suitable for cases where the code amount is small and simple. DLL injection requires that the injected code be placed in a certain DLL file first, and then the entire DLL file is injected into the target process. All data used in the DLL code is located in the data area of the DLL, and the code and data coexist in the memory when the entire DLL is inserted into the target process, so the code can be executed normally. Code injection only injects the necessary code into the target process, and in order to make the injected code run normally, the data used in the code must also be injected. In addition, the advantages of code injection are: less memory occupation; difficult to find traces; no need for additional DLL files.
[0082] In another example of the present application, the method further comprises the following steps:
[0083] If the confirmation instruction of the thread checking is received within the preset reply timeout interval, the reply instruction is returned to the monitoring service through the process communication pipe by the mapping component.
[0084] Further, the method further comprises the following steps:
[0085] When the monitoring service receives the reply instruction, the built-in timer is reset;
[0086] The step of setting the reply timeout interval by the monitoring service using the built-in timer and generating the corresponding detection instruction is jumped to execute.
[0087] In the embodiment, if the confirmation instruction of the thread checking is received within the preset reply timeout interval, the reply instruction, such as the check ack instruction, can be returned to the monitoring service through the process communication pipe by the mapping component. When the monitoring service receives the reply instruction, the built-in timer is reset through the monitoring service, and the step 202 is jumped to execute.
[0088] It should be noted that after resetting the built-in timer, since the detection commands can correspond to different target program threads, the response timeout intervals for each target program thread can be compiled into an execution table. This allows the monitoring service to generate the corresponding detection commands sequentially. Furthermore, if only the same target program thread is being targeted, the corresponding detection command can be directly generated and sent to the mapping component for thread checking according to a preset detection cycle.
[0089] like Figure 3 As shown, Figure 3 This diagram illustrates the execution logic of a thread checking process according to an embodiment of the present invention. The monitoring service is named "monitor," the built-in timer is named "Timer," the host program is named "host," the mapping component is named "host," and the user is named "user." Specifically, it may include the following steps a to f:
[0090] a) Use a Timer to create a timeout task;
[0091] b) Through the process communication pipe established above, the monitor sends the check command to the host (which can be understood as a special signaling data format);
[0092] c) After receiving the command, the Host switches to the corresponding target thread through thread injection to perform thread checks;
[0093] d) If the host receives a confirmation command from the user, it sends a check ack (which can be understood as a special signaling data format) command to the monitor through the inter-process communication pipe;
[0094] e) After receiving the check ack, the Monitor resets the Timer.
[0095] f) Repeat steps a to f.
[0096] Step 205: If no confirmation instruction for thread checking is received within the preset response timeout period, the process snapshot of the target program thread is saved through the monitoring service, and timeout confirmation information is output.
[0097] Furthermore, step 205 may include the following sub-steps:
[0098] If no confirmation instruction for thread checking is received within the preset response timeout period, the process snapshot of the target program thread at the current moment is saved through the monitoring service.
[0099] The monitoring service sends a timeout command to the mapping component via the process communication pipe.
[0100] The timeout confirmation information is output by the mapping component through the callback interface.
[0101] In the embodiment, if the confirmation instruction of the thread check is not received within the preset reply timeout interval, it indicates that the target program thread is stuck or cannot respond at this time, at this time, the process snapshot of the target program thread at the current time can be saved by the monitoring service using the system API to store the parameters of the target program thread. The timeout instruction is sent by the monitoring service to the mapping component through the process communication pipe to inform the mapping component that the user needs to be informed, at this time, the timeout confirmation information can be output to the external terminal or the user by the mapping component through the previously registered callback interface.
[0102] Please refer to Figure 4 , Figure 4 is an execution logic diagram of a thread check timeout process in the embodiment of the application. The monitoring service is monitor, the built-in timer is Timer, the host program is host program, the mapping component is host, and the user is user. The execution logic diagram can include the following steps a-c.
[0103] a) The monitor saves the process snapshot using the system API;
[0104] b) The timeout instruction (which can be understood as a special signaling data format) is sent to the host through the pipe established above;
[0105] c) The host informs the user through the registered callback.
[0106] In a specific implementation, the monitoring service loads the detection task into the timer to start, and sends a detection request to the host to make the host call the detection request to the target thread set, and the monitoring service and the host are connected through the ASIO established IPC channel; in the case where the confirmation character is not accepted from the terminal, the monitoring service saves the process snapshot, and sends a timeout notification to the host to make the host send a timeout confirmation message to the user, wherein the confirmation character is used to confirm whether the timer is timed out.
[0107] It should be noted that when the confirmation instruction is received within the reply timeout interval, the execution logic of the above step 205 can be triggered, and the execution logic can be set by the timeout task.
[0108] In an example of the application, the method further includes the following steps:
[0109] When the host program exits the access, the process communication pipe is interrupted to stop the monitoring service.
[0110] In a specific implementation, when the host program exits, the ASIO receives a pipe disconnection notification, the monitor exits immediately, and thus the process inspection on the host program is stopped.
[0111] In addition, the use of the ASIO to establish the IPC channel is isolated from the host program, and the influence on the host program is reduced.
[0112] In the embodiment of the application, when the Windows system accesses the host program, the mapping component is called to create a process communication pipe and connect a monitoring service; the monitoring service sends a detection instruction to the mapping component through the process communication pipe; the mapping component responds to the detection instruction, locates a target program thread corresponding to the detection instruction from the host program, and performs thread inspection; when no confirmation instruction of the thread inspection is received within a preset reply timeout interval, the monitoring service saves a process snapshot of the target program thread, and returns timeout confirmation information to the host program, so that in the case that the thread is stuck or deadlocked, the process snapshot of the thread can be effectively stored, the thread information is timely saved, and effective abnormal analysis is facilitated, and the positioning accuracy of the abnormal position is improved.
[0113] Please refer to Figure 5 , Figure 5 A structural block diagram of a program thread sticking monitoring device is shown.
[0114] The application provides a program thread sticking monitoring device applied to a Windows system, and the device comprises:
[0115] The initialization module 501 is configured to call a mapping component to create a process communication pipe and connect a monitoring service when the host program is accessed.
[0116] The detection instruction sending module 502 is configured to send a detection instruction to the mapping component through the process communication pipe by the monitoring service.
[0117] The thread inspection module 503 is configured to respond to the detection instruction by the mapping component, locate a target program thread corresponding to the detection instruction from the host program, and perform thread inspection.
[0118] The timeout execution module 504 is configured to save a process snapshot of the target program thread by the monitoring service if no confirmation instruction of the thread inspection is received within a preset reply timeout interval, and output timeout confirmation information.
[0119] Optionally, the initialization module 501 is specifically configured to:
[0120] When the host program is accessed, a callback interface of the mapping component is registered.
[0121] The process communication pipe is created by the calling component using a preset programming library.
[0122] The monitoring service is started by calling the component and connected to the process communication pipeline.
[0123] Optionally, the monitoring service is provided with a built-in timer; the detection instruction sending module 502 is specifically configured to:
[0124] The built-in timer is set by the monitoring service to set a reply timeout interval, and a corresponding detection instruction is generated;
[0125] The detection instruction is sent by the monitoring service to the mapping component through the process communication pipeline.
[0126] Optionally, the timeout execution module 504 is specifically configured to:
[0127] If the confirmation instruction of the thread check is not received within the preset reply timeout interval, the process snapshot of the target program thread at the current time is saved by the monitoring service;
[0128] The timeout instruction is sent by the monitoring service to the mapping component through the process communication pipeline.
[0129] The timeout confirmation information is output by the mapping component through the callback interface.
[0130] Optionally, the device further comprises:
[0131] The reply execution module is configured to, if the confirmation instruction of the thread check is received within the preset reply timeout interval, return the reply instruction to the monitoring service through the process communication pipeline by the mapping component.
[0132] Optionally, the device further comprises:
[0133] The timer resetting module is configured to, when the monitoring service receives the reply instruction, reset the built-in timer.
[0134] The loop module is configured to jump to execute the step of setting the reply timeout interval by the monitoring service using the built-in timer, and generating a corresponding detection instruction.
[0135] Optionally, the device further comprises:
[0136] The service stopping module is configured to, when the host program exits the access, interrupt the process communication pipeline to stop the monitoring service.
[0137] The application further provides an electronic device comprising a memory and a processor, the memory stores a computer program, and the computer program is executed by the processor to make the processor execute the steps of the program thread stall monitoring method according to any one of the above.
[0138] The application further provides a computer readable storage medium, which stores a computer program, and the computer program is executed to implement the program thread lag monitoring method according to any one of the preceding embodiments.
[0139] Those skilled in the art can clearly understand that, for the convenience and brevity of description, the specific working processes of the above-described devices and modules can refer to the corresponding processes in the foregoing method embodiments, which will not be described herein.
[0140] In the several embodiments provided by the present application, it should be understood that the disclosed devices and methods can be implemented in other manners. For example, the described device embodiments are merely schematic. For example, the division of the modules is merely a logical function division. For another example, an optional component can be added or a component can be omitted. For another example, the internal structure of a component can also be divided into other forms. In addition, the coupling or direct coupling or communication connection between the modules can be indirect coupling or communication connection through some interfaces, or mechanical or electrical or other forms.
[0141] The modules described as separated components can or can not be physically separated, and the components displayed as modules can or can not be physical modules, i.e., can be located in one place, or can be distributed on a plurality of network modules. Some or all of the modules can be selected according to actual needs to achieve the purposes of the embodiments.
[0142] In addition, each functional module in the various embodiments of the present application can be integrated in one processing module, or each module can exist physically independently, or two or more modules can be integrated in one module. The integrated module can be realized in the form of hardware or in the form of a software functional module.
[0143] When the integrated module is realized in the form of a software functional module and sold or used as an independent product, it can be stored in a computer readable storage medium. Based on this understanding, the technical solutions of the present application essentially or the part that contributes to the prior art or the whole or part of the technical solutions can be embodied in the form of a software product. The computer software product is stored in a storage medium, and includes a plurality of instructions for causing an electronic device (which can be a personal computer, a server, or a network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present application. The foregoing 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.
[0144] The above-described and above-embodied examples are merely used to illustrate the technical solutions of the present application, but not to limit the present application; although the present application has been described in detail with reference to the foregoing examples, those skilled in the art should understand that the technical solutions recorded in the foregoing examples can be modified, or some technical features can be replaced by equivalent features; and these modifications or replacements do not make the essence of the corresponding technical solutions deviate from the spirit and scope of the technical solutions of the embodiments of the present application.
Claims
1. A method for monitoring program thread stalls, the method comprising: The method is applied to a Windows system and comprises the following steps: When accessing a host program, a mapping component is called to create a process communication pipe and connect a monitoring service; the mapping component is a host interface exported by host.dll; The monitoring service sends a detection instruction to the mapping component through the process communication pipe; The mapping component locates a target program thread corresponding to the detection instruction from the host program in response to the detection instruction and switches to the corresponding target thread to perform thread checking by thread injection; If no confirmation instruction of the thread checking is received within a preset reply timeout interval, the monitoring service saves a process snapshot of the target program thread and outputs timeout confirmation information; The step of calling the mapping component to create the process communication pipe and connect the monitoring service when accessing the host program comprises the following steps: When accessing the host program, a mapping component is called to register a callback interface; A process communication pipe is created by a calling component using a preset programming library; The monitoring service is started by the calling component and connected to the process communication pipe; The monitoring service is provided with a built-in timer; the step of sending the detection instruction to the mapping component through the process communication pipe by the monitoring service comprises the following steps: The built-in timer is used by the monitoring service to set a reply timeout interval, each target program thread is respectively assigned a corresponding reply timeout interval as an execution table, and corresponding detection instructions are sequentially generated in order; The detection instruction is sent to the mapping component through the process communication pipe by the monitoring service.
2. The method of claim 1, wherein, The step of saving a process snapshot of the target program thread at the current time by the monitoring service and outputting timeout confirmation information if no confirmation instruction of the thread checking is received within a preset reply timeout interval comprises the following steps: If no confirmation instruction of the thread checking is received within a preset reply timeout interval, the monitoring service saves a process snapshot of the target program thread at the current time; A timeout instruction is sent to the mapping component through the process communication pipe by the monitoring service; Timeout confirmation information is outputted by the mapping component through the callback interface.
3. The method of claim 1, wherein, The method further comprises the following steps: If a confirmation instruction of the thread checking is received within a preset reply timeout interval, a reply instruction is returned to the monitoring service through the process communication pipe by the mapping component.
4. The method of claim 3, wherein, The method further comprises the following steps: When the monitoring service receives a reply instruction, the built-in timer is reset; The step of setting a reply timeout interval by the monitoring service using the built-in timer and generating corresponding detection instructions is jumped to execute.
5. The method of claim 1, wherein, The method further comprises the following steps: When the host program exits access, the process communication pipe is interrupted to stop the monitoring service.
6. A program thread stall monitoring apparatus, comprising: The device is applied to a Windows system and comprises the following components: An initialization module is configured to call a mapping component to create a process communication pipe and connect a monitoring service when accessing a host program; the mapping component is a host interface exported by host.dll; The detection instruction sending module is configured to send detection instructions to the mapping component through the monitoring service via the process communication pipeline. The thread checking module is configured to locate target program threads corresponding to the detection instructions from the host program in response to the detection instructions via the mapping component, and switch to the corresponding target threads to perform thread checking by means of thread injection. The timeout execution module is configured to save a process snapshot of the target program threads via the monitoring service and output timeout confirmation information if no confirmation instruction of the thread checking is received within a preset reply timeout interval. The initialization module is specifically configured to: register a callback interface of the mapping component when accessing the host program; create a process communication pipeline by calling a component using a preset programming library; start the monitoring service by the calling component, and connect the monitoring service to the process communication pipeline; the monitoring service is provided with a built-in timer; and the detection instruction sending module is specifically configured to: set a reply timeout interval by the monitoring service using the built-in timer, make each target program thread correspondingly set as an execution table, and generate corresponding detection instructions in sequence; send the detection instructions to the mapping component through the monitoring service via the process communication pipeline.
7. An electronic device, comprising: The computer program is executed to implement the program thread stall monitoring method according to any one of claims 1-5.
8. A computer-readable storage medium having stored thereon a computer program, characterized in that, The computer program is executed to implement the program thread stall monitoring method according to any one of claims 1-5.
Citation Information
Patent Citations
Container monitoring method and apparatus
CN105389243A
Thread jamming identification method and apparatus
CN106708710A
Interface lagging detection method and device and electronic equipment
CN115964208A