Skip to content

Potential contribution - runtime stats output, using fmt library #1195

@bazineta

Description

@bazineta

We've got a long-running (a very, very long running) daemon process that uses the fmt library for logging, and it's handy to be able to ask the daemon to log heap and process statistics to the log on-demand (we use the USR1 signal for this).

To that end, we've got a header-only fmt::formatter specialization for that, in the vein of mi_stats_print_out(), using a fluent table builder approach to allow for us to easily define and change what we want in that logged output, ends up being a very declarative approach:

https://gist.github.com/bazineta/3f5fa91e077239a53fec3c43370f34f0

We're on C++23, using mimalloc v3 and the latest version of the fmt library, so the code presumes that. Curious if this might be helpful to others.

Sample output:

heap stats  |        peak |       total |     current
------------+-------------+-------------+------------
   reserved |     1.0 GiB |     1.0 GiB |     1.0 GiB
  committed |    11.8 MiB |    12.1 MiB |    11.8 MiB
    touched |           0 |           0 |           0
    threads |           4 |           4 |           4
      pages |           0 |           0 |           0
 -abandoned |           0 |           0 |           0
  -reclaima |           0
  -reclaimf |           0
 -reabandon |           0
     -waits |           0
  -extended |           0
    -retire |           0
     arenas |           1
  -rollback |           0
      mmaps |          11
    commits |           0
     resets |           0
     purges |           0
      reset |           0
     purged |           0
   searches |     0.0 avg
        rss |    34.3 MiB
     faults |          60
    elapsed |    13.978 s
       user |     0.040 s
     system |     0.019 s

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions