6 void write_iolog_put(struct thread_data *td, struct io_u *io_u)
8 fprintf(td->iolog_f, "%u,%llu,%lu\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)
34 while ((n = rb_first(&td->io_hist_tree)) != NULL) {
35 ipo = rb_entry(n, struct io_piece, rb_node);
36 rb_erase(n, &td->io_hist_tree);
42 * log a successful 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 rb_node **p, *parent;
47 struct io_piece *ipo, *__ipo;
49 ipo = malloc(sizeof(struct io_piece));
50 ipo->file = io_u->file;
51 ipo->offset = io_u->offset;
52 ipo->len = io_u->buflen;
55 * We don't need to sort the entries, if:
57 * Sequential writes, or
58 * Random writes that lay out the file as it goes along
60 * For both these cases, just reading back data in the order we
61 * wrote it out is the fastest.
63 if (!td_random(td) || !td->o.overwrite ||
64 (io_u->file->flags & FIO_FILE_NOSORT)) {
65 INIT_LIST_HEAD(&ipo->list);
66 list_add_tail(&ipo->list, &td->io_hist_list);
70 RB_CLEAR_NODE(&ipo->rb_node);
71 p = &td->io_hist_tree.rb_node;
75 * Sort the entry into the verification list
80 __ipo = rb_entry(parent, struct io_piece, rb_node);
81 if (ipo->offset <= __ipo->offset)
87 rb_link_node(&ipo->rb_node, parent, p);
88 rb_insert_color(&ipo->rb_node, &td->io_hist_tree);
91 void write_iolog_close(struct thread_data *td)
99 * Open a stored log and read in the entries.
101 static int init_iolog_read(struct thread_data *td)
103 unsigned long long offset;
107 int rw, reads, writes;
109 f = fopen(td->o.read_iolog_file, "r");
111 perror("fopen read iolog");
116 * Read in the read iolog and store it, reuse the infrastructure
117 * for doing verifications.
121 while ((p = fgets(str, 4096, f)) != NULL) {
122 struct io_piece *ipo;
124 if (sscanf(p, "%d,%llu,%u", &rw, &offset, &bytes) != 3) {
125 log_err("bad iolog: %s\n", p);
130 else if (rw == DDIR_WRITE)
132 else if (rw != DDIR_SYNC) {
133 log_err("bad ddir: %d\n", rw);
137 ipo = malloc(sizeof(*ipo));
138 INIT_LIST_HEAD(&ipo->list);
139 ipo->offset = offset;
141 ipo->ddir = (enum fio_ddir) rw;
142 if (bytes > td->o.max_bs[rw])
143 td->o.max_bs[rw] = bytes;
144 list_add_tail(&ipo->list, &td->io_log_list);
150 if (!reads && !writes)
152 else if (reads && !writes)
153 td->o.td_ddir = TD_DDIR_READ;
154 else if (!reads && writes)
155 td->o.td_ddir = TD_DDIR_READ;
157 td->o.td_ddir = TD_DDIR_RW;
163 * Setup a log for storing io patterns.
165 static int init_iolog_write(struct thread_data *td)
169 f = fopen(td->o.write_iolog_file, "w+");
171 perror("fopen write iolog");
176 * That's it for writing, setup a log buffer and we're done.
179 td->iolog_buf = malloc(8192);
180 setvbuf(f, td->iolog_buf, _IOFBF, 8192);
184 int init_iolog(struct thread_data *td)
188 if (td->io_ops->flags & FIO_DISKLESSIO)
191 if (td->o.read_iolog_file)
192 ret = init_iolog_read(td);
193 else if (td->o.write_iolog_file)
194 ret = init_iolog_write(td);
199 void setup_log(struct io_log **log)
201 struct io_log *l = malloc(sizeof(*l));
204 l->max_samples = 1024;
205 l->log = malloc(l->max_samples * sizeof(struct io_sample));
209 void __finish_log(struct io_log *log, const char *name)
214 f = fopen(name, "w");
220 for (i = 0; i < log->nr_samples; i++)
221 fprintf(f, "%lu, %lu, %u\n", log->log[i].time, log->log[i].val, log->log[i].ddir);
228 void finish_log(struct thread_data *td, struct io_log *log, const char *name)
232 snprintf(file_name, 200, "client%d_%s.log", td->thread_number, name);
233 __finish_log(log, file_name);