cpuproc

package module
v0.0.0-...-dbf01c1 Latest Latest
Warning

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

Go to latest
Published: Jun 15, 2024 License: Apache-2.0 Imports: 19 Imported by: 4

README

cpuproc

计算进程cpu的使用率

支持平台

  • linux

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ClocksPerSec = float64(100)
View Source
var EnvKey = EnvKeyType("env")

EnvKey is a context key that can be used to set programmatically the environment gopsutil relies on to perform calls against the OS. Example of use:

ctx := context.WithValue(context.Background(), common.EnvKey, EnvMap{common.HostProcEnvKey: "/myproc"})
avg, err := load.AvgWithContext(ctx)

Functions

func BootTimeWithContext

func BootTimeWithContext(ctx context.Context, enableCache bool) (uint64, error)

func GetEnvWithContext

func GetEnvWithContext(ctx context.Context, key string, dfault string, combineWith ...string) string

GetEnvWithContext retrieves the environment variable key. If it does not exist it returns the default. The context may optionally contain a map superseding os.EnvKey.

func GetOSReleaseWithContext

func GetOSReleaseWithContext(ctx context.Context) (platform string, version string, err error)

func HostEtcWithContext

func HostEtcWithContext(ctx context.Context, combineWith ...string) string

func HostProcWithContext

func HostProcWithContext(ctx context.Context, combineWith ...string) string

func HostRootWithContext

func HostRootWithContext(ctx context.Context, combineWith ...string) string

func NewProcess

func NewProcess(pid int32) *proc

func PathExists

func PathExists(filename string) bool

func Percent

func Percent(interval time.Duration, percpu bool) ([]float64, error)

func PercentTotal

func PercentTotal(interval time.Duration) (float64, error)

func PercentWithContext

func PercentWithContext(ctx context.Context, interval time.Duration, percpu bool) ([]float64, error)

func ReadFile

func ReadFile(filename string) (string, error)

ReadFile reads contents from a file

func ReadLine

func ReadLine(filename string, prefix string) (string, error)

func ReadLines

func ReadLines(filename string) ([]string, error)

ReadLines reads contents from a file and splits them by new lines. A convenience wrapper to ReadLinesOffsetN(filename, 0, -1).

func ReadLinesOffsetN

func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error)

ReadLinesOffsetN reads contents from file and splits them by new line. The offset tells at which line number to start. The count determines the number of lines to read (starting from offset): n >= 0: at most n lines n < 0: whole file

func Sleep

func Sleep(ctx context.Context, interval time.Duration) error

Sleep awaits for provided interval. Can be interrupted by context cancellation.

func VirtualizationWithContext

func VirtualizationWithContext(ctx context.Context) (string, string, error)

Types

type EnvKeyType

type EnvKeyType string

type EnvMap

type EnvMap map[EnvKeyType]string

type PageFaultsStat

type PageFaultsStat struct {
	MinorFaults      uint64 `json:"minorFaults"`
	MajorFaults      uint64 `json:"majorFaults"`
	ChildMinorFaults uint64 `json:"childMinorFaults"`
	ChildMajorFaults uint64 `json:"childMajorFaults"`
}

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.

func Times

func Times(percpu bool) ([]TimesStat, error)

func TimesWithContext

func TimesWithContext(ctx context.Context, percpu bool) ([]TimesStat, error)

func (TimesStat) Total

func (c TimesStat) Total() float64

Directories

Path Synopsis
example

Jump to

Keyboard shortcuts

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