A thread dead loop detection method, device and apparatus
By acquiring CPU usage information and thread execution information, calculating the CPU resource utilization level, determining and adjusting priorities to detect thread dead loops, the problem of low efficiency in existing technologies is solved, and efficient automated detection is achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- DATANG MOBILE COMM EQUIP CO LTD
- Filing Date
- 2021-11-05
- Publication Date
- 2026-06-19
AI Technical Summary
Current technologies for detecting thread dead loops are inefficient, requiring manual checks of CPU usage and individual investigation of high-occupancy threads, resulting in low efficiency.
By obtaining CPU usage information and thread execution information, the utilization of CPU computing resources is calculated, the thread with the highest utilization is identified as the thread to be tested, and the priority of the test thread is adjusted to be lower than the target priority of the thread to be tested. The target priority of the thread's cycle is obtained, and the runtime of the thread is obtained to determine the dead loop.
It enables efficient detection of thread dead loops without relying on manual intervention, reducing the impact on other threads and improving detection efficiency.
Smart Images

Figure CN116089098B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of software technology, and in particular to a method, device, and apparatus for detecting thread dead loops. Background Technology
[0002] The CPU (Central Processing Unit) is a device capable of processing data and running programs. Different programs can run in different threads within the CPU. However, due to design flaws or other malfunctions, threads may enter infinite loops during execution. Infinite loop threads continuously run, consuming significant CPU computing resources and thus affecting the operation of other threads. To ensure the CPU can process data normally, it is necessary to detect and handle infinite loop threads.
[0003] In existing technologies, it is necessary to manually check CPU utilization and examine the execution status of each thread on the CPU with high CPU utilization to detect threads in infinite loops. This method is inefficient for detecting infinite loops. Summary of the Invention
[0004] The purpose of this invention is to provide a method, device, and apparatus for detecting dead loops in threads, thereby improving the efficiency of detecting dead loop threads. The specific technical solution is as follows:
[0005] In a first aspect, embodiments of the present invention provide a method for detecting thread dead loops, the method comprising:
[0006] Obtain CPU usage information of the CPU and thread execution information of the threads running on the CPU;
[0007] Based on the CPU usage information, calculate the utilization level of the CPU computing resources;
[0008] If the usage level reaches a preset level, then based on the thread running information, the thread with the highest CPU usage is identified as the thread to be detected.
[0009] The execution priority of the preset test thread is adjusted from the lowest priority to the target priority. The test thread and the thread to be tested belong to the same target process. The target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference.
[0010] Obtain the runtime of the test thread within the first preset time period;
[0011] If the runtime is less than the second preset runtime, then the thread to be detected is determined to be in an infinite loop.
[0012] In one embodiment of the present invention, after determining that the thread to be detected has entered an infinite loop, the method further includes:
[0013] The thread to be detected is suspended.
[0014] If the management thread for managing the device where the CPU is located is running on the CPU, and the execution priority of the management thread is lower than the execution priority of the thread to be detected, then the information contained in the task stack of the thread to be detected is recorded, the device is reset, and the CPU is controlled to rerun the thread to be detected based on the recorded information.
[0015] In one embodiment of the present invention, calculating the utilization level of the CPU computing resources based on the CPU usage information includes:
[0016] Based on the CPU runtime, CPU wait time and CPU idle time contained in the CPU usage information, the first total usage time of the CPU within the first preset time period is calculated.
[0017] The ratio between the CPU runtime and the first total usage time is calculated to represent the utilization level of CPU computing resources.
[0018] In one embodiment of the present invention, determining the thread with the highest CPU usage based on the thread execution information as the thread to be detected includes:
[0019] Based on the thread running information, calculate the thread runtime of each thread running on the CPU within the second preset time period;
[0020] Based on the CPU usage information, calculate the second total CPU usage time within the second preset time period;
[0021] Calculate the ratio between the thread runtime of each thread and the second total usage time, and use it as the CPU usage level of each thread;
[0022] Select the thread with the highest usage as the thread to be tested.
[0023] Secondly, this invention provides a thread dead loop detection device, including a memory, a transceiver, and a processor:
[0024] A memory for storing computer programs; a transceiver for sending and receiving data under the control of the processor; and a processor for reading the computer programs from the memory and performing the following operations:
[0025] Obtain CPU usage information of the CPU and thread execution information of the threads running on the CPU;
[0026] Based on the CPU usage information, calculate the utilization level of the CPU computing resources;
[0027] If the usage level reaches a preset level, then based on the thread running information, the thread with the highest CPU usage is identified as the thread to be detected.
[0028] The execution priority of the preset test thread is adjusted from the lowest priority to the target priority. The test thread and the thread to be tested belong to the same target process. The target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference.
[0029] Obtain the runtime of the test thread within the first preset time period;
[0030] If the runtime is less than the second preset runtime, then the thread to be detected is determined to be in an infinite loop.
[0031] In one embodiment of the present invention, after determining that the thread to be detected has entered an infinite loop, the method further includes:
[0032] The thread to be detected is suspended.
[0033] If the management thread for managing the device where the CPU is located is running on the CPU, and the execution priority of the management thread is lower than the execution priority of the thread to be detected, then the information contained in the task stack of the thread to be detected is recorded, the device is reset, and the CPU is controlled to rerun the thread to be detected based on the recorded information.
[0034] In one embodiment of the present invention, calculating the utilization level of the CPU computing resources based on the CPU usage information specifically includes:
[0035] Based on the CPU runtime, CPU wait time and CPU idle time contained in the CPU usage information, the first total usage time of the CPU within the first preset time period is calculated.
[0036] The ratio between the CPU runtime and the first total usage time is calculated to represent the utilization level of CPU computing resources.
[0037] In one embodiment of the present invention, determining the thread with the highest CPU usage based on the thread execution information as the thread to be detected specifically includes:
[0038] Based on the thread running information, calculate the thread runtime of each thread running on the CPU within the second preset time period;
[0039] Based on the CPU usage information, calculate the second total CPU usage time within the second preset time period;
[0040] Calculate the ratio between the thread runtime of each thread and the second total usage time, and use it as the CPU usage level of each thread;
[0041] Select the thread with the highest usage as the thread to be tested.
[0042] Thirdly, embodiments of the present invention provide a thread dead loop detection device, the device comprising:
[0043] The information acquisition module is used to acquire CPU usage information of the CPU and thread execution information of the threads running on the CPU.
[0044] The degree calculation module is used to calculate the degree of CPU computing resource utilization based on the CPU usage information.
[0045] The thread determination module is used to determine the thread with the highest CPU usage as the thread to be detected based on the thread running information if the usage level reaches a preset level.
[0046] The priority adjustment module is used to adjust the execution priority of a preset test thread from the lowest priority to the target priority. The test thread and the thread to be tested belong to the same target process. The target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference.
[0047] The duration acquisition module is used to acquire the runtime of the test thread within a first preset duration.
[0048] The dead loop determination module is used to determine that the thread to be detected is in a dead loop if the runtime is less than a second preset duration.
[0049] Fourthly, embodiments of the present invention provide a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of any of the methods described in the first aspect.
[0050] Fifthly, embodiments of the present invention also provide a computer program product containing instructions that, when run on a computer, cause the computer to perform any of the steps described in the first aspect.
[0051] Beneficial effects of the embodiments of the present invention:
[0052] This invention provides a method for detecting thread dead loops. First, CPU usage information and thread execution information of threads running on the CPU are obtained. Based on the CPU usage information, the CPU resource utilization level is calculated. If the utilization level reaches a preset level, the thread with the highest CPU usage is identified as the thread to be detected, based on the thread execution information. The execution priority of a preset test thread is adjusted from the lowest priority to a target priority lower than the execution priority of the thread to be detected, with the difference between the two priorities being a preset difference. Then, the runtime of the test thread within a first preset time period is obtained; if the runtime is less than the preset time period, it is determined that the thread to be detected has entered a dead loop.
[0053] As seen above, if the CPU's computing resource usage reaches a preset level, it indicates that the CPU's computing resources are being used extensively. There may be threads within the CPU that are consuming significant computing resources due to infinite loops. Therefore, it's possible to begin detecting infinite loops in the threads running on the CPU. If a thread is in an infinite loop, it will be executed repeatedly, often consuming the highest amount of CPU resources. Thus, the thread with the highest resource consumption can be selected as the thread to be tested. Furthermore, both the thread to be tested and the test thread belong to the target process. After starting the test thread, the execution priority of the test thread is adjusted to be lower than that of the thread to be tested, with the difference between their priorities set to a preset target priority. If the thread to be tested is in an infinite loop and consuming significant computing resources, the test thread will often not run after the first preset duration. Therefore, if the test thread's runtime is less than the second preset duration, it can be considered that the test thread is in an infinite loop. Otherwise, if the thread under test does not enter an infinite loop, after the first preset time period, the CPU will schedule a test thread with a priority close to that of the thread under test. Therefore, if the runtime of the test thread is not less than the second preset time period, it can be considered that the test thread has not entered an infinite loop. Thus, through this embodiment of the invention, it is possible to determine whether a thread has entered an infinite loop without manual intervention, thereby improving the efficiency of detecting infinite loop threads.
[0054] In addition, the test thread originally has the lowest execution priority among the threads contained in the target process. Therefore, in most cases, the test thread will not be executed and will not occupy CPU computing resources in most cases, thus not affecting the operation of other threads. Attached Figure Description
[0055] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on these drawings.
[0056] Figure 1 A flowchart illustrating the first thread dead loop detection method provided in this embodiment of the invention;
[0057] Figure 2 A flowchart illustrating the second thread dead loop detection method provided in this embodiment of the invention;
[0058] Figure 3 This is a schematic diagram of the structure of a thread dead loop detection device provided in an embodiment of the present invention;
[0059] Figure 4 This is a schematic diagram of the structure of the first type of thread dead loop detection device provided in an embodiment of the present invention;
[0060] Figure 5 This is a schematic diagram of the structure of a second type of thread dead loop detection device provided in an embodiment of the present invention. Detailed Implementation
[0061] In this embodiment of the invention, the term "and / or" describes the relationship between associated objects, indicating that three relationships can exist. For example, A and / or B can represent: A existing alone, A and B existing simultaneously, or B existing alone. The character " / " generally indicates that the preceding and following associated objects have an "or" relationship.
[0062] In this embodiment of the invention, the term "multiple" refers to two or more, and other quantifiers are similar.
[0063] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art based on the embodiments of the present invention are within the scope of protection of the present invention.
[0064] Since the efficiency of detecting dead loop threads in the existing technology is low, in order to solve this problem, the present invention provides a method, device and apparatus for detecting dead loop threads.
[0065] This invention provides a method for detecting thread dead loops, the method comprising:
[0066] Obtain CPU usage information and thread execution information of the threads running on the aforementioned CPU;
[0067] Based on the CPU usage information above, calculate the utilization level of the CPU computing resources.
[0068] If the above usage level reaches a preset level, then based on the above thread running information, the thread with the highest CPU usage is identified as the thread to be detected.
[0069] The execution priority of the preset test thread is adjusted from the lowest priority to the target priority. The test thread and the thread to be tested belong to the same target process. The target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference.
[0070] Obtain the runtime of the above test threads within the first preset time period;
[0071] If the above runtime is less than the second preset runtime, then it is determined that the above-mentioned thread to be detected has entered an infinite loop.
[0072] As seen above, if the CPU's computing resource usage reaches a preset level, it indicates that the CPU's computing resources are being used extensively. There may be threads within the CPU that are consuming significant computing resources due to infinite loops. Therefore, it's possible to begin detecting infinite loops in the threads running on the CPU. If a thread is in an infinite loop, it will be executed repeatedly, often consuming the highest amount of CPU resources. Thus, the thread with the highest resource consumption can be selected as the thread to be tested. Furthermore, both the thread to be tested and the test thread belong to the target process. After starting the test thread, the execution priority of the test thread is adjusted to be lower than that of the thread to be tested, with the difference between their priorities set to a preset target priority. If the thread to be tested is in an infinite loop and consuming significant computing resources, the test thread will often not run after the first preset duration. Therefore, if the test thread's runtime is less than the second preset duration, it can be considered that the test thread is in an infinite loop. Otherwise, if the thread under test does not enter an infinite loop, after the first preset time period, the CPU will schedule a test thread with a priority close to that of the thread under test. Therefore, if the runtime of the test thread is not less than the second preset time period, it can be considered that the test thread has not entered an infinite loop. Thus, through this embodiment of the invention, it is possible to determine whether a thread has entered an infinite loop without manual intervention, thereby improving the efficiency of detecting infinite loop threads.
[0073] In addition, the test thread originally has the lowest execution priority among the threads contained in the target process. Therefore, in most cases, the test thread will not be executed and will not occupy CPU computing resources in most cases, thus not affecting the operation of other threads.
[0074] See Figure 1 The above is a flowchart of the first thread dead loop detection method provided in the embodiment of the present invention. The method includes the following steps S101-S106.
[0075] In this embodiment of the invention, the executing entity can be a process running on the CPU installed within the device, and this process can be referred to as the main process. The device can be any electronic device, such as a mobile phone, computer, or base station.
[0076] S101: Obtain CPU usage information of the CPU and thread execution information of the threads running on the aforementioned CPU.
[0077] Specifically, the CPU mentioned above can be the CPU running the main process, or it can be another CPU installed within the device. The thread mentioned above can be a thread running within the main process, or it can be a thread running outside the main process. If the thread runs in a process other than the main process, then the process running the thread can be called a slave process.
[0078] If the aforementioned thread runs within the main process, the main process can directly obtain the thread's running information and the CPU's CPU usage information.
[0079] Additionally, if the aforementioned thread runs within a slave process, the slave process can obtain the thread's task name, thread TID (Thread Identifier), slave process PID (Process Identifier), thread execution priority, and the CPU ID of the CPU on which the thread is running. It also provides a hook interface, allowing the slave process to register the thread with the main process based on the obtained information. After thread registration, the main process can obtain the thread's execution information and the CPU usage information of the running thread.
[0080] Specifically, the thread execution information mentioned above may include the user-mode execution time (utime) and kernel-mode execution time (stime) of the thread. The CPU usage information mentioned above may include the duration of user-mode CPU usage, the duration of user-mode CPU usage used for nice-weighted process allocation, the duration of system-mode CPU usage, CPU idle time, CPU wait time for disk writes to complete, the duration consumed by hard interrupts, the duration consumed by soft interrupts, the time spent running other operating systems in the virtual environment, and the time spent by the operating system running virtual CPUs. All durations included in the thread execution information and CPU usage information can be cumulative durations from the start of the statistics.
[0081] In addition, the various durations included in the thread running information and CPU usage information can all be represented in the form of tick counts. A tick is the smallest time slice for process scheduling in the operating system. The duration of a tick varies in different operating systems, often ranging from 1ms to 10ms.
[0082] In one embodiment of the present invention, the device can continuously write CPU usage information to a preset CPU information file according to a first write cycle. The CPU information file records the CPU usage information of each CPU installed in the device. The main process can then read the CPU information file to obtain the CPU usage information of the CPUs. For example, if the operating system configured for the device is Linux, the CPU information file can be a proc / stat file.
[0083] Specifically, the first write cycle can be the same as the operating system's clock cycle, or it can be any other cycle. The duration of the clock cycle often varies depending on the operating system configured on the device; for example, the duration of the clock cycle can be 3 seconds, 5 seconds, etc.
[0084] In another embodiment of the present invention, the device can continuously write thread execution information to a preset thread information file according to a second write cycle. The thread information file records the thread execution information of each thread executed by each CPU installed on the device. The main process can then read the thread information file to obtain the thread execution information. For example, if the operating system configured on the device is Linux, the thread information file is also a proc / stat file.
[0085] Specifically, the second write cycle can be the same as the operating system's clock cycle, or it can be any other cycle.
[0086] In addition, the aforementioned devices often perform thread scheduling based on the clock cycle of the configured operating system. Thread scheduling will not occur within a clock cycle, meaning that the thread running information and CPU usage information will not change within a clock cycle. Therefore, the aforementioned main process can obtain CPU usage information and thread running information once every clock cycle.
[0087] Furthermore, the device may contain multiple CPUs, each capable of running multiple threads. For each CPU's main process, the solution provided in this embodiment can be used to detect dead loop threads running on that CPU. This requires the main process to acquire a large amount of thread execution information for subsequent detection and processing, and it also requires processing a significant amount of data. To reduce the amount of data the main process needs to process, some threads on the CPU with a higher probability of dead loops can be pre-selected as critical threads. The main process only monitors these critical threads, acquires their execution information, and performs further dead loop detection only on these critical threads, thereby reducing the amount of data processed by the main process.
[0088] Furthermore, when a device has multiple CPUs installed, it can allocate a CPU to a thread, and the allocated CPU will run that thread. Therefore, for a given thread, the CPU running that thread is not fixed, making it difficult for the main process to determine which CPU the thread it needs to monitor is running on, and thus difficult to obtain thread execution information. To address this, thread affinity can be configured, that is, assigning a fixed CPU to each thread so that the main process can obtain thread execution information.
[0089] S102: Based on the CPU usage information above, calculate the utilization level of the CPU computing resources.
[0090] Specifically, the CPU consumes computing resources during data processing. The longer the CPU spends processing data per unit of time, the higher the utilization of CPU computing resources. Therefore, based on CPU usage information, the duration of CPU data processing per unit of time can be statistically analyzed, and the ratio between the statistically analyzed duration and the unit time can be calculated as the utilization level of CPU computing resources.
[0091] As the CPU runs, the computing resources consumed by the processes executing within it constantly change, meaning the utilization of CPU computing resources also fluctuates. To ensure that the calculated utilization accurately reflects the current state of CPU resource usage, the unit duration mentioned above can be relatively small. The ratio of the CPU's data processing time within the unit duration prior to the current moment to the current unit duration is used to represent the current CPU resource utilization. For example, the unit duration could be 10ms, 20ms, etc.
[0092] In one embodiment of the present invention, step S102 can be implemented by steps A-B as shown below, which will not be described in detail here.
[0093] S103: If the above usage level reaches a preset level, then based on the above thread running information, determine the thread with the highest CPU usage as the thread to be detected.
[0094] Specifically, if a thread running on the CPU is in an infinite loop, that thread will be executed repeatedly, consuming a large amount of CPU computing resources. This leads to high CPU resource utilization. Therefore, if CPU resource utilization is high, further detection of infinite loop threads is necessary. Conversely, if CPU resource utilization is low, it indicates a low probability of an infinite loop thread, and subsequent steps can be discontinued, terminating the process.
[0095] Furthermore, a thread's CPU usage refers to the extent to which that thread consumes CPU computing resources. A higher CPU usage level indicates that the thread consumes more CPU computing resources. If any of the aforementioned CPU threads are in an infinite loop, this thread will be executed repeatedly and will typically have the highest CPU usage. Therefore, the thread with the highest CPU usage can be selected as the thread to be further investigated.
[0096] In one embodiment of the present invention, the thread to be detected can be determined by the following step C.
[0097] Step C: If the above usage level always reaches the preset level within the third preset time period, then based on the above thread running information, determine the thread with the highest CPU usage as the thread to be detected.
[0098] Specifically, some threads may consume a significant amount of CPU resources even without entering an infinite loop. However, after a period of time, once these threads finish executing, the CPU usage will decrease, and they will not occupy a large amount of CPU resources for an extended period. But threads that enter an infinite loop will occupy a large amount of CPU resources for a prolonged period, resulting in consistently high CPU usage.
[0099] Therefore, this embodiment only considers a potential infinite loop among the CPU's running threads if the usage level consistently reaches a preset level within a third preset time period, and only then will it continue to identify the thread to be detected and proceed with the subsequent detection process. This prevents normally running threads from consuming excessive CPU computing resources in a short period, thus avoiding the waste of computing resources caused by triggering the infinite loop detection process.
[0100] In one embodiment of the present invention, the thread to be detected can be determined by steps D-G below, which will not be described in detail here.
[0101] S104: Adjust the execution priority of the preset test thread from the lowest priority to the target priority.
[0102] The test thread and the thread under test belong to the same target process. The target process has a lower priority than the execution priority of the thread under test, and the difference between the test thread and the execution priority of the thread under test is a preset difference.
[0103] Specifically, before adjusting the execution priority of the test thread, the execution priority of the test thread is the lowest among the threads in the target process. If the CPU usage does not reach the preset level, the test thread is unlikely to be executed. Therefore, the test thread will not occupy CPU computing resources in most cases, and will not affect the operation of other threads.
[0104] Furthermore, since the target priority is lower than the execution priority of the thread under test, if the thread under test does not enter an infinite loop, theoretically the CPU can schedule the threads and execute the thread under test and the test thread simultaneously. If the thread under test enters an infinite loop, it will consume a large amount of CPU computing resources, making it difficult for the test thread to be executed. However, if the difference between the target priority and the execution priority of the thread under test is too large, even if the thread under test does not enter an infinite loop, the CPU will prioritize executing other threads with a smaller difference in execution priority from the thread under test, and the test thread may still be difficult to execute, making it difficult to distinguish whether the thread under test has entered an infinite loop based on the execution status of the test thread. Therefore, the aforementioned preset difference can be set to a small value. For example, a preset difference of 1 would adjust the execution priority of the test thread to the target priority, making the execution priority of the test thread second only to the thread under test.
[0105] S105: Obtain the runtime of the above test thread within the first preset duration.
[0106] Specifically, after adjusting the priority of the test thread to the first preset duration of the target priority, the thread running information of the test thread can be obtained, and the runtime of the test thread within the first preset duration can be determined based on the thread running information.
[0107] Furthermore, since the execution priority of the thread under test is higher than that of the test thread, the CPU will prioritize executing the thread under test. If the thread under test enters an infinite loop, the CPU will have difficulty executing the test thread, resulting in a shorter runtime for the obtained test thread. Additionally, if the aforementioned first preset duration is too short, even if the thread under test does not enter an infinite loop, the CPU may still not execute the test thread within a short period, resulting in a similarly short runtime for the obtained test thread, making it difficult to distinguish whether the thread under test has malfunctioned based on runtime. Therefore, the aforementioned first preset duration can be set to a larger value to ensure that the runtime is sufficient to detect whether the thread under test has malfunctioned.
[0108] For example, the first preset duration can be 10 minutes, 15 minutes, etc.
[0109] S106: If the above runtime is less than the second preset runtime, then it is determined that the above thread to be detected has entered an infinite loop.
[0110] If the above runtime is less than the second preset runtime, it means that the runtime of the test thread within the first preset runtime is short. In other words, the CPU mainly executes the thread under test within the first preset runtime, and the thread under test occupies the CPU's computing resources for a long time. Therefore, it can be determined that the above thread under test has entered an infinite loop.
[0111] As seen above, if the CPU's computing resource usage reaches a preset level, it indicates that the CPU's computing resources are being used extensively. There may be threads within the CPU that are consuming significant computing resources due to infinite loops. Therefore, it's possible to begin detecting infinite loops in the threads running on the CPU. If a thread is in an infinite loop, it will be executed repeatedly, often consuming the highest amount of CPU resources. Thus, the thread with the highest resource consumption can be selected as the thread to be tested. Furthermore, both the thread to be tested and the test thread belong to the target process. After starting the test thread, the execution priority of the test thread is adjusted to be lower than that of the thread to be tested, with the difference between their priorities set to a preset target priority. If the thread to be tested is in an infinite loop and consuming significant computing resources, the test thread will often not run after the first preset duration. Therefore, if the test thread's runtime is less than the second preset duration, it can be considered that the test thread is in an infinite loop. Otherwise, if the thread under test does not enter an infinite loop, after the first preset time period, the CPU will schedule a test thread with a priority close to that of the thread under test. Therefore, if the runtime of the test thread is not less than the second preset time period, it can be considered that the test thread has not entered an infinite loop. Thus, through this embodiment of the invention, it is possible to determine whether a thread has entered an infinite loop without manual intervention, thereby improving the efficiency of detecting infinite loop threads.
[0112] In addition, the test thread originally has the lowest execution priority among the threads contained in the target process. Therefore, in most cases, the test thread will not be executed and will not occupy CPU computing resources in most cases, thus not affecting the operation of other threads.
[0113] In one embodiment of the present invention, the CPU usage level can be determined through the following steps A-B.
[0114] Step A: Based on the CPU runtime, CPU wait time and CPU idle time contained in the above CPU usage information, calculate the first total usage time of the CPU within the first preset time period.
[0115] The CPU runtime mentioned above can be the sum of the user-mode CPU usage time, the user-mode CPU usage time allocated for nice weighting processes, the system-mode CPU usage time, the time consumed by hard interrupts, the time consumed by soft interrupts, the time spent running other operating systems in the virtual environment, and the time spent running virtual CPUs in the operating system, all contained in the CPU usage information.
[0116] CPU wait time can be the duration the CPU waits for disk writes to complete, as contained in the CPU usage information.
[0117] Specifically, the CPU is used regardless of whether it is in a running state, a waiting state, or an idle state. Therefore, the durations of each item contained in the CPU usage information can be added together, that is, the CPU running time, the CPU waiting time, and the CPU idle time are added together to obtain the first total usage time.
[0118] Step B: Calculate the ratio between the CPU runtime and the total first usage time to represent the utilization level of CPU computing resources.
[0119] Specifically, the CPU does not process data and does not consume CPU computing resources when it is in an idle or waiting state. It only consumes computing resources when the CPU is running. The longer the CPU runs, the more computing resources it consumes. The ratio between the CPU runtime and the total usage time can be calculated to represent the degree of CPU computing resource utilization.
[0120] In another embodiment of the present invention, the thread to be detected can be determined by the following steps D-G.
[0121] Step D: Based on the above thread running information, calculate the thread runtime of each thread running on the above CPU within the second preset time period.
[0122] Specifically, the thread execution information of each thread at the start and end times of the second preset time period can be obtained separately. For each thread, the cumulative user-mode execution time and kernel-mode execution time at the start time are obtained from the thread execution information. The user-mode execution time and kernel-mode execution time are added together to obtain the first cumulative execution time of the thread at the start time. Similarly, the cumulative user-mode execution time and kernel-mode execution time at the end time are obtained and added together to obtain the second cumulative execution time of the thread at the end time. The difference between the second and first execution times is calculated to obtain the thread runtime within the second preset time period.
[0123] Step E: Based on the CPU usage information above, calculate the second total usage time of the CPU within the second preset time period.
[0124] Specifically, the total CPU usage time at the start of the second preset duration and the total CPU usage time at the end of the second preset duration can be calculated separately, and the difference between the two can be used as the second total usage time.
[0125] The method for calculating the total CPU usage time can be found in steps A-B above, and will not be repeated here.
[0126] Step F: Calculate the ratio between the runtime of each thread and the total usage time mentioned above, as the CPU usage level of each thread.
[0127] Specifically, the higher the CPU usage of a thread, the longer the CPU needs to run that thread; that is, the higher the proportion of the total CPU usage time dedicated to running that thread. Therefore, the ratio of each thread's runtime to the total CPU usage time can be calculated to represent the CPU usage of each thread.
[0128] Step G: Select the thread with the highest resource usage as the thread to be tested.
[0129] See Figure 2 This is a flowchart illustrating the second thread dead loop detection method provided in this embodiment of the invention, which is consistent with the aforementioned... Figure 1 Compared to the illustrated embodiment, after step S106, the following steps S107-S108 are also included.
[0130] S107: Control the above-mentioned thread to be detected to be suspended.
[0131] Specifically, if the thread to be monitored is located in the main process, the main process can directly suspend the thread. If the thread to be monitored is located in a slave process, the main process can send a thread suspension command to the slave thread, and the slave thread can control the suspension of the thread to be monitored after receiving the thread suspension command. After the thread to be monitored is suspended, it will not be executed, thereby releasing the computing resources occupied by the thread to be monitored that is in an infinite loop, allowing other threads to continue to run normally.
[0132] In addition, after suspending the thread to be tested, the information contained in the task stack of the thread to be tested can be recorded. The above information can be recorded in the log and saved to the disk. The above information can include the task name corresponding to the thread to be tested, the position of the program execution corresponding to the thread to be tested, etc. In most cases, the above position is the location of the program in the program corresponding to the thread to be tested that has an error that caused the thread to be tested to enter an infinite loop.
[0133] Furthermore, after suspending the thread under test, an alarm message can be generated. This alarm message includes the task name of the task being tested and the thread's tid. The main process can control the device to directly display the alarm message or send it to a remote control device to inform administrators that the thread under test has entered an infinite loop.
[0134] S108: If the management thread used to manage the device where the CPU is located is running on the CPU, and the execution priority of the management thread is lower than the execution priority of the thread to be detected, record the information contained in the task stack of the thread to be detected, control the reset of the device, and control the CPU to rerun the thread to be detected based on the recorded information.
[0135] Specifically, if the management thread and the thread under test run on the same CPU, and the management thread has a lower execution priority than the thread under test, an infinite loop in the thread under test will affect the normal operation of the management thread, making it difficult for users to manage the device through the management thread, causing the device to enter a managed state. This is especially true if the device is a large device such as a base station, which staff often need to manage remotely. If the management thread malfunctions, it will make it difficult for staff to control the large device. After suspending the thread under test, in order to re-execute the management thread, the device can be reset, and the thread under test can be run based on the recorded information, without executing the program that caused the infinite loop, thus preventing the thread under test from looping again after the device is reset and re-executed.
[0136] In addition, if the thread to be detected and the management thread do not belong to the same CPU, or if the management thread and the thread to be detected run on the same CPU but the execution priority of the management thread is higher than that of the thread to be detected, then the infinite loop of the thread to be detected will not affect the operation of the management thread. Therefore, it is not necessary to reset the device after suspending the thread to be detected.
[0137] As can be seen from the above, after determining that the thread under test has entered an infinite loop, in order to prevent the thread under test from continuing to occupy a large amount of CPU computing resources, the main process can control the thread under test to be suspended, thereby releasing the CPU computing resources occupied by the thread under test, allowing the CPU to continue executing other threads normally. Furthermore, if the aforementioned management thread and the thread under test run on the same CPU, and the execution priority of the management thread is lower than that of the thread under test, then suspending the thread under test that is affecting the management thread can reset the aforementioned device, allowing the management thread to be executed normally again. This enables the user to manage the aforementioned device through the management thread, preventing the device from entering a managed state.
[0138] Corresponding to the aforementioned thread dead loop detection method, this embodiment of the invention also provides a thread dead loop detection device.
[0139] See Figure 3 The diagram below illustrates the structure of a thread dead loop detection device according to an embodiment of the present invention, including a memory 301, a transceiver 302, and a processor 303.
[0140] Memory 301 is used to store computer programs; transceiver 302 is used to send and receive data under the control of the processor; processor 303 is used to read the computer programs in the memory and perform the following operations:
[0141] Obtain CPU usage information of the CPU and thread execution information of the threads running on the CPU;
[0142] Based on the CPU usage information, calculate the utilization level of the CPU computing resources;
[0143] If the usage level reaches a preset level, then based on the thread running information, the thread with the highest CPU usage is identified as the thread to be detected.
[0144] The execution priority of the preset test thread is adjusted from the lowest priority to the target priority. The test thread and the thread to be tested belong to the same target process. The target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference.
[0145] Obtain the runtime of the test thread within the first preset time period;
[0146] If the runtime is less than the second preset runtime, then the thread to be detected is determined to be in an infinite loop.
[0147] As seen above, if the CPU's computing resource usage reaches a preset level, it indicates that the CPU's computing resources are being used extensively. There may be threads within the CPU that are consuming significant computing resources due to infinite loops. Therefore, it's possible to begin detecting infinite loops in the threads running on the CPU. If a thread is in an infinite loop, it will be executed repeatedly, often consuming the highest amount of CPU resources. Thus, the thread with the highest resource consumption can be selected as the thread to be tested. Furthermore, both the thread to be tested and the test thread belong to the target process. After starting the test thread, the execution priority of the test thread is adjusted to be lower than that of the thread to be tested, with the difference between their priorities set to a preset target priority. If the thread to be tested is in an infinite loop and consuming significant computing resources, the test thread will often not run after the first preset duration. Therefore, if the test thread's runtime is less than the second preset duration, it can be considered that the test thread is in an infinite loop. Otherwise, if the thread under test does not enter an infinite loop, after the first preset time period, the CPU will schedule a test thread with a priority close to that of the thread under test. Therefore, if the runtime of the test thread is not less than the second preset time period, it can be considered that the test thread has not entered an infinite loop. Thus, through this embodiment of the invention, it is possible to determine whether a thread has entered an infinite loop without manual intervention, thereby improving the efficiency of detecting infinite loop threads.
[0148] In addition, the test thread originally has the lowest execution priority among the threads contained in the target process. Therefore, in most cases, the test thread will not be executed and will not occupy CPU computing resources in most cases, thus not affecting the operation of other threads.
[0149] In one embodiment of the present invention, after determining that the thread to be detected has entered an infinite loop, the method further includes:
[0150] The thread to be detected is suspended.
[0151] If the management thread for managing the device where the CPU is located is running on the CPU, and the execution priority of the management thread is lower than the execution priority of the thread to be detected, then the information contained in the task stack of the thread to be detected is recorded, the device is reset, and the CPU is controlled to rerun the thread to be detected based on the recorded information.
[0152] As can be seen from the above, after determining that the thread under test has entered an infinite loop, in order to prevent the thread under test from continuing to occupy a large amount of CPU computing resources, the main process can control the thread under test to be suspended, thereby releasing the CPU computing resources occupied by the thread under test, allowing the CPU to continue executing other threads normally. Furthermore, if the aforementioned management thread and the thread under test run on the same CPU, and the execution priority of the management thread is lower than that of the thread under test, then suspending the thread under test that is affecting the management thread can reset the aforementioned device, allowing the management thread to be executed normally again. This enables the user to manage the aforementioned device through the management thread, preventing the device from entering a managed state.
[0153] In one embodiment of the present invention, calculating the utilization level of the CPU computing resources based on the CPU usage information specifically includes:
[0154] Based on the CPU runtime, CPU wait time and CPU idle time contained in the CPU usage information, the first total usage time of the CPU within the first preset time period is calculated.
[0155] The ratio between the CPU runtime and the first total usage time is calculated to represent the utilization level of CPU computing resources.
[0156] In one embodiment of the present invention, determining the thread with the highest CPU usage based on the thread execution information as the thread to be detected specifically includes:
[0157] Based on the thread running information, calculate the thread runtime of each thread running on the CPU within the second preset time period;
[0158] Based on the CPU usage information, calculate the second total CPU usage time within the second preset time period;
[0159] Calculate the ratio between the thread runtime of each thread and the second total usage time, and use it as the CPU usage level of each thread;
[0160] Select the thread with the highest usage as the thread to be tested.
[0161] Corresponding to the aforementioned thread dead loop detection method, this embodiment of the invention also provides a thread dead loop detection device.
[0162] See Figure 4 This is a schematic diagram of the structure of a first type of thread dead loop detection device provided in an embodiment of the present invention. The device includes:
[0163] The information acquisition module 401 is used to acquire CPU usage information of the CPU and thread execution information of the threads running on the CPU.
[0164] The degree calculation module 402 is used to calculate the degree of CPU computing resource utilization based on the CPU usage information;
[0165] The thread determination module 403 is used to determine the thread with the highest CPU usage as the thread to be detected based on the thread running information if the usage level reaches a preset level.
[0166] The priority adjustment module 404 is used to adjust the execution priority of the preset test thread from the lowest priority to the target priority, wherein the test thread and the thread to be tested belong to the same target process, the target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference.
[0167] The duration acquisition module 405 is used to acquire the runtime of the test thread within a first preset duration;
[0168] The dead loop determination module 406 is used to determine that the thread to be detected has entered a dead loop if the runtime is less than a second preset duration.
[0169] As seen above, if the CPU's computing resource usage reaches a preset level, it indicates that the CPU's computing resources are being used extensively. There may be threads within the CPU that are consuming significant computing resources due to infinite loops. Therefore, it's possible to begin detecting infinite loops in the threads running on the CPU. If a thread is in an infinite loop, it will be executed repeatedly, often consuming the highest amount of CPU resources. Thus, the thread with the highest resource consumption can be selected as the thread to be tested. Furthermore, both the thread to be tested and the test thread belong to the target process. After starting the test thread, the execution priority of the test thread is adjusted to be lower than that of the thread to be tested, with the difference between their priorities set to a preset target priority. If the thread to be tested is in an infinite loop and consuming significant computing resources, the test thread will often not run after the first preset duration. Therefore, if the test thread's runtime is less than the second preset duration, it can be considered that the test thread is in an infinite loop. Otherwise, if the thread under test does not enter an infinite loop, after the first preset time period, the CPU will schedule a test thread with a priority close to that of the thread under test. Therefore, if the runtime of the test thread is not less than the second preset time period, it can be considered that the test thread has not entered an infinite loop. Thus, through this embodiment of the invention, it is possible to determine whether a thread has entered an infinite loop without manual intervention, thereby improving the efficiency of detecting infinite loop threads.
[0170] In addition, the test thread originally has the lowest execution priority among the threads contained in the target process. Therefore, in most cases, the test thread will not be executed and will not occupy CPU computing resources in most cases, thus not affecting the operation of other threads.
[0171] See Figure 5 This is a schematic diagram of the structure of the second type of thread dead loop detection device provided in the embodiments of the present invention, which is consistent with the aforementioned Figure 4 Compared to the illustrated embodiment, the above-described apparatus further includes:
[0172] The thread suspension module 407 is used to control the suspension of the thread to be detected.
[0173] The device reset module 408 is used to record the information contained in the task stack of the thread under test if the management thread for managing the device where the CPU is located is running on the CPU and the execution priority of the management thread is lower than the execution priority of the thread under test, and to control the device to be reset, and to control the CPU to rerun the thread under test based on the recorded information.
[0174] As can be seen from the above, after determining that the thread under test has entered an infinite loop, in order to prevent the thread under test from continuing to occupy a large amount of CPU computing resources, the main process can control the thread under test to be suspended, thereby releasing the CPU computing resources occupied by the thread under test, allowing the CPU to continue executing other threads normally. Furthermore, if the aforementioned management thread and the thread under test run on the same CPU, and the execution priority of the management thread is lower than that of the thread under test, then suspending the thread under test that is affecting the management thread can reset the aforementioned device, allowing the management thread to be executed normally again. This enables the user to manage the aforementioned device through the management thread, preventing the device from entering a managed state.
[0175] In one embodiment of the present invention, the degree calculation module 402 is specifically used for:
[0176] Based on the CPU runtime, CPU wait time and CPU idle time contained in the CPU usage information, the first total usage time of the CPU within the first preset time period is calculated.
[0177] The ratio between the CPU runtime and the first total usage time is calculated to represent the utilization level of CPU computing resources.
[0178] In one embodiment of the present invention, the thread determination module 403 is specifically used for:
[0179] Based on the thread running information, calculate the thread runtime of each thread running on the CPU within the second preset time period;
[0180] Based on the CPU usage information, calculate the second total CPU usage time within the second preset time period;
[0181] Calculate the ratio between the thread runtime of each thread and the second total usage time, and use it as the CPU usage level of each thread;
[0182] Select the thread with the highest usage as the thread to be tested.
[0183] In another embodiment of the present invention, a computer-readable storage medium is also provided, which stores a computer program that, when executed by a processor, implements the steps of any of the above-described thread dead loop detection methods.
[0184] When detecting thread infinite loops using the computer-readable storage medium provided in this embodiment of the invention, if the CPU computing resource usage reaches a preset level, it indicates that the CPU's computing resources are being used extensively, and there may be threads in the CPU that are consuming a large amount of computing resources due to infinite loops. Therefore, the detection of thread infinite loops can begin. If a thread is in an infinite loop, it will be executed repeatedly, and its CPU computing resource usage will often be the highest. Therefore, the thread with the highest usage can be selected as the thread to be detected. Furthermore, both the thread to be detected and the test thread belong to the target process. After starting the detection of the thread to be detected, the execution priority of the test thread is adjusted to be lower than the execution priority of the thread to be detected, and the difference between their execution priorities is a preset difference target priority. If the thread to be detected is in an infinite loop and consumes a large amount of computing resources, the test thread will often not be executed after a first preset duration. Therefore, if the runtime of the test thread is less than a second preset duration, it can be considered that the test thread is in an infinite loop. Otherwise, if the thread under test does not enter an infinite loop, after the first preset time period, the CPU will schedule a test thread with a priority close to that of the thread under test. Therefore, if the runtime of the test thread is not less than the second preset time period, it can be considered that the test thread has not entered an infinite loop. Thus, through this embodiment of the invention, it is possible to determine whether a thread has entered an infinite loop without manual intervention, thereby improving the efficiency of detecting infinite loop threads.
[0185] In addition, the test thread originally has the lowest execution priority among the threads contained in the target process. Therefore, in most cases, the test thread will not be executed and will not occupy CPU computing resources in most cases, thus not affecting the operation of other threads.
[0186] In another embodiment of the present invention, a computer program product containing instructions is also provided, which, when run on a computer, causes the computer to execute any of the thread dead loop detection methods described above.
[0187] When detecting thread dead loops using the computer program product provided in this embodiment of the invention, if the CPU computing resource usage reaches a preset level, it indicates that the CPU's computing resources are being used extensively, and there may be threads in the CPU that are consuming a large amount of computing resources due to dead loops. Therefore, the detection of thread dead loops can begin. If a thread is in a dead loop, it will be executed repeatedly, and its CPU computing resource usage will often be the highest. Therefore, the thread with the highest usage can be selected as the thread to be detected. Furthermore, both the thread to be detected and the test thread belong to the target process. After starting the detection of the thread to be detected, the execution priority of the test thread is adjusted to be lower than the execution priority of the thread to be detected, and the difference between their execution priorities is a preset difference target priority. If the thread to be detected is in a dead loop and consuming a large amount of computing resources, the test thread will often not be executed after a first preset duration. Therefore, if the runtime of the test thread is less than a second preset duration, it can be considered that the test thread is in a dead loop. Otherwise, if the thread under test does not enter an infinite loop, after the first preset time period, the CPU will schedule a test thread with a priority close to that of the thread under test. Therefore, if the runtime of the test thread is not less than the second preset time period, it can be considered that the test thread has not entered an infinite loop. Thus, through this embodiment of the invention, it is possible to determine whether a thread has entered an infinite loop without manual intervention, thereby improving the efficiency of detecting infinite loop threads.
[0188] In addition, the test thread originally has the lowest execution priority among the threads contained in the target process. Therefore, in most cases, the test thread will not be executed and will not occupy CPU computing resources in most cases, thus not affecting the operation of other threads.
[0189] In the above embodiments, implementation can be achieved entirely or partially through software, hardware, firmware, or any combination thereof. When implemented using software, it can be implemented entirely or partially in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of the present invention are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another website, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that integrates one or more available media. The available medium can be a magnetic medium (e.g., floppy disk, hard disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., solid state disk (SSD)).
[0190] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such a process, method, article, or apparatus. Without further limitations, an element defined by the phrase "comprising one..." does not exclude the presence of other identical elements in the process, method, article, or apparatus that includes said element.
[0191] The various embodiments in this specification are described in a related manner. Similar or identical parts between embodiments can be referred to mutually. Each embodiment focuses on describing the differences from other embodiments. In particular, the embodiments for devices, apparatuses, storage media, and computer programs are basically similar to the method embodiments, and therefore the descriptions are relatively simple; relevant parts can be referred to the descriptions of the method embodiments.
[0192] Those skilled in the art will understand that embodiments of this application can be provided as methods, systems, or computer program products. Therefore, this application can take the form of a completely hardware embodiment, a completely software embodiment, or an embodiment combining software and hardware aspects. Furthermore, this application can take the form of a computer program product implemented on one or more computer-usable storage media (including, but not limited to, disk storage and optical storage) containing computer-usable program code.
[0193] This application is described with reference to flowchart illustrations and / or block diagrams of methods, apparatus (systems), and computer program products according to embodiments of this application. It will be understood that each block of the flowchart illustrations and / or block diagrams, and combinations of blocks in the flowchart illustrations and / or block diagrams, can be implemented by computer-executable instructions. These computer-executable instructions can be provided to a processor of a general-purpose computer, special-purpose computer, embedded processor, or other programmable data processing apparatus to produce a machine, such that the instructions, which execute via the processor of the computer or other programmable data processing apparatus, generate instructions for implementing the flowchart. Figure 1 One or more processes and / or boxes Figure 1 A device that provides the functions specified in one or more boxes.
[0194] These processor-executable instructions may also be stored in a processor-readable memory that can direct a computer or other programmable data processing device to function in a particular manner, such that the instructions stored in the processor-readable memory produce an article of manufacture including instruction means, which are implemented in a process Figure 1 One or more processes and / or boxes Figure 1 The function specified in one or more boxes.
[0195] These processors can execute instructions that can also be loaded onto a computer or other programmable data processing device, causing a series of operational steps to be performed on the computer or other programmable device to produce a computer-implemented process, thereby providing instructions that execute on the computer or other programmable device for implementing the process. Figure 1 One or more processes and / or boxes Figure 1 The steps of the function specified in one or more boxes.
[0196] Obviously, those skilled in the art can make various modifications and variations to this application without departing from the spirit and scope of this application. Therefore, if these modifications and variations of this application fall within the scope of the embodiments of this application and their equivalents, this application also intends to include these modifications and variations.
Claims
1. A method for detecting thread dead loops, characterized in that, The method includes: Obtain CPU usage information of the CPU and thread execution information of the threads running on the CPU; Based on the CPU usage information, calculate the utilization level of the CPU computing resources; If the usage level reaches a preset level, then based on the thread running information, the thread with the highest CPU usage is identified as the thread to be detected. The execution priority of the preset test thread is adjusted from the lowest priority to the target priority. The test thread and the thread to be tested belong to the same target process. The target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference. Obtain the runtime of the test thread within the first preset time period; If the runtime is less than the second preset runtime, then the thread to be detected is determined to be in an infinite loop.
2. The method according to claim 1, characterized in that, After determining that the thread to be detected has entered an infinite loop, the method further includes: The thread to be detected is suspended. If the management thread for managing the device where the CPU is located is running on the CPU, and the execution priority of the management thread is lower than the execution priority of the thread to be detected, then the information contained in the task stack of the thread to be detected is recorded, the device is reset, and the CPU is controlled to rerun the thread to be detected based on the recorded information.
3. The method according to claim 1 or 2, characterized in that, The step of calculating the utilization level of CPU computing resources based on the CPU usage information includes: Based on the CPU runtime, CPU wait time and CPU idle time contained in the CPU usage information, the first total usage time of the CPU within the first preset time period is calculated. The ratio between the CPU runtime and the first total usage time is calculated to represent the utilization level of CPU computing resources.
4. The method according to claim 1 or 2, characterized in that, The step of determining the thread with the highest CPU usage based on the thread execution information as the thread to be detected includes: Based on the thread running information, calculate the thread runtime of each thread running on the CPU within the second preset time period; Based on the CPU usage information, calculate the second total CPU usage time within the second preset time period; Calculate the ratio between the thread runtime of each thread and the second total usage time, and use it as the CPU usage level of each thread; Select the thread with the highest usage as the thread to be tested.
5. A thread infinite loop detection device, characterized in that, Includes memory, transceiver, and processor: A memory for storing computer programs; a transceiver for sending and receiving data under the control of the processor; and a processor for reading the computer programs from the memory and performing the following operations: Obtain CPU usage information of the CPU and thread execution information of the threads running on the CPU; Based on the CPU usage information, calculate the utilization level of the CPU computing resources; If the usage level reaches a preset level, then based on the thread running information, the thread with the highest CPU usage is identified as the thread to be detected. The execution priority of the preset test thread is adjusted from the lowest priority to the target priority. The test thread and the thread to be tested belong to the same target process. The target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference. Obtain the runtime of the test thread within the first preset time period; If the runtime is less than the second preset runtime, then the thread to be detected is determined to be in an infinite loop.
6. The device according to claim 5, characterized in that, After determining that the thread to be detected has entered an infinite loop, the method further includes: The thread to be detected is suspended. If the management thread for managing the device where the CPU is located is running on the CPU, and the execution priority of the management thread is lower than the execution priority of the thread to be detected, then the information contained in the task stack of the thread to be detected is recorded, the device is reset, and the CPU is controlled to rerun the thread to be detected based on the recorded information.
7. The device according to claim 5 or 6, characterized in that, The calculation of the CPU computing resource utilization based on the CPU usage information specifically includes: Based on the CPU runtime, CPU wait time and CPU idle time contained in the CPU usage information, the first total usage time of the CPU within the first preset time period is calculated. The ratio between the CPU runtime and the first total usage time is calculated to represent the utilization level of CPU computing resources.
8. The device according to claim 5 or 6, characterized in that, The step of determining the thread with the highest CPU usage based on the thread execution information as the thread to be detected specifically includes: Based on the thread running information, calculate the thread runtime of each thread running on the CPU within the second preset time period; Based on the CPU usage information, calculate the second total CPU usage time within the second preset time period; Calculate the ratio between the thread runtime of each thread and the second total usage time, and use it as the CPU usage level of each thread; Select the thread with the highest usage as the thread to be tested.
9. A thread infinite loop detection device, characterized in that, The device includes: The information acquisition module is used to acquire CPU usage information of the CPU and thread execution information of the threads running on the CPU. The degree calculation module is used to calculate the degree of CPU computing resource utilization based on the CPU usage information. The thread determination module is used to determine the thread with the highest CPU usage as the thread to be detected based on the thread running information if the usage level reaches a preset level. The priority adjustment module is used to adjust the execution priority of a preset test thread from the lowest priority to the target priority. The test thread and the thread to be tested belong to the same target process. The target priority is lower than the execution priority of the thread to be tested, and the difference between the target priority and the execution priority of the thread to be tested is a preset difference. The duration acquisition module is used to acquire the runtime of the test thread within a first preset duration. The dead loop determination module is used to determine that the thread to be detected is in a dead loop if the runtime is less than a second preset duration.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the steps of the method described in any one of claims 1-4.