Thread monitoring method, device, equipment and storage medium

By calling the monitoring thread in the application program to obtain the thread running parameters and call stack, the problem of inability to accurately diagnose application exceptions in the existing technology is solved, and accurate monitoring and diagnosis of application exceptions are achieved.

CN114328073BActive Publication Date: 2025-01-17SHENZHEN TENCENT COMP SYST CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202011081396.9
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2020-10-10
Publication Date
2025-01-17
Estimated Expiration
2040-10-10

AI Technical Summary

Technical Problem

In the prior art, the main thread running in the application is monitored, and the reasons for abnormal problems in the application cannot be accurately obtained, which makes it difficult to diagnose and solve the problem.

Method used

By calling the monitoring thread in the target object to be monitored, the running parameters of the currently running thread are obtained. If there is an exception, its call stack is read to determine the set of calling functions called by the exception.

Benefits of technology

It achieves accurate monitoring and abnormal diagnosis of thread running parameters in applications, can accurately obtain the causes of application exceptions, and improves the efficiency of problem solving.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN114328073B_ABST
    Figure CN114328073B_ABST
Patent Text Reader

Abstract

The embodiment of the present invention discloses a thread monitoring method, device, equipment and storage medium. Among them, a thread monitoring method includes: during the operation of the target object to be monitored, calling the monitoring thread to obtain the operating parameters of the currently running thread in the target object; if there is an abnormality in the operating parameters of the currently running thread in the target object, reading the call stack of the currently running thread; determining the call function set called by the currently running thread in the target object according to the call stack of the currently running thread; determining the call function in the call function set as the call function abnormally called by the currently running thread. By adopting this solution, the cause of the abnormal problem of the application can be accurately obtained.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of Internet technology, and in particular to a thread monitoring method, device, equipment and storage medium. Background Art

[0002] With the development of Internet technology, various applications (such as taxi applications, social applications, and office applications) have emerged, bringing great convenience to users' work and life. However, during the operation of these applications, if the application has abnormal problems such as freezing, it is easy to cause the application to crash. In the prior art, the main thread running in the application is monitored to obtain the cause of the abnormal problem of the application; however, the accuracy of this monitoring method is relatively low, and the cause of the abnormal problem of the application cannot be accurately obtained. Summary of the invention

[0003] The embodiments of the present invention provide a thread monitoring method, apparatus, device and storage medium, which can accurately obtain the cause of abnormal problems in an application program.

[0004] On the one hand, an embodiment of the present invention provides a thread monitoring method, the thread monitoring method comprising:

[0005] During the operation of the target object to be monitored, the monitoring thread is called to obtain the operation parameters of the currently running thread in the target object;

[0006] If the running parameters of the currently running thread in the target object are abnormal, then read the call stack of the currently running thread;

[0007] Determine a set of calling functions called by the currently running thread in the target object according to the calling stack of the currently running thread;

[0008] The calling function in the calling function set is determined as the calling function abnormally called by the currently running thread.

[0009] The above-mentioned operation parameters include the operation time, and the above-mentioned monitoring thread includes a parameter monitoring function;

[0010] If the running parameters of the currently running thread in the target object are abnormal, the call stack of the currently running thread is read, including:

[0011] Calling the parameter monitoring function to monitor the running parameters of the currently running thread, wherein the parameter monitoring function includes a first duration threshold;

[0012] If the running time of the currently running thread is greater than the first time threshold, it is determined that the running parameters of the currently running thread in the target object are abnormal, and a callback function is called to read the call stack of the currently running thread.

[0013] The above method further comprises:

[0014] Get the address pointer of the above parameter monitoring function;

[0015] Obtain the time limit variable in the above parameter monitoring function according to the address pointer of the above parameter monitoring function;

[0016] The threshold of the duration limit variable is set to the first duration threshold, and a calling strategy is added to the parameter monitoring function. The calling strategy is used to call the callback function to read the call stack of the currently running thread if the running time of the currently running thread is greater than the first duration threshold.

[0017] The above operating parameters include operating resource occupancy rate;

[0018] If the running parameters of the currently running thread in the target object are abnormal, the call stack of the currently running thread is read, including:

[0019] If the operation resource occupancy rate of the currently running thread in the target object is greater than the preset occupancy rate threshold, then obtaining the duration of the operation resource occupancy rate of the currently running thread in the target object being greater than the preset occupancy rate threshold;

[0020] If the duration exceeds the second duration threshold, it is determined that the running parameters of the currently running thread are abnormal, and the call stack of the currently running thread is read.

[0021] If the duration of the above operation exceeds the second duration threshold, it is determined that the operation parameters of the currently running thread are abnormal, and the call stack of the currently running thread is read, including:

[0022] If the duration exceeds the second duration threshold, it is determined that the running parameters of the currently running thread are abnormal, and the corresponding relationship between the thread identifier and the thread type is obtained;

[0023] Determine the thread type of the currently running thread according to the corresponding relationship between the thread identifier and the thread type;

[0024] If the thread type of the currently running thread is the target thread type, the call stack of the currently running thread is read; the target thread type refers to the thread type used to interpret and compile code information.

[0025] The step of determining the set of calling functions in the target object that call the currently running thread according to the call stack of the currently running thread includes:

[0026] Determine the target function called by the currently running thread from the call stack of the currently running thread;

[0027] Obtaining a call stack frame of the target function, and determining an upper layer call pointer from the call stack frame of the target function;

[0028] Determine, according to the upper-layer calling pointer, an upper-layer calling function that calls the target function as a first calling function;

[0029] Obtaining a call stack frame of the first calling function;

[0030] A set of calling functions called by a currently running thread in the target object is determined according to the target function, the first calling function and a calling stack frame of the first calling function.

[0031] The step of determining the set of calling functions called by the currently running thread in the target object according to the target function, the first calling function and the calling stack frame of the first calling function includes:

[0032] If there is an upper-layer call pointer in the call stack frame of the first call function, determine the call function that calls the first call function in the target object as the second call function according to the upper-layer call pointer in the call stack frame of the first call function, and add the target function, the first call function and the second call function to the call function set;

[0033] If there is no upper-layer call pointer in the call stack frame of the first calling function, the target function and the first calling function are added to the calling function set.

[0034] On the one hand, an embodiment of the present application provides a thread monitoring device, including:

[0035] A first acquisition module is used to call a monitoring thread to acquire the running parameters of the currently running thread in the target object to be monitored during its running process;

[0036] A reading module, configured to read the call stack of the currently running thread if there is an abnormality in the running parameters of the currently running thread in the target object;

[0037] A first determining module, configured to determine a set of calling functions called by the currently running thread in the target object according to the calling stack of the currently running thread;

[0038] The second determining module is used to determine the calling function in the calling function set as the calling function abnormally called by the currently running thread.

[0039] The above-mentioned operation parameters include the operation time, and the above-mentioned monitoring thread includes a parameter monitoring function;

[0040] The above-mentioned reading module includes:

[0041] A monitoring unit, configured to call the parameter monitoring function to monitor the running parameters of the currently running thread, wherein the parameter monitoring function includes a first duration threshold;

[0042] The calling unit is used to determine that there is an abnormality in the running parameters of the currently running thread in the above-mentioned target object if the running time of the above-mentioned currently running thread is greater than the above-mentioned first time threshold, and call the callback function to read the call stack of the above-mentioned currently running thread.

[0043] The above device further comprises:

[0044] A second acquisition module is used to obtain the address pointer of the parameter monitoring function;

[0045] A third acquisition module is used to acquire the time limit variable in the parameter monitoring function according to the address pointer of the parameter monitoring function;

[0046] Add a module to set the threshold of the above-mentioned duration limit variable to the above-mentioned first duration threshold, and add a calling strategy in the above-mentioned parameter monitoring function, wherein the above-mentioned calling strategy is used to call the above-mentioned callback function to read the call stack of the above-mentioned currently running thread if the running time of the above-mentioned currently running thread is greater than the above-mentioned first duration threshold.

[0047] The above operating parameters include operating resource occupancy rate;

[0048] The above-mentioned reading module includes:

[0049] A first acquisition unit is used to acquire, if the operation resource occupancy rate of the currently running thread in the target object is greater than a preset occupancy rate threshold, a duration during which the operation resource occupancy rate of the currently running thread in the target object is greater than the preset occupancy rate threshold;

[0050] The reading unit is used to determine that there is an abnormality in the running parameters of the currently running thread if the duration exceeds a second duration threshold, and read the call stack of the currently running thread.

[0051] The reading unit is specifically used for:

[0052] If the duration exceeds the second duration threshold, it is determined that the running parameters of the currently running thread are abnormal, and the corresponding relationship between the thread identifier and the thread type is obtained;

[0053] Determine the thread type of the currently running thread according to the corresponding relationship between the thread identifier and the thread type;

[0054] If the thread type of the currently running thread is the target thread type, the call stack of the currently running thread is read; the target thread type refers to the thread type used to interpret and compile code information.

[0055] Wherein, the second determination module includes:

[0056] A first determining unit, configured to determine a target function called by the currently running thread from a call stack of the currently running thread;

[0057] A second determining unit is used to obtain a call stack frame of the target function and determine an upper layer call pointer from the call stack frame of the target function;

[0058] A third determining unit, configured to determine, according to the upper-layer calling pointer, an upper-layer calling function that calls the target function as a first calling function;

[0059] An acquiring unit, used for acquiring a call stack frame of the first calling function;

[0060] The fourth determining unit is used to determine a set of calling functions called by a currently running thread in the target object according to the target function, the first calling function and a calling stack frame of the first calling function.

[0061] The fourth determining unit is specifically used for:

[0062] If there is an upper-layer call pointer in the call stack frame of the first call function, determine the call function that calls the first call function in the target object as the second call function according to the upper-layer call pointer in the call stack frame of the first call function, and add the target function, the first call function and the second call function to the call function set;

[0063] If there is no upper-layer call pointer in the call stack frame of the first calling function, the target function and the first calling function are added to the calling function set.

[0064] The embodiment of the present application provides a computer device, including: a processor, a memory, and a network interface;

[0065] The processor is connected to a memory and a network interface, wherein the network interface is used to provide a data communication function, the memory is used to store a computer program, and the processor is used to call the computer program to execute the method in the embodiment of the present application.

[0066] An embodiment of the present application provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the method in the embodiment of the present application is executed.

[0067] In the process of the target object to be monitored, the embodiment of the present invention obtains the running parameters of the currently running thread in the above target object by calling the monitoring thread; if the running parameters of the currently running thread in the above target object are abnormal, the call stack of the currently running thread is read; the call stack can be used to trace back to the call function set called by the above currently running thread, and the call function in the call function set is the cause of the abnormal running parameters of the currently running thread. Therefore, the call function set called by the currently running thread in the target object can be determined according to the call stack of the currently running thread; the call function in the call function set is determined as the call function abnormally called by the currently running thread. It can be seen that in this application, by analyzing the currently running thread and the call stack of the currently running thread, not only can the thread with abnormal running parameters be traced back, but also the call function abnormally called by the abnormal thread can be obtained; it is conducive to accurately obtaining the cause of the abnormal call of the currently running thread, that is, it is conducive to accurately obtaining the cause of the abnormal problem of the target object. BRIEF DESCRIPTION OF THE DRAWINGS

[0068] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the accompanying drawings required for use in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are some embodiments of the present invention. For ordinary technicians in this field, other accompanying drawings can be obtained based on these accompanying drawings without paying any creative work.

[0069] Figure 1 It is a flowchart of a thread monitoring method provided in an embodiment of the present application;

[0070] Figure 2 is a schematic diagram of a method for detecting abnormal problems provided in an embodiment of the present application;

[0071] Figure 3 It is a structural diagram of a Native call stack frame provided in an embodiment of the present application;

[0072] Figure 4 It is a structural diagram of a JS call stack frame provided in an embodiment of the present application;

[0073] Figure 5 It is a flowchart of another thread monitoring method provided in an embodiment of the present application;

[0074] Figure 6 It is a structural diagram of a call stack provided for an embodiment of the present application;

[0075] Figure 7 It is a structural schematic diagram of a thread monitoring device provided by an embodiment of the present invention;

[0076] Figure 8 It is a structural schematic diagram of a computer device provided by an embodiment of the present invention. DETAILED DESCRIPTION

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

[0078] See also Figure 1 , is a flowchart of a thread monitoring method provided by an embodiment of the present application. The embodiment of the present application can be executed by an electronic device, which may refer to a terminal or a server. The terminal may include but is not limited to: a smart phone, a tablet computer, a laptop computer, a desktop computer, a smart speaker, a smart watch, etc.; the server may be an independent physical server, or a server cluster or distributed system composed of multiple physical servers, or a cloud server that provides basic cloud computing services such as cloud services, cloud databases, cloud computing, cloud functions, cloud storage, network services, cloud communications, middleware services, domain name services, security services, content delivery networks (Content Delivery Network, CDN), and big data and artificial intelligence platforms. The thread monitoring method includes the following steps S101~S104.

[0079] S101, during the operation of the target object to be monitored, calling a monitoring thread to obtain the operation parameters of the currently running thread in the target object.

[0080] In order to make the target object know which threads call the code execution of the function to cause the problem when the target object is stuck or consumes a lot of power during the operation process, therefore, during the operation of the target object to be monitored, the monitoring thread can be called to obtain the running parameters of the currently running thread in the target object. Specifically, the target object to be monitored can refer to RN services, small games, small program applications, etc., and the RN refers to the abbreviation of React Native, which is a cross-platform mobile application development framework and a derivative product of the JS framework software on the native mobile application platform. RN uses the Javascript language. JS refers to JavaScript (referred to as "JS"), which is a lightweight, interpreted or just-in-time compiled high-level programming language with function priority. The running parameters of the running thread can refer to the time spent executing the corresponding code in the running thread, or the running resource occupancy rate occupied when executing the code corresponding to the running thread, such as the CPU (central controller) occupancy rate, memory occupancy rate, network occupancy rate, etc. The control thread can monitor the running parameters of the current running thread in the target object, so that the target object can be monitored for abnormal problems such as stuck and high power consumption during the operation process.

[0081] S102: If the running parameters of the currently running thread in the target object are abnormal, read the call stack of the currently running thread.

[0082] When the monitoring thread finds that the running parameters of the currently running thread in the target object are abnormal, it reads the call stack of the currently running thread. The call stack is the function information called in a certain order in a thread of an application (i.e., the target object) during its running. By restoring the stack, you can know the function information called in a thread of the application, including function name and location information. Among them, a thread may call many functions, but each thread can only execute one function at a time point. The executed function is called the current calling function.

[0083] Optionally, in the embodiment of the present application, the currently running thread in the target object may refer to a JS thread, where JS refers to JavaScript (referred to as "JS"), which is a lightweight, interpreted or just-in-time compiled high-level programming language with function priority, and a JS thread refers to a thread that uses the JavaScript programming language. In the prior art, the abnormal problems of threads can only be monitored based on pure Native call stack frames, where Native refers to a computer function, and the implementation of Native functions is implemented by non-Java languages, such as C or C++. Based on pure Native call stack frames, it is not possible to monitor the abnormal problems of JS running threads, nor is it possible to specifically obtain the reasons for the occurrence of abnormal problems. A call stack frame refers to a memory model of the code execution corresponding to a function, which is used for function calls and function execution data areas. When each function is executed, a stack frame is created for storing local variable tables, operand stacks, dynamic links, function exits, etc. According to the call stack frames corresponding to each calling function called by the currently running thread, the call stack of the currently running thread in the target object can be determined. In addition, when monitoring the running thread in the prior art, the abnormal problem information of the main thread is obtained, but the abnormal problem information of the specific JS running thread cannot be obtained. In addition, the abnormal problem of the running thread is analyzed based on the Native call stack frame information, and the specific reason for the abnormal problem of the JS running thread cannot be accurately obtained. Therefore, during the operation of the target object to be monitored, the monitoring thread can be called to obtain the running parameters of the currently running thread in the target object for monitoring. If the running parameters of the currently running thread are abnormal, the call stack of the currently running thread is read.

[0084] Among them, in the prior art, when a problem occurs with the target object, what is obtained in the prior art is the information of the traditional Native call stack frame, and not the information of the JS call stack frame corresponding to the JS running thread in the target object, which cannot help the JS business solve the problem, and therefore cannot obtain the specific reason why the problem occurs in the JS running thread in the target object. Only by obtaining the call stack frame of the JS thread can the JS business know that there is a problem with the code of the JS function in its own JS running thread, and locate and solve the problem. The JS call stack frame refers to the call stack frame of a function that uses the Javascript language. A running thread may call many functions, but each thread can only execute one function at a time point. The executed function is called the current calling function, and the current calling function is used as the target function. For example Figure 2 As shown, it is a schematic diagram of a method for detecting abnormal problems provided by this embodiment, such as Figure 2As shown, in the prior art, when monitoring the running thread, the operation of the main thread is detected based on the detection thread to determine whether the main thread has timed out or the CPU is too high. If the main thread has timed out or the CPU is too high, the call stack of the main thread is dumped. After the dump is successful, wait for a while and continue to detect the main thread. If the main thread does not have a timeout or the CPU is too high, wait for a while and continue to detect the main thread. Among them, when dumping the call stack of the main thread in the prior art, the Native call stack frame of the main thread is dumped. If the current running thread is a JS running thread, the reason for the abnormality of the JS running thread cannot be obtained based on the Native call stack frame. Figure 3 As shown, it is a schematic diagram of the structure of a Native call stack frame provided in an embodiment of the present application, such as Figure 3 As shown in the figure, the traditional stack frame backtracing of the Native call stack frame to obtain the exception problem information is based on the call stack frame information of the arm (microprocessor). The arm call stack frame can recursively obtain all the information of the call stack frame through the information of LR (return pointer), FP (frame pointer), and SP (stack pointer). Figure 3 As shown, the Native call stack frame structure includes the return pointer of the upper-layer calling function that calls the target function (i.e., the current calling function), the frame pointer of the upper-layer calling function that calls the target function, and the allocated memory (Allocation) and stack parameters (stuck arguments). The return pointer in the Native call stack frame structure refers to the return pointer of the upper-layer calling function that calls the target function, the frame pointer 1 refers to the frame pointer of the target function, and the frame pointer 2 refers to the frame pointer of the upper-layer function that calls the target function. The high address in the Native call stack frame structure stores the data that was pushed into the stack first, i.e., the bottom of the stack; the low address stores the data that was pushed into the stack later, i.e., the top of the stack. Specifically, the frame pointer (ebp) is used for addressing in the stack, and the stack pointer (esp) moves with the pushing and popping of data, that is, the frame pointer points to the bottom of the current stack frame (high address), and the stack pointer points to the top of the current stack frame (ground address).

[0085] like Figure 4 As shown, it is a schematic diagram of a JS call stack frame structure provided by an embodiment of the present application, such as Figure 4 As shown in the figure, the JS call stack frame is also somewhat similar to the Native arm call stack frame. When JavascriptCore (a virtual machine that specializes in processing JavaScript code) interprets and generates bytecodes or performs JIT (Just-in-Time Compiler) and other optimizations, it organizes the transfer of parameters and call stack frame information according to its own call stack frame call form. Specifically, Figure 4As shown in the figure, when a function call occurs, the parameters n, ... parameter 2, and parameter 1 of the upper-level calling function (the function that calls the target function) are pushed into the stack one by one from the high address (towards the bottom of the stack) to the low address (towards the top of the stack), and then the this pointer is pushed into the stack. The object that this pointer finally points to is the calling target function (the current calling function). This is a keyword in C++ (programming language) and a pointer that points to the current object, through which all members of the current object can be accessed. Next is the number of parameters pushed into the stack, followed by the information of the target function (the current calling function callee), followed by the information of the code block (JS codeBlock) of the target function (the current calling function), the return address information after JavascriptCore execution, and the information of the upper-level calling function (caller). According to this structure, the JavascriptCore interpreter generates the conventions for each JS calling function call. The parameter passing rules of JS function calls and armv8 function calls in Native are somewhat similar, but the parameter passing of JS is basically based on stack passing, and armv8 may also use registers to pass parameters as much as possible, so the parameter passing of JS is more efficient. The information obtained in the prior art is the traditional Native call stack frame information, not the JS call stack frame information corresponding to the JS running thread in the target object, which cannot help the JS business solve the problem, and therefore cannot obtain the specific cause of the problem in the JS business in the target object. Only by obtaining the call stack frame of the JS running thread can the JS business know that the code of the JS function of its own JS running thread has a problem, locate the problem and solve it, and obtain the code information of the call function in the JS running thread where the abnormal problem occurs based on the JS call stack frame.

[0086] Optionally, the running parameters include the running duration, and the above-mentioned monitoring thread includes a parameter monitoring function; the parameter monitoring function is called to monitor the running parameters of the currently running thread, and the parameter monitoring function includes a first duration threshold; if the running duration of the currently running thread is greater than the first duration threshold, it is determined that there is an abnormality in the running parameters of the currently running thread in the target object, and the callback function is called to read the call stack of the currently running thread.

[0087] The running parameters of the currently running thread in the target object can be the running time. The above-mentioned monitoring thread includes a parameter monitoring function. During the running process of the target object to be monitored, the parameter monitoring function in the monitoring thread can be called to monitor the running parameters of the currently running thread, that is, to monitor the running time of the currently running thread in the target object, so as to judge in real time whether the currently running thread is stuck. If the running time of the currently running thread is greater than the first time threshold, it is determined that there is an abnormality in the running parameters of the currently running thread in the target object, indicating that the currently running thread has been stuck, and the callback function is called to read the call stack of the currently running thread. If the running time of the currently running thread is less than or equal to the first time threshold, it is determined that there is no abnormality in the running parameters of the currently running thread in the target object, indicating that the currently running thread is in normal operation, and the running parameters of the currently running thread are continued to be monitored. Among them, the callback function is used to feedback the running thread with abnormal running parameters, that is, if the running time of the currently running thread is greater than the first time threshold, the callback function will be triggered to feedback the abnormality of the currently running thread in the target object, and provide the call stack information of the function called by the currently running thread with abnormal running.

[0088] Optionally, before calling the parameter monitoring function to monitor the running parameters of the currently running thread, the address pointer of the parameter monitoring function is obtained, and the duration limit variable in the parameter monitoring function is obtained according to the address pointer of the parameter monitoring function. The threshold of the duration limit variable is set to the first duration threshold, and a calling strategy is added to the parameter monitoring function, and the calling strategy is used to call the callback function to read the call stack of the currently running thread if the running time of the currently running thread is greater than the first duration threshold.

[0089] Before calling the parameter monitoring function to monitor the running parameters of the currently running thread, a parameter monitoring function for monitoring the currently running thread in the target object can be constructed and initialized. After the parameter monitoring function is initialized, the address pointer of the parameter monitoring function is obtained, and the duration limit variable in the parameter monitoring function is obtained according to the address pointer of the parameter monitoring function. The threshold of the duration limit variable is set to the first duration threshold, and a calling strategy is added to the parameter monitoring function. The calling strategy is used to call the callback function to read the call stack of the currently running thread if the running time of the currently running thread is greater than the first duration threshold. That is, if the running time of the currently running thread is too long and greater than the first duration threshold, it means that the currently running thread is stuck, and the callback strategy will be triggered, calling the callback function, feedback will be given to the currently stuck running thread, and the call stack of the currently running thread will be read.

[0090] In one embodiment, the currently running thread in the target object may be a JS running thread, and the running time of the currently running thread in the target object may be monitored by the Watchdog mechanism. The Watchdog mechanism is a built-in monitoring mechanism in JavascriptCore (a virtual machine that specializes in processing JavaScript code) that detects whether the time taken for the JS thread to execute a task submission execution exceeds the jam threshold. Due to the closure of Webkit (an open source browser engine) (many websites are not compatible with the Webkit kernel, such as login interfaces, online banking and other web pages cannot use browsers with the Webkit kernel), the Watchdog mechanism is not a publicly available method. Therefore, we trigger the opening of the watchdog in the entire JavascripteCore by setting the setenv (used to change or increase environment variables) of the environment variable. Before calling the parameter monitoring function to monitor the running parameters of the currently running thread, a parameter monitoring function for monitoring the running parameters of the currently running thread can be constructed, that is, a parameter monitoring function of the virtual machine corresponding to the current running thread of the target object is constructed (that is, a function in the hook target object is established in the target object that can be called by itself) and the parameter monitoring function is initialized. After initializing the parameter monitoring function, the address pointer of the parameter monitoring function can be obtained, that is, the address of the member variable m_watchdog instance of the object can be found through the offset value sent, and the duration limit variable in the parameter monitoring function can be obtained according to the address pointer of the parameter monitoring function. The threshold of the duration limit variable is set to the first duration threshold, and a calling strategy is added to the parameter monitoring function. The calling strategy is used to call the callback function to read the call stack of the currently running thread if the running time of the currently running thread is greater than the first duration threshold. When the code execution times out, the callback function will be triggered, and the call stack of the calling function called by the currently running thread can be obtained according to the callback function, thereby realizing the dynamic triggering of the Watchdog mechanism and triggering the pre-set callback function according to the specified first duration threshold, and finally achieving the jam monitoring of the currently running thread.

[0091] Optionally, the running parameters of the currently running thread include the running resource occupancy rate; if the running resource occupancy rate of the currently running thread in the target object is greater than a preset occupancy rate threshold, the duration during which the running resource occupancy rate of the currently running thread in the target object is greater than the preset occupancy rate threshold is obtained; if the duration exceeds a second duration threshold, it is determined that there is an abnormality in the running parameters of the currently running thread, and the call stack of the currently running thread is read.

[0092] The running parameters of the currently running thread may refer to the CPU occupancy rate. A monitoring thread may be established to monitor the running resource occupancy rates of all running threads in the target object, and obtain the running resource occupancy rate values ​​of all running threads in the target object in real time. If the running resource occupancy rate of the currently running thread in the target object is greater than the preset occupancy rate threshold, the duration of the running resource occupancy rate of the currently running thread in the target object greater than the preset occupancy rate threshold is obtained, that is, the running thread in the target object whose running resource occupancy rate is greater than the preset resource occupancy rate is timed. If the duration exceeds the second duration threshold, it is determined that there is an abnormality in the running parameters of the currently running thread, indicating that the running resource occupancy rate of the currently running thread is too high, and abnormal occupancy occurs, which will lead to excessive power consumption, and then the call stack of the currently running thread is read.

[0093] Optionally, if the duration exceeds a second duration threshold, it is determined that there is an abnormality in the running parameters of the currently running thread, and the correspondence between the thread identifier and the thread type is obtained; based on the correspondence between the thread identifier and the thread type, the thread type of the currently running thread is determined; if the thread type of the currently running thread is the target thread type, the call stack of the currently running thread is read, and the target thread type refers to the thread type used to interpret and compile code information.

[0094] In an embodiment of the present application, if the duration of the operation resource occupancy rate of the previously run thread is greater than the preset occupancy rate threshold and exceeds the second duration threshold, it is determined that the operation parameters of the currently run thread are abnormal, that is, the running thread of the target object occupies the operation resources too high for a long time. Then the correspondence between the thread identifier and the thread type can be obtained, and the thread type of the currently running thread in the target object is determined according to the correspondence between the thread identifier and the thread type. If the thread type of the currently running thread in the target object is the target thread type, the call stack of the currently running thread is read, and the target thread type refers to the thread type that directly interprets and runs the code information of the called function. In the implementation of the present application, the target thread type can be a JS thread type. The currently running thread in the target object can be a JS thread. Since JavascriptCore supports multi-threaded calls, we cannot directly know whether a thread is a JS thread. A data table hashmap can be constructed. HashMap is a hash map used for mapping (key-value pair) processing, which is used to store the mapping relationship between the thread id and the thread type. According to the mapping relationship between the thread id and the thread type, it is possible to know whether the thread type of the currently running thread is a JS thread type. If it is determined that the JS thread has abnormal power consumption, the call stack of the currently running thread is obtained.

[0095] S103: Determine a set of calling functions called by the currently running thread in the target object according to the calling stack of the currently running thread.

[0096] S104: Determine a calling function in the calling function set as a calling function abnormally called by the currently running thread.

[0097] If there is an abnormal problem in the currently running thread, the function currently called by the currently running thread is read as the target function, and the call stack of the target function is obtained, and the call stack is backtracked to obtain the call function set called by the currently running thread in the target object. Among them, the call stack frame of the target function can be obtained. As mentioned above, the call stack frame (i.e., stack frame) refers to the memory model of the code execution corresponding to the function. When each function is executed, a stack frame (Stack Frame) is created for storing the local variable table, operand stack, dynamic link, function exit, etc. The call stack frame of the target function stores the code information of the target function and the information of the upper-level call function that calls the target function. Therefore, the information of the upper-level call function that calls the target function can be determined according to the call stack frame of the target function called by the currently running thread, and the call function set that calls the target function can be determined according to the information of the upper-level call function that calls the target function, thereby obtaining the call function set called by the currently running thread in the target object.

[0098] The embodiment of the present invention obtains the running parameters of the currently running thread in the target object to be monitored by calling a monitoring thread during the running of the target object to be monitored; wherein the running parameters of the currently running thread include the running time and the running resource occupancy rate, and the running time of the currently running thread can be monitored by calling the parameter monitoring function in the monitoring thread, and if there is an abnormality in the running parameters of the currently running thread in the target object, the callback function is called to read the call stack of the currently running thread; the running resource occupancy rate of the currently running thread can also be monitored by the monitoring thread, and if there is an abnormality in the running parameters of the currently running thread in the target object, it is determined whether the currently running thread is a target type thread, and if the current thread is a target type thread, the call stack of the currently running thread is read; the call stack of the currently running thread is analyzed to specifically analyze the reason why the currently running thread has an abnormality; the call stack can be used to trace back to the call function set called by the currently running thread, and the call function in the call function set is the reason why the running parameters of the currently running thread are abnormal. Therefore, the call function set called by the currently running thread in the target object can be determined according to the call stack of the currently running thread; the call function in the call function set is determined as the call function abnormally called by the currently running thread. It can be seen that in this application, by analyzing the currently running thread and the call stack of the currently running thread, not only can the thread with abnormal running parameters be traced back, but also the call function abnormally called by the abnormal thread can be obtained; it is conducive to accurately obtaining the cause of the abnormal call of the currently running thread, that is, it is conducive to accurately obtaining the cause of the abnormal problem of the target object.

[0099] like Figure 5 As shown, it is a flow chart of another thread monitoring method provided by an embodiment of the present application, such as Figure 5 As shown, the other thread monitoring method includes steps S201 to S208.

[0100] S201, during the operation of the target object to be monitored, calling a monitoring thread to obtain the operation parameters of the currently running thread in the target object.

[0101] S202: If the running parameters of the currently running thread in the target object are abnormal, read the call stack of the currently running thread.

[0102] The specific contents of steps S201 to S202 can be found in Figure 1 The specific contents described are not repeated here in the embodiments of the present application.

[0103] S203: Determine the target function called by the currently running thread from the call stack of the currently running thread.

[0104] S204, obtaining a call stack frame of the target function, and determining an upper layer call pointer from the call stack frame of the target function.

[0105] If the running parameters of the currently running thread in the target object are abnormal, the function called by the currently running thread is determined from the call stack of the currently running thread, that is, the top calling function in the call stack of the currently running thread, as the target function, and the call stack frame of the target function in the currently running thread is read. The currently running thread in the target object can be a JS thread, such as Figure 4 As shown, the call stack frame of the JS thread includes the parameters of the upper-layer calling function (the function that calls the target function) and the information of the target function (the current calling function callee) code block (JS codeBlock), as well as the information of the upper-layer calling function (caller). After obtaining the call stack frame of the target function of the currently running thread, the code information of the target function and the function name and location information of the upper-layer calling function that calls the target function can be obtained in the call stack frame of the target function. Therefore, the address pointer of the upper-layer calling function that calls the target function, that is, the upper-layer call pointer, can be obtained in the call stack frame of the target function.

[0106] S205, determining an upper-layer calling function that calls the target function according to the upper-layer calling pointer as a first calling function.

[0107] S206, obtaining a call stack frame of the first calling function.

[0108] S207: Determine a set of calling functions called by a currently running thread in the target object according to the target function, the first calling function, and a calling stack frame of the first calling function.

[0109] S208: Determine the calling function in the calling function set as the calling function abnormally called by the currently running thread.

[0110] The calling function that calls the target function in the target object is determined according to the upper-layer calling pointer of the upper-layer calling function that calls the target function, as the first calling function. Then the calling stack frame of the first calling function is obtained. Similarly, the calling stack frame of the first calling function also stores the code block information of the first calling function and the information of the upper-layer calling function that calls the first calling function. Therefore, the calling function set that calls the currently running thread in the target object can be determined according to the first calling function and the calling stack frame of the first calling function.

[0111] Optionally, if there is an upper-level call pointer in the call stack frame of the first call function, the call function that calls the first call function in the target object is determined as the second call function according to the upper-level call pointer in the call stack frame of the first call function, and the target function, the first call function and the second call function are added to the call function set. If there is no upper-level call pointer in the call stack frame of the first call function, the target function and the first call function are added to the call function set.

[0112] If there is an upper-level call pointer in the call stack frame of the first call function, it means that the first call function has an upper-level call function and is not the initial call function; if there is no upper-level call pointer in the call stack frame of the first call function, it means that the first call function is the initial call function and has no upper-level call function. If there is an upper-level call pointer in the call stack frame of the first call function, then according to the upper-level call pointer in the call stack of the first call function, determine the call function that calls the first call function in the target object as the second call function, and add the first call function and the second call function to the call function set. Then, determine whether there is an upper-level call function for the second call function. If there is an upper-level call function for the second call function, obtain the upper-level call function of the second call function as the third call function. By analogy, backtrack until the upper-level call function is empty or reaches the maximum backtracking depth. The maximum backtracking depth refers to backtracking to the bottom of the call stack of the currently running thread, so as to obtain all the call functions called by the currently running thread.

[0113] Optional, such as Figure 6 As shown in the figure, it is a schematic diagram of the structure of a call stack provided by an embodiment of the present application. When a C++ function calls a JS function, JavascriptCore will generate a VMEntryRecord

[0114] (Virtual Machine Input Record) structure, VMEntryRecord (Virtual Machine Input Record) records the called function and the upper layer calling function information. Multiple VMEntryRecord (Virtual Machine Input Record) are combined to form a set of call stack relationships between C++ and JS. Figure 6As shown, the direction from bottom to top is the direction from high address to low address, the stack pointer (SP) points to the top of the JS call stack, and the low address direction of the JS call stack stores the information of the local function call stack (i.e., the Native call stack frame). In the call stack, find the pointer to enter the current VM virtual machine, and enter the current VM virtual machine according to the pointer. The VMEntryRecord (virtual machine input record) in the current VM virtual machine is the information of the call function called by the JS running thread. The currently called target function and the upper-level call function of the target function are obtained in the VMEntryRecord (virtual machine input record) of the current vm virtual machine, and the previous VMEntryRecord of the current VMEntryRecord is obtained according to the upper-level call function of the target function, that is, the call stack frame of the upper-level caller (first call function) of the target function is determined according to the call stack frame of the current target function. By analogy, the call stack of the currently running thread is backtracked until the upper-level call function (caller) is empty or the maximum backtracking depth is reached, and the maximum depth refers to the stack bottom of the call stack backtracked to the currently running thread. In this way, a call function set of all abnormal calls of the currently running thread is obtained, and the call function in the call function set is determined as the call function of the abnormal call of the currently running thread.

[0115] Optionally, when obtaining all the calling functions abnormally called by the currently running thread, you can search for the JS function structure (JSfuntion) and code block (CodeBlock) corresponding to each calling function. The JS function structure (JSfuntion) stores the function name and function body information of the calling function, and you can retrieve the code information of the corresponding calling function in the calling function set from the memory structure of the corresponding calling function structure (JSfuntion), so you can get the code information of the abnormal calling function of the currently running thread with an exception, so you can know which specific codes cause the JS thread execution to be abnormal.

[0116] The embodiment of the present invention obtains the running parameters of the currently running thread in the target object to be monitored by calling a monitoring thread during the running of the target object to be monitored; wherein the running parameters of the currently running thread include the running time and the running resource occupancy rate, and the running time of the currently running thread can be monitored by calling the parameter monitoring function in the monitoring thread, and if there is an abnormality in the running parameters of the currently running thread in the target object, the callback function is called to read the call stack of the currently running thread; the running resource occupancy rate of the currently running thread can also be monitored by the monitoring thread, and if there is an abnormality in the running parameters of the currently running thread in the target object, it is determined whether the currently running thread is a target type thread, and if the current thread is a target type thread, the call stack of the currently running thread is read; the call stack of the currently running thread is analyzed to specifically analyze the reason why the currently running thread has an abnormality; the call stack can be used to trace back to the call function set called by the currently running thread, and the call function in the call function set is the reason why the running parameters of the currently running thread are abnormal. Therefore, the call function set called by the currently running thread in the target object can be determined according to the call stack of the currently running thread; the call function in the call function set is determined as the call function abnormally called by the currently running thread. It can be seen that in this application, by stack tracing of the currently running thread and the call stack of the currently running thread, not only can the thread with abnormal running parameters be traced back, but also the call function abnormally called by the abnormal thread can be obtained; it is conducive to accurately obtaining the cause of the abnormal call of the currently running thread, that is, it is conducive to accurately obtaining the cause of the abnormal problem of the target object.

[0117] See also Figure 7 , is a schematic diagram of the structure of a thread monitoring device provided in an embodiment of the present application. The thread monitoring device provided in an embodiment of the present application may be in an electronic device. In this embodiment, the thread monitoring device includes:

[0118] The first acquisition module 11 is used to call the monitoring thread to obtain the running parameters of the currently running thread in the target object to be monitored during its running process;

[0119] A reading module 12 is used to read the call stack of the currently running thread if there is an abnormality in the running parameters of the currently running thread in the target object;

[0120] The reading module 12 includes:

[0121] A monitoring unit, configured to call the parameter monitoring function to monitor the running parameters of the currently running thread, wherein the parameter monitoring function includes a first duration threshold;

[0122] The calling unit is used to determine that there is an abnormality in the running parameters of the currently running thread in the above-mentioned target object if the running time of the above-mentioned currently running thread is greater than the above-mentioned first time threshold, and call the callback function to read the call stack of the above-mentioned currently running thread.

[0123] The above operating parameters include operating resource occupancy rate;

[0124] The reading module 12 includes:

[0125] A first acquisition unit is used to acquire, if the operation resource occupancy rate of the currently running thread in the target object is greater than a preset occupancy rate threshold, a duration during which the operation resource occupancy rate of the currently running thread in the target object is greater than the preset occupancy rate threshold;

[0126] The reading unit is used to determine that there is an abnormality in the running parameters of the currently running thread if the duration exceeds a second duration threshold, and read the call stack of the currently running thread.

[0127] The reading unit is specifically used for:

[0128] If the duration exceeds the second duration threshold, it is determined that the running parameters of the currently running thread are abnormal, and the corresponding relationship between the thread identifier and the thread type is obtained;

[0129] Determine the thread type of the currently running thread according to the corresponding relationship between the thread identifier and the thread type;

[0130] If the thread type of the currently running thread is a target thread type, then the call stack of the currently running thread is read, and the target thread type refers to a thread type used to interpret and compile code information.

[0131] A first determining module 13, configured to determine a set of calling functions called by the currently running thread in the target object according to the calling stack of the currently running thread;

[0132] The second determining module 14 is used to determine the calling function in the calling function set as the calling function abnormally called by the currently running thread.

[0133] The above-mentioned operation parameters include the operation time, and the above-mentioned monitoring thread includes a parameter monitoring function;

[0134] The second determining module 14 includes:

[0135] A first determining unit, configured to determine a target function called by the currently running thread from a call stack of the currently running thread;

[0136] A second determining unit is used to obtain a call stack frame of the target function and determine an upper layer call pointer from the call stack frame of the target function;

[0137] A third determining unit, configured to determine, according to the upper-layer calling pointer, an upper-layer calling function that calls the target function as a first calling function;

[0138] An acquiring unit, used for acquiring a call stack frame of the first calling function;

[0139] The fourth determining unit is used to determine a set of calling functions called by a currently running thread in the target object according to the target function, the first calling function and a calling stack frame of the first calling function.

[0140] The fourth determining unit is specifically used for:

[0141] If there is an upper-layer call pointer in the call stack frame of the first call function, determine the call function that calls the first call function in the target object as the second call function according to the upper-layer call pointer in the call stack frame of the first call function, and add the target function, the first call function and the second call function to the call function set;

[0142] If there is no upper-layer call pointer in the call stack frame of the first calling function, the target function and the first calling function are added to the calling function set.

[0143] The above device further comprises:

[0144] A second acquisition module is used to obtain the address pointer of the parameter monitoring function;

[0145] A third acquisition module is used to acquire the time limit variable in the parameter monitoring function according to the address pointer of the parameter monitoring function;

[0146] Add a module to set the threshold of the above-mentioned duration limit variable to the above-mentioned first duration threshold, and add a calling strategy in the above-mentioned parameter monitoring function, wherein the above-mentioned calling strategy is used to call the above-mentioned callback function to read the call stack of the above-mentioned currently running thread if the running time of the above-mentioned currently running thread during running is greater than the above-mentioned first duration threshold.

[0147] The embodiment of the present invention obtains the running parameters of the currently running thread in the target object to be monitored by calling a monitoring thread during the running of the target object to be monitored; wherein the running parameters of the currently running thread include the running time and the running resource occupancy rate, and the running time of the currently running thread can be monitored by calling the parameter monitoring function in the monitoring thread, and if there is an abnormality in the running parameters of the currently running thread in the target object, the callback function is called to read the call stack of the currently running thread; the running resource occupancy rate of the currently running thread can also be monitored by the monitoring thread, and if there is an abnormality in the running parameters of the currently running thread in the target object, it is determined whether the currently running thread is a target type thread, and if the current thread is a target type thread, the call stack of the currently running thread is read; the call stack of the currently running thread is analyzed to specifically analyze the reason why the currently running thread has an abnormality; the call stack can be used to trace back to the call function set called by the currently running thread, and the call function in the call function set is the reason why the running parameters of the currently running thread are abnormal. Therefore, the call function set called by the currently running thread in the target object can be determined according to the call stack of the currently running thread; the call function in the call function set is determined as the call function abnormally called by the currently running thread. It can be seen that in this application, by stack tracing of the currently running thread and the call stack of the currently running thread, not only can the thread with abnormal running parameters be traced back, but also the call function abnormally called by the abnormal thread can be obtained; it is conducive to accurately obtaining the cause of the abnormal call of the currently running thread, that is, it is conducive to accurately obtaining the cause of the abnormal problem of the target object.

[0148] See also Figure 8 , is a schematic diagram of the structure of a computer device provided in an embodiment of the present application. Figure 8 As shown, the above-mentioned computer device 1000 may include: a processor 1001, a network interface 1004 and a memory 1005. In addition, the above-mentioned computer device 1000 may also include: a user interface 1003, and at least one communication bus 1002. Among them, the communication bus 1002 is used to realize the connection and communication between these components. Among them, the user interface 1003 may include a display screen (Display), a keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a wireless interface. The network interface 1004 may optionally include a standard wired interface and a wireless interface (such as a WI-FI interface). The memory 1005 may be a high-speed RAM memory, or it may be a non-volatile memory (non-volatile memory), such as at least one disk storage. The memory 1005 may optionally also be at least one storage device located away from the aforementioned processor 1001. As Figure 8As shown, the memory 1005 as a computer-readable storage medium may include an operating system, a network communication module, a user interface module, and a device control application program.

[0149] exist Figure 8 In the computer device 1000 shown, the network interface 1004 can provide a network communication function; the user interface 1003 is mainly used to provide an input interface for the user; and the processor 1001 can be used to call the device control application stored in the memory 1005 to achieve:

[0150] During the operation of the target object to be monitored, the monitoring thread is called to obtain the operation parameters of the currently running thread in the target object;

[0151] If the running parameters of the currently running thread in the target object are abnormal, then read the call stack of the currently running thread;

[0152] Determine a set of calling functions called by the currently running thread in the target object according to the calling stack of the currently running thread;

[0153] The calling function in the calling function set is determined as the calling function abnormally called by the currently running thread.

[0154] The above-mentioned operation parameters include the operation time, and the above-mentioned monitoring thread includes a parameter monitoring function;

[0155] If the running parameters of the currently running thread in the target object are abnormal, the call stack of the currently running thread is read, including:

[0156] Calling the parameter monitoring function to monitor the running parameters of the currently running thread, wherein the parameter monitoring function includes a first duration threshold;

[0157] If the running time of the currently running thread is greater than the first time threshold, it is determined that the running parameters of the currently running thread in the target object are abnormal, and a callback function is called to read the call stack of the currently running thread.

[0158] The above method further comprises:

[0159] Get the address pointer of the above parameter monitoring function;

[0160] Obtain the time limit variable in the above parameter monitoring function according to the address pointer of the above parameter monitoring function;

[0161] The threshold of the duration limit variable is set to the first duration threshold, and a calling strategy is added to the parameter monitoring function. The calling strategy is used to call the callback function to read the call stack of the currently running thread if the running time of the currently running thread is greater than the first duration threshold.

[0162] The above operating parameters include operating resource occupancy rate;

[0163] If the running parameters of the currently running thread in the target object are abnormal, the call stack of the currently running thread is read, including:

[0164] If the operation resource occupancy rate of the currently running thread in the target object is greater than the preset occupancy rate threshold, then obtaining the duration of the operation resource occupancy rate of the currently running thread in the target object being greater than the preset occupancy rate threshold;

[0165] If the duration exceeds the second duration threshold, it is determined that the running parameters of the currently running thread are abnormal, and the call stack of the currently running thread is read.

[0166] If the duration of the above operation exceeds the second duration threshold, it is determined that the operation parameters of the currently running thread are abnormal, and the call stack of the currently running thread is read, including:

[0167] If the duration exceeds the second duration threshold, it is determined that the running parameters of the currently running thread are abnormal, and the corresponding relationship between the thread identifier and the thread type is obtained;

[0168] Determine the thread type of the currently running thread according to the corresponding relationship between the thread identifier and the thread type;

[0169] If the thread type of the currently running thread is the target thread type, the call stack of the currently running thread is read; the target thread type refers to the thread type used to interpret and compile code information.

[0170] The step of determining the set of calling functions in the target object that call the currently running thread according to the call stack of the currently running thread includes:

[0171] Determine the target function called by the currently running thread from the call stack of the currently running thread;

[0172] Obtaining a call stack frame of the target function, and determining an upper layer call pointer from the call stack frame of the target function;

[0173] Determine, according to the upper-layer calling pointer, an upper-layer calling function that calls the target function as a first calling function;

[0174] Obtaining a call stack frame of the first calling function;

[0175] A set of calling functions called by a currently running thread in the target object is determined according to the target function, the first calling function and a calling stack frame of the first calling function.

[0176] The step of determining the set of calling functions called by the currently running thread in the target object according to the target function, the first calling function and the calling stack frame of the first calling function includes:

[0177] If there is an upper-layer call pointer in the call stack frame of the first call function, determine the call function that calls the first call function in the target object as the second call function according to the upper-layer call pointer in the call stack frame of the first call function, and add the target function, the first call function and the second call function to the call function set;

[0178] If there is no upper-layer call pointer in the call stack frame of the first calling function, the target function and the first calling function are added to the calling function set.

[0179] The embodiment of the present invention obtains the running parameters of the currently running thread in the target object to be monitored by calling a monitoring thread during the running of the target object to be monitored; wherein the running parameters of the currently running thread include the running time and the running resource occupancy rate, and the running time of the currently running thread can be monitored by calling the parameter monitoring function in the monitoring thread, and if there is an abnormality in the running parameters of the currently running thread in the target object, the callback function is called to read the call stack of the currently running thread; the running resource occupancy rate of the currently running thread can also be monitored by the monitoring thread, and if there is an abnormality in the running parameters of the currently running thread in the target object, it is determined whether the currently running thread is a target type thread, and if the current thread is a target type thread, the call stack of the currently running thread is read; the call stack of the currently running thread is analyzed to specifically analyze the reason why the currently running thread has an abnormality; the call stack can be used to trace back to the call function set called by the currently running thread, and the call function in the call function set is the reason why the running parameters of the currently running thread are abnormal. Therefore, the call function set called by the currently running thread in the target object can be determined according to the call stack of the currently running thread; the call function in the call function set is determined as the call function abnormally called by the currently running thread. It can be seen that in this application, by stack tracing of the currently running thread and the call stack of the currently running thread, not only can the thread with abnormal running parameters be traced back, but also the call function abnormally called by the abnormal thread can be obtained; it is conducive to accurately obtaining the cause of the abnormal call of the currently running thread, that is, it is conducive to accurately obtaining the cause of the abnormal problem of the target object.

[0180] In addition, it should be pointed out here that: the embodiment of the present application also provides a computer-readable storage medium, and the computer-readable storage medium stores a computer program executed by the thread monitoring device mentioned above, and the computer program includes program instructions. When the processor executes the program instructions, the above-mentioned Figure 1 or Figure 5 The description of the above-mentioned thread monitoring method in the corresponding embodiment will not be repeated here. In addition, the description of the beneficial effects of the same method will not be repeated. For technical details not disclosed in the computer-readable storage medium embodiment involved in this application, please refer to the description of the method embodiment of this application. As an example, program instructions may be deployed on a computer device for execution, or deployed on multiple computer devices located at one location for execution, or, executed on multiple computer devices distributed at multiple locations and interconnected by a communication network, and multiple computer devices distributed at multiple locations and interconnected by a communication network may constitute a blockchain network.

[0181] Those skilled in the art can understand that all or part of the processes in the above-mentioned embodiments can be implemented by instructing the relevant hardware through a computer program, and the above-mentioned program can be stored in a computer-readable storage medium, and when the program is executed, it can include the processes of the embodiments of the above-mentioned methods. The above-mentioned storage medium can be a disk, an optical disk, a read-only memory (ROM) or a random access memory (RAM), etc.

[0182] The above disclosure is only the preferred embodiment of the present invention, which certainly cannot be used to limit the scope of the present invention. Therefore, equivalent changes made according to the claims of the present invention are still within the scope of the present invention.

Claims

1. A thread monitoring method, characterized in that: include: During the operation of the target object to be monitored, calling the monitoring thread to obtain the operation parameters of the currently running thread in the target object; The target object to be monitored refers to RN-like services, mini-games or mini-program applications; the currently running thread in the target object is a JS running thread, and RN is a cross-platform mobile application development framework; If the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread; Determine a set of calling functions called by the currently running thread in the target object according to the call stack of the currently running thread; A calling function in the calling function set is determined as the calling function abnormally called by the currently running thread.

2. The method according to claim 1, characterized in that The operation parameters include the operation duration, and the monitoring thread includes a parameter monitoring function; If the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread includes: Calling the parameter monitoring function to monitor the running parameters of the currently running thread, the parameter monitoring function including a first duration threshold; If the running time of the currently running thread is greater than the first time threshold, it is determined that there is an abnormality in the running parameters of the currently running thread in the target object, and a callback function is called to read the call stack of the currently running thread.

3. The method according to claim 2, characterized in that The method further comprises: Obtaining the address pointer of the parameter monitoring function; Acquire the duration limit variable in the parameter monitoring function according to the address pointer of the parameter monitoring function; The threshold of the duration limit variable is set to the first duration threshold, and a calling strategy is added in the parameter monitoring function, wherein the calling strategy is used to call the callback function to read the call stack of the currently running thread if the running time of the currently running thread is greater than the first duration threshold.

4. The method according to any one of claims 1 to 3, characterized in that: The operating parameters include operating resource occupancy rate; If the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread includes: If the operation resource occupancy rate of the currently running thread in the target object is greater than a preset occupancy rate threshold, then obtaining the duration of the operation resource occupancy rate of the currently running thread in the target object being greater than the preset occupancy rate threshold; If the duration exceeds the second duration threshold, it is determined that an abnormality exists in the running parameters of the currently running thread, and the call stack of the currently running thread is read.

5. The method according to claim 4, characterized in that If the duration of the interrupt exceeds the second duration threshold, determining that an abnormality exists in the running parameters of the currently running thread, and reading the call stack of the currently running thread, includes: If the duration exceeds a second duration threshold, determining that an abnormality exists in the running parameters of the currently running thread, and obtaining a corresponding relationship between the thread identifier and the thread type; Determining the thread type of the currently running thread according to the corresponding relationship between the thread identifier and the thread type; If the thread type of the currently running thread is a target thread type, then the call stack of the currently running thread is read; the target thread type refers to a thread type used to interpret and compile code information.

6. The method according to any one of claims 1 to 3, characterized in that: The step of determining a set of calling functions called by the currently running thread in the target object according to the call stack of the currently running thread includes: Determine the target function called by the currently running thread from the call stack of the currently running thread; Obtaining a call stack frame of the target function, and determining an upper layer call pointer from the call stack frame of the target function; Determine, according to the upper-layer calling pointer, an upper-layer calling function that calls the target function as a first calling function; Obtaining a call stack frame of the first calling function; A set of calling functions called by a currently running thread in the target object is determined according to the target function, the first calling function and a calling stack frame of the first calling function.

7. The method according to claim 6, characterized in that The step of determining a set of calling functions called by the currently running thread in the target object according to the target function, the first calling function and the calling stack frame of the first calling function comprises: If there is an upper-layer call pointer in the call stack frame of the first call function, determine the call function that calls the first call function in the target object as the second call function according to the upper-layer call pointer in the call stack frame of the first call function, and add the target function, the first call function and the second call function to the call function set; If there is no upper-layer call pointer in the call stack frame of the first calling function, the target function and the first calling function are added to the calling function set.

8. A thread monitoring device, characterized in that: include: An acquisition module is used to call a monitoring thread to acquire the operation parameters of the currently running thread in the target object to be monitored during the operation of the target object to be monitored; The target object to be monitored refers to RN-like services, mini-games or mini-program applications; the currently running thread in the target object is a JS running thread, and RN is a cross-platform mobile application development framework; A reading module, configured to read a call stack of a currently running thread if an abnormality exists in the running parameters of the currently running thread in the target object; A first determining module, configured to determine a set of calling functions called by the currently running thread in the target object according to a call stack of the currently running thread; The second determining module is used to determine the calling function in the calling function set as the calling function abnormally called by the currently running thread.

9. A computer device, characterized in that: include: Processor, memory, and network interface; The processor is connected to a memory and a network interface, wherein the network interface is used to provide a data communication function, the memory is used to store program codes, and the processor is used to call the program codes to execute the method according to any one of claims 1 to 7.

10. A computer-readable storage medium, characterized in that: The computer-readable storage medium stores a computer program, wherein the computer program includes program instructions, and when the program instructions are executed by a processor, the steps of the method according to any one of claims 1 to 7 are executed.

Citation Information

Patent Citations

  • Lagging processing method and related equipment

    CN109840177A

  • Program exception response method and device

    CN110245077A