Per-thread ring storage and sequence allocator for latrec.
latrec.h is usable on its own with an explicitly owned latrec_t. This file backs the convenience API on top of it: one ring per calling thread, opened on first stamp and named <prefix>.<tid>, plus the process-wide sequence counter. Keeping the storage in one translation unit gives a single ring per thread rather than one per includer.
SPDX-FileCopyrightText: Copyright (c) 2026 Northeastern University SPDX-License-Identifier: Apache-2.0
Definition in file latrec.c.
| #define LATREC_TLS_ENTRIES_LOG2 18 |
Capacity of a per-thread ring, as a power of two. The mapping is pre-faulted at open, so the ring is resident and a stamp costs the same at any size; the size sets the footprint and how long a run fits before wrapping. It is file-backed, so that footprint is page cache and disk, not anonymous memory.
Every thread that stamps in a LIBE3_ENABLE_LATREC build opens a ring, with no per-run opt-out, so this default is what an ordinary run of an enabled build costs per thread. It is deliberately modest for that reason: a long capture raises it per role (see entries_log2() below and docs/utilities/latrec.md) rather than every test and example paying for a capacity only a benchmark needs. A ring that wrapped says so: rec_count keeps counting past the capacity. 256 K records = 8 MiB per thread
Definition at line 34 of file latrec.c.
| unsigned entries_log2 |
( |
const char * | role | ) |
|
|
static |
Ring capacity for a role: LATREC_ENTRIES_LOG2_<ROLE> if set, else LATREC_ENTRIES_LOG2, else the compiled-in default. The per-role name is the role uppercased with every non-alphanumeric character replaced by '_', so role "oai.mac" reads LATREC_ENTRIES_LOG2_OAI_MAC. Roles differ by orders of magnitude in stamp rate, so sizing them together either wastes memory or wraps the busiest ring.
- Parameters
-
| role | ring role, NULL or empty for no per-role override |
- Returns
- the capacity as a power of two
< 256 K records = 8 MiB per thread
Definition at line 91 of file latrec.c.
| unsigned entries_log2_from |
( |
const char * | name | ) |
|
|
static |
LATREC_ENTRIES_LOG2 overrides the compiled-in capacity; out-of-range and unparseable values fall back to it.
- Parameters
-
| name | environment variable to read |
- Returns
- the capacity as a power of two, 0 when the variable is unset or invalid
< Smallest ring capacity accepted from the environment, as a power of two
< Largest ring capacity accepted from the environment, as a power of two
< Smallest ring capacity accepted from the environment, as a power of two
< Largest ring capacity accepted from the environment, as a power of two
Definition at line 69 of file latrec.c.
| void latrec_set_output_dir |
( |
const char * | dir | ) |
|
Directory the per-thread rings are written to, for the whole process. Call before the first latrec_tls_open*(); rings already open are unaffected. NULL or empty restores LATREC_DEFAULT_DIR. This chooses where, never whether: with LIBE3_ENABLE_LATREC on, the recorder records regardless. Two processes that should not share rings (concurrent tests, one benchmark per directory) each set their own.
- Parameters
-
| dir | directory for the rings, NULL or empty for LATREC_DEFAULT_DIR |
Definition at line 114 of file latrec.c.
| latrec_t * latrec_tls_open_as |
( |
const char * | role | ) |
|
Opens the calling thread's ring as <role>.<tid>, or <program>.<tid> when role is NULL or empty; idempotent. Capacity comes from LATREC_ENTRIES_LOG2_<ROLE> (role uppercased, non-alphanumerics as '_'), else LATREC_ENTRIES_LOG2, else the compiled-in default. The open pre-faults the whole mapping, which takes tens of ms; the stamp path does not call it.
- Parameters
-
| role | ring name prefix, NULL or empty for the program name |
- Returns
- the calling thread's ring, a disabled one if the open failed
< Per-thread rings tracked for the flush at exit
Definition at line 122 of file latrec.c.