I think it is correct.  It gets adjusted incrementally:

new_count = total_count + incremental_count
cumulative_time = total_count / total_count_per_second + incremental_count / incremental_count_per_second
new_cumulative_count_per_second = new_count / cumulative_time

I suppose I could sum the counts and time deltas and update count and update count_ps, count and sum in one operation at the end.