How atoptool/atop works
Project type and purpose
• Atop is a Linux system- and process-level performance monitor and logger, written in C, with optional kernel/BPF modules and daemons for extended metrics (network, GPU, cgroups).
• It provides both an interactive full-screen ASCII UI (atop), daily raw‐counter logging (atopacctd + atopsar), and utilities (atopcat, atopconvert) for post-processing.
File structure and README
• Top-level binaries & scripts: “atop.c”, “acctproc.c/h”, “atopacctd.c/h”, “atopgpud”, shell scripts and service/timer units.
• Data‐collection modules: cgroups.c/h, gpucom.c/h, ifprop.c/h, netatop*.c, photoproc.c/h, photosyst.c/h, rawlog.c/h, show*.c/h, etc.
• Config & packaging: systemd units, init scripts, Makefile, rpmspec, man pages.
• Previous versions under “prev/”: historical headers for backwards compatibility.
A. Kernel‐space interfaces
1. Native /proc and syscalls (CPU, memory, disk, process tables)
2. Optional netatop kernel module or BPF module (netatop-bpf) for per-process network stats
B. Data‐collection layer (user‐space daemons & libraries)
1. atop (interactive full-screen UI)
2. atopacctd (daemon for interval‐based raw logging)
3. atopgpud (optional GPU daemon)
4. Library modules: cgroups, photoproc, gpucom, netstats, parseable/json, etc.
C. Storage & rotation
1. Raw log files on disk (compressed counters)
2. Systemd timer or cron + atop‐rotate.service for log rotation
D. Post‐processing utilities
1. atopsar (generate reports from raw logs)
2. atopcat / atopconvert (view or convert log data)
E. Packaging & deployment
1. Service units (systemd: atop.service, atopacctd.service, atopgpud.service)
2. SysV/OpenRC scripts (atop.init, atopacct.init)
3. Makefile, rpmspec files
Relationships and data flows
• atopacctd writes raw counter snapshots to log files → storage folder.
• atop (UI) reads live data directly and can read from logs (for retrospective view).
• atopsar, atopcat, atopconvert read raw logs → produce reports/CSV/ASCII.
• Cron/systemd timer triggers rotation service → log rotation and archival.
• Optional netatop and atopgpud feed additional metrics into the same collection pipeline.
Architectural patterns & design principles
• Layered architecture: kernel data sources → user-space collectors → storage → presentation
• Modular collectors: each resource-type (CPU, memory, disk, network, GPU, cgroups) is a separate module, loaded at compile time.
• Daemonization: distinct processes handle logging (atopacctd) vs. live UI (atop).
• Extensibility points: add new modules (e.g. netatop-bpf) by implementing collector interfaces (shown in json.h / parseable.h).
• Separation of concerns: I/O & parsing in “json.c/h” and “parseable.c/h”; display logic in “drawbar.c”, “show*.c”.
Technologies & frameworks to call out
• Language: C
• IPC / Metrics sourcing: /proc, netlink, BPF, kernel module interfaces
• Compression: inline gzip during rawlog writes
• Scheduling: systemd timers, cron jobs, shell scripts
• Packaging: RPM spec, Makefile, init scripts
• Terminal UI: ASCII full-screen via ncurses-style drawing routines