+ /*
+ * Get a new log array, and add to our list
+ */
+ cur_log = get_new_log(iolog);
+ if (!cur_log) {
+ log_err("fio: failed extending iolog! Will stop logging.\n");
+ return NULL;
+ }
+
+ if (!iolog->pending || !iolog->pending->nr_samples)
+ return cur_log;
+
+ /*
+ * Flush pending items to new log
+ */
+ for (i = 0; i < iolog->pending->nr_samples; i++) {
+ struct io_sample *src, *dst;
+
+ src = get_sample(iolog, iolog->pending, i);
+ dst = get_sample(iolog, cur_log, i);
+ memcpy(dst, src, log_entry_sz(iolog));
+ }
+ cur_log->nr_samples = iolog->pending->nr_samples;
+
+ iolog->pending->nr_samples = 0;
+ return cur_log;
+disable:
+ if (iolog)
+ iolog->disabled = true;
+ return NULL;
+}
+
+void regrow_logs(struct thread_data *td)
+{
+ regrow_log(td->slat_log);
+ regrow_log(td->clat_log);
+ regrow_log(td->clat_hist_log);
+ regrow_log(td->lat_log);
+ regrow_log(td->bw_log);
+ regrow_log(td->iops_log);
+ td->flags &= ~TD_F_REGROW_LOGS;
+}
+
+static struct io_logs *get_cur_log(struct io_log *iolog)
+{
+ struct io_logs *cur_log;
+
+ cur_log = iolog_cur_log(iolog);
+ if (!cur_log) {
+ cur_log = get_new_log(iolog);
+ if (!cur_log)
+ return NULL;
+ }
+
+ if (cur_log->nr_samples < cur_log->max_samples)
+ return cur_log;
+
+ /*
+ * Out of space. If we're in IO offload mode, or we're not doing
+ * per unit logging (hence logging happens outside of the IO thread
+ * as well), add a new log chunk inline. If we're doing inline
+ * submissions, flag 'td' as needing a log regrow and we'll take
+ * care of it on the submission side.
+ */
+ if ((iolog->td && iolog->td->o.io_submit_mode == IO_MODE_OFFLOAD) ||
+ !per_unit_log(iolog))
+ return regrow_log(iolog);
+
+ if (iolog->td)
+ iolog->td->flags |= TD_F_REGROW_LOGS;
+ if (iolog->pending)
+ assert(iolog->pending->nr_samples < iolog->pending->max_samples);
+ return iolog->pending;
+}
+
+static void __add_log_sample(struct io_log *iolog, union io_sample_data data,
+ enum fio_ddir ddir, unsigned long long bs,
+ unsigned long t, uint64_t offset)
+{
+ struct io_logs *cur_log;
+
+ if (iolog->disabled)
+ return;
+ if (flist_empty(&iolog->io_logs))
+ iolog->avg_last[ddir] = t;
+
+ cur_log = get_cur_log(iolog);
+ if (cur_log) {
+ struct io_sample *s;
+
+ s = get_sample(iolog, cur_log, cur_log->nr_samples);
+
+ s->data = data;
+ s->time = t + (iolog->td ? iolog->td->unix_epoch : 0);
+ io_sample_set_ddir(iolog, s, ddir);
+ s->bs = bs;