Artifact 37512e39f8bf1325dd7427974f173d87d55f4b1e47161564e5d7ee94bd8b0e3d:
- File
src/tally.h
— part of check-in
[38c2e6220a]
at
2026-11-16 21:25:35
on branch trunk
— Suit counts how often each skill, agent and command is used
The counts come from the records a harness already keeps of its own work, read afterwards. What those records look like is data in the wardrobe's harness section: where the files are, where a record's time and folder are, and rules that say what an invocation looks like. No harness is named in suit's code. docs/harnesses.md has the rules for the first harness, checked against real records.
A streaming reader walks each JSON line against the rules in 64 KiB chunks, keeps at most the first 512 bytes of any string and stops at 64 levels, so a line of any length cannot grow its memory. It has its own fuzz target.
Suit keeps its own tally per machine under usage/ in its home folder, outside any wardrobe: one line per invocation with time, harness, kind, name, project and call id. A call copied into a resumed or forked record is counted once, by its id. The tally outlives the harness's own clean-up and drops what is older than 400 days.
suit usage scan reads what is new; a first scan reads files changed in the last 45 days and later scans read only new bytes. suit usage prints the table for a window, default 30 days, and --tsv gives the same rows for other tools. suit tend with no name runs the scan after tending; a failed scan is reported and changes nothing else. suit-run is untouched and the speed budget passes as before.
Measured: a generated tree of 200 files and 200 MiB scans in about half a second and a second scan opens no record file. On a real tree of 2547 files, read-only into a scratch home: 3756 invocations in 60 seconds, 10 MiB at peak.
A new suite, test/usage.sh, with 236 cases, is part of the gate.
2855 unit checks (was 1473), 620 shell cases, 1153 store cases, 846 placement cases, 378 project cases and 236 usage cases, under clang, under gcc 16, with no user name set, and under a strict umask, in one run of make gate (41 minutes). 100% coverage in all 28 source files. One existing unit line changed: a table of fault points gained entries. (user: dmestas, size: 2369) [annotate] [blame] [check-ins using]
#ifndef SUIT_TALLY_H #define SUIT_TALLY_H #include <stddef.h> #include <stdint.h> // Usage counts (docs/usage.md): what suit keeps, per machine, of how often each // skill, agent and command was invoked, read from the session records the // harnesses keep. $SUIT_HOME/usage/events and $SUIT_HOME/usage/offsets. constexpr size_t TALLY_EVENTS_FILE_MAX = 33554432; // the events file, in bytes constexpr size_t TALLY_EVENTS_NEW_MAX = 8388608; // the events one scan may add, in bytes constexpr uint32_t TALLY_EVENTS_MAX = 500000; // events kept constexpr uint32_t TALLY_FILES_MAX = 16384; // session files known at once constexpr uint32_t TALLY_ROWS_MAX = 65536; // distinct names in one report constexpr int TALLY_DAYS_KEPT = 400; // events older than this are dropped constexpr int TALLY_FIRST_SCAN_DAYS = 45; // a first scan reads files modified this recently constexpr int TALLY_WINDOW_DEFAULT = 30; // `suit usage scan`: read what is new in every harness's session records and // add it to the tally. Prints one line. 0, 1 after a message, 2 for a config // the scan cannot use, or EXIT_BUSY. int cmd_usage_scan(void); // `suit usage [--since DAYS] [--kind KIND] [--harness NAME] [--project KEY] [--tsv]`: // a scan, then the table. ARGV is what follows "usage". 2 for bad arguments. int cmd_usage(int argc, char **argv); // `suit tend` with no name: tend every wardrobe, then scan once. The scan's // failure is reported and does not change the exit status. int cmd_tend_all(void); // ---- for the tests ---------------------------------------------------------- // SEC seconds since 1970 as "YYYY-MM-DDTHH:MM:SS" into OUT (20 bytes). void tally_civil(int64_t sec, char out[20]); // Whether the LEN bytes start with a time of that form and hold no tab or newline. bool tally_time_ok(const char *t, size_t len); // Drop the lines of BUF (LEN bytes, each ending in a newline, starting with a // time) whose time is before CUTOFF, then lines from the front until at most // MAX_EVENTS lines and MAX_BYTES bytes remain. Returns the new length. size_t tally_trim(char *buf, size_t len, const char *cutoff, uint32_t max_events, size_t max_bytes); // Whether the PLEN bytes of PATTERN, with "*" for any run of bytes, match all of NAME. bool tally_wild(const char *pattern, size_t plen, const char *name); #endif