mirror of
https://github.com/ebrandi/FDD-book.git
synced 2026-12-06 00:23:30 +00:00
Organize companion code and materials by book part: part-01/ Foundations part-02/ Kernel & driver fundamentals part-03/ Character & block devices part-04/ Networking & storage part-05/ Buses & advanced topics part-06/ Debugging & performance part-07/ Real-world drivers appendices/ Supplementary material README.md Overview and build instructions
43 lines
1 KiB
Bash
Executable file
43 lines
1 KiB
Bash
Executable file
#!/bin/sh
|
|
#
|
|
# read-histogram.sh - poll the v2.3 latency histogram every second
|
|
# and print a simple textual display.
|
|
#
|
|
# Usage: ./read-histogram.sh [iterations]
|
|
|
|
ITER=${1:-10}
|
|
BOUNDS="<=1us <=10us <=100us <=1ms <=10ms <=100ms <=1s >1s"
|
|
|
|
if [ ! -c /dev/perfdemo ]; then
|
|
echo "perfdemo is not loaded."
|
|
exit 1
|
|
fi
|
|
|
|
for i in $(seq 1 $ITER); do
|
|
echo "=== $(date) ==="
|
|
# sysctl -x prints raw hex; we need to turn it into 8 uint64.
|
|
sysctl -b hw.perfdemo.latency_histogram | \
|
|
od -An -tu8 -v -w64 | \
|
|
tr -s ' ' '\n' | grep -v '^$' | head -8 > /tmp/perfdemo_hist
|
|
|
|
total=0
|
|
while read n; do
|
|
total=$((total + n))
|
|
done < /tmp/perfdemo_hist
|
|
|
|
echo "Total samples: $total"
|
|
idx=1
|
|
for b in $BOUNDS; do
|
|
n=$(sed -n "${idx}p" /tmp/perfdemo_hist)
|
|
if [ "$total" -gt 0 ]; then
|
|
pct=$(echo "scale=1; $n * 100 / $total" | bc)
|
|
else
|
|
pct=0
|
|
fi
|
|
printf " %-10s %8d (%.1f%%)\n" "$b" "$n" "$pct"
|
|
idx=$((idx + 1))
|
|
done
|
|
sleep 1
|
|
done
|
|
|
|
rm -f /tmp/perfdemo_hist
|