Refactor and re-enable stats output.
Properly emit handler stats output and add type hints.
Remove obsolete create-stats-print-fn macro.