[go: up one dir, main page]
More Web Proxy on the site http://driver.im/

CN115701584A - Thread determining method and device, storage medium and electronic device - Google Patents

Thread determining method and device, storage medium and electronic device Download PDF

Info

Publication number
CN115701584A
CN115701584A CN202110882374.0A CN202110882374A CN115701584A CN 115701584 A CN115701584 A CN 115701584A CN 202110882374 A CN202110882374 A CN 202110882374A CN 115701584 A CN115701584 A CN 115701584A
Authority
CN
China
Prior art keywords
thread
target
determining
threads
interface
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
CN202110882374.0A
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.)
Zhejiang Dahua Technology Co Ltd
Original Assignee
Zhejiang Dahua Technology 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 Dahua Technology Co Ltd filed Critical Zhejiang Dahua Technology Co Ltd
Priority to CN202110882374.0A priority Critical patent/CN115701584A/en
Publication of CN115701584A publication Critical patent/CN115701584A/en
Pending legal-status Critical Current

Links

Images

Landscapes

  • Debugging And Monitoring (AREA)

Abstract

The embodiment of the invention provides a method and a device for determining a thread, a storage medium and an electronic device, wherein the method comprises the following steps: under the condition that the target utilization rate of the target processor exceeds a first threshold value, determining a preset number of first threads, wherein the first threads are threads which occupy resources included in a target process and meet target conditions; determining a first thread identification of a first thread described by a first interface included in a target processor; calling target log information of the first thread based on the first thread identification; and determining a target thread from the first threads based on the target log information. The invention solves the problems of the prior art that a tool is needed when a thread with high CPU utilization rate is determined, and the universality is poor, and achieves the effects of high universality and small external dependence.

Description

Thread determining method and device, storage medium and electronic device
Technical Field
The embodiment of the invention relates to the field of communication, in particular to a method and a device for determining a thread, a storage medium and an electronic device.
Background
The diagnosable function of the large system software directly determines the quality of the product and the quality of life of development and operation and maintenance engineers. The high utilization rate of the CPU can influence the software function and performance.
In the related art, with the rapid development of the internet of things, more edge devices have operating systems that implement more intelligent functions, but some devices have some tools (e.g., db2top, perf, ebpf) and commands (e.g., jstack) of linux operating systems that are cut off due to memory, cost, or security. However, linux or some commands onboard the integrated tool are typically required to implement diagnostics when determining the thread that results in high CPU utilization.
Therefore, the related art has the problems that tools are needed to determine the threads causing high CPU utilization rate, and the universality is poor.
In view of the above problems in the related art, no effective solution has been proposed so far.
Disclosure of Invention
The embodiment of the invention provides a method and a device for determining a thread, a storage medium and an electronic device, which are used for at least solving the problems that tools are needed when threads with high CPU utilization rate are determined in the related technology, and the universality is poor.
According to an embodiment of the present invention, there is provided a method for determining a thread, including: under the condition that the target utilization rate of a target processor exceeds a first threshold value, determining a preset number of first threads, wherein the first threads are threads which meet target conditions and are occupied by resources included in a target process; determining a first thread identification of the first thread of a first interface description included in the target processor; calling target log information of the first thread based on the first thread identification; and determining a target thread from the first threads based on the target log information.
According to another embodiment of the present invention, there is provided a thread determining apparatus including: the first determining module is used for determining a predetermined number of first threads under the condition that the target utilization rate of the target processor exceeds a first threshold, wherein the first threads are threads which meet target conditions and are occupied by resources included in a target process; a second determining module, configured to determine a first thread identifier of the first thread described by a first interface included in the target processor; the calling module is used for calling the target log information of the first thread based on the first thread identification; and the third determining module is used for determining a target thread from the first threads based on the target log information.
According to yet another embodiment of the invention, there is also provided a computer-readable storage medium having a computer program stored therein, wherein the computer program, when executed by a processor, implements the steps of the method as set forth in any of the above.
According to yet another embodiment of the present invention, there is also provided an electronic device, including a memory in which a computer program is stored and a processor configured to execute the computer program to perform the steps in any of the above method embodiments.
According to the method and the device, under the condition that the target utilization rate of the target processor exceeds a first threshold value, a first thread of the preset data is determined, wherein the first thread is a thread which occupies resources included in the target process and meets target conditions, a first thread identifier of the first thread described by a first interface included in the target processor is determined, target log information of the first thread is called according to the first thread identifier, and the target thread is determined from the first thread according to the target log information. The target log information of the first thread can be called directly according to the thread identification of the first thread described by the first interface, so that the target thread is determined without depending on a specific tool. Therefore, the method can solve the problems that tools are needed when threads with high CPU utilization rate are determined and the universality is poor in the related technology, and achieves the effects of high universality and small external dependence.
Drawings
Fig. 1 is a block diagram of a hardware configuration of a mobile terminal of a method for determining a thread according to an embodiment of the present invention;
FIG. 2 is a flow diagram of a method of determining a thread according to an embodiment of the invention;
FIG. 3 is a timing diagram of target log information for invoking a first thread based on a first thread identification in accordance with an exemplary embodiment of the present invention;
FIG. 4 is a schematic diagram of a DMO according to an exemplary embodiment of the invention;
FIG. 5 is a flowchart of a method for determining a thread according to an embodiment of the present invention;
fig. 6 is a block diagram of a thread determination apparatus according to an embodiment of the present invention.
Detailed Description
Embodiments of the present invention will be described in detail below with reference to the accompanying drawings in conjunction with embodiments.
It should be noted that the terms "first," "second," and the like in the description and claims of the present invention and in the drawings described above are used for distinguishing between similar elements and not necessarily for describing a particular sequential or chronological order.
The method embodiments provided in the embodiments of the present application may be executed in a mobile terminal, a computer terminal, or a similar computing device. Taking the example of the method running on a mobile terminal, fig. 1 is a block diagram of a hardware structure of the mobile terminal of a method for determining a thread according to an embodiment of the present invention. As shown in fig. 1, the mobile terminal may include one or more (only one shown in fig. 1) processors 102 (the processor 102 may include, but is not limited to, a processing device such as a microprocessor MCU or a programmable logic device FPGA), and a memory 104 for storing data, wherein the mobile terminal may further include a transmission device 106 for communication functions and an input-output device 108. It will be understood by those skilled in the art that the structure shown in fig. 1 is only an illustration, and does not limit the structure of the mobile terminal. For example, the mobile terminal may also include more or fewer components than shown in FIG. 1, or have a different configuration than shown in FIG. 1.
The memory 104 may be used to store computer programs, for example, software programs and modules of application software, such as computer programs corresponding to the thread determination method in the embodiment of the present invention, and the processor 102 executes various functional applications and data processing by running the computer programs stored in the memory 104, so as to implement the above-mentioned method. The memory 104 may include high speed random access memory, and may also include non-volatile memory, such as one or more magnetic storage devices, flash memory, or other non-volatile solid-state memory. In some examples, the memory 104 may further include memory located remotely from the processor 102, which may be connected to the mobile terminal over a network. Examples of such networks include, but are not limited to, the internet, intranets, local area networks, mobile communication networks, and combinations thereof.
The transmission device 106 is used to receive or transmit data via a network. Specific examples of the network described above may include a wireless network provided by a communication provider of the mobile terminal. In one example, the transmission device 106 includes a Network adapter (NIC) that can be connected to other Network devices through a base station to communicate with the internet. In one example, the transmission device 106 may be a Radio Frequency (RF) module, which is used to communicate with the internet in a wireless manner.
In this embodiment, a method for determining a thread is provided, and fig. 2 is a flowchart of a method for determining a thread according to an embodiment of the present invention, as shown in fig. 2, the flowchart includes the following steps:
step S202, under the condition that the target utilization rate of a target processor exceeds a first threshold value, determining a predetermined number of first threads, wherein the first threads are threads which occupy resources included in a target process and meet target conditions;
step S204, determining a first thread identifier of the first thread described by a first interface included in the target processor;
step S206, calling target log information of the first thread based on the first thread identification;
step S208, determining a target thread from the first threads based on the target log information.
In the above embodiment, in order to avoid the influence of the service other than the diagnostic logic when the target utilization rate of the target processor is high, one thread may be started alone to implement the diagnostic logic processing, and nothing other than the diagnostic logic is done, so as to avoid the influence of the service other than the diagnostic logic on normal diagnosis caused by the CPU being flushed or deadlock or dead loop being triggered. That is, one thread may be separately launched for determining the target thread.
In the above embodiment, in the case that the target usage exceeds the first threshold, a target process included in the target processor may be first determined, and a predetermined number of first threads are determined in the target process. After the first thread is determined, determining that the first interface description obtains a first thread identifier of the first thread, taking the first thread identifier as input, and calling out target log information of the first thread. And determining a target thread according to the target log information. The target processor may be a central processing unit CPU, and the first interface may be a POSIX standard interface.
Alternatively, the execution subject of the above steps may be the target processor.
According to the method and the device, under the condition that the target utilization rate of the target processor exceeds a first threshold value, a first thread of the preset data is determined, wherein the first thread is a thread which occupies resources included in a target process and meets a target condition, a first thread identifier of the first thread described by a first interface included in the target processor is determined, target log information of the first thread is called according to the first thread identifier, and the target thread is determined from the first thread according to the target log information. The target log information of the first thread can be called directly according to the thread identification of the first thread described by the first interface, so that the target thread is determined without depending on a specific tool. Therefore, the problem that tools are needed when threads with high CPU utilization rate are determined in the related technology and the universality is poor can be solved, and the effects of high universality and small external dependence are achieved.
In one exemplary embodiment, in the event that the target usage of the target processor exceeds a first threshold, determining the predetermined number of first threads comprises: determining a target duration for which the target usage rate continuously exceeds the first threshold; and determining the preset number of the first threads under the condition that the target duration is greater than or equal to a preset duration. In this embodiment, in order to avoid the CPU utilization (corresponding to the target utilization) from fluctuating repeatedly above and below a threshold value, triggering mass log records, a shock-proof process may be added to the diagnostic logic. That is, a certain time (for example, 1 minute) continuously accumulated exceeds the threshold (corresponding to the first threshold), and it is defined that the CPU utilization rate is high and exceeds the threshold. If the continuous accumulation time (1 minute) is lower than the threshold value, the original accumulation time is cleared, and the continuous time is accumulated again. That is, only when the target duration that the target usage rate is higher than the first threshold is greater than or equal to the predetermined duration, the target usage rate of the target processor is considered to exceed the first threshold, and then the predetermined number of first threads is determined. The preset time period may be 1min, which is only an exemplary description, and the preset time period may also be 30s, 2min, and the like, which is not limited in the present invention.
In the above embodiment, the CPU utilization of the target processor may be calculated by reading/proc/stat files, the CPU utilization of the board is obtained and then compared with a threshold, and if a certain time (for example, 1 minute) continuously accumulates and exceeds the threshold, the CPU utilization is defined as being higher than the threshold. If the continuous accumulated time (1 minute) is lower than the threshold value, the original accumulated time is cleared, and the continuous time is accumulated again. Therefore, the CPU data is subjected to anti-oscillation processing, the condition that the CPU fluctuates up and down at a threshold value to frequently trigger subsequent records is avoided, and mass log records are avoided.
In one exemplary embodiment, determining the predetermined number of first threads includes: determining a first resource occupancy rate of each process included in the target processor based on first file information included in the target processor; determining a target process corresponding to the maximum resource occupancy rate in the first resource occupancy rates; determining a predetermined number of the first threads from the target process. In this embodiment, after determining that the target utilization exceeds the first threshold, that is, after defining that the board-level CPU utilization is high, the CPU utilization (corresponding to the first resource occupancy) of each process in the board may be calculated by reading/proc/< process pid >/stat and/proc/stat file information, determining the process pid of the TOP1 process (corresponding to the above), and if the pid is the id of the self-generated process, determining that the process of the CPU flush-up this time causes, and performing subsequent thread-level CPU utilization high definition. That is, each process in the target processor may determine the first resource occupancy, and if the process 1 determines that the first resource occupancy of the process 2 is the highest, that is, the pid of the process 2 is not the id of the native process (process 1), the process of determining the first thread is not required. If the process 2 determines that the first resource occupancy rate of the process 2 is the highest, that is, the pid of the process 2 is the id of the self-generated process (process 2), the process of determining the first thread is performed.
In one exemplary embodiment, determining a predetermined number of the first threads from the target process comprises: determining a second resource occupancy rate of each thread included in the target process; determining the predetermined number of threads with the highest second resource occupancy as the predetermined number of the first threads. In this embodiment, after defining that the CPU utilization of the process (corresponding to the first resource occupancy) is the highest, the TOP3 threads (the predetermined number of first threads) can be selected by reading/proc/< pid >/stat of the process and/proc/< pid >/task >/thread tid >/stat file to calculate the CPU utilization of each thread in the process (i.e. the second resource occupancy). That is, the predetermined number may be 3, which is only an exemplary illustration, and the predetermined number may be 2,4,5, etc., which is not limited by the present invention.
In one exemplary embodiment, determining a first thread identification of the first thread of a first interface description included in the target processor comprises: determining a first thread control character for the first thread; determining a second thread identification of the first thread stored in a core based on the first thread control character; determining the first thread identification based on the second thread identification. In this embodiment, after the first thread is determined, a first thread control character tid of the first thread may be determined, and a second thread identifier of the first thread stored in the kernel is determined according to the tid. And determining the first thread identifier according to the second thread identifier. The first thread identifier tid and the second thread identifier tid may be the same.
In one exemplary embodiment, determining the first thread identification based on the second thread identification comprises: acquiring a mapping relation between a thread identifier stored in a kernel and a thread identifier of a thread described by the first interface; determining the first thread identification corresponding to the second thread identification based on the mapping relation. In this embodiment, the thread identifier stored in the kernel and the thread identifier of the thread described by the first interface have a one-to-one mapping relationship, and the mapping relationship may be obtained to determine the first thread identifier corresponding to the second thread identifier according to the mapping relationship. Wherein, the mapping relation can be preset.
In one exemplary embodiment, before obtaining the mapping relationship between the thread identifier stored by the kernel and the thread identifier of the thread described by the first interface, the method further includes: embedding the mapping relation between the thread identifier stored in the kernel and the thread identifier of the thread described by the first interface into a first function, calling a second interface to determine the storage address of the first function, and storing the first function embedded with the mapping relation into the storage address; acquiring a mapping relationship between a thread identifier stored by a kernel and a thread identifier of a thread described by the first interface comprises: and acquiring the mapping relation from the storage address. In this embodiment, the mapping relationship may be embedded in the first function, the second interface may be called to determine the saving address of the first function, and the first function in which the mapping relationship is embedded may be saved in the saving address. When the mapping relation needs to be obtained, the mapping relation can be obtained from the storage address. Wherein the second interface may be a dlsym interface. The first function may be a sleep function.
In the above embodiment, after most of the service processing threads process services in one cycle, the system interfaces such as sleep are called to release CPU resources, and the processing is performed again until the next cycle. Or the data transceiving thread calls an event monitoring interface (select, poll, etc.) to monitor whether the connection socket has data. The two threads are typically thread synchronized through a thread synchronization interface (sem wait, etc.). These threads must call, and the function for releasing the CPU resources can be defined as a sleep function.
When the same function is realized in a set of engineering codes, which function is specifically used depends on the link sequence, the link priority of the library realized by the user is higher than that of a third-party library, and the library realized by the user can be indicated in the compilation engineering makefile, so that the same function name is ensured and the function realized by the user is used.
By rewriting the sleep function in the software code, the mapping relationship between the thread ID (corresponding to the first thread ID, which can be obtained through pthread _ self interface) described by POSIX of each thread and the thread ID (corresponding to the second thread ID, which can be obtained through syscall (_ NR _ gettid), which is consistent with the ID of the corresponding thread in the/proc/process ID/task directory) in the kernel is saved.
The rewriting function comprises the following processing steps:
1) Calling the dlsym interface and transmitting an RTLD _ NEXT parameter to acquire and store the address of the real rewriting function.
2) Thread ID information mapping saving processing logic: if the thread does not allocate a control block for storing information, the thread is allocated with a control block, and the control block stores the mapping relation between the thread ID (obtained by calling a pthread _ self interface) described by the thread POSIX and the thread ID (obtained by syscall (\\u NR _ gettid) in the kernel, wherein the ID is consistent with the ID of the corresponding thread in the/proc/< process ID >/task directory). If the thread has allocated a control block that holds thread information, no processing is done and this step is ignored.
3) And calling the real function through the saved address of the real rewriting function.
As can be seen from the above steps, in step 2, a storage logic of the mapping relationship between the thread ID described by POSIX and the thread ID in the kernel is added.
Taking the sleep function as an example, the rewritten sleep pseudo code is as follows:
Figure BDA0003192530900000081
Figure BDA0003192530900000091
in one exemplary embodiment, invoking target log information of the first thread based on the first thread identification comprises: calling a second function based on the first thread identification; calling a third interface based on a second function to send a first signal to the first thread so as to instruct the first thread to call a third function, so as to acquire call stack information of the first thread, store the call stack information into a target variable, and feed back a second signal; and receiving the second signal, and recording the call stack information stored in the target variable into a target log based on the second signal to obtain the target log information. In this embodiment, the second function may be called according to the first thread identifier, the third interface may be called according to the second function, and the first signal may be sent to the first thread to instruct the first thread to call the third function, so as to obtain the call stack information of the first thread. And storing the call stack information into the target variable and feeding back second information. And the detection thread receives the second signal and records the call stack information stored in the target variable into the target log according to the second signal so as to obtain the target log. The second function may be a detection function, the third interface may be a pthread _ kill interface, the first signal may be a registration signal, the third function may be a call function, and the target variable may be a global variable.
In the above embodiment, after determining a predetermined number of first threads, for example, a TOP3 thread, the thread ID described by POSIX obtained from the corresponding pthread _ self interface may be found from the thread ID information mapping control block according to tid (corresponding to the first thread identifier and having a value consistent with the thread ID in the kernel) of the TOP3 thread. Taking a thread ID (obtained by a pthread _ self interface) described by POSIX as a reference, calling the pthread _ kill interface, and recording a call stack of the TOP3 thread and a CPU utilization value of each thread according to a thread call stack acquisition flow.
In the above embodiment, referring to fig. 3, as shown in fig. 3, when the process starts, a self-defined registration signal a (e.g. sigrmmin + 10) may be set by calling a signal processing setting function sign defined by the POSIX standard, where the processing function corresponding to the signal a (e.g. sigrmmin + 10) is B, and the processing logic of the function B is: and acquiring the current call stack, storing the current call stack into a global variable D, and releasing the semaphore E to inform the detection thread that the call stack acquisition processing is finished.
When a call stack needs to be fetched, the detection function F sends a custom semaphore a (e.g. sigrmmin + 10) to the thread C that needs to fetch the call stack via the pthread _ kill function defined by the POSIX standard, and then waits for the semaphore E to be released. After sending the custom signal a (e.g., SIGRTMIN + 10), the trigger handling function B is called, and the function B obtains the current thread call stack and saves it to the global variable D and releases the semaphore E. And after waiting until the semaphore E is released, the detection function F obtains the call stack of the thread C through the global variable D and records the log. By the operation, the function call stack can be recorded by using the POSIX standard interface.
When the CPU utilization rate exceeds the threshold value, the call stack of the thread with high CPU utilization rate can be obtained by triggering, so that automatic diagnosis when the CPU utilization rate is high is realized by using a POSIX standard interface, namely, the target thread is determined. The automatic diagnosis with high CPU utilization rate is realized by utilizing the POSIX standard interface, other tools and commands are not relied on, other modules are not required to be matched and modified, the transportability is strong, the universality is high, and the external dependence is small.
The function for setting and modifying the signal processing mode defined by the POSIX standard is sigaction, and the interface header file, the prototype and the parameters of the function are described as follows:
#include<signal.h>
int sigaction(int signum,const struct sigaction*act,struct sigaction*oldact);
wherein signum is a signal to be operated. The specific signal values are as follows:
1)SIGHUP 2)SIGINT 3)SIGQUIT 4)SIGILL 5)SIGTRAP
6)SIGABRT 7)SIGBUS 8)SIGFPE 9)SIGKILL 10)SIGUSR1
11)SIGSEGV 12)SIGUSR2 13)SIGPIPE 14)SIGALRM 15)SIGTERM
16)SIGSTKFLT 17)SIGCHLD 18)SIGCONT 19)SIGSTOP 20)SIGTSTP
21)SIGTTIN 22)SIGTTOU 23)SIGURG 24)SIGXCPU 25)SIGXFSZ
26)SIGVTALRM 27)SIGPROF 28)SIGWINCH 29)SIGIO 30)SIGPWR
31)SIGSYS 34)SIGRTMIN 35)SIGRTMIN+1 36)SIGRTMIN+2
37)SIGRTMIN+3 38)SIGRTMIN+4 39)SIGRTMIN+5 40)SIGRTMIN+6
41)SIGRTMIN+7 42)SIGRTMIN+8 43)SIGRTMIN+9 44)SIGRTMIN+10
45)SIGRTMIN+11 46)SIGRTMIN+12 47)SIGRTMIN+13
48)SIGRTMIN+14 49)SIGRTMIN+15 50)SIGRTMAX-14
51)SIGRTMAX-13 52)SIGRTMAX-12 53)SIGRTMAX-11
54)SIGRTMAX-10 55)SIGRTMAX-9 56)SIGRTMAX-8
57)SIGRTMAX-7 58)SIGRTMAX-6 59)SIGRTMAX-5 60)SIGRTMAX-4
61)SIGRTMAX-3 62)SIGRTMAX-2 63)SIGRTMAX-1 64)SIGRTMAX
where act denotes a new processing mode for a signal to be set. Oldact represents the original way of processing the signal.
In one exemplary embodiment, determining a target thread from the first threads based on the log information comprises: determining the target thread from a plurality of first threads based on the target log information of the plurality of first threads invoked multiple times; wherein the target log information of each call to the first thread is executed if the usage rate of the target processor exceeds the first threshold, and the first threshold that the usage rate of the target processor exceeds is different among different call operations. In this embodiment, in order to improve the detection accuracy and ensure that the diagnostic logic can be fully scheduled to execute, several levels of thresholds (for example, 75%,85%, and 95%) may be set, and if the thresholds exceed the levels, one recording is triggered, and logs of multiple levels are mutually certified to ensure the accuracy and the reliability of the diagnostic data, and also to avoid that the diagnostic logic cannot be scheduled and the diagnostic data recording is affected in some extreme scenarios (CPU utilization rate 100%). The CPU obtains the target thread once when exceeding one grade, and the accuracy of diagnosis definition is improved by mutual evidence of information recorded by a plurality of grades. And diagnostic data is acquired when the CPU is low, so that the problem that the diagnostic data record is influenced due to insufficient diagnostic logic scheduling under some extreme scenes (the CPU utilization rate is 100%) due to resource jamming is avoided.
In the above embodiment, the determination of the target thread may be done in one DMO (occurrence domain). Referring to fig. 4, the DMO schematic diagram can be seen in fig. 4, as shown in fig. 4, GEN _ threaddidinfo is responsible for mapping and storing thread ID information, GEN _ slotcpounfo is responsible for calculating a board-level CPU usage (corresponding to the above target usage), GEN _ PIDCpuInfo is responsible for calculating a process-level CPU usage (corresponding to a first resource occupancy), GEN _ TIDCpuInfo is responsible for calculating a thread-level CPU usage (corresponding to a second resource occupancy), FTC _ CallStack is responsible for acquiring and recording call stack information, ARES is responsible for defining and shaking prevention processing of high CPU usage at multiple levels of thresholds, ARES independently starts one thread to implement diagnostic logic processing, and things except the diagnostic logic do not, thereby avoiding that services except the diagnostic logic rush the CPU usage or trigger a deadlock loop to affect normal diagnosis. Where DMO is Domain occupancy, which is where an event or record occurs, which is where the event or record was first captured. ARES, the Activity Record/Event Source, the Record of the Activity and the Event Source. GEN, generator, record (Record) or Event (Event) information block Generator. FTC is First-Tier Catcher, first line Catcher.
The following describes a thread determination method with reference to a specific embodiment:
fig. 5 is a flowchart of a method for determining a thread according to an embodiment of the present invention, where as shown in fig. 5, the flowchart includes:
step S502, the utilization rate of the unipolar plate CPU is defined.
In step S504, whether the oscillation release processing exceeds the threshold value is judged, and if yes, step S506 is executed, and if no, step S518 is executed.
Step S506, process level CPU utilization is defined.
In step S508, if the CPU utilization of the process is the highest, step S510 is executed if the determination result is yes, and step S518 is executed if the determination result is no.
Step S510, the utilization rate of the thread-level CPU in the process is defined.
And S512, selecting the TOP3 thread, and finding the thread ID described by the POSIX according to the tid.
Step S514, taking the thread ID described by POSIX as a reference, calling pthread _ kill interface to record TOP3 thread call stack.
In step S516, the CPU occupancy value of the TOP3 thread is recorded.
And step S518, ending.
In the foregoing embodiment, the high CPU utilization may be detected in a step-by-step refinement manner according to a single board level, a process level, and a thread level, and finally, which thread is high may be accurately reached, and a call stack of the thread with the high CPU utilization is recorded by using a call stack acquisition flow. The method and the device can accurately determine the target thread causing high CPU utilization rate without depending on other tools.
Through the above description of the embodiments, those skilled in the art can clearly understand that the method according to the above embodiments can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware, but the former is a better implementation mode in many cases. Based on such understanding, the technical solutions of the present invention may be embodied in the form of a software product, which is stored in a storage medium (e.g., ROM/RAM, magnetic disk, optical disk) and includes instructions for enabling a terminal device (e.g., a mobile phone, a computer, a server, or a network device) to execute the method according to the embodiments of the present invention.
In this embodiment, a thread determining apparatus is further provided, and the apparatus is used to implement the foregoing embodiments and preferred embodiments, and details of which have been already described are not described again. As used below, the term "module" may be a combination of software and/or hardware that implements a predetermined function. Although the means described in the embodiments below are preferably implemented in software, an implementation in hardware, or a combination of software and hardware is also possible and contemplated.
Fig. 6 is a block diagram of a thread determining apparatus according to an embodiment of the present invention, and as shown in fig. 6, the apparatus includes:
a first determining module 62, configured to determine, when a target utilization of a target processor exceeds a first threshold, a predetermined number of first threads, where the first threads are threads whose resource occupation included in a target process meets a target condition;
a second determining module 64, configured to determine a first thread identifier of the first thread described by the first interface included in the target processor;
a calling module 66, configured to call target log information of the first thread based on the first thread identifier;
a third determining module 68, configured to determine a target thread from the first threads based on the target log information.
In one exemplary embodiment, the first determination module 62 may determine the predetermined number of first threads in the event that the target utilization of the target processor exceeds the first threshold by: determining a target duration for which the target usage rate continuously exceeds the first threshold; and determining the preset number of the first threads under the condition that the target duration is greater than or equal to a preset duration.
In one exemplary embodiment, the first determination module 62 may determine the predetermined number of first threads by: determining a first resource occupancy rate of each process included in the target processor based on first file information included in the target processor; determining a target process corresponding to the maximum resource occupancy rate in the first resource occupancy rates; determining a predetermined number of the first threads from the target process.
In an exemplary embodiment, the first determining module 62 may determine the predetermined number of the first threads from the target process by: determining a second resource occupancy rate of each thread included in the target process; determining the predetermined number of threads with the highest second resource occupancy as the predetermined number of the first threads.
In an exemplary embodiment, the second determining module 64 may determine the first thread identification of the first thread described by the first interface included in the target processor by: determining a first thread control character for the first thread; determining a second thread identification of the first thread stored in a core based on the first thread control character; determining the first thread identification based on the second thread identification.
In an exemplary embodiment, the second determination module 64 may determine the first thread identification based on the second thread identification by: acquiring a mapping relation between a thread identifier stored in a kernel and a thread identifier of a thread described by the first interface; determining the first thread identification corresponding to the second thread identification based on the mapping relation.
In an exemplary embodiment, the apparatus may be configured to, before obtaining a mapping relationship between a kernel-stored thread identifier and a thread identifier of a thread described by the first interface, embed the mapping relationship between the kernel-stored thread identifier and the thread identifier of the thread described by the first interface into a first function, call a second interface to determine a save address of the first function, and save the first function in which the mapping relationship is embedded into the save address; the second determining module 64 may obtain the mapping relationship between the thread identifier stored in the kernel and the thread identifier of the thread described by the first interface by: and acquiring the mapping relation from the storage address.
In one exemplary embodiment, invoking module 66 may implement invoking the target log information of the first thread based on the first thread identification by: calling a second function based on the first thread identification; calling a third interface based on a second function to send a first signal to the first thread so as to instruct the first thread to call a third function, so as to acquire call stack information of the first thread, store the call stack information into a target variable, and feed back a second signal; and receiving the second signal, and recording the call stack information stored in the target variable into a target log based on the second signal to obtain the target log information.
In an exemplary embodiment, the third determination module 68 may determine the target thread from the first threads based on the log information by: determining the target thread from a plurality of first threads based on the target log information of the plurality of first threads invoked multiple times; wherein the target log information of each call to the first thread is executed if the usage rate of the target processor exceeds the first threshold, and the first threshold that the usage rate of the target processor exceeds is different in different call operations.
It should be noted that the above modules may be implemented by software or hardware, and for the latter, the following may be implemented, but not limited to: the modules are all positioned in the same processor; alternatively, the modules are respectively located in different processors in any combination.
Embodiments of the present invention also provide a computer-readable storage medium having a computer program stored thereon, wherein the computer program, when executed by a processor, implements the steps of the method as set forth in any of the above.
In an exemplary embodiment, the computer-readable storage medium may include, but is not limited to: various media capable of storing computer programs, such as a usb disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a removable hard disk, a magnetic disk, or an optical disk.
Embodiments of the present invention further provide an electronic device, comprising a memory in which a computer program is stored and a processor configured to execute the computer program to perform the steps in any of the above method embodiments.
In an exemplary embodiment, the electronic apparatus may further include a transmission device and an input/output device, wherein the transmission device is connected to the processor, and the input/output device is connected to the processor.
For specific examples in this embodiment, reference may be made to the examples described in the foregoing embodiments and exemplary implementations, and details of this embodiment are not repeated herein.
It will be apparent to those skilled in the art that the modules or steps of the present invention described above may be implemented in a general purpose computing device, they may be centralized in a single computing device or distributed across a network of multiple computing devices, and they may be implemented in program code that is executable by a computing device, such that they may be stored in a memory device and executed by a computing device, and in some cases, the steps shown or described may be executed in an order different from that shown or described herein, or they may be separately fabricated into individual integrated circuit modules, or multiple modules or steps therein may be fabricated into a single integrated circuit module. Thus, the present invention is not limited to any specific combination of hardware and software.
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 principle of the present invention should be included in the protection scope of the present invention.

Claims (12)

1. A method for determining a thread, comprising:
under the condition that the target utilization rate of a target processor exceeds a first threshold value, determining a preset number of first threads, wherein the first threads are threads which meet target conditions and are occupied by resources included in a target process;
determining a first thread identification of the first thread of a first interface description included in the target processor;
calling target log information of the first thread based on the first thread identification;
and determining a target thread from the first threads based on the target log information.
2. The method of claim 1, wherein determining the predetermined number of first threads in the event the target usage rate of the target processor exceeds a first threshold comprises:
determining a target duration for which the target usage rate continuously exceeds the first threshold;
and determining the preset number of the first threads under the condition that the target duration is greater than or equal to a preset duration.
3. The method of claim 1, wherein determining a predetermined number of first threads comprises:
determining a first resource occupancy rate of each process included in the target processor based on first file information included in the target processor;
determining a target process corresponding to the maximum resource occupancy rate in the first resource occupancy rates;
determining a predetermined number of the first threads from the target process.
4. The method of claim 3, wherein determining a predetermined number of the first threads from the target process comprises:
determining a second resource occupancy rate of each thread included in the target process;
determining the predetermined number of threads with the highest second resource occupancy as the predetermined number of the first threads.
5. The method of claim 1, wherein determining a first thread identification of the first thread of a first interface description included in the target processor comprises:
determining a first thread control character for the first thread;
determining a second thread identification of the first thread stored in a core based on the first thread control character;
determining the first thread identification based on the second thread identification.
6. The method of claim 5, wherein determining the first thread identification based on the second thread identification comprises:
acquiring a mapping relation between a thread identifier stored in a kernel and a thread identifier of a thread described by the first interface;
and determining the first thread identification corresponding to the second thread identification based on the mapping relation.
7. The method of claim 6,
before obtaining a mapping relationship between the thread identifier stored by the kernel and the thread identifier of the thread described by the first interface, the method further includes: embedding the mapping relation between the thread identifier stored in the kernel and the thread identifier of the thread described by the first interface into a first function, calling a second interface to determine the storage address of the first function, and storing the first function embedded with the mapping relation into the storage address;
acquiring a mapping relationship between a thread identifier stored by a kernel and a thread identifier of a thread described by the first interface comprises: and acquiring the mapping relation from the storage address.
8. The method of claim 1, wherein invoking target log information for the first thread based on the first thread identification comprises:
calling a second function based on the first thread identification;
calling a third interface based on a second function to send a first signal to the first thread so as to instruct the first thread to call a third function, so as to acquire call stack information of the first thread, store the call stack information into a target variable, and feed back a second signal;
and receiving the second signal, and recording the call stack information stored in the target variable into a target log based on the second signal to obtain the target log information.
9. The method of claim 1, wherein determining a target thread from the first threads based on the log information comprises:
determining the target thread from a plurality of first threads based on the target log information of the plurality of first threads invoked multiple times;
wherein the target log information of each call to the first thread is executed if the usage rate of the target processor exceeds the first threshold, and the first threshold that the usage rate of the target processor exceeds is different among different call operations.
10. A thread determining apparatus, comprising:
the system comprises a first determining module, a second determining module and a third determining module, wherein the first determining module is used for determining a preset number of first threads under the condition that the target utilization rate of a target processor exceeds a first threshold value, and the first threads are threads which occupy resources and meet target conditions in a target process;
a second determining module, configured to determine a first thread identifier of the first thread described by a first interface included in the target processor;
the calling module is used for calling the target log information of the first thread based on the first thread identification;
and the third determining module is used for determining a target thread from the first threads based on the target log information.
11. A computer-readable storage medium, in which a computer program is stored, which computer program, when being executed by a processor, carries out the steps of the method of any one of claims 1 to 9.
12. An electronic device comprising a memory and a processor, wherein the memory has a computer program stored therein, and the processor is configured to execute the computer program to perform the method of any of claims 1 to 9.
CN202110882374.0A 2021-08-02 2021-08-02 Thread determining method and device, storage medium and electronic device Pending CN115701584A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202110882374.0A CN115701584A (en) 2021-08-02 2021-08-02 Thread determining method and device, storage medium and electronic device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202110882374.0A CN115701584A (en) 2021-08-02 2021-08-02 Thread determining method and device, storage medium and electronic device

Publications (1)

Publication Number Publication Date
CN115701584A true CN115701584A (en) 2023-02-10

Family

ID=85142549

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202110882374.0A Pending CN115701584A (en) 2021-08-02 2021-08-02 Thread determining method and device, storage medium and electronic device

Country Status (1)

Country Link
CN (1) CN115701584A (en)

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116860436A (en) * 2023-06-15 2023-10-10 重庆智铸达讯通信有限公司 Thread data processing method, device, equipment and storage medium

Cited By (1)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN116860436A (en) * 2023-06-15 2023-10-10 重庆智铸达讯通信有限公司 Thread data processing method, device, equipment and storage medium

Similar Documents

Publication Publication Date Title
CN108268372B (en) Mock test processing method and device, storage medium and computer equipment
CN110830577B (en) Service request call tracking method and device, computer equipment and storage medium
US10791037B2 (en) Reliable transfer of numerous geographically distributed large files to a centralized store
CN110232010A (en) A kind of alarm method, alarm server and monitoring server
CN111045810B (en) Task scheduling processing method and device
CN108363653B (en) Deployment method and device of monitoring system, computer equipment and storage medium
CN110554912B (en) Method and device for scheduling equipment to execute tasks
CN109560976B (en) Message delay monitoring method and device
CN115701584A (en) Thread determining method and device, storage medium and electronic device
CN112306567A (en) Cluster management system and container management and control method
CN110858829B (en) Video processing method, device and system, analysis server and transcoding server
CN116302989A (en) Pressure testing method and system, storage medium and computer equipment
CN111241594B (en) Method, device, computer equipment and storage medium for signing transaction information
CN112306871A (en) Data processing method, device, equipment and storage medium
CN111796906A (en) Container management method, device, equipment and storage medium
CN110837431A (en) Service control method, service control device, computer equipment and computer-readable storage medium
CN108920323B (en) Application data statistical method and device and mobile terminal
CN108804152B (en) Method and device for adjusting configuration parameters
CN108572863B (en) Distributed task scheduling system and method
CN106708737B (en) Test method and device
CN115981871A (en) GPU resource scheduling method, device, equipment and storage medium
CN100501699C (en) Method and system for capturing and storing bare nucleus in exception in multi-core processor
CN106330548B (en) Flow statistical method, device and system
CN112055058A (en) Data storage method and device and computer readable storage medium
CN111258728A (en) Task execution method and device, storage medium and electronic device

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