iowatcher: Make seconds unsigned
[blktrace.git] / iowatcher / main.c
index 4ae4d346c8afb75ee6fc3a280e0f67db270f748b..5cbfa53ddf4a2e218e830c1e5d6c3b6976b07f4d 100644 (file)
@@ -12,7 +12,7 @@
  *
  *  You should have received a copy of the GNU General Public License
  *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
  *  Parts of this file were imported from Jens Axboe's blktrace sources (also GPL)
  */
 #include "list.h"
 #include "tracers.h"
 #include "mpstat.h"
+#include "fio.h"
 
 LIST_HEAD(all_traces);
+LIST_HEAD(fio_traces);
 
 static char line[1024];
 static int line_len = 1024;
 static int found_mpstat = 0;
 static int make_movie = 0;
+static int keep_movie_svgs = 0;
 static int opt_graph_width = 0;
 static int opt_graph_height = 0;
 
 static int columns = 1;
-static int num_xticks = 7;
+static int num_xticks = 9;
 static int num_yticks = 4;
 
 static double min_time = 0;
@@ -71,6 +74,7 @@ static int total_graphs_written = 1;
 enum {
        IO_GRAPH_INDEX = 0,
        TPUT_GRAPH_INDEX,
+       FIO_GRAPH_INDEX,
        CPU_SYS_GRAPH_INDEX,
        CPU_IO_GRAPH_INDEX,
        CPU_IRQ_GRAPH_INDEX,
@@ -94,6 +98,7 @@ enum {
 static char *graphs_by_name[] = {
        "io",
        "tput",
+       "fio",
        "cpu-sys",
        "cpu-io",
        "cpu-irq",
@@ -134,14 +139,17 @@ static int last_active_graph = IOPS_GRAPH_INDEX;
 
 static int label_index = 0;
 static int num_traces = 0;
+static int num_fio_traces = 0;
 static int longest_label = 0;
 
 static char *graph_title = "";
 static char *output_filename = "trace.svg";
-static char *blktrace_device = NULL;
+static char *blktrace_devices[MAX_DEVICES_PER_TRACE];
+static int num_blktrace_devices = 0;
 static char *blktrace_outfile = "trace";
 static char *blktrace_dest_dir = ".";
 static char *program_to_run = NULL;
+static char *ffmpeg_codec = "libx264";
 
 static void alloc_mpstat_gld(struct trace_file *tf)
 {
@@ -219,10 +227,13 @@ static int graphs_left(int cur)
        return left;
 }
 
-static void join_path(char *path, char *filename)
+static char * join_path(char *dest_dir, char *filename)
 {
-       path = strcat(path, "/");
-       path = strcat(path, filename);
+       /* alloc 2 extra bytes for '/' and '\0' */
+       char *path = malloc(strlen(dest_dir) + strlen(filename) + 2);
+       sprintf(path, "%s%s%s", dest_dir, "/", filename);
+
+       return path;
 }
 
 static void add_trace_file(char *filename)
@@ -241,6 +252,23 @@ static void add_trace_file(char *filename)
        num_traces++;
 }
 
+static void add_fio_trace_file(char *filename)
+{
+       struct trace_file *tf;
+
+       tf = calloc(1, sizeof(*tf));
+       if (!tf) {
+               fprintf(stderr, "Unable to allocate memory\n");
+               exit(1);
+       }
+       tf->label = "";
+       tf->filename = strdup(filename);
+       list_add_tail(&tf->list, &fio_traces);
+       tf->line_color = pick_fio_color();
+       tf->fio_trace = 1;
+       num_fio_traces++;
+}
+
 static void setup_trace_file_graphs(void)
 {
        struct trace_file *tf;
@@ -251,10 +279,13 @@ static void setup_trace_file_graphs(void)
                alloc_ptrs = 16;
        else
                alloc_ptrs = 1;
+
        list_for_each_entry(tf, &all_traces, list) {
-               tf->tput_gld = alloc_line_data(tf->min_seconds, tf->max_seconds, tf->stop_seconds);
+               tf->tput_reads_gld = alloc_line_data(tf->min_seconds, tf->max_seconds, tf->stop_seconds);
+               tf->tput_writes_gld = alloc_line_data(tf->min_seconds, tf->max_seconds, tf->stop_seconds);
                tf->latency_gld = alloc_line_data(tf->min_seconds, tf->max_seconds, tf->stop_seconds);
                tf->queue_depth_gld = alloc_line_data(tf->min_seconds, tf->max_seconds, tf->stop_seconds);
+
                tf->iop_gld = alloc_line_data(tf->min_seconds, tf->max_seconds, tf->stop_seconds);
                tf->gdd_writes = calloc(alloc_ptrs, sizeof(struct graph_dot_data));
                tf->gdd_reads = calloc(alloc_ptrs, sizeof(struct graph_dot_data));
@@ -272,6 +303,15 @@ static void setup_trace_file_graphs(void)
                        tf->mpstat_gld[i]->max = 100;
                }
        }
+
+       list_for_each_entry(tf, &fio_traces, list) {
+               if (tf->trace->fio_seconds > 0) {
+                       tf->fio_gld = alloc_line_data(tf->min_seconds,
+                                                     tf->max_seconds,
+                                                     tf->stop_seconds);
+               }
+       }
+
 }
 
 static void read_traces(void)
@@ -286,8 +326,7 @@ static void read_traces(void)
        char *path = NULL;
 
        list_for_each_entry(tf, &all_traces, list) {
-               path = strdup(blktrace_dest_dir);
-               join_path(path, tf->filename);
+               path = join_path(blktrace_dest_dir, tf->filename);
 
                trace = open_trace(path);
                if (!trace)
@@ -295,8 +334,9 @@ static void read_traces(void)
 
                last_time = find_last_time(trace);
                tf->trace = trace;
-               tf->max_seconds = SECONDS(last_time);
-               tf->stop_seconds = SECONDS(last_time);
+               tf->max_seconds = SECONDS(last_time) + 1;
+               tf->stop_seconds = SECONDS(last_time) + 1;
+
                find_extreme_offsets(trace, &tf->min_offset, &tf->max_offset,
                                    &max_bank, &max_bank_offset);
                filter_outliers(trace, tf->min_offset, tf->max_offset, &ymin, &ymax);
@@ -308,7 +348,17 @@ static void read_traces(void)
                tf->mpstat_max_seconds = trace->mpstat_seconds;
                if (tf->mpstat_max_seconds)
                        found_mpstat = 1;
-               path = NULL;
+
+               free(path);
+       }
+
+       list_for_each_entry(tf, &fio_traces, list) {
+               trace = open_fio_trace(tf->filename);
+               if (!trace)
+                       exit(1);
+               tf->trace = trace;
+               tf->max_seconds = tf->trace->fio_seconds;
+               tf->stop_seconds = tf->trace->fio_seconds;
        }
 }
 
@@ -321,13 +371,39 @@ static void pick_line_graph_color(void)
                for (i = 0; i < tf->io_plots; i++) {
                        if (tf->gdd_reads[i]) {
                                tf->line_color = tf->gdd_reads[i]->color;
-                               break;
+                               tf->reads_color = tf->gdd_reads[i]->color;
                        }
                        if (tf->gdd_writes[i]) {
                                tf->line_color = tf->gdd_writes[i]->color;
-                               break;
+                               tf->writes_color = tf->gdd_writes[i]->color;
                        }
+                       if (tf->writes_color && tf->reads_color)
+                               break;
                }
+               if (!tf->reads_color)
+                       tf->reads_color = tf->line_color;
+               if (!tf->writes_color)
+                       tf->writes_color = tf->line_color;
+       }
+}
+
+static void read_fio_events(struct trace_file *tf)
+{
+       u64 bw = 0;
+       int time = 0;
+       int dir = 0;
+       int ret;
+
+       first_fio(tf->trace);
+       while (1) {
+               ret = read_fio_event(tf->trace, &time, &bw, &dir);
+               if (ret)
+                       break;
+
+               if (dir <= 1)
+                       add_fio_gld(time, bw, tf->fio_gld);
+               if (next_fio_line(tf->trace))
+                       break;
        }
 }
 
@@ -338,25 +414,28 @@ static void read_trace_events(void)
        struct trace *trace;
        int ret;
        int i;
-       int time;
+       unsigned int time;
        double user, sys, iowait, irq, soft;
        double max_user = 0, max_sys = 0, max_iowait = 0,
               max_irq = 0, max_soft = 0;
 
+       list_for_each_entry(tf, &fio_traces, list)
+               read_fio_events(tf);
+
        list_for_each_entry(tf, &all_traces, list) {
                trace = tf->trace;
+
                first_record(trace);
-               while (1) {
+               do {
+                       if (SECONDS(get_record_time(trace)) > tf->max_seconds)
+                               continue;
                        check_record(trace);
-                       add_tput(trace, tf->tput_gld);
+                       add_tput(trace, tf->tput_writes_gld, tf->tput_reads_gld);
                        add_iop(trace, tf->iop_gld);
                        add_io(trace, tf);
                        add_pending_io(trace, tf->queue_depth_gld);
                        add_completed_io(trace, tf->latency_gld);
-                       ret = next_record(trace);
-                       if (ret)
-                               break;
-               }
+               } while (!(ret = next_record(trace)));
        }
        list_for_each_entry(tf, &all_traces, list) {
                trace = tf->trace;
@@ -366,7 +445,7 @@ static void read_trace_events(void)
 
                first_mpstat(trace);
 
-               for (time = 0; time < tf->mpstat_stop_seconds; time ++) {
+               for (time = 0; time < tf->mpstat_stop_seconds; time++) {
                        for (i = 0; i < (trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS; i += MPSTAT_GRAPHS) {
                                ret = read_mpstat_event(trace, &user, &sys,
                                                        &iowait, &irq, &soft);
@@ -421,6 +500,15 @@ static void set_trace_label(char *label)
                longest_label = len;
 
        list_for_each_entry(tf, &all_traces, list) {
+               if (cur == label_index) {
+                       tf->label = strdup(label);
+                       label_index++;
+                       return;
+                       break;
+               }
+               cur++;
+       }
+       list_for_each_entry(tf, &fio_traces, list) {
                if (cur == label_index) {
                        tf->label = strdup(label);
                        label_index++;
@@ -443,7 +531,8 @@ static void set_blktrace_outfile(char *arg)
 }
 
 
-static void compare_minmax_tf(struct trace_file *tf, int *max_seconds, u64 *min_offset, u64 *max_offset)
+static void compare_minmax_tf(struct trace_file *tf, unsigned int *max_seconds,
+                             u64 *min_offset, u64 *max_offset)
 {
        if (tf->max_seconds > *max_seconds)
                *max_seconds = tf->max_seconds;
@@ -453,11 +542,14 @@ static void compare_minmax_tf(struct trace_file *tf, int *max_seconds, u64 *min_
                *min_offset = tf->min_offset;
 }
 
-static void set_all_minmax_tf(int min_seconds, int max_seconds, u64 min_offset, u64 max_offset)
+static void set_all_minmax_tf(unsigned int min_seconds,
+                             unsigned int max_seconds,
+                             u64 min_offset, u64 max_offset)
 {
        struct trace_file *tf;
-
-       list_for_each_entry(tf, &all_traces, list) {
+       struct list_head *traces = &all_traces;
+again:
+       list_for_each_entry(tf, traces, list) {
                tf->min_seconds = min_seconds;
                tf->max_seconds = max_seconds;
                if (tf->stop_seconds > max_seconds)
@@ -471,6 +563,10 @@ static void set_all_minmax_tf(int min_seconds, int max_seconds, u64 min_offset,
                tf->min_offset = min_offset;
                tf->max_offset = max_offset;
        }
+       if (traces == &all_traces) {
+               traces = &fio_traces;
+               goto again;
+       }
 }
 
 static char *create_movie_temp_dir(void)
@@ -628,7 +724,8 @@ static int count_io_plot_types(void)
        return total_io_types;
 }
 
-static void plot_io(struct plot *plot, int min_seconds, int max_seconds, u64 min_offset, u64 max_offset)
+static void plot_io(struct plot *plot, unsigned int min_seconds,
+                   unsigned int max_seconds, u64 min_offset, u64 max_offset)
 {
        struct trace_file *tf;
        int i;
@@ -653,13 +750,20 @@ static void plot_io(struct plot *plot, int min_seconds, int max_seconds, u64 min
                if (!tf->label)
                        label[0] = 0;
                else {
-                       strcpy(label, tf->label);
+                       strncpy(label, tf->label, 255);
+                       label[255] = 0;
                        if (io_per_process)
                                strcat(label, " ");
                }
                pos = label + strlen(label);
 
                for (i = 0; i < tf->io_plots; i++) {
+                       if (tf->gdd_writes[i]) {
+                               svg_io_graph(plot, tf->gdd_writes[i]);
+                               if (io_per_process)
+                                       strcpy(pos, tf->gdd_writes[i]->label);
+                               svg_add_legend(plot, label, " Writes", tf->gdd_writes[i]->color);
+                       }
                        if (tf->gdd_reads[i]) {
                                svg_io_graph(plot, tf->gdd_reads[i]);
                                if (io_per_process)
@@ -667,12 +771,6 @@ static void plot_io(struct plot *plot, int min_seconds, int max_seconds, u64 min
                                svg_add_legend(plot, label, " Reads", tf->gdd_reads[i]->color);
                        }
 
-                       if (tf->gdd_writes[i]) {
-                               svg_io_graph(plot, tf->gdd_writes[i]);
-                               if (io_per_process)
-                                       strcpy(pos, tf->gdd_writes[i]->label);
-                               svg_add_legend(plot, label, " Writes", tf->gdd_writes[i]->color);
-                       }
                }
        }
        if (plot->add_xlabel)
@@ -681,7 +779,8 @@ static void plot_io(struct plot *plot, int min_seconds, int max_seconds, u64 min
        close_plot(plot);
 }
 
-static void plot_tput(struct plot *plot, int min_seconds, int max_seconds)
+static void plot_tput(struct plot *plot, unsigned int min_seconds,
+                     unsigned int max_seconds, int with_legend)
 {
        struct trace_file *tf;
        char *units;
@@ -691,14 +790,21 @@ static void plot_tput(struct plot *plot, int min_seconds, int max_seconds)
        if (active_graphs[TPUT_GRAPH_INDEX] == 0)
                return;
 
-       if (num_traces > 1)
-               svg_alloc_legend(plot, num_traces);
+       if (with_legend)
+               svg_alloc_legend(plot, num_traces * 2);
+
        list_for_each_entry(tf, &all_traces, list) {
-               if (tf->tput_gld->max > max)
-                       max = tf->tput_gld->max;
+               if (tf->tput_writes_gld->max > max)
+                       max = tf->tput_writes_gld->max;
+               if (tf->tput_reads_gld->max > max)
+                       max = tf->tput_reads_gld->max;
+       }
+       list_for_each_entry(tf, &all_traces, list) {
+               if (tf->tput_writes_gld->max > 0)
+                       tf->tput_writes_gld->max = max;
+               if (tf->tput_reads_gld->max > 0)
+                       tf->tput_reads_gld->max = max;
        }
-       list_for_each_entry(tf, &all_traces, list)
-               tf->tput_gld->max = max;
 
        setup_axis(plot);
        set_plot_label(plot, "Throughput");
@@ -712,26 +818,87 @@ static void plot_tput(struct plot *plot, int min_seconds, int max_seconds)
        set_xticks(plot, num_xticks, min_seconds, max_seconds);
 
        list_for_each_entry(tf, &all_traces, list) {
-               svg_line_graph(plot, tf->tput_gld, tf->line_color, 0, 0);
-               if (num_traces > 1)
-                       svg_add_legend(plot, tf->label, "", tf->line_color);
+               if (tf->tput_writes_gld->max > 0) {
+                       svg_line_graph(plot, tf->tput_writes_gld, tf->writes_color, 0, 0);
+                       if (with_legend)
+                               svg_add_legend(plot, tf->label, "Writes", tf->writes_color);
+               }
+               if (tf->tput_reads_gld->max > 0) {
+                       svg_line_graph(plot, tf->tput_reads_gld, tf->reads_color, 0, 0);
+                       if (with_legend)
+                               svg_add_legend(plot, tf->label, "Reads", tf->reads_color);
+               }
        }
 
        if (plot->add_xlabel)
                set_xlabel(plot, "Time (seconds)");
-       if (num_traces > 1)
+
+       if (with_legend)
                svg_write_legend(plot);
+
        close_plot(plot);
        total_graphs_written++;
 }
 
-static void plot_cpu(struct plot *plot, int max_seconds, char *label,
+static void plot_fio_tput(struct plot *plot,
+                         unsigned int min_seconds, unsigned int max_seconds)
+{
+       struct trace_file *tf;
+       char *units;
+       char line[128];
+       u64 max = 0;
+
+       if (num_fio_traces == 0 || active_graphs[FIO_GRAPH_INDEX] == 0)
+               return;
+
+       if (num_fio_traces > 1)
+               svg_alloc_legend(plot, num_fio_traces);
+
+       list_for_each_entry(tf, &fio_traces, list) {
+               if (tf->fio_gld->max > max)
+                       max = tf->fio_gld->max;
+       }
+
+       list_for_each_entry(tf, &fio_traces, list) {
+               if (tf->fio_gld->max > 0)
+                       tf->fio_gld->max = max;
+       }
+
+       setup_axis(plot);
+       set_plot_label(plot, "Fio Throughput");
+
+       tf = list_entry(all_traces.next, struct trace_file, list);
+
+       scale_line_graph_bytes(&max, &units, 1024);
+       sprintf(line, "%sB/s", units);
+       set_ylabel(plot, line);
+       set_yticks(plot, num_yticks, 0, max, "");
+
+       set_xticks(plot, num_xticks, min_seconds, max_seconds);
+       list_for_each_entry(tf, &fio_traces, list) {
+               if (tf->fio_gld->max > 0) {
+                       svg_line_graph(plot, tf->fio_gld, tf->line_color, 0, 0);
+                       if (num_fio_traces > 1)
+                               svg_add_legend(plot, tf->label, "", tf->line_color);
+               }
+       }
+
+       if (plot->add_xlabel)
+               set_xlabel(plot, "Time (seconds)");
+
+       if (num_fio_traces > 1)
+               svg_write_legend(plot);
+       close_plot(plot);
+       total_graphs_written++;
+}
+
+static void plot_cpu(struct plot *plot, unsigned int max_seconds, char *label,
                     int active_index, int gld_index)
 {
        struct trace_file *tf;
        int max = 0;
        int i;
-       int gld_i;
+       unsigned int gld_i;
        char *color;
        double avg = 0;
        int ymax;
@@ -768,11 +935,11 @@ static void plot_cpu(struct plot *plot, int max_seconds, char *label,
        list_for_each_entry(tf, &all_traces, list) {
                if (tf->mpstat_gld == 0)
                        break;
-               for (i = tf->mpstat_gld[0]->min_seconds;
-                    i < tf->mpstat_gld[0]->stop_seconds; i++) {
-                       if (tf->mpstat_gld[gld_index]->data[i].count) {
-                               avg += (tf->mpstat_gld[gld_index]->data[i].sum /
-                                       tf->mpstat_gld[gld_index]->data[i].count);
+               for (gld_i = tf->mpstat_gld[0]->min_seconds;
+                    gld_i < tf->mpstat_gld[0]->stop_seconds; gld_i++) {
+                       if (tf->mpstat_gld[gld_index]->data[gld_i].count) {
+                               avg += (tf->mpstat_gld[gld_index]->data[gld_i].sum /
+                                       tf->mpstat_gld[gld_index]->data[gld_i].count);
                        }
                }
                avg /= tf->mpstat_gld[gld_index]->stop_seconds -
@@ -828,7 +995,8 @@ static void plot_cpu(struct plot *plot, int max_seconds, char *label,
        total_graphs_written++;
 }
 
-static void plot_queue_depth(struct plot *plot, int min_seconds, int max_seconds)
+static void plot_queue_depth(struct plot *plot, unsigned int min_seconds,
+                            unsigned int max_seconds)
 {
        struct trace_file *tf;
 
@@ -869,14 +1037,38 @@ static void convert_movie_files(char *movie_dir)
 
 static void mencode_movie(char *movie_dir)
 {
-       fprintf(stderr, "Creating movie %s\n", movie_dir);
+       fprintf(stderr, "Creating movie %s with ffmpeg\n", movie_dir);
        snprintf(line, line_len, "ffmpeg -r 20 -y -i %s/%%10d-%s.svg.png -b:v 250k "
-                "-vcodec libx264 %s", movie_dir, output_filename, output_filename);
+                "-vcodec %s %s", movie_dir, output_filename, ffmpeg_codec,
+                output_filename);
+       system(line);
+}
+
+static void tencode_movie(char *movie_dir)
+{
+       fprintf(stderr, "Creating movie %s with png2theora\n", movie_dir);
+       snprintf(line, line_len, "png2theora -o %s %s/%%010d-%s.svg.png",
+                       output_filename, movie_dir, output_filename);
        system(line);
 }
 
+static void encode_movie(char *movie_dir)
+{
+       char *last_dot = strrchr(output_filename, '.');
+
+       if (last_dot &&
+           (!strncmp(last_dot, ".ogg", 4) || !strncmp(last_dot, ".ogv", 4))) {
+               tencode_movie(movie_dir);
+       } else
+               mencode_movie(movie_dir);
+}
+
 static void cleanup_movie(char *movie_dir)
 {
+       if (keep_movie_svgs) {
+               fprintf(stderr, "Keeping movie dir %s\n", movie_dir);
+               return;
+       }
        fprintf(stderr, "Removing movie dir %s\n", movie_dir);
        snprintf(line, line_len, "rm %s/*", movie_dir);
        system(line);
@@ -931,8 +1123,7 @@ static void plot_io_movie(struct plot *plot)
                        set_graph_size(cols / graph_width_factor, rows / 8);
                        plot->timeline = i / graph_width_factor;
 
-                       plot_tput(plot, tf->min_seconds,
-                                 tf->max_seconds);
+                       plot_tput(plot, tf->min_seconds, tf->max_seconds, 0);
 
                        plot_cpu(plot, tf->max_seconds,
                                   "CPU System Time", CPU_SYS_GRAPH_INDEX, MPSTAT_SYS);
@@ -1001,12 +1192,13 @@ static void plot_io_movie(struct plot *plot)
                free_all_plot_history(&movie_history);
        }
        convert_movie_files(movie_dir);
-       mencode_movie(movie_dir);
+       encode_movie(movie_dir);
        cleanup_movie(movie_dir);
        free(movie_dir);
 }
 
-static void plot_latency(struct plot *plot, int min_seconds, int max_seconds)
+static void plot_latency(struct plot *plot, unsigned int min_seconds,
+                        unsigned int max_seconds)
 {
        struct trace_file *tf;
        char *units;
@@ -1052,7 +1244,8 @@ static void plot_latency(struct plot *plot, int min_seconds, int max_seconds)
        total_graphs_written++;
 }
 
-static void plot_iops(struct plot *plot, int min_seconds, int max_seconds)
+static void plot_iops(struct plot *plot, unsigned int min_seconds,
+                     unsigned int max_seconds)
 {
        struct trace_file *tf;
        char *units;
@@ -1123,9 +1316,10 @@ enum {
        HELP_LONG_OPT = 1,
 };
 
-char *option_string = "T:t:o:l:r:O:N:d:D:p:m::h:w:c:x:y:a:P";
+char *option_string = "F:T:t:o:l:r:O:N:d:D:p:m::h:w:c:x:y:a:C:PK";
 static struct option long_options[] = {
        {"columns", required_argument, 0, 'c'},
+       {"fio-trace", required_argument, 0, 'F'},
        {"title", required_argument, 0, 'T'},
        {"trace", required_argument, 0, 't'},
        {"output", required_argument, 0, 'o'},
@@ -1137,6 +1331,8 @@ static struct option long_options[] = {
        {"blktrace-destination", required_argument, 0, 'D'},
        {"prog", required_argument, 0, 'p'},
        {"movie", optional_argument, 0, 'm'},
+       {"codec", optional_argument, 0, 'C'},
+       {"keep-movie-svgs", no_argument, 0, 'K'},
        {"width", required_argument, 0, 'w'},
        {"height", required_argument, 0, 'h'},
        {"xzoom", required_argument, 0, 'x'},
@@ -1153,10 +1349,13 @@ static void print_usage(void)
                "\t-d (--device): device for blktrace to trace\n"
                "\t-D (--blktrace-destination): destination for blktrace\n"
                "\t-t (--trace): trace file name (more than one allowed)\n"
+               "\t-F (--fio-trace): fio bandwidth trace (more than one allowed)\n"
                "\t-l (--label): trace label in the graph\n"
                "\t-o (--output): output file name (SVG only)\n"
                "\t-p (--prog): program to run while blktrace is run\n"
+               "\t-K (--keep-movie-svgs keep svgs generated for movie mode\n"
                "\t-m (--movie [=spindle|rect]): create IO animations\n"
+               "\t-C (--codec): ffmpeg codec. Use ffmpeg -codecs to list\n"
                "\t-r (--rolling): number of seconds in the rolling averge\n"
                "\t-T (--title): graph title\n"
                "\t-N (--no-graph): skip a single graph (io, tput, latency, queue_depth, \n"
@@ -1249,6 +1448,9 @@ static int parse_options(int ac, char **av)
                        add_trace_file(optarg);
                        set_blktrace_outfile(optarg);
                        break;
+               case 'F':
+                       add_fio_trace_file(optarg);
+                       break;
                case 'o':
                        output_filename = strdup(optarg);
                        break;
@@ -1269,7 +1471,11 @@ static int parse_options(int ac, char **av)
                        disable_one_graph(optarg);
                        break;
                case 'd':
-                       blktrace_device = strdup(optarg);
+                       if (num_blktrace_devices == MAX_DEVICES_PER_TRACE - 1) {
+                               fprintf(stderr, "Too many blktrace devices provided\n");
+                               exit(1);
+                       }
+                       blktrace_devices[num_blktrace_devices++] = strdup(optarg);
                        break;
                case 'D':
                        blktrace_dest_dir = strdup(optarg);
@@ -1281,6 +1487,9 @@ static int parse_options(int ac, char **av)
                case 'p':
                        program_to_run = strdup(optarg);
                        break;
+               case 'K':
+                       keep_movie_svgs = 1;
+                       break;
                case 'm':
                        make_movie = 1;
                        if (optarg) {
@@ -1293,6 +1502,9 @@ static int parse_options(int ac, char **av)
                        fprintf(stderr, "Using movie style: %s\n",
                                movie_styles[movie_style]);
                        break;
+               case 'C':
+                       ffmpeg_codec = strdup(optarg);
+                       break;
                case 'h':
                        opt_graph_height = atoi(optarg);
                        break;
@@ -1349,11 +1561,11 @@ action_err:
        return 0;
 }
 
-static void dest_mkdir()
+static void dest_mkdir(char *dir)
 {
        int ret;
 
-       ret = mkdir(blktrace_dest_dir, 0777);
+       ret = mkdir(dir, 0777);
        if (ret && errno != EEXIST) {
                fprintf(stderr, "failed to mkdir error %s\n", strerror(errno));
                exit(errno);
@@ -1363,8 +1575,8 @@ static void dest_mkdir()
 int main(int ac, char **av)
 {
        struct plot *plot;
-       int min_seconds = 0;
-       int max_seconds = 0;
+       unsigned int min_seconds = 0;
+       unsigned int max_seconds = 0;
        u64 max_offset = 0;
        u64 min_offset = ~(u64)0;
        struct trace_file *tf;
@@ -1398,19 +1610,28 @@ int main(int ac, char **av)
        if (opt_graph_width)
                set_graph_width(opt_graph_width);
 
-       if (list_empty(&all_traces)) {
+       if (list_empty(&all_traces) && list_empty(&fio_traces)) {
                fprintf(stderr, "No traces found, exiting\n");
                exit(1);
        }
 
-       if (blktrace_device) {
-               char *path = strdup(blktrace_dest_dir);
+       if (num_blktrace_devices) {
+               char *path;
+
+               dest_mkdir(blktrace_dest_dir);
+               if (num_blktrace_devices > 1) {
+                       snprintf(line, line_len, "%s/%s", blktrace_dest_dir,
+                                blktrace_outfile);
+                       dest_mkdir(line);
+               }
+
+               path = join_path(blktrace_dest_dir, blktrace_outfile);
 
-               dest_mkdir();
-               join_path(path, blktrace_outfile);
+               snprintf(line, line_len, "%s.dump", path);
+               unlink(line);
 
-               ret = start_blktrace(blktrace_device, blktrace_outfile,
-                                    blktrace_dest_dir);
+               ret = start_blktrace(blktrace_devices, num_blktrace_devices,
+                                    blktrace_outfile, blktrace_dest_dir);
                if (ret) {
                        fprintf(stderr, "exiting due to blktrace failure\n");
                        exit(1);
@@ -1425,13 +1646,13 @@ int main(int ac, char **av)
                                exit(1);
                        }
                        wait_for_tracers();
-                       blktrace_to_dump(path);
                } else {
                        /* no program specified, just wait for
                         * blktrace to exit
                         */
                        wait_for_tracers();
                }
+               free(path);
        }
 
        /* step one, read all the traces */
@@ -1440,6 +1661,8 @@ int main(int ac, char **av)
        /* step two, find the maxes for time and offset */
        list_for_each_entry(tf, &all_traces, list)
                compare_minmax_tf(tf, &max_seconds, &min_offset, &max_offset);
+       list_for_each_entry(tf, &fio_traces, list)
+               compare_minmax_tf(tf, &max_seconds, &min_offset, &max_offset);
        min_seconds = min_time;
        if (max_seconds > max_time)
                max_seconds = ceil(max_time);
@@ -1471,7 +1694,7 @@ int main(int ac, char **av)
 
        if (active_graphs[IO_GRAPH_INDEX] || found_mpstat)
                set_legend_width(longest_label + longest_proc_name + 1 + strlen("writes"));
-       else if (num_traces > 1)
+       else if (num_traces >= 1 || num_fio_traces >= 1)
                set_legend_width(longest_label);
        else
                set_legend_width(0);
@@ -1495,7 +1718,10 @@ int main(int ac, char **av)
                num_yticks--;
 
        check_plot_columns(plot, TPUT_GRAPH_INDEX);
-       plot_tput(plot, min_seconds, max_seconds);
+       plot_tput(plot, min_seconds, max_seconds, 1);
+
+       check_plot_columns(plot, FIO_GRAPH_INDEX);
+       plot_fio_tput(plot, min_seconds, max_seconds);
 
        check_plot_columns(plot, CPU_IO_GRAPH_INDEX);
        plot_cpu(plot, max_seconds, "CPU IO Wait Time",