6 void write_iolog_put(struct thread_data *td, struct io_u *io_u)
8 fprintf(td->iolog_f, "%u,%llu,%u\n", io_u->ddir, io_u->offset, io_u->buflen);
11 int read_iolog_get(struct thread_data *td, struct io_u *io_u)
15 if (!list_empty(&td->io_log_list)) {
16 ipo = list_entry(td->io_log_list.next, struct io_piece, list);
18 io_u->offset = ipo->offset;
19 io_u->buflen = ipo->len;
20 io_u->ddir = ipo->ddir;
21 io_u->file = ipo->file;
29 void prune_io_piece_log(struct thread_data *td)
33 while (!list_empty(&td->io_hist_list)) {
34 ipo = list_entry(td->io_hist_list.next, struct io_piece, list);
42 * log a succesful write, so we can unwind the log for verify
44 void log_io_piece(struct thread_data *td, struct io_u *io_u)
46 struct io_piece *ipo = malloc(sizeof(struct io_piece));
47 struct list_head *entry;
49 INIT_LIST_HEAD(&ipo->list);
50 ipo->file = io_u->file;
51 ipo->offset = io_u->offset;
52 ipo->len = io_u->buflen;
55 * for random io where the writes extend the file, it will typically
56 * be laid out with the block scattered as written. it's faster to
57 * read them in in that order again, so don't sort
59 if (td->sequential || !td->overwrite) {
60 list_add_tail(&ipo->list, &td->io_hist_list);
65 * for random io, sort the list so verify will run faster
67 entry = &td->io_hist_list;
68 while ((entry = entry->prev) != &td->io_hist_list) {
69 struct io_piece *__ipo = list_entry(entry, struct io_piece, list);
71 if (__ipo->offset < ipo->offset)
75 list_add(&ipo->list, entry);
78 void write_iolog_close(struct thread_data *td)
86 * Open a stored log and read in the entries.
88 static int init_iolog_read(struct thread_data *td)
90 unsigned long long offset;
94 int rw, reads, writes;
96 f = fopen(td->read_iolog_file, "r");
98 perror("fopen read iolog");
103 * Read in the read iolog and store it, reuse the infrastructure
104 * for doing verifications.
108 while ((p = fgets(str, 4096, f)) != NULL) {
109 struct io_piece *ipo;
111 if (sscanf(p, "%d,%llu,%u", &rw, &offset, &bytes) != 3) {
112 log_err("bad iolog: %s\n", p);
117 else if (rw == DDIR_WRITE)
120 log_err("bad ddir: %d\n", rw);
124 ipo = malloc(sizeof(*ipo));
125 INIT_LIST_HEAD(&ipo->list);
126 ipo->offset = offset;
128 ipo->ddir = (enum fio_ddir) rw;
129 if (bytes > td->max_bs[rw])
130 td->max_bs[rw] = bytes;
131 list_add_tail(&ipo->list, &td->io_log_list);
137 if (!reads && !writes)
139 else if (reads && !writes)
140 td->ddir = DDIR_READ;
141 else if (!reads && writes)
142 td->ddir = DDIR_READ;
150 * Setup a log for storing io patterns.
152 static int init_iolog_write(struct thread_data *td)
156 f = fopen(td->write_iolog_file, "w+");
158 perror("fopen write iolog");
163 * That's it for writing, setup a log buffer and we're done.
166 td->iolog_buf = malloc(8192);
167 setvbuf(f, td->iolog_buf, _IOFBF, 8192);
171 int init_iolog(struct thread_data *td)
175 if (td->io_ops->flags & FIO_CPUIO)
178 if (td->read_iolog_file)
179 ret = init_iolog_read(td);
180 else if (td->write_iolog_file)
181 ret = init_iolog_write(td);
186 int setup_rate(struct thread_data *td)
188 int nr_reads_per_sec;
193 if (td->rate < td->ratemin) {
194 log_err("min rate larger than nominal rate\n");
198 nr_reads_per_sec = (td->rate * 1024) / td->min_bs[DDIR_READ];
199 td->rate_usec_cycle = 1000000 / nr_reads_per_sec;
200 td->rate_pending_usleep = 0;
204 void setup_log(struct io_log **log)
206 struct io_log *l = malloc(sizeof(*l));
209 l->max_samples = 1024;
210 l->log = malloc(l->max_samples * sizeof(struct io_sample));
214 void finish_log(struct thread_data *td, struct io_log *log, const char *name)
220 snprintf(file_name, 200, "client%d_%s.log", td->thread_number, name);
221 f = fopen(file_name, "w");
227 for (i = 0; i < log->nr_samples; i++)
228 fprintf(f, "%lu, %lu, %u\n", log->log[i].time, log->log[i].val, log->log[i].ddir);