power

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: 26 Imported by: 0

Documentation

Overview

Package power interacts with power management on behalf of local tests.

Index

Constants

View Source
const (
	SignalPowerSupplyPoll     = "PowerSupplyPoll"
	SignalSuspendImminent     = "SuspendImminent"
	SignalDarkSuspendImminent = "DarkSuspendImminent"
	SignalSuspendDone         = "SuspendDone"
)

Signal names of power manager D-Bus API.

Variables

This section is empty.

Functions

func ListSysfsBatteryPaths

func ListSysfsBatteryPaths(ctx context.Context) ([]string, error)

ListSysfsBatteryPaths lists paths of batteries which supply power to the system and has voltage_now and current_now attributes.

func ListSysfsThermalSensors

func ListSysfsThermalSensors(ctx context.Context) (map[string]string, error)

ListSysfsThermalSensors lists names and paths of thermal sensors which can be read through sysfs.

func LowBatteryShutdownPercent

func LowBatteryShutdownPercent(ctx context.Context) (float64, error)

LowBatteryShutdownPercent gets the battery percentage below which the system turns off.

func NewSignalWatcher

func NewSignalWatcher(ctx context.Context, signalNames ...string) (*dbusutil.SignalWatcher, error)

NewSignalWatcher creates an D-Bus signal watcher on PowerManager interface.

func ReadBatteryCapacity

func ReadBatteryCapacity(devPath string) (float64, error)

ReadBatteryCapacity returns the percentage of current charge of a battery which comes from /sys/class/power_supply/<supply name>/capacity.

func ReadBatteryChargeNow

func ReadBatteryChargeNow(devPath string) (float64, error)

ReadBatteryChargeNow returns the charge of a battery in Ah. which comes from /sys/class/power_supply/<supply name>/charge_now.

func ReadBatteryEnergy

func ReadBatteryEnergy(devPath string) (float64, error)

ReadBatteryEnergy returns the remaining energy of a battery in Wh.

func ReadBatteryProperty

func ReadBatteryProperty(devPath, property string) (float64, error)

ReadBatteryProperty reads the battery property file content from the given battery path, and return a float value. The given file content should be an integer, and error will be returned otherwise.

func ReadSystemPower

func ReadSystemPower(devPath string) (float64, error)

ReadSystemPower returns system power consumption in Watts. It is assumed that power supplies at devPath have attributes voltage_now and current_now. If reading these attributes fails, this function returns non-nil error, otherwise returns power consumption of the battery.

func RequestKeepAwake

func RequestKeepAwake(ctx context.Context, tconn *chrome.TestConn, level Level) (func(ctx context.Context, tconn *chrome.TestConn) error, error)

RequestKeepAwake sends a request to keep the system awake. A function is returned to restore the previous state. Full reference can be found here: https://developer.chrome.com/docs/extensions/reference/power/.

func SetDisplayPower

func SetDisplayPower(ctx context.Context, powerStatus DisplayPowerStatus) error

SetDisplayPower sets the display values by sending SetPower to DisplayService.

func SignalName

func SignalName(s *dbus.Signal) string

SignalName extracts the signal name from a dbus.Signal object.

func SysfsBatteryPath

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

SysfsBatteryPath returns a path of battery which supply power to the system and has voltage_now and current_now attributes.

func TestMetrics

func TestMetrics() []perf.TimelineDatasource

TestMetrics returns a slice of metrics that should be used for power tests.

func TurnOnDisplay

func TurnOnDisplay(ctx context.Context) error

TurnOnDisplay turns on a display by sending a HandleWakeNotification to PowerManager to light up the display.

Types

type BatteryStatus

type BatteryStatus int

BatteryStatus represents a charging status of a battery.

const (
	BatteryStatusUnknown BatteryStatus = iota
	BatteryStatusCharging
	BatteryStatusDischarging
	BatteryStatusNotCharging
	BatteryStatusFull
)

These values are corresponds to status attribute of sysfs power_supply.

func MapStringToBatteryStatus

func MapStringToBatteryStatus(statusStr string) (BatteryStatus, bool)

MapStringToBatteryStatus maps string to BatteryStatus.

func ReadBatteryStatus

func ReadBatteryStatus(devPath string) (BatteryStatus, error)

ReadBatteryStatus returns the current battery status.

type CPUUsageJiffies

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

CPUUsageJiffies stores a snapshot of total (load+idle) and load jiffy counters from /proc/stat.

type CpuidleStateMetrics

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

CpuidleStateMetrics records the C-states of the DUT.

NOTE: The cpuidle timings are measured according to the kernel. They resemble hardware cstates, but they might not have a direct correspondence. Furthermore, they generally may be greater than the time the CPU actually spends in the corresponding cstate, as the hardware may enter shallower states than requested.

func NewCpuidleStateMetrics

func NewCpuidleStateMetrics() *CpuidleStateMetrics

NewCpuidleStateMetrics creates a timeline metric to collect C-state numbers.

func (*CpuidleStateMetrics) Setup

func (cs *CpuidleStateMetrics) Setup(ctx context.Context, prefix string) error

Setup determines what C-states are supported and which CPUs should be queried.

func (*CpuidleStateMetrics) Snapshot

func (cs *CpuidleStateMetrics) Snapshot(ctx context.Context, values *perf.Values) error

Snapshot computes the cpuidle residency between this and the previous snapshot, and reports them as metrics.

func (*CpuidleStateMetrics) Start

func (cs *CpuidleStateMetrics) Start(ctx context.Context) error

Start collects initial cpuidle numbers which we can use to compute the residency between now and the first Snapshot.

func (*CpuidleStateMetrics) Stop

func (cs *CpuidleStateMetrics) Stop(ctx context.Context, values *perf.Values) error

Stop does nothing.

type DisplayManager

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

DisplayManager is used to interact with the display service over D-Bus.

func NewDisplayManager

func NewDisplayManager(ctx context.Context) (*DisplayManager, error)

NewDisplayManager connects to display_service via D-Bus and returns a DisplayManager object.

type DisplayPowerStatus

type DisplayPowerStatus int

DisplayPowerStatus is setting to change the power status of the display.

const (
	DisplayPowerAllOn DisplayPowerStatus = iota
	DisplayPowerAllOff
	DisplayPowerInternalOffExternalOn
	DisplayPowerInternalOnExternalOff
)

These consts are from /src/platform2/system_api/dbus/service_constants.h

type Level

type Level int

Level describes the power level management to use.

const (
	// Display keeps the screen and system active.
	Display Level = iota
	// System keeps the system active but allows the screen to be dimmed or turned off.
	System
)

type PackageCStatesMetrics

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

PackageCStatesMetrics records the package C-states of the DUT. This metric is only supported on Intel devices.

func NewPackageCStatesMetrics

func NewPackageCStatesMetrics() *PackageCStatesMetrics

NewPackageCStatesMetrics creates a timeline metric to collect package C-state numbers.

func (*PackageCStatesMetrics) Setup

func (cs *PackageCStatesMetrics) Setup(ctx context.Context, prefix string) error

Setup determines what C-states are supported and which CPUs should be queried.

func (*PackageCStatesMetrics) Snapshot

func (cs *PackageCStatesMetrics) Snapshot(ctx context.Context, values *perf.Values) error

Snapshot computes the package cstate residency between this and the previous snapshot, and reports them as metrics.

func (*PackageCStatesMetrics) Start

func (cs *PackageCStatesMetrics) Start(ctx context.Context) error

Start collects initial package cstate numbers which we can use to compute the residency between now and the first Snapshot.

func (*PackageCStatesMetrics) Stop

func (cs *PackageCStatesMetrics) Stop(ctx context.Context, values *perf.Values) error

Stop does nothing.

type PowerManager

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

PowerManager is used to interact with the powerd process over D-Bus. For detailed spec of each D-Bus method, please find src/platform2/power_manager/dbus_bindings/org.chromium.PowerManager.xml

func NewPowerManager

func NewPowerManager(ctx context.Context) (*PowerManager, error)

NewPowerManager connects to power_manager via D-Bus and returns a PowerManager object.

func (*PowerManager) GetScreenBrightnessPercent

func (m *PowerManager) GetScreenBrightnessPercent(ctx context.Context) (float64, error)

GetScreenBrightnessPercent returns current screen brightness by calling PowerManager.GetScreenBrightnessPercent D-Bus method.

func (*PowerManager) GetSwitchStates

func (m *PowerManager) GetSwitchStates(ctx context.Context) (*pmpb.SwitchStates, error)

GetSwitchStates calls PowerManager.GetSwitchStates D-Bus method.

func (*PowerManager) HandleWakeNotification

func (m *PowerManager) HandleWakeNotification(ctx context.Context) error

HandleWakeNotification calls PowerManager.HandleWakeNotification D-Bus method.

func (*PowerManager) SetScreenBrightness

func (m *PowerManager) SetScreenBrightness(ctx context.Context, percentage float64) error

SetScreenBrightness updates the screen brightness to the specified percentage by calling PowerManager.SetScreenBrightness D-Bus method.

type PowerManagerEmitter

type PowerManagerEmitter struct{} // NOLINT

PowerManagerEmitter is used to emit signals on behalf of power manager over D-Bus. For detailed spec of each D-Bus signal, please find src/platform2/power_manager/dbus_bindings/org.chromium.PowerManager.xml

func NewPowerManagerEmitter

func NewPowerManagerEmitter(ctx context.Context) (*PowerManagerEmitter, error)

NewPowerManagerEmitter stops the real power manager.

func (*PowerManagerEmitter) EmitDarkSuspendImminent

func (p *PowerManagerEmitter) EmitDarkSuspendImminent(ctx context.Context, msg *pmpb.SuspendImminent) error

EmitDarkSuspendImminent emits DarkSuspendImminent D-Bus signal.

func (*PowerManagerEmitter) EmitPowerSupplyPoll

func (p *PowerManagerEmitter) EmitPowerSupplyPoll(ctx context.Context, msg *pmpb.PowerSupplyProperties) error

EmitPowerSupplyPoll emits PowerSupplyPoll D-Bus signal.

func (*PowerManagerEmitter) EmitSuspendDone

func (p *PowerManagerEmitter) EmitSuspendDone(ctx context.Context, msg *pmpb.SuspendDone) error

EmitSuspendDone emits SuspendDone D-Bus signal.

func (*PowerManagerEmitter) EmitSuspendImminent

func (p *PowerManagerEmitter) EmitSuspendImminent(ctx context.Context, msg *pmpb.SuspendImminent) error

EmitSuspendImminent emits SuspendImminent D-Bus signal.

func (*PowerManagerEmitter) Stop

Stop restarts the real power manager.

type ProcfsCPUMetrics

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

ProcfsCPUMetrics holds the CPU metrics read from procfs.

func NewProcfsCPUMetrics

func NewProcfsCPUMetrics() *ProcfsCPUMetrics

NewProcfsCPUMetrics creates a struct to capture CPU metrics with procfs.

func (*ProcfsCPUMetrics) Setup

func (c *ProcfsCPUMetrics) Setup(ctx context.Context, prefix string) error

Setup creates the metric.

func (*ProcfsCPUMetrics) Snapshot

func (c *ProcfsCPUMetrics) Snapshot(ctx context.Context, values *perf.Values) error

Snapshot takes a snapshot of CPU metrics.

func (*ProcfsCPUMetrics) Start

func (c *ProcfsCPUMetrics) Start(ctx context.Context) error

Start takes the first snapshot of CPU metrics.

func (*ProcfsCPUMetrics) Stop

func (c *ProcfsCPUMetrics) Stop(ctx context.Context, values *perf.Values) error

Stop does nothing.

type RAPLPowerMetrics

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

RAPLPowerMetrics records the power consumption in Watt of the DUT.

func NewRAPLPowerMetrics

func NewRAPLPowerMetrics() *RAPLPowerMetrics

NewRAPLPowerMetrics creates a timeline metric to collect Intel RAPL energy numbers.

func (*RAPLPowerMetrics) Setup

func (r *RAPLPowerMetrics) Setup(_ context.Context, prefix string) error

Setup creates a RAPLSnapshot which lets us sample energy numbers without worrying about overflow. We do this in Setup because there's some extra work scanning sysfs that might be expensive if done during the test.

func (*RAPLPowerMetrics) Snapshot

func (r *RAPLPowerMetrics) Snapshot(_ context.Context, values *perf.Values) error

Snapshot computes the energy consumption between this and the previous snapshot, and reports them as metrics.

func (*RAPLPowerMetrics) Start

func (r *RAPLPowerMetrics) Start(_ context.Context) error

Start collects initial energy numbers which we can use to compute the average power consumption between now and the first Snapshot.

func (*RAPLPowerMetrics) Stop

func (r *RAPLPowerMetrics) Stop(_ context.Context, values *perf.Values) error

Stop does nothing.

type RAPLSnapshot

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

RAPLSnapshot represents a snapshot of the RAPL values. It contains the RAPL values plus other variables needed to make the "diff" more efficient.

func NewRAPLSnapshot

func NewRAPLSnapshot() (*RAPLSnapshot, error)

NewRAPLSnapshot returns a RAPLSnapshot. If no rapl files can be found, it returns a nil RAPLSnapshot, but does not return an error.

func (*RAPLSnapshot) DiffWithCurrentRAPL

func (r *RAPLSnapshot) DiffWithCurrentRAPL() (*RAPLValues, error)

DiffWithCurrentRAPL returns the joules used since the snapshot was taken.

func (*RAPLSnapshot) DiffWithCurrentRAPLAndReset

func (r *RAPLSnapshot) DiffWithCurrentRAPLAndReset() (*RAPLValues, error)

DiffWithCurrentRAPLAndReset returns the joules used since the snapshot was taken. The current snapshot is updated so that the next diff will be relative to now.

type RAPLValues

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

RAPLValues represents the Intel "Running Average Power Limit" (RAPL) values. For further info read: https://www.kernel.org/doc/Documentation/power/powercap/powercap.txt

func (*RAPLValues) Core

func (rapl *RAPLValues) Core() float64

Core returns the joules from the CPU.

func (*RAPLValues) DRAM

func (rapl *RAPLValues) DRAM() float64

DRAM returns the joules from the DRAM.

func (*RAPLValues) Duration

func (rapl *RAPLValues) Duration() time.Duration

Duration returns RAPL measuring time.

func (*RAPLValues) ReportPerfMetrics

func (rapl *RAPLValues) ReportPerfMetrics(perfValues *perf.Values, prefix string)

ReportPerfMetrics appends to perfValues all the RAPL values. prefix is an optional string what will be used in perf.Metric Name.

func (*RAPLValues) ReportWattPerfMetrics

func (rapl *RAPLValues) ReportWattPerfMetrics(perfValues *perf.Values, prefix string, timeDelta time.Duration)

ReportWattPerfMetrics appends to perfValues all the RAPL values in Watts. prefix is an optional string what will be used in perf.Metric Name. timeDelta is the measurement interval in seconds.

func (*RAPLValues) Total

func (rapl *RAPLValues) Total() float64

Total returns the sum of joules at the top level.

func (*RAPLValues) Uncore

func (rapl *RAPLValues) Uncore() float64

Uncore returns the joules from the GPU.

type Status

type Status struct {
	LinePowerConnected bool
	LinePowerCurrent   float64
	LinePowerType      string

	BatteryPresent          bool
	BatteryDischarging      bool
	BatteryPercent          float64
	BatteryDisplayPercent   float64
	BatteryCharge           float64
	BatteryChargeFull       float64
	BatteryChargeFullDesign float64
	BatteryCurrent          float64
	BatteryEnergy           float64
	BatteryEnergyRate       float64
	BatteryVoltage          float64
	BatteryStatus           string
}

Status holds power supply information reported by powerd's dump_power_status tool.

func GetStatus

func GetStatus(ctx context.Context) (*Status, error)

GetStatus returns current power supply information.

type SysfsBatteryMetrics

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

SysfsBatteryMetrics hold the metrics read from sysfs.

func NewSysfsBatteryMetrics

func NewSysfsBatteryMetrics() *SysfsBatteryMetrics

NewSysfsBatteryMetrics creates a struct to capture battery metrics with sysfs.

func (*SysfsBatteryMetrics) Setup

func (b *SysfsBatteryMetrics) Setup(ctx context.Context, prefix string) error

Setup reads the low battery shutdown percent that that we can error out a test if the battery is ever too low.

func (*SysfsBatteryMetrics) Snapshot

func (b *SysfsBatteryMetrics) Snapshot(_ context.Context, values *perf.Values) error

Snapshot takes a snapshot of battery metrics. If there are no batteries can be used to report the metrics, Snapshot does nothing and returns without error.

func (*SysfsBatteryMetrics) Start

Start captures the initial battery state which the first snapshot will be relative to.

func (*SysfsBatteryMetrics) Stop

func (b *SysfsBatteryMetrics) Stop(_ context.Context, values *perf.Values) error

Stop reports the total amount of energy used during the test.

type SysfsThermalMetrics

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

SysfsThermalMetrics holds the metrics to read from sysfs.

func NewSysfsThermalMetrics

func NewSysfsThermalMetrics() *SysfsThermalMetrics

NewSysfsThermalMetrics creates a struct to capture thermal metrics with sysfs.

func (*SysfsThermalMetrics) Setup

func (b *SysfsThermalMetrics) Setup(ctx context.Context, prefix string) error

Setup checks which thermal sensors are available.

func (*SysfsThermalMetrics) Snapshot

func (b *SysfsThermalMetrics) Snapshot(ctx context.Context, values *perf.Values) error

Snapshot takes a snapshot of thermal metrics. If there are no thermal sensors, Snapshot does nothing and returns without error.

func (*SysfsThermalMetrics) SnapshotValues

func (b *SysfsThermalMetrics) SnapshotValues(ctx context.Context) (map[perf.Metric]float64, error)

SnapshotValues takes a snapshot of thermal metrics and returns a map of metrics to values.

func (*SysfsThermalMetrics) Start

func (b *SysfsThermalMetrics) Start(ctx context.Context) error

Start is not required for SysfsThermalMetrics.

func (*SysfsThermalMetrics) Stop

func (b *SysfsThermalMetrics) Stop(ctx context.Context, values *perf.Values) error

Stop does nothing.

type ThermalMetric

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

ThermalMetric holds the name, sysfs path and perf.Metric object of a thermal sensor.

type UserActivityType

type UserActivityType int32

UserActivityType is a status code for the PowerManager related D-Bus methods.

Directories

Path Synopsis
Package charge provides necessary functionality to perform battery charge, drain on DUT.
Package charge provides necessary functionality to perform battery charge, drain on DUT.
Package setup contains helpers to set up a DUT for a power test.
Package setup contains helpers to set up a DUT for a power test.

Jump to

Keyboard shortcuts

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