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;
56 * this doesn't include the IO graph,
57 * but it counts the other graphs as they go out
59 static int total_graphs_written = 1;
64 "orange", "darkviolet",
71 char *pick_color(void) {
72 char *ret = colors[color_index];
75 ret = colors[color_index];
81 char *pick_cpu_color(void) {
82 char *ret = colors[cpu_color_index];
85 ret = colors[cpu_color_index];
100 QUEUE_DEPTH_GRAPH_INDEX,
114 static char *graphs_by_name[] = {
133 char *movie_styles[] = {
139 static int movie_style = 0;
141 static int lookup_movie_style(char *str)
145 for (i = 0; i < NUM_MOVIE_STYLES; i++) {
146 if (strcmp(str, movie_styles[i]) == 0)
152 static int active_graphs[TOTAL_GRAPHS];
153 static int last_active_graph = IOPS_GRAPH_INDEX;
155 static int label_index = 0;
156 static int num_traces = 0;
157 static int longest_label = 0;
160 struct list_head list;
171 struct graph_line_data *tput_gld;
172 struct graph_line_data *iop_gld;
173 struct graph_line_data *latency_gld;
174 struct graph_line_data *queue_depth_gld;
175 struct graph_dot_data *gdd_writes;
176 struct graph_dot_data *gdd_reads;
179 int mpstat_stop_seconds;
180 struct graph_line_data **mpstat_gld;
183 static void alloc_mpstat_gld(struct trace_file *tf)
185 struct graph_line_data **ptr;
187 if (tf->trace->mpstat_num_cpus == 0)
190 ptr = calloc((tf->trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS,
191 sizeof(struct graph_line_data *));
193 perror("Unable to allocate mpstat arrays\n");
196 tf->mpstat_gld = ptr;
199 static void enable_all_graphs(void)
202 for (i = 0; i < TOTAL_GRAPHS; i++)
203 active_graphs[i] = 1;
206 static void disable_all_graphs(void)
209 for (i = 0; i < TOTAL_GRAPHS; i++)
210 active_graphs[i] = 0;
213 static int enable_one_graph(char *name)
216 for (i = 0; i < TOTAL_GRAPHS; i++) {
217 if (strcmp(name, graphs_by_name[i]) == 0) {
218 active_graphs[i] = 1;
225 static int disable_one_graph(char *name)
228 for (i = 0; i < TOTAL_GRAPHS; i++) {
229 if (strcmp(name, graphs_by_name[i]) == 0) {
230 active_graphs[i] = 0;
237 static int last_graph(void)
240 for (i = TOTAL_GRAPHS - 1; i >= 0; i--) {
241 if (active_graphs[i]) {
248 static int graphs_left(int cur)
252 for (i = cur; i < TOTAL_GRAPHS; i++) {
253 if (active_graphs[i])
259 static void add_trace_file(char *filename)
261 struct trace_file *tf;
263 tf = calloc(1, sizeof(*tf));
265 fprintf(stderr, "Unable to allocate memory\n");
269 tf->filename = strdup(filename);
270 list_add_tail(&tf->list, &all_traces);
271 tf->read_color = pick_color();
272 tf->write_color = pick_color();
276 static void setup_trace_file_graphs(void)
278 struct trace_file *tf;
281 list_for_each_entry(tf, &all_traces, list) {
282 tf->tput_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
283 tf->latency_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
284 tf->queue_depth_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
285 tf->iop_gld = alloc_line_data(tf->seconds, tf->stop_seconds);
286 tf->gdd_writes = alloc_dot_data(tf->seconds, tf->max_offset, tf->stop_seconds);
287 tf->gdd_reads = alloc_dot_data(tf->seconds, tf->max_offset, tf->stop_seconds);
289 if (tf->trace->mpstat_num_cpus == 0)
292 alloc_mpstat_gld(tf);
293 for (i = 0; i < (tf->trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS; i++) {
295 alloc_line_data(tf->mpstat_seconds,
297 tf->mpstat_gld[i]->max = 100;
302 static void read_traces(void)
304 struct trace_file *tf;
312 list_for_each_entry(tf, &all_traces, list) {
313 trace = open_trace(tf->filename);
317 last_time = find_last_time(trace);
319 tf->seconds = SECONDS(last_time);
320 tf->stop_seconds = SECONDS(last_time);
321 find_highest_offset(trace, &tf->max_offset, &max_bank,
323 filter_outliers(trace, tf->max_offset, &ymin, &ymax);
324 tf->max_offset = ymax;
326 read_mpstat(trace, tf->filename);
327 tf->mpstat_stop_seconds = trace->mpstat_seconds;
328 tf->mpstat_seconds = trace->mpstat_seconds;
329 if (tf->mpstat_seconds)
334 static void read_trace_events(void)
337 struct trace_file *tf;
342 double user, sys, iowait, irq, soft;
343 double max_user = 0, max_sys = 0, max_iowait = 0,
344 max_irq = 0, max_soft = 0;
346 list_for_each_entry(tf, &all_traces, list) {
351 add_tput(trace, tf->tput_gld);
352 add_iop(trace, tf->iop_gld);
353 add_io(trace, tf->gdd_writes, tf->gdd_reads);
354 add_pending_io(trace, tf->queue_depth_gld);
355 add_completed_io(trace, tf->latency_gld);
356 ret = next_record(trace);
361 list_for_each_entry(tf, &all_traces, list) {
364 if (trace->mpstat_num_cpus == 0)
369 for (time = 0; time < tf->mpstat_stop_seconds; time ++) {
370 for (i = 0; i < (trace->mpstat_num_cpus + 1) * MPSTAT_GRAPHS; i += MPSTAT_GRAPHS) {
371 ret = read_mpstat_event(trace, &user, &sys,
372 &iowait, &irq, &soft);
375 if (next_mpstat_line(trace))
384 if (iowait > max_iowait)
387 add_mpstat_gld(time, sys, tf->mpstat_gld[i + MPSTAT_SYS]);
388 add_mpstat_gld(time, irq, tf->mpstat_gld[i + MPSTAT_IRQ]);
389 add_mpstat_gld(time, soft, tf->mpstat_gld[i + MPSTAT_SOFT]);
390 add_mpstat_gld(time, user, tf->mpstat_gld[i + MPSTAT_USER]);
391 add_mpstat_gld(time, iowait, tf->mpstat_gld[i + MPSTAT_IO]);
393 if (next_mpstat(trace) == NULL)
399 list_for_each_entry(tf, &all_traces, list) {
402 if (trace->mpstat_num_cpus == 0)
405 tf->mpstat_gld[MPSTAT_SYS]->max = max_sys;
406 tf->mpstat_gld[MPSTAT_IRQ]->max = max_irq;
407 tf->mpstat_gld[MPSTAT_SOFT]->max = max_soft;
408 tf->mpstat_gld[MPSTAT_USER]->max = max_user;
409 tf->mpstat_gld[MPSTAT_IO]->max = max_iowait;;
414 static void set_trace_label(char *label)
417 struct trace_file *tf;
418 int len = strlen(label);
420 if (len > longest_label)
423 list_for_each_entry(tf, &all_traces, list) {
424 if (cur == label_index) {
425 tf->label = strdup(label);
433 static char *graph_title = "";
434 static char *output_filename = "trace.svg";
435 static char *blktrace_device = NULL;
436 static char *blktrace_outfile = "trace";
437 static char *blktrace_dest_dir = ".";
438 static char *program_to_run = NULL;
440 static void set_blktrace_outfile(char *arg)
442 char *s = strdup(arg);
443 char *last_dot = strrchr(s, '.');
446 if (strcmp(last_dot, ".dump") == 0)
449 blktrace_outfile = s;
453 static void compare_max_tf(struct trace_file *tf, int *seconds, u64 *max_offset)
455 if (tf->seconds > *seconds)
456 *seconds = tf->seconds;
457 if (tf->max_offset > *max_offset)
458 *max_offset = tf->max_offset;
461 static void set_all_max_tf(int seconds, u64 max_offset)
463 struct trace_file *tf;
465 list_for_each_entry(tf, &all_traces, list) {
466 tf->seconds = seconds;
467 tf->max_offset = max_offset;
471 static char *create_movie_temp_dir(void)
474 char *pattern = strdup("io-movie-XXXXXX");;
476 ret = mkdtemp(pattern);
478 perror("Unable to create temp directory for movie files");
484 static struct plot_history *alloc_plot_history(char *color)
486 struct plot_history *ph = calloc(1, sizeof(struct plot_history));
489 perror("memory allocation failed");
492 ph->history = calloc(4096, sizeof(double));
494 perror("memory allocation failed");
497 ph->history_len = 4096;
502 LIST_HEAD(movie_history_writes);
503 LIST_HEAD(movie_history_reads);
504 int num_histories = 0;
506 static void add_history(struct plot_history *ph, struct list_head *list)
508 struct plot_history *entry;
510 list_add_tail(&ph->list, list);
513 if (num_histories > 12) {
515 entry = list_entry(list->next, struct plot_history, list);
516 list_del(&entry->list);
517 free(entry->history);
522 static void plot_movie_history(struct plot *plot, struct list_head *list)
524 struct plot_history *ph;
526 if (num_histories > 2)
527 rewind_spindle_steps(num_histories - 1);
529 list_for_each_entry(ph, list, list) {
530 if (movie_style == MOVIE_SPINDLE)
531 svg_io_graph_movie_array_spindle(plot, ph);
533 svg_io_graph_movie_array(plot, ph);
537 static void free_all_plot_history(struct list_head *head)
539 struct plot_history *entry;
540 while (!list_empty(head)) {
541 entry = list_entry(head->next, struct plot_history, list);
542 list_del(&entry->list);
543 free(entry->history);
548 static void plot_io(struct plot *plot, int seconds, u64 max_offset)
550 struct trace_file *tf;
552 if (active_graphs[IO_GRAPH_INDEX] == 0)
557 svg_alloc_legend(plot, num_traces * 2);
559 set_plot_label(plot, "Device IO");
560 set_ylabel(plot, "Offset (MB)");
561 set_yticks(plot, 4, 0, max_offset / (1024 * 1024), "");
562 set_xticks(plot, num_xticks, 0, seconds);
564 list_for_each_entry(tf, &all_traces, list) {
565 char *label = tf->label;
569 svg_io_graph(plot, tf->gdd_reads, tf->read_color);
570 if (tf->gdd_reads->total_ios)
571 svg_add_legend(plot, label, " Reads", tf->read_color);
573 svg_io_graph(plot, tf->gdd_writes, tf->write_color);
574 if (tf->gdd_writes->total_ios) {
575 svg_add_legend(plot, label, " Writes", tf->write_color);
578 if (plot->add_xlabel)
579 set_xlabel(plot, "Time (seconds)");
580 svg_write_legend(plot);
584 static void plot_tput(struct plot *plot, int seconds)
586 struct trace_file *tf;
591 if (active_graphs[TPUT_GRAPH_INDEX] == 0)
595 svg_alloc_legend(plot, num_traces);
596 list_for_each_entry(tf, &all_traces, list) {
597 if (tf->tput_gld->max > max)
598 max = tf->tput_gld->max;
600 list_for_each_entry(tf, &all_traces, list)
601 tf->tput_gld->max = max;
604 set_plot_label(plot, "Throughput");
606 tf = list_entry(all_traces.next, struct trace_file, list);
608 scale_line_graph_bytes(&max, &units, 1024);
609 sprintf(line, "%sB/s", units);
610 set_ylabel(plot, line);
611 set_yticks(plot, 4, 0, max, "");
612 set_xticks(plot, num_xticks, 0, seconds);
614 list_for_each_entry(tf, &all_traces, list) {
615 svg_line_graph(plot, tf->tput_gld, tf->read_color, 0, 0);
617 svg_add_legend(plot, tf->label, "", tf->read_color);
620 if (plot->add_xlabel)
621 set_xlabel(plot, "Time (seconds)");
623 svg_write_legend(plot);
625 total_graphs_written++;
628 static void plot_cpu(struct plot *plot, int seconds, char *label,
629 int active_index, int gld_index)
631 struct trace_file *tf;
640 if (active_graphs[active_index] == 0)
643 list_for_each_entry(tf, &all_traces, list) {
644 if (tf->trace->mpstat_num_cpus > max)
645 max = tf->trace->mpstat_num_cpus;
650 tf = list_entry(all_traces.next, struct trace_file, list);
652 ymax = tf->mpstat_gld[gld_index]->max;
656 svg_alloc_legend(plot, num_traces * max);
659 set_plot_label(plot, label);
661 seconds = tf->mpstat_seconds;
663 set_yticks(plot, 4, 0, tf->mpstat_gld[gld_index]->max, "");
664 set_ylabel(plot, "Percent");
665 set_xticks(plot, num_xticks, 0, seconds);
668 list_for_each_entry(tf, &all_traces, list) {
669 for (i = 0; i < tf->mpstat_gld[0]->stop_seconds; i++) {
670 if (tf->mpstat_gld[gld_index]->data[i].count) {
671 avg += (tf->mpstat_gld[gld_index]->data[i].sum /
672 tf->mpstat_gld[gld_index]->data[i].count);
675 avg /= tf->mpstat_gld[gld_index]->stop_seconds;
676 color = pick_cpu_color();
677 svg_line_graph(plot, tf->mpstat_gld[0], color, 0, 0);
678 svg_add_legend(plot, tf->label, " avg", color);
680 for (i = 1; i < tf->trace->mpstat_num_cpus + 1; i++) {
681 struct graph_line_data *gld = tf->mpstat_gld[i * MPSTAT_GRAPHS + gld_index];
684 for (gld_i = 0; gld_i < gld->stop_seconds; gld_i++) {
685 if (gld->data[i].count) {
686 this_avg += gld->data[i].sum /
691 this_avg /= gld->stop_seconds;
693 for (gld_i = 0; gld_i < gld->stop_seconds; gld_i++) {
696 if (gld->data[gld_i].count == 0)
698 val = (double)gld->data[gld_i].sum /
699 gld->data[gld_i].count;
701 if (this_avg > avg + 30 || val > 95) {
702 color = pick_cpu_color();
703 svg_line_graph(plot, gld, color, avg + 30, 95);
704 snprintf(line, line_len, " CPU %d\n", i - 1);
705 svg_add_legend(plot, tf->label, line, color);
714 if (plot->add_xlabel)
715 set_xlabel(plot, "Time (seconds)");
717 if (!plot->no_legend) {
718 svg_write_legend(plot);
719 svg_free_legend(plot);
722 total_graphs_written++;
725 static void plot_queue_depth(struct plot *plot, int seconds)
727 struct trace_file *tf;
729 if (active_graphs[QUEUE_DEPTH_GRAPH_INDEX] == 0)
733 set_plot_label(plot, "Queue Depth");
735 svg_alloc_legend(plot, num_traces);
737 tf = list_entry(all_traces.next, struct trace_file, list);
738 set_ylabel(plot, "Pending IO");
739 set_yticks(plot, 4, 0, tf->queue_depth_gld->max, "");
740 set_xticks(plot, num_xticks, 0, seconds);
742 list_for_each_entry(tf, &all_traces, list) {
743 svg_line_graph(plot, tf->queue_depth_gld, tf->read_color, 0, 0);
745 svg_add_legend(plot, tf->label, "", tf->read_color);
748 if (plot->add_xlabel)
749 set_xlabel(plot, "Time (seconds)");
751 svg_write_legend(plot);
753 total_graphs_written++;
756 static void convert_movie_files(char *movie_dir)
758 fprintf(stderr, "Converting svg files in %s\n", movie_dir);
759 snprintf(line, line_len, "find %s -name \\*.svg | xargs -I{} -n 1 -P 8 rsvg-convert -o {}.png {}",
764 static void mencode_movie(char *movie_dir)
766 fprintf(stderr, "Creating movie %s\n", movie_dir);
767 snprintf(line, line_len, "ffmpeg -r 20 -y -i %s/%%10d-%s.svg.png -b:v 250k "
768 "-vcodec libx264 %s", movie_dir, output_filename, output_filename);
772 static void cleanup_movie(char *movie_dir)
774 fprintf(stderr, "Removing movie dir %s\n", movie_dir);
775 snprintf(line, line_len, "rm %s/*", movie_dir);
778 snprintf(line, line_len, "rmdir %s", movie_dir);
782 static void plot_io_movie(struct plot *plot)
784 struct trace_file *tf;
785 char *movie_dir = create_movie_temp_dir();
787 struct plot_history *read_history;
788 struct plot_history *write_history;
791 int movie_frames_per_sec = 20;
792 int total_frames = movie_len * movie_frames_per_sec;
795 int graph_width_factor = 5;
798 get_graph_size(&cols, &rows);
799 batch_count = cols / total_frames;
801 if (batch_count == 0)
804 list_for_each_entry(tf, &all_traces, list) {
805 char *label = tf->label;
811 snprintf(line, line_len, "%s/%010d-%s.svg", movie_dir, i, output_filename);
812 set_plot_output(plot, line);
813 set_plot_title(plot, graph_title);
814 orig_y_offset = plot->start_y_offset;
818 set_graph_size(cols / graph_width_factor, rows / 8);
819 plot->timeline = i / graph_width_factor;
821 plot_tput(plot, tf->gdd_reads->seconds);
823 plot_cpu(plot, tf->gdd_reads->seconds,
824 "CPU System Time", CPU_SYS_GRAPH_INDEX, MPSTAT_SYS);
826 plot->direction = PLOT_ACROSS;
827 plot_queue_depth(plot, tf->gdd_reads->seconds);
829 /* movie graph starts here */
830 plot->start_y_offset = orig_y_offset;
831 set_graph_size(cols - cols / graph_width_factor, rows);
834 plot->direction = PLOT_DOWN;;
836 if (movie_style == MOVIE_SPINDLE)
837 setup_axis_spindle(plot);
841 svg_alloc_legend(plot, num_traces * 2);
843 read_history = alloc_plot_history(tf->read_color);
844 write_history = alloc_plot_history(tf->write_color);
845 read_history->col = i;
846 write_history->col = i;
848 if (tf->gdd_reads->total_ios)
849 svg_add_legend(plot, label, " Reads", tf->read_color);
850 if (tf->gdd_writes->total_ios)
851 svg_add_legend(plot, label, " Writes", tf->write_color);
854 while (i < cols && batch_i < batch_count) {
855 svg_io_graph_movie(tf->gdd_reads, read_history, i);
856 svg_io_graph_movie(tf->gdd_writes, write_history, i);
861 add_history(read_history, &movie_history_reads);
862 add_history(write_history, &movie_history_writes);
864 plot_movie_history(plot, &movie_history_reads);
865 plot_movie_history(plot, &movie_history_writes);
867 svg_write_legend(plot);
871 close_plot_file(plot);
873 free_all_plot_history(&movie_history_reads);
874 free_all_plot_history(&movie_history_writes);
876 convert_movie_files(movie_dir);
877 mencode_movie(movie_dir);
878 cleanup_movie(movie_dir);
882 static void plot_latency(struct plot *plot, int seconds)
884 struct trace_file *tf;
889 if (active_graphs[LATENCY_GRAPH_INDEX] == 0)
893 svg_alloc_legend(plot, num_traces);
894 list_for_each_entry(tf, &all_traces, list) {
895 if (tf->latency_gld->max > max)
896 max = tf->latency_gld->max;
898 list_for_each_entry(tf, &all_traces, list)
899 tf->latency_gld->max = max;
902 set_plot_label(plot, "IO Latency");
904 tf = list_entry(all_traces.next, struct trace_file, list);
906 scale_line_graph_time(&max, &units);
907 sprintf(line, "latency (%ss)", units);
908 set_ylabel(plot, line);
909 set_yticks(plot, 4, 0, max, "");
910 set_xticks(plot, num_xticks, 0, seconds);
912 list_for_each_entry(tf, &all_traces, list) {
913 svg_line_graph(plot, tf->latency_gld, tf->read_color, 0, 0);
915 svg_add_legend(plot, tf->label, "", tf->read_color);
918 if (plot->add_xlabel)
919 set_xlabel(plot, "Time (seconds)");
921 svg_write_legend(plot);
923 total_graphs_written++;
926 static void plot_iops(struct plot *plot, int seconds)
928 struct trace_file *tf;
932 if (active_graphs[IOPS_GRAPH_INDEX] == 0)
935 list_for_each_entry(tf, &all_traces, list) {
936 if (tf->iop_gld->max > max)
937 max = tf->iop_gld->max;
940 list_for_each_entry(tf, &all_traces, list)
941 tf->iop_gld->max = max;
944 set_plot_label(plot, "IOPs");
946 svg_alloc_legend(plot, num_traces);
948 tf = list_entry(all_traces.next, struct trace_file, list);
950 scale_line_graph_bytes(&max, &units, 1000);
951 set_ylabel(plot, "IO/s");
953 set_yticks(plot, 4, 0, max, units);
954 set_xticks(plot, num_xticks, 0, seconds);
956 list_for_each_entry(tf, &all_traces, list) {
957 svg_line_graph(plot, tf->iop_gld, tf->read_color, 0, 0);
959 svg_add_legend(plot, tf->label, "", tf->read_color);
962 if (plot->add_xlabel)
963 set_xlabel(plot, "Time (seconds)");
965 svg_write_legend(plot);
968 total_graphs_written++;
971 static void check_plot_columns(struct plot *plot, int index)
975 if (columns > 1 && (total_graphs_written == 0 ||
976 total_graphs_written % columns != 0)) {
977 count = graphs_left(index);
978 if (plot->direction == PLOT_DOWN) {
979 plot->start_x_offset = 0;
980 if (count <= columns)
981 plot->add_xlabel = 1;
983 plot->direction = PLOT_ACROSS;
986 plot->direction = PLOT_DOWN;
987 if (index == last_active_graph)
988 plot->add_xlabel = 1;
997 char *option_string = "T:t:o:l:r:O:N:d:p:m::h:w:c:";
998 static struct option long_options[] = {
999 {"columns", required_argument, 0, 'c'},
1000 {"title", required_argument, 0, 'T'},
1001 {"trace", required_argument, 0, 't'},
1002 {"output", required_argument, 0, 'o'},
1003 {"label", required_argument, 0, 'l'},
1004 {"rolling", required_argument, 0, 'r'},
1005 {"no-graph", required_argument, 0, 'N'},
1006 {"only-graph", required_argument, 0, 'O'},
1007 {"device", required_argument, 0, 'd'},
1008 {"prog", required_argument, 0, 'p'},
1009 {"movie", optional_argument, 0, 'm'},
1010 {"width", required_argument, 0, 'w'},
1011 {"height", required_argument, 0, 'h'},
1012 {"help", no_argument, 0, HELP_LONG_OPT},
1016 static void print_usage(void)
1018 fprintf(stderr, "iowatcher usage:\n"
1019 "\t-d (--device): device for blktrace to trace\n"
1020 "\t-t (--trace): trace file name (more than one allowed)\n"
1021 "\t-l (--label): trace label in the graph\n"
1022 "\t-o (--output): output file name (SVG only)\n"
1023 "\t-p (--prog): program to run while blktrace is run\n"
1024 "\t-m (--movie [=spindle|rect]): create IO animations\n"
1025 "\t-r (--rolling): number of seconds in the rolling averge\n"
1026 "\t-T (--title): graph title\n"
1027 "\t-N (--no-graph): skip a single graph (io, tput, latency, queue_depth, \n"
1028 "\t\t\tiops, cpu-sys, cpu-io, cpu-irq cpu-soft cpu-user)\n"
1029 "\t-O (--only-graph): add a single graph to the output\n"
1030 "\t-h (--height): set the height of each graph\n"
1031 "\t-w (--width): set the width of each graph\n"
1032 "\t-c (--columns): numbers of columns in graph output\n"
1037 static int parse_options(int ac, char **av)
1043 // int this_option_optind = optind ? optind : 1;
1044 int option_index = 0;
1046 c = getopt_long(ac, av, option_string,
1047 long_options, &option_index);
1054 graph_title = strdup(optarg);
1057 add_trace_file(optarg);
1058 set_blktrace_outfile(optarg);
1061 output_filename = strdup(optarg);
1064 set_trace_label(optarg);
1067 set_rolling_avg(atoi(optarg));
1071 disable_all_graphs();
1074 enable_one_graph(optarg);
1077 disable_one_graph(optarg);
1080 blktrace_device = strdup(optarg);
1083 program_to_run = strdup(optarg);
1088 movie_style = lookup_movie_style(optarg);
1089 if (movie_style < 0) {
1090 fprintf(stderr, "Unknown movie style %s\n", optarg);
1094 fprintf(stderr, "Using movie style: %s\n",
1095 movie_styles[movie_style]);
1098 opt_graph_height = atoi(optarg);
1101 opt_graph_width = atoi(optarg);
1104 columns = atoi(optarg);
1118 int main(int ac, char **av)
1123 struct trace_file *tf;
1127 init_io_hash_table();
1129 enable_all_graphs();
1131 parse_options(ac, av);
1133 last_active_graph = last_graph();
1135 set_io_graph_scale(256);
1136 if (movie_style == MOVIE_SPINDLE)
1137 set_graph_size(750, 550);
1139 set_graph_size(700, 400);
1142 * the plots in the movie don't have a seconds
1143 * line yet, this makes us skip it
1145 last_active_graph = TOTAL_GRAPHS + 1;
1147 if (opt_graph_height)
1148 set_graph_height(opt_graph_height);
1150 if (opt_graph_width)
1151 set_graph_width(opt_graph_width);
1153 if (list_empty(&all_traces)) {
1154 fprintf(stderr, "No traces found, exiting\n");
1158 if (blktrace_device) {
1159 ret = start_blktrace(blktrace_device, blktrace_outfile,
1162 fprintf(stderr, "exiting due to blktrace failure\n");
1165 start_mpstat(blktrace_outfile);
1166 if (program_to_run) {
1167 ret = run_program(program_to_run);
1169 fprintf(stderr, "failed to run %s\n",
1174 blktrace_to_dump(blktrace_outfile);
1176 /* no program specified, just wait for
1183 /* step one, read all the traces */
1186 /* step two, find the maxes for time and offset */
1187 list_for_each_entry(tf, &all_traces, list)
1188 compare_max_tf(tf, &seconds, &max_offset);
1190 /* push the max we found into all the tfs */
1191 set_all_max_tf(seconds, max_offset);
1193 /* alloc graphing structs for all the traces */
1194 setup_trace_file_graphs();
1196 /* run through all the traces and read their events */
1197 read_trace_events();
1199 plot = alloc_plot();
1202 plot_io_movie(plot);
1206 set_plot_output(plot, output_filename);
1208 if (active_graphs[IO_GRAPH_INDEX] || found_mpstat)
1209 set_legend_width(longest_label + strlen("writes"));
1210 else if (num_traces > 1)
1211 set_legend_width(longest_label);
1213 set_legend_width(0);
1215 get_graph_size(&cols, &rows);
1217 plot->add_xlabel = 1;
1218 set_plot_title(plot, graph_title);
1220 plot_io(plot, seconds, max_offset);
1221 plot->add_xlabel = 0;
1224 set_graph_size(cols / columns, rows);
1225 num_xticks /= columns;
1230 check_plot_columns(plot, TPUT_GRAPH_INDEX);
1231 plot_tput(plot, seconds);
1233 check_plot_columns(plot, CPU_IO_GRAPH_INDEX);
1234 plot_cpu(plot, seconds, "CPU IO Wait Time",
1235 CPU_IO_GRAPH_INDEX, MPSTAT_IO);
1237 check_plot_columns(plot, CPU_SYS_GRAPH_INDEX);
1238 plot_cpu(plot, seconds, "CPU System Time",
1239 CPU_SYS_GRAPH_INDEX, MPSTAT_SYS);
1241 check_plot_columns(plot, CPU_IRQ_GRAPH_INDEX);
1242 plot_cpu(plot, seconds, "CPU IRQ Time",
1243 CPU_IRQ_GRAPH_INDEX, MPSTAT_IRQ);
1245 check_plot_columns(plot, CPU_SOFT_GRAPH_INDEX);
1246 plot_cpu(plot, seconds, "CPU SoftIRQ Time",
1247 CPU_SOFT_GRAPH_INDEX, MPSTAT_SOFT);
1249 check_plot_columns(plot, CPU_USER_GRAPH_INDEX);
1250 plot_cpu(plot, seconds, "CPU User Time",
1251 CPU_USER_GRAPH_INDEX, MPSTAT_USER);
1253 check_plot_columns(plot, LATENCY_GRAPH_INDEX);
1254 plot_latency(plot, seconds);
1256 check_plot_columns(plot, QUEUE_DEPTH_GRAPH_INDEX);
1257 plot_queue_depth(plot, seconds);
1259 check_plot_columns(plot, IOPS_GRAPH_INDEX);
1260 plot_iops(plot, seconds);
1264 close_plot_file(plot);