The localization method that thread is abnormal and systemTechnical field
The present invention relates to field of computer technology, relate in particular to the abnormal localization method of a kind of thread and system.
Background technology
Thread is the elementary cell of operating system distribution processor time, and a plurality of threads run time version simultaneously can be arranged in process.Each thread maintenance abnormality handling procedure, dispatching priority and a group system are used for preserving the structure of thread context before this thread of scheduling.The method of existing monitoring thread running status has two kinds:
Heartbeat detection: whether set up a monitoring thread, monitoring each thread has heartbeat, if in a period of time, certain thread does not have heartbeat, thinks that this thread is abnormal;
Status poll: set up a monitoring thread, inquire about at set intervals the running status of each thread, if find that certain thread operation stops, and thinks that this thread is abnormal;
The total major defect of above two kinds of prior aries is:
State that can only monitoring thread is if thread can not be determined the particular location that thread is abnormal extremely;
When carrying out the complicated and time consumption computing, adopt above two kinds of technology may have the situation of erroneous judgement thread running status when thread.
Summary of the invention
The technical matters that (one) will solve
The technical problem to be solved in the present invention is: the abnormal localization method of a kind of thread and system are provided, cause with quick location the code position that thread is abnormal.
(2) technical scheme
For addressing the above problem, on the one hand, the invention provides the abnormal localization method of a kind of thread, comprising:
Monitor the running status of each monitored thread, judge whether monitored thread operation is abnormal;
Generate dump file when judgement obtains monitored thread abnormal, described dump file comprises internal memory, the stack information of in-process each thread;
By debugging described dump file, locate the code position at the abnormal place of monitored thread.
Preferably, also comprise the step that increases monitoring thread before the step of the running status of the monitored thread of described monitoring, monitor the running status of each monitored thread by described monitoring thread.
Preferably, monitor the running status of each monitored thread by described monitoring thread, judge whether abnormal step comprises in monitored thread operation:
Described each monitored thread is registered to described monitoring thread when initialization, and sets initial value and the abnormal number of times limit value of the time-out time of each monitored thread, the initial value of counter, abnormal number of times;
Each monitored thread upgrades the counter of self in normal course of operation;
If monitoring thread is found certain monitored thread and do not upgrade the counter of self in the time-out time of described setting, adds 1 for the abnormal number of times of this monitored thread;
If abnormal number of times corresponding to monitored thread be greater than the abnormal number of times limit value of described setting, judgement this monitored thread abnormal, and the counter that this monitored thread is corresponding and extremely number of times reset to the initial value of correspondence.
Preferably, if abnormal number of times corresponding to described monitored thread is greater than the abnormal number of times limit value of described setting, the step that judges this monitored thread abnormal comprises: if continuous abnormal number of times corresponding to monitored thread greater than the abnormal number of times limit value of described setting, this monitored thread abnormal of judgement.
Preferably, if monitoring thread is found certain monitored thread and do not upgrade the counter of self in previous time-out time, but upgraded the counter of self in current time-out time, the abnormal number of times that described monitored thread is corresponding resets to corresponding initial value.
Preferably, also be included in daily record after the step of this monitored thread abnormal of judgement in the step of identifier of recording exceptional thread.
Preferably, the step of described debugging dump file comprises: find corresponding abnormal thread according to the identifier of described abnormal thread.
Preferably, described dump file is the dmp file.
On the other hand, the present invention also provides a kind of thread abnormal positioning system, comprising:
Monitoring module for the running status of each monitored thread of monitoring, judges whether monitored thread operation is abnormal;
The dump file generation module is used for generating dump file when judgement obtains monitored thread abnormal, and described dump file comprises internal memory, the stack information of in-process each thread;
Abnormal locating module is used for locating the code position at the abnormal place of monitored thread by the described dump file of debugging.
(3) beneficial effect
The present invention can not only the monitoring thread running status, and when the thread operation exception, internal memory and stack information by the current operation of the automatic record thread of dump file, the developer is according to internal memory and the stack information of record, just the code position that causes that thread is abnormal be can locate fast, debugging and the reparation of thread facilitated.
Continuous abnormal number of times corresponding to the monitored thread of the present invention just judges this monitored thread abnormal during greater than the abnormal number of times limit value of described setting, can reduce the probability of some thread erroneous judgement complicated and consuming time.
Method of the present invention increases monitoring thread can be completed, and the scope of application is wider, also applicable to announced software.
Description of drawings
Fig. 1 is the schematic flow sheet of the localization method abnormal according to a kind of thread of the embodiment of the present invention;
Fig. 2 is the schematic flow sheet of the localization method abnormal according to a kind of thread of the embodiment of the present invention;
Fig. 3 is according to the sequential chart between embodiment of the present invention monitoring thread and monitored thread;
Fig. 4 is the structural representation block diagram of the abnormal positioning system of thread a kind of according to the embodiment of the present invention.
Embodiment
That the present invention is described in detail is as follows below in conjunction with drawings and Examples.
Embodiment one:
Figure 1 shows that the schematic flow sheet of the localization method that a kind of thread of the present embodiment record is abnormal, described method comprises:
S110: monitor the running status of each monitored thread, judge whether monitored thread operation is abnormal;
S120: generate dump file when judgement obtains monitored thread abnormal;
S130: by debugging described dump file, locate the code position at the abnormal place of monitored thread.
In the present embodiment, described dump file comprises internal memory, the stack information of in-process each thread.
The method of the present embodiment can not only the monitoring thread running status, and when the thread operation exception, internal memory and stack information by the current operation of the automatic record thread of dump file, the developer is according to internal memory and the stack information of record, just the code position that causes that thread is abnormal be can locate fast, debugging and the reparation of thread facilitated.
Embodiment two:
Figure 2 shows that the schematic flow sheet of the localization method that the another kind of thread of the present embodiment record is abnormal, described method comprises:
S210: increase monitoring thread in application;
S220: described each monitored thread is registered to described monitoring thread when initialization, and sets initial value and the abnormal number of times limit value of the time-out time of each monitored thread, the initial value of counter, abnormal number of times;
S230: each monitored thread upgrades the counter of self in normal course of operation;
S240: do not upgrade the counter of self if monitoring thread is found certain monitored thread in the time-out time of described setting, add 1 for the abnormal number of times of this monitored thread;
S250: if continuous abnormal number of times corresponding to monitored thread is greater than the abnormal number of times limit value of described setting, judge this monitored thread abnormal, generate described dump file, and corresponding counter and the abnormal number of times of this monitored thread reset to corresponding initial value, the identifier of recording exceptional thread in daily record; Wherein, in order to obtain the continuous abnormal number of times of monitored thread, if monitoring thread is found certain monitored thread and do not upgrade the counter of self in previous time-out time, but upgraded the counter of self in current time-out time, the abnormal number of times that described monitored thread is corresponding resets to corresponding initial value; The identifier of described abnormal thread is used for finding according to the identifier of described abnormal thread the abnormal thread of correspondence when the debugging dump file;
S260: by debugging described dump file, locate the code position at the abnormal place of monitored thread.
In the present embodiment, described dump file is the dmp file, when determining monitored thread abnormal, generates described dmp file by calling MiniDump WriteDump function in the present embodiment; After generating the dmp file, by WinDBG instrument debugging dmp file, can locate fast abnormal thread operation code position.
Fig. 3 is the sequential chart between the present embodiment monitoring thread and monitored thread, as shown in Figure 3, comprises a monitoring thread Monitor and three monitored thread ThreadA, ThreadB and ThreadC in this implementation.Wherein, the monitored thread ThreadA of the first two and ThreadB successively pass through initialization, are registered to described monitoring thread, and have set time-out time Ti, counter C1iInitial value, abnormal number of times C2iInitial value and abnormal number of times limit value; Monitored thread ThreadC does not also carry out initialization.
Constantly upgrade the counter C1 of self in the operational process of two monitored thread ThreadA and ThreadBi, monitoring thread finds that certain monitored thread in the time-out time Ti that sets, fails to upgrade its counter C1i, thinks that this thread is abnormal, its abnormal number of times C2iAdd 1;
At monitored thread continuous abnormal number of times C2iDuring greater than the abnormal number of times limit value set, generate described dmp file, and counter reset C1iWith abnormal number of times C2iBe initial value.
Continuous abnormal number of times corresponding to monitored thread just judges this monitored thread abnormal during greater than the abnormal number of times limit value of described setting, can reduce the probability of some thread erroneous judgement complicated and consuming time.
Embodiment three:
Figure 4 shows that the structural representation block diagram of the positioning system that a kind of thread of the present embodiment record is abnormal, described system comprises:
Monitoring module 410 for the running status of each monitored thread of monitoring, judges whether monitored thread operation is abnormal;
Dumpfile generation module 420 is used for generating dump file when judgement obtains monitored thread abnormal, and described dump file comprises internal memory, the stack information of in-process each thread;
Abnormal locating module 430 is used for locating the code position at the abnormal place of monitored thread by the described dump file of debugging.
The system of the present embodiment can not only the monitoring thread running status, and when the thread operation exception, internal memory and stack information by the current operation of the automatic record thread of dump file, the developer is according to internal memory and the stack information of record, just the code position that causes that thread is abnormal be can locate fast, debugging and the reparation of thread facilitated.
Above embodiment only is used for explanation the present invention; and be not limitation of the present invention; the those of ordinary skill in relevant technologies field; without departing from the spirit and scope of the present invention; can also make a variety of changes and modification; therefore all technical schemes that are equal to also belong to category of the present invention, and scope of patent protection of the present invention should be defined by the claims.