Appendix A: Cheat sheet
What this appendix is for: looking things up when
you know what you want to measure but have forgotten how to
write it. It explains nothing new; the days in parentheses lead to the
chapters in which every command is shown with all options and real
output. All commands run on the target system (perf1 in the course)
unless stated otherwise. Replace PID, DIENST
(service) and DEV (device) with your values.
The 60-second check
In this order, each command on its own (Day 2). The rough picture
first, then break it down, top at the end.
| No. |
Command |
What you look for |
USE |
| 1 |
uptime |
load average – rising or falling? Compare with the number of
CPUs |
saturation (rough) |
| 2 |
sudo dmesg -T \| tail |
OOM killer, disk errors, dropped packets |
errors |
| 3 |
vmstat 1 5 |
r > CPUs, b > 0,
si/so > 0, wa, st
(ignore the first line) |
everything, roughly |
| 4 |
mpstat -P ALL 1 5 |
one CPU at 100 %, the others idle? %iowait,
%steal |
utilization, imbalance |
| 5 |
pidstat 1 5 |
who is computing, is %wait high? |
who? |
| 6 |
iostat -sxz 1 5 |
await, aqu-sz, %util per
device |
utilization, saturation |
| 7 |
free -m |
available, not free |
utilization |
| 8 |
sar -n DEV 1 5 |
throughput per network card against the baseline |
utilization |
| 9 |
sar -n TCP,ETCP 1 5 |
retrans/s, estres/s |
errors |
| 10 |
top |
cross-check |
– |
USE checklist for Linux
For every resource: Utilization,
Saturation, Errors (Day 1).
| Resource |
Utilization |
Saturation |
Errors |
| CPU |
mpstat -P ALL 1: 100 - %idle per CPU |
vmstat 1: r > number of CPUs;
cat /proc/pressure/cpu; runqlat-bpfcc (Day 4,
14) |
– (rare; perf stat for hardware) |
| CPU in a cgroup |
systemd-cgtop -c |
cpu.stat:
nr_throttled/nr_periods; the cgroup’s
cpu.pressure (Day 15) |
– |
| Memory |
free -m: available;
sar -r 1 |
vmstat 1: si/so;
/proc/pressure/memory; sar -B 1:
pgscank/s (Day 6, 7) |
dmesg: Out of memory,
oom-kill |
| Memory in a cgroup |
memory.current |
memory.events: high;
memory.pressure (Day 7) |
memory.events: oom_kill |
| Disk |
iostat -x 1: %util |
iostat -x 1: aqu-sz, *_await;
/proc/pressure/io (Day 9) |
dmesg: I/O error |
| File system |
df -h |
fsync duration (bpftrace, Day 8, 14) |
dmesg: EXT4-fs error |
| Network card |
sar -n DEV 1: rxkB/s, txkB/s
against the link rate |
tc -s qdisc: backlog,
dropped; ip -s link (Day 11, 12) |
ip -s link: errors,
dropped |
| TCP |
ss -tin (per connection) |
ss -lnt: Recv-Q on listening sockets;
nstat -az TcpExtListenOverflows (Day 12) |
sar -n ETCP 1: retrans/s |
| conntrack |
nf_conntrack_count against
nf_conntrack_max
(sysctl net.netfilter.nf_conntrack_count net.netfilter.nf_conntrack_max) |
– |
dmesg: table full, dropping packet (Day
12) |
Who, what, where – the next questions
| Question |
Command |
Day |
| Which process is computing? |
pidstat -u 1 5 |
2 |
| Which service is computing? |
systemd-cgtop -b -n 3 -d 4 --depth=2 -c system.slice |
15 |
| Which cgroup is PID in? |
cat /proc/PID/cgroup |
3, 15 |
| Which function is computing? |
sudo perf record -F 99 -g -p PID -- sleep 10, then
sudo perf report --stdio |
5 |
| Flame graph |
sudo perf script > out.perf,
~/FlameGraph/stackcollapse-perf.pl out.perf > out.folded,
~/FlameGraph/flamegraph.pl out.folded > flame.svg |
5 |
| Python functions in perf |
PYTHONPERFSUPPORT=1 in the process’s environment (from
Python 3.12) |
16 |
| Which system calls, how long? |
sudo syscount-bpfcc -L -p PID -d 10 |
14, 16 |
| Which files does a process open? |
sudo opensnoop-bpfcc -p PID |
8 |
| Who starts processes? |
sudo execsnoop-bpfcc |
14 |
| Who is growing in memory? |
ps -eo pid,rss,comm --sort=-rss, then
pidstat -r -p PID 1 |
6 |
| Who is in swap? |
grep VmSwap /proc/PID/status |
7 |
| How long do block requests wait? |
sudo biolatency-bpfcc -D 10 1 |
9, 14 |
| How long do processes wait for the CPU? |
sudo runqlat-bpfcc -m 5 1 |
4, 14 |
| Count system calls without slowing down |
sudo perf stat -e raw_syscalls:sys_enter BEFEHL |
13 |
bpftrace one-liners
All with sudo, stop with Ctrl+C; the maps appear
automatically (Day 14).
| Question |
One-liner |
| System calls per process |
bpftrace -e 'tracepoint:raw_syscalls:sys_enter { @[comm] = count(); }' |
openat per process |
bpftrace -e 'tracepoint:syscalls:sys_enter_openat { @[comm] = count(); }' |
Which files does cat open? |
bpftrace -e 'tracepoint:syscalls:sys_enter_openat /comm == "cat"/ { printf("%d %s %s\n", pid, comm, str(args.filename)); }' |
| Disk bytes per process |
bpftrace -e 'tracepoint:block:block_rq_issue { @[comm] = sum(args.bytes); }' |
Duration of fsync as a histogram |
bpftrace -e 'tracepoint:syscalls:sys_enter_fsync { @s[tid] = nsecs; } tracepoint:syscalls:sys_exit_fsync /@s[tid]/ { @ms[comm] = hist((nsecs - @s[tid]) / 1000000); delete(@s[tid]); }' |
| Fields of a tracepoint |
bpftrace -lv tracepoint:block:block_rq_issue |
| What is loaded? |
sudo bpftool prog list |
Setting and checking limits
| Goal |
Command |
Day |
| Start a command with a CPU quota |
sudo systemd-run --unit=NAME -p CPUQuota=50% BEFEHL |
15 |
| Weight for a service |
CPUWeight=10 in the unit, then
daemon-reload and restart |
15, 16 |
| Disk throttle |
sudo systemd-run --unit=NAME -p "IOWriteBandwidthMax=/dev/sdb 20M" BEFEHL |
15 |
| Memory limit |
MemoryHigh= / MemoryMax= in the unit |
7 |
| Limit on the running service |
sudo systemctl set-property --runtime DIENST CPUQuota=50% |
15 |
| Undo runtime changes |
sudo systemctl revert DIENST |
15 |
| What applies? |
systemctl show -p CPUWeight -p CPUQuotaPerSecUSec DIENST |
15 |
| sysctl for now |
sudo sysctl -w NAME=WERT |
15 |
| sysctl for good |
/etc/sysctl.d/NN-name.conf with a comment, then
sudo sysctl --system |
15 |
| I/O scheduler |
cat /sys/block/DEV/queue/scheduler;
echo none \| sudo tee /sys/block/DEV/queue/scheduler |
15 |
(BEFEHL = command, WERT = value.)
Generating and measuring load
| Goal |
Command |
Day |
| CPU load |
stress-ng --cpu 4 --timeout 60s |
1, 4 |
| Disk throughput |
fio --name=t --filename=/daten/t.bin --size=2G --rw=randread --bs=4k --iodepth=32 --ioengine=libaio --direct=1 --runtime=20 --time_based --group_reporting |
10 |
| Network throughput |
on last1 iperf3 -s, on perf1
iperf3 -c last1 -t 10 |
11 |
| HTTP load |
wrk -t2 -c8 -d30s --latency http://perf1:PORT/ |
12, 15, 16 |
| Measure one request |
curl -s -o /dev/null -w "%{time_connect} %{time_total}\n" URL |
16 |
| Delay the network (test) |
sudo tc qdisc add dev eth0 root netem delay 20ms; undo
with sudo tc qdisc del dev eth0 root |
11 |
Rules of thumb
- First the number, then the cause. Every
investigation starts with a measurement of the symptom.
- Averages lie, percentiles (p99) and histograms
don’t (Day 1, 14).
- The load average also counts processes waiting in D
– high load with an idle CPU means I/O (Day 3).
available, not free –
free memory is wasted memory (Day 6).
- Throttled processes look like waiting ones: high
%wait on an idle machine → check the cgroup (Day 15).
- You don’t see a throttle at the disk
(
%util low), but in io.pressure (Day 15).
- The sender sees retransmits (Day 11).
- A CPU profile shows no waiting time – use
syscount -L, offcputime, bpftrace (Day 5,
16).
- One change at a time, measure again after each (Day
16).
- Tune only if the difference is larger than the
spread (Day 10, 15).