mirror of
https://github.com/kuhyx/testsAndMisc.git
synced 2026-11-11 21:54:00 +01:00
Three units along the file's own concerns: atop_agg.c (204) ingest -- tokenising atop output, folding lines, main atop_agg_state.c (113) the per-PID hash tables, slot lookup, epochs, alloc atop_agg_emit.c (178) the ranked, name-aggregated report Table geometry and the four table functions that now cross a unit boundary go in a private atop_agg_internal.h. Those four lose `static` -- the one visibility change here. The Makefile edit is the load-bearing part: SRC had to grow or the build would have linked the old single unit and the suite would have passed with the new files unused. Checked by reading the compile line, not the exit status. I had written this file off as unverifiable earlier. Wrong: the Makefile has had test and coverage targets all along. Coverage is 92.9% lines / 100% functions on the same 211 source lines, before and after -- the best verifier of anything left over the cap. Production binary builds at -O2 and runs. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011w2Pj4Ek3ZNMQVYcFHgXDY
36 lines
1.2 KiB
C
36 lines
1.2 KiB
C
/*
|
|
* Private constants shared between atop_agg.c (ingest) and atop_agg_emit.c
|
|
* (reporting). Not part of the public interface in atop_agg.h: callers of the
|
|
* library never need the table geometry, but both translation units size their
|
|
* loops and stack buffers from it, so it cannot live in either .c file alone.
|
|
*/
|
|
#ifndef ATOP_AGG_INTERNAL_H
|
|
#define ATOP_AGG_INTERNAL_H
|
|
|
|
#include "atop_agg.h"
|
|
|
|
/*
|
|
* A real-world day of atop on a dev box can see >700k distinct PIDs
|
|
* because every short-lived compiler/shell subprocess gets a fresh ID.
|
|
* 2M slots keeps the load factor below ~40% for that workload, keeping
|
|
* linear-probe chains short without dynamic resizing.
|
|
*/
|
|
#define HASH_CAP_BITS 21
|
|
#define HASH_CAP (1u << HASH_CAP_BITS)
|
|
#define HASH_MASK (HASH_CAP - 1u)
|
|
#define MAX_EPOCHS 4096
|
|
#define MAX_TOKENS 64
|
|
|
|
|
|
/*
|
|
* Table internals, shared because ingest (atop_agg.c) looks slots up while
|
|
* allocation and epoch recording live in atop_agg_state.c. Not `static` any
|
|
* more precisely because they now cross a translation-unit boundary.
|
|
*/
|
|
unsigned int hash_pid(int pid);
|
|
PidCpu *cpu_slot(State *s, int pid);
|
|
PidRam *ram_slot(State *s, int pid);
|
|
void add_epoch(State *s, long epoch);
|
|
|
|
#endif /* ATOP_AGG_INTERNAL_H */
|