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 = &td->io_hist_tree.rb_node;
47 struct rb_node *parent = NULL;
48 struct io_piece *ipo, *__ipo;
50 ipo = malloc(sizeof(struct io_piece));
51 memset(&ipo->rb_node, 0, sizeof(ipo->rb_node));
52 ipo->file = io_u->file;
53 ipo->offset = io_u->offset;
54 ipo->len = io_u->buflen;
57 * Sort the entry into the verification list
62 __ipo = rb_entry(parent, struct io_piece, rb_node);
63 if (ipo->offset < __ipo->offset)
65 else if (ipo->offset > __ipo->offset)
71 rb_link_node(&ipo->rb_node, parent, p);
72 rb_insert_color(&ipo->rb_node, &td->io_hist_tree);
75 void write_iolog_close(struct thread_data *td)
83 * Open a stored log and read in the entries.
85 static int init_iolog_read(struct thread_data *td)
87 unsigned long long offset;
91 int rw, reads, writes;
93 f = fopen(td->o.read_iolog_file, "r");
95 perror("fopen read iolog");
100 * Read in the read iolog and store it, reuse the infrastructure
101 * for doing verifications.
105 while ((p = fgets(str, 4096, f)) != NULL) {
106 struct io_piece *ipo;
108 if (sscanf(p, "%d,%llu,%u", &rw, &offset, &bytes) != 3) {
109 log_err("bad iolog: %s\n", p);
114 else if (rw == DDIR_WRITE)
117 log_err("bad ddir: %d\n", rw);
121 ipo = malloc(sizeof(*ipo));
122 INIT_LIST_HEAD(&ipo->list);
123 ipo->offset = offset;
125 ipo->ddir = (enum fio_ddir) rw;
126 if (bytes > td->o.max_bs[rw])
127 td->o.max_bs[rw] = bytes;
128 list_add_tail(&ipo->list, &td->io_log_list);
134 if (!reads && !writes)
136 else if (reads && !writes)
137 td->o.td_ddir = TD_DDIR_READ;
138 else if (!reads && writes)
139 td->o.td_ddir = TD_DDIR_READ;
141 td->o.td_ddir = TD_DDIR_RW;
147 * Setup a log for storing io patterns.
149 static int init_iolog_write(struct thread_data *td)
153 f = fopen(td->o.write_iolog_file, "w+");
155 perror("fopen write iolog");
160 * That's it for writing, setup a log buffer and we're done.
163 td->iolog_buf = malloc(8192);
164 setvbuf(f, td->iolog_buf, _IOFBF, 8192);
168 int init_iolog(struct thread_data *td)
172 if (td->io_ops->flags & FIO_DISKLESSIO)
175 if (td->o.read_iolog_file)
176 ret = init_iolog_read(td);
177 else if (td->o.write_iolog_file)
178 ret = init_iolog_write(td);
183 void setup_log(struct io_log **log)
185 struct io_log *l = malloc(sizeof(*l));
188 l->max_samples = 1024;
189 l->log = malloc(l->max_samples * sizeof(struct io_sample));
193 void __finish_log(struct io_log *log, const char *name)
198 f = fopen(name, "w");
204 for (i = 0; i < log->nr_samples; i++)
205 fprintf(f, "%lu, %lu, %u\n", log->log[i].time, log->log[i].val, log->log[i].ddir);
212 void finish_log(struct thread_data *td, struct io_log *log, const char *name)
216 snprintf(file_name, 200, "client%d_%s.log", td->thread_number, name);
217 __finish_log(log, file_name);