summaryrefslogtreecommitdiff
path: root/bin/run-with-rapl
blob: 54d2d9c3f434df13033e15a6c3ec6a06118c7fe1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#!/bin/sh

DFATOOL="$(dirname "$0")/.."

if test -z "${COUNTERS}"; then
	COUNTERS="$(ls -1 /sys/class/powercap)"
fi

NAMES=
UJ_FILES=
for counter in ${COUNTERS}; do
	if test -e /sys/class/powercap/${counter}/name && test -e /sys/class/powercap/${counter}/energy_uj; then
		NAMES="${NAMES} $(cat /sys/class/powercap/${counter}/name)_${counter} "
		UJ_FILES="${UJ_FILES} /sys/class/powercap/${counter}/energy_uj"
	fi
done

if ! cat ${UJ_FILES} > /dev/null; then
	echo "Unable to read all counters (${UJ_FILES})" >&2
	echo "You may need to run sudo chmod a+r /sys/class/powercap/*/energy_uj" >&2
	exit 1
fi

OUTPUT=$(mktemp)

RAPL_START=$(cat ${UJ_FILES})
3>${OUTPUT} perf stat -x, -e duration_time --log-fd 3 "$@"
RAPL_END=$(cat ${UJ_FILES})

"${DFATOOL}/libexec/rapl-to-dfatool.py" "$(cat ${OUTPUT})" "${NAMES}" "${RAPL_START}" "${RAPL_END}"

rm -f ${OUTPUT}