*
* 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;
enum {
IO_GRAPH_INDEX = 0,
TPUT_GRAPH_INDEX,
+ FIO_GRAPH_INDEX,
CPU_SYS_GRAPH_INDEX,
CPU_IO_GRAPH_INDEX,
CPU_IRQ_GRAPH_INDEX,
static char *graphs_by_name[] = {
"io",
"tput",
+ "fio",
"cpu-sys",
"cpu-io",
"cpu-irq",
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)
{
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;
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));
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)
list_for_each_entry(tf, &all_traces, list) {
path = join_path(blktrace_dest_dir, tf->filename);
+
trace = open_trace(path);
if (!trace)
exit(1);
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);
tf->mpstat_max_seconds = trace->mpstat_seconds;
if (tf->mpstat_max_seconds)
found_mpstat = 1;
+
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;
+ }
}
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;
}
}
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) {
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);
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++;
static void set_all_minmax_tf(int min_seconds, 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)
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)
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)
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)
close_plot(plot);
}
-static void plot_tput(struct plot *plot, int min_seconds, int max_seconds)
+static void plot_tput(struct plot *plot, int min_seconds, int max_seconds,
+ int with_legend)
{
struct trace_file *tf;
char *units;
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");
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_fio_tput(struct plot *plot, int min_seconds, 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 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);
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);
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);
}
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'},
{"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'},
"\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"
add_trace_file(optarg);
set_blktrace_outfile(optarg);
break;
+ case 'F':
+ add_fio_trace_file(optarg);
+ break;
case 'o':
output_filename = strdup(optarg);
break;
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);
case 'p':
program_to_run = strdup(optarg);
break;
+ case 'K':
+ keep_movie_svgs = 1;
+ break;
case 'm':
make_movie = 1;
if (optarg) {
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;
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);
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) {
+ if (num_blktrace_devices) {
char *path;
- dest_mkdir();
+ 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);
- ret = start_blktrace(blktrace_device, blktrace_outfile,
- blktrace_dest_dir);
+ snprintf(line, line_len, "%s.dump", path);
+ unlink(line);
+
+ 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);
exit(1);
}
wait_for_tracers();
- blktrace_to_dump(path);
} else {
/* no program specified, just wait for
* blktrace to exit
/* 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);
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);
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",