[PATCH] First cut at supporting > 1 file per job
[fio.git] / log.c
diff --git a/log.c b/log.c
index 42aedf270ff0882c56de0f13b78614f1c88bfff6..00e3913bd8a8b212f92233ceb3ff501201266a26 100644 (file)
--- a/log.c
+++ b/log.c
@@ -18,6 +18,7 @@ int read_iolog_get(struct thread_data *td, struct io_u *io_u)
                io_u->offset = ipo->offset;
                io_u->buflen = ipo->len;
                io_u->ddir = ipo->ddir;
                io_u->offset = ipo->offset;
                io_u->buflen = ipo->len;
                io_u->ddir = ipo->ddir;
+               io_u->file = ipo->file;
                free(ipo);
                return 0;
        }
                free(ipo);
                return 0;
        }
@@ -46,6 +47,7 @@ void log_io_piece(struct thread_data *td, struct io_u *io_u)
        struct list_head *entry;
 
        INIT_LIST_HEAD(&ipo->list);
        struct list_head *entry;
 
        INIT_LIST_HEAD(&ipo->list);
+       ipo->file = io_u->file;
        ipo->offset = io_u->offset;
        ipo->len = io_u->buflen;
 
        ipo->offset = io_u->offset;
        ipo->len = io_u->buflen;
 
@@ -122,7 +124,7 @@ int init_iolog(struct thread_data *td)
                struct io_piece *ipo;
 
                if (sscanf(p, "%d,%llu,%u", &rw, &offset, &bytes) != 3) {
                struct io_piece *ipo;
 
                if (sscanf(p, "%d,%llu,%u", &rw, &offset, &bytes) != 3) {
-                       fprintf(stderr, "bad iolog: %s\n", p);
+                       log_err("bad iolog: %s\n", p);
                        continue;
                }
                if (rw == DDIR_READ)
                        continue;
                }
                if (rw == DDIR_READ)
@@ -130,7 +132,7 @@ int init_iolog(struct thread_data *td)
                else if (rw == DDIR_WRITE)
                        writes++;
                else {
                else if (rw == DDIR_WRITE)
                        writes++;
                else {
-                       fprintf(stderr, "bad ddir: %d\n", rw);
+                       log_err("bad ddir: %d\n", rw);
                        continue;
                }
 
                        continue;
                }
 
@@ -160,3 +162,52 @@ int init_iolog(struct thread_data *td)
 
        return 0;
 }
 
        return 0;
 }
+
+int setup_rate(struct thread_data *td)
+{
+       int nr_reads_per_sec;
+
+       if (!td->rate)
+               return 0;
+
+       if (td->rate < td->ratemin) {
+               log_err("min rate larger than nominal rate\n");
+               return -1;
+       }
+
+       nr_reads_per_sec = (td->rate * 1024) / td->min_bs;
+       td->rate_usec_cycle = 1000000 / nr_reads_per_sec;
+       td->rate_pending_usleep = 0;
+       return 0;
+}
+
+void setup_log(struct io_log **log)
+{
+       struct io_log *l = malloc(sizeof(*l));
+
+       l->nr_samples = 0;
+       l->max_samples = 1024;
+       l->log = malloc(l->max_samples * sizeof(struct io_sample));
+       *log = l;
+}
+
+void finish_log(struct thread_data *td, struct io_log *log, const char *name)
+{
+       char file_name[256];
+       FILE *f;
+       unsigned int i;
+
+       snprintf(file_name, 200, "client%d_%s.log", td->thread_number, name);
+       f = fopen(file_name, "w");
+       if (!f) {
+               perror("fopen log");
+               return;
+       }
+
+       for (i = 0; i < log->nr_samples; i++)
+               fprintf(f, "%lu, %lu, %u\n", log->log[i].time, log->log[i].val, log->log[i].ddir);
+
+       fclose(f);
+       free(log->log);
+       free(log);
+}