kernelmeter

package
v0.0.0-...-683b059 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2022 License: BSD-3-Clause Imports: 12 Imported by: 0

Documentation

Overview

Package kernelmeter provides a mechanism for collecting kernel-related measurements in parallel with the execution of a test.

Several kernel quantities (e.g page faults, swaps) are exposed via sysfs or procfs in the form of counters. We are generally interested in the absolute increments of these values over a period of time, and their rate of change. A kernelmeter.Meter instance keeps track of the initial values of the counters so that deltas can be computed. It also calculates the peak rate over an interval. Additionally, various methods are available for reading snapshots of other exported kernel quantities.

Package kernelmeter provides a mechanism for collecting kernel-related measurements in parallel with the execution of a test, and through snapshots of values exported in procfs and sysfs.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func HasZram

func HasZram() bool

HasZram returns true when the system uses swap on a zram device, and no other device.

func LogMemoryParameters

func LogMemoryParameters(ctx context.Context, ratio float64) error

LogMemoryParameters logs various kernel parameters as well as some calculated quantities to help understand the memory manager behavior.

func PSIMemoryLines

func PSIMemoryLines() ([]string, error)

PSIMemoryLines returns a snapshot of /proc/pressure/memory as a list of lines, or nil if PSI is not available on the system.

func ParseVMStats

func ParseVMStats(vmstat string) (map[string]uint64, error)

ParseVMStats converts the contents of a /proc/vmstat file to a map.

func ReadMemInfo

func ReadMemInfo() (map[string]MemSize, error)

ReadMemInfo returns all name-value pairs from /proc/meminfo. The values returned are in bytes.

func VMStats

func VMStats() (map[string]uint64, error)

VMStats returns /proc/vmstat values in a map. /proc/vmstat numbers are in unsigned long long.

Types

type MemInfoFields

type MemInfoFields struct {
	Total, Free, Anon, File, SwapTotal, SwapUsed MemSize
}

MemInfoFields holds selected fields of /proc/meminfo.

func MemInfo

func MemInfo() (data *MemInfoFields, err error)

MemInfo returns selected /proc/meminfo fields.

type MemSize

type MemSize uint64

MemSize represents an amount of RAM in bytes.

func ChromeosLowMem

func ChromeosLowMem() (available, criticalMargin MemSize, ramWeight int, err error)

ChromeosLowMem returns sysfs information from the chromeos low-mem module.

func NewMemSizeKiB

func NewMemSizeKiB(kib int) MemSize

NewMemSizeKiB converts an amount in KiB to a memory size in bytes.

func NewMemSizeMiB

func NewMemSizeMiB(mib int) MemSize

NewMemSizeMiB converts an amount in MiB to a memory size in bytes.

func NewMemSizePages

func NewMemSizePages(pages int) MemSize

NewMemSizePages converts a number of pages to its memory size in bytes.

func ProcessMemory

func ProcessMemory() (allocated MemSize, err error)

ProcessMemory returns the approximate amount of virtual memory (swapped or not) currently allocated by processes.

func (MemSize) String

func (m MemSize) String() string

String converts a MemSize to a string for printing. The value is printed in MiB, since MiB resolution is more than sufficient for this application. For Values smaller than 2 MiB, print a few decimals.

type Meter

type Meter struct {
	// contains filtered or unexported fields
}

Meter collects kernel performance statistics.

func New

func New(ctx context.Context) *Meter

New creates a Meter and starts the sampling goroutine.

func (*Meter) Close

func (m *Meter) Close(ctx context.Context)

Close stops the sampling goroutine and releases other resources.

func (*Meter) Reset

func (m *Meter) Reset()

Reset resets a Meter so that it is ready for a new set of measurements.

func (*Meter) VMStats

func (m *Meter) VMStats() (*VMStatsData, error)

VMStats returns the total number of events, and the average and max rates, for various memory manager events.

type VMCounterData

type VMCounterData struct {
	// Count is the number of events since the last reset.
	Count uint64
	// AverageRate is the average rate (increase/second) for the duration
	// of the sampling.
	AverageRate float64
	// MaxRate is the maximum rate seen during the sampling
	// (increase/second over samplePeriod intervals).
	MaxRate float64
	// RecentRate is the average rate in the most recent window with size
	// vmCountWindowLength periods (or slightly more), or however many
	// periods are available since the most recent reset, including the
	// most recent sample.
	RecentRate float64
}

VMCounterData contains statistics for a memory manager event counter, such as the page fault counter (pgmajfault in /proc/vmstat).

type VMStatsData

type VMStatsData struct {
	// PageFault reports major page fault count and rates.
	PageFault VMCounterData
	// SwapIn reports swapin count and rates.
	SwapIn VMCounterData
	// SwapOut reports swapout count and rates.
	SwapOut VMCounterData
	// OOM reports out-of-memory kill count and rates.
	OOM VMCounterData
}

VMStatsData contains statistics for various memory manager counters. The fields of VMStatsData must match the names and indices above.

type ZramStatsData

type ZramStatsData struct{ Original, Compressed, Used uint64 }

ZramStatsData contains stats from the zram block device.

func ZramStats

func ZramStats(ctx context.Context) (*ZramStatsData, error)

ZramStats returns zram block device usage counts.

Jump to

Keyboard shortcuts

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