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;
55 "orange", "darkviolet",
62 char *pick_color(void) {
63 char *ret = colors[color_index];
66 ret = colors[color_index];
72 char *pick_cpu_color(void) {
73 char *ret = colors[cpu_color_index];
76 ret = colors[cpu_color_index];
91 QUEUE_DEPTH_GRAPH_INDEX,
105 static char *graphs_by_name[] = {
124 char *movie_styles[] = {
130 static int movie_style = 0;
132 static int lookup_movie_style(char *str)
136 for (i = 0; i < NUM_MOVIE_STYLES; i++) {
137 if (strcmp(str, movie_styles[i]) == 0)
143 static int active_graphs[TOTAL_GRAPHS];
144 static int last_active_graph = IOPS_GRAPH_INDEX;
146 static int label_index = 0;
147 static int num_traces = 0;
148 static int longest_label = 0;
151 struct list_head list;
162 struct graph_line_data *tput_gld;
163 struct graph_line_data *iop_gld;
164 struct graph_line_data *latency_gld;
165 struct graph_line_data *queue_depth_gld;
166 struct graph_dot_data *gdd_writes;
167 struct graph_dot_data *gdd_reads;
170 int mpstat_stop_seconds;
171 struct graph_line_data **mpstat_gld;
174 static void alloc_mpstat_gld(struct trace_file *tf)
176 struct graph_line_data **ptr;
178 if (tf->trace->mpstat_num_cpus == 0)
181 ptr = calloc((tf->trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS,
182 sizeof(struct graph_line_data *));
184 perror("Unable to allocate mpstat arrays\n");
187 tf->mpstat_gld = ptr;
190 static void enable_all_graphs(void)
193 for (i = 0; i < TOTAL_GRAPHS; i++)
194 active_graphs[i] = 1;
197 static void disable_all_graphs(void)
200 for (i = 0; i < TOTAL_GRAPHS; i++)
201 active_graphs[i] = 0;
204 static int enable_one_graph(char *name)
207 for (i = 0; i < TOTAL_GRAPHS; i++) {
208 if (strcmp(name, graphs_by_name[i]) == 0) {
209 active_graphs[i] = 1;
216 static int disable_one_graph(char *name)
219 for (i = 0; i < TOTAL_GRAPHS; i++) {
220 if (strcmp(name, graphs_by_name[i]) == 0) {
221 active_graphs[i] = 0;
228 static int last_graph(void)
231 for (i = TOTAL_GRAPHS - 1; i >= 0; i--) {
232 if (active_graphs[i]) {
238 static void add_trace_file(char *filename)
240 struct trace_file *tf;
242 tf = calloc(1, sizeof(*tf));
244 fprintf(stderr, "Unable to allocate memory\n");
248 tf->filename = strdup(filename);
249 list_add_tail(&tf->list, &all_traces);
250 tf->read_color = pick_color();
251 tf->write_color = pick_color();
255 static void setup_trace_file_graphs(void)
257 struct trace_file *tf;
260 list_for_each_entry(tf, &all_traces, list) {
261 tf->tput_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
262 tf->latency_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
263 tf->queue_depth_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
264 tf->iop_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
265 tf->gdd_writes = alloc_dot_data(tf->seconds, tf->max_offset, tf->stop_seconds);
266 tf->gdd_reads = alloc_dot_data(tf->seconds, tf->max_offset, tf->stop_seconds);
268 if (tf->trace->mpstat_num_cpus == 0)
271 alloc_mpstat_gld(tf);
272 for (i = 0; i < (tf->trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS; i++) {
274 alloc_line_data(tf->mpstat_seconds,
276 tf->mpstat_gld[i]->max = 100;
281 static void read_traces(void)
283 struct trace_file *tf;
291 list_for_each_entry(tf, &all_traces, list) {
292 trace = open_trace(tf->filename);
296 last_time = find_last_time(trace);
298 tf->seconds = SECONDS(last_time);
299 tf->stop_seconds = SECONDS(last_time);
300 find_highest_offset(trace, &tf->max_offset, &max_bank,
302 filter_outliers(trace, tf->max_offset, &ymin, &ymax);
303 tf->max_offset = ymax;
305 read_mpstat(trace, tf->filename);
306 tf->mpstat_stop_seconds = trace->mpstat_seconds;
307 tf->mpstat_seconds = trace->mpstat_seconds;
308 if (tf->mpstat_seconds)
313 static void read_trace_events(void)
316 struct trace_file *tf;
321 double user, sys, iowait, irq, soft;
322 double max_user = 0, max_sys = 0, max_iowait = 0,
323 max_irq = 0, max_soft = 0;
325 list_for_each_entry(tf, &all_traces, list) {
330 add_tput(trace, tf->tput_gld);
331 add_iop(trace, tf->iop_gld);
332 add_io(trace, tf->gdd_writes, tf->gdd_reads);
333 add_pending_io(trace, tf->queue_depth_gld);
334 add_completed_io(trace, tf->latency_gld);
335 ret = next_record(trace);
340 list_for_each_entry(tf, &all_traces, list) {
343 if (trace->mpstat_num_cpus == 0)
348 for (time = 0; time < tf->mpstat_stop_seconds; time ++) {
349 for (i = 0; i < (trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS; i += MPSTAT_GRAPHS) {
350 ret = read_mpstat_event(trace, &user, &sys,
351 &iowait, &irq, &soft);
354 if (next_mpstat_line(trace))
363 if (iowait > max_iowait)
366 add_mpstat_gld(time, sys, tf->mpstat_gld[i + MPSTAT_SYS]);
367 add_mpstat_gld(time, irq, tf->mpstat_gld[i + MPSTAT_IRQ]);
368 add_mpstat_gld(time, soft, tf->mpstat_gld[i + MPSTAT_SOFT]);
369 add_mpstat_gld(time, user, tf->mpstat_gld[i + MPSTAT_USER]);
370 add_mpstat_gld(time, iowait, tf->mpstat_gld[i + MPSTAT_IO]);
372 if (next_mpstat(trace) == NULL)
378 list_for_each_entry(tf, &all_traces, list) {
381 if (trace->mpstat_num_cpus == 0)
384 tf->mpstat_gld[MPSTAT_SYS]->max = max_sys;
385 tf->mpstat_gld[MPSTAT_IRQ]->max = max_irq;
386 tf->mpstat_gld[MPSTAT_SOFT]->max = max_soft;
387 tf->mpstat_gld[MPSTAT_USER]->max = max_user;
388 tf->mpstat_gld[MPSTAT_IO]->max = max_iowait;;
393 static void set_trace_label(char *label)
396 struct trace_file *tf;
397 int len = strlen(label);
399 if (len > longest_label)
402 list_for_each_entry(tf, &all_traces, list) {
403 if (cur == label_index) {
404 tf->label = strdup(label);
412 static char *graph_title = "";
413 static char *output_filename = "trace.svg";
414 static char *blktrace_device = NULL;
415 static char *blktrace_outfile = "trace";
416 static char *blktrace_dest_dir = ".";
417 static char *program_to_run = NULL;
419 static void set_blktrace_outfile(char *arg)
421 char *s = strdup(arg);
422 char *last_dot = strrchr(s, '.');
425 if (strcmp(last_dot, ".dump") == 0)
428 blktrace_outfile = s;
432 static void compare_max_tf(struct trace_file *tf, int *seconds, u64 *max_offset)
434 if (tf->seconds > *seconds)
435 *seconds = tf->seconds;
436 if (tf->max_offset > *max_offset)
437 *max_offset = tf->max_offset;
440 static void set_all_max_tf(int seconds, u64 max_offset)
442 struct trace_file *tf;
444 list_for_each_entry(tf, &all_traces, list) {
445 tf->seconds = seconds;
446 tf->max_offset = max_offset;
450 static char *create_movie_temp_dir(void)
453 char *pattern = strdup("io-movie-XXXXXX");;
455 ret = mkdtemp(pattern);
457 perror("Unable to create temp directory for movie files");
463 static struct plot_history *alloc_plot_history(char *color)
465 struct plot_history *ph = calloc(1, sizeof(struct plot_history));
468 perror("memory allocation failed");
471 ph->history = calloc(4096, sizeof(double));
473 perror("memory allocation failed");
476 ph->history_len = 4096;
481 LIST_HEAD(movie_history_writes);
482 LIST_HEAD(movie_history_reads);
483 int num_histories = 0;
485 static void add_history(struct plot_history *ph, struct list_head *list)
487 struct plot_history *entry;
489 list_add_tail(&ph->list, list);
492 if (num_histories > 12) {
494 entry = list_entry(list->next, struct plot_history, list);
495 list_del(&entry->list);
496 free(entry->history);
501 static void plot_movie_history(struct plot *plot, struct list_head *list)
503 struct plot_history *ph;
505 if (num_histories > 2)
506 rewind_spindle_steps(num_histories - 1);
508 list_for_each_entry(ph, list, list) {
509 if (movie_style == MOVIE_SPINDLE)
510 svg_io_graph_movie_array_spindle(plot, ph);
512 svg_io_graph_movie_array(plot, ph);
516 static void free_all_plot_history(struct list_head *head)
518 struct plot_history *entry;
519 while (!list_empty(head)) {
520 entry = list_entry(head->next, struct plot_history, list);
521 list_del(&entry->list);
522 free(entry->history);
527 static void __plot_io(struct plot *plot, int seconds, u64 max_offset)
529 struct trace_file *tf;
533 svg_alloc_legend(plot, num_traces * 2);
535 set_plot_label(plot, "Device IO");
536 set_ylabel(plot, "Offset (MB)");
537 set_yticks(plot, 4, 0, max_offset / (1024 * 1024), "");
538 set_xticks(plot, 9, 0, seconds);
540 list_for_each_entry(tf, &all_traces, list) {
541 char *label = tf->label;
545 svg_io_graph(plot, tf->gdd_reads, tf->read_color);
546 if (tf->gdd_reads->total_ios)
547 svg_add_legend(plot, label, " Reads", tf->read_color);
549 svg_io_graph(plot, tf->gdd_writes, tf->write_color);
550 if (tf->gdd_writes->total_ios) {
551 svg_add_legend(plot, label, " Writes", tf->write_color);
554 if (plot->add_xlabel)
555 set_xlabel(plot, "Time (seconds)");
556 svg_write_legend(plot);
559 static void plot_io(struct plot *plot, int seconds, u64 max_offset)
561 if (active_graphs[IO_GRAPH_INDEX] == 0)
564 plot->add_xlabel = last_active_graph == IO_GRAPH_INDEX;
565 __plot_io(plot, seconds, max_offset);
569 static void __plot_tput(struct plot *plot, int seconds)
571 struct trace_file *tf;
577 svg_alloc_legend(plot, num_traces);
578 list_for_each_entry(tf, &all_traces, list) {
579 if (tf->tput_gld->max > max)
580 max = tf->tput_gld->max;
582 list_for_each_entry(tf, &all_traces, list)
583 tf->tput_gld->max = max;
586 set_plot_label(plot, "Throughput");
588 tf = list_entry(all_traces.next, struct trace_file, list);
590 scale_line_graph_bytes(&max, &units, 1024);
591 sprintf(line, "%sB/s", units);
592 set_ylabel(plot, line);
593 set_yticks(plot, 4, 0, max, "");
594 set_xticks(plot, 9, 0, seconds);
596 list_for_each_entry(tf, &all_traces, list) {
597 svg_line_graph(plot, tf->tput_gld, tf->read_color, 0, 0);
599 svg_add_legend(plot, tf->label, "", tf->read_color);
602 if (plot->add_xlabel)
603 set_xlabel(plot, "Time (seconds)");
605 svg_write_legend(plot);
608 static void plot_tput(struct plot *plot, int seconds)
610 if (active_graphs[TPUT_GRAPH_INDEX] == 0)
613 plot->add_xlabel = last_active_graph == TPUT_GRAPH_INDEX;
614 __plot_tput(plot, seconds);
618 static int __plot_cpu(struct plot *plot, int seconds, char *label,
619 int active_index, int gld_index)
621 struct trace_file *tf;
630 list_for_each_entry(tf, &all_traces, list) {
631 if (tf->trace->mpstat_num_cpus > max)
632 max = tf->trace->mpstat_num_cpus;
637 tf = list_entry(all_traces.next, struct trace_file, list);
639 ymax = tf->mpstat_gld[gld_index]->max;
643 svg_alloc_legend(plot, num_traces * max);
645 plot->add_xlabel = last_active_graph == active_index;
647 set_plot_label(plot, label);
649 seconds = tf->mpstat_seconds;
651 set_yticks(plot, 4, 0, tf->mpstat_gld[gld_index]->max, "");
652 set_ylabel(plot, "Percent");
653 set_xticks(plot, 9, 0, seconds);
656 list_for_each_entry(tf, &all_traces, list) {
657 for (i = 0; i < tf->mpstat_gld[0]->stop_seconds; i++) {
658 if (tf->mpstat_gld[gld_index]->data[i].count) {
659 avg += (tf->mpstat_gld[gld_index]->data[i].sum /
660 tf->mpstat_gld[gld_index]->data[i].count);
663 avg /= tf->mpstat_gld[gld_index]->stop_seconds;
664 color = pick_cpu_color();
665 svg_line_graph(plot, tf->mpstat_gld[0], color, 0, 0);
666 svg_add_legend(plot, tf->label, " avg", color);
668 for (i = 1; i < tf->trace->mpstat_num_cpus + 1; i++) {
669 struct graph_line_data *gld = tf->mpstat_gld[i * MPSTAT_GRAPHS + gld_index];
672 for (gld_i = 0; gld_i < gld->stop_seconds; gld_i++) {
673 if (gld->data[i].count) {
674 this_avg += gld->data[i].sum /
679 this_avg /= gld->stop_seconds;
681 for (gld_i = 0; gld_i < gld->stop_seconds; gld_i++) {
684 if (gld->data[gld_i].count == 0)
686 val = (double)gld->data[gld_i].sum /
687 gld->data[gld_i].count;
689 if (this_avg > avg + 30 || val > 95) {
690 color = pick_cpu_color();
691 svg_line_graph(plot, gld, color, avg + 30, 95);
692 snprintf(line, line_len, " CPU %d\n", i - 1);
693 svg_add_legend(plot, tf->label, line, color);
702 if (plot->add_xlabel)
703 set_xlabel(plot, "Time (seconds)");
705 if (!plot->no_legend) {
706 svg_write_legend(plot);
707 svg_free_legend(plot);
712 static void plot_cpu(struct plot *plot, int seconds, char *label,
713 int active_index, int gld_index)
715 if (active_graphs[active_index] == 0)
718 plot->add_xlabel = last_active_graph == active_index;
719 if (!__plot_cpu(plot, seconds, label, active_index, gld_index))
723 static void __plot_queue_depth(struct plot *plot, int seconds)
725 struct trace_file *tf;
727 plot->add_xlabel = last_active_graph == QUEUE_DEPTH_GRAPH_INDEX;
730 set_plot_label(plot, "Queue Depth");
732 svg_alloc_legend(plot, num_traces);
734 tf = list_entry(all_traces.next, struct trace_file, list);
735 set_ylabel(plot, "Pending IO");
736 set_yticks(plot, 4, 0, tf->queue_depth_gld->max, "");
737 set_xticks(plot, 9, 0, seconds);
739 list_for_each_entry(tf, &all_traces, list) {
740 svg_line_graph(plot, tf->queue_depth_gld, tf->read_color, 0, 0);
742 svg_add_legend(plot, tf->label, "", tf->read_color);
745 if (plot->add_xlabel)
746 set_xlabel(plot, "Time (seconds)");
748 svg_write_legend(plot);
751 static void plot_queue_depth(struct plot *plot, int seconds)
753 if (active_graphs[QUEUE_DEPTH_GRAPH_INDEX] == 0)
755 __plot_queue_depth(plot, seconds);
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);
823 __plot_tput(plot, tf->gdd_reads->seconds);
824 svg_write_time_line(plot, i / graph_width_factor);
827 if (!__plot_cpu(plot, tf->gdd_reads->seconds,
828 "CPU System Time", CPU_SYS_GRAPH_INDEX, MPSTAT_SYS)) {
829 svg_write_time_line(plot, i / graph_width_factor);
833 __plot_queue_depth(plot, tf->gdd_reads->seconds);
834 svg_write_time_line(plot, i / graph_width_factor);
836 close_plot_col(plot);
838 /* movie graph starts here */
839 plot->start_y_offset = orig_y_offset;
840 set_graph_size(cols - cols / graph_width_factor, rows);
843 if (movie_style == MOVIE_SPINDLE)
844 setup_axis_spindle(plot);
848 svg_alloc_legend(plot, num_traces * 2);
850 read_history = alloc_plot_history(tf->read_color);
851 write_history = alloc_plot_history(tf->write_color);
852 read_history->col = i;
853 write_history->col = i;
855 if (tf->gdd_reads->total_ios)
856 svg_add_legend(plot, label, " Reads", tf->read_color);
857 if (tf->gdd_writes->total_ios)
858 svg_add_legend(plot, label, " Writes", tf->write_color);
861 while (i < cols && batch_i < batch_count) {
862 svg_io_graph_movie(tf->gdd_reads, read_history, i);
863 svg_io_graph_movie(tf->gdd_writes, write_history, i);
868 add_history(read_history, &movie_history_reads);
869 add_history(write_history, &movie_history_writes);
871 plot_movie_history(plot, &movie_history_reads);
872 plot_movie_history(plot, &movie_history_writes);
874 svg_write_legend(plot);
878 close_plot_file(plot);
880 free_all_plot_history(&movie_history_reads);
881 free_all_plot_history(&movie_history_writes);
883 convert_movie_files(movie_dir);
884 mencode_movie(movie_dir);
885 cleanup_movie(movie_dir);
889 static void plot_latency(struct plot *plot, int seconds)
891 struct trace_file *tf;
896 if (active_graphs[LATENCY_GRAPH_INDEX] == 0)
900 svg_alloc_legend(plot, num_traces);
901 list_for_each_entry(tf, &all_traces, list) {
902 if (tf->latency_gld->max > max)
903 max = tf->latency_gld->max;
905 list_for_each_entry(tf, &all_traces, list)
906 tf->latency_gld->max = max;
908 plot->add_xlabel = last_active_graph == TPUT_GRAPH_INDEX;
910 set_plot_label(plot, "IO Latency");
912 tf = list_entry(all_traces.next, struct trace_file, list);
914 scale_line_graph_time(&max, &units);
915 sprintf(line, "latency (%ss)", units);
916 set_ylabel(plot, line);
917 set_yticks(plot, 4, 0, max, "");
918 set_xticks(plot, 9, 0, seconds);
920 list_for_each_entry(tf, &all_traces, list) {
921 svg_line_graph(plot, tf->latency_gld, tf->read_color, 0, 0);
923 svg_add_legend(plot, tf->label, "", tf->read_color);
926 if (plot->add_xlabel)
927 set_xlabel(plot, "Time (seconds)");
929 svg_write_legend(plot);
933 static void plot_iops(struct plot *plot, int seconds)
935 struct trace_file *tf;
939 if (active_graphs[IOPS_GRAPH_INDEX] == 0)
942 list_for_each_entry(tf, &all_traces, list) {
943 if (tf->iop_gld->max > max)
944 max = tf->iop_gld->max;
947 list_for_each_entry(tf, &all_traces, list)
948 tf->iop_gld->max = max;
951 plot->add_xlabel = last_active_graph == IOPS_GRAPH_INDEX;
953 set_plot_label(plot, "IOPs");
955 svg_alloc_legend(plot, num_traces);
957 tf = list_entry(all_traces.next, struct trace_file, list);
959 scale_line_graph_bytes(&max, &units, 1000);
960 set_ylabel(plot, "IO/s");
962 set_yticks(plot, 4, 0, max, units);
963 set_xticks(plot, 9, 0, seconds);
965 list_for_each_entry(tf, &all_traces, list) {
966 svg_line_graph(plot, tf->iop_gld, tf->read_color, 0, 0);
968 svg_add_legend(plot, tf->label, "", tf->read_color);
971 if (plot->add_xlabel)
972 set_xlabel(plot, "Time (seconds)");
974 svg_write_legend(plot);
983 char *option_string = "T:t:o:l:r:O:N:d:p:m::h:w:";
984 static struct option long_options[] = {
985 {"title", required_argument, 0, 'T'},
986 {"trace", required_argument, 0, 't'},
987 {"output", required_argument, 0, 'o'},
988 {"label", required_argument, 0, 'l'},
989 {"rolling", required_argument, 0, 'r'},
990 {"no-graph", required_argument, 0, 'N'},
991 {"only-graph", required_argument, 0, 'O'},
992 {"device", required_argument, 0, 'd'},
993 {"prog", required_argument, 0, 'p'},
994 {"movie", optional_argument, 0, 'm'},
995 {"width", required_argument, 0, 'w'},
996 {"height", required_argument, 0, 'h'},
997 {"help", no_argument, 0, HELP_LONG_OPT},
1001 static void print_usage(void)
1003 fprintf(stderr, "iowatcher usage:\n"
1004 "\t-d (--device): device for blktrace to trace\n"
1005 "\t-t (--trace): trace file name (more than one allowed)\n"
1006 "\t-l (--label): trace label in the graph\n"
1007 "\t-o (--output): output file name (SVG only)\n"
1008 "\t-p (--prog): program to run while blktrace is run\n"
1009 "\t-p (--movie [=spindle|rect]): create IO animations\n"
1010 "\t-r (--rolling): number of seconds in the rolling averge\n"
1011 "\t-T (--title): graph title\n"
1012 "\t-N (--no-graph): skip a single graph (io, tput, latency, queue_depth, \n"
1013 "\t\t\tiops, cpu-sys, cpu-io, cpu-irq cpu-soft cpu-user)\n"
1014 "\t-O (--only-graph): add a single graph to the output\n"
1015 "\t-h (--height): set the height of each graph\n"
1016 "\t-w (--width): set the width of each graph\n"
1021 static int parse_options(int ac, char **av)
1027 // int this_option_optind = optind ? optind : 1;
1028 int option_index = 0;
1030 c = getopt_long(ac, av, option_string,
1031 long_options, &option_index);
1038 graph_title = strdup(optarg);
1041 add_trace_file(optarg);
1042 set_blktrace_outfile(optarg);
1045 output_filename = strdup(optarg);
1048 set_trace_label(optarg);
1051 set_rolling_avg(atoi(optarg));
1055 disable_all_graphs();
1058 enable_one_graph(optarg);
1061 disable_one_graph(optarg);
1064 blktrace_device = strdup(optarg);
1067 program_to_run = strdup(optarg);
1072 movie_style = lookup_movie_style(optarg);
1073 if (movie_style < 0) {
1074 fprintf(stderr, "Unknown movie style %s\n", optarg);
1078 fprintf(stderr, "Using movie style: %s\n",
1079 movie_styles[movie_style]);
1082 opt_graph_height = atoi(optarg);
1085 opt_graph_width = atoi(optarg);
1099 int main(int ac, char **av)
1104 struct trace_file *tf;
1107 init_io_hash_table();
1109 enable_all_graphs();
1111 parse_options(ac, av);
1113 last_active_graph = last_graph();
1115 set_io_graph_scale(256);
1116 if (movie_style == MOVIE_SPINDLE)
1117 set_graph_size(750, 550);
1119 set_graph_size(700, 400);
1121 if (opt_graph_height)
1122 set_graph_height(opt_graph_height);
1124 if (opt_graph_width)
1125 set_graph_width(opt_graph_height);
1127 if (list_empty(&all_traces)) {
1128 fprintf(stderr, "No traces found, exiting\n");
1132 if (blktrace_device) {
1133 ret = start_blktrace(blktrace_device, blktrace_outfile,
1136 fprintf(stderr, "exiting due to blktrace failure\n");
1139 start_mpstat(blktrace_outfile);
1140 if (program_to_run) {
1141 ret = run_program(program_to_run);
1143 fprintf(stderr, "failed to run %s\n",
1148 blktrace_to_dump(blktrace_outfile);
1150 /* no program specified, just wait for
1157 /* step one, read all the traces */
1160 /* step two, find the maxes for time and offset */
1161 list_for_each_entry(tf, &all_traces, list)
1162 compare_max_tf(tf, &seconds, &max_offset);
1164 /* push the max we found into all the tfs */
1165 set_all_max_tf(seconds, max_offset);
1167 /* alloc graphing structs for all the traces */
1168 setup_trace_file_graphs();
1170 /* run through all the traces and read their events */
1171 read_trace_events();
1173 plot = alloc_plot();
1176 plot_io_movie(plot);
1180 set_plot_output(plot, output_filename);
1182 if (active_graphs[IO_GRAPH_INDEX] || found_mpstat)
1183 set_legend_width(longest_label + strlen("writes"));
1184 else if (num_traces > 1)
1185 set_legend_width(longest_label);
1187 set_legend_width(0);
1189 set_plot_title(plot, graph_title);
1190 plot_io(plot, seconds, max_offset);
1191 plot_tput(plot, seconds);
1192 plot_cpu(plot, seconds, "CPU IO Wait Time",
1193 CPU_IO_GRAPH_INDEX, MPSTAT_IO);
1194 plot_cpu(plot, seconds, "CPU System Time",
1195 CPU_SYS_GRAPH_INDEX, MPSTAT_SYS);
1196 plot_cpu(plot, seconds, "CPU IRQ Time",
1197 CPU_IRQ_GRAPH_INDEX, MPSTAT_IRQ);
1198 plot_cpu(plot, seconds, "CPU SoftIRQ Time",
1199 CPU_SOFT_GRAPH_INDEX, MPSTAT_SOFT);
1200 plot_cpu(plot, seconds, "CPU User Time",
1201 CPU_USER_GRAPH_INDEX, MPSTAT_USER);
1203 plot_latency(plot, seconds);
1204 plot_queue_depth(plot, seconds);
1205 plot_iops(plot, seconds);
1209 close_plot_file(plot);