summaryrefslogtreecommitdiff
path: root/docs/tutorial/scripts/workload.sh
blob: ebbf58b233de9aefe712fb31fa3049ae114d1954 (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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env bash
# Background workload for demo tapes. Generates a steady mix of file I/O
# (open/read/close), big writes (fsync/dd), stat-heavy traffic, and ioworkload
# scenarios so every TUI tab has something interesting to display.
#
# Designed to be killed via `kill $!` from the tape wrapper. All children are
# placed in this script's process group so a single signal cleans them up.

set -u

ROOT="$(cd "$(dirname "$0")/.." && pwd)"
IOWORKLOAD="${ROOT}/../ioworkload"
SCRATCH="$(mktemp -d -t ior-demo-workload-XXXXXX)"
trap 'rm -rf "$SCRATCH"' EXIT

cleanup() {
    trap - TERM INT
    # Kill the entire process group so all background loops stop.
    kill -- -$$ 2>/dev/null || true
    exit 0
}
trap cleanup TERM INT

# A) walk /usr and read first byte of each file: tons of openat/read/close + varied paths.
(
    while true; do
        find /usr/share /usr/lib -maxdepth 4 -type f 2>/dev/null \
            | shuf -n 800 \
            | xargs -r -I{} sh -c 'head -c 1 "{}" >/dev/null 2>&1' || true
        sleep 1
    done
) &

# B) periodic large write with fsync via dd: fills the latency tab with slow writes.
(
    while true; do
        dd if=/dev/zero of="${SCRATCH}/big.bin" bs=1M count=20 conv=fsync status=none 2>/dev/null || true
        sleep 3
        rm -f "${SCRATCH}/big.bin"
    done
) &

# C) stat-heavy directory crawl: feeds the syscall tab with newfstatat/getdents.
(
    while true; do
        find /etc /var/log -maxdepth 3 >/dev/null 2>&1 || true
        sleep 2
    done
) &

# D) ioworkload scenario rotation if the binary exists: gives us syscall variety
# beyond what the shell utilities trigger (mmap, dup, fcntl, sync, rename, link).
if [ -x "$IOWORKLOAD" ]; then
    (
        scenarios=(
            open-basic
            readwrite-basic
            stat-basic
            stat-statx
            mmap-basic
            sync-basic
            dup-basic
            fcntl-dupfd
            rename-basic
            link-basic
            dir-basic
        )
        while true; do
            for s in "${scenarios[@]}"; do
                "$IOWORKLOAD" --scenario="$s" >/dev/null 2>&1 || true
            done
        done
    ) &
fi

# Idle until killed.
wait