Skip to content

Instantly share code, notes, and snippets.

@dstansby
Created November 23, 2022 18:21
Show Gist options
  • Save dstansby/39f91627542d540b7676f528da9dfb20 to your computer and use it in GitHub Desktop.
Save dstansby/39f91627542d540b7676f528da9dfb20 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
#
# Bash script to sample Intel RAPL inteface and save numbers to a file.
# This script will run until manually interrupted.
#
# The CPU_POWER_OUTPUT_FILE environment variable must be set before
# running this script.
# Make sure CPU_POWER_OUTPUT_FILE variable is defined
set -u
: "$CPU_POWER_OUTPUT_FILE"
# Sampling cadence in seconds
CADENCE="0.1"
COUNTER="/sys/class/powercap/intel-rapl/intel-rapl:0/energy_uj"
echo "Sampling $COUNTER" >> $CPU_POWER_OUTPUT_FILE
echo "Cadence = $CADENCE seconds" >> $CPU_POWER_OUTPUT_FILE
while /bin/true; do
RAPL=$(cat $COUNTER)
TIME=$(date --iso-8601=ns)
echo "$TIME, $RAPL" >> $CPU_POWER_OUTPUT_FILE
sleep $CADENCE
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment