Something went wrong. Try again.
This repository has no description
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839#!/usr/bin/env bash# Samples how many CPUs this machine's work keeps busy, every <interval> seconds, until# killed. One line per sample: "<unix time> <busy CPUs>", where busy CPUs is CPU time# used over the interval divided by the interval (so 12.5 means twelve and a half threads# kept busy on average).## bench/cpu-sample.sh <out-file> [interval-seconds, default 2]## Reads the container's own cgroup (/sys/fs/cgroup/cpu.stat, usage_usec) when there is# one, which counts this guest's work only -- on a build lane that is what matters, since# /proc/stat inside an LXC shows the whole node, other tenants included. Falls back to# /proc/stat's non-idle time otherwise. bench/cpu-phases.py turns the samples into# per-phase averages and peaks.set -euo pipefailOUT="${1:?usage: bench/cpu-sample.sh <out-file> [interval-seconds]}"INTERVAL="${2:-2}"
# Prints cumulative busy CPU time in microseconds.busy_usec() { if [ -r /sys/fs/cgroup/cpu.stat ]; then awk '$1 == "usage_usec" { print $2; exit }' /sys/fs/cgroup/cpu.stat else # user nice system idle iowait irq softirq steal, in clock ticks (USER_HZ, 100/s). awk '$1 == "cpu" { print ($2 + $3 + $4 + $7 + $8 + $9) * 10000; exit }' /proc/stat fi}
: > "$OUT"prev_t="$EPOCHREALTIME"prev_u="$(busy_usec)"while sleep "$INTERVAL"; do t="$EPOCHREALTIME" u="$(busy_usec)" awk -v t0="$prev_t" -v t1="$t" -v u0="$prev_u" -v u1="$u" \ 'BEGIN { printf "%.3f %.2f\n", t1, (u1 - u0) / ((t1 - t0) * 1e6) }' >> "$OUT" prev_t="$t" prev_u="$u"done