2 * Copyright (C) 2012 Fusion-io
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public
6 * License v2 as published by the Free Software Foundation.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 * Parts of this file were imported from Jens Axboe's blktrace sources (also GPL)
19 #include <sys/types.h>
28 #include <asm/types.h>
41 LIST_HEAD(all_traces);
43 static char line[1024];
44 static int line_len = 1024;
45 static int found_mpstat = 0;
46 static int cpu_color_index = 0;
47 static int color_index = 0;
48 static int make_movie = 0;
49 static int opt_graph_width = 0;
50 static int opt_graph_height = 0;
52 static int columns = 1;
53 static int num_xticks = 9;
54 static int num_yticks = 4;
57 * this doesn't include the IO graph,
58 * but it counts the other graphs as they go out
60 static int total_graphs_written = 1;
65 "orange", "darkviolet",
72 char *pick_color(void) {
73 char *ret = colors[color_index];
76 ret = colors[color_index];
82 char *pick_cpu_color(void) {
83 char *ret = colors[cpu_color_index];
86 ret = colors[cpu_color_index];
101 QUEUE_DEPTH_GRAPH_INDEX,
115 static char *graphs_by_name[] = {
134 char *movie_styles[] = {
140 static int movie_style = 0;
142 static int lookup_movie_style(char *str)
146 for (i = 0; i < NUM_MOVIE_STYLES; i++) {
147 if (strcmp(str, movie_styles[i]) == 0)
153 static int active_graphs[TOTAL_GRAPHS];
154 static int last_active_graph = IOPS_GRAPH_INDEX;
156 static int label_index = 0;
157 static int num_traces = 0;
158 static int longest_label = 0;
161 struct list_head list;
172 struct graph_line_data *tput_gld;
173 struct graph_line_data *iop_gld;
174 struct graph_line_data *latency_gld;
175 struct graph_line_data *queue_depth_gld;
176 struct graph_dot_data *gdd_writes;
177 struct graph_dot_data *gdd_reads;
180 int mpstat_stop_seconds;
181 struct graph_line_data **mpstat_gld;
184 static void alloc_mpstat_gld(struct trace_file *tf)
186 struct graph_line_data **ptr;
188 if (tf->trace->mpstat_num_cpus == 0)
191 ptr = calloc((tf->trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS,
192 sizeof(struct graph_line_data *));
194 perror("Unable to allocate mpstat arrays\n");
197 tf->mpstat_gld = ptr;
200 static void enable_all_graphs(void)
203 for (i = 0; i < TOTAL_GRAPHS; i++)
204 active_graphs[i] = 1;
207 static void disable_all_graphs(void)
210 for (i = 0; i < TOTAL_GRAPHS; i++)
211 active_graphs[i] = 0;
214 static int enable_one_graph(char *name)
217 for (i = 0; i < TOTAL_GRAPHS; i++) {
218 if (strcmp(name, graphs_by_name[i]) == 0) {
219 active_graphs[i] = 1;
226 static int disable_one_graph(char *name)
229 for (i = 0; i < TOTAL_GRAPHS; i++) {
230 if (strcmp(name, graphs_by_name[i]) == 0) {
231 active_graphs[i] = 0;
238 static int last_graph(void)
241 for (i = TOTAL_GRAPHS - 1; i >= 0; i--) {
242 if (active_graphs[i]) {
249 static int graphs_left(int cur)
253 for (i = cur; i < TOTAL_GRAPHS; i++) {
254 if (active_graphs[i])
260 static void add_trace_file(char *filename)
262 struct trace_file *tf;
264 tf = calloc(1, sizeof(*tf));
266 fprintf(stderr, "Unable to allocate memory\n");
270 tf->filename = strdup(filename);
271 list_add_tail(&tf->list, &all_traces);
272 tf->read_color = pick_color();
273 tf->write_color = pick_color();
277 static void setup_trace_file_graphs(void)
279 struct trace_file *tf;
282 list_for_each_entry(tf, &all_traces, list) {
283 tf->tput_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
284 tf->latency_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
285 tf->queue_depth_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
286 tf->iop_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
287 tf->gdd_writes = alloc_dot_data(tf->seconds, tf->max_offset, tf->stop_seconds);
288 tf->gdd_reads = alloc_dot_data(tf->seconds, tf->max_offset, tf->stop_seconds);
290 if (tf->trace->mpstat_num_cpus == 0)
293 alloc_mpstat_gld(tf);
294 for (i = 0; i < (tf->trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS; i++) {
296 alloc_line_data(tf->mpstat_seconds,
298 tf->mpstat_gld[i]->max = 100;
303 static void read_traces(void)
305 struct trace_file *tf;
313 list_for_each_entry(tf, &all_traces, list) {
314 trace = open_trace(tf->filename);
318 last_time = find_last_time(trace);
320 tf->seconds = SECONDS(last_time);
321 tf->stop_seconds = SECONDS(last_time);
322 find_highest_offset(trace, &tf->max_offset, &max_bank,
324 filter_outliers(trace, tf->max_offset, &ymin, &ymax);
325 tf->max_offset = ymax;
327 read_mpstat(trace, tf->filename);
328 tf->mpstat_stop_seconds = trace->mpstat_seconds;
329 tf->mpstat_seconds = trace->mpstat_seconds;
330 if (tf->mpstat_seconds)
335 static void read_trace_events(void)
338 struct trace_file *tf;
343 double user, sys, iowait, irq, soft;
344 double max_user = 0, max_sys = 0, max_iowait = 0,
345 max_irq = 0, max_soft = 0;
347 list_for_each_entry(tf, &all_traces, list) {
352 add_tput(trace, tf->tput_gld);
353 add_iop(trace, tf->iop_gld);
354 add_io(trace, tf->gdd_writes, tf->gdd_reads);
355 add_pending_io(trace, tf->queue_depth_gld);
356 add_completed_io(trace, tf->latency_gld);
357 ret = next_record(trace);
362 list_for_each_entry(tf, &all_traces, list) {
365 if (trace->mpstat_num_cpus == 0)
370 for (time = 0; time < tf->mpstat_stop_seconds; time ++) {
371 for (i = 0; i < (trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS; i += MPSTAT_GRAPHS) {
372 ret = read_mpstat_event(trace, &user, &sys,
373 &iowait, &irq, &soft);
376 if (next_mpstat_line(trace))
385 if (iowait > max_iowait)
388 add_mpstat_gld(time, sys, tf->mpstat_gld[i + MPSTAT_SYS]);
389 add_mpstat_gld(time, irq, tf->mpstat_gld[i + MPSTAT_IRQ]);
390 add_mpstat_gld(time, soft, tf->mpstat_gld[i + MPSTAT_SOFT]);
391 add_mpstat_gld(time, user, tf->mpstat_gld[i + MPSTAT_USER]);
392 add_mpstat_gld(time, iowait, tf->mpstat_gld[i + MPSTAT_IO]);
394 if (next_mpstat(trace) == NULL)
400 list_for_each_entry(tf, &all_traces, list) {
403 if (trace->mpstat_num_cpus == 0)
406 tf->mpstat_gld[MPSTAT_SYS]->max = max_sys;
407 tf->mpstat_gld[MPSTAT_IRQ]->max = max_irq;
408 tf->mpstat_gld[MPSTAT_SOFT]->max = max_soft;
409 tf->mpstat_gld[MPSTAT_USER]->max = max_user;
410 tf->mpstat_gld[MPSTAT_IO]->max = max_iowait;;
415 static void set_trace_label(char *label)
418 struct trace_file *tf;
419 int len = strlen(label);
421 if (len > longest_label)
424 list_for_each_entry(tf, &all_traces, list) {
425 if (cur == label_index) {
426 tf->label = strdup(label);
434 static char *graph_title = "";
435 static char *output_filename = "trace.svg";
436 static char *blktrace_device = NULL;
437 static char *blktrace_outfile = "trace";
438 static char *blktrace_dest_dir = ".";
439 static char *program_to_run = NULL;
441 static void set_blktrace_outfile(char *arg)
443 char *s = strdup(arg);
444 char *last_dot = strrchr(s, '.');
447 if (strcmp(last_dot, ".dump") == 0)
450 blktrace_outfile = s;
454 static void compare_max_tf(struct trace_file *tf, int *seconds, u64 *max_offset)
456 if (tf->seconds > *seconds)
457 *seconds = tf->seconds;
458 if (tf->max_offset > *max_offset)
459 *max_offset = tf->max_offset;
462 static void set_all_max_tf(int seconds, u64 max_offset)
464 struct trace_file *tf;
466 list_for_each_entry(tf, &all_traces, list) {
467 tf->seconds = seconds;
468 tf->max_offset = max_offset;
472 static char *create_movie_temp_dir(void)
475 char *pattern = strdup("io-movie-XXXXXX");;
477 ret = mkdtemp(pattern);
479 perror("Unable to create temp directory for movie files");
485 static struct plot_history *alloc_plot_history(char *color)
487 struct plot_history *ph = calloc(1, sizeof(struct plot_history));
490 perror("memory allocation failed");
493 ph->history = calloc(4096, sizeof(double));
495 perror("memory allocation failed");
498 ph->history_len = 4096;
503 LIST_HEAD(movie_history_writes);
504 LIST_HEAD(movie_history_reads);
505 int num_histories = 0;
507 static void add_history(struct plot_history *ph, struct list_head *list)
509 struct plot_history *entry;
511 list_add_tail(&ph->list, list);
514 if (num_histories > 12) {
516 entry = list_entry(list->next, struct plot_history, list);
517 list_del(&entry->list);
518 free(entry->history);
523 static void plot_movie_history(struct plot *plot, struct list_head *list)
525 struct plot_history *ph;
527 if (num_histories > 2)
528 rewind_spindle_steps(num_histories - 1);
530 list_for_each_entry(ph, list, list) {
531 if (movie_style == MOVIE_SPINDLE)
532 svg_io_graph_movie_array_spindle(plot, ph);
534 svg_io_graph_movie_array(plot, ph);
538 static void free_all_plot_history(struct list_head *head)
540 struct plot_history *entry;
541 while (!list_empty(head)) {
542 entry = list_entry(head->next, struct plot_history, list);
543 list_del(&entry->list);
544 free(entry->history);
549 static void plot_io(struct plot *plot, int seconds, u64 max_offset)
551 struct trace_file *tf;
553 if (active_graphs[IO_GRAPH_INDEX] == 0)
558 svg_alloc_legend(plot, num_traces * 2);
560 set_plot_label(plot, "Device IO");
561 set_ylabel(plot, "Offset (MB)");
562 set_yticks(plot, num_yticks, 0, max_offset / (1024 * 1024), "");
563 set_xticks(plot, num_xticks, 0, seconds);
565 list_for_each_entry(tf, &all_traces, list) {
566 char *label = tf->label;
570 svg_io_graph(plot, tf->gdd_reads, tf->read_color);
571 if (tf->gdd_reads->total_ios)
572 svg_add_legend(plot, label, " Reads", tf->read_color);
574 svg_io_graph(plot, tf->gdd_writes, tf->write_color);
575 if (tf->gdd_writes->total_ios) {
576 svg_add_legend(plot, label, " Writes", tf->write_color);
579 if (plot->add_xlabel)
580 set_xlabel(plot, "Time (seconds)");
581 svg_write_legend(plot);
585 static void plot_tput(struct plot *plot, int seconds)
587 struct trace_file *tf;
592 if (active_graphs[TPUT_GRAPH_INDEX] == 0)
596 svg_alloc_legend(plot, num_traces);
597 list_for_each_entry(tf, &all_traces, list) {
598 if (tf->tput_gld->max > max)
599 max = tf->tput_gld->max;
601 list_for_each_entry(tf, &all_traces, list)
602 tf->tput_gld->max = max;
605 set_plot_label(plot, "Throughput");
607 tf = list_entry(all_traces.next, struct trace_file, list);
609 scale_line_graph_bytes(&max, &units, 1024);
610 sprintf(line, "%sB/s", units);
611 set_ylabel(plot, line);
612 set_yticks(plot, num_yticks, 0, max, "");
613 set_xticks(plot, num_xticks, 0, seconds);
615 list_for_each_entry(tf, &all_traces, list) {
616 svg_line_graph(plot, tf->tput_gld, tf->read_color, 0, 0);
618 svg_add_legend(plot, tf->label, "", tf->read_color);
621 if (plot->add_xlabel)
622 set_xlabel(plot, "Time (seconds)");
624 svg_write_legend(plot);
626 total_graphs_written++;
629 static void plot_cpu(struct plot *plot, int seconds, char *label,
630 int active_index, int gld_index)
632 struct trace_file *tf;
641 if (active_graphs[active_index] == 0)
644 list_for_each_entry(tf, &all_traces, list) {
645 if (tf->trace->mpstat_num_cpus > max)
646 max = tf->trace->mpstat_num_cpus;
651 tf = list_entry(all_traces.next, struct trace_file, list);
653 ymax = tf->mpstat_gld[gld_index]->max;
657 svg_alloc_legend(plot, num_traces * max);
660 set_plot_label(plot, label);
662 seconds = tf->mpstat_seconds;
664 set_yticks(plot, num_yticks, 0, tf->mpstat_gld[gld_index]->max, "");
665 set_ylabel(plot, "Percent");
666 set_xticks(plot, num_xticks, 0, seconds);
669 list_for_each_entry(tf, &all_traces, list) {
670 if (tf->mpstat_gld == 0)
672 for (i = 0; i < tf->mpstat_gld[0]->stop_seconds; i++) {
673 if (tf->mpstat_gld[gld_index]->data[i].count) {
674 avg += (tf->mpstat_gld[gld_index]->data[i].sum /
675 tf->mpstat_gld[gld_index]->data[i].count);
678 avg /= tf->mpstat_gld[gld_index]->stop_seconds;
679 color = pick_cpu_color();
680 svg_line_graph(plot, tf->mpstat_gld[0], color, 0, 0);
681 svg_add_legend(plot, tf->label, " avg", color);
683 for (i = 1; i < tf->trace->mpstat_num_cpus + 1; i++) {
684 struct graph_line_data *gld = tf->mpstat_gld[i * MPSTAT_GRAPHS + gld_index];
687 for (gld_i = 0; gld_i < gld->stop_seconds; gld_i++) {
688 if (gld->data[i].count) {
689 this_avg += gld->data[i].sum /
694 this_avg /= gld->stop_seconds;
696 for (gld_i = 0; gld_i < gld->stop_seconds; gld_i++) {
699 if (gld->data[gld_i].count == 0)
701 val = (double)gld->data[gld_i].sum /
702 gld->data[gld_i].count;
704 if (this_avg > avg + 30 || val > 95) {
705 color = pick_cpu_color();
706 svg_line_graph(plot, gld, color, avg + 30, 95);
707 snprintf(line, line_len, " CPU %d\n", i - 1);
708 svg_add_legend(plot, tf->label, line, color);
717 if (plot->add_xlabel)
718 set_xlabel(plot, "Time (seconds)");
720 if (!plot->no_legend) {
721 svg_write_legend(plot);
722 svg_free_legend(plot);
725 total_graphs_written++;
728 static void plot_queue_depth(struct plot *plot, int seconds)
730 struct trace_file *tf;
732 if (active_graphs[QUEUE_DEPTH_GRAPH_INDEX] == 0)
736 set_plot_label(plot, "Queue Depth");
738 svg_alloc_legend(plot, num_traces);
740 tf = list_entry(all_traces.next, struct trace_file, list);
741 set_ylabel(plot, "Pending IO");
742 set_yticks(plot, num_yticks, 0, tf->queue_depth_gld->max, "");
743 set_xticks(plot, num_xticks, 0, seconds);
745 list_for_each_entry(tf, &all_traces, list) {
746 svg_line_graph(plot, tf->queue_depth_gld, tf->read_color, 0, 0);
748 svg_add_legend(plot, tf->label, "", tf->read_color);
751 if (plot->add_xlabel)
752 set_xlabel(plot, "Time (seconds)");
754 svg_write_legend(plot);
756 total_graphs_written++;
759 static void convert_movie_files(char *movie_dir)
761 fprintf(stderr, "Converting svg files in %s\n", movie_dir);
762 snprintf(line, line_len, "find %s -name \\*.svg | xargs -I{} -n 1 -P 8 rsvg-convert -o {}.png {}",
767 static void mencode_movie(char *movie_dir)
769 fprintf(stderr, "Creating movie %s\n", movie_dir);
770 snprintf(line, line_len, "ffmpeg -r 20 -y -i %s/%%10d-%s.svg.png -b:v 250k "
771 "-vcodec libx264 %s", movie_dir, output_filename, output_filename);
775 static void cleanup_movie(char *movie_dir)
777 fprintf(stderr, "Removing movie dir %s\n", movie_dir);
778 snprintf(line, line_len, "rm %s/*", movie_dir);
781 snprintf(line, line_len, "rmdir %s", movie_dir);
785 static void plot_io_movie(struct plot *plot)
787 struct trace_file *tf;
788 char *movie_dir = create_movie_temp_dir();
790 struct plot_history *read_history;
791 struct plot_history *write_history;
794 int movie_frames_per_sec = 20;
795 int total_frames = movie_len * movie_frames_per_sec;
798 int graph_width_factor = 5;
801 get_graph_size(&cols, &rows);
802 batch_count = cols / total_frames;
804 if (batch_count == 0)
807 list_for_each_entry(tf, &all_traces, list) {
808 char *label = tf->label;
814 snprintf(line, line_len, "%s/%010d-%s.svg", movie_dir, i, output_filename);
815 set_plot_output(plot, line);
816 set_plot_title(plot, graph_title);
817 orig_y_offset = plot->start_y_offset;
821 set_graph_size(cols / graph_width_factor, rows / 8);
822 plot->timeline = i / graph_width_factor;
824 plot_tput(plot, tf->gdd_reads->seconds);
826 plot_cpu(plot, tf->gdd_reads->seconds,
827 "CPU System Time", CPU_SYS_GRAPH_INDEX, MPSTAT_SYS);
829 plot->direction = PLOT_ACROSS;
830 plot_queue_depth(plot, tf->gdd_reads->seconds);
832 /* movie graph starts here */
833 plot->start_y_offset = orig_y_offset;
834 set_graph_size(cols - cols / graph_width_factor, rows);
837 plot->direction = PLOT_DOWN;;
839 if (movie_style == MOVIE_SPINDLE)
840 setup_axis_spindle(plot);
844 svg_alloc_legend(plot, num_traces * 2);
846 read_history = alloc_plot_history(tf->read_color);
847 write_history = alloc_plot_history(tf->write_color);
848 read_history->col = i;
849 write_history->col = i;
851 if (tf->gdd_reads->total_ios)
852 svg_add_legend(plot, label, " Reads", tf->read_color);
853 if (tf->gdd_writes->total_ios)
854 svg_add_legend(plot, label, " Writes", tf->write_color);
857 while (i < cols && batch_i < batch_count) {
858 svg_io_graph_movie(tf->gdd_reads, read_history, i);
859 svg_io_graph_movie(tf->gdd_writes, write_history, i);
864 add_history(read_history, &movie_history_reads);
865 add_history(write_history, &movie_history_writes);
867 plot_movie_history(plot, &movie_history_reads);
868 plot_movie_history(plot, &movie_history_writes);
870 svg_write_legend(plot);
874 close_plot_file(plot);
876 free_all_plot_history(&movie_history_reads);
877 free_all_plot_history(&movie_history_writes);
879 convert_movie_files(movie_dir);
880 mencode_movie(movie_dir);
881 cleanup_movie(movie_dir);
885 static void plot_latency(struct plot *plot, int seconds)
887 struct trace_file *tf;
892 if (active_graphs[LATENCY_GRAPH_INDEX] == 0)
896 svg_alloc_legend(plot, num_traces);
898 list_for_each_entry(tf, &all_traces, list) {
899 if (tf->latency_gld->max > max)
900 max = tf->latency_gld->max;
903 list_for_each_entry(tf, &all_traces, list)
904 tf->latency_gld->max = max;
907 set_plot_label(plot, "IO Latency");
909 tf = list_entry(all_traces.next, struct trace_file, list);
911 scale_line_graph_time(&max, &units);
912 sprintf(line, "latency (%ss)", units);
913 set_ylabel(plot, line);
914 set_yticks(plot, num_yticks, 0, max, "");
915 set_xticks(plot, num_xticks, 0, seconds);
917 list_for_each_entry(tf, &all_traces, list) {
918 svg_line_graph(plot, tf->latency_gld, tf->read_color, 0, 0);
920 svg_add_legend(plot, tf->label, "", tf->read_color);
923 if (plot->add_xlabel)
924 set_xlabel(plot, "Time (seconds)");
926 svg_write_legend(plot);
928 total_graphs_written++;
931 static void plot_iops(struct plot *plot, int seconds)
933 struct trace_file *tf;
937 if (active_graphs[IOPS_GRAPH_INDEX] == 0)
940 list_for_each_entry(tf, &all_traces, list) {
941 if (tf->iop_gld->max > max)
942 max = tf->iop_gld->max;
945 list_for_each_entry(tf, &all_traces, list)
946 tf->iop_gld->max = max;
949 set_plot_label(plot, "IOPs");
951 svg_alloc_legend(plot, num_traces);
953 tf = list_entry(all_traces.next, struct trace_file, list);
955 scale_line_graph_bytes(&max, &units, 1000);
956 set_ylabel(plot, "IO/s");
958 set_yticks(plot, num_yticks, 0, max, units);
959 set_xticks(plot, num_xticks, 0, seconds);
961 list_for_each_entry(tf, &all_traces, list) {
962 svg_line_graph(plot, tf->iop_gld, tf->read_color, 0, 0);
964 svg_add_legend(plot, tf->label, "", tf->read_color);
967 if (plot->add_xlabel)
968 set_xlabel(plot, "Time (seconds)");
970 svg_write_legend(plot);
973 total_graphs_written++;
976 static void check_plot_columns(struct plot *plot, int index)
980 if (columns > 1 && (total_graphs_written == 0 ||
981 total_graphs_written % columns != 0)) {
982 count = graphs_left(index);
983 if (plot->direction == PLOT_DOWN) {
984 plot->start_x_offset = 0;
985 if (count <= columns)
986 plot->add_xlabel = 1;
988 plot->direction = PLOT_ACROSS;
991 plot->direction = PLOT_DOWN;
992 if (index == last_active_graph)
993 plot->add_xlabel = 1;
1002 char *option_string = "T:t:o:l:r:O:N:d:p:m::h:w:c:";
1003 static struct option long_options[] = {
1004 {"columns", required_argument, 0, 'c'},
1005 {"title", required_argument, 0, 'T'},
1006 {"trace", required_argument, 0, 't'},
1007 {"output", required_argument, 0, 'o'},
1008 {"label", required_argument, 0, 'l'},
1009 {"rolling", required_argument, 0, 'r'},
1010 {"no-graph", required_argument, 0, 'N'},
1011 {"only-graph", required_argument, 0, 'O'},
1012 {"device", required_argument, 0, 'd'},
1013 {"prog", required_argument, 0, 'p'},
1014 {"movie", optional_argument, 0, 'm'},
1015 {"width", required_argument, 0, 'w'},
1016 {"height", required_argument, 0, 'h'},
1017 {"help", no_argument, 0, HELP_LONG_OPT},
1021 static void print_usage(void)
1023 fprintf(stderr, "iowatcher usage:\n"
1024 "\t-d (--device): device for blktrace to trace\n"
1025 "\t-t (--trace): trace file name (more than one allowed)\n"
1026 "\t-l (--label): trace label in the graph\n"
1027 "\t-o (--output): output file name (SVG only)\n"
1028 "\t-p (--prog): program to run while blktrace is run\n"
1029 "\t-p (--movie [=spindle|rect]): create IO animations\n"
1030 "\t-r (--rolling): number of seconds in the rolling averge\n"
1031 "\t-T (--title): graph title\n"
1032 "\t-N (--no-graph): skip a single graph (io, tput, latency, queue_depth, \n"
1033 "\t\t\tiops, cpu-sys, cpu-io, cpu-irq cpu-soft cpu-user)\n"
1034 "\t-O (--only-graph): add a single graph to the output\n"
1035 "\t-h (--height): set the height of each graph\n"
1036 "\t-w (--width): set the width of each graph\n"
1037 "\t-c (--columns): numbers of columns in graph output\n"
1042 static int parse_options(int ac, char **av)
1048 // int this_option_optind = optind ? optind : 1;
1049 int option_index = 0;
1051 c = getopt_long(ac, av, option_string,
1052 long_options, &option_index);
1059 graph_title = strdup(optarg);
1062 add_trace_file(optarg);
1063 set_blktrace_outfile(optarg);
1066 output_filename = strdup(optarg);
1069 set_trace_label(optarg);
1072 set_rolling_avg(atoi(optarg));
1076 disable_all_graphs();
1079 enable_one_graph(optarg);
1082 disable_one_graph(optarg);
1085 blktrace_device = strdup(optarg);
1088 program_to_run = strdup(optarg);
1093 movie_style = lookup_movie_style(optarg);
1094 if (movie_style < 0) {
1095 fprintf(stderr, "Unknown movie style %s\n", optarg);
1099 fprintf(stderr, "Using movie style: %s\n",
1100 movie_styles[movie_style]);
1103 opt_graph_height = atoi(optarg);
1106 opt_graph_width = atoi(optarg);
1109 columns = atoi(optarg);
1123 int main(int ac, char **av)
1128 struct trace_file *tf;
1132 init_io_hash_table();
1134 enable_all_graphs();
1136 parse_options(ac, av);
1138 last_active_graph = last_graph();
1140 set_io_graph_scale(256);
1141 if (movie_style == MOVIE_SPINDLE)
1142 set_graph_size(750, 550);
1144 set_graph_size(700, 400);
1147 * the plots in the movie don't have a seconds
1148 * line yet, this makes us skip it
1150 last_active_graph = TOTAL_GRAPHS + 1;
1152 if (opt_graph_height)
1153 set_graph_height(opt_graph_height);
1155 if (opt_graph_width)
1156 set_graph_width(opt_graph_width);
1158 if (list_empty(&all_traces)) {
1159 fprintf(stderr, "No traces found, exiting\n");
1163 if (blktrace_device) {
1164 ret = start_blktrace(blktrace_device, blktrace_outfile,
1167 fprintf(stderr, "exiting due to blktrace failure\n");
1170 start_mpstat(blktrace_outfile);
1171 if (program_to_run) {
1172 ret = run_program(program_to_run);
1174 fprintf(stderr, "failed to run %s\n",
1179 blktrace_to_dump(blktrace_outfile);
1181 /* no program specified, just wait for
1188 /* step one, read all the traces */
1191 /* step two, find the maxes for time and offset */
1192 list_for_each_entry(tf, &all_traces, list)
1193 compare_max_tf(tf, &seconds, &max_offset);
1195 /* push the max we found into all the tfs */
1196 set_all_max_tf(seconds, max_offset);
1198 /* alloc graphing structs for all the traces */
1199 setup_trace_file_graphs();
1201 /* run through all the traces and read their events */
1202 read_trace_events();
1204 plot = alloc_plot();
1207 plot_io_movie(plot);
1211 set_plot_output(plot, output_filename);
1213 if (active_graphs[IO_GRAPH_INDEX] || found_mpstat)
1214 set_legend_width(longest_label + strlen("writes"));
1215 else if (num_traces > 1)
1216 set_legend_width(longest_label);
1218 set_legend_width(0);
1220 get_graph_size(&cols, &rows);
1222 plot->add_xlabel = 1;
1223 set_plot_title(plot, graph_title);
1225 plot_io(plot, seconds, max_offset);
1226 plot->add_xlabel = 0;
1229 set_graph_size(cols / columns, rows);
1230 num_xticks /= columns;
1237 check_plot_columns(plot, TPUT_GRAPH_INDEX);
1238 plot_tput(plot, seconds);
1240 check_plot_columns(plot, CPU_IO_GRAPH_INDEX);
1241 plot_cpu(plot, seconds, "CPU IO Wait Time",
1242 CPU_IO_GRAPH_INDEX, MPSTAT_IO);
1244 check_plot_columns(plot, CPU_SYS_GRAPH_INDEX);
1245 plot_cpu(plot, seconds, "CPU System Time",
1246 CPU_SYS_GRAPH_INDEX, MPSTAT_SYS);
1248 check_plot_columns(plot, CPU_IRQ_GRAPH_INDEX);
1249 plot_cpu(plot, seconds, "CPU IRQ Time",
1250 CPU_IRQ_GRAPH_INDEX, MPSTAT_IRQ);
1252 check_plot_columns(plot, CPU_SOFT_GRAPH_INDEX);
1253 plot_cpu(plot, seconds, "CPU SoftIRQ Time",
1254 CPU_SOFT_GRAPH_INDEX, MPSTAT_SOFT);
1256 check_plot_columns(plot, CPU_USER_GRAPH_INDEX);
1257 plot_cpu(plot, seconds, "CPU User Time",
1258 CPU_USER_GRAPH_INDEX, MPSTAT_USER);
1260 check_plot_columns(plot, LATENCY_GRAPH_INDEX);
1261 plot_latency(plot, seconds);
1263 check_plot_columns(plot, QUEUE_DEPTH_GRAPH_INDEX);
1264 plot_queue_depth(plot, seconds);
1266 check_plot_columns(plot, IOPS_GRAPH_INDEX);
1267 plot_iops(plot, seconds);
1271 close_plot_file(plot);