Documentation
¶
Overview ¶
SPDX-License-Identifier: BSD-3-Clause
Index ¶
- Variables
- func Counts(logical bool) (int, error)
- func CountsWithContext(ctx context.Context, logical bool) (int, error)
- func Percent(interval time.Duration, percpu bool) ([]float64, error)
- func PercentWithContext(ctx context.Context, interval time.Duration, percpu bool) ([]float64, error)
- type ExLinux
- type ExTimesStat
- type InfoStat
- type TimesStat
Constants ¶
This section is empty.
Variables ¶
var ClocksPerSec = float64(100)
Functions ¶
Types ¶
type ExLinux ¶ added in v4.26.9
type ExLinux struct{}
func NewExLinux ¶ added in v4.26.9
func NewExLinux() *ExLinux
func (*ExLinux) Times ¶ added in v4.26.9
func (ex *ExLinux) Times(percpu bool) ([]ExTimesStat, error)
func (*ExLinux) TimesWithContext ¶ added in v4.26.9
TimesWithContext returns raw CPU tick counters without floating-point conversion. CPU rows are selected and parsed like the package-level Times function; absent optional counters are zero. Unlike the legacy API, read errors and invalid selected CPU rows are returned instead of skipped.
type ExTimesStat ¶ added in v4.26.9
type ExTimesStat struct {
CPU string `json:"cpu"`
User uint64 `json:"user"`
System uint64 `json:"system"`
Idle uint64 `json:"idle"`
Nice uint64 `json:"nice"`
Iowait uint64 `json:"iowait"`
Irq uint64 `json:"irq"`
Softirq uint64 `json:"softirq"`
Steal uint64 `json:"steal"`
Guest uint64 `json:"guest"`
GuestNice uint64 `json:"guestNice"`
}
ExTimesStat contains the unscaled Linux CPU time counters from /proc/stat. Counters are in USER_HZ ticks, rather than the seconds used by TimesStat. Divide a counter by ClocksPerSec to get seconds, or use ToTimesStat.
User includes Guest, and Nice includes GuestNice, because the kernel accounts guest time into both. Subtract Guest and GuestNice when summing all fields.
Counters are reported as read. A counter can decrease, in particular Iowait. Check that the new value is not smaller than the old one before you subtract.
func (ExTimesStat) String ¶ added in v4.26.9
func (c ExTimesStat) String() string
func (ExTimesStat) ToTimesStat ¶ added in v4.26.9
func (c ExTimesStat) ToTimesStat() TimesStat
ToTimesStat converts the counters to the seconds returned by the package-level Times function.
type InfoStat ¶
type InfoStat struct {
CPU int32 `json:"cpu"`
VendorID string `json:"vendorId"`
Family string `json:"family"`
Model string `json:"model"`
Stepping int32 `json:"stepping"`
PhysicalID string `json:"physicalId"`
CoreID string `json:"coreId"`
Cores int32 `json:"cores"`
ModelName string `json:"modelName"`
Mhz float64 `json:"mhz"`
CacheSize int32 `json:"cacheSize"`
Flags []string `json:"flags"`
Microcode string `json:"microcode"`
}
func Info ¶
CPUInfo on linux will return 1 item per physical thread.
CPUs have three levels of counting: sockets, cores, threads. Cores with HyperThreading count as having 2 threads per core. Sockets often come with many physical CPU cores. For example a single socket board with two cores each with HT will return 4 CPUInfoStat structs on Linux and the "Cores" field set to 1.
type TimesStat ¶
type TimesStat struct {
CPU string `json:"cpu"`
User float64 `json:"user"`
System float64 `json:"system"`
Idle float64 `json:"idle"`
Nice float64 `json:"nice"`
Iowait float64 `json:"iowait"`
Irq float64 `json:"irq"`
Softirq float64 `json:"softirq"`
Steal float64 `json:"steal"`
Guest float64 `json:"guest"`
GuestNice float64 `json:"guestNice"`
}
TimesStat contains the amounts of time the CPU has spent performing different kinds of work. Time units are in seconds. It is based on linux /proc/stat file.