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 ¶
- func HasZram() bool
- func LogMemoryParameters(ctx context.Context, ratio float64) error
- func PSIMemoryLines() ([]string, error)
- func ParseVMStats(vmstat string) (map[string]uint64, error)
- func ReadMemInfo() (map[string]MemSize, error)
- func VMStats() (map[string]uint64, error)
- type MemInfoFields
- type MemSize
- type Meter
- type VMCounterData
- type VMStatsData
- type ZramStatsData
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 ¶
LogMemoryParameters logs various kernel parameters as well as some calculated quantities to help understand the memory manager behavior.
func PSIMemoryLines ¶
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 ¶
ParseVMStats converts the contents of a /proc/vmstat file to a map.
func ReadMemInfo ¶
ReadMemInfo returns all name-value pairs from /proc/meminfo. The values returned are in bytes.
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 ¶
ChromeosLowMem returns sysfs information from the chromeos low-mem module.
func NewMemSizeKiB ¶
NewMemSizeKiB converts an amount in KiB to a memory size in bytes.
func NewMemSizeMiB ¶
NewMemSizeMiB converts an amount in MiB to a memory size in bytes.
func NewMemSizePages ¶
NewMemSizePages converts a number of pages to its memory size in bytes.
func ProcessMemory ¶
ProcessMemory returns the approximate amount of virtual memory (swapped or not) currently allocated by processes.
type Meter ¶
type Meter struct {
// contains filtered or unexported fields
}
Meter collects kernel performance statistics.
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.