CN114328073A - Thread monitoring method, device, equipment and storage medium - Google Patents

Thread monitoring method, device, equipment and storage medium Download PDF

Info

Publication number
CN114328073A
CN114328073A CN202011081396.9A CN202011081396A CN114328073A CN 114328073 A CN114328073 A CN 114328073A CN 202011081396 A CN202011081396 A CN 202011081396A CN 114328073 A CN114328073 A CN 114328073A
Authority
CN
China
Prior art keywords
thread
function
calling
currently running
call
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202011081396.9A
Other languages
Chinese (zh)
Inventor
张凯
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Shenzhen Tencent Computer Systems Co Ltd
Original Assignee
Shenzhen Tencent Computer Systems Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Shenzhen Tencent Computer Systems Co Ltd filed Critical Shenzhen Tencent Computer Systems Co Ltd
Priority to CN202011081396.9A priority Critical patent/CN114328073A/en
Publication of CN114328073A publication Critical patent/CN114328073A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention discloses a thread monitoring method, a thread monitoring device, thread monitoring equipment and a storage medium. The thread monitoring method comprises the following steps: calling a monitoring thread to acquire the running parameters of the currently running thread in a target object in the running process of the target object to be monitored; if the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread; determining a calling function set called by the currently running thread in the target object according to the calling stack of the currently running thread; and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread. By adopting the scheme, the reason of the abnormal problem of the application program can be accurately acquired.

Description

Thread monitoring method, device, equipment and storage medium
Technical Field
The present invention relates to the field of internet technologies, and in particular, to a method, an apparatus, a device, and a storage medium for thread monitoring.
Background
With the development of internet technology, various applications (such as taxi taking applications, social applications, office applications) have come into operation, and great convenience is brought to work and life of users. However, in the process of running these applications, if the application has an abnormal problem such as jamming, the application is likely to be flashed back. In the prior art, the reason for the abnormal problem of the application program is obtained by monitoring a main thread running in the application program; however, the accuracy of this monitoring method is low, and the reason why the application program has an abnormal problem cannot be accurately obtained.
Disclosure of Invention
The embodiment of the invention provides a thread monitoring method, a thread monitoring device, a thread monitoring equipment and a storage medium, which can accurately acquire the reason of the abnormal problem of an application program.
In one aspect, an embodiment of the present invention provides a thread monitoring method, where the thread monitoring method includes:
calling a monitoring thread to acquire the running parameters of the currently running thread in a target object to be monitored in the running process of the target object;
if the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread;
determining a calling function set called by the currently running thread in the target object according to the calling stack of the currently running thread;
and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread.
The operation parameters comprise operation duration, and the monitoring threads comprise parameter monitoring functions;
if the running parameter of the currently running thread in the target object is abnormal, reading the call stack of the currently running thread, including:
calling the parameter monitoring function to monitor the running parameters of the currently running thread, wherein the parameter monitoring function comprises a first time length threshold;
and if the running time of the currently running thread is longer than the first time threshold, determining that the running parameters of the currently running thread in the target object are abnormal, and calling a callback function to read the call stack of the currently running thread.
Wherein, the method further comprises:
acquiring an address pointer of the parameter monitoring function;
acquiring a time limit variable in the parameter monitoring function according to an address pointer of the parameter monitoring function;
setting the threshold of the time limit variable as a first time threshold, and adding a calling strategy in the parameter monitoring function, wherein the calling strategy is used for calling the callback function to read the calling stack of the currently running thread if the running time of the currently running thread is greater than the first time threshold.
Wherein the operation parameters comprise operation resource occupancy rates;
if the running parameter of the currently running thread in the target object is abnormal, reading the call stack of the currently running thread, including:
if the operating resource occupancy rate of the currently operated thread in the target object is greater than the preset occupancy rate threshold, acquiring the duration of the currently operated thread in the target object when the operating resource occupancy rate is greater than the preset occupancy rate threshold;
and if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and reading the call stack of the currently running thread.
Wherein, if the duration exceeds a second duration threshold, determining that the running parameter of the currently running thread is abnormal, and reading the call stack of the currently running thread, includes:
if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and acquiring the corresponding relation between the thread identification and the thread type;
determining the thread type of the currently running thread according to the corresponding relation between the thread identification and the thread type;
if the thread type of the currently running thread is a target thread type, reading a call stack of the currently running thread; the above-mentioned target thread type refers to a thread type for interpreting and compiling code information.
Wherein, the determining, according to the call stack of the currently running thread, a call function set in the target object for calling the currently running thread includes:
determining a target function called by the currently running thread from a call stack of the currently running thread;
acquiring a calling stack frame of the target function, and determining an upper layer calling pointer from the calling stack frame of the target function;
determining an upper layer calling function for calling the target function according to the upper layer calling pointer, and taking the upper layer calling function as a first calling function;
acquiring a calling stack frame of the first calling function;
and determining a calling function set 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.
Determining a calling function set 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, wherein the determining comprises the following steps of;
if an upper-layer call pointer exists in the call stack frame of the first call function, determining a call function for calling the first call function in the target object according to the upper-layer call pointer in the call stack frame of the first call function, using the call function as a second call function, and adding the target function, the first call function and the second call function to the call function set;
and if the calling stack frame of the first calling function does not have an upper layer calling pointer, adding the target function and the first calling function into the calling function set.
In one aspect, an embodiment of the present application provides a thread monitoring apparatus, including:
the first acquisition module is used for calling a monitoring thread to acquire the running parameters of the currently running thread in the target object in the running process of the target object to be monitored;
a reading module, configured to read a call stack of a currently running thread if an operating parameter of the currently running thread in the target object is abnormal;
a first determining module, configured to determine, according to the call stack of the currently running thread, a call function set called by the currently running thread in the target object;
and the second determining module is used for determining the calling function in the calling function set as the calling function abnormally called by the currently running thread.
The operation parameters comprise operation duration, and the monitoring threads comprise parameter monitoring functions;
the reading module comprises:
the monitoring unit is used for calling the parameter monitoring function to monitor the running parameters of the currently running thread, and the parameter monitoring function comprises a first time length threshold;
and the calling unit is used for determining that the running parameter of the currently running thread in the target object is abnormal if the running time of the currently running thread in running is longer than the first time threshold, and calling a callback function to read the calling stack of the currently running thread.
Wherein, above-mentioned device still includes:
the second acquisition module is used for acquiring an address pointer of the parameter monitoring function;
a third obtaining module, configured to obtain a time limit variable in the parameter monitoring function according to the address pointer of the parameter monitoring function;
and the adding module is used for setting the threshold of the time length limiting variable as the first time length threshold, and adding a calling strategy in the parameter monitoring function, wherein the calling strategy is used for calling the callback function to read the calling stack of the currently running thread if the running time length of the currently running thread is greater than the first time length threshold.
Wherein the operation parameters comprise operation resource occupancy rates;
the reading module comprises:
a first obtaining unit, configured to obtain a duration for which an occupancy rate of a running resource of a currently running thread in the target object is greater than a preset occupancy rate threshold if the occupancy rate of the running resource of the currently running thread in the target object is greater than the preset occupancy rate threshold;
and the reading unit is used for determining that the running parameters of the currently running thread are abnormal if the duration exceeds a second duration threshold value, and reading the call stack of the currently running thread.
Wherein, the reading unit is specifically configured to:
if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and acquiring the corresponding relation between the thread identification and the thread type;
determining the thread type of the currently running thread according to the corresponding relation between the thread identification and the thread type;
if the thread type of the currently running thread is a target thread type, reading a call stack of the currently running thread; the above-mentioned target thread type refers to a thread type for interpreting and compiling code information.
Wherein the second determining module includes:
a first determining unit, configured to determine, from a call stack of the currently running thread, a target function called by the currently running thread;
a second determining unit, configured 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;
a third determining unit, configured to determine, according to the upper layer call pointer, an upper layer call function that calls the target function, as a first call function;
an obtaining unit, configured to obtain a call stack frame of the first call function;
a fourth determining unit, configured to determine, according to the target function, the first call function, and the call stack frame of the first call function, a call function set called by a currently running thread in the target object.
Wherein, the fourth determining unit is specifically configured to:
if an upper-layer call pointer exists in the call stack frame of the first call function, determining a call function for calling the first call function in the target object according to the upper-layer call pointer in the call stack frame of the first call function, using the call function as a second call function, and adding the target function, the first call function and the second call function to the call function set;
and if the calling stack frame of the first calling function does not have an upper layer calling pointer, adding the target function and the first calling function into the calling function set.
An embodiment of the present application provides a computer device, including: a processor, a memory, a network interface;
the processor is connected with a memory and a network interface, wherein the network interface is used for providing a data communication function, the memory is used for storing a computer program, and the processor is used for calling the computer program to execute the method in the embodiment of the application.
Embodiments of the present application provide a computer-readable storage medium storing a computer program comprising program instructions that, when executed by a processor, perform a method as in embodiments of the present application.
In the embodiment of the invention, in the running process of a target object to be monitored, the running parameters of a currently running thread in the target object are obtained by calling a monitoring thread; if the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread; the call stack can be used for backtracking the call function set called by the currently running thread, and the call function in the call function set is the reason for causing the running parameter of the currently running thread to be abnormal. Therefore, the calling function set called by the currently running thread in the target object can be determined according to the calling stack of the currently running thread; and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread. Therefore, in the application, by analyzing the currently running thread and the call stack of the currently running thread, the thread with abnormal running parameters can be traced, and the call function called by the abnormal thread can be obtained; the method and the device are favorable for accurately acquiring the reason of the abnormal call of the currently running thread, namely the reason of the abnormal problem of the target object.
Drawings
In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the drawings needed to be used in the description of the embodiments are briefly introduced below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and it is obvious for those skilled in the art to obtain other drawings based on these drawings without creative efforts.
Fig. 1 is a schematic flowchart of a thread monitoring method according to an embodiment of the present application;
FIG. 2 is a schematic diagram of a method for detecting an abnormal problem according to an embodiment of the present application;
fig. 3 is a schematic structural diagram of a Native call stack frame according to an embodiment of the present disclosure;
fig. 4 is a schematic structural diagram of a JS call stack frame according to an embodiment of the present application;
FIG. 5 is a flowchart illustrating another thread monitoring method according to an embodiment of the present disclosure;
FIG. 6 is a diagram illustrating a call stack according to an embodiment of the present disclosure;
fig. 7 is a schematic structural diagram of a thread monitoring apparatus according to an embodiment of the present invention;
fig. 8 is a schematic structural diagram of a computer device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present application will be clearly and completely described below with reference to the drawings in the embodiments of the present application, and it is obvious that the described embodiments are some, but not all, embodiments of the present application. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Please refer to fig. 1, which is a flowchart illustrating a thread monitoring method according to an embodiment of the present application, where the embodiment of the present application may be executed by an electronic device, the electronic device may refer to a terminal or a server, and the terminal may include but is not limited to: smart phones, tablet computers, notebook computers, desktop computers, smart speakers, smart watches, and the like; the server may be an independent physical server, a server cluster or a distributed system formed by a plurality of physical servers, or a cloud server providing basic cloud computing services such as cloud service, a cloud database, cloud computing, a cloud function, cloud storage, Network service, cloud communication, middleware service, domain name service, security service, Content Delivery Network (CDN), big data and an artificial intelligence platform. The thread monitoring method includes the following steps S101 to S104.
S101, in the running process of the target object to be monitored, calling a monitoring thread to obtain the running parameters of the currently running thread in the target object.
In order to make the target object have the problems of jamming, large power consumption and the like in the running process, the problem caused by the execution of codes for calling functions by threads can be specifically known, so that in the running process 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 may refer to a similar RN service, a mini game, an applet, and the like, where the RN refers to a short for fact Native, is a cross-platform mobile application development framework, and is a derivative of JS framework software on a Native mobile application platform, and the RN uses Javascript. JS is JavaScript (JS), which is a lightweight, interpreted, or just-in-time high-level programming language with function priority. The operation parameter of the running thread may refer to a time length spent when executing a corresponding code in the running thread, or an operation resource occupancy rate occupied when executing a code corresponding to the running thread, such as a CPU (central processing unit) occupancy rate, a memory occupancy rate, a network occupancy rate, and the like. The control thread can monitor the running parameters of the current running thread in the target object, so that abnormal problems of blockage, large power consumption and the like in the running process of the target object can be monitored.
S102, if the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread.
And when the monitoring thread finds that the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread. The call stack is function information called in a certain thread of an application program (namely, a target object) according to a certain sequence in the running process of the application program, and the function information called in the certain thread of the application program can be known to comprise a function name, position information and the like through the reduction stack. In this case, there may be many functions called by one thread, but each thread can only execute one function at a time point, and the executed function is referred to as a currently called function.
Optionally, in the embodiment of the present application, the currently running thread in the target object may be a JS thread, JS refers to JavaScript (JS for short), which is a lightweight, interpreted, or just-in-time high-level programming language with function priority, and the JS thread refers to a thread using the JavaScript programming language. In the prior art, the thread exception problem can only be monitored based on a pure Native call stack frame, Native refers to a computer function, and the Native function is realized by a non-Java language, such as C or C + +. The abnormal problem of the JS operation thread can not be monitored based on the pure Native call stack frame, and the abnormal problem caused by the reason can not be obtained exactly. The call Stack Frame is a memory model of code execution corresponding to a function, and is used for function call and a data area of function execution, when each function is executed, a Stack Frame (Stack Frame) is created for storing a local variable table, an operand Stack, a dynamic link, a function outlet and the like, and according to the call Stack Frame corresponding to each call function called by the currently-running thread, the call Stack of the currently-running thread in the target object can be determined. In addition, in the prior art, when the operation thread is monitored, the abnormal problem information of the main thread is obtained, the specific abnormal problem information of the JS operation thread cannot be obtained, and the abnormal problem of the operation thread is analyzed based on Native calling stack frame information, so that the specific reason that the abnormal problem exists in the JS operation thread cannot be accurately obtained. Therefore, in the process of running 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, and if the running parameters of the currently running thread are abnormal, the call stack of the currently running thread is read.
When a problem occurs in a target object in the prior art, the information of a traditional Native call stack frame is obtained in the prior art, the information of a JS call stack frame corresponding to a JS operation thread in the target object is not obtained, and the JS service cannot be helped to solve the problem, so that a specific reason for the problem occurring in the JS operation thread in the target object cannot be obtained. Only if the calling stack frame of the JS thread is obtained, the JS service can know that the code of the JS function in the JS running thread of the JS service is in problem, and the problem is solved. The JS call stack frame is a call stack frame using a function of Javascript. The functions called by one running thread may be many, but each thread can only execute one function at one time point, the executed function is called a current calling function, and the current calling function is taken as a target function. As shown in fig. 2, for a schematic diagram of a method for detecting an abnormal problem provided in this embodiment, as shown in fig. 2, when monitoring a running thread in the prior art, the running of a main thread is detected according to a detection thread, and whether the running of the main thread is overtime or CPU is too high is determined, if the running of the main thread is overtime or CPU is too high, a call stack of the main thread is dumped, and after the dumping is successful, the main thread is continuously detected by waiting for a period of time. And if the main thread does not run overtime or the CPU is too high, continuing to detect the main thread after a period of time. In the prior art, when the call stack of the main thread is dumped, the Native call stack frame of the main thread is dumped, and if the current running thread is the JS running thread, the reason why the JS running thread is abnormal cannot be obtained according to the Native call stack frame. As shown in fig. 3, for a schematic structural diagram of a Native call stack frame provided in the embodiment of the present application, as shown in fig. 3, conventionally, tracing back a Native call stack frame to obtain exception problem information is completed based on call stack frame information based on an arm (microprocessor). The arm call stack frame can recursively obtain all information of the call stack frame through the information of LR (return pointer), FP (frame pointer), SP (stack pointer). As shown in fig. 3, the Native call stack frame structure includes a return pointer of an upper-layer call function that calls a target function (i.e., a current call function), and a frame pointer of an upper-layer call function that calls the target function, as well as an Allocation memory (Allocation) and stack parameters (stuck definitions). The return pointer in the Native call stack frame structure is the return pointer of the upper layer call function calling the target function, the frame pointer 1 is the frame pointer of the target function, and the frame pointer 2 is the frame pointer of the upper layer function calling the target function. Native calls the high address in the frame structure of the stack and stores the data which is firstly put on the stack, namely the direction of the bottom of the stack; the lower address stores the data that is pushed later, i.e., the top of stack direction. Specifically, the purpose of the frame pointer (ebp) is to address in the stack, and the stack pointer (esp) moves along with the pushing and the pulling of data, that is, the frame pointer points to the bottom (high address) of the current stack frame, and the stack pointer points to the top (ground address) of the current stack frame.
As shown in fig. 4, which is a schematic diagram of a JS call stack frame structure provided in the embodiment of the present application, as shown in fig. 4, the JS call stack frame is also somewhat similar to a Native arm call stack frame. When JavaScript core (a virtual machine specially processing JavaScript codes) interprets and generates bytecode or performs JIT (just in time compiler) optimization, the parameter transfer and the transfer of call stack frame information are organized according to its call stack frame call form. Specifically, as shown in fig. 4, when a function call occurs, the parameters n, … …, 2, and 1 of the upper-level calling function (the function that calls the target function) are sequentially stacked one by one from the upper address (bottom direction) to the lower address (top direction), and then a this pointer is stacked, where the object that the this pointer finally points to is the calling target function (current calling function), and this is a key in C + + (programming language), and is also a pointer that points to the current object, through which all members of the current object can be accessed. Next is the number of push parameters, then information of the push target function (currently calling function), next information of the code block (JS codeBlock) of the push target function (currently calling function), and return address information after execution of javascript core, and information of the upper layer calling function (caller). With this structure, the interpreter of javascript core generates the rules for engagement of each JS call function call. The parameter passing rules of the function call of JS and the function call of armv8 in Native are somewhat similar, but only the parameter passing of JS is basically based on stack passing, and the parameter passing of armv8 can use registers to pass parameters as much as possible, so the parameter passing of JS is more efficient. In the prior art, the information of the traditional Native call stack frame is obtained, the information of the JS call stack frame corresponding to the JS running thread in the target object is not obtained, and the JS service cannot be helped to solve the problem, so that the specific reason for the occurrence of the JS service in the target object cannot be obtained. Only if the calling stack frame of the JS operation thread is obtained, the JS service can know that the code of the JS function of the JS operation thread is a problem, the problem is solved by positioning, and the code information of the calling function in the JS operation thread which is specially in an abnormal problem can be obtained according to the JS calling stack frame.
Optionally, the operation parameter includes an operation duration, and the monitoring thread includes a parameter monitoring function; calling a parameter monitoring function to monitor the running parameters of the currently running thread, wherein the parameter monitoring function comprises a first time length threshold; and if the running time of the currently running thread is longer than the first time threshold, determining that the running parameter of the currently running thread in the target object is abnormal, and calling a callback function to read the call stack of the currently running thread.
The running parameter of the currently running thread in the target object can be running time length, the monitoring thread comprises a parameter monitoring function, and in 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 parameter of the currently running thread, namely the running time length of the currently running thread in the target object is monitored, so that whether the currently running thread is blocked or not is judged in real time. If the running time of the currently running thread is longer than the first time threshold, determining that the running parameter of the currently running thread in the target object is abnormal, indicating that the currently running thread is stuck, and calling a callback function to read a call stack of the currently running thread. And if the running time of the currently running thread is less than or equal to the first time threshold, determining that the running parameters of the currently running thread in the target object are not abnormal, indicating that the currently running thread belongs to normal running, and continuously monitoring the running parameters of the currently running thread. The callback function is used for feeding back the running thread with abnormal running parameters, namely if the running time of the current running thread is longer than a first time threshold, the callback function is triggered, the current running thread in the target object is fed back to be abnormal, and calling stack information of the function called by the current running thread with the abnormal running parameter is provided.
Optionally, before the parameter monitoring function is called to monitor the operating parameter of the currently operating thread, an address pointer of the parameter monitoring function is obtained, and the duration limiting variable in the parameter monitoring function is obtained according to the address pointer of the parameter monitoring function. Setting the threshold of the time length limiting variable as a first time length threshold, adding a calling strategy in the parameter monitoring function, wherein the calling strategy is used for calling a callback function to read a calling stack of a currently running thread if the running time of the currently running thread is greater than the first time length threshold.
Before calling the parameter monitoring function to monitor the operating parameters of the currently operating thread, a parameter monitoring function for monitoring the currently operating thread in the target object can be constructed, and the parameter monitoring function is initialized. After the parameter monitoring function is initialized, the address pointer of the parameter monitoring function is obtained, and the time limit variable in the parameter monitoring function is obtained according to the address pointer of the parameter monitoring function. Setting the threshold of the time length limiting variable as a first time length threshold, adding a calling strategy in the parameter monitoring function, wherein the calling strategy is used for calling a callback function to read a calling stack of a currently running thread if the running time of the currently running thread is greater than the first time length threshold. That is, if the running time of the currently running thread is too long and is greater than the first time threshold, it indicates that the currently running thread is stuck, a callback policy is triggered, a callback function is called, the currently stuck running thread is fed back, and a call stack of the currently running thread is read.
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 through a Watchdog mechanism. The Watchdog mechanism is a monitoring mechanism which is arranged in Javascript core (a virtual machine specially processing JavaScript codes) and detects whether the consumed time for the JS thread to execute task submission execution exceeds a morton threshold value. Due to the closed (many websites are not compatible with the Webkit kernel, and web pages such as login interface, internet bank and the like cannot use the browser of the Webkit kernel) of the Webkit (open source browser engine), the Watchdog mechanism is not a publicly usable mode. Therefore, we trigger the turn on of watchdog in the whole javascript score by setting setenv (for changing or adding environment variable) of the environment variable. Before the parameter monitoring function is called to monitor the operating parameters of the currently running thread, a parameter monitoring function for monitoring the operating parameters of the currently running thread can be constructed, that is, a parameter monitoring function of a virtual machine corresponding to the currently running thread of a target object (that is, a function in a hook target object, and a parameter monitoring function which can be called by the user is established in the target object) is constructed, and the parameter monitoring function is initialized. After the parameter monitoring function is initialized, 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 is found through the issued offset value, and the time length limiting variable in the parameter monitoring function is obtained according to the address pointer of the parameter monitoring function. Setting the threshold of the time length limiting variable as a first time length threshold, adding a calling strategy in the parameter monitoring function, wherein the calling strategy is used for calling a callback function to read a calling stack of the currently running thread if the running time length of the currently running thread in running is greater than the first time length threshold. When the code execution times out, a callback function is triggered, the call stack of the call function called by the currently running thread can be obtained according to the callback function, so that the Watchdog mechanism is dynamically triggered to run, the preset callback function is triggered according to the specified first time threshold, and the blockage monitoring of the currently running thread is finally realized.
Optionally, the operation parameter of the currently operated thread includes an operation resource occupancy rate; if the operating resource occupancy rate of the currently operated thread in the target object is greater than the preset occupancy rate threshold, acquiring the duration of the currently operated thread in the target object when the operating resource occupancy rate is greater than the preset occupancy rate threshold; and if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and reading the call stack of the currently running thread.
The operation parameters of the currently operated threads can refer to the CPU occupancy rate, a monitoring thread can be established, the operation resource occupancy rates of all the operation threads in the target object are monitored, and the operation resource occupancy rates of all the operation threads in the target object are obtained 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, acquiring the duration of the time when the running resource occupancy rate of the currently running thread in the target object is greater than the preset occupancy rate threshold, namely timing the running thread of which the running resource occupancy rate is greater than the preset resource occupancy rate in the target object. And if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and reading the call stack of the currently running thread if the current running thread is abnormal, which indicates that the running resource occupancy rate of the currently running thread is too high, abnormal occupation occurs, and the power consumption is too high.
Optionally, if the duration exceeds the second duration threshold, determining that an operating parameter of the currently running thread is abnormal, 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 relation between the thread identification and the thread type; and if the thread type of the currently running thread is a target thread type, reading the call stack of the currently running thread, wherein the target thread type is the thread type for interpreting and compiling the code information.
In the embodiment of the application, if the duration of the running resource occupancy rate of the previous running thread is greater than the second duration threshold when the preset occupancy rate threshold is greater than the occupancy rate threshold, it is determined that the running parameter of the current running thread is abnormal, that is, the running resource is occupied too much for the long time of the running thread of the target object. The corresponding relationship 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 corresponding relationship between the thread identifier and the thread type. And if the thread type of the current running thread in the target object is the target thread type, reading the call stack of the current running thread, wherein the target thread type is the thread type which directly explains and runs the code information of the called function. In the implementation of the present application, the target thread type may be a JS thread type. The currently running thread in the target object can be a JS thread, since javascript core supports multi-threaded calling, but we cannot directly know whether a thread is a JS thread. The mapping relationship between the thread id and the thread type can be stored by constructing a data table HashMap which is a hash mapping used for mapping (key value pair) processing. According to the mapping relation between the thread id and the thread type, whether the thread type of the currently running thread is the JS thread type can be known. And if the JS thread has abnormal power consumption, acquiring a call stack of the currently running thread.
S103, determining a calling function set called by the currently running thread in the target object according to the calling stack of the currently running thread.
And S104, determining the calling function in the calling function set as the calling function abnormally called by the currently running thread.
If the current running thread has an abnormal problem, reading a function called by the current running thread as a target function, acquiring a call stack of the target function, performing stack backtracking on the call stack, and acquiring a call function set called by the current running thread in a target object. As described above, the call Stack Frame (i.e., Stack Frame) of the target function may be obtained, where the call Stack Frame refers to a memory model for code execution corresponding to the function, and a Stack Frame (Stack Frame) is created when each function is executed, and is used to store a local variable table, an operand Stack, a dynamic link, a function exit, and the like. The calling stack frame of the target function stores code information of the target function and information of an upper calling function for calling the target function, so that the information of the upper calling function for calling the target function can be determined according to the calling stack frame of the target function called by the currently running thread, and a calling function set for calling the target function is determined according to the information of the upper calling function for calling the target function, so that the calling function set called by the currently running thread in the target object is obtained.
In the embodiment of the invention, a monitoring thread is called to obtain the running parameters of the currently running thread in the target object in the running process of the target object to be monitored; the running parameters of the currently running thread comprise running duration and running resource occupancy rate, the running duration of the currently running thread can be monitored according to a parameter monitoring function in a calling monitoring thread, and if the running parameters of the currently running thread in the target object are abnormal, a call-back function is called to read a calling stack of the currently running thread; the running resource occupancy rate of the currently running thread can also be monitored according to the monitoring thread, if the running parameters of the currently running thread in the target object are abnormal, whether the currently running thread is a target type thread or not is judged, and if the currently running thread is the target type thread, the call stack of the currently running thread is read; analyzing the call stack of the currently running thread, wherein the reason why the currently running thread is abnormal can be specifically analyzed; the call stack can be used for backtracking the call function set called by the currently running thread, and the call function in the call function set is the reason for causing the running parameter of the currently running thread to be abnormal. Therefore, the calling function set called by the currently running thread in the target object can be determined according to the calling stack of the currently running thread; and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread. Therefore, in the application, by analyzing the currently running thread and the call stack of the currently running thread, the thread with abnormal running parameters can be traced, and the call function called by the abnormal thread can be obtained; the method and the device are favorable for accurately acquiring the reason of the abnormal call of the currently running thread, namely the reason of the abnormal problem of the target object.
As shown in fig. 5, which is a schematic flowchart of another thread monitoring method provided in the embodiment of the present application, as shown in fig. 5, the another thread monitoring method includes steps S201 to S208.
S201, in the running process of the target object to be monitored, calling a monitoring thread to obtain the running parameters of the currently running thread in the target object.
S202, if the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread.
The specific contents of steps S201 to S202 can refer to the specific contents illustrated in fig. 1, and the embodiments of the present application will not be described herein again.
S203, determining the target function called by the current running thread from the call stack of the current running thread.
S204, acquiring the calling stack frame of the target function, and determining an upper layer calling pointer from the calling stack frame of the target function.
If the running parameters of the currently running thread in the target object are abnormal, determining a function called by the currently running thread from the call stack of the currently running thread, namely a call function at the top layer in the call stack of the currently running thread, as a target function, and reading a call stack frame of the target function in the currently running thread. The currently running thread in the target object may be a JS thread, and as shown in fig. 4, the call stack frame of the JS thread includes parameters of an upper layer call function (a function that calls the target function), information of a target function (current call function callee) code block (JS codeBlock), and information of an upper layer call function (caller). After the calling stack frame of the target function of the current running thread is obtained, the code information of the target function, and the function name and the position information of the upper layer calling function calling the target function can be obtained in the calling stack frame of the target function. Therefore, the address pointer of the upper layer calling function calling the target function, namely the upper layer calling pointer, can be obtained in the calling stack frame of the target function.
S205, determining an upper layer calling function of the calling target function according to the upper layer calling pointer as a first calling function.
S206, acquiring a calling stack frame of the first calling function.
S207, determining a calling function set 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.
S208, determining the calling function in the calling function set as the calling function abnormally called by the currently running thread.
And determining a calling function for calling the target function in the target object as a first calling function according to an upper calling pointer of an upper calling function for calling the target function. And then acquiring a calling stack frame of the first calling function, wherein the calling stack frame of the first calling function also stores code block information of the first calling function and information of an upper layer calling function calling the first calling function. Therefore, the calling function set calling 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.
Optionally, if the upper-layer call pointer exists in the call stack frame of the first call function, determining, according to the upper-layer call pointer in the call stack frame of the first call function, a call function in the target object, which calls the first call function, as a second call function, and adding the target function, the first call function, and the second call function to the call function set. And if the calling stack frame of the first calling function does not have an upper layer calling pointer, adding the target function and the first calling function into the calling function set.
If the calling stack frame of the first calling function has an upper layer calling pointer, the first calling function is indicated to be stored in the upper layer calling function and is not the initial calling function; if the calling stack frame of the first calling function does not have the upper layer calling pointer, the first calling function is the initial calling function and does not have the upper layer calling function. If the upper layer call pointer exists in the call stack frame of the first call function, determining a call function calling the first call function in the target object according to the upper layer call pointer in the call stack of the first call function, using the call function as a second call function, and adding the first call function and the second call function to the call function set. And then judging whether the second calling function exists in an upper calling function or not, and if the second calling function exists in the upper calling function, acquiring the upper calling function of the second calling function as a third calling function. And in the same way, backtracking is carried out until the upper layer calling function is empty or the maximum backtracking depth is reached, wherein the maximum backtracking depth refers to the stack bottom of the calling stack backtracking to the currently running thread, so that all calling functions called by the currently running thread are obtained.
Optionally, as shown in fig. 6, for the schematic structural diagram of the call stack provided in the embodiment of the present application, when a JS function is called by a C + + function, the javascript core generates a VMEntryRecord again
The (virtual machine input record) structure, VMEntryRecord (virtual machine input record) records the called function, and information of the upper layer calling function. Multiple VMEntryRecord (virtual machine input records) combine to form a set of call stack relationships between C + + and JS. As shown in fig. 6, the direction from bottom to top is the direction from the high address to the 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 information of the local function call stack (i.e., Native call stack frame). And finding a pointer entering the current VM virtual machine in the call stack, and entering the current VM virtual machine according to the pointer, wherein the VMEntryRecord (virtual machine input record) in the current VM virtual machine is information of a call function called by the JS operation thread. The method comprises the steps of obtaining a currently called target function and an upper layer calling function of the target function at the VMEntryRecord (virtual machine input record) of the current vm virtual machine, obtaining the last VMEntryRecord of the current VMEntryRecord according to the upper layer calling function of the target function, and determining a calling stack frame of an upper layer caller (first calling function) of the target function according to the calling stack frame of the current target function. In this way, the call stack of the currently running thread is traced back until the upper layer call function (caller) is empty or the maximum tracing depth is reached, wherein the maximum tracing depth refers to the stack bottom of the call stack traced back to the currently running thread. Therefore, a calling function set of all abnormal calls of the currently running thread is obtained, and the calling function in the calling function set is determined as the calling function of the abnormal calls of the currently running thread.
Optionally, when all the calling functions abnormally called by the currently running thread are obtained, a JS function structure (JSfuntion) and a code block (CodeBlock) corresponding to each calling function may be searched. The function name and function body information of the calling function are stored in the JS function structure (JSFusion), so that the code information of the calling function corresponding to the calling function in the calling function set can be taken out from the memory structure corresponding to the JSFusion, and the code information of the abnormal calling function of the running thread with the current abnormality can be obtained, and the specific codes can be specifically known to cause the abnormal execution of the JS thread.
In the embodiment of the invention, a monitoring thread is called to obtain the running parameters of the currently running thread in the target object in the running process of the target object to be monitored; the running parameters of the currently running thread comprise running duration and running resource occupancy rate, the running duration of the currently running thread can be monitored according to a parameter monitoring function in a calling monitoring thread, and if the running parameters of the currently running thread in the target object are abnormal, a call-back function is called to read a calling stack of the currently running thread; the running resource occupancy rate of the currently running thread can also be monitored according to the monitoring thread, if the running parameters of the currently running thread in the target object are abnormal, whether the currently running thread is a target type thread or not is judged, and if the currently running thread is the target type thread, the call stack of the currently running thread is read; analyzing the call stack of the currently running thread, wherein the reason why the currently running thread is abnormal can be specifically analyzed; the call stack can be used for backtracking the call function set called by the currently running thread, and the call function in the call function set is the reason for causing the running parameter of the currently running thread to be abnormal. Therefore, the calling function set called by the currently running thread in the target object can be determined according to the calling stack of the currently running thread; and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread. Therefore, in the application, by performing stack backtracking on the currently running thread and the call stack of the currently running thread, not only the thread with abnormal running parameters can be traced, but also the call function called by the abnormal thread can be obtained; the method and the device are favorable for accurately acquiring the reason of the abnormal call of the currently running thread, namely the reason of the abnormal problem of the target object.
Please refer to fig. 7, which is a schematic structural diagram of a thread monitoring apparatus according to an embodiment of the present disclosure, where the thread monitoring apparatus according to the embodiment of the present disclosure may be implemented in an electronic device. In this embodiment, the thread monitoring apparatus includes:
a first obtaining module 11, configured to invoke a monitoring thread to obtain an operation parameter of a currently running thread in a target object to be monitored in a running process of the target object;
a reading module 12, configured to read a call stack of a currently running thread if an operating parameter of the currently running thread in the target object is abnormal;
the reading module 12 includes:
the monitoring unit is used for calling the parameter monitoring function to monitor the running parameters of the currently running thread, and the parameter monitoring function comprises a first time length threshold;
and the calling unit is used for determining that the running parameter of the currently running thread in the target object is abnormal if the running time of the currently running thread is greater than the first time threshold, and calling a callback function to read the calling stack of the currently running thread.
Wherein the operation parameters comprise operation resource occupancy rates;
the reading module 12 includes:
a first obtaining unit, configured to obtain a duration for which an occupancy rate of a running resource of a currently running thread in the target object is greater than a preset occupancy rate threshold if the occupancy rate of the running resource of the currently running thread in the target object is greater than the preset occupancy rate threshold;
and the reading unit is used for determining that the running parameters of the currently running thread are abnormal if the duration exceeds a second duration threshold value, and reading the call stack of the currently running thread.
Wherein, the reading unit is specifically configured to:
if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and acquiring the corresponding relation between the thread identification and the thread type;
determining the thread type of the currently running thread according to the corresponding relation between the thread identification and the thread type;
and if the thread type of the currently running thread is a target thread type, reading the call stack of the currently running thread, wherein the target thread type is a thread type used for interpreting and compiling code information.
A first determining module 13, configured to determine, according to the call stack of the currently running thread, a call function set called by the currently running thread in the target object;
and a second determining module 14, configured to determine a calling function in the calling function set as a calling function that is abnormally called by the currently running thread.
The operation parameters comprise operation duration, and the monitoring threads comprise parameter monitoring functions;
wherein, the second determining module 14 includes:
a first determining unit, configured to determine, from a call stack of the currently running thread, a target function called by the currently running thread;
a second determining unit, configured 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;
a third determining unit, configured to determine, according to the upper layer call pointer, an upper layer call function that calls the target function, as a first call function;
an obtaining unit, configured to obtain a call stack frame of the first call function;
a fourth determining unit, configured to determine, according to the target function, the first call function, and the call stack frame of the first call function, a call function set called by a currently running thread in the target object.
Wherein, the fourth determining unit is specifically configured to:
if an upper-layer call pointer exists in the call stack frame of the first call function, determining a call function for calling the first call function in the target object according to the upper-layer call pointer in the call stack frame of the first call function, using the call function as a second call function, and adding the target function, the first call function and the second call function to the call function set;
and if the calling stack frame of the first calling function does not have an upper layer calling pointer, adding the target function and the first calling function into the calling function set.
Wherein, above-mentioned device still includes:
the second acquisition module is used for acquiring an address pointer of the parameter monitoring function;
a third obtaining module, configured to obtain a time limit variable in the parameter monitoring function according to the address pointer of the parameter monitoring function;
and the adding module is used for setting the threshold of the time length limiting variable as the first time length threshold, and adding a calling strategy in the parameter monitoring function, wherein the calling strategy is used for calling the callback function to read the calling stack of the currently running thread if the running time length of the currently running thread in running is greater than the first time length threshold.
In the embodiment of the invention, a monitoring thread is called to obtain the running parameters of the currently running thread in the target object in the running process of the target object to be monitored; the running parameters of the currently running thread comprise running duration and running resource occupancy rate, the running duration of the currently running thread can be monitored according to a parameter monitoring function in a calling monitoring thread, and if the running parameters of the currently running thread in the target object are abnormal, a call-back function is called to read a calling stack of the currently running thread; the running resource occupancy rate of the currently running thread can also be monitored according to the monitoring thread, if the running parameters of the currently running thread in the target object are abnormal, whether the currently running thread is a target type thread or not is judged, and if the currently running thread is the target type thread, the call stack of the currently running thread is read; analyzing the call stack of the currently running thread, wherein the reason why the currently running thread is abnormal can be specifically analyzed; the call stack can be used for backtracking the call function set called by the currently running thread, and the call function in the call function set is the reason for causing the running parameter of the currently running thread to be abnormal. Therefore, the calling function set called by the currently running thread in the target object can be determined according to the calling stack of the currently running thread; and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread. Therefore, in the application, by performing stack backtracking on the currently running thread and the call stack of the currently running thread, not only the thread with abnormal running parameters can be traced, but also the call function called by the abnormal thread can be obtained; the method and the device are favorable for accurately acquiring the reason of the abnormal call of the currently running thread, namely the reason of the abnormal problem of the target object.
Please refer to fig. 8, which is a schematic structural diagram of a computer device according to an embodiment of the present application. As shown in fig. 8, the computer apparatus 1000 may include: the processor 1001, the network interface 1004, and the memory 1005, and the computer apparatus 1000 may further include: a user interface 1003, and at least one communication bus 1002. Wherein a communication bus 1002 is used to enable connective communication between these components. The user interface 1003 may include a Display screen (Display) and a Keyboard (Keyboard), and the optional user interface 1003 may also include a standard wired interface and a standard wireless interface. The network interface 1004 may optionally include a standard wired interface, a wireless interface (e.g., WI-FI interface). The memory 1005 may be a high-speed RAM memory or a non-volatile memory (e.g., at least one disk memory). The memory 1005 may optionally be at least one memory device located remotely from the processor 1001. As shown in fig. 8, a memory 1005, which is a kind of computer-readable storage medium, may include therein an operating system, a network communication module, a user interface module, and a device control application program.
In the computer device 1000 shown in fig. 8, the network interface 1004 may provide a network communication function; the user interface 1003 is an interface for providing a user with input; and the processor 1001 may be used to invoke a device control application stored in the memory 1005 to implement:
calling a monitoring thread to acquire the running parameters of the currently running thread in a target object to be monitored in the running process of the target object;
if the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread;
determining a calling function set called by the currently running thread in the target object according to the calling stack of the currently running thread;
and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread.
The operation parameters comprise operation duration, and the monitoring threads comprise parameter monitoring functions;
if the running parameter of the currently running thread in the target object is abnormal, reading the call stack of the currently running thread, including:
calling the parameter monitoring function to monitor the running parameters of the currently running thread, wherein the parameter monitoring function comprises a first time length threshold;
and if the running time of the currently running thread is longer than the first time threshold, determining that the running parameters of the currently running thread in the target object are abnormal, and calling a callback function to read the call stack of the currently running thread.
Wherein, the method further comprises:
acquiring an address pointer of the parameter monitoring function;
acquiring a time limit variable in the parameter monitoring function according to an address pointer of the parameter monitoring function;
setting the threshold of the time limit variable as a first time threshold, and adding a calling strategy in the parameter monitoring function, wherein the calling strategy is used for calling the callback function to read the calling stack of the currently running thread if the running time of the currently running thread is greater than the first time threshold.
Wherein the operation parameters comprise operation resource occupancy rates;
if the running parameter of the currently running thread in the target object is abnormal, reading the call stack of the currently running thread, including:
if the operating resource occupancy rate of the currently operated thread in the target object is greater than the preset occupancy rate threshold, acquiring the duration of the currently operated thread in the target object when the operating resource occupancy rate is greater than the preset occupancy rate threshold;
and if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and reading the call stack of the currently running thread.
Wherein, if the duration exceeds a second duration threshold, determining that the running parameter of the currently running thread is abnormal, and reading the call stack of the currently running thread, includes:
if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and acquiring the corresponding relation between the thread identification and the thread type;
determining the thread type of the currently running thread according to the corresponding relation between the thread identification and the thread type;
if the thread type of the currently running thread is a target thread type, reading a call stack of the currently running thread; the above-mentioned target thread type refers to a thread type for interpreting and compiling code information.
Wherein, the determining, according to the call stack of the currently running thread, a call function set in the target object for calling the currently running thread includes:
determining a target function called by the currently running thread from a call stack of the currently running thread;
acquiring a calling stack frame of the target function, and determining an upper layer calling pointer from the calling stack frame of the target function;
determining an upper layer calling function for calling the target function according to the upper layer calling pointer, and taking the upper layer calling function as a first calling function;
acquiring a calling stack frame of the first calling function;
and determining a calling function set 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.
Determining a calling function set 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, wherein the determining comprises the following steps of;
if an upper-layer call pointer exists in the call stack frame of the first call function, determining a call function for calling the first call function in the target object according to the upper-layer call pointer in the call stack frame of the first call function, using the call function as a second call function, and adding the target function, the first call function and the second call function to the call function set;
and if the calling stack frame of the first calling function does not have an upper layer calling pointer, adding the target function and the first calling function into the calling function set.
In the embodiment of the invention, a monitoring thread is called to obtain the running parameters of the currently running thread in the target object in the running process of the target object to be monitored; the running parameters of the currently running thread comprise running duration and running resource occupancy rate, the running duration of the currently running thread can be monitored according to a parameter monitoring function in a calling monitoring thread, and if the running parameters of the currently running thread in the target object are abnormal, a call-back function is called to read a calling stack of the currently running thread; the running resource occupancy rate of the currently running thread can also be monitored according to the monitoring thread, if the running parameters of the currently running thread in the target object are abnormal, whether the currently running thread is a target type thread or not is judged, and if the currently running thread is the target type thread, the call stack of the currently running thread is read; analyzing the call stack of the currently running thread, wherein the reason why the currently running thread is abnormal can be specifically analyzed; the call stack can be used for backtracking the call function set called by the currently running thread, and the call function in the call function set is the reason for causing the running parameter of the currently running thread to be abnormal. Therefore, the calling function set called by the currently running thread in the target object can be determined according to the calling stack of the currently running thread; and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread. Therefore, in the application, by performing stack backtracking on the currently running thread and the call stack of the currently running thread, not only the thread with abnormal running parameters can be traced, but also the call function called by the abnormal thread can be obtained; the method and the device are favorable for accurately acquiring the reason of the abnormal call of the currently running thread, namely the reason of the abnormal problem of the target object.
Further, here, it is to be noted that: an embodiment of the present invention further provides a computer-readable storage medium, where the computer-readable storage medium stores a computer program executed by the aforementioned thread monitoring apparatus, and the computer program includes program instructions, and when the processor executes the program instructions, the description of the thread monitoring method in the embodiment corresponding to fig. 1 or fig. 5 can be executed, so that details are not repeated here. In addition, the beneficial effects of the same method are not described in detail. For technical details not disclosed in embodiments of the computer-readable storage medium referred to in the present application, reference is made to the description of embodiments of the method of the present application. By way of example, the program instructions may be executed on one computer device, or on multiple computer devices located at one site, or distributed across multiple sites and interconnected by a communication network, which may comprise a blockchain network.
It will be understood by those skilled in the art that all or part of the processes of the methods of the embodiments described above can be implemented by a computer program, which can be stored in a computer-readable storage medium, and when executed, can include the processes of the embodiments of the methods described above. The storage medium may be a magnetic disk, an optical disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), or the like.
The above disclosure is only for the purpose of illustrating the preferred embodiments of the present invention, and it is therefore to be understood that the invention is not limited by the scope of the appended claims.

Claims (10)

1. A method for thread monitoring, comprising:
calling a monitoring thread to acquire the running parameters of the currently running thread in a target object in the running process of the target object to be monitored;
if the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread;
determining a calling function set called by the currently running thread in the target object according to the calling stack of the currently running thread;
and determining the calling function in the calling function set as the calling function abnormally called by the currently running thread.
2. The method of claim 1, wherein the operational parameter comprises a length of time of operation, and wherein the monitoring thread comprises 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, wherein the reading comprises the following steps:
calling the parameter monitoring function to monitor the running parameters of the currently running thread, wherein the parameter monitoring function comprises a first time length threshold;
if the running time of the currently running thread is longer than the first time threshold, determining that the running parameters of the currently running thread in the target object are abnormal, and calling a callback function to read a call stack of the currently running thread.
3. The method of claim 2, further comprising:
acquiring an address pointer of the parameter monitoring function;
acquiring a time limit variable in the parameter monitoring function according to an address pointer of the parameter monitoring function;
setting the threshold of the time limit variable as the first time threshold, and adding a calling strategy in the parameter monitoring function, wherein the calling strategy is used for calling the callback function to read the calling stack of the currently running thread if the running time of the currently running thread is greater than the first time threshold.
4. The method of any of claims 1-3, wherein the operating parameters include operating resource occupancy;
if the running parameters of the currently running thread in the target object are abnormal, reading the call stack of the currently running thread, wherein the reading comprises the following steps:
if the operating resource occupancy rate of the currently operated thread in the target object is greater than a preset occupancy rate threshold, acquiring the duration of the currently operated thread in the target object when the operating resource occupancy rate is greater than the preset occupancy rate threshold;
and if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and reading the call stack of the currently running thread.
5. The method of claim 4, wherein determining that the running parameter of the currently running thread is abnormal and reading the call stack of the currently running thread if the duration exceeds a second duration threshold comprises:
if the duration exceeds a second duration threshold, determining that the running parameters of the currently running thread are abnormal, and acquiring the corresponding relation between the thread identification and the thread type;
determining the thread type of the currently running thread according to the corresponding relation between the thread identification and the thread type;
if the thread type of the currently running thread is the target thread type, reading a call stack of the currently running thread; the target thread type refers to a thread type for interpreting and compiling code information.
6. The method according to any of claims 1-3, wherein said determining a set of calling functions called by the currently running thread in the target object based on the call stack of the currently running thread comprises:
determining a target function called by the currently running thread from a call stack of the currently running thread;
acquiring a calling stack frame of the target function, and determining an upper layer calling pointer from the calling stack frame of the target function;
determining an upper layer calling function for calling the target function according to the upper layer calling pointer, and taking the upper layer calling function as a first calling function;
acquiring a calling stack frame of the first calling function;
and determining a calling function set 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.
7. The method of claim 6, wherein determining a set of calling functions called by a currently running thread in the target object from the target function, the first calling function, and a call stack frame of the first calling function comprises;
if an upper-layer call pointer exists in the call stack frame of the first call function, determining a call function for calling the first call function in the target object according to the upper-layer call pointer in the call stack frame of the first call function, using the call function as a second call function, and adding the target function, the first call function and the second call function to the call function set;
and if the calling stack frame of the first calling function does not have an upper layer calling pointer, adding the target function and the first calling function into the calling function set.
8. A thread monitoring device, comprising:
the acquisition module is used for calling a monitoring thread to acquire the running parameters of the currently running thread in the target object in the running process of the target object to be monitored;
the reading module is used for reading the call stack of the currently running thread if the running parameters of the currently running thread in the target object are abnormal;
a first determining module, configured to determine, according to the call stack of the currently running thread, a call function set called by the currently running thread in the target object;
and the second determining module is used for determining the calling function in the calling function set as the calling function abnormally called by the currently running thread.
9. A computer device, comprising: a processor, a memory, and a network interface;
the processor is connected to a memory for providing data communication functions, a network interface for storing program code, and a processor for calling the program code to perform the method of 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 comprising program instructions which, when executed by a processor, perform the steps of the method according to any one of claims 1 to 7.
CN202011081396.9A 2020-10-10 2020-10-10 Thread monitoring method, device, equipment and storage medium Pending CN114328073A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202011081396.9A CN114328073A (en) 2020-10-10 2020-10-10 Thread monitoring method, device, equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202011081396.9A CN114328073A (en) 2020-10-10 2020-10-10 Thread monitoring method, device, equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114328073A true CN114328073A (en) 2022-04-12

Family

ID=81032295

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202011081396.9A Pending CN114328073A (en) 2020-10-10 2020-10-10 Thread monitoring method, device, equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114328073A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116431376A (en) * 2023-06-09 2023-07-14 苏州浪潮智能科技有限公司 Core dumping method, system, equipment and computer readable storage medium
CN117827596A (en) * 2024-03-05 2024-04-05 大连高德瑞信科技有限公司 Safe and controllable thread real-time monitoring method and system

Cited By (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116431376A (en) * 2023-06-09 2023-07-14 苏州浪潮智能科技有限公司 Core dumping method, system, equipment and computer readable storage medium
CN116431376B (en) * 2023-06-09 2023-09-05 苏州浪潮智能科技有限公司 Core dumping method, system, equipment and computer readable storage medium
CN117827596A (en) * 2024-03-05 2024-04-05 大连高德瑞信科技有限公司 Safe and controllable thread real-time monitoring method and system
CN117827596B (en) * 2024-03-05 2024-04-26 大连高德瑞信科技有限公司 Safe and controllable thread real-time monitoring method and system

Similar Documents

Publication Publication Date Title
US10146531B2 (en) Method and apparatus for generating a refactored code
US20070136402A1 (en) Automatic prediction of future out of memory exceptions in a garbage collected virtual machine
US10417011B2 (en) Thread-agile execution of dynamic programming language programs
CN104346148A (en) Method, device and system for acquiring program performance consumption information
CN114328073A (en) Thread monitoring method, device, equipment and storage medium
CN111813635A (en) Monitoring method, system and device for intelligent contracts of block chains
CN114297700B (en) Dynamic and static combined mobile application privacy protocol extraction method and related equipment
CN114490116B (en) Data processing method and device, electronic equipment and storage medium
CN114546590A (en) Java virtual machine heap memory set object monitoring method and memory overflow analysis method
US20160117157A1 (en) Eager and optimistic evaluation of promises
CN113296752A (en) Method, system, device and storage medium for generating API document
CN107885489A (en) A kind of method and system of quick detection real name registration data index
CN107729208A (en) A kind of power transmission and transforming equipment monitoring device deep monitored system
CN116737677A (en) Resource processing method, device, computer equipment and readable storage medium
CN110764745B (en) Variable transmission and collection method, device and computer readable storage medium
CN113656044B (en) Android installation package compression method and device, computer equipment and storage medium
CN115269431A (en) Interface testing method and device, electronic equipment and storage medium
CN112860235A (en) Method, device, equipment and storage medium for processing text
CN113687880A (en) Method, device, equipment and medium for calling component
US11720468B1 (en) Unwinding program call stacks for performance profiling
CN112463626A (en) Memory leak positioning method and device, computer equipment and storage medium
CN116340102B (en) Memory overflow monitoring method, device, equipment and storage medium
CN112131000B (en) Memory release method and device for plug-in application program
US20230012881A1 (en) Method and apparatus for reading data, electronic device and storage medium
Das Investigating performance issues in mobile apps

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination