CN107491378A - A kind of determination method and device of CPU usage - Google Patents

A kind of determination method and device of CPU usage Download PDF

Info

Publication number
CN107491378A
CN107491378A CN201710771205.3A CN201710771205A CN107491378A CN 107491378 A CN107491378 A CN 107491378A CN 201710771205 A CN201710771205 A CN 201710771205A CN 107491378 A CN107491378 A CN 107491378A
Authority
CN
China
Prior art keywords
timeslice
target process
time piece
cpu
piece
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN201710771205.3A
Other languages
Chinese (zh)
Inventor
楚泽彤
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou DPTech Technologies Co Ltd
Original Assignee
Hangzhou DPTech Technologies Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou DPTech Technologies Co Ltd filed Critical Hangzhou DPTech Technologies Co Ltd
Priority to CN201710771205.3A priority Critical patent/CN107491378A/en
Publication of CN107491378A publication Critical patent/CN107491378A/en
Pending legal-status Critical Current

Links

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3003Monitoring arrangements specially adapted to the computing system or computing system component being monitored
    • G06F11/3024Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a central processing unit [CPU]

Landscapes

  • Engineering & Computer Science (AREA)
  • Computing Systems (AREA)
  • Physics & Mathematics (AREA)
  • Theoretical Computer Science (AREA)
  • Mathematical Physics (AREA)
  • Quality & Reliability (AREA)
  • General Engineering & Computer Science (AREA)
  • General Physics & Mathematics (AREA)
  • Debugging And Monitoring (AREA)

Abstract

The present invention provides a kind of determination method and device of CPU usage, and methods described includes:If regulation goal process, the mark based on the target process obtains structure corresponding to the target process;Based on the structure, CPU occupied second timeslices when obtaining the very first time piece and the called last target process that target process when the last target process is called takes;Obtain the 3rd timeslice of current goal process occupancy and current CPU total time piece;Based on the very first time piece, second timeslice, the 3rd timeslice and the total time piece, the CPU usage of the target process is determined.Using the embodiment of the present invention, system resource is saved, improves the stability of system, improves system treatment effeciency.

Description

A kind of determination method and device of CPU usage
Technical field
The present invention relates to the determination method and device of network communication technology field, more particularly to a kind of CPU usage.
Background technology
Generally, CPU records the progress information currently run in process chained list, and CPU travels through by timer period Process chained list, to obtain the CPU time slice that process takes in the unit interval.The CPU that CPU is taken by process in the unit interval Timeslice and the ratio of CPU total time pieces, determine the CPU usage of process.
In the prior art, due to the use of timer, system resource is wasted;The high-speed cruising of timer can also influence The stability of system, cause the stability of a system low, treatment effeciency is low.
The content of the invention
In view of this, the present invention provides a kind of determination method and device of CPU usage, with solve system resource waste, The problem of stability of a system is low, treatment effeciency is low.
To achieve the above object, it is as follows to provide technical scheme by the present invention:
According to the first aspect of the invention, it is proposed that a kind of determination method of CPU usage, methods described include:
If regulation goal process, the mark based on the target process obtains structure corresponding to the target process;
Based on the structure, obtain the last target process it is called when the target process take first when Between piece and CPU occupied second timeslices during the called last target process;
Obtain the 3rd timeslice of current goal process occupancy and current CPU total time piece;
Based on the very first time piece, second timeslice, the 3rd timeslice and the total time piece, institute is determined State the CPU usage of target process.
According to the second aspect of the invention, it is proposed that a kind of determining device of CPU usage, including:
First acquisition module, if being configured as regulation goal process, the mark based on the target process obtains the mesh Structure corresponding to mark process;
Second acquisition module, it is configured as being based on the structure, obtains the called when institute of the last target process CPU occupied second timeslices when stating the very first time piece and the called last target process of target process occupancy;
3rd acquisition module, be configured as obtaining the 3rd timeslice that current goal process takes and current CPU it is total when Between piece;
First determining module, it is configured as based on the very first time piece, second timeslice, the 3rd timeslice With the total time piece, the CPU usage of the target process is determined.
From above technical scheme, if target process scheduling occurs, by structure corresponding to target process, obtain CPU is occupied when the very first time piece and last target process that target process takes when last target process is called are called Second timeslice, and by statistical module obtain the 3rd timeslice that current goal process takes and current CPU it is total when Between piece, be based ultimately upon very first time piece, the second timeslice, the 3rd timeslice and total time piece, determine target process CPU take Rate, due to not being related to the use of timer, system resource is saved, the introducing of structure improves the stability of system, lifting System treatment effeciency.
Brief description of the drawings
Fig. 1 is the embodiment flow chart of the determination method of a CPU usage provided by the invention;
Fig. 2 is the embodiment flow chart of the determination method of another CPU usage provided by the invention;
Fig. 3 is a kind of CPU provided by the invention hardware structure diagram;
Fig. 4 is the embodiment block diagram of the determining device of a CPU usage provided by the invention;
Fig. 5 is the embodiment block diagram of the determining device of another CPU usage provided by the invention.
Embodiment
Here exemplary embodiment will be illustrated in detail, its example is illustrated in the accompanying drawings.Following description is related to During accompanying drawing, unless otherwise indicated, the same numbers in different accompanying drawings represent same or analogous key element.Following exemplary embodiment Described in embodiment do not represent and the consistent all embodiments of the present invention.On the contrary, they be only with it is such as appended The example of the consistent apparatus and method of some aspects being described in detail in claims, of the invention.
It is only merely for the purpose of description specific embodiment in terminology used in the present invention, and is not intended to be limiting the present invention. It is also intended in " one kind " of the singulative of the invention with used in appended claims, " described " and "the" including majority Form, unless context clearly shows that other implications.It is also understood that term "and/or" used herein refers to and wrapped Containing the associated list items purpose of one or more, any or all may be combined.
It will be appreciated that though various information, but this may be described using term first, second, third, etc. in the present invention A little information should not necessarily be limited by these terms.These terms are only used for same type of information being distinguished from each other out.For example, do not departing from In the case of the scope of the invention, the first information can also be referred to as the second information, and similarly, the second information can also be referred to as One information.Depending on linguistic context, word as used in this " if " can be construed to " ... when " or " when ... When " or " in response to determining ".
Fig. 1 is the embodiment flow chart of the determination method of a CPU usage provided by the invention, the CPU usage The method of determination can be applied in CPU, as shown in figure 1, the determination method of the CPU usage comprises the following steps:
Step 101:Determine whether regulation goal process, if regulation goal process, perform step 102- steps 105, if Target process is not dispatched, then performs step 106.
Step 102:Mark based on target process obtains structure corresponding to target process.
Step 103:Based on structure, the very first time piece that target process takes when last target process is called is obtained CPU occupied second timeslices when being called with last target process.
Step 104:Obtain the 3rd timeslice of current goal process occupancy and current CPU total time piece.
Step 105:Based on very first time piece, the second timeslice, the 3rd timeslice and total time piece, target process is determined CPU usage.
Step 106:The occupancy for determining target process is zero.
In a step 101, in one embodiment, CPU determines whether regulation goal process, if regulation goal process, holds Row step 102- steps 105, if not dispatching target process, perform step 106.
In a step 102, in one embodiment, the corresponding structure of each process, different structures are corresponding not With mark, mark can be that process name claim, sequence number etc. can distinguish the mark of different structure body.If CPU regulation goal processes, CPU obtains the mark of target process, and marks of the CPU based on target process obtains structure corresponding to target process, the structure Corresponding mark is consistent with the mark of target process.
In step 103, in one embodiment, CPU obtains target when last target process is called from structure CPU occupied second timeslices when the very first time piece and last target process that process takes are called.Art technology Personnel are it is understood that include at least one data in structure.It is as follows, it is a structure example:
Wherein, " process_usage " is structure name;" long " is the specifier of data type;“last_process_ Time " is the very first time piece that target process takes when last target process is called;" last_cpu_time " is the last time CPU occupied second timeslices when target process is called.
At step 104, in one embodiment, CPU can obtain that current goal process takes by statistical module the The total time piece of three timeslices and current CPU.It will be appreciated by persons skilled in the art that the 3rd of current goal process occupancy the Timeslice and current CPU total time piece can be counted by statistical module, specifically, when how statistical module counts the 3rd Between piece and current CPU total time piece process refer to the associated description of prior art.
In step 105, in one embodiment, CPU can determine target process by formula y=(a-b)/(c-d) CPU usage.Wherein a is the 3rd timeslice, and b is very first time piece, and c is current CPU total time piece, and d is the second timeslice. It will be appreciated by persons skilled in the art that formula y=(a-b)/(c-d) is merely illustrative, can not be formed to this hair Bright limitation.
In step 106, in one embodiment, because target process is not scheduled, therefore CPU determines accounting for for target process It is zero with rate.
In the embodiment of the present invention, if target process scheduling occurs, by structure corresponding to target process, upper one is obtained CPU is occupied when the very first time piece and last target process that target process takes when secondary target process is called are called Second timeslice, and the 3rd timeslice of current goal process occupancy and current CPU total time piece are obtained by statistical module, Very first time piece, the second timeslice, the 3rd timeslice and total time piece are based ultimately upon, determines the CPU usage of target process, by In the use for not being related to timer, system resource is saved, the introducing of structure improves the stability of system, improves system Treatment effeciency.
Fig. 2 is the embodiment flow chart of the determination method of a CPU usage provided by the invention, with reference to Fig. 1, to CPU Specifically how very first time piece, the second timeslice, the 3rd timeslice and total time piece are based on, determine that the CPU of target process takes Rate it is illustrative, as shown in Fig. 2 comprising the following steps:
Step 201:Determine that the very first time between very first time piece and the 3rd timeslice is poor.
Step 202:Determine the second time difference between the second timeslice and total time piece.
Step 203:Proportionate relationship based on very first time difference with the second time difference, determine the CPU usage of target process.
Step 204:Very first time piece is updated to the 3rd timeslice, the second timeslice is updated to total time piece.
In step 201- steps 203, with reference to the associated description in Fig. 1 steps 105, with CPU by formula y=(a-b)/ (c-d) exemplified by the CPU usage for determining target process, wherein a is the 3rd timeslice, and b is very first time piece, and c is current CPU's Total time piece, d is the second timeslice.CPU determines that the very first time between very first time piece b and the 3rd timeslice a is poor;CPU is true Fixed the second time difference between second timeslice d and total time piece c;Ratios of the CPU based on very first time difference with the second time difference Relation, determine the CPU usage y of target process.
In step 204, very first time piece is updated to the 3rd timeslice by CPU, and the second timeslice is updated into total time Piece, when being called in order to which target process is next, after the very first time piece after renewal can be obtained by structure and is updated Second timeslice.It should be noted that the numerical value of very first time piece and second timeslice of the structure in original state is zero. It will be appreciated by persons skilled in the art that step 204 can be after step 104 either step front/rear execution, walk herein Rapid 204 execution sequence is merely illustrative.
In the embodiment of the present invention, CPU has been described in detail and is based on very first time piece, the second timeslice, the 3rd timeslice and total Timeslice, determines the process of the CPU usage of target process, while CPU is by the very first time piece in structure and the second time Piece is updated so that can be continuing with structure when target process is called next time and be determined occupancy, improve system Treatment effeciency.
Corresponding to the determination method of above-mentioned CPU usage, the invention also provides the hardware structure diagram of the CPU shown in Fig. 3. Fig. 3 is refer to, in hardware view, the CPU includes processor, internal bus, network interface, internal memory and non-volatile memories Device, the hardware being also possible that certainly required for other business.Processor calculates corresponding to being read from nonvolatile memory Machine program is into internal memory and then runs, and the determining device of CPU usage is formed on logic level.Certainly, except software is realized Outside mode, the present invention is not precluded from other implementations, such as mode of logical device or software and hardware combining etc., also It is that the executive agent for saying following handling process is not limited to each logic unit or hardware or logical device.
Fig. 4 is the embodiment block diagram of the determining device of a CPU usage provided by the invention, as shown in figure 4, the CPU The determining device of occupancy can include:First acquisition module 41, the second acquisition module 42, the 3rd acquisition module 43, first are true Cover half block 44, wherein:
First acquisition module 41, if being configured as regulation goal process, the mark based on target process obtains target process Corresponding structure;
Second acquisition module 42, it is configured as being based on structure, obtains target process when last target process is called CPU occupied second timeslices when the very first time piece and last target process of occupancy are called;
3rd acquisition module 43, it is configured as obtaining the total of the 3rd timeslice that current goal process takes and current CPU Timeslice;
First determining module 44, it is configured as being based on very first time piece, the second timeslice, the 3rd timeslice and total time Piece, determine the CPU usage of target process.
Fig. 5 is the embodiment block diagram of the determining device of another CPU usage provided by the invention, as shown in figure 5, upper On the basis of stating embodiment illustrated in fig. 4, the first determining module 44 includes:
First determination sub-module 441, it is configured to determine that the very first time between very first time piece and the 3rd timeslice is poor;
Second determination sub-module 442, the second time difference being configured to determine that between the second timeslice and total time piece;
3rd determination sub-module 443, it is configured as, based on very first time difference and the proportionate relationship of the second time difference, determining mesh The CPU usage of mark process.
In one embodiment, the determining device of CPU usage also includes:
Timeslice update module 45, it is configured as very first time piece being updated to the 3rd timeslice, by the second timeslice more It is newly total time piece.
In one embodiment, the determining device of CPU usage also includes:
Second determining module 46, if being configured as unscheduled target process, it is determined that the occupancy of target process is zero.
The function of unit and the implementation process of effect specifically refer to and step are corresponded in the above method in said apparatus Implementation process, it will not be repeated here.
For device embodiment, because it corresponds essentially to embodiment of the method, so related part is real referring to method Apply the part explanation of example.Device embodiment described above is only schematical, wherein described be used as separating component The unit of explanation can be or may not be physically separate, can be as the part that unit is shown or can also It is not physical location, you can with positioned at a place, or can also be distributed on multiple NEs.Can be according to reality Need to select some or all of module therein to realize the purpose of the present invention program.Those of ordinary skill in the art are not paying In the case of going out creative work, you can to understand and implement.
As seen from the above-described embodiment, if target process scheduling occurs, by structure corresponding to target process, in acquisition CPU is occupied when target process takes when target process is called very first time piece and last target process are called The second timeslice, and pass through statistical module and obtain the 3rd timeslice that current goal process takes and current CPU total time Piece, very first time piece, the second timeslice, the 3rd timeslice and total time piece are based ultimately upon, determine that the CPU of target process takes Rate, due to not being related to the use of timer, system resource is saved, the introducing of structure improves the stability of system, lifting System treatment effeciency.
Those skilled in the art will readily occur to the present invention its after considering specification and putting into practice invention disclosed herein Its embodiment.It is contemplated that cover the present invention any modification, purposes or adaptations, these modifications, purposes or Person's adaptations follow the general principle of the present invention and including undocumented common knowledges in the art of the invention Or conventional techniques.Description and embodiments are considered only as exemplary, and true scope and spirit of the invention are by following Claim is pointed out.
It should also be noted that, term " comprising ", "comprising" or its any other variant are intended to nonexcludability Comprising so that process, method, commodity or equipment including a series of elements not only include those key elements, but also wrapping Include the other element being not expressly set out, or also include for this process, method, commodity or equipment intrinsic want Element.In the absence of more restrictions, the key element limited by sentence "including a ...", it is not excluded that wanted including described Other identical element also be present in the process of element, method, commodity or equipment.
The foregoing is merely illustrative of the preferred embodiments of the present invention, is not intended to limit the invention, all essences in the present invention God any modification, equivalent substitution and improvements done etc., should be included within the scope of protection of the invention with principle.

Claims (8)

1. a kind of determination method of CPU usage, it is characterised in that methods described includes:
If regulation goal process, the mark based on the target process obtains structure corresponding to the target process;
Based on the structure, the very first time piece that the target process takes when the last target process is called is obtained CPU occupied second timeslices when being called with the last target process;
Obtain the 3rd timeslice of current goal process occupancy and current CPU total time piece;
Based on the very first time piece, second timeslice, the 3rd timeslice and the total time piece, the mesh is determined The CPU usage of mark process.
2. according to the method for claim 1, it is characterised in that described based on the very first time piece, second time Piece, the 3rd timeslice and the total time piece, the CPU usage of the target process is determined, including:
Determine that the very first time between the very first time piece and the 3rd timeslice is poor;
Determine the second time difference between second timeslice and the total time piece;
It is poor with the proportionate relationship of second time difference based on the very first time, determine the CPU usage of the target process.
3. according to the method for claim 1, it is characterised in that methods described also includes:
The very first time piece is updated to the 3rd timeslice, second timeslice is updated to the total time piece.
4. according to the method for claim 1, it is characterised in that methods described also includes:
If unscheduled target process, it is determined that the occupancy of the target process is zero.
5. a kind of determining device of CPU usage, it is characterised in that described device includes:
First acquisition module, if being configured as regulation goal process, the mark based on the target process obtains the target and entered Structure corresponding to journey;
Second acquisition module, it is configured as being based on the structure, obtains mesh when the last target process is called CPU occupied second timeslices when very first time piece and the called last target process that mark process takes;
3rd acquisition module, it is configured as obtaining the 3rd timeslice of current goal process occupancy and current CPU total time piece;
First determining module, it is configured as being based on the very first time piece, second timeslice, the 3rd timeslice and institute Total time piece is stated, determines the CPU usage of the target process.
6. device according to claim 5, it is characterised in that first determining module includes:
First determination sub-module, the very first time being configured to determine that between the very first time piece and the 3rd timeslice Difference;
Second determination sub-module, the second time difference being configured to determine that between second timeslice and the total time piece;
3rd determination sub-module, it is poor with the proportionate relationship of second time difference based on the very first time to be configured as, it is determined that The CPU usage of the target process.
7. device according to claim 5, it is characterised in that described device also includes:
Timeslice update module, it is configured as the very first time piece being updated to the 3rd timeslice, during by described second Between piece be updated to the total time piece.
8. device according to claim 5, it is characterised in that described device also includes:
Second determining module, if being configured as unscheduled target process, it is determined that the occupancy of the target process is zero.
CN201710771205.3A 2017-08-31 2017-08-31 A kind of determination method and device of CPU usage Pending CN107491378A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201710771205.3A CN107491378A (en) 2017-08-31 2017-08-31 A kind of determination method and device of CPU usage

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201710771205.3A CN107491378A (en) 2017-08-31 2017-08-31 A kind of determination method and device of CPU usage

Publications (1)

Publication Number Publication Date
CN107491378A true CN107491378A (en) 2017-12-19

Family

ID=60646041

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201710771205.3A Pending CN107491378A (en) 2017-08-31 2017-08-31 A kind of determination method and device of CPU usage

Country Status (1)

Country Link
CN (1) CN107491378A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111427758A (en) * 2020-03-17 2020-07-17 北京百度网讯科技有限公司 Task calculation amount determining method and device and electronic equipment
CN112764934A (en) * 2021-01-29 2021-05-07 上海弘积信息科技有限公司 Method for calculating CPU utilization rate of load balancing equipment

Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103458020A (en) * 2013-08-28 2013-12-18 华南理工大学 Method and system for monitoring cloud platform based on XCP
CN103455407A (en) * 2013-09-03 2013-12-18 小米科技有限责任公司 Mobile terminal CPU (Central Processing Unit) occupation rate monitoring method and device and mobile terminal
CN104375898A (en) * 2014-11-20 2015-02-25 无锡悟莘科技有限公司 Mobile terminal CPU occupancy rate optimization method
CN106708709A (en) * 2015-07-30 2017-05-24 中兴通讯股份有限公司 CPU occupancy rate detection method and device

Patent Citations (4)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103458020A (en) * 2013-08-28 2013-12-18 华南理工大学 Method and system for monitoring cloud platform based on XCP
CN103455407A (en) * 2013-09-03 2013-12-18 小米科技有限责任公司 Mobile terminal CPU (Central Processing Unit) occupation rate monitoring method and device and mobile terminal
CN104375898A (en) * 2014-11-20 2015-02-25 无锡悟莘科技有限公司 Mobile terminal CPU occupancy rate optimization method
CN106708709A (en) * 2015-07-30 2017-05-24 中兴通讯股份有限公司 CPU occupancy rate detection method and device

Non-Patent Citations (2)

* Cited by examiner, † Cited by third party
Title
XYZ-X: "task_struct结构体(PCB)描述", 《HTTPS://BLOG.CSDN.NET/XYZBAIHAIPING/ARTICLE/DETAILS/51591890》 *
天使羊波波闪耀光芒: "Linux time函数", 《WWW.LIVE-IN.ORG/ARCHIVES/2248.HTML》 *

Cited By (3)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN111427758A (en) * 2020-03-17 2020-07-17 北京百度网讯科技有限公司 Task calculation amount determining method and device and electronic equipment
CN112764934A (en) * 2021-01-29 2021-05-07 上海弘积信息科技有限公司 Method for calculating CPU utilization rate of load balancing equipment
CN112764934B (en) * 2021-01-29 2024-01-30 上海弘积信息科技有限公司 Calculation method for CPU utilization rate of load balancing equipment

Similar Documents

Publication Publication Date Title
Liu et al. A new improved NEH heuristic for permutation flowshop scheduling problems
CN101419579B (en) Apparatus and method for providing quality of service on DRAM
CN104484203B (en) For the method for exhibiting data and device of table data displaying control
CN104268018B (en) Job scheduling method and job scheduler in a kind of Hadoop clusters
CN106372977B (en) A kind of processing method and equipment of virtual account
CN107153565A (en) Configure the method and its network equipment of resource
CN107404481B (en) User information recognition methods and device
CN109767070A (en) Case distribution method, device, computer equipment and storage medium
CN103748559B (en) The method and system for carrying out processor workload partition is fed back using work requirements
CN105988930A (en) Test case generation method and device
CN110008744A (en) Data desensitization method and relevant apparatus
CN107491378A (en) A kind of determination method and device of CPU usage
Li et al. MapReduce task scheduling in heterogeneous geo-distributed data centers
CN104268293B (en) The index treating method and apparatus that can not add up in database
CN108268312A (en) Method for scheduling task and scheduler
Singh et al. Analysis of single server finite queueing model with reneging
CN110321357A (en) A kind of read/writing control method, device and server
van de Vrugt et al. Assigning treatment rooms at the emergency department
CN106874291A (en) The processing method and processing device of text classification
US20150195122A1 (en) Method and System for Transparent Network Acceleration
CN107562542A (en) distributed data processing system data partition method and device
CN104462448B (en) A kind of packet name classification method and device
CN103530742B (en) Improve the method and device of scheduling arithmetic speed
CN110209656A (en) Data processing method and device
CN108984427A (en) The processing method and processing device of memory in a kind of equipment based on Shen prestige framework

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
RJ01 Rejection of invention patent application after publication

Application publication date: 20171219

RJ01 Rejection of invention patent application after publication