6 void write_iolog_put(struct thread_data *td, struct io_u *io_u)
8 fprintf(td->iolog_f, "%d,%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;
28 void prune_io_piece_log(struct thread_data *td)
32 while (!list_empty(&td->io_hist_list)) {
33 ipo = list_entry(td->io_hist_list.next, struct io_piece, list);
41 * log a succesful write, so we can unwind the log for verify
43 void log_io_piece(struct thread_data *td, struct io_u *io_u)
45 struct io_piece *ipo = malloc(sizeof(struct io_piece));
46 struct list_head *entry;
48 INIT_LIST_HEAD(&ipo->list);
49 ipo->offset = io_u->offset;
50 ipo->len = io_u->buflen;
53 * for random io where the writes extend the file, it will typically
54 * be laid out with the block scattered as written. it's faster to
55 * read them in in that order again, so don't sort
57 if (td->sequential || !td->overwrite) {
58 list_add_tail(&ipo->list, &td->io_hist_list);
63 * for random io, sort the list so verify will run faster
65 entry = &td->io_hist_list;
66 while ((entry = entry->prev) != &td->io_hist_list) {
67 struct io_piece *__ipo = list_entry(entry, struct io_piece, list);
69 if (__ipo->offset < ipo->offset)
73 list_add(&ipo->list, entry);
76 void write_iolog_close(struct thread_data *td)
83 int init_iolog(struct thread_data *td)
85 unsigned long long offset;
89 int rw, i, reads, writes;
91 if (!td->read_iolog && !td->write_iolog)
95 f = fopen(td->iolog_file, "r");
97 f = fopen(td->iolog_file, "w");
100 perror("fopen iolog");
101 printf("file %s, %d/%d\n", td->iolog_file, td->read_iolog, td->write_iolog);
106 * That's it for writing, setup a log buffer and we're done.
108 if (td->write_iolog) {
110 td->iolog_buf = malloc(8192);
111 setvbuf(f, td->iolog_buf, _IOFBF, 8192);
116 * Read in the read iolog and store it, reuse the infrastructure
117 * for doing verifications.
120 reads = writes = i = 0;
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 fprintf(stderr, "bad iolog: %s\n", p);
130 else if (rw == DDIR_WRITE)
133 fprintf(stderr, "bad ddir: %d\n", rw);
137 ipo = malloc(sizeof(*ipo));
138 INIT_LIST_HEAD(&ipo->list);
139 ipo->offset = offset;
141 if (bytes > td->max_bs)
144 list_add_tail(&ipo->list, &td->io_log_list);
154 if (reads && !writes)
155 td->ddir = DDIR_READ;
156 else if (!reads && writes)
157 td->ddir = DDIR_READ;
164 int setup_rate(struct thread_data *td)
166 int nr_reads_per_sec;
171 if (td->rate < td->ratemin) {
172 fprintf(stderr, "min rate larger than nominal rate\n");
176 nr_reads_per_sec = (td->rate * 1024) / td->min_bs;
177 td->rate_usec_cycle = 1000000 / nr_reads_per_sec;
178 td->rate_pending_usleep = 0;
182 void setup_log(struct io_log **log)
184 struct io_log *l = malloc(sizeof(*l));
187 l->max_samples = 1024;
188 l->log = malloc(l->max_samples * sizeof(struct io_sample));
192 void finish_log(struct thread_data *td, struct io_log *log, const char *name)
198 snprintf(file_name, 200, "client%d_%s.log", td->thread_number, name);
199 f = fopen(file_name, "w");
205 for (i = 0; i < log->nr_samples; i++)
206 fprintf(f, "%lu, %lu, %u\n", log->log[i].time, log->log[i].val, log->log[i].ddir);