Implement commandline option --statistics.

See --help for detailed description how it works.
Internally using shutdown hooks, so NEARLY EVERY entry is written.
The only remaining problem might be the GUI terminating
WHILE main() is writing out data.
But that's not the intended use-case anyway;
see the upcoming --automate flag.