+ elapsed = mtime_since_now(&td->epoch);
+
+ /*
+ * If no time averaging, just add the log sample.
+ */
+ if (!iolog->avg_msec) {
+ __add_log_sample(iolog, val, ddir, bs, elapsed);
+ return;
+ }
+
+ /*
+ * Add the sample. If the time period has passed, then
+ * add that entry to the log and clear.
+ */
+ add_stat_sample(&iolog->avg_window[ddir], val);
+
+ /*
+ * If period hasn't passed, adding the above sample is all we
+ * need to do.
+ */
+ this_window = elapsed - iolog->avg_last;
+ if (this_window < iolog->avg_msec)
+ return;
+
+ /*
+ * Note an entry in the log. Use the mean from the logged samples,
+ * making sure to properly round up. Only write a log entry if we
+ * had actual samples done.
+ */
+ if (iolog->avg_window[DDIR_READ].samples) {
+ unsigned long mr;
+
+ mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
+ __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
+ }
+ if (iolog->avg_window[DDIR_WRITE].samples) {
+ unsigned long mw;
+
+ mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
+ __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
+ }
+
+ reset_io_stat(&iolog->avg_window[DDIR_READ]);
+ reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
+ iolog->avg_last = elapsed;