- struct thread_stat *ts = &td->ts;
- unsigned long spent, iops;
- enum fio_ddir ddir;
- unsigned int next, next_log;
-
- next_log = td->o.iops_avg_time;
-
- spent = mtime_since(&td->iops_sample_time, t);
- if (spent < td->o.iops_avg_time &&
- td->o.iops_avg_time - spent >= LOG_MSEC_SLACK)
- return td->o.iops_avg_time - spent;
-
- td_io_u_lock(td);
-
- /*
- * Compute both read and write rates for the interval.
- */
- for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
- uint64_t delta;
-
- delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
- if (!delta)
- continue; /* No entries for interval */
-
- if (spent)
- iops = (delta * 1000) / spent;
- else
- iops = 0;
-
- add_stat_sample(&ts->iops_stat[ddir], iops);
-
- if (td->iops_log) {
- unsigned int bs = 0;
-
- if (td->o.min_bs[ddir] == td->o.max_bs[ddir])
- bs = td->o.min_bs[ddir];
-
- next = add_log_sample(td, td->iops_log,
- sample_val(iops), ddir, bs, 0);
- next_log = min(next_log, next);
- }
-
- td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
- }
-
- timeval_add_msec(&td->iops_sample_time, td->o.iops_avg_time);
-
- td_io_u_unlock(td);
-
- if (spent <= td->o.iops_avg_time)
- return min(next_log, td->o.iops_avg_time);
-
- next = td->o.iops_avg_time - (1 + spent - td->o.iops_avg_time);
- return min(next, next_log);
+ return __add_samples(td, &td->iops_sample_time, t, td->o.iops_avg_time,
+ td->this_io_blocks, td->stat_io_blocks,
+ td->ts.iops_stat, td->iops_log, false);