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
78
79
80
81
82
83
84
85
86
87
88
89
|
# AGENTS.md
This file provides guidance to AI coding assistants working with the I/O Riot NG (ior) codebase.
## Build/Test Commands
**Prerequisites**: Ensure `libbpfgo` is cloned at `../libbpfgo` relative to this repository (or set `LIBBPFGO`), pinned to `v0.9.2-libbpf-1.5.1`, and rebuilt with:
```bash
git -C ../libbpfgo checkout v0.9.2-libbpf-1.5.1
git -C ../libbpfgo submodule update --init --recursive
make -C ../libbpfgo libbpfgo-static
```
If builds/tests fail with missing libbpf headers (for example `bpf/bpf.h` not found), rerun the commands above and then run `env GOTOOLCHAIN=auto mage world`. Prefer Mage targets over raw `go test` for packages that import `libbpfgo`; Mage wires the required `CGO_CFLAGS`, `CGO_LDFLAGS`, and `LIBBPFGO` values.
```bash
env GOTOOLCHAIN=auto mage all # Build everything (BPF objects and Go binary)
env GOTOOLCHAIN=auto mage test # Run all tests
GOTOOLCHAIN=auto TEST_NAME=TestEventloop mage testWithName # Run specific test
env GOTOOLCHAIN=auto mage integrationTest # Build + run integration tests (default parallelism is capped)
GOTOOLCHAIN=auto INTEGRATION_PARALLEL=1 mage integrationTest # Force serial integration tests
env GOTOOLCHAIN=auto mage generate # Generate code (required after modifying tracepoint definitions)
env GOTOOLCHAIN=auto mage bench # Run benchmarks
env GOTOOLCHAIN=auto mage prReview # Run PR review baseline: world + benchProf
env GOTOOLCHAIN=auto mage clean # Clean build artifacts
env GOTOOLCHAIN=auto mage world # Clean + generate + test + build (recommended reset path)
```
## Code Generation
**Run `mage generate` before building when tracepoint definitions change!**
A Mage target generates code from Linux kernel tracepoint data:
```bash
mage generate # Generate all code (C and Go)
mage generateTracepointsC # Generate C tracepoint handlers from /sys/kernel/tracing
mage generateTypesGo # Generate Go types from C structs
mage generateTracepointsGo # Generate Go tracepoint list
```
Generated files (do not edit manually):
- `internal/c/generated_tracepoints.c` - BPF C handlers for syscall tracepoints
- `internal/types/generated_types.go` - Go structs matching C structs + type mappings
- `internal/tracepoints/generated_tracepoints.go` - List of available syscall tracepoints
Generator source code:
- `internal/generate/` - Parser, classifier, and code generation logic
## Architecture
- **Entry point**: `cmd/ior/main.go` - Linux-only BPF-based I/O syscall tracer
- **Core packages**: `/internal/event/` (BPF event handling), `/internal/flamegraph/` (FlameGraph generation), `/internal/c/` (BPF programs)
- **Output**: TUI dashboard and TUI flamegraphs (no embedded web flamegraph server mode)
- **TUI package**: `/internal/tui/` contains top-level Bubble Tea orchestration (`tui.go`), shared key map (`keys.go`), and styles (`styles.go`).
- **Dashboard tabs**: `/internal/tui/dashboard/` contains tab renderers (overview/syscalls/files/processes/latency/gaps) and tab framework model.
- **Export modal**: `/internal/tui/export/model.go` implements the centered modal used for CSV export flow in TUI mode.
## TUI Behavior
- **Default mode** is TUI (`-plain` disables TUI and prints CSV rows to stdout).
- **TUI trace flow** ingests events into the in-memory stats engine; it does **not** continuously write trace rows to disk.
- **File output in TUI** is explicit export only (`e`), writing `ior-stream-<timestamp>.csv` in the current directory from the current filtered stream snapshot.
- **Export toggle flag**: `-tuiExport=true|false` (default `true`) enables or disables TUI stream CSV export at runtime.
- **Tab navigation** supports `tab/shift+tab`, numeric keys `1..6`, and directional keys `left/right` and `h/l`.
- **When export is disabled**, export key hints are hidden from dashboard help and `e` does not open export modal.
## Code Style
- Standard Go conventions with static linking (`-ldflags '-w -extldflags "-static"'`)
- Keep functions under 50 lines, refactor larger code to `/internal/` packages
- Use generated types from `/internal/types/generated_types.go` for kernel-userspace communication
- BPF C code in `/internal/c/ior.bpf.c` should be minimal for verification
- Import style: `"ior/internal/packagename"` for internal packages
- Error handling: Return errors, don't panic except for setup validation
## Rollback
If `v0.9.2-libbpf-1.5.1` stops working, roll the local checkout back to commit
`90dbffffbdab` (module version
`v0.6.0-libbpf-1.3.0.20240111220235-90dbffffbdab`), update `go.mod`/`go.sum`
accordingly, and rebuild:
```bash
git -C ../libbpfgo checkout 90dbffffbdab
git -C ../libbpfgo submodule update --init --recursive
make -C ../libbpfgo libbpfgo-static
```
|