Collect and log stats on exit