Documentation
¶
Overview ¶
Package power interacts with power management on behalf of local tests.
Index ¶
- Constants
- func ListSysfsBatteryPaths(ctx context.Context) ([]string, error)
- func ListSysfsThermalSensors(ctx context.Context) (map[string]string, error)
- func LowBatteryShutdownPercent(ctx context.Context) (float64, error)
- func NewSignalWatcher(ctx context.Context, signalNames ...string) (*dbusutil.SignalWatcher, error)
- func ReadBatteryCapacity(devPath string) (float64, error)
- func ReadBatteryChargeNow(devPath string) (float64, error)
- func ReadBatteryEnergy(devPath string) (float64, error)
- func ReadBatteryProperty(devPath, property string) (float64, error)
- func ReadSystemPower(devPath string) (float64, error)
- func RequestKeepAwake(ctx context.Context, tconn *chrome.TestConn, level Level) (func(ctx context.Context, tconn *chrome.TestConn) error, error)
- func SetDisplayPower(ctx context.Context, powerStatus DisplayPowerStatus) error
- func SignalName(s *dbus.Signal) string
- func SysfsBatteryPath(ctx context.Context) (string, error)
- func TestMetrics() []perf.TimelineDatasource
- func TurnOnDisplay(ctx context.Context) error
- type BatteryStatus
- type CPUUsageJiffies
- type CpuidleStateMetrics
- func (cs *CpuidleStateMetrics) Setup(ctx context.Context, prefix string) error
- func (cs *CpuidleStateMetrics) Snapshot(ctx context.Context, values *perf.Values) error
- func (cs *CpuidleStateMetrics) Start(ctx context.Context) error
- func (cs *CpuidleStateMetrics) Stop(ctx context.Context, values *perf.Values) error
- type DisplayManager
- type DisplayPowerStatus
- type Level
- type PackageCStatesMetrics
- func (cs *PackageCStatesMetrics) Setup(ctx context.Context, prefix string) error
- func (cs *PackageCStatesMetrics) Snapshot(ctx context.Context, values *perf.Values) error
- func (cs *PackageCStatesMetrics) Start(ctx context.Context) error
- func (cs *PackageCStatesMetrics) Stop(ctx context.Context, values *perf.Values) error
- type PowerManager
- func (m *PowerManager) GetScreenBrightnessPercent(ctx context.Context) (float64, error)
- func (m *PowerManager) GetSwitchStates(ctx context.Context) (*pmpb.SwitchStates, error)
- func (m *PowerManager) HandleWakeNotification(ctx context.Context) error
- func (m *PowerManager) SetScreenBrightness(ctx context.Context, percentage float64) error
- type PowerManagerEmitter
- func (p *PowerManagerEmitter) EmitDarkSuspendImminent(ctx context.Context, msg *pmpb.SuspendImminent) error
- func (p *PowerManagerEmitter) EmitPowerSupplyPoll(ctx context.Context, msg *pmpb.PowerSupplyProperties) error
- func (p *PowerManagerEmitter) EmitSuspendDone(ctx context.Context, msg *pmpb.SuspendDone) error
- func (p *PowerManagerEmitter) EmitSuspendImminent(ctx context.Context, msg *pmpb.SuspendImminent) error
- func (*PowerManagerEmitter) Stop(ctx context.Context) error
- type ProcfsCPUMetrics
- type RAPLPowerMetrics
- type RAPLSnapshot
- type RAPLValues
- func (rapl *RAPLValues) Core() float64
- func (rapl *RAPLValues) DRAM() float64
- func (rapl *RAPLValues) Duration() time.Duration
- func (rapl *RAPLValues) ReportPerfMetrics(perfValues *perf.Values, prefix string)
- func (rapl *RAPLValues) ReportWattPerfMetrics(perfValues *perf.Values, prefix string, timeDelta time.Duration)
- func (rapl *RAPLValues) Total() float64
- func (rapl *RAPLValues) Uncore() float64
- type Status
- type SysfsBatteryMetrics
- func (b *SysfsBatteryMetrics) Setup(ctx context.Context, prefix string) error
- func (b *SysfsBatteryMetrics) Snapshot(_ context.Context, values *perf.Values) error
- func (b *SysfsBatteryMetrics) Start(_ context.Context) error
- func (b *SysfsBatteryMetrics) Stop(_ context.Context, values *perf.Values) error
- type SysfsThermalMetrics
- func (b *SysfsThermalMetrics) Setup(ctx context.Context, prefix string) error
- func (b *SysfsThermalMetrics) Snapshot(ctx context.Context, values *perf.Values) error
- func (b *SysfsThermalMetrics) SnapshotValues(ctx context.Context) (map[perf.Metric]float64, error)
- func (b *SysfsThermalMetrics) Start(ctx context.Context) error
- func (b *SysfsThermalMetrics) Stop(ctx context.Context, values *perf.Values) error
- type ThermalMetric
- type UserActivityType
Constants ¶
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 ¶
ListSysfsBatteryPaths lists paths of batteries which supply power to the system and has voltage_now and current_now attributes.
func ListSysfsThermalSensors ¶
ListSysfsThermalSensors lists names and paths of thermal sensors which can be read through sysfs.
func LowBatteryShutdownPercent ¶
LowBatteryShutdownPercent gets the battery percentage below which the system turns off.
func NewSignalWatcher ¶
NewSignalWatcher creates an D-Bus signal watcher on PowerManager interface.
func ReadBatteryCapacity ¶
ReadBatteryCapacity returns the percentage of current charge of a battery which comes from /sys/class/power_supply/<supply name>/capacity.
func ReadBatteryChargeNow ¶
ReadBatteryChargeNow returns the charge of a battery in Ah. which comes from /sys/class/power_supply/<supply name>/charge_now.
func ReadBatteryEnergy ¶
ReadBatteryEnergy returns the remaining energy of a battery in Wh.
func ReadBatteryProperty ¶
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 ¶
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 ¶
SignalName extracts the signal name from a dbus.Signal object.
func SysfsBatteryPath ¶
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 ¶
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 ¶
Snapshot computes the cpuidle residency between this and the previous snapshot, and reports them as metrics.
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 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 ¶
Snapshot computes the package cstate residency between this and the previous snapshot, and reports them as metrics.
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.
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.
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 ¶
Snapshot computes the energy consumption between this and the previous snapshot, and reports them as metrics.
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.
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 ¶
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.
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 ¶
Snapshot takes a snapshot of thermal metrics. If there are no thermal sensors, Snapshot does nothing and returns without error.
func (*SysfsThermalMetrics) SnapshotValues ¶
SnapshotValues takes a snapshot of thermal metrics and returns a map of metrics to values.
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.
Source Files
¶
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. |