Skip to content

Add rbtree_walk() utility and dynablock size histogram at exit #3554

@runlevel5

Description

@runlevel5

While working on the PPC64LE dynarec, I added a small debugging aid that I think would be useful upstream as well.

What this adds:

  1. 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().

  2. 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions