CPU utilization rate calculation method and system, storage medium and electronic equipment

By using accumulating counters and timers in FreeRTOS, the CPU occupancy data of the target task is obtained in real time, which solves the problem of not being able to determine the peak CPU occupancy value and achieves more efficient resource scheduling and utilization.

CN119512858APending Publication Date: 2025-02-25JIANGLING MOTORS
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202411518754.6
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-10-29
Publication Date
2025-02-25

AI Technical Summary

Technical Problem

The peak CPU occupancy rate of a specific task cannot be determined in the existing FreeRTOS, which makes it difficult for task scheduling to provide an effective reference and affects the effective utilization of system resources.

Method used

By obtaining the initial CPU occupancy data and using the accumulation counter and timer of the idle task, the CPU occupancy data of the target task is obtained in real time to determine the peak CPU occupancy value of the target task.

Benefits of technology

It realizes accurate determination of the peak CPU occupancy rate of the target task, provides effective resource scheduling reference, and improves the utilization efficiency of system resources.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119512858A_ABST
    Figure CN119512858A_ABST
Patent Text Reader

Abstract

The invention provides a CPU utilization rate calculation method and system, a storage medium and electronic equipment, and the method comprises the steps: obtaining initial CPU occupancy rate data of a system in an initial state, judging whether a target task is operated or not, and if the target task is operated, judging whether an initial value of an accumulation counter corresponding to an idle task is a preset value or not; if the initial value of the accumulation counter is the preset value, starting a timer, enabling the accumulation counter to carry out accumulation and counting, and judging whether the value of the timer reaches a preset time value or not in real time; and if the value of the timer reaches a preset time value, obtaining operation data of the accumulation counter, determining real-time CPU occupancy rate data of the current system according to the operation data, and determining target CPU occupancy rate data corresponding to the target task according to the real-time CPU occupancy rate data and the initial CPU occupancy rate data. According to the task scheduling method and device, the problem that in the prior art, the CPU occupancy rate peak value of a specific task cannot be determined in FreeRTOS, and then effective reference is difficult to provide for task scheduling is solved.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The present invention relates to the field of computer technology, and in particular to a CPU usage calculation method, system, storage medium and electronic device. Background Art

[0002] As a lightweight operating system, the open source embedded real-time operating system (Free Real Time Operating System, FreeRTOS) has the following functions: task management, time management, semaphores, message queues, memory management, recording functions, software timers, coroutines, etc. Using FreeRTOS can make more reasonable and effective use of CPU resources, simplify the design of application software, shorten system development time, and better ensure the real-time performance and reliability of the system.

[0003] In the operation of the system, due to the limited resources, it is usually necessary to regulate the system resources according to the CPU occupancy rate corresponding to each running task to ensure the effective use of resources and the efficient operation of each task. However, in the current FreeRTOS (Chinese name: small real-time operating system), although the statistics of the CPU occupancy rate of each task have been realized, the CPU occupancy rate is a cumulative value and cannot reflect the instantaneous CPU usage rate of the system. The processing of some specific tasks cannot feedback the peak value through the CPU occupancy rate value of the system itself, and it is difficult to accurately and maximize the effective use of system resources by referring to the cumulative value to schedule the tasks. Summary of the invention

[0004] Based on this, the purpose of the present invention is to provide a CPU usage calculation method, system, storage medium and electronic device, aiming to solve the problem that the peak CPU occupancy of a specific task cannot be determined in FreeRTOS in the prior art, and thus it is difficult to provide an effective reference for task scheduling.

[0005] A method for calculating CPU usage according to an embodiment of the present invention includes:

[0006] Get the initial CPU usage data of the system in the initial state and determine whether the target task is running;

[0007] If the target task is running, determine whether the initial value of the cumulative counter corresponding to the idle task is a preset value;

[0008] If the initial value of the cumulative counter is a preset value, start the timer to make the cumulative counter accumulate and count, and determine in real time whether the value of the timer reaches the preset time value;

[0009] If the value of the timer reaches the preset time value, the operating data of the cumulative counter is obtained, the real-time CPU occupancy data of the current system is determined according to the operating data, and the target CPU occupancy data corresponding to the target task is determined according to the real-time CPU occupancy data and the initial CPU occupancy data.

[0010] In addition, a CPU usage calculation method according to the above embodiment of the present invention may also have the following additional technical features:

[0011] Furthermore, after the step of determining whether the initial value of the cumulative counter corresponding to the idle task is a preset value, the following steps are included:

[0012] If the initial value of the cumulative counter is not a preset value, obtaining whether the value of the timer corresponding to the cumulative counter is less than a preset time value;

[0013] If not, obtain the operating data corresponding to the cumulative counter, determine the real-time CPU occupancy data of the current system according to the operating data, and determine the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data.

[0014] Furthermore, the step of obtaining the initial CPU occupancy data of the system in the initial state includes:

[0015] Initialize the system, the timer and the cumulative counter, and perform statistics on the cumulative counter for the first time when the idle function is run for the first time, obtain the running data of the cumulative counter corresponding to when the timing time of the timer reaches the preset time value for the first time, and then determine the initial CPU occupancy data.

[0016] Further, the step of determining the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data includes:

[0017] Subtract the initial CPU occupancy rate data from the real-time CPU occupancy rate data, and use the difference between the two as the ordinate and time as the abscissa to obtain a curve graph of the target CPU occupancy rate changing over time;

[0018] The target CPU occupancy rate data corresponding to the target task is determined according to the peak point and the valley point on the curve graph.

[0019] Furthermore, after the step of determining the target CPU occupancy data corresponding to the target task, the step further includes:

[0020] The running data of the cumulative counter is cleared, and the target CPU occupancy rate data is uploaded to the cloud database as the historical CPU occupancy rate data corresponding to the target task.

[0021] Further, the step of obtaining the initial CPU occupancy data of the system in the initial state includes:

[0022] The historical CPU occupancy rate data corresponding to the task to be run is obtained from the cloud database, and the resources of the system are allocated according to the historical CPU occupancy rate data.

[0023] Furthermore, after the step of determining the target CPU occupancy data corresponding to the target task, the step further includes:

[0024] The target CPU occupancy data is compared with the corresponding historical CPU occupancy data in the cloud database to determine whether the ratio of the two is greater than a preset threshold. If an over-threshold flag is generated, the target CPU occupancy data is marked so that the subsequent system operation of the target task will allocate system resources according to the over-threshold flag and the historical CPU occupancy data.

[0025] Another object of the present invention is a CPU usage calculation system, the system comprising:

[0026] The target task determination module is used to obtain the initial CPU occupancy data of the system in the initial state and determine whether the target task is running;

[0027] The cumulative counter judgment module is used to judge whether the initial value of the cumulative counter corresponding to the idle task is a preset value when the target task is running;

[0028] A timer judgment module, used for starting the timer and making the accumulative counter accumulate and count when the initial value of the accumulative counter is a preset value, and judging in real time whether the value of the timer reaches the preset time value;

[0029] The target CPU occupancy determination module is used to obtain the operating data of the cumulative counter when the timer value reaches a preset time value, determine the real-time CPU occupancy data of the current system according to the operating data, and determine the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data.

[0030] Another object of an embodiment of the present invention is to provide a storage medium having a computer program stored thereon, wherein the program, when executed by a processor, implements the steps of the above-mentioned CPU usage calculation method.

[0031] Another object of an embodiment of the present invention is to provide an electronic device, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, wherein the processor implements the steps of the above-mentioned CPU usage calculation method when executing the program.

[0032] The present invention obtains the current CPU occupancy data, i.e., the initial CPU occupancy data, when the system is just started, and then obtains the data when the target task is running through the cumulative counter corresponding to the idle task, and then obtains the CPU occupancy data when the system runs the target task in multiple preset time periods through the counting of the cumulative counter and the timing of the timer, i.e., the real-time CPU occupancy data, and then compares the real-time CPU occupancy data with the initial occupancy data, so as to determine the CPU occupancy data corresponding to the target task in multiple time periods, and then determine the peak value of the CPU occupancy of the target task, and the statistics are performed through the idle task, and do not affect the operation of important tasks of the system. Therefore, the present invention solves the problem that the peak value of the CPU occupancy of a specific task cannot be determined in FreeRTOS in the prior art, and thus it is difficult to provide an effective reference for the scheduling of tasks. BRIEF DESCRIPTION OF THE DRAWINGS

[0033] Figure 1 is a flowchart of a method for calculating CPU usage in a first embodiment of the present invention;

[0034] Figure 2 A schematic diagram of the results of the CPU usage calculation system in the second embodiment of the present invention;

[0035] Figure 3 is a schematic structural diagram of an electronic device in a third embodiment of the present invention;

[0036] The following specific implementation manner will further illustrate the present invention in conjunction with the above-mentioned drawings. DETAILED DESCRIPTION

[0037] In order to facilitate the understanding of the present invention, the present invention will be described more fully below with reference to the relevant drawings. Several embodiments of the present invention are given in the drawings. However, the present invention can be implemented in many different forms and is not limited to the embodiments described herein. On the contrary, the purpose of providing these embodiments is to make the disclosure of the present invention more thorough and comprehensive.

[0038] It should be noted that when an element is referred to as being "fixed to" another element, it may be directly on the other element or there may be a central element. When an element is considered to be "connected to" another element, it may be directly connected to the other element or there may be a central element at the same time. The terms "vertical", "horizontal", "left", "right" and similar expressions used herein are for illustrative purposes only.

[0039] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as those commonly understood by those skilled in the art of the present invention. The terms used herein in the specification of the present invention are only for the purpose of describing specific embodiments and are not intended to limit the present invention. The term "and / or" used herein includes any and all combinations of one or more related listed items.

[0040] Embodiment 1

[0041] See also Figure 1 , which shows a CPU usage calculation method in a first embodiment of the present invention, and the method specifically includes steps S01 to S03.

[0042] S01, obtaining the initial CPU occupancy data of the system in the initial state, and determining whether the target task is running;

[0043] Specifically, the step of obtaining the initial CPU occupancy data of the system in the initial state includes: initializing the system, the timer and the cumulative counter, and performing statistics on the cumulative counter for the first time when the idle function is run for the first time, obtaining the operating data of the cumulative counter corresponding to when the timing time of the timer reaches the preset time value for the first time, and then determining the initial CPU occupancy data.

[0044] S02, if the target task is running, determining whether the initial value of the cumulative counter corresponding to the idle task is a preset value;

[0045] Specifically, if the initial value of the cumulative counter is not a preset value, obtain whether the value of the timer corresponding to the cumulative counter is less than the preset time value; if not, obtain the operating data corresponding to the cumulative counter, determine the real-time CPU occupancy data of the current system according to the operating data, and determine the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data. When calculating the CPU occupancy, it is possible that the target task to be calculated is already running. Therefore, it is necessary to first determine by the value of the cumulative counter whether the target task has just been run or has been running for a period of time. If it has been running for a period of time, determine by the value of the timer whether the running time has reached the preset value. If not, maintain this state until the running time reaches the preset value, and then read the operating data of this time period, and then use it to determine the required real-time CPU occupancy.

[0046] S03, if the initial value of the cumulative counter is a preset value, start the timer and make the cumulative counter accumulate and count, and determine in real time whether the value of the timer reaches the preset time value;

[0047] S04, if the value of the timer reaches the preset time value, obtain the operating data of the cumulative counter, determine the real-time CPU occupancy data of the current system according to the operating data, and determine the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data.

[0048] Specifically, the real-time CPU occupancy data is subtracted from the initial CPU occupancy data, and the difference between the two is used as the vertical coordinate and the time is used as the horizontal coordinate to obtain a curve graph showing the change of the target CPU occupancy over time; the target CPU occupancy data corresponding to the target task is determined according to the peak points and valley points on the curve graph.

[0049] In addition, after the step of determining the target CPU occupancy data corresponding to the target task, the following step is further included:

[0050] The running data of the cumulative counter is cleared, and the target CPU occupancy rate data is uploaded to the cloud database as the historical CPU occupancy rate data corresponding to the target task.

[0051] Furthermore, after the step of determining the target CPU occupancy data corresponding to the target task, the step also includes: comparing the target CPU occupancy data with the corresponding historical CPU occupancy data in the cloud database to determine whether the ratio of the two is greater than a preset threshold value, and if an over-threshold flag is generated, marking the target CPU occupancy data so that the subsequent system operation of the target task will allocate system resources according to the over-threshold flag and the historical CPU occupancy data.

[0052] In addition, after the step of obtaining the initial CPU occupancy rate data of the system in the initial state, the step includes: obtaining the historical CPU occupancy rate data corresponding to the task to be run from the cloud database, and allocating the resources of the system according to the historical CPU occupancy rate data. By recording the historical CPU occupancy rate of each task, the system can have a good reference for resource allocation when the task is running.

[0053] In summary, the CPU usage calculation method in the above embodiment of the present invention obtains the current CPU occupancy data, i.e., the initial CPU occupancy data, when the system is just started, and then obtains the data when the target task is running through the cumulative counter corresponding to the idle task, and then obtains the CPU occupancy data when the system runs the target task in multiple preset time periods through the counting of the cumulative counter and the timing of the timer, i.e., the real-time CPU occupancy data, and then compares the real-time CPU occupancy data with the initial occupancy data to determine the CPU occupancy data corresponding to the target task in multiple time periods, and then determine the peak value of the CPU occupancy of the target task, and the statistics are performed through the idle task, which does not affect the operation of important tasks of the system. Therefore, the present invention solves the problem that the peak value of the CPU occupancy of a specific task cannot be determined in FreeRTOS in the prior art, and it is difficult to provide an effective reference for the scheduling of tasks.

[0054] Embodiment 2

[0055] See also Figure 2 , which is a structural block diagram of a CPU usage calculation system proposed in the second embodiment of the present invention, the CPU usage calculation system 200 comprises: a target task determination module 21, an accumulation counter judgment module 22, a timer judgment module 23 and a target CPU occupancy determination module 24, wherein:

[0056] The target task determination module 21 is used to obtain the initial CPU occupancy data of the system in the initial state and determine whether the target task is running;

[0057] The cumulative counter judgment module 22 is used to judge whether the initial value of the cumulative counter corresponding to the idle task is a preset value when the target task is running;

[0058] The timer judgment module 23 is used to start the timer and make the accumulative counter accumulate and count when the initial value of the accumulative counter is a preset value, and judge in real time whether the value of the timer reaches the preset time value;

[0059] The target CPU occupancy determination module 24 is used to obtain the operating data of the cumulative counter when the timer value reaches the preset time value, determine the real-time CPU occupancy data of the current system according to the operating data, and determine the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data.

[0060] Furthermore, in other embodiments of the present invention, the CPU usage calculation system 200 further includes:

[0061] A time value judgment module, used for obtaining whether the value of the timer corresponding to the cumulative counter is less than a preset time value when the initial value of the cumulative counter is not a preset value;

[0062] a target CPU occupancy calculation module, for obtaining the operation data corresponding to the cumulative counter when the value of the timer corresponding to the cumulative counter is less than a preset time value, determining the real-time CPU occupancy data of the current system according to the operation data, and determining the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data;

[0063] The data uploading module is used to clear the running data of the cumulative counter and upload the target CPU occupancy rate data to the cloud database as the historical CPU occupancy rate data corresponding to the target task.

[0064] The resource allocation module is used to obtain the historical CPU occupancy rate data corresponding to the task to be run from the cloud database, and allocate the resources of the system according to the historical CPU occupancy rate data.

[0065] A marking module is used to compare the target CPU occupancy data with the corresponding historical CPU occupancy data in the cloud database to determine whether the ratio of the two is greater than a preset threshold value. If an over-threshold mark is generated, the target CPU occupancy data is marked so that the subsequent system operation of the target task will allocate system resources according to the over-threshold mark and the historical CPU occupancy data.

[0066] Furthermore, in other embodiments of the present invention, the target task determination module 21 further includes:

[0067] The initial CPU occupancy calculation unit is used to initialize the system, the timer and the cumulative counter, and perform statistics on the cumulative counter for the first time when the idle function is run for the first time, obtain the operating data of the cumulative counter corresponding to when the timing time of the timer reaches the preset time value for the first time, and then determine the initial CPU occupancy data.

[0068] Furthermore, in other embodiments of the present invention, the target CPU occupancy rate determination module 24 further includes:

[0069] The curve determination unit is used to subtract the initial CPU occupancy data from the real-time CPU occupancy data, and use the difference between the two as the vertical coordinate and time as the horizontal coordinate to obtain a curve graph of the target CPU occupancy changing with time.

[0070] The target CPU occupancy rate determining unit is used to determine the target CPU occupancy rate data corresponding to the target task according to the peak point and the valley point on the curve graph.

[0071] The functions or operation steps implemented when the above modules are executed are substantially the same as those in the above method embodiments, and will not be repeated here.

[0072] Embodiment 3

[0073] Another aspect of the present invention provides an electronic device, see Figure 3 , shown is a schematic diagram of an electronic device in the third embodiment of the present invention, including a memory 20, a processor 10, and a computer program 30 stored in the memory and executable on the processor, wherein the processor 10 implements the CPU usage calculation method as described above when executing the computer program 30.

[0074] In some embodiments, the processor 10 may be a central processing unit (CPU), a controller, a microcontroller, a microprocessor or other data processing chip, used to run program codes or process data stored in the memory 20, such as executing access restriction programs.

[0075] Among them, the memory 20 includes at least one type of readable storage medium, and the readable storage medium includes flash memory, hard disk, multimedia card, card-type memory (for example, SD or DX memory, etc.), magnetic memory, disk, optical disk, etc. The memory 20 may be an internal storage unit of an electronic device in some embodiments, such as a hard disk of the electronic device. The memory 20 may also be an external storage device of an electronic device in other embodiments, such as a plug-in hard disk equipped on the electronic device, a smart memory card (Smart Media Card, SMC), a secure digital (Secure Digital, SD) card, a flash card (FlashCard), etc. Further, the memory 20 may also include both an internal storage unit and an external storage device of the electronic device. The memory 20 may be used not only to store application software and various types of data of the electronic device, but also to temporarily store data that has been output or is to be output.

[0076] It should be pointed out that Figure 3 The structure shown does not constitute a limitation on the electronic device. In other embodiments, the electronic device may include fewer or more components than those shown in the figure, or combine certain components, or arrange the components differently.

[0077] The embodiment of the present invention further provides a computer-readable storage medium on which a computer program is stored. When the program is executed by a processor, the method for calculating the CPU usage rate as described above is implemented.

[0078] Those skilled in the art will appreciate that the logic and / or steps represented in the flowchart or otherwise described herein, for example, may be considered as an ordered list of executable instructions for implementing logical functions, and may be embodied in any computer-readable medium for use by an instruction execution system, device or apparatus (such as a computer-based system, a system including a processor, or other system that can fetch instructions from an instruction execution system, device or apparatus and execute instructions), or in conjunction with such instruction execution systems, devices or apparatuses. For purposes of this specification, a "computer-readable medium" may be any device that can contain, store, communicate, propagate or transmit a program for use by an instruction execution system, device or apparatus, or in conjunction with such instruction execution systems, devices or apparatuses.

[0079] More specific examples of computer-readable media (a non-exhaustive list) include the following: an electrical connection with one or more wires (electronic device), a portable computer disk case (magnetic device), a random access memory (RAM), a read-only memory (ROM), an erasable and programmable read-only memory (EPROM or flash memory), an optical fiber device, and a portable compact disk read-only memory (CDROM). In addition, the computer-readable medium may even be a paper or other suitable medium on which the program is printed, since the program may be obtained electronically, for example, by optically scanning the paper or other medium, followed by editing, deciphering or, if necessary, processing in another suitable manner, and then stored in a computer memory.

[0080] It should be understood that the various parts of the present invention can be implemented by hardware, software, firmware or a combination thereof. In the above-mentioned embodiments, a plurality of steps or methods can be implemented by software or firmware stored in a memory and executed by a suitable instruction execution system. For example, if implemented by hardware, as in another embodiment, it can be implemented by any one of the following technologies known in the art or a combination thereof: a discrete logic circuit having a logic gate circuit for implementing a logic function for a data signal, a dedicated integrated circuit having a suitable combination of logic gate circuits, a programmable gate array (PGA), a field programmable gate array (FPGA), etc.

[0081] In the description of this specification, the description with reference to the terms "one embodiment", "some embodiments", "examples", "specific examples" or "some examples" means that the specific features, structures, materials or characteristics described in conjunction with the embodiment or example are included in at least one embodiment or example of the present invention. In this specification, the schematic representations of the above terms do not necessarily refer to the same embodiment or example. Moreover, the specific features, structures, materials or characteristics described may be combined in any one or more embodiments or examples in a suitable manner.

[0082] The above embodiments only express several implementation methods of the present invention, and the descriptions thereof are relatively specific and detailed, but they cannot be understood as limiting the scope of the present invention. It should be pointed out that, for a person of ordinary skill in the art, several modifications and improvements can be made without departing from the concept of the present invention, and these all belong to the protection scope of the present invention. Therefore, the protection scope of the present invention patent shall be subject to the attached claims.

Claims

1. A method for calculating CPU usage, characterized in that: The method comprises: Get the initial CPU usage data of the system in the initial state and determine whether the target task is running; If the target task is running, determine whether the initial value of the cumulative counter corresponding to the idle task is a preset value; If the initial value of the cumulative counter is a preset value, start the timer to make the cumulative counter accumulate and count, and determine in real time whether the value of the timer reaches the preset time value; If the value of the timer reaches the preset time value, the operating data of the cumulative counter is obtained, the real-time CPU occupancy data of the current system is determined according to the operating data, and the target CPU occupancy data corresponding to the target task is determined according to the real-time CPU occupancy data and the initial CPU occupancy data.

2. The CPU usage calculation method according to claim 1, characterized in that: The step of determining whether the initial value of the accumulative counter corresponding to the idle task is a preset value includes: If the initial value of the cumulative counter is not a preset value, obtaining whether the value of the timer corresponding to the cumulative counter is less than a preset time value; If not, obtain the operating data corresponding to the cumulative counter, determine the real-time CPU occupancy data of the current system according to the operating data, and determine the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data.

3. The CPU usage calculation method according to claim 2, characterized in that: The step of obtaining the initial CPU occupancy data of the system in the initial state comprises: Initialize the system, the timer and the cumulative counter, and perform statistics on the cumulative counter for the first time when the idle function is run for the first time, obtain the running data of the cumulative counter corresponding to when the timing time of the timer reaches the preset time value for the first time, and then determine the initial CPU occupancy data.

4. The CPU usage calculation method according to claim 1, characterized in that: The step of determining the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data comprises: Subtract the initial CPU occupancy rate data from the real-time CPU occupancy rate data, and use the difference between the two as the ordinate and time as the abscissa to obtain a curve graph of the target CPU occupancy rate changing over time; The target CPU occupancy rate data corresponding to the target task is determined according to the peak point and the valley point on the curve graph.

5. The CPU usage calculation method according to claim 3, characterized in that: After the step of determining the target CPU occupancy data corresponding to the target task, the following step is further included: The running data of the cumulative counter is cleared, and the target CPU occupancy rate data is uploaded to the cloud database as the historical CPU occupancy rate data corresponding to the target task.

6. The CPU usage calculation method according to claim 5, characterized in that: The step of obtaining the initial CPU occupancy rate data of the system in the initial state includes: The historical CPU occupancy rate data corresponding to the task to be run is obtained from the cloud database, and the resources of the system are allocated according to the historical CPU occupancy rate data.

7. The CPU usage calculation method according to claim 6, characterized in that: After the step of determining the target CPU occupancy data corresponding to the target task, the following step is further included: The target CPU occupancy data is compared with the corresponding historical CPU occupancy data in the cloud database to determine whether the ratio of the two is greater than a preset threshold. If an over-threshold flag is generated, the target CPU occupancy data is marked so that the subsequent system operation of the target task will allocate system resources according to the over-threshold flag and the historical CPU occupancy data.

8. A CPU usage calculation system, characterized in that: Used to implement the CPU usage calculation method according to any one of claims 1 to 7, the system comprises: The target task determination module is used to obtain the initial CPU occupancy data of the system in the initial state and determine whether the target task is running; The cumulative counter judgment module is used to judge whether the initial value of the cumulative counter corresponding to the idle task is a preset value when the target task is running; A timer judgment module, used for starting the timer and making the accumulative counter accumulate and count when the initial value of the accumulative counter is a preset value, and judging in real time whether the value of the timer reaches the preset time value; The target CPU occupancy determination module is used to obtain the operating data of the cumulative counter when the timer value reaches a preset time value, determine the real-time CPU occupancy data of the current system according to the operating data, and determine the target CPU occupancy data corresponding to the target task according to the real-time CPU occupancy data and the initial CPU occupancy data.

9. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the program is executed by a processor, the steps of the CPU usage calculation method according to any one of claims 1 to 7 are implemented.

10. An electronic device, characterized in that: The method comprises a memory, a processor and a computer program stored in the memory and executable on the processor, wherein the processor implements the CPU usage rate calculation method as claimed in any one of claims 1 to 7 when executing the program.