Add compute_total_stats utility function.