While working on the PPC64LE dynarec, I added a small debugging aid that I think would be useful upstream as well.
What this adds:
-
rbtree_walk() — a generic in-order tree traversal function for rbtree_t that calls a user-provided callback for each node with (start, end, data, userdata). This is a read-only utility alongside the existing rbtree_print().
-
Dynablock size histogram at exit — when LOG_INFO is enabled and DYNAREC is compiled in, FreeBox64Context() prints a histogram of live dynablock sizes (by x86 code size) before tearing down db_sizes. It shows the distribution across 12 buckets (1-8 bytes through 8193+), plus total block count, total bytes, max size, and average size.
Example output:
BOX64 Dynarec block size histogram (14523 live blocks, 1843200 total x64 bytes, max=6144, avg=126):
1-8 bytes: 3241 blocks (22.3%)
9-16 bytes: 2856 blocks (19.7%)
17-32 bytes: 2190 blocks (15.1%)
33-64 bytes: 1987 blocks (13.7%)
65-128 bytes: 1654 blocks (11.4%)
129-256 bytes: 1203 blocks ( 8.3%)
257-512 bytes: 782 blocks ( 5.4%)
513-1024 bytes: 410 blocks ( 2.8%)
1025-2048 bytes: 142 blocks ( 1.0%)
2049-4096 bytes: 48 blocks ( 0.3%)
4097-8192 bytes: 10 blocks ( 0.1%)
This replaces the commented-out dynarec_log line that was already there in FreeBox64Context().
Risk: Very low — it's purely informational logging behind LOG_INFO, only runs at exit, and the rbtree_walk() function is a straightforward read-only traversal of the existing leftmost→successor chain.
Files changed:
src/tools/rbtree.c — add rbtree_walk()
src/include/rbtree.h — declare rbtree_walk() with doc comment
src/box64context.c — add histogram code in FreeBox64Context(), add #include <inttypes.h>
I'm happy to open a PR for this if there's interest.
While working on the PPC64LE dynarec, I added a small debugging aid that I think would be useful upstream as well.
What this adds:
rbtree_walk()— a generic in-order tree traversal function forrbtree_tthat calls a user-provided callback for each node with(start, end, data, userdata). This is a read-only utility alongside the existingrbtree_print().Dynablock size histogram at exit — when
LOG_INFOis enabled andDYNARECis compiled in,FreeBox64Context()prints a histogram of live dynablock sizes (by x86 code size) before tearing downdb_sizes. It shows the distribution across 12 buckets (1-8 bytes through 8193+), plus total block count, total bytes, max size, and average size.Example output:
This replaces the commented-out
dynarec_logline that was already there inFreeBox64Context().Risk: Very low — it's purely informational logging behind
LOG_INFO, only runs at exit, and therbtree_walk()function is a straightforward read-only traversal of the existing leftmost→successor chain.Files changed:
src/tools/rbtree.c— addrbtree_walk()src/include/rbtree.h— declarerbtree_walk()with doc commentsrc/box64context.c— add histogram code inFreeBox64Context(), add#include <inttypes.h>I'm happy to open a PR for this if there's interest.