CN110609773A - Java thread CPU utilization rate obtaining method and device - Google Patents

Java thread CPU utilization rate obtaining method and device Download PDF

Info

Publication number
CN110609773A
CN110609773A CN201910836931.8A CN201910836931A CN110609773A CN 110609773 A CN110609773 A CN 110609773A CN 201910836931 A CN201910836931 A CN 201910836931A CN 110609773 A CN110609773 A CN 110609773A
Authority
CN
China
Prior art keywords
java
time period
preset time
running time
thread
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
CN201910836931.8A
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.)
Beijing Boln Software Ltd By Share Ltd
Original Assignee
Beijing Boln Software Ltd By Share 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 Beijing Boln Software Ltd By Share Ltd filed Critical Beijing Boln Software Ltd By Share Ltd
Priority to CN201910836931.8A priority Critical patent/CN110609773A/en
Publication of CN110609773A publication Critical patent/CN110609773A/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/302Monitoring arrangements specially adapted to the computing system or computing system component being monitored where the computing system component is a software system
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06FELECTRIC DIGITAL DATA PROCESSING
    • G06F11/00Error detection; Error correction; Monitoring
    • G06F11/30Monitoring
    • G06F11/3051Monitoring arrangements for monitoring the configuration of the computing system or of the computing system component, e.g. monitoring the presence of processing resources, peripherals, I/O links, software programs

Abstract

The embodiment of the invention provides a method and a device for acquiring the CPU utilization rate of a Java thread, wherein the method comprises the following steps: acquiring the running time of each Java thread in a preset time period, the number of CPU cores and the running time of a Java virtual machine in the preset time period every other preset time period; and acquiring the CPU utilization rate of the Java threads according to the running time of each Java thread in the preset time period, the CPU core number and the running time of the Java virtual machine in the preset time period. The embodiment of the invention can accurately acquire the CPU utilization rate of the Java thread.

Description

Java thread CPU utilization rate obtaining method and device
Technical Field
The invention relates to the technical field of computers, in particular to a method and a device for acquiring the CPU utilization rate of a Java thread.
Background
With the progress of science and technology, computer technology is rapidly developing at a rapid pace.
At present, most of the existing methods for calculating the CPU (central processing unit) utilization rate are to calculate the CPU utilization rate of a process (i.e. the CPU utilization rate occupied by the process during operation), and the starting point is to calculate the value of the process accurately. The method for calculating the CPU utilization rate of the existing computing process comprises the following main implementation modes: based on an operating system, if a result is obtained by calling a linux command through a script, data processing is carried out; or the computation of the CPU is completed through Tick counting based on the VxWorks operating system, and the other more precise computation mode is still the VxWorks operating system and is combined with hardware and related command control, so that the CPU utilization rate of the process is more precisely computed.
However, the above existing methods for calculating the CPU utilization rate have too limited usage scenarios, and almost depend on the operating system, and even the operating system to which a part of the calculation method is applicable is not commonly used; moreover, the calculation result of the existing method for calculating the CPU utilization rate is directed to the process, not to the Java thread, and the pursuit of accuracy causes the calculation to be complex.
Disclosure of Invention
Aiming at the problems in the prior art, the embodiment of the invention provides a method and a device for acquiring the CPU utilization rate of a Java thread.
The embodiment of the invention provides a method for acquiring the CPU utilization rate of a Java thread, which comprises the following steps:
acquiring the running time of each Java thread in a preset time period, the number of CPU cores and the running time of a Java virtual machine in the preset time period every other preset time period;
and acquiring the CPU utilization rate of the Java threads according to the running time of each Java thread in the preset time period, the CPU core number and the running time of the Java virtual machine in the preset time period.
Optionally, the acquiring, every other preset time period, the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period includes:
and acquiring the running time of each Java thread in the preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period through an interface provided by JDK of Java every other preset time period.
Optionally, the interface provided by Java JDK includes: a management interface ThreadMXBean of a Java virtual machine thread system, a management interface OperatingSystemMXBean of an operating system and a management interface RuntimmeMXBean of a Java virtual machine runtime system;
correspondingly, every other preset time period, the running time of each Java thread in the preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period are obtained through an interface provided by Java JDK, including:
and acquiring the running time of each Java thread in a preset time period through a ThreadMXBean every other preset time period, acquiring the number of CPU cores through an OperatingSystemMXBean, and acquiring the running time of the Java virtual machine in the preset time period through a RuntimeMXBean.
Optionally, the obtaining the CPU utilization of the Java threads according to the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period includes:
adding the running time of each Java thread in the preset time period to obtain the total running time value of all Java threads in the preset time period;
multiplying the running time of the Java virtual machine in the preset time period by the number of CPU cores to obtain the total running time value of the Java virtual machines of all CPUs in the preset time period;
and acquiring the CPU utilization rate of the Java threads according to the total running time values of all the Java threads in the preset time period and the total running time values of the Java virtual machines of all the CPUs in the preset time period.
Optionally, the obtaining the usage rate of the Java thread CPUs according to the total runtime value of all Java threads in the preset time period and the total runtime value of the Java virtual machines of all CPUs in the preset time period includes:
calculating the CPU utilization rate of the Java threads according to the total running time values of all the Java threads in the preset time period and the total running time values of all the Java virtual machines of the CPUs in the preset time period by using a first formula;
wherein the first formula is:
Pcpufor Java threads CPU usage, t1The total running time value, t, of all Java threads in the preset time period2And the total running time value of the Java virtual machines of all the CPUs in the preset time period.
The embodiment of the invention provides a Java thread CPU utilization rate acquisition device, which comprises:
the first acquisition module is used for acquiring the running time of each Java thread in a preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period every other preset time period;
and the second acquisition module is used for acquiring the CPU utilization rate of the Java threads according to the running time of each Java thread in the preset time period, the CPU core number and the running time of the Java virtual machine in the preset time period.
Optionally, the first obtaining module is specifically configured to
And acquiring the running time of each Java thread in the preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period through an interface provided by JDK of Java every other preset time period.
Optionally, the second obtaining module is specifically configured to
Adding the running time of each Java thread in the preset time period to obtain the total running time value of all Java threads in the preset time period;
multiplying the running time of the Java virtual machine in the preset time period by the number of CPU cores to obtain the total running time value of the Java virtual machines of all CPUs in the preset time period;
and acquiring the CPU utilization rate of the Java threads according to the total running time values of all the Java threads in the preset time period and the total running time values of the Java virtual machines of all the CPUs in the preset time period.
An embodiment of the present invention provides an electronic device, which includes a memory, a processor, and a computer program stored in the memory and executable on the processor, and when the processor executes the computer program, the steps of the method are implemented.
According to the method and the device for acquiring the CPU utilization rate of the Java threads, provided by the embodiment of the invention, the running time, the CPU core number and the running time of the Java virtual machine in the preset time period of each Java thread are acquired every other preset time period, and the CPU utilization rate of the Java threads is acquired according to the acquired running time, the CPU core number and the running time of the Java virtual machine in the preset time period of each Java thread, so that the CPU utilization rate of the Java threads can be accurately acquired.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are some embodiments of the present invention, and those skilled in the art can also obtain other drawings according to the drawings without creative efforts.
Fig. 1 is a schematic flowchart of a method for acquiring CPU utilization of a Java thread according to an embodiment of the present invention;
fig. 2 is a schematic structural diagram of a Java thread CPU utilization obtaining apparatus according to an embodiment of the present invention;
fig. 3 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
In order to make the objects, technical solutions and advantages of the embodiments of the present invention clearer, the technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are some, but not all, embodiments of the present invention. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
Fig. 1 is a schematic flowchart illustrating a method for acquiring Java thread CPU utilization according to an embodiment of the present invention, where as shown in fig. 1, the method for acquiring Java thread CPU utilization according to the embodiment includes:
and S1, acquiring the running time of each Java thread in the preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period every other preset time period.
It should be noted that the execution subject of the Java thread CPU utilization obtaining method in this embodiment is a processor.
It is understood that the preset time period may be set according to actual requirements, and the preset time period is not limited in this embodiment, and may be set to 5 minutes, 10 minutes, 30 minutes, 1 hour, 5 hours, and the like, for example.
It can be understood that, in this embodiment, the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period are acquired every preset time period, and then the Java thread CPU utilization is obtained by calculation according to the acquired data.
And S2, acquiring the CPU utilization rate of the Java threads according to the running time of each Java thread in the preset time period, the CPU core number and the running time of the Java virtual machine in the preset time period.
It can be understood that, in this embodiment, the Java thread CPU utilization rate is actually the CPU utilization rate occupied by the Java thread during running in the preset time period.
It can be understood that, in this step, the CPU utilization of the Java threads may be calculated and obtained according to the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period.
It can be understood that the method for obtaining the usage rate of the Java thread CPU provided in this embodiment is mainly suitable for calculation monitoring and data statistics of CPU resources occupied by Java thread running for the calculation of Java system running data, and can estimate the Java thread running fluctuation according to the Java thread CPU usage rate calculated in a plurality of preset time periods when the Java thread runs in a stable running state.
According to the method for acquiring the CPU utilization rate of the Java thread, the operating time, the CPU core number and the Java virtual machine in the preset time period are acquired through every other preset time period, the operating time, the CPU core number and the Java virtual machine in the preset time period are acquired according to the acquired operating time, the CPU core number and the Java virtual machine in the preset time period, and the CPU utilization rate of the Java thread is acquired through the operating time in the preset time period.
Further, on the basis of the foregoing embodiment, the step S1 in this embodiment may include:
every other preset time period, the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period are obtained through an interface provided by Java JDK (Java Development Kit, which is a Java language software Development Kit).
Specifically, the interface provided by Java JDK may include: ThreadMXBean (management interface for Java virtual machine thread system), operatingsystemxbean (management interface for operating system), and RuntimeMXBean (management interface for Java virtual machine runtime system);
correspondingly, every other preset time period, the present embodiment may obtain the running time of each Java thread in the preset time period through ThreadMXBean, obtain the number of CPU cores through operating system mxbean, and obtain the running time of the Java virtual machine in the preset time period through RuntimeMXBean.
It can be understood that, in this embodiment, ThreadMXBean, operatingsystemxbean, and RuntimeMXBean can be obtained through JMX (Java Management Extensions), then the running time of each Java thread in the preset time period is obtained through ThreadMXBean, the number of CPU cores is obtained through operatingsystemxbean, and the running time of the Java virtual machine in the preset time period is obtained through RuntimeMXBean.
It can be understood that, acquiring data (the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period) required by subsequent computation of this embodiment by using an interface provided by JDK of Java enables the method of this embodiment to be applied to various platforms, and is easy to implement and implement.
Further, on the basis of the foregoing embodiment, the step S2 in this embodiment may include:
adding the running time of each Java thread in the preset time period to obtain the total running time value of all Java threads in the preset time period;
multiplying the running time of the Java virtual machine in the preset time period by the number of CPU cores to obtain the total running time value of the Java virtual machines of all CPUs in the preset time period;
and acquiring the CPU utilization rate of the Java threads according to the total running time values of all the Java threads in the preset time period and the total running time values of the Java virtual machines of all the CPUs in the preset time period.
Specifically, in this embodiment, the CPU utilization of the Java thread may be calculated according to the total running time value of all Java threads in the preset time period and the total running time value of all Java virtual machines of the CPU in the preset time period by using a first formula;
wherein the first formula is:
Pcpufor Java threads CPU usage, t1The total running time value, t, of all Java threads in the preset time period2And the total running time value of the Java virtual machines of all the CPUs in the preset time period.
The method for acquiring the CPU utilization rate of the Java thread can accurately acquire the CPU utilization rate of the Java thread, is high in applicability, depends on a Java interface instead of an operating system or calculates the CPU utilization rate of the Java thread through too low-level hardware, is simple in calculation mode, is irrelevant to the operating system, does not need to know the implementation too high than the low level, calculates once every preset time period through a timing task, and can perform relatively visual and accurate statistics on the CPU utilization rate of the Java thread in operation.
Fig. 2 is a schematic structural diagram illustrating an apparatus for acquiring Java thread CPU utilization according to an embodiment of the present invention, and as shown in fig. 2, the apparatus for acquiring Java thread CPU utilization according to the embodiment includes: a first acquisition module 21 and a second acquisition module 22; wherein:
the first obtaining module 21 is configured to obtain, every preset time period, the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period;
the second obtaining module 22 is configured to obtain the CPU utilization of the Java threads according to the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period.
Specifically, the first obtaining module 21 obtains, every preset time period, the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period; the second obtaining module 22 obtains the CPU utilization of the Java threads according to the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period.
It should be noted that the apparatus for acquiring Java thread CPU utilization rate according to this embodiment is applied to a processor.
It is understood that the preset time period may be set according to actual requirements, and the preset time period is not limited in this embodiment, and may be set to 5 minutes, 10 minutes, 30 minutes, 1 hour, 5 hours, and the like, for example.
It can be understood that the first obtaining module 21 obtains the running time, the number of CPU cores, and the running time of the Java virtual machine in the preset time period of each Java thread every preset time period, and then calculates the Java thread CPU utilization according to the obtained data.
It can be understood that, in this embodiment, the Java thread CPU utilization rate is actually the CPU utilization rate occupied by the Java thread during running in the preset time period.
It is understood that the second obtaining module 22 may calculate and obtain the Java thread CPU usage according to the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period.
It can be understood that the apparatus for obtaining Java thread CPU utilization rate provided in this embodiment is mainly suitable for calculation monitoring and data statistics of CPU resources occupied by Java thread during running for the calculation of Java system running data, and can estimate Java thread running fluctuation according to Java thread CPU utilization rate calculated in a plurality of preset time periods when Java thread running fluctuation is large.
The device for acquiring the CPU utilization rate of the Java thread can accurately acquire the CPU utilization rate of the Java thread, has a simple calculation mode, calculates once every preset time period through the timing task, and can perform more visual and accurate statistics on the CPU utilization condition of the Java thread in operation.
Further, on the basis of the above embodiment, the first obtaining module 21 may be specifically configured to
And acquiring the running time of each Java thread in the preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period through an interface provided by JDK of Java every other preset time period.
Specifically, the interface provided by Java JDK may include: ThreadMXBean (management interface for Java virtual machine thread system), operatingsystemxbean (management interface for operating system), and RuntimeMXBean (management interface for Java virtual machine runtime system);
correspondingly, the first obtaining module 21 may be specifically configured to obtain, every preset time period, the running time of each Java thread in the preset time period through ThreadMXBean, obtain the number of CPU cores through operating system mxbean, and obtain the running time of the Java virtual machine in the preset time period through RuntimeMXBean.
It can be understood that the first obtaining module 21 may obtain ThreadMXBean, operatingsystemxbean, and RuntimeMXBean through JMX, further obtain the running time of each Java thread in the preset time period through ThreadMXBean, obtain the number of CPU cores through operatingsystemxbean, and obtain the running time of the Java virtual machine in the preset time period through RuntimeMXBean.
It can be understood that, acquiring data (the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period) required by subsequent computation of this embodiment by using an interface provided by JDK of Java enables the method of this embodiment to be applied to various platforms, and is easy to implement and implement.
Further, on the basis of the above embodiment, the second obtaining module 22 may be specifically configured to
Adding the running time of each Java thread in the preset time period to obtain the total running time value of all Java threads in the preset time period;
multiplying the running time of the Java virtual machine in the preset time period by the number of CPU cores to obtain the total running time value of the Java virtual machines of all CPUs in the preset time period;
and acquiring the CPU utilization rate of the Java threads according to the total running time values of all the Java threads in the preset time period and the total running time values of the Java virtual machines of all the CPUs in the preset time period.
Specifically, the second obtaining module 22 may calculate, according to the total running time values of all Java threads in the preset time period and the total running time values of all Java virtual machines of the CPU in the preset time period, the CPU utilization of the Java threads through a first formula;
wherein the first formula is:
Pcpufor Java threads CPU usage, t1The total running time value, t, of all Java threads in the preset time period2And the total running time value of the Java virtual machines of all the CPUs in the preset time period.
The device for acquiring the CPU utilization rate of the Java thread can accurately acquire the CPU utilization rate of the Java thread, is high in applicability, depends on a Java interface instead of an operating system or calculates the CPU utilization rate of the Java thread through too low-level hardware, is simple in calculation mode, is irrelevant to the operating system, does not need to know the implementation too high-level hardware, calculates once every preset time period through a timing task, and can perform relatively visual and accurate statistics on the CPU utilization rate of the Java thread in operation.
The device for acquiring the utilization rate of the Java thread CPU, provided by the embodiment of the present invention, may be used to implement the technical solution of the foregoing method embodiment, and the implementation principle and technical effect are similar, which are not described herein again.
Fig. 3 is a schematic physical structure diagram of an electronic device according to an embodiment of the present invention, as shown in fig. 3, the electronic device may include a memory 302, a processor 301, a bus 303, and a computer program stored in the memory 302 and executable on the processor 301, where the processor 301 and the memory 302 communicate with each other through the bus 303. The processor 301, when executing the computer program, implements the steps of the above method, for example, including: acquiring the running time of each Java thread in a preset time period, the number of CPU cores and the running time of a Java virtual machine in the preset time period every other preset time period; and acquiring the CPU utilization rate of the Java threads according to the running time of each Java thread in the preset time period, the CPU core number and the running time of the Java virtual machine in the preset time period.
An embodiment of the present invention provides a non-transitory computer-readable storage medium, on which a computer program is stored, and the computer program, when executed by a processor, implements the steps of the above method, for example, including: acquiring the running time of each Java thread in a preset time period, the number of CPU cores and the running time of a Java virtual machine in the preset time period every other preset time period; and acquiring the CPU utilization rate of the Java threads according to the running time of each Java thread in the preset time period, the CPU core number and the running time of the Java virtual machine in the preset time period.
The above-described embodiments of the apparatus are merely illustrative, and the units described as separate parts may or may not be physically separate, and parts displayed as units may or may not be physical units, may be located in one place, or may be distributed on a plurality of network units. Some or all of the modules may be selected according to actual needs to achieve the purpose of the solution of the present embodiment. One of ordinary skill in the art can understand and implement it without inventive effort.
Through the above description of the embodiments, those skilled in the art will clearly understand that each embodiment can be implemented by software plus a necessary general hardware platform, and certainly can also be implemented by hardware. With this understanding in mind, the above-described technical solutions may be embodied in the form of a software product, which can be stored in a computer-readable storage medium such as ROM/RAM, magnetic disk, optical disk, etc., and includes instructions for causing a computer device (which may be a personal computer, a server, or a network device, etc.) to execute the methods described in the embodiments or some parts of the embodiments.
Finally, it should be noted that: the above examples are only intended to illustrate the technical solution of the present invention, but not to limit it; although the present invention has been described in detail with reference to the foregoing embodiments, it will be understood by those of ordinary skill in the art that: the technical solutions described in the foregoing embodiments may still be modified, or some technical features may be equivalently replaced; and such modifications or substitutions do not depart from the spirit and scope of the corresponding technical solutions of the embodiments of the present invention.

Claims (10)

1. A Java thread CPU utilization rate obtaining method is characterized by comprising the following steps:
acquiring the running time of each Java thread in a preset time period, the number of CPU cores and the running time of a Java virtual machine in the preset time period every other preset time period;
and acquiring the CPU utilization rate of the Java threads according to the running time of each Java thread in the preset time period, the CPU core number and the running time of the Java virtual machine in the preset time period.
2. The method for acquiring Java thread CPU utilization according to claim 1, wherein acquiring, every preset time period, the running time of each Java thread in the preset time period, the CPU core number, and the running time of the Java virtual machine in the preset time period includes:
and acquiring the running time of each Java thread in the preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period through an interface provided by JDK of Java every other preset time period.
3. The method according to claim 2, wherein the interface provided by Java JDK comprises: a management interface ThreadMXBean of a Java virtual machine thread system, a management interface OperatingSystemMXBean of an operating system and a management interface RuntimmeMXBean of a Java virtual machine runtime system;
correspondingly, every other preset time period, the running time of each Java thread in the preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period are obtained through an interface provided by Java JDK, including:
and acquiring the running time of each Java thread in a preset time period through a ThreadMXBean every other preset time period, acquiring the number of CPU cores through an OperatingSystemMXBean, and acquiring the running time of the Java virtual machine in the preset time period through a RuntimeMXBean.
4. The method for obtaining the usage rate of the Java thread CPU according to the running time of each Java thread in the preset time period, the number of CPU cores, and the running time of the Java virtual machine in the preset time period, as recited in claim 1, comprising:
adding the running time of each Java thread in the preset time period to obtain the total running time value of all Java threads in the preset time period;
multiplying the running time of the Java virtual machine in the preset time period by the number of CPU cores to obtain the total running time value of the Java virtual machines of all CPUs in the preset time period;
and acquiring the CPU utilization rate of the Java threads according to the total running time values of all the Java threads in the preset time period and the total running time values of the Java virtual machines of all the CPUs in the preset time period.
5. The method for obtaining Java thread CPU utilization according to claim 4, wherein obtaining Java thread CPU utilization according to the total runtime value of all Java threads in the preset time period and the total runtime value of Java virtual machines of all CPUs in the preset time period comprises:
calculating the CPU utilization rate of the Java threads according to the total running time values of all the Java threads in the preset time period and the total running time values of all the Java virtual machines of the CPUs in the preset time period by using a first formula;
wherein the first formula is:
Pcpufor Java threads CPU usage, t1The total running time value, t, of all Java threads in the preset time period2And the total running time value of the Java virtual machines of all the CPUs in the preset time period.
6. A Java thread CPU usage acquisition apparatus, comprising:
the first acquisition module is used for acquiring the running time of each Java thread in a preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period every other preset time period;
and the second acquisition module is used for acquiring the CPU utilization rate of the Java threads according to the running time of each Java thread in the preset time period, the CPU core number and the running time of the Java virtual machine in the preset time period.
7. The apparatus according to claim 6, wherein the first obtaining module is specifically configured to obtain the CPU usage of the Java thread
And acquiring the running time of each Java thread in the preset time period, the number of CPU cores and the running time of the Java virtual machine in the preset time period through an interface provided by JDK of Java every other preset time period.
8. The apparatus according to claim 6, wherein the second obtaining module is specifically configured to obtain the Java thread CPU utilization
Adding the running time of each Java thread in the preset time period to obtain the total running time value of all Java threads in the preset time period;
multiplying the running time of the Java virtual machine in the preset time period by the number of CPU cores to obtain the total running time value of the Java virtual machines of all CPUs in the preset time period;
and acquiring the CPU utilization rate of the Java threads according to the total running time values of all the Java threads in the preset time period and the total running time values of the Java virtual machines of all the CPUs in the preset time period.
9. An electronic device comprising a memory, a processor and a computer program stored on the memory and executable on the processor, characterized in that the steps of the method according to any of claims 1 to 5 are implemented when the computer program is executed by the processor.
10. A non-transitory computer-readable storage medium, on which a computer program is stored, which, when being executed by a processor, carries out the steps of the method according to any one of claims 1 to 5.
CN201910836931.8A 2019-09-05 2019-09-05 Java thread CPU utilization rate obtaining method and device Pending CN110609773A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN201910836931.8A CN110609773A (en) 2019-09-05 2019-09-05 Java thread CPU utilization rate obtaining method and device

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN201910836931.8A CN110609773A (en) 2019-09-05 2019-09-05 Java thread CPU utilization rate obtaining method and device

Publications (1)

Publication Number Publication Date
CN110609773A true CN110609773A (en) 2019-12-24

Family

ID=68892376

Family Applications (1)

Application Number Title Priority Date Filing Date
CN201910836931.8A Pending CN110609773A (en) 2019-09-05 2019-09-05 Java thread CPU utilization rate obtaining method and device

Country Status (1)

Country Link
CN (1) CN110609773A (en)

Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103455407A (en) * 2013-09-03 2013-12-18 小米科技有限责任公司 Mobile terminal CPU (Central Processing Unit) occupation rate monitoring method and device and mobile terminal
CN106528318A (en) * 2016-11-29 2017-03-22 迈普通信技术股份有限公司 Thread endless loop detection method and device
CN108959020A (en) * 2018-05-08 2018-12-07 华为技术有限公司 A kind of calculation method and device of Computer CPU Utilization Ratio
CN109684167A (en) * 2018-12-06 2019-04-26 北京城市网邻信息技术有限公司 Calculation method, device, storage medium and the terminal of application program CPU usage
CN110083495A (en) * 2018-01-26 2019-08-02 上海新岸线电子技术有限公司 A method of CPU is occupied based on MIPS analysis thread

Patent Citations (5)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN103455407A (en) * 2013-09-03 2013-12-18 小米科技有限责任公司 Mobile terminal CPU (Central Processing Unit) occupation rate monitoring method and device and mobile terminal
CN106528318A (en) * 2016-11-29 2017-03-22 迈普通信技术股份有限公司 Thread endless loop detection method and device
CN110083495A (en) * 2018-01-26 2019-08-02 上海新岸线电子技术有限公司 A method of CPU is occupied based on MIPS analysis thread
CN108959020A (en) * 2018-05-08 2018-12-07 华为技术有限公司 A kind of calculation method and device of Computer CPU Utilization Ratio
CN109684167A (en) * 2018-12-06 2019-04-26 北京城市网邻信息技术有限公司 Calculation method, device, storage medium and the terminal of application program CPU usage

Similar Documents

Publication Publication Date Title
CN108721898B (en) Frame rate determination method and apparatus, storage medium, and electronic apparatus
US8881125B2 (en) Indirect software performance analysis
JP6369170B2 (en) Execution time estimation apparatus and method
Ouyang et al. Straggler detection in parallel computing systems through dynamic threshold calculation
US20230305880A1 (en) Cluster distributed resource scheduling method, apparatus and device, and storage medium
Willnecker et al. Comparing the accuracy of resource demand measurement and estimation techniques
CN115168130A (en) Chip testing method and device, electronic equipment and storage medium
CN110851297A (en) Method, device, system and medium for processing interface jitter state
EP2672388A1 (en) Multi-processor parallel simulation method, system and scheduler
EP3077910B1 (en) Methods and apparatus to optimize platform simulation resource consumption
CN106886477B (en) Method and device for setting monitoring threshold in cloud system
CN110609773A (en) Java thread CPU utilization rate obtaining method and device
CN108418730B (en) Network flow testing method, device, equipment and computer readable storage medium
CN113220463B (en) Binding strategy inference method and device, electronic equipment and storage medium
CN112181853A (en) Program debugging method, device and system
CN110174865B (en) Method and device for controlling target information acquisition rate
CN107678945B (en) Method and device for judging webpage application blocking
CN112346994A (en) Test information correlation method and device, computer equipment and storage medium
CN112433914A (en) Method and system for acquiring parallel computing task progress
Tchana et al. A self-scalable and auto-regulated request injection benchmarking tool for automatic saturation detection
CN112540885A (en) CPU load value detection method and device based on user space
CN111026623A (en) BMC running time testing method, system, terminal and storage medium
CN115981985A (en) Code block monitoring method and device, electronic equipment and readable storage medium
US10430311B2 (en) Measuring execution time of benchmark programs in a simulated environment
CN116719730A (en) Performance test method, device, equipment and medium

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

Application publication date: 20191224