LinuxCommandLibrary

powerstat

Measure system power consumption

TLDR

Measure power with the default of 10 samples with an interval of 10 seconds

$ powerstat
copy

Measure power with custom number of samples and interval duration
$ powerstat [interval] [number_of_samples]
copy

Measure power using Intel's RAPL interface
$ powerstat -R [interval] [number_of_samples]
copy

Show a histogram of the power measurements
$ powerstat -H [interval] [number_of_samples]
copy

Enable all statistics gathering options
$ powerstat -a [interval] [number_of_samples]
copy

SYNOPSIS

powerstat [options] [interval] [count]

PARAMETERS

-r
    Raw output
Displays raw power values without unit conversion or aggregation.

-c
    CSV output
Outputs data in a comma-separated values (CSV) format, suitable for parsing and analysis.

-C
    Cumulative power
Reports cumulative power consumption since the start of the command or the last reset.

-p
    Per-processor power
Shows power consumption for each individual CPU core/processor if supported by hardware.

-a
    Show all
Includes all available power metrics in the output, overriding defaults.

-q
    Quiet mode
Suppresses the initial header, displaying only the power statistics.

-H
    No header
Similar to -q, but typically used for more compact output when piping to other tools.

-i interval
    Sampling interval
Sets the time in seconds between each power measurement sample. The default is 5 seconds.

-n count
    Number of samples
Specifies the total number of samples to take before exiting. By default, powerstat runs indefinitely.

-R
    Reset battery counter
Resets the battery power counter, useful for starting a fresh measurement cycle.

-s
    System units
Displays power in system units (e.g., Watts) instead of the default percentage or other abstracted units.

-z
    Show idle states
Includes information about CPU idle states (C-states) and their residency.

-d
    Debug output
Enables verbose debugging information, useful for troubleshooting.

-D
    Display device names
Attempts to display human-readable names for detected power devices.

-h
    Help
Displays a brief help message and exits.

-o FILENAME
    Output to file
Redirects the command's output to the specified file instead of standard output.

-S SECTION
    Specific section
Filters the output to show only a particular section, e.g., CPU, GPU, DEVICES, BATTERY.

-T
    Show temperature
Includes temperature readings from available sensors in the output.

-v
    Version
Displays the powerstat version information and exits.

DESCRIPTION

powerstat is a Linux command-line tool designed to measure the power consumption of a running system. It provides real-time insights into various power-related metrics, including CPU, GPU, device, and battery usage. The tool samples power counters and presents the data in a human-readable format, making it invaluable for diagnosing power-related issues, evaluating power efficiency of hardware components, or monitoring the impact of system configurations on energy consumption.

It relies on hardware support for reporting power data, such as Intel's RAPL (Running Average Power Limit) interface for CPUs. powerstat can display average, minimum, and maximum power values over a specified interval, helping users understand power trends under different workloads. Its output can be customized to show raw data, CSV format, or focus on specific hardware sections. It's often used by developers and system administrators to optimize energy usage and extend battery life on portable devices.

CAVEATS

Root Privileges Required: powerstat often requires root privileges (or sudo) to access hardware power counters and system metrics.

Hardware Dependency: The accuracy and completeness of the reported data are highly dependent on the underlying hardware's support for power reporting interfaces (e.g., Intel RAPL, AMD PMC, ACPI). Not all systems or components will provide full data.

System Overhead: While generally lightweight, running powerstat continuously may introduce a minimal amount of system overhead due to data sampling.

Interpretation: Understanding the reported values (especially raw ones) might require knowledge of specific hardware architectures and power management concepts.

UNITS OF MEASUREMENT

By default, powerstat attempts to display power in Watts (W) or Joules (J), but depending on the hardware and the -s option, it might show percentages or abstract values. Understanding the units is crucial for correct interpretation.

TYPICAL USAGE

A common way to use powerstat is sudo powerstat 5 10 to take 10 samples at 5-second intervals, or sudo powerstat -S CPU to focus specifically on CPU power.

INTERPRETING OUTPUT

The output typically shows average, minimum, and maximum power consumption over the sampling period, along with battery drain rates if applicable. High variability between min/max can indicate fluctuating workloads.

HISTORY

powerstat originated from the Ubuntu Kernel team, with significant contributions from Arjan van de Ven. It was developed to provide a simpler, more direct alternative or complement to existing power profiling tools like powertop, which primarily focuses on identifying specific processes or components causing power drain. powerstat instead gives an immediate, aggregated overview of system-wide power consumption, making it quick to assess the overall power state and the impact of system changes. Its development aligns with the broader Linux community's effort to improve power efficiency on servers and portable devices.

SEE ALSO

powertop(8), perf(1), turbostat(8), s-tui(1), mpstat(1), iostat(1)

Copied to clipboard