Add 'stat' command and per-key memory estimation to rdb-cli#103
Draft
moticless wants to merge 4 commits into
Draft
Add 'stat' command and per-key memory estimation to rdb-cli#103moticless wants to merge 4 commits into
moticless wants to merge 4 commits into
Conversation
Introduce a new `stat` output format that aggregates while parsing and, at end-of-RDB, prints a human-formatted memory-statistics report (estimated): a by-type table (keys, items, volatile, expired, memory, avg, mem%) with a TOTAL row, followed by the top-N keys by estimated memory. Memory use is bounded (per-type aggregates + the top-N buffer), independent of the number of keys in the dump. Extend the `print` format with per-key memory specifiers: %n (encoding), %z (estimated in-memory size in bytes) and %g (largest element size). Format specifiers now also accept an optional printf-style width (e.g. %-20k, %10z). Factor the shared key-size accumulation, estimator and file/lifecycle plumbing into a new handlersCommon module reused by both the print and stat handlers, and share the JSON/string escaping helper via extCommon. New public API: RDBX_createHandlersToStat(). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds memory-oriented capabilities to
rdb-cli, surfaced through its generated output:statcommand that prints a human-formatted, estimated memory-statistics report.print(%nencoding,%zestimated bytes,%glargest element), plus optional printf-style field widths.Both share a single key-size estimator, so the per-key
%znumber and thestataggregates are computed the same way.stat— generated outputExtending
rdb-cliUsage:print— extended per-key memory outputNew specifiers for
--key:%nquicklist,listpack,intset,skiplist)%z%gSpecifiers also accept an optional width, e.g.
%-20k,%10z.Implementation notes
handlersCommonmodule holds the shared key-size accumulator, the in-memory size estimator, and file/lifecycle plumbing; both theprintandstathandlers composeRdbxHandlersBaseand register their own data callbacks over it.MEMORY USAGE— calibrated so large keys land within ~25% of liveMEMORY USAGE. It is explicitly an estimate.extCommon(rdbxOutputPlainEscaping).RDBX_createHandlersToStat(p, topN, nowSecs, outFilename).test/test_rdb_to_mem_stat.c.Status
Draft — opening for early feedback on the output format and on the memory-estimation heuristic.
🤖 Generated with Claude Code