cpu

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 20, 2020 License: Apache-2.0 Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Load

type Load struct {
	Avg   float64 `json:"avg"`
	Max   float64 `json:"max"`
	Min   float64 `json:"min"`
	Error string  `json:"error,omitempty"`
}

Load holds CPU utilization % measured in three intervals of 200ms each

func GetHistoricLoad

func GetHistoricLoad() Load

GetHistoricLoad returns the historic CPU utilization of the current process

func GetLoad

func GetLoad() Load

GetLoad returns the CPU utilization of the current process This function works by calcualating the amount of cpu clock cycles the current process used in a given time window

This corresponds to the CPU utilization calculation done by tools like top. Here, we use the getclocktime with the CLOCK_PROCESS_CPUTIME_ID parameter to obtain the total number of clock ticks used by the process so far. Then we sleep for 200ms and obtain the the total number of clock ticks again. The difference between the two counts provides us the number of clock ticks used by the process in the 200ms interval.

The ratio of clock ticks used (measured in nanoseconds) to number of nanoseconds in 200 milliseconds provides us the CPU usage for the process currently

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL