feat(scheduler-sim-diagnostics): promote byte-unit formatting to shared lib (task 7)
Adds Requirement 6 (Human-Readable Units for Byte-Valued Limit Amounts) to the spec: requirements, design, research, and tasks 7-10. Task 7 (Foundation): promotes the REPL's byte-unit scaling algorithm and byte-valued-resource classifier into src/lib/utils.c/utils.h (xce_format_bytes_human, xce_is_bytes_valued_resource), alongside a new display-mode-aware composer (xce_format_units_value, xce_units_mode_t) -- following the fmt_jobid()/fmt_jobid_ex() precedent. repl_fmt.c's scheduler-only functions become one-line delegating wrappers. repl_info.c's repl_format_numeric_resource_value() (shared by info worker/info resource, not just the upcoming info limit) is retyped to delegate to the new shared composer via a small translate_units_mode() bridge, so every consumer benefits from one implementation going forward. No existing symbol's signature changed; only new symbols were added. Confirmed behavior-preserving: full scheduler suite 85/85 unchanged, including info worker/info resource's own regression tests. One narrow, untested, out-of-requirement-scope corner case found and documented (swp's RAW/BOTH mode rendering under the new single-value composer interface) -- logged in tasks.md's Implementation Notes. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01RLSNJhNoULvVcUhXEFafQC
This commit is contained in:
parent
8c363de75f
commit
eb23c158ae
10 changed files with 535 additions and 85 deletions
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include <capnp_c.h>
|
||||
#include <math.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <tlog.h>
|
||||
|
|
@ -211,6 +212,51 @@ extern int fmt_jobid(char*, size_t, uint64_t);
|
|||
extern int parse_jobid(uint64_t*, char*);
|
||||
extern uint64_t array_jobid(uint64_t);
|
||||
extern uint64_t array_idx(uint64_t);
|
||||
|
||||
/*
|
||||
* xce_units_mode_t / xce_format_bytes_human() / xce_is_bytes_valued_resource()
|
||||
* / xce_format_units_value() -- scheduler-sim-diagnostics spec, task 7 (Req
|
||||
* 6.1, 6.3, 6.5). Shared-library promotion of the scheduler REPL's
|
||||
* byte-unit scaling algorithm (formerly repl_fmt.c's
|
||||
* repl_format_bytes_human()), its byte-valued-resource classification
|
||||
* (formerly repl_fmt.c's repl_is_bytes_valued_resource()), and a
|
||||
* display-mode-aware value composer (formerly repl_info.c's
|
||||
* repl_format_numeric_resource_value()'s byte-valued branch), so any
|
||||
* `libxce` consumer -- not only the scheduler's REPL -- can reach this
|
||||
* display-only formatting. `fmt_jobid()`/`fmt_jobid_ex()` immediately above
|
||||
* are the precedent this follows: a small, generic, cross-component
|
||||
* display-formatting helper with no domain coupling.
|
||||
*
|
||||
* All three functions are pure and display-only -- none of them ever
|
||||
* mutate a caller-supplied value or feed back into a stored/wire value.
|
||||
* `xce_is_bytes_valued_resource()` is a fixed 5-name list (`mem`, `tmp`,
|
||||
* `maxmem`, `maxtmp`, `maxswap`); a `NULL` name returns `false`.
|
||||
* `xce_format_bytes_human()` adaptively scales `bytes` to the smallest
|
||||
* B/KB/MB/GB/TB/PB unit it fits, writing e.g. "20.56 GB" into `buf`.
|
||||
* `xce_format_units_value()` assumes the caller has already decided
|
||||
* `bytes_value` is byte-valued (via `xce_is_bytes_valued_resource()` or the
|
||||
* caller's own equivalent check) -- it does not re-derive that decision:
|
||||
* RAW renders the bare "%f" of `bytes_value` alone, HUMAN renders
|
||||
* `xce_format_bytes_human()`'s scaled form alone, and BOTH (the default for
|
||||
* any other mode value) renders "<raw> (<human>)".
|
||||
*
|
||||
* `xce_repl_units_mode_t` (scheduler-private, `repl_internal.h`) is a
|
||||
* deliberately separate, independently-defined enum with the same three
|
||||
* semantic values -- a `src/lib` type must not be defined in terms of a
|
||||
* scheduler-internal concept. The scheduler bridges the two at its one call
|
||||
* site (`repl_info.c`'s `translate_units_mode()`).
|
||||
*/
|
||||
typedef enum {
|
||||
XCE_UNITS_RAW = 1,
|
||||
XCE_UNITS_HUMAN,
|
||||
XCE_UNITS_BOTH
|
||||
} xce_units_mode_t;
|
||||
|
||||
extern void xce_format_bytes_human(double bytes, char* buf, size_t bufsz);
|
||||
extern bool xce_is_bytes_valued_resource(const char* name);
|
||||
extern void xce_format_units_value(xce_units_mode_t mode, double bytes_value,
|
||||
char* buf, size_t bufsz);
|
||||
|
||||
extern void unblock_sig(int);
|
||||
extern void block_sig(int);
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue