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