CN108959020A - A kind of calculation method and device of Computer CPU Utilization Ratio - Google Patents
A kind of calculation method and device of Computer CPU Utilization Ratio Download PDFInfo
- Publication number
- CN108959020A CN108959020A CN201810430440.9A CN201810430440A CN108959020A CN 108959020 A CN108959020 A CN 108959020A CN 201810430440 A CN201810430440 A CN 201810430440A CN 108959020 A CN108959020 A CN 108959020A
- Authority
- CN
- China
- Prior art keywords
- core
- utilization rate
- cpu
- computer
- utilization
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Granted
Links
Classifications
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/3003—Monitoring arrangements specially adapted to the computing system or computing system component being monitored
- G06F11/3024—Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a central processing unit [CPU]
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/34—Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
- G06F11/3409—Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment
- G06F11/3419—Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment by assessing time
- G06F11/3423—Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment for performance assessment by assessing time where the assessed time is active or idle time
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F11/00—Error detection; Error correction; Monitoring
- G06F11/30—Monitoring
- G06F11/34—Recording or statistical evaluation of computer activity, e.g. of down time, of input/output operation ; Recording or statistical evaluation of user activity, e.g. usability assessment
- G06F11/3452—Performance evaluation by statistical analysis
Landscapes
- Engineering & Computer Science (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- Quality & Reliability (AREA)
- General Physics & Mathematics (AREA)
- Computer Hardware Design (AREA)
- Computing Systems (AREA)
- Mathematical Physics (AREA)
- Life Sciences & Earth Sciences (AREA)
- Bioinformatics & Cheminformatics (AREA)
- Bioinformatics & Computational Biology (AREA)
- Evolutionary Biology (AREA)
- Probability & Statistics with Applications (AREA)
- Debugging And Monitoring (AREA)
Abstract
The embodiment of the present application discloses the calculation method and device of a kind of Computer CPU Utilization Ratio, it is related to field of computer technology, it solves in the prior art after opening Hyper-Threading, the problem of needing to carry out kernel programming exploitation to operating system, and customized development needed to different OS or virtual platform.The specific scheme is that obtaining the utilization rate of the thread run on each Core;Utilization rate based on the thread run on the Core calculates the physical core utilization rate for running the Core;The utilization rate of the CPU is calculated based on the physical core utilization rate of one or more of Core.Scheme provided by the embodiments of the present application is suitable for calculating the utilization rate of CPU.
Description
Technical field
The invention relates to field of computer technology more particularly to a kind of calculation methods of Computer CPU Utilization Ratio
And device.
Background technique
Central processing unit (Central Processing Unit, abbreviation CPU) occupies larger ratio in the cost of computer
Weight, how valid metric, CPU management utilization rate are as the critical issue for promoting IT system resource efficiency.
When the eighties, since the structure and technology of CPU are relatively simple, top order or times of windows can be passed through
Business manager, measures the service condition of cpu resource.But with technologies such as hyperthread (Hyper-Threading, abbreviation HT)
It is widely applied, for the processor for opening hyperthread characteristic, the cpu busy percentage that the orders such as Top obtain can not be correctly presented
The actual use situation of cpu resource leads to many puzzlements or misleading in cpu resource management process.Such as: enable hyperthread
Afterwards, when CPU resource utilization shows 50%, actual CPU resource utilization has played most of ability of CPU, reaches
70%-100%.
Prior art one kind can be compared with the method for accuracy amount CPU resource utilization are as follows: after opening hyperthread, VMware is logical
It crosses its software and obtains non-hang-up periodicity (unhalted cycles), and divided by cycles sum, obtain the physical core benefit of Core
With rate.
But the technical solution obtains cpu busy percentage using customized development, needs to carry out kernel programming to operating system
Exploitation, is only applicable to VMware commercialization platform.And under other scenes, such as the general-purpose operating system (Operating System,
Abbreviation OS) and other xen, based on the platforms such as kernel virtual machine (Kernel-based Virtual Machine, KVM), on
Scheme is stated without versatility, cpu busy percentage can not be obtained.
Summary of the invention
The embodiment of the present application provides the calculation method and device of a kind of Computer CPU Utilization Ratio, for different OS or void
Quasi-ization platform is generally applicable, can be after opening Hyper-Threading, and the benefit of CPU can accurately be obtained by not needing exploitation or a small amount of exploitation
With rate.
In order to achieve the above objectives, the embodiment of the present application adopts the following technical scheme that
The embodiment of the present application in a first aspect, provide a kind of calculation method of central processing unit (CPU) cpu busy percentage, should
Computer includes CPU, which includes to run at least two threads, this method on one or more physical core Core, each Core
It include: firstly, obtaining the utilization rate of the thread run on each Core;Then, the utilization rate based on the thread run on Core
Calculate the physical core utilization rate for running the Core;The physical core utilization rate based on one or more Core calculates the benefit of CPU again
With rate.In this way, pass through the utilization rate for obtaining thread, and the physical core of Core can be accurately obtained using the utilization rate of thread
Utilization rate, and then the utilization rate of CPU is obtained, because the utilization rate of thread can be obtained by not needing exploitation or a small amount of exploitation generally,
It is generally applicable for different OS or virtual platform in this way, cost of implementation is low, and versatility is good.
With reference to first aspect, in the first possible implementation, the above-mentioned utilization based on the thread run on Core
Rate calculates the physical core utilization rate of the Core, comprising: is based on preset model, the utilization rate of the thread run on the Core is converted
For the physical core utilization rate of the Core.The preset model includes the first model and the second model, which is to indicate Core
The model of relationship between the utilization rate of the thread of upper operation and the utilization rate of the Core;Second model is the utilization for indicating Core
The model of relationship between rate and the physical core utilization rate of the Core.Correspondingly, above-mentioned be based on preset model, will be transported on the Core
The utilization rate of capable thread is converted to the physical core utilization rate of the Core, can specifically include: by the thread run on Core
Utilization rate substitutes into first model, obtains the utilization rate of the Core;And the utilization rate of the Core is substituted into second model, it obtains
Take the physical core utilization rate of the Core.In a kind of implementation, when running k thread on Core, k is integer, and k >=2,
First model, specifically:Wherein, thUtilization rate for h-th of the thread run on the Core, x is should
The utilization rate of Core.In this way, can accurately be obtained corresponding each according to the utilization rate of the thread run on each Core
The utilization rate of Core.Second model, specifically: y=2x-x2, wherein y is the physical core utilization rate of the Core.Such one
Come, the true utilization rate of the Core can be obtained according to the utilization rate of Core, without being developed for OS or virtual platform
The physical core utilization rate of each Core can be obtained in the register information of special module reading processor.In this way, pass through
The first model and the second model built up in advance can accurately and rapidly obtain the physical core utilization rate of Core.
It is above-mentioned to be based on one in alternatively possible implementation with reference to first aspect with above-mentioned possible implementation
The physical core utilization rate of a or multiple Core calculates the utilization rate of CPU, specifically includes: the physics based on one or more Core
Core utilization rate obtains utilization rate of the average physical core utilization rate of the Core of CPU as the CPU.In this way, include more in CPU
When a Core, the physical core utilization rate for each Core that can include according to CPU averages to obtain the utilization rate of the CPU.
With reference to first aspect with above-mentioned possible implementation, in alternatively possible implementation, when computer packet
When containing multiple CPU, multiple cpu busy percentages of the computer are the average utilization of multiple CPU.In this way, in computer packet
When containing multiple CPU, the cpu busy percentage of the computer can be obtained according to the utilization rate for each CPU for including in computer, thus
To the true cpu resource service condition of computer.
The second aspect of the embodiment of the present application provides a kind of computing device of central processing unit (CPU) cpu busy percentage, should
Computer includes CPU, which includes to run at least two threads on one or more physical core Core, each Core, the calculating
Device includes: acquiring unit and computing unit;Acquiring unit, for obtaining the line run on each Core at least one Core
The utilization rate of journey;Computing unit calculates the physics for running the Core for the utilization rate based on the thread run on the Core
Core utilization rate;The computing unit, the physical core utilization rate for being also used to Core based on one or more calculate the utilization rate of CPU.
In conjunction with second aspect, in the first possible implementation, above-mentioned computing unit is specifically used for based on default mould
The utilization rate of the thread run on the Core is converted to the physical core utilization rate of the Core by type.The preset model includes
The associated description of first model and the second model, first model and the second model can refer in a first aspect, no longer superfluous herein
It states.Correspondingly, the computing unit, is specifically used for: first model is based on, by the utilization rate of the thread run on the Core
Be converted to the utilization rate of the Core;The computing unit is specifically used for being based on second model, by the utilization rate of the Core
Be converted to the physical core utilization rate of the Core.
In conjunction with second aspect and above-mentioned possible implementation, in alternatively possible implementation, the computing unit,
Be specifically used for: the physical core utilization rate based on one or more of Core obtains the average physical core benefit of the Core of the CPU
Use rate as the utilization rate of the CPU.
In conjunction with second aspect and above-mentioned possible implementation, in alternatively possible implementation, above-mentioned computer
Comprising multiple CPU, multiple cpu busy percentages of the computer are the average utilization of multiple CPU.
The effect description of the various implementations of above-mentioned second aspect and second aspect can be corresponding with reference to first aspect
The description of effect, details are not described herein.
The third aspect of the embodiment of the present application, provides a kind of computer, include in the structure of the computer processor and
Memory, the processor include at least one CPU, and each CPU includes to distinguish on one or more physical core Core, each Core
At least two threads are run, which saves the necessary program instruction of the computer and data, be somebody's turn to do for coupling with processor
Processor is for executing the program instruction stored in memory, so that the computer executes the above method.
The fourth aspect of the embodiment of the present application provides a kind of computer storage medium, deposits in the computer storage medium
Computer program code is contained, when the computer program code is run on a processor, so that the processor executes the
The calculating side of any central processing unit (CPU) cpu busy percentage in the possible implementation of one side or first aspect
Method.
5th aspect of the embodiment of the present application, provides a kind of computer program product, which stores above-mentioned
The computer software instructions that processor executes, the computer software instructions include the journey for executing the above-mentioned aspect scheme
Sequence.
6th aspect of the embodiment of the present application, provides a kind of device, which exists with the product form of chip, the dress
It include processor and memory in the structure set, which saves the necessary program of the device and refer to for coupling with processor
It enables and data, the processor calculates in the above method for executing the program instruction stored in memory so that the device executes
The function of the computing device of machine cpu busy percentage.
Detailed description of the invention
Fig. 1 is a kind of structural schematic diagram of computer provided by the embodiments of the present application;
Fig. 2 is a kind of structural schematic diagram of specific computer provided by the embodiments of the present application;
Fig. 3 is a kind of flow chart of the calculation method of Computer CPU Utilization Ratio provided by the embodiments of the present application;
Fig. 4 is actual value and reason between the utilization rate of Core provided by the embodiments of the present application and the physical core utilization rate of Core
By the comparison schematic diagram of value;
Fig. 5 is a kind of composition schematic diagram of computer provided by the embodiments of the present application;
Fig. 6 is the composition schematic diagram of another computer provided by the embodiments of the present application.
Specific embodiment
The embodiment of the present application provides a kind of calculation method of Computer CPU Utilization Ratio, and illustratively, which can be
Tablet computer, desktop type, on knee, laptop, Ultra-Mobile PC (Ultra-mobile Personal
Computer, UMPC), handheld computer, net book, personal digital assistant (Personal Digital Assistant,
PDA), the equipment such as are not done the concrete form of computer in the embodiment of the present application specifically limited.
Fig. 1 is a kind of structural schematic diagram of computer 100 provided by the embodiments of the present application.As shown in Figure 1, the computer
100 include: hardware layer and software layer, and hardware layer includes processor 101, memory 102, bus 103 etc., and software layer includes operation
System 104.
Processor 101: being the core component of computer 100, for running the operating system and computer of computer 100
Application program (including system application and third party application) on 100.
In the embodiment of the present application, processor 101 be specifically as follows central processing unit (central processing unit,
CPU), it may be implemented or execute and combine various illustrative logic blocks described in the embodiment of the present application disclosure,
Module and circuit;Processor is also possible to realize the combination of computing function, such as combines comprising one or more microprocessors,
DSP and the combination of microprocessor etc..The embodiment of the present application is only illustrated so that processor is CPU as an example, as shown in Figure 1, calculating
Machine 100 includes CPU, which includes that physical core Core runs at least two threads after opening Hyper-Threading on each Core
(Fig. 1 is only illustrated with two threads).The quantity for the CPU that the embodiment of the present application includes for computer and each CPU include
The quantity of physical core Core is simultaneously not limited.It will be appreciated that Fig. 1 is merely illustrative structure chart, run on each Core
The quantity of thread may be the same or different, and the embodiment of the present application is to this without limiting.
Memory 102: can be used for storing software program and module, and processor 101 is stored in memory 102 by operation
In software program and module, thereby executing the various function application and data processing of computer 100.Memory 102 can
Include one or more computer readable storage mediums.Memory 102 includes storing program area and storage data area, wherein is deposited
Store up program area can application program needed for storage program area, at least one function etc., realize that the application is implemented for example, can store
The program of the calculation method for the Computer CPU Utilization Ratio that example provides.Storage data area can store the data of the creation of computer 100
Deng.For example, during the calculation method for executing Computer CPU Utilization Ratio can be stored, the utilization rate of the thread of acquisition, and it is each
Stage calculated result, for example, multiple CPU of the physical core utilization rate of the utilization rate of Core, Core, the utilization rate of CPU, computer
Utilization rate etc..
In the embodiment of the present application, memory 102 can specifically include volatile memory (volatile memory), example
Such as random access memory (random-access memory, RAM);The memory also may include nonvolatile memory
(non-volatile memory), flash memory (flash memory), hard disk (hard fisk drive, HDD) or solid
State hard disk (solid-state drive, SSD);The memory can also include the combination of the memory of mentioned kind.
Bus 103: it is the common communication main line for transmitting information between the various functional components of computer, is passed according to computer
The bus of defeated information category, computer can be divided into data/address bus, address bus and control bus, be respectively intended to transmission number
According to, data address and control signal.
Operating system 104 (Operating System, abbreviation OS) is to manage and control computer hardware and software resource
Computer program, be the most basic system software run directly on " bare machine ", for supporting other software, such as various
The operation of application program.Operating system can be various operating systems in the embodiment of the present application, for example, Windows operating system,
(SuSE) Linux OS, iOS operating system, Android open source operating system and operate in Windows operating system and
Virtualization operations platform such as kvm, xen on (SuSE) Linux OS etc..
It will be appreciated that Fig. 1 is merely illustrative, in practical application, computer 100 may include than shown in Fig. 1 more
More or less component, for example, it is also possible to include user interface, for supporting to interact between system and user and information
Exchange or communication interface, for supporting terminal and other terminals, server, the communication between network;Structure shown in Fig. 1 is not
Any restrictions are constituted to computer provided by the embodiments of the present application.
In order to solve in background technique, when obtaining cpu busy percentage, need to carry out operating system kernel programming exploitation, and
The problem of needing customized development to different OS or virtual platform, the embodiment of the present application provide a kind of computer CPU utilization
The calculation method of rate, the calculation method are generally applicable to different OS or virtual platform, can be after opening Hyper-Threading, no
It needs to develop or a small amount of exploitation can accurately obtain cpu busy percentage.
For convenience of explanation, as shown in Fig. 2, a kind of structural schematic diagram of specific computer is provided, here only with Fig. 2
Shown in structural schematic diagram the calculation method of Computer CPU Utilization Ratio provided by the embodiments of the present application is illustrated.
The computer 200 includes two CPU, is denoted as CPU1 and CPU2 respectively, and CPU1 and CPU2 separately include two physical core Core, point
It is not denoted as Core11, Core12, Core21 and Core22, runs two threads on the Core11 that CPU1 includes, is denoted as line respectively
Journey 111 and thread 112 run two threads on the Core12 that CPU1 includes, are denoted as thread 121 and thread 122, CPU2 packet respectively
Two threads are run on the Core21 contained, are denoted as thread 211 and thread 212 respectively, are run two on the Core22 that CPU2 includes
Thread is denoted as thread 221 and thread 222 respectively.
The calculation method of Computer CPU Utilization Ratio provided by the embodiments of the present application is to open Hyper-Threading in computer
It is carried out under scene afterwards.The Hyper-Threading can make CPU be performed simultaneously multiple thread, after opening Hyper-Threading, each
At least two threads are run on physical core Core.Thread in following embodiments is each line opened after Hyper-Threading
Journey.Method provided by the embodiments of the present application can be applied under various operating systems and the various scenes of virtual platform.
In conjunction with Fig. 1, Fig. 2, as shown in figure 3, the calculation method of Computer CPU Utilization Ratio provided by the embodiments of the present application can be with
Including S301-S303:
S301, the utilization rate for obtaining the thread run on each Core.
The utilization rate of thread, when referring to the occupied timeslice of the application program run on thread the line is busy assignable in journey
Between piece ratio, be able to reflect the service condition of thread computing resource.
Specifically, the utilization rate of all threads run on one or more Core that CPU includes, example can be obtained respectively
Such as, referring to fig. 2, for CPU1, the utilization rate of thread 111, thread 112, thread 121 and thread 122 can be obtained respectively.
Illustratively, can be obtained based on the utilization rate of the thread recorded in operating system run on each Core it is all
The utilization rate of thread.
S302, the utilization rate based on the thread run on the Core calculate the physical core utilization rate for running the Core.
The physical core utilization rate of Core refers to that the Core currently used computing resource accounts for that the Core is all to be able to use
The ratio of computing resource is able to reflect the service condition of the real resources of Core.
Illustratively, utilization rate based on the thread run on Core calculate run the physical core utilization rate of the Core can be with
It include: that the utilization rate of the thread run on the Core is converted to based on preset model by the physical core utilization rate of the Core.
Specifically, the preset model be the utilization rate of the thread and Core for indicating to run on Core physical core utilization rate it
Between relationship model, the embodiment of the present application for preset model concrete form and without concrete restriction, by any one
The utilization rate of the thread run on Core substitutes into preset model, obtains the physical core utilization rate of the Core in the protection of the application
In range.
Illustratively, which may include the first model and the second model.First model is to indicate on Core
The model of relationship between the utilization rate of the thread of operation and the utilization rate of the Core;Second model is the utilization for indicating the Core
The model of relationship between rate and the physical core utilization rate of the Core.
Correspondingly, S302 can specifically include S302a-S302b:
S302a, it is based on first model, the utilization rate of the thread run on the Core is converted to the Core's
Utilization rate.
The utilization rate of Core refers to that the occupied timeslice of application program run on all threads that the Core includes accounts for
The ratio of assignable timeslice on all threads that Core includes.
The utilization rate of the thread run on any one Core is substituted into the first model, the utilization of the Core can be obtained
Rate.
Concrete form the embodiment of the present application of first model is without concrete restriction.As long as one can be clearly showed that
Relationship between the utilization rate of the thread run on Core and the utilization rate of the Core.In a kind of implementation, when described
When running k thread on Core, k is integer, and k >=2, and the first model can be with are as follows:
Wherein, thUtilization rate for h-th of the thread run on a Core, x are the benefit of the Core
With rate, k is the quantity of the thread run on the Core.
Illustratively, when the thread run on a Core is three, the utilization rate of the Core is
When the thread run on one Core is two, the utilization rate of the Core is
As shown in connection with fig. 2, if the utilization rate of thread 111 is 25%, the utilization rate of thread 112 is 35%, then Core11
Utilization rate be 30%.
If the utilization rate of thread 121 is 30%, the utilization rate of thread 122 is 50%, then the utilization rate of Core12 is
40%.
If the utilization rate of thread 211 is 40%, the utilization rate of thread 212 is 50%, then the utilization rate of Core21 is
45%.
If the utilization rate of thread 221 is 35%, the utilization rate of thread 222 is 45%, then the utilization rate of Core22 is
40%.
S302b, it is based on second model, the physical core that the utilization rate of the Core is converted to the Core is utilized
Rate.
The utilization rate of any one Core is substituted into the second model, the physical core utilization rate of the Core can be obtained.
Concrete form the embodiment of the present application of second model is without concrete restriction.As long as one can be clearly showed that
Relationship between the utilization rate of Core and the physical core utilization rate of the Core.In a kind of implementation, which can
With are as follows:
Y=2x-x2, wherein y is the physical core utilization rate of Core, and x is the utilization rate of the Core.
Illustratively, as shown in connection with fig. 2, if the utilization rate of Core11 is 30%, the true money of the Core11 is embodied
The physical core utilization rate of source service condition is 2*0.3-0.3^2=0.51=51%.
If the utilization rate of Core12 is 40%, the physical core for embodying the real resources service condition of the Core12 is utilized
Rate is 2*0.4-0.4^2=0.64=64%.
If the utilization rate of Core21 is 45%, the physical core for embodying the real resources service condition of the Core21 is utilized
Rate is 2*0.45-0.45^2=0.6975=69.8%.
If the utilization rate of Core22 is 40%, the physical core for embodying the real resources service condition of the Core22 is utilized
Rate is 2*0.4-0.4^2=0.64=64%.
As shown in figure 4, being the utilization rate of Core compared with actual value and theoretical value between the physical core utilization rate of Core
Schematic diagram, horizontal axis indicate the utilization rate of Core, and the longitudinal axis indicates the physical core utilization rate of Core, and black circle is the utilization rate of Core
In 15%-75%, the physical core utilization rate for the Core that calculation method provided by the embodiments of the present application obtains, curve table are utilized
Show the utilization rate of Core in 15%-75%, the practical range of values of the physical core utilization rate of the actually detected Core arrived, due to sample
This points is excessive, and the actual value of the physical core utilization rate of the actually detected Core arrived uses curve in the curve ranges
Region indicate the actually detected Core arrived physical core utilization rate practical range of values, by the data ratio for carrying out enough samples
To verifying, the theoretical value of the physical core utilization rate for the Core that the embodiment of the present application is calculated and the actually detected Core arrived
Physical core utilization rate actual value it is very close.
S303, the utilization rate that the CPU is calculated based on the physical core utilization rate of one or more of Core.
The utilization rate of CPU is referred to the ratio of the allowable resource for being accounted for the CPU using resource of the CPU, is able to reflect this
The service condition of the real resources of CPU.
It should be noted that how the embodiment of the present application calculates the physical core utilization rate by one or more Core
Obtain the specific calculation of the utilization rate of the CPU and be not limited, any one by one or more Core physical core
Utilization rate, the method for obtaining the utilization rate of the CPU are within the scope of the invention.
Illustratively, based on one or more Core physical core utilization rate calculate CPU utilization rate a kind of realization side
Formula can be with are as follows: the physical core utilization rate based on one or more Core obtains the average physical core utilization rate of the Core of the CPU
Utilization rate as the CPU.
The average physical core utilization rate of the Core of the CPU can be with are as follows:
The physical core utilization rate of the CPU one or more Core for including is substituted intoObtain the CPU's
The average physical core utilization rate of Core, the as utilization rate of the CPU, whereinFor the utilization rate of CPU, yiInclude for the CPU
The physical core utilization rate of i-th of Core, m are the number for the Core for including in the CPU, and m is integer.
It is understood that the embodiment of the present application for the Core for including in each CPU quantity and be not limited, often
The quantity for the Core for including in a CPU may be the same or different.Illustratively, the quantity for the Core for including in CPU is two
When a, the utilization rate of the CPU can be
Illustratively, as shown in connection with fig. 2, if the physical core benefit that the physical core utilization rate of Core11 is 51%, Core12
It is 64% with rate, then the utilization rate of CPU1 is 57.5%.
If the physical core utilization rate that the physical core utilization rate of Core21 is 69.8%, Core22 is 64%, then CPU2
Utilization rate is 66.9%.
Illustratively, the embodiment of the present application for the CPU for including in computer quantity and be not limited, if computer
Comprising multiple CPU, multiple cpu busy percentages of the computer are the average utilization of multiple CPU.
Multiple cpu busy percentages of the computer refer to that all CPU's that computer includes accounts for the computer using resource
The ratio of the allowable resource for all CPU for including is able to reflect the service condition of the real resources of the computer.
Illustratively, multiple cpu busy percentages of the computer can be with are as follows:
The utilization rate of each CPU substitutes into the multiple CPU for including by computerObtain the more of computer
A cpu busy percentage, wherein z is multiple cpu busy percentages of computer,Utilization for j-th of CPU for including in the computer
Rate, n are that the number for the CPU for including, n >=2, and n are integer in the computer.
Specifically, the cpu busy percentage of the computer is the utilization of the single cpu when computer only includes a CPU
Rate;When in computer including multiple CPU, the cpu busy percentage of the computer can be the benefit for multiple CPU that the computer includes
With the average value of rate.The cpu busy percentage of computer refers in the application, starts and is shown after the task manager of computer in performance column
The CPU usage shown.
Illustratively, as shown in connection with fig. 2, if the utilization rate that the utilization rate of CPU1 is 57.5%, CPU2 is 66.9%, then
The cpu busy percentage of the computer 200 is 62.2%.
A kind of calculation method of Computer CPU Utilization Ratio provided by the embodiments of the present application is transported on each Core by obtaining
The utilization rate of capable thread, the utilization rate based on the thread run on the Core calculate the physical core utilization rate for running the Core,
Physical core utilization rate based on one or more Core calculates the utilization rate of CPU.The embodiment of the present application is by obtaining thread
Utilization rate, and the physical core utilization rate of Core is calculated using the utilization rate of thread, and then obtain the true utilization rate of CPU,
Compared with needing in the prior art to different OS or virtual platform customized development, the method for the application calculating cpu busy percentage
Generally applicable for different OS or virtual platform, true CPU utilization rate can accurately be obtained by not needing exploitation or a small amount of exploitation
Data.
It is above-mentioned that mainly scheme provided in an embodiment of the present invention is described from the angle of method and step.It is understood that
It is that in order to realize the above functions, it comprises execute the corresponding hardware configuration of each function and/or software module for computer.This
Field technical staff should be readily appreciated that, unit and algorithm described in conjunction with the examples disclosed in the embodiments of the present disclosure
Step, the application can be realized with the combining form of hardware and computer software.Professional technician can be to each specific
Application use different methods to achieve the described function, but such implementation should not be considered as beyond the scope of the present invention.
The embodiment of the present application can carry out the division of functional module according to above method example to computer, for example, can be with
Two or more functions, can also be integrated in a processing module by corresponding each each functional module of function division
In.Above-mentioned integrated module both can take the form of hardware realization, can also be realized in the form of software function module.It needs
It is noted that be schematical, only a kind of logical function partition to the division of module in the embodiment of the present invention, it is practical real
It is current that there may be another division manner.
In the case where each function division of use correspondence each functional module, Fig. 5 shows involved in above-described embodiment
And computer a kind of possible structural schematic diagram, which includes: acquiring unit 501 and computing unit 502.It obtains
Take unit 501 for supporting computer to execute the S301 in Fig. 3;Computing unit 502 is for supporting computer to execute in Fig. 3
S302-S303.Wherein, all related contents for each step that above method embodiment is related to can quote corresponding function mould
The function of block describes, and details are not described herein.
Using integrated unit, one kind that Fig. 6 shows computer involved in above-described embodiment can
The structural schematic diagram of energy.The computer 600 includes: memory module 601 and processing module 602.Processing module 602 is used for calculating
The movement of machine carries out control management, for example, processing module 602 is used to that computer to be supported to execute the S301-S303 in Fig. 3, and/or
Other processes for techniques described herein.Memory module 601, for storing the program code and data of computer.When
Above-mentioned memory module 601 is memory, and when processing module 602 is processor, the specific structure of computer shown in fig. 6 can be
Above-mentioned Fig. 1 or computer shown in Fig. 2, wherein all related contents for each component that above-mentioned Fig. 1 or Fig. 2 is related to are retouched
The function description that can quote Fig. 6 corresponding component is stated, details are not described herein.Another kind is realized, involved by above-described embodiment
Computer configuation can also be include processor and interface, processor and interface communication, processor is of the invention real for executing
Apply example.Processor can be CPU, be also possible to other hardware, such as field programmable gate array (Field-Programmable
Gate Array, FPGA) etc., or both combination.
The step of method in conjunction with described in present disclosure or algorithm can realize in a manner of hardware, can also
It is realized in a manner of being to execute software instruction by processor.Software instruction can be made of corresponding software module, software mould
It is read-only that block can be stored on random access memory (Random Access Memory, RAM), flash memory, erasable programmable
Memory (Erasable Programmable ROM, EPROM), Electrically Erasable Programmable Read-Only Memory (Electrically
EPROM, EEPROM), register, hard disk, mobile hard disk, CD-ROM (CD-ROM) or any other shape well known in the art
In the storage medium of formula.A kind of illustrative storage medium is coupled to processor, to enable a processor to from the storage medium
Information is read, and information can be written to the storage medium.Certainly, storage medium is also possible to the component part of processor.Processing
Device and storage medium can be located in ASIC.In addition, the ASIC can be located in core network interface equipment.Certainly, processor and
Storage medium can also be used as discrete assembly and be present in core network interface equipment.
Those skilled in the art are it will be appreciated that in said one or multiple examples, function described in the invention
It can be realized with hardware, software, firmware or their any combination.It when implemented in software, can be by these functions
Storage in computer-readable medium or as on computer-readable medium one or more instructions or code transmitted.
Computer-readable medium includes computer storage media and communication media, and wherein communication media includes convenient for from a place to another
Any medium of one place transmission computer program.Storage medium can be general or specialized computer can access it is any
Usable medium.
Above-described specific embodiment has carried out further the purpose of the present invention, technical scheme and beneficial effects
It is described in detail, it should be understood that being not intended to limit the present invention the foregoing is merely a specific embodiment of the invention
Protection scope, all any modification, equivalent substitution, improvement and etc. on the basis of technical solution of the present invention, done should all
Including within protection scope of the present invention.
Claims (16)
1. a kind of calculation method of central processing unit (CPU) cpu busy percentage, which is characterized in that the computer includes CPU, institute
Stating CPU includes to run at least two threads on one or more physical core Core, each Core, and the calculation method includes:
Obtain the utilization rate of the thread run on each Core;
Utilization rate based on the thread run on the Core calculates the physical core utilization rate for running the Core;
The utilization rate of the CPU is calculated based on the physical core utilization rate of one or more of Core.
2. the calculation method of Computer CPU Utilization Ratio according to claim 1, which is characterized in that described based on described
The utilization rate of the thread run on Core calculates the physical core utilization rate of the Core, comprising:
Based on preset model, the utilization rate of the thread run on the Core is converted to the physical core utilization rate of the Core.
3. the calculation method of Computer CPU Utilization Ratio according to claim 2, which is characterized in that the preset model packet
The first model and the second model are included,
It is described to be based on preset model, the physical core that the utilization rate of the thread run on the Core is converted to the Core is utilized
Rate specifically includes:
Based on first model, the utilization rate of the thread run on the Core is converted to the utilization rate of the Core;
Based on second model, the utilization rate of the Core is converted to the physical core utilization rate of the Core.
4. the calculation method of Computer CPU Utilization Ratio according to claim 3, which is characterized in that transported when on the Core
When k thread of row, k is integer, and k >=2, first model, specifically:
Wherein, thUtilization rate for h-th of the thread run on the Core, x are the utilization of the Core
Rate.
5. the calculation method of Computer CPU Utilization Ratio according to claim 4, which is characterized in that second model, tool
Body are as follows:
Y=2x-x2, wherein y is the physical core utilization rate of the Core.
6. the calculation method of Computer CPU Utilization Ratio according to claim 1-5, which is characterized in that the base
The utilization rate of the CPU is calculated in the physical core utilization rate of one or more of Core, is specifically included:
The average physical core utilization rate that physical core utilization rate based on one or more of Core obtains the Core of the CPU is made
For the utilization rate of the CPU.
7. the calculation method of Computer CPU Utilization Ratio according to claim 1-6, which is characterized in that the meter
Calculation machine includes multiple CPU, and multiple cpu busy percentages of the computer are the average utilization of the multiple CPU.
8. a kind of computing device of Computer CPU Utilization Ratio, which is characterized in that the computer includes CPU, and the CPU includes one
At least two threads are run on a or multiple physical core Core, each Core, described device includes: acquiring unit and calculates single
Member;
The acquiring unit, for obtaining the utilization rate of the thread run on each Core at least one described Core;
The computing unit calculates the physical core for running the Core for the utilization rate based on the thread run on the Core
Utilization rate;
The computing unit is also used to calculate the utilization of the CPU based on the physical core utilization rate of one or more of Core
Rate.
9. the computing device of Computer CPU Utilization Ratio according to claim 8, which is characterized in that the computing unit, tool
Body is used to be based on preset model, and the physical core that the utilization rate of the thread run on the Core is converted to the Core is utilized
Rate.
10. the computing device of Computer CPU Utilization Ratio according to claim 9, which is characterized in that the preset model packet
The first model and the second model are included,
The computing unit is specifically used for being based on first model, the utilization rate of the thread run on the Core is converted
For the utilization rate of the Core;
The computing unit is specifically used for being based on second model, the utilization rate of the Core is converted to the Core's
Physical core utilization rate.
11. the computing device of Computer CPU Utilization Ratio according to claim 10, which is characterized in that when on the Core
When running k thread, k is integer, and k >=2, first model, specifically:
Wherein, thUtilization rate for h-th of the thread run on the Core, x are the utilization of the Core
Rate.
12. the computing device of Computer CPU Utilization Ratio according to claim 11, which is characterized in that second model,
Specifically:
Y=2x-x2, wherein y is the physical core utilization rate of the Core.
13. according to the computing device of the described in any item Computer CPU Utilization Ratios of claim 8-12, which is characterized in that described
Computing unit is specifically used for:
The average physical core utilization rate that physical core utilization rate based on one or more of Core obtains the Core of the CPU is made
For the utilization rate of the CPU.
14. according to the computing device of the described in any item Computer CPU Utilization Ratios of claim 8-13, which is characterized in that described
Computer includes multiple CPU, and multiple cpu busy percentages of the computer are the average utilization of the multiple CPU.
15. a kind of computer storage medium, it is stored with computer program code in the computer storage medium, feature exists
In when the computer program code is run on a processor, so that the processor is executed such as any one of claim 1-7
The calculation method of the Computer CPU Utilization Ratio.
16. a kind of computer, which is characterized in that the computer includes processor and interface, the processor and interface communication,
The processor requires the calculation method of the described in any item Computer CPU Utilization Ratios of 1-7 for perform claim.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810430440.9A CN108959020B (en) | 2018-05-08 | 2018-05-08 | Method and device for calculating CPU utilization rate of computer |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201810430440.9A CN108959020B (en) | 2018-05-08 | 2018-05-08 | Method and device for calculating CPU utilization rate of computer |
Publications (2)
Publication Number | Publication Date |
---|---|
CN108959020A true CN108959020A (en) | 2018-12-07 |
CN108959020B CN108959020B (en) | 2021-01-12 |
Family
ID=64499689
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201810430440.9A Active CN108959020B (en) | 2018-05-08 | 2018-05-08 | Method and device for calculating CPU utilization rate of computer |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN108959020B (en) |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN110609773A (en) * | 2019-09-05 | 2019-12-24 | 北京宝兰德软件股份有限公司 | Java thread CPU utilization rate obtaining method and device |
US11106481B2 (en) | 2019-04-19 | 2021-08-31 | Red Hat, Inc. | Safe hyper-threading for virtual machines |
Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050138442A1 (en) * | 2003-12-22 | 2005-06-23 | International Business Machines Corporation | Method and system for energy management in a simultaneous multi-threaded (SMT) processing system including per-thread device usage monitoring |
US20100162018A1 (en) * | 2008-12-05 | 2010-06-24 | Stmicroelectronics Pvt. Ltd. | System and method for optimizing electrical power consumption |
CN101876933A (en) * | 2009-04-28 | 2010-11-03 | 深圳富泰宏精密工业有限公司 | Analysis system and method for CPU utilization rate |
CN103649864A (en) * | 2011-06-27 | 2014-03-19 | 英特尔公司 | Increasing power efficiency of turbo mode operation in a processor |
CN104081315A (en) * | 2011-12-15 | 2014-10-01 | 英特尔公司 | Method, apparatus and system for energy efficiency and energy conservation including thread consolidation |
US20150033240A1 (en) * | 2013-07-23 | 2015-01-29 | Fujitsu Limited | Measuring method, a non-transitory computer-readable storage medium, and information processing apparatus |
US20160087859A1 (en) * | 2014-09-23 | 2016-03-24 | Chia-Chee Kuan | Monitor a data center infrastructure |
CN106293981A (en) * | 2016-07-29 | 2017-01-04 | 浪潮电子信息产业股份有限公司 | A kind of detection method of server CPU Hyper-Threading |
US20180107523A1 (en) * | 2016-01-13 | 2018-04-19 | International Business Machines Corporation | Managing a set of wear-leveling data using a set of thread events |
CN108255572A (en) * | 2016-12-29 | 2018-07-06 | 华为技术有限公司 | A kind of VCPU switching methods and physical host |
JP2018139064A (en) * | 2017-02-24 | 2018-09-06 | 日本電信電話株式会社 | Virtual computer system and resource allocation method thereof |
CN106104479B (en) * | 2014-03-27 | 2019-06-11 | 国际商业机器公司 | Standby time accumulation in multi-threaded computer system |
-
2018
- 2018-05-08 CN CN201810430440.9A patent/CN108959020B/en active Active
Patent Citations (12)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US20050138442A1 (en) * | 2003-12-22 | 2005-06-23 | International Business Machines Corporation | Method and system for energy management in a simultaneous multi-threaded (SMT) processing system including per-thread device usage monitoring |
US20100162018A1 (en) * | 2008-12-05 | 2010-06-24 | Stmicroelectronics Pvt. Ltd. | System and method for optimizing electrical power consumption |
CN101876933A (en) * | 2009-04-28 | 2010-11-03 | 深圳富泰宏精密工业有限公司 | Analysis system and method for CPU utilization rate |
CN103649864A (en) * | 2011-06-27 | 2014-03-19 | 英特尔公司 | Increasing power efficiency of turbo mode operation in a processor |
CN104081315A (en) * | 2011-12-15 | 2014-10-01 | 英特尔公司 | Method, apparatus and system for energy efficiency and energy conservation including thread consolidation |
US20150033240A1 (en) * | 2013-07-23 | 2015-01-29 | Fujitsu Limited | Measuring method, a non-transitory computer-readable storage medium, and information processing apparatus |
CN106104479B (en) * | 2014-03-27 | 2019-06-11 | 国际商业机器公司 | Standby time accumulation in multi-threaded computer system |
US20160087859A1 (en) * | 2014-09-23 | 2016-03-24 | Chia-Chee Kuan | Monitor a data center infrastructure |
US20180107523A1 (en) * | 2016-01-13 | 2018-04-19 | International Business Machines Corporation | Managing a set of wear-leveling data using a set of thread events |
CN106293981A (en) * | 2016-07-29 | 2017-01-04 | 浪潮电子信息产业股份有限公司 | A kind of detection method of server CPU Hyper-Threading |
CN108255572A (en) * | 2016-12-29 | 2018-07-06 | 华为技术有限公司 | A kind of VCPU switching methods and physical host |
JP2018139064A (en) * | 2017-02-24 | 2018-09-06 | 日本電信電話株式会社 | Virtual computer system and resource allocation method thereof |
Cited By (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US11106481B2 (en) | 2019-04-19 | 2021-08-31 | Red Hat, Inc. | Safe hyper-threading for virtual machines |
CN110609773A (en) * | 2019-09-05 | 2019-12-24 | 北京宝兰德软件股份有限公司 | Java thread CPU utilization rate obtaining method and device |
Also Published As
Publication number | Publication date |
---|---|
CN108959020B (en) | 2021-01-12 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
US7809918B1 (en) | Method, apparatus, and computer-readable medium for providing physical memory management functions | |
US20170351607A1 (en) | Multi-Section Garbage Collection | |
US9710380B2 (en) | Managing shared cache by multi-core processor | |
US9753851B2 (en) | Multi-section garbage collection system including real-time garbage collection scheduling | |
CN111324427B (en) | Task scheduling method and device based on DSP | |
CN109669774A (en) | Quantization method, method of combination, device and the network equipment of hardware resource | |
US20210258265A1 (en) | Resource management for components of a virtualized execution environment | |
CN110020859A (en) | A kind of block chain common recognition method, apparatus and electronic equipment executed parallel | |
WO2022139920A1 (en) | Resource manager access control | |
CN108959020A (en) | A kind of calculation method and device of Computer CPU Utilization Ratio | |
US20220086226A1 (en) | Virtual device portability | |
US11237761B2 (en) | Management of multiple physical function nonvolatile memory devices | |
CN108701052A (en) | Send method, apparatus and system of the affairs without tracking | |
US20110289284A1 (en) | Multi-processor device and inter-process communication method thereof | |
CN104657195A (en) | Resource binding method and device | |
CN107943605A (en) | A kind of storage card processing method and processing device | |
US11249760B2 (en) | Parameter management between programs | |
US10268218B2 (en) | Decreasing the internal temperature of a computer in response to corrosion | |
CN108279968B (en) | Virtual machine resource scheduling method and device | |
CN109710278A (en) | A kind of method, apparatus and terminal device unloading application program | |
US20230147878A1 (en) | Implementing heterogeneous memory within a programming environment | |
CN104573421A (en) | Multi-partition based MCU chip information protection method and device | |
CN112346879B (en) | Process management method, device, computer equipment and storage medium | |
CN104778144B (en) | Intelligent terminal method of controlling operation thereof and device based on OTG | |
WO2016134637A1 (en) | Bar code recognition method and device |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |