CN109947636B - Abnormal thread positioning method and device - Google Patents

Abnormal thread positioning method and device Download PDF

Info

Publication number
CN109947636B
CN109947636B CN201711385324.1A CN201711385324A CN109947636B CN 109947636 B CN109947636 B CN 109947636B CN 201711385324 A CN201711385324 A CN 201711385324A CN 109947636 B CN109947636 B CN 109947636B
Authority
CN
China
Prior art keywords
thread
state
abnormal
heartbeat
running state
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.)
Active
Application number
CN201711385324.1A
Other languages
Chinese (zh)
Other versions
CN109947636A (en
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.)
Zhejiang Uniview Technologies Co Ltd
Original Assignee
Zhejiang Uniview Technologies 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 Zhejiang Uniview Technologies Co Ltd filed Critical Zhejiang Uniview Technologies Co Ltd
Priority to CN201711385324.1A priority Critical patent/CN109947636B/en
Publication of CN109947636A publication Critical patent/CN109947636A/en
Application granted granted Critical
Publication of CN109947636B publication Critical patent/CN109947636B/en
Active legal-status Critical Current
Anticipated expiration legal-status Critical

Links

Images

Abstract

The embodiment of the invention provides an abnormal thread positioning method and device, which are applied to embedded equipment. The method comprises the following steps: acquiring running state parameters of corresponding threads in a polling mode according to thread identifications of the threads in the embedded equipment, wherein the running state parameters comprise at least one of thread states and heartbeat parameters of the corresponding threads; judging whether the state of the corresponding thread is abnormal or not according to the obtained running state parameters of each thread; and when the state of the thread is judged to be abnormal, positioning the thread in the abnormal state and storing the stack frame information of the positioned thread into a log file. The abnormal thread positioning method is high in positioning efficiency, can automatically and accurately position the abnormal thread in the embedded equipment, and reduces the workload of software developers.

Description

Abnormal thread positioning method and device
Technical Field
The invention relates to the technical field of embedded equipment, in particular to an abnormal thread positioning method and device.
Background
With the continuous development of the internet of things technology and the network technology, the application of embedded devices is becoming more and more popular. For the embedded device, once the thread of the device runs abnormally, the device cannot run normally.
At present, when an embedded device has thread abnormality, a software developer needs to perform field debugging on the embedded device through an external debugging tool to obtain stack frame information of each thread in the device, and perform manual analysis on each stack frame information to realize positioning of an abnormal thread. The abnormal thread positioning scheme has the advantages of low positioning efficiency, large workload of software developers and low thread positioning accuracy.
Disclosure of Invention
In order to overcome the above disadvantages in the prior art, an object of the present invention is to provide a method and an apparatus for locating an abnormal thread, where the method has high locating efficiency, and can automatically and accurately locate the abnormal thread in an embedded device, thereby reducing the workload of software developers.
As to the method, a preferred embodiment of the present invention provides an exception thread positioning method applied to an embedded device, where the method includes:
acquiring running state parameters of corresponding threads in a polling mode according to thread identifications of the threads in the embedded equipment, wherein the running state parameters comprise at least one of thread states and heartbeat parameters of the corresponding threads;
judging whether the state of the corresponding thread is abnormal or not according to the obtained running state parameters of each thread;
and when the state of the thread is judged to be abnormal, positioning the thread in the abnormal state, and storing the stack frame information of the positioned thread into a log file.
In terms of apparatus, a preferred embodiment of the present invention provides an exception thread positioning apparatus, which is applied to an embedded device, the apparatus including:
the parameter acquisition module is used for acquiring running state parameters of corresponding threads in a polling mode according to thread identifications of the threads in the embedded equipment, wherein the running state parameters comprise at least one of thread states and heartbeat parameters of the corresponding threads;
the abnormity judgment module is used for judging whether the state of the corresponding thread is abnormal according to the obtained running state parameters of each thread;
and the thread positioning module is used for positioning the thread in the abnormal state when the state of the thread is judged to be abnormal, and storing the positioned stack frame information of the thread into a log file.
Compared with the prior art, the method and the device for positioning the abnormal thread provided by the preferred embodiment of the invention have the following beneficial effects: the abnormal thread positioning method is high in positioning efficiency, can automatically and accurately position the abnormal thread in the embedded equipment, and reduces the workload of software developers. Firstly, the method obtains the running state parameters of each thread in a polling mode according to the thread identification of each thread in the embedded equipment; then, the method judges whether the state of the corresponding thread is abnormal according to the obtained running state parameters of each thread; finally, when the thread state is judged to be abnormal, the method positions the thread in the abnormal state and stores the stack frame information of the positioned thread into the log file, so that the abnormal thread can be accurately positioned in a very short time, a software developer can obtain the stack frame information of the corresponding abnormal thread in the embedded device in a mode of directly looking up the log file when needing to obtain the stack frame information of the abnormal thread in the embedded device, the field abnormal environment of the embedded device does not need to be reserved, and the workload of the software developer is reduced.
In order to make the aforementioned and other objects, features and advantages of the present invention comprehensible, preferred embodiments accompanied with figures are described in detail below.
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 embodiments are briefly described below, it should be understood that the following drawings only illustrate some embodiments of the present invention, and therefore should not be considered as limiting the scope of the claims of the present invention, and it is obvious for those skilled in the art that other related drawings can be obtained according to the drawings without inventive efforts.
Fig. 1 is a block diagram of an embedded device according to a preferred embodiment of the present invention.
Fig. 2 is a block diagram illustrating an exception thread positioning method according to a preferred embodiment of the present invention.
Fig. 3 is a first flowchart illustrating the sub-steps included in step S220 shown in fig. 2.
Fig. 4 is a second flowchart illustrating the sub-steps included in step S220 shown in fig. 2.
Fig. 5 is a third flowchart illustrating the sub-steps included in step S220 shown in fig. 2.
Fig. 6 is a flowchart illustrating the sub-steps included in step S230 shown in fig. 2.
FIG. 7 is a block diagram of the exception thread locating apparatus shown in FIG. 1 according to the preferred embodiment of the present invention.
Icon: 10-an embedded device; 11-a memory; 12-a processor; 13-a communication unit; 100-an exception thread locating device; 110-a parameter acquisition module; 120-an anomaly determination module; 130-thread location module.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. The components of embodiments of the present invention generally described and illustrated in the figures herein may be arranged and designed in a wide variety of different configurations.
Thus, the following detailed description of the embodiments of the present invention, as presented in the figures, is not intended to limit the scope of the invention, as claimed, but is merely representative of selected embodiments of the invention. 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 invention.
It should be noted that: like reference numbers and letters refer to like items in the following figures, and thus, once an item is defined in one figure, it need not be further defined and explained in subsequent figures.
In the description of the present invention, it should be noted that the terms "first", "second", "third", etc. are used only for distinguishing the description, and are not intended to indicate or imply relative importance.
How to provide an abnormal thread positioning method and device with high positioning efficiency, which can automatically and precisely position an abnormal thread in an embedded device to reduce the workload of a software developer, is a technical problem which needs to be solved urgently for those skilled in the art.
Some embodiments of the invention are described in detail below with reference to the accompanying drawings. The embodiments described below and the features of the embodiments can be combined with each other without conflict.
Fig. 1 is a block diagram of an embedded device 10 according to a preferred embodiment of the present invention. In the embodiment of the present invention, at least one thread runs on the embedded device 10, and the embedded device 10 can automatically and precisely locate an abnormal thread that may exist in the at least one thread, so as to reduce the workload of a software developer of the embedded device 10. The embedded Device 10 may be, but is not limited to, a Linux system-based monitoring Device, a tablet computer, a Personal Digital Assistant (PDA), a Mobile Internet Device (MID), and the like. Optionally, the embedded device 10 is a monitoring device.
In the embodiment, the embedded device 10 includes an exception thread locating apparatus 100, a memory 11, a processor 12 and a communication unit 13. The memory 11, the processor 12 and the communication unit 13 are electrically connected to each other directly or indirectly to realize data transmission or interaction. For example, the components may be electrically connected to each other via one or more communication buses or signal lines.
The Memory 11 may be, but not limited to, a Flash Memory (Flash Memory), an Erasable Programmable Read-Only Memory (EPROM), an electrically Erasable Programmable Read-Only Memory (EEPROM), and the like.
The processor 12 may be an integrated circuit chip having signal processing capabilities. The Processor 12 may be a general-purpose Processor including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also digital signal processors, application specific integrated circuits, off-the-shelf programmable gate arrays or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components. The processor 12 may implement or perform the methods, steps, and logic blocks disclosed in the embodiments of the present invention. A general purpose processor may be a microprocessor or the processor may be any conventional processor or the like. Wherein the at least one thread running on the embedded device 10 is executed by the processor 12.
The communication unit 13 is configured to establish a communication connection between the embedded device 10 and another external device through a network, and to transmit and receive data through the network.
The exception thread locating means 100 comprises at least one software functional module which can be stored in the memory 11 in the form of software or firmware. The processor 12 may be used to execute an executable module stored in the memory 11 corresponding to the exception thread locating device 100, such as a software functional module and a computer program included in the exception thread locating device 100. In this embodiment, the abnormal thread positioning apparatus 100 has high efficiency in positioning the abnormal thread, and can automatically and accurately position the abnormal thread that may exist in at least one thread running on the embedded device 10, thereby reducing the workload of the software developer of the embedded device 10 and improving the work efficiency of the software developer.
It is understood that the block diagram shown in fig. 1 is only a schematic structural component of the embedded device 10, and the embedded device 10 may include more or less components than those shown in fig. 1, or have a different configuration than that shown in fig. 1. The components shown in fig. 1 may be implemented in hardware, software, or a combination thereof.
Fig. 2 is a block diagram illustrating a method for locating an exception thread according to a preferred embodiment of the present invention. In the embodiment of the present invention, the abnormal thread positioning method is applied to the embedded device 10, and is used to automatically and accurately position an abnormal thread that may exist in at least one thread running on the embedded device 10, so as to reduce the workload of a software developer and improve the software development efficiency of the software developer. The detailed flow and steps of the exception thread locating method shown in fig. 2 are described in detail below.
In the embodiment of the present invention, the method for locating an abnormal thread includes the following steps:
step S210, obtaining the running state parameters of the corresponding threads in a polling manner according to the thread identifiers of the threads in the embedded device 10.
In this embodiment, the running state parameters are used to represent running conditions of corresponding threads, and the embedded device 10 may obtain the running state parameters of each thread by monitoring the running state parameters of each thread running on the embedded device 10, so as to accurately locate an abnormal thread that may exist in each thread based on the running state parameters of each thread. The embedded device 10 monitors the operating state parameters of the threads by polling the operating state parameters of the threads according to the thread identifiers of the threads.
Wherein the running state comprises at least one of a thread state and a heartbeat parameter of a corresponding thread.
In this embodiment, each thread corresponds to a separate thread identifier when running on the embedded device 10, and the thread identifiers are used to distinguish the corresponding thread from other threads. The embedded device 10 may find the corresponding thread according to the thread identifier of each thread, and obtain the running state parameter of each thread in a polling manner. The thread state is used for representing the current execution state of the corresponding thread, the thread state comprises an operation state, a sleep state and an abnormal state, the operation state represents that the corresponding thread is in a normal execution calling state, the sleep state represents that the corresponding thread is in a blocked execution calling state, and the abnormal state represents that the corresponding thread is in an abnormal state; the heartbeat parameter is used for representing the execution condition of the corresponding thread, the heartbeat parameter comprises a current thread heartbeat value of the corresponding thread and a thread heartbeat value of the corresponding thread in the last polling, the thread heartbeat value represents the execution times of the corresponding thread, if a certain thread is normally executed at least once in a time period between the last polling and the current polling, the thread heartbeat value of the thread in the current polling is different from the thread heartbeat value in the last polling, and the thread heartbeat value in the current polling is larger than the thread heartbeat value in the last polling. In an implementation manner of this embodiment, when a thread is normally executed once, a thread heartbeat value corresponding to the thread is automatically incremented by one.
In this embodiment, the running state parameters of each thread obtained by the embedded device 10 may only include the thread state of each thread, may only include the heartbeat parameter of each thread, and may also include the thread state and the heartbeat parameter of each thread. In an implementation manner of the embodiment of the present invention, the embedded device 10 may create a monitoring thread with a single function only for monitoring the operating state parameters of each thread in advance, and implement the step flow corresponding to the step S210 by using the monitoring thread, where the monitoring thread may obtain the thread identifier of each thread by calling a gettid function.
Step S220, determining whether the state of the corresponding thread is abnormal according to the obtained running state parameters of each thread.
In this embodiment, the processing manner in which the embedded device 10 determines whether the state of each thread is abnormal is related to the substantial content of the operating state parameter obtained by the embedded device 10, and different substantial contents correspond to different processing manners, for example, if the processing manner corresponding to the operating state parameter obtained by the embedded device 10 only includes the heartbeat parameter of each thread is a first scheme, and the processing manner corresponding to the operating state parameter obtained by the embedded device 10 only includes the thread state of each thread is a second scheme, the first scheme is different from the second scheme.
Optionally, please refer to fig. 3, which is a first flowchart illustrating the sub-steps included in step S220 shown in fig. 2. In the first implementation manner of this embodiment, when the obtained running state parameter only includes the heartbeat parameter of the corresponding thread, the step S220 may include the sub-steps S221 and S222:
in sub-step S221, the current thread heartbeat value of each thread is compared with the thread heartbeat value of the corresponding thread in the previous polling.
In this embodiment, the embedded device 10 determines whether the thread has been normally executed in the time period between two corresponding polls by comparing the current thread heartbeat value of the corresponding thread in the current poll with the thread heartbeat value of the thread in the last poll.
In step S222, if the current thread heartbeat value of the thread is the same as the thread heartbeat value in the last polling, it is determined that the state of the thread is abnormal.
In this embodiment, if the current thread heartbeat value of the thread during the current polling is the same as the thread heartbeat value of the thread during the last polling, the thread is not executed in the time period between two corresponding polling times, and the embedded device 10 may determine that the state of the thread is abnormal and belongs to an abnormal thread.
Optionally, please refer to fig. 4, which is a second flowchart illustrating the sub-steps included in step S220 shown in fig. 2. In a second implementation manner of this embodiment, when the obtained running state parameter only includes the thread state of the corresponding thread, the step S220 may include a sub-step S223 and a sub-step S224:
in step S223, the thread state of each thread is identified.
In this embodiment, the embedded device 10 determines that the thread state of the thread is a running state, a sleeping state, or an abnormal state by reading and identifying the thread state of the corresponding thread.
In step S224, if the thread state of the corresponding thread is abnormal, it is determined that the thread state is abnormal.
In this embodiment, if the thread state of the thread during the current polling is an abnormal state, indicating that the thread is abnormal, the embedded device 10 may determine that the thread state is abnormal and belongs to an abnormal thread.
Optionally, please refer to fig. 5, which is a third flowchart illustrating the sub-steps included in step S220 shown in fig. 2. In a third implementation manner of this embodiment, when the obtained running state parameter includes a heartbeat parameter of a corresponding thread in addition to a thread state of the corresponding thread, unlike the implementation manner corresponding to fig. 4, the step S220 may further include a substep S225 in addition to the substeps S223 and the substep S224 described above:
and a substep S225, comparing the current thread heartbeat value of the thread with the thread heartbeat value in the last polling if the thread status of the corresponding thread is running, determining that the thread status is abnormal if the current thread heartbeat value of the thread is the same as the thread heartbeat value in the last polling, and correspondingly modifying the thread status of the thread to be abnormal.
In this embodiment, if the running state parameters obtained by the embedded device 10 include the thread state and the heartbeat parameter of the corresponding thread, the embedded device 10 first identifies the thread state of each thread, and when it is identified that the thread state of the corresponding thread is the running state, compares the current thread heartbeat value of the thread in the current polling with the thread heartbeat value in the last polling, so as to determine whether the thread is abnormal according to the comparison result. When the current thread heartbeat value of the thread during the current polling is the same as the thread heartbeat value during the last polling, indicating that the thread is not executed in the time period between the two corresponding polling under the condition of being in the running state, the embedded device 10 may determine that the state of the thread is abnormal and belongs to an abnormal thread, and correspondingly adjust and modify the thread state of the thread to be in an abnormal state.
In an implementation manner of the embodiment of the present invention, the monitoring thread created by the embedded device 10 may also execute any one of the three implementation manners corresponding to fig. 3 to fig. 5, so as to determine whether each thread running in the embedded device 10 is abnormal.
Referring to fig. 2 again, in step S230, when the state of the thread is determined to be abnormal, the thread in the abnormal state is located, and the stack frame information of the located thread is saved in the log file.
In this embodiment, after determining whether the states of the threads are abnormal to determine abnormal threads that may exist in the threads running on the embedded device 10, the embedded device 10 performs positioning processing on the abnormal threads according to the thread identifier corresponding to the thread whose state is determined to be abnormal, so as to reduce the workload of software developers.
Optionally, please refer to fig. 6, which is a flowchart illustrating the sub-steps included in step S230 shown in fig. 2. In this embodiment, the step of locating the thread in the abnormal state in step S230 and saving the stack frame information of the located thread in the log file includes substeps S231 and substep S232:
and a substep S231, sending a positioning signal to the corresponding thread according to the thread identifier of the thread in the abnormal state to acquire stack frame information of the thread.
In this embodiment, the embedded device 10 may pre-configure a processing action function associated with a positioning signal based on the sigaction function, and the processing action function corresponds to acquiring stack frame information corresponding to a thread capturing the positioning signal, where the positioning signal may be pre-set by a software developer in a self-defined manner, and the stack frame information includes at least one of a return address, a local variable, and a stack frame address of the corresponding thread. When the embedded device 10 determines that the state of a thread is abnormal, the thread identifier of the thread determined to be abnormal according to the state sends a positioning signal to the thread, and when the thread captures the positioning signal, the processing action function is triggered to obtain stack frame information of the abnormal thread through the processing action function. In an implementation manner of this embodiment, the processing action function obtains stack frame information of a corresponding thread by calling a back function and a back _ symbols function.
And a substep S232, recording the acquired stack frame information of the thread in the abnormal state into a log file for saving.
In this embodiment, after acquiring the stack frame information of the abnormal thread, the embedded device 10 stores the stack frame information of the abnormal thread by recording the stack frame information of the thread in a log file. Different from the scheme in the prior art in which a software developer needs to perform external debugging by using an external debugging tool to obtain stack frame information of an abnormal thread in a field abnormal environment where the embedded device 10 is reserved, the software developer can obtain the stack frame information of the abnormal thread corresponding to the software developer in a manner of directly referring to the log file when the software developer needs to obtain the stack frame information of the abnormal thread in the embedded device 10, and the field abnormal environment of the embedded device 10 does not need to be reserved, thereby ensuring that a possible self-recovery mechanism of the embedded device 10 can normally operate.
Fig. 7 is a block diagram of the exception thread locating device 100 shown in fig. 1 according to a preferred embodiment of the present invention. In the embodiment of the present invention, the abnormal thread positioning apparatus 100 includes a parameter obtaining module 110, an abnormal determining module 120, and a thread positioning module 130.
The parameter obtaining module 110 is configured to obtain the running state parameters of the corresponding threads in a polling manner according to the thread identifiers of the threads in the embedded device 10.
In this embodiment, the running state includes at least one of a thread state and a heartbeat parameter of a corresponding thread. The thread state is used for representing the current execution state of the corresponding thread, the thread state comprises an operation state, a sleep state and an abnormal state, the operation state represents that the corresponding thread is in a normal execution calling state, the sleep state represents that the corresponding thread is in a blocked execution calling state, and the abnormal state represents that the corresponding thread is in an abnormal state; the heartbeat parameters are used for representing the execution condition of the corresponding thread, and comprise the current thread heartbeat value of the corresponding thread and the thread heartbeat value of the corresponding thread in the last polling. The running state parameter obtained by the parameter obtaining module 110 may only include the thread state of each thread, may only include the heartbeat parameter of each thread, and may also include the thread state and the heartbeat parameter of each thread. The parameter obtaining module 110 may execute step S210 shown in fig. 2, and the specific execution process may refer to the above detailed description of step S210, which is not repeated herein.
The abnormal determining module 120 is configured to determine whether the state of the corresponding thread is abnormal according to the obtained running state parameter of each thread.
In a first implementation manner of this embodiment, if the operation state parameters obtained by the parameter obtaining module 110 only include heartbeat parameters of corresponding threads, the method for determining whether the state of the corresponding thread is abnormal by the abnormality determining module 120 according to the obtained operation state parameters of each thread includes:
comparing the current thread heartbeat value of each thread with the thread heartbeat value of the corresponding thread in the last polling;
and if the current thread heartbeat value of the thread is the same as the heartbeat value of the thread in the last polling, judging that the state of the thread is abnormal.
In a second implementation manner of this embodiment, if the operation state parameters obtained by the parameter obtaining module 110 only include the thread states of the corresponding threads, the method for determining whether the states of the corresponding threads are abnormal by the abnormality determining module 120 according to the obtained operation state parameters of the threads includes:
identifying the thread state of each thread;
and if the thread state of the corresponding thread is the abnormal state, judging that the thread state is abnormal.
In a third implementation manner of this embodiment, if the operation state parameter obtained by the parameter obtaining module 110 includes not only the thread state of the corresponding thread but also the heartbeat parameter of the corresponding thread, the abnormality determining module 120 determines, according to the obtained operation state parameter of each thread, whether the state of the corresponding thread is abnormal, which includes, in addition to the contents corresponding to the second implementation manner, further includes:
if the thread state of the corresponding thread is the running state, comparing the current thread heartbeat value of the thread with the thread heartbeat value in the last polling, judging that the thread state is abnormal when the current thread heartbeat value of the thread is the running state, and correspondingly modifying the thread state of the thread into the abnormal state.
In this embodiment, the abnormality determining module 120 may execute step S220 shown in fig. 2 and any one of the embodiments in fig. 3, fig. 4, and fig. 5 corresponding to the step S220, and the specific execution process may refer to the above detailed description of step S220, sub-step S221, sub-step S222, sub-step S223, sub-step S224, and sub-step S225, which is not repeated herein.
The thread positioning module 130 is configured to, when the state of the thread is determined to be abnormal, position the thread in the abnormal state, and store the stack frame information of the positioned thread in the log file.
In this embodiment, the manner for the thread positioning module 130 to position the thread in the abnormal state and store the stack frame information of the positioned thread in the log file includes:
sending a positioning signal to a corresponding thread according to the thread identifier of the thread in the abnormal state to acquire stack frame information of the thread, wherein the stack frame information comprises at least one of a return address, a local variable and a stack frame address of the corresponding thread;
and recording the acquired stack frame information of the thread in the abnormal state into a log file for storage.
The thread positioning module 130 may execute step S230 shown in fig. 2, and substeps S231 and substep S232 shown in fig. 6, and the specific execution process may refer to the detailed description of step S230, substep S231 and substep S232, which is not repeated herein.
In summary, in the method and the apparatus for locating an abnormal thread provided in the preferred embodiment of the present invention, the locating efficiency of the abnormal thread locating method is high, and the abnormal thread in the embedded device can be accurately located by itself, so as to reduce the workload of the software developer. Firstly, the method obtains the running state parameters of each thread in a polling mode according to the thread identification of each thread in the embedded equipment; then, the method judges whether the state of the corresponding thread is abnormal according to the obtained running state parameters of each thread; finally, when the thread state is judged to be abnormal, the method positions the thread in the abnormal state, and stores the stack frame information of the positioned thread into a log file, so that the abnormal thread can be accurately positioned in a very short time, a software developer can obtain the stack frame information of the corresponding abnormal thread in the embedded device in a mode of directly looking up the log file when needing to obtain the stack frame information of the abnormal thread in the embedded device, the field abnormal environment of the embedded device does not need to be reserved, and the workload of the software developer is reduced.
The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention, and various modifications and changes may be made by those skilled in the art. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention should be included in the protection scope of the present invention.

Claims (8)

1. An abnormal thread positioning method is applied to an embedded device, and comprises the following steps:
acquiring running state parameters of corresponding threads in a polling mode according to thread identifications of the threads in the embedded equipment, wherein the running state parameters comprise at least one of thread states and heartbeat parameters of the corresponding threads;
judging whether the state of the corresponding thread is abnormal or not according to the obtained running state parameters of each thread;
when the state of the thread is judged to be abnormal, a positioning signal is sent to the corresponding thread according to the thread identification of the thread in the abnormal state, a processing action function is called to obtain stack frame information of the thread, the obtained stack frame information of the thread in the abnormal state is recorded in a log file for storage, wherein the processing action function is used for obtaining the stack frame information corresponding to the thread capturing the positioning signal, and the stack frame information comprises at least one of a return address, a local variable and a stack frame address of the corresponding thread.
2. The method according to claim 1, wherein when the running state parameter includes a heartbeat parameter of the corresponding thread, and the heartbeat parameter includes a current thread heartbeat value of the corresponding thread and a thread heartbeat value of the corresponding thread when the corresponding thread is polled last time, the step of determining whether the state of the corresponding thread is abnormal according to the obtained running state parameter of each thread includes:
comparing the current thread heartbeat value of each thread with the thread heartbeat value of the corresponding thread in the last polling;
and if the current thread heartbeat value of the thread is the same as the heartbeat value of the thread in the last polling, judging that the state of the thread is abnormal.
3. The method according to claim 1, wherein when the running state parameter includes a thread state of the corresponding thread, and the thread state includes a running state, a sleeping state, and an abnormal state, the step of determining whether the state of the corresponding thread is abnormal according to the obtained running state parameter of each thread includes:
identifying the thread state of each thread;
and if the thread state of the corresponding thread is the abnormal state, judging that the thread state is abnormal.
4. The method according to claim 3, wherein when the running state parameters further include heartbeat parameters of corresponding threads, and the heartbeat parameters include current thread heartbeat values of corresponding threads and thread heartbeat values of corresponding threads in the last polling, the step of determining whether the state of corresponding threads is abnormal according to the obtained running state parameters of each thread further includes:
if the thread state of the corresponding thread is the running state, comparing the current thread heartbeat value of the thread with the thread heartbeat value in the last polling, judging that the thread state is abnormal when the current thread heartbeat value of the thread is the same as the thread heartbeat value in the last polling, and correspondingly modifying the thread state of the thread to be the abnormal state.
5. An abnormal thread positioning device, which is applied to an embedded device, the device comprising:
the parameter acquisition module is used for acquiring running state parameters of corresponding threads in a polling mode according to thread identifications of the threads in the embedded equipment, wherein the running state parameters comprise at least one of thread states and heartbeat parameters of the corresponding threads;
the abnormity judgment module is used for judging whether the state of the corresponding thread is abnormal according to the obtained running state parameters of each thread;
and the thread positioning module is used for sending a positioning signal to a corresponding thread according to the thread identifier of the thread in the abnormal state when the state of the thread is judged to be abnormal, calling a processing action function to acquire stack frame information of the thread, and then recording the acquired stack frame information of the thread in the abnormal state into a log file for storage, wherein the processing action function is used for acquiring the stack frame information corresponding to the thread capturing the positioning signal, and the stack frame information comprises at least one of a return address, a local variable and a stack frame address of the corresponding thread.
6. The apparatus according to claim 5, wherein when the running state parameter includes a heartbeat parameter of the corresponding thread, and the heartbeat parameter includes a current thread heartbeat value of the corresponding thread and a thread heartbeat value of the corresponding thread when polling last time, the manner in which the abnormality determining module determines whether the state of the corresponding thread is abnormal according to the obtained running state parameter of each thread includes:
comparing the current thread heartbeat value of each thread with the thread heartbeat value of the corresponding thread in the last polling;
and if the current thread heartbeat value of the thread is the same as the thread heartbeat value in the last polling, judging that the state of the thread is abnormal.
7. The apparatus of claim 5, wherein when the running state parameters include thread states of corresponding threads, and the thread states include a running state, a sleep state, and an exception state, the manner for the exception determining module to determine whether the state of the corresponding thread is abnormal according to the obtained running state parameters of each thread includes:
identifying the thread state of each thread;
and if the thread state of the corresponding thread is the abnormal state, judging that the thread state is abnormal.
8. The apparatus according to claim 7, wherein when the running state parameters further include heartbeat parameters of corresponding threads, and the heartbeat parameters include a current thread heartbeat value of a corresponding thread and a thread heartbeat value of a corresponding thread when polling last time, the manner for the anomaly determination module to determine whether the state of the corresponding thread is anomalous according to the obtained running state parameters of each thread further includes:
if the thread state of the corresponding thread is the running state, comparing the current thread heartbeat value of the thread with the thread heartbeat value in the last polling, judging that the thread state is abnormal when the current thread heartbeat value of the thread is the running state, and correspondingly modifying the thread state of the thread into the abnormal state.
CN201711385324.1A 2017-12-20 2017-12-20 Abnormal thread positioning method and device Active CN109947636B (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201711385324.1A CN109947636B (en) 2017-12-20 2017-12-20 Abnormal thread positioning method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201711385324.1A CN109947636B (en) 2017-12-20 2017-12-20 Abnormal thread positioning method and device

Publications (2)

Publication Number Publication Date
CN109947636A CN109947636A (en) 2019-06-28
CN109947636B true CN109947636B (en) 2022-11-04

Family

ID=67004250

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201711385324.1A Active CN109947636B (en) 2017-12-20 2017-12-20 Abnormal thread positioning method and device

Country Status (1)

Country Link
CN (1) CN109947636B (en)

Families Citing this family (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN110572474B (en) * 2019-09-26 2021-09-21 四川长虹电器股份有限公司 Method for embedded terminal long-connection communication
CN112905372A (en) * 2021-02-02 2021-06-04 浙江大华技术股份有限公司 Thread abnormity diagnosis method and device

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101141327A (en) * 2007-10-11 2008-03-12 中兴通讯股份有限公司 Method for detecting network node abnormality
CN103092746A (en) * 2013-02-05 2013-05-08 上海大唐移动通信设备有限公司 Positioning method and system for thread anomaly
CN103246589A (en) * 2012-02-03 2013-08-14 京信通信系统(中国)有限公司 Multithread monitoring method and device
CN107451046A (en) * 2016-05-30 2017-12-08 腾讯科技(深圳)有限公司 A kind of method and terminal for detecting thread

Family Cites Families (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
US6862635B1 (en) * 1998-11-13 2005-03-01 Cray Inc. Synchronization techniques in a multithreaded environment
CN104268055B (en) * 2014-09-01 2017-07-14 腾讯科技(深圳)有限公司 The monitoring method and device of a kind of program exception
CN105824749B (en) * 2016-03-09 2019-06-25 上海博达数据通信有限公司 The analysis method of User space process exception under a kind of Linux system

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN101141327A (en) * 2007-10-11 2008-03-12 中兴通讯股份有限公司 Method for detecting network node abnormality
CN103246589A (en) * 2012-02-03 2013-08-14 京信通信系统(中国)有限公司 Multithread monitoring method and device
CN103092746A (en) * 2013-02-05 2013-05-08 上海大唐移动通信设备有限公司 Positioning method and system for thread anomaly
CN107451046A (en) * 2016-05-30 2017-12-08 腾讯科技(深圳)有限公司 A kind of method and terminal for detecting thread

Also Published As

Publication number Publication date
CN109947636A (en) 2019-06-28

Similar Documents

Publication Publication Date Title
WO2019095580A1 (en) Test method and apparatus, computer device, and readable storage medium
CN109542744A (en) Detect method, apparatus, storage medium and the terminal of terminal booting abnormal problem
CN109947636B (en) Abnormal thread positioning method and device
CN110308880B (en) Log printing method, system, computer device and computer readable storage medium
CN110609778A (en) Method and system for storing server downtime log
CN111694677A (en) Message queue management method, device, terminal and computer-readable storage medium
CN111966380A (en) BMC (baseboard management controller) firmware upgrading method, system, terminal and storage medium
CN112286825A (en) Screen testing method and device for intelligent cabin and electronic equipment
CN112486745A (en) SSD (solid State disk) safety power failure test method and device, computer equipment and storage medium
CN113672306B (en) Server component self-checking abnormity recovery method, device, system and medium
CN110928889A (en) Training model updating method, device and computer storage medium
CN115630011A (en) Method and device for realizing I2C bus communication of master and slave equipment by using CPLD
CN107273291B (en) Processor debugging method and system
CN108958823B (en) Method for modifying set value of basic input and output system
CN115269252A (en) Application program fault processing method, device, equipment and storage medium
CN113032232B (en) Correlation method, correlation device and equipment for performance detection of equipment
CN114374627A (en) Method, device and system for restarting baseboard management controller and server
CN115185734A (en) Firmware abnormity diagnosis method and device based on interruption, computer equipment and storage medium
CN111400113B (en) Complete machine self-checking method, device and system of computer system
CN114116276A (en) BMC hang-up self-recovery method, system, terminal and storage medium
CN113485284B (en) Message data processing method, device, equipment and storage medium
CN110442387B (en) Parameter self-adaption method and device of vehicle-mounted system and vehicle
CN113254281A (en) Detection method and detection device for USB controller
CN114328080A (en) Firmware state detection method and device and electronic equipment
US20200159646A1 (en) Information processing apparatus

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
GR01 Patent grant
GR01 Patent grant