2 * gfio - gui front end for fio - the flexible io tester
4 * Copyright (C) 2012 Stephen M. Cameron <stephenmcameron@gmail.com>
6 * The license below covers all files distributed with fio unless otherwise
7 * noted in the file itself.
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License version 2 as
11 * published by the Free Software Foundation.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 static void gfio_update_thread_status(char *status_message, double perc);
33 #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
35 typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
37 static void connect_clicked(GtkWidget *widget, gpointer data);
38 static void start_job_clicked(GtkWidget *widget, gpointer data);
40 static struct button_spec {
41 const char *buttontext;
43 const char *tooltiptext;
44 const int start_insensitive;
45 } buttonspeclist[] = {
46 #define CONNECT_BUTTON 0
47 #define START_JOB_BUTTON 1
48 { "Connect", connect_clicked, "Connect to host", 0 },
51 "Send current fio job to fio server to be executed", 1 },
73 GtkWidget *write_iops;
83 GtkWidget *bottomalign;
84 GtkWidget *thread_status_pb;
86 GtkWidget *button[ARRAYSIZE(buttonspeclist)];
87 GtkWidget *scrolled_window;
89 GtkWidget *error_info_bar;
90 GtkWidget *error_label;
91 GtkWidget *results_notebook;
92 GtkWidget *results_window;
94 struct probe_widget probe;
95 struct eta_widget eta;
99 struct fio_client *client;
104 static void clear_ui_info(struct gui *ui)
106 gtk_label_set_text(GTK_LABEL(ui->probe.hostname), "");
107 gtk_label_set_text(GTK_LABEL(ui->probe.os), "");
108 gtk_label_set_text(GTK_LABEL(ui->probe.arch), "");
109 gtk_label_set_text(GTK_LABEL(ui->probe.fio_ver), "");
110 gtk_entry_set_text(GTK_ENTRY(ui->eta.name), "");
111 gtk_entry_set_text(GTK_ENTRY(ui->eta.iotype), "");
112 gtk_entry_set_text(GTK_ENTRY(ui->eta.ioengine), "");
113 gtk_entry_set_text(GTK_ENTRY(ui->eta.iodepth), "");
114 gtk_entry_set_text(GTK_ENTRY(ui->eta.jobs), "");
115 gtk_entry_set_text(GTK_ENTRY(ui->eta.files), "");
116 gtk_entry_set_text(GTK_ENTRY(ui->eta.read_bw), "");
117 gtk_entry_set_text(GTK_ENTRY(ui->eta.read_iops), "");
118 gtk_entry_set_text(GTK_ENTRY(ui->eta.write_bw), "");
119 gtk_entry_set_text(GTK_ENTRY(ui->eta.write_iops), "");
122 static GtkWidget *new_info_entry_in_frame(GtkWidget *box, const char *label)
124 GtkWidget *entry, *frame;
126 frame = gtk_frame_new(label);
127 entry = gtk_entry_new();
128 gtk_entry_set_editable(GTK_ENTRY(entry), 0);
129 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
130 gtk_container_add(GTK_CONTAINER(frame), entry);
135 static GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label)
137 GtkWidget *label_widget;
140 frame = gtk_frame_new(label);
141 label_widget = gtk_label_new(NULL);
142 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
143 gtk_container_add(GTK_CONTAINER(frame), label_widget);
148 static GtkWidget *create_spinbutton(GtkWidget *hbox, double min, double max, double defval)
150 GtkWidget *button, *box;
152 box = gtk_hbox_new(FALSE, 3);
153 gtk_container_add(GTK_CONTAINER(hbox), box);
155 button = gtk_spin_button_new_with_range(min, max, 1.0);
156 gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
158 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
159 gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), defval);
164 static void gfio_set_connected(struct gui *ui, int connected)
167 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1);
169 gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Disconnect");
172 gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Connect");
173 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0);
177 static void label_set_int_value(GtkWidget *entry, unsigned int val)
181 sprintf(tmp, "%u", val);
182 gtk_label_set_text(GTK_LABEL(entry), tmp);
185 static void entry_set_int_value(GtkWidget *entry, unsigned int val)
189 sprintf(tmp, "%u", val);
190 gtk_entry_set_text(GTK_ENTRY(entry), tmp);
194 #define ALIGN_RIGHT 2
198 GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, unsigned int flags)
200 GtkCellRenderer *renderer;
201 GtkTreeViewColumn *col;
202 double xalign = 0.0; /* left as default */
203 PangoAlignment align;
206 align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT :
207 (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT :
209 visible = !(flags & INVISIBLE);
211 renderer = gtk_cell_renderer_text_new();
212 col = gtk_tree_view_column_new();
214 gtk_tree_view_column_set_title(col, title);
215 if (!(flags & UNSORTABLE))
216 gtk_tree_view_column_set_sort_column_id(col, index);
217 gtk_tree_view_column_set_resizable(col, TRUE);
218 gtk_tree_view_column_pack_start(col, renderer, TRUE);
219 gtk_tree_view_column_add_attribute(col, renderer, "text", index);
220 gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
222 case PANGO_ALIGN_LEFT:
225 case PANGO_ALIGN_CENTER:
228 case PANGO_ALIGN_RIGHT:
232 gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
233 gtk_tree_view_column_set_visible(col, visible);
234 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
238 static GtkWidget *gfio_output_clat_percentiles(unsigned int *ovals,
244 GType types[FIO_IO_U_LIST_MAX_LEN];
245 GtkWidget *tree_view;
246 GtkTreeSelection *selection;
251 for (i = 0; i < len; i++)
252 types[i] = G_TYPE_INT;
254 model = gtk_list_store_newv(len, types);
256 tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
257 gtk_widget_set_can_focus(tree_view, FALSE);
259 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
260 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
262 for (i = 0; i < len; i++) {
265 sprintf(fbuf, "%2.2f%%", plist[i].u.f);
266 tree_view_column(tree_view, i, fbuf, ALIGN_RIGHT | UNSORTABLE);
269 gtk_list_store_append(model, &iter);
271 for (i = 0; i < len; i++)
272 gtk_list_store_set(model, &iter, i, ovals[i], -1);
277 static void gfio_show_clat_percentiles(GtkWidget *vbox, struct thread_stat *ts,
280 unsigned int *io_u_plat = ts->io_u_plat[ddir];
281 unsigned long nr = ts->clat_stat[ddir].samples;
282 fio_fp64_t *plist = ts->percentile_list;
283 unsigned int *ovals, len, minv, maxv, scale_down;
285 GtkWidget *tree_view, *frame, *hbox;
288 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
293 * We default to usecs, but if the value range is such that we
294 * should scale down to msecs, do that.
296 if (minv > 2000 && maxv > 99999) {
304 tree_view = gfio_output_clat_percentiles(ovals, plist, len, base, scale_down);
306 sprintf(tmp, "Completion percentiles (%s)", base);
307 frame = gtk_frame_new(tmp);
308 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
310 hbox = gtk_hbox_new(FALSE, 3);
311 gtk_container_add(GTK_CONTAINER(frame), hbox);
313 gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3);
319 static void gfio_show_lat(GtkWidget *vbox, const char *name, unsigned long min,
320 unsigned long max, double mean, double dev)
322 const char *base = "(usec)";
323 GtkWidget *hbox, *label, *frame;
327 if (!usec_to_msec(&min, &max, &mean, &dev))
330 minp = num2str(min, 6, 1, 0);
331 maxp = num2str(max, 6, 1, 0);
333 sprintf(tmp, "%s %s", name, base);
334 frame = gtk_frame_new(tmp);
335 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
337 hbox = gtk_hbox_new(FALSE, 3);
338 gtk_container_add(GTK_CONTAINER(frame), hbox);
340 label = new_info_label_in_frame(hbox, "Minimum");
341 gtk_label_set_text(GTK_LABEL(label), minp);
342 label = new_info_label_in_frame(hbox, "Maximum");
343 gtk_label_set_text(GTK_LABEL(label), maxp);
344 label = new_info_label_in_frame(hbox, "Average");
345 sprintf(tmp, "%5.02f", mean);
346 gtk_label_set_text(GTK_LABEL(label), tmp);
347 label = new_info_label_in_frame(hbox, "Standard deviation");
348 sprintf(tmp, "%5.02f", dev);
349 gtk_label_set_text(GTK_LABEL(label), tmp);
360 static void gfio_show_ddir_status(GtkWidget *mbox, struct group_run_stats *rs,
361 struct thread_stat *ts, int ddir)
363 const char *ddir_label[2] = { "Read", "Write" };
364 GtkWidget *frame, *label, *box, *vbox, *main_vbox;
365 unsigned long min, max, runt;
366 unsigned long long bw, iops;
367 unsigned int flags = 0;
369 char *io_p, *bw_p, *iops_p;
372 if (!ts->runtime[ddir])
375 i2p = is_power_of_2(rs->kb_base);
376 runt = ts->runtime[ddir];
378 bw = (1000 * ts->io_bytes[ddir]) / runt;
379 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
380 bw_p = num2str(bw, 6, 1, i2p);
382 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
383 iops_p = num2str(iops, 6, 1, 0);
385 box = gtk_hbox_new(FALSE, 3);
386 gtk_box_pack_start(GTK_BOX(mbox), box, TRUE, FALSE, 3);
388 frame = gtk_frame_new(ddir_label[ddir]);
389 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 5);
391 main_vbox = gtk_vbox_new(FALSE, 3);
392 gtk_container_add(GTK_CONTAINER(frame), main_vbox);
394 box = gtk_hbox_new(FALSE, 3);
395 gtk_box_pack_start(GTK_BOX(main_vbox), box, TRUE, FALSE, 3);
397 label = new_info_label_in_frame(box, "IO");
398 gtk_label_set_text(GTK_LABEL(label), io_p);
399 label = new_info_label_in_frame(box, "Bandwidth");
400 gtk_label_set_text(GTK_LABEL(label), bw_p);
401 label = new_info_label_in_frame(box, "IOPS");
402 gtk_label_set_text(GTK_LABEL(label), iops_p);
403 label = new_info_label_in_frame(box, "Runtime (msec)");
404 label_set_int_value(label, ts->runtime[ddir]);
406 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
407 double p_of_agg = 100.0;
408 const char *bw_str = "KB";
412 p_of_agg = mean * 100 / (double) rs->agg[ddir];
413 if (p_of_agg > 100.0)
417 if (mean > 999999.9) {
425 sprintf(tmp, "Bandwidth (%s)", bw_str);
426 frame = gtk_frame_new(tmp);
427 gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 5);
429 box = gtk_hbox_new(FALSE, 3);
430 gtk_container_add(GTK_CONTAINER(frame), box);
432 label = new_info_label_in_frame(box, "Minimum");
433 label_set_int_value(label, min);
434 label = new_info_label_in_frame(box, "Maximum");
435 label_set_int_value(label, max);
436 label = new_info_label_in_frame(box, "Percentage of jobs");
437 sprintf(tmp, "%3.2f%%", p_of_agg);
438 gtk_label_set_text(GTK_LABEL(label), tmp);
439 label = new_info_label_in_frame(box, "Average");
440 sprintf(tmp, "%5.02f", mean);
441 gtk_label_set_text(GTK_LABEL(label), tmp);
442 label = new_info_label_in_frame(box, "Standard deviation");
443 sprintf(tmp, "%5.02f", dev);
444 gtk_label_set_text(GTK_LABEL(label), tmp);
447 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
449 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
451 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
455 frame = gtk_frame_new("Latency");
456 gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 5);
458 vbox = gtk_vbox_new(FALSE, 3);
459 gtk_container_add(GTK_CONTAINER(frame), vbox);
461 if (flags & GFIO_SLAT)
462 gfio_show_lat(vbox, "Submission latency", min, max, mean, dev);
463 if (flags & GFIO_CLAT)
464 gfio_show_lat(vbox, "Completion latency", min, max, mean, dev);
465 if (flags & GFIO_LAT)
466 gfio_show_lat(vbox, "Total latency", min, max, mean, dev);
469 if (ts->clat_percentiles)
470 gfio_show_clat_percentiles(main_vbox, ts, ddir);
478 static GtkWidget *gfio_output_lat_buckets(double *lat, unsigned int num,
481 GtkWidget *tree_view;
482 GtkTreeSelection *selection;
489 * Check if all are empty, in which case don't bother
491 for (i = 0, skipped = 0; i < num; i++)
498 types = malloc(num * sizeof(GType));
500 for (i = 0; i < num; i++)
501 types[i] = G_TYPE_STRING;
503 model = gtk_list_store_newv(num, types);
507 tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
508 gtk_widget_set_can_focus(tree_view, FALSE);
510 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
511 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
513 for (i = 0; i < num; i++)
514 tree_view_column(tree_view, i, labels[i], ALIGN_RIGHT | UNSORTABLE);
516 gtk_list_store_append(model, &iter);
518 for (i = 0; i < num; i++) {
522 sprintf(fbuf, "0.00");
524 sprintf(fbuf, "%3.2f%%", lat[i]);
526 gtk_list_store_set(model, &iter, i, fbuf, -1);
532 static void gfio_show_latency_buckets(GtkWidget *vbox, struct thread_stat *ts)
534 GtkWidget *box, *frame, *tree_view;
535 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
536 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
537 const char *uranges[] = { "2", "4", "10", "20", "50", "100",
538 "250", "500", "750", "1000", };
539 const char *mranges[] = { "2", "4", "10", "20", "50", "100",
540 "250", "500", "750", "1000", "2000",
543 stat_calc_lat_u(ts, io_u_lat_u);
544 stat_calc_lat_m(ts, io_u_lat_m);
546 tree_view = gfio_output_lat_buckets(io_u_lat_u, FIO_IO_U_LAT_U_NR, uranges);
548 frame = gtk_frame_new("Latency buckets (usec)");
549 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
551 box = gtk_hbox_new(FALSE, 3);
552 gtk_container_add(GTK_CONTAINER(frame), box);
553 gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, FALSE, 3);
556 tree_view = gfio_output_lat_buckets(io_u_lat_m, FIO_IO_U_LAT_M_NR, mranges);
558 frame = gtk_frame_new("Latency buckets (msec)");
559 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
561 box = gtk_hbox_new(FALSE, 3);
562 gtk_container_add(GTK_CONTAINER(frame), box);
563 gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, FALSE, 3);
567 static void gfio_show_cpu_usage(GtkWidget *vbox, struct thread_stat *ts)
569 GtkWidget *box, *frame, *entry;
570 double usr_cpu, sys_cpu;
571 unsigned long runtime;
574 runtime = ts->total_run_time;
576 double runt = (double) runtime;
578 usr_cpu = (double) ts->usr_time * 100 / runt;
579 sys_cpu = (double) ts->sys_time * 100 / runt;
585 frame = gtk_frame_new("OS resources");
586 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
588 box = gtk_hbox_new(FALSE, 3);
589 gtk_container_add(GTK_CONTAINER(frame), box);
591 entry = new_info_entry_in_frame(box, "User CPU");
592 sprintf(tmp, "%3.2f%%", usr_cpu);
593 gtk_entry_set_text(GTK_ENTRY(entry), tmp);
594 entry = new_info_entry_in_frame(box, "System CPU");
595 sprintf(tmp, "%3.2f%%", sys_cpu);
596 gtk_entry_set_text(GTK_ENTRY(entry), tmp);
597 entry = new_info_entry_in_frame(box, "Context switches");
598 entry_set_int_value(entry, ts->ctx);
599 entry = new_info_entry_in_frame(box, "Major faults");
600 entry_set_int_value(entry, ts->majf);
601 entry = new_info_entry_in_frame(box, "Minor faults");
602 entry_set_int_value(entry, ts->minf);
604 static void gfio_add_sc_depths_tree(GtkListStore *model,
605 struct thread_stat *ts, unsigned int len,
608 double io_u_dist[FIO_IO_U_MAP_NR];
610 /* Bits 0, and 3-8 */
611 const int add_mask = 0x1f9;
615 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
617 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
619 gtk_list_store_append(model, &iter);
621 gtk_list_store_set(model, &iter, 0, submit ? "Submit" : "Complete", -1);
623 for (i = 1, j = 0; i < len; i++) {
626 if (!(add_mask & (1UL << (i - 1))))
627 sprintf(fbuf, "0.0%%");
629 sprintf(fbuf, "%3.1f%%", io_u_dist[j]);
633 gtk_list_store_set(model, &iter, i, fbuf, -1);
638 static void gfio_add_total_depths_tree(GtkListStore *model,
639 struct thread_stat *ts, unsigned int len)
641 double io_u_dist[FIO_IO_U_MAP_NR];
643 /* Bits 1-6, and 8 */
644 const int add_mask = 0x17e;
647 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
649 gtk_list_store_append(model, &iter);
651 gtk_list_store_set(model, &iter, 0, "Total", -1);
653 for (i = 1, j = 0; i < len; i++) {
656 if (!(add_mask & (1UL << (i - 1))))
657 sprintf(fbuf, "0.0%%");
659 sprintf(fbuf, "%3.1f%%", io_u_dist[j]);
663 gtk_list_store_set(model, &iter, i, fbuf, -1);
668 static void gfio_show_io_depths(GtkWidget *vbox, struct thread_stat *ts)
670 GtkWidget *frame, *box, *tree_view;
671 GtkTreeSelection *selection;
673 GType types[FIO_IO_U_MAP_NR + 1];
676 const char *labels[NR_LABELS] = { "Depth", "0", "1", "2", "4", "8", "16", "32", "64", ">= 64" };
678 frame = gtk_frame_new("IO depths");
679 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
681 box = gtk_hbox_new(FALSE, 3);
682 gtk_container_add(GTK_CONTAINER(frame), box);
684 for (i = 0; i < NR_LABELS; i++)
685 types[i] = G_TYPE_STRING;
687 model = gtk_list_store_newv(NR_LABELS, types);
689 tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
690 gtk_widget_set_can_focus(tree_view, FALSE);
692 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
693 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
695 for (i = 0; i < NR_LABELS; i++)
696 tree_view_column(tree_view, i, labels[i], ALIGN_RIGHT | UNSORTABLE);
698 gfio_add_total_depths_tree(model, ts, NR_LABELS);
699 gfio_add_sc_depths_tree(model, ts, NR_LABELS, 1);
700 gfio_add_sc_depths_tree(model, ts, NR_LABELS, 0);
702 gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, FALSE, 3);
705 static gboolean results_window_delete(GtkWidget *w, gpointer data)
707 struct gui *ui = (struct gui *) data;
709 gtk_widget_destroy(w);
710 ui->results_window = NULL;
711 ui->results_notebook = NULL;
715 static GtkWidget *get_results_window(struct gui *ui)
717 GtkWidget *win, *notebook;
719 if (ui->results_window)
720 return ui->results_notebook;
722 win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
723 gtk_window_set_title(GTK_WINDOW(win), "Results");
724 g_signal_connect(win, "delete-event", G_CALLBACK(results_window_delete), ui);
725 g_signal_connect(win, "destroy", G_CALLBACK(results_window_delete), ui);
727 notebook = gtk_notebook_new();
728 gtk_container_add(GTK_CONTAINER(win), notebook);
730 ui->results_window = win;
731 ui->results_notebook = notebook;
732 return ui->results_notebook;
735 static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts,
736 struct group_run_stats *rs)
738 GtkWidget *res_win, *box, *vbox, *entry;
739 struct gui *ui = client->client_data;
743 res_win = get_results_window(ui);
745 vbox = gtk_vbox_new(FALSE, 3);
747 box = gtk_hbox_new(TRUE, 3);
748 gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
750 gtk_notebook_append_page(GTK_NOTEBOOK(res_win), vbox, gtk_label_new(ts->name));
752 entry = new_info_entry_in_frame(box, "Name");
753 gtk_entry_set_text(GTK_ENTRY(entry), ts->name);
754 if (strlen(ts->description)) {
755 entry = new_info_entry_in_frame(box, "Description");
756 gtk_entry_set_text(GTK_ENTRY(entry), ts->description);
758 entry = new_info_entry_in_frame(box, "Group ID");
759 entry_set_int_value(entry, ts->groupid);
760 entry = new_info_entry_in_frame(box, "Jobs");
761 entry_set_int_value(entry, ts->members);
762 entry = new_info_entry_in_frame(box, "Error");
763 entry_set_int_value(entry, ts->error);
764 entry = new_info_entry_in_frame(box, "PID");
765 entry_set_int_value(entry, ts->pid);
767 if (ts->io_bytes[DDIR_READ])
768 gfio_show_ddir_status(vbox, rs, ts, DDIR_READ);
769 if (ts->io_bytes[DDIR_WRITE])
770 gfio_show_ddir_status(vbox, rs, ts, DDIR_WRITE);
772 gfio_show_latency_buckets(vbox, ts);
773 gfio_show_cpu_usage(vbox, ts);
774 gfio_show_io_depths(vbox, ts);
776 gtk_widget_show_all(ui->results_window);
780 static void gfio_text_op(struct fio_client *client, struct fio_net_cmd *cmd)
783 GtkTextBuffer *buffer;
786 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui.textview));
788 gtk_text_buffer_get_end_iter(buffer, &end);
789 gtk_text_buffer_insert(buffer, &end, buf, -1);
791 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(ui.textview),
792 &end, 0.0, FALSE, 0.0,0.0);
794 fio_client_ops.text_op(client, cmd);
798 static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd)
801 printf("gfio_disk_util_op called\n");
802 fio_client_ops.disk_util(client, cmd);
806 extern int sum_stat_clients;
807 extern struct thread_stat client_ts;
808 extern struct group_run_stats client_gs;
810 static int sum_stat_nr;
812 static void gfio_thread_status_op(struct fio_client *client,
813 struct fio_net_cmd *cmd)
815 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
817 gfio_display_ts(client, &p->ts, &p->rs);
819 if (sum_stat_clients == 1)
822 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
823 sum_group_stats(&client_gs, &p->rs);
826 client_ts.groupid = p->ts.groupid;
828 if (++sum_stat_nr == sum_stat_clients) {
829 strcpy(client_ts.name, "All clients");
830 gfio_display_ts(client, &client_ts, &client_gs);
834 static void gfio_group_stats_op(struct fio_client *client,
835 struct fio_net_cmd *cmd)
838 printf("gfio_group_stats_op called\n");
839 fio_client_ops.group_stats(client, cmd);
843 static void gfio_update_eta(struct jobs_eta *je)
857 if (je->eta_sec != INT_MAX && je->elapsed_sec) {
858 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
859 eta_to_str(eta_str, je->eta_sec);
862 sprintf(tmp, "%u", je->nr_running);
863 gtk_entry_set_text(GTK_ENTRY(ui.eta.jobs), tmp);
864 sprintf(tmp, "%u", je->files_open);
865 gtk_entry_set_text(GTK_ENTRY(ui.eta.files), tmp);
868 if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
869 if (je->m_rate || je->t_rate) {
872 mr = num2str(je->m_rate, 4, 0, i2p);
873 tr = num2str(je->t_rate, 4, 0, i2p);
874 gtk_entry_set_text(GTK_ENTRY(ui.eta);
875 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
878 } else if (je->m_iops || je->t_iops)
879 p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
881 gtk_entry_set_text(GTK_ENTRY(ui.eta.cr_bw), "---");
882 gtk_entry_set_text(GTK_ENTRY(ui.eta.cr_iops), "---");
883 gtk_entry_set_text(GTK_ENTRY(ui.eta.cw_bw), "---");
884 gtk_entry_set_text(GTK_ENTRY(ui.eta.cw_iops), "---");
887 if (je->eta_sec != INT_MAX && je->nr_running) {
891 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
892 strcpy(output, "-.-% done");
896 sprintf(output, "%3.1f%% done", perc);
899 rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
900 rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
902 iops_str[0] = num2str(je->iops[0], 4, 1, 0);
903 iops_str[1] = num2str(je->iops[1], 4, 1, 0);
905 gtk_entry_set_text(GTK_ENTRY(ui.eta.read_bw), rate_str[0]);
906 gtk_entry_set_text(GTK_ENTRY(ui.eta.read_iops), iops_str[0]);
907 gtk_entry_set_text(GTK_ENTRY(ui.eta.write_bw), rate_str[1]);
908 gtk_entry_set_text(GTK_ENTRY(ui.eta.write_iops), iops_str[1]);
917 char *dst = output + strlen(output);
919 sprintf(dst, " - %s", eta_str);
922 gfio_update_thread_status(output, perc);
926 static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
928 struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
929 const char *os, *arch;
932 os = fio_get_os_string(probe->os);
936 arch = fio_get_arch_string(probe->arch);
941 client->name = strdup((char *) probe->hostname);
945 gtk_label_set_text(GTK_LABEL(ui.probe.hostname), (char *) probe->hostname);
946 gtk_label_set_text(GTK_LABEL(ui.probe.os), os);
947 gtk_label_set_text(GTK_LABEL(ui.probe.arch), arch);
948 sprintf(buf, "%u.%u.%u", probe->fio_major, probe->fio_minor, probe->fio_patch);
949 gtk_label_set_text(GTK_LABEL(ui.probe.fio_ver), buf);
954 static void gfio_update_thread_status(char *status_message, double perc)
956 static char message[100];
957 const char *m = message;
959 strncpy(message, status_message, sizeof(message) - 1);
960 gtk_progress_bar_set_text(
961 GTK_PROGRESS_BAR(ui.thread_status_pb), m);
962 gtk_progress_bar_set_fraction(
963 GTK_PROGRESS_BAR(ui.thread_status_pb), perc / 100.0);
964 gtk_widget_queue_draw(ui.window);
967 static void gfio_quit_op(struct fio_client *client)
969 struct gui *ui = client->client_data;
972 gfio_set_connected(ui, 0);
976 static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd)
978 struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload;
979 struct gui *ui = client->client_data;
983 p->iodepth = le32_to_cpu(p->iodepth);
984 p->rw = le32_to_cpu(p->rw);
986 for (i = 0; i < 2; i++) {
987 p->min_bs[i] = le32_to_cpu(p->min_bs[i]);
988 p->max_bs[i] = le32_to_cpu(p->max_bs[i]);
991 p->numjobs = le32_to_cpu(p->numjobs);
992 p->group_reporting = le32_to_cpu(p->group_reporting);
996 gtk_entry_set_text(GTK_ENTRY(ui->eta.name), (gchar *) p->jobname);
997 gtk_entry_set_text(GTK_ENTRY(ui->eta.iotype), ddir_str(p->rw));
998 gtk_entry_set_text(GTK_ENTRY(ui->eta.ioengine), (gchar *) p->ioengine);
1000 sprintf(tmp, "%u", p->iodepth);
1001 gtk_entry_set_text(GTK_ENTRY(ui->eta.iodepth), tmp);
1003 gdk_threads_leave();
1006 static void gfio_client_timed_out(struct fio_client *client)
1008 struct gui *ui = client->client_data;
1009 GtkWidget *dialog, *label, *content;
1012 gdk_threads_enter();
1014 gfio_set_connected(ui, 0);
1017 sprintf(buf, "Client %s: timeout talking to server.\n", client->hostname);
1019 dialog = gtk_dialog_new_with_buttons("Timed out!",
1020 GTK_WINDOW(ui->window),
1021 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
1022 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
1024 content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
1025 label = gtk_label_new((const gchar *) buf);
1026 gtk_container_add(GTK_CONTAINER(content), label);
1027 gtk_widget_show_all(dialog);
1028 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
1030 gtk_dialog_run(GTK_DIALOG(dialog));
1031 gtk_widget_destroy(dialog);
1033 gdk_threads_leave();
1036 struct client_ops gfio_client_ops = {
1037 .text_op = gfio_text_op,
1038 .disk_util = gfio_disk_util_op,
1039 .thread_status = gfio_thread_status_op,
1040 .group_stats = gfio_group_stats_op,
1041 .eta = gfio_update_eta,
1042 .probe = gfio_probe_op,
1043 .quit = gfio_quit_op,
1044 .add_job = gfio_add_job_op,
1045 .timed_out = gfio_client_timed_out,
1046 .stay_connected = 1,
1049 static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
1050 __attribute__((unused)) gpointer data)
1055 static void *job_thread(void *arg)
1057 fio_handle_clients(&gfio_client_ops);
1061 static int send_job_files(struct gui *ui)
1065 for (i = 0; i < ui->nr_job_files; i++) {
1066 ret = fio_clients_send_ini(ui->job_files[i]);
1070 free(ui->job_files[i]);
1071 ui->job_files[i] = NULL;
1073 while (i < ui->nr_job_files) {
1074 free(ui->job_files[i]);
1075 ui->job_files[i] = NULL;
1082 static void start_job_thread(struct gui *ui)
1084 if (send_job_files(ui)) {
1085 printf("Yeah, I didn't really like those options too much.\n");
1086 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1);
1091 static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
1094 struct gui *ui = data;
1096 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0);
1097 start_job_thread(ui);
1100 static void file_open(GtkWidget *w, gpointer data);
1102 static void connect_clicked(GtkWidget *widget, gpointer data)
1104 struct gui *ui = data;
1106 if (!ui->connected) {
1107 if (!ui->nr_job_files)
1108 file_open(widget, data);
1109 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No jobs running");
1110 fio_clients_connect();
1111 pthread_create(&ui->t, NULL, job_thread, NULL);
1112 gfio_set_connected(ui, 1);
1114 fio_clients_terminate();
1115 gfio_set_connected(ui, 0);
1120 static void add_button(struct gui *ui, int i, GtkWidget *buttonbox,
1121 struct button_spec *buttonspec)
1123 ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext);
1124 g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui);
1125 gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], FALSE, FALSE, 3);
1126 gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext);
1127 gtk_widget_set_sensitive(ui->button[i], !buttonspec->start_insensitive);
1130 static void add_buttons(struct gui *ui,
1131 struct button_spec *buttonlist,
1136 for (i = 0; i < nbuttons; i++)
1137 add_button(ui, i, ui->buttonbox, &buttonlist[i]);
1140 static void on_info_bar_response(GtkWidget *widget, gint response,
1143 if (response == GTK_RESPONSE_OK) {
1144 gtk_widget_destroy(widget);
1145 ui.error_info_bar = NULL;
1149 void report_error(GError *error)
1151 if (ui.error_info_bar == NULL) {
1152 ui.error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
1155 g_signal_connect(ui.error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL);
1156 gtk_info_bar_set_message_type(GTK_INFO_BAR(ui.error_info_bar),
1159 ui.error_label = gtk_label_new(error->message);
1160 GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui.error_info_bar));
1161 gtk_container_add(GTK_CONTAINER(container), ui.error_label);
1163 gtk_box_pack_start(GTK_BOX(ui.vbox), ui.error_info_bar, FALSE, FALSE, 0);
1164 gtk_widget_show_all(ui.vbox);
1167 snprintf(buffer, sizeof(buffer), "Failed to open file.");
1168 gtk_label_set(GTK_LABEL(ui.error_label), buffer);
1172 static int get_connection_details(char **host, int *port, int *type,
1175 GtkWidget *dialog, *box, *vbox, *hentry, *hbox, *frame, *pentry, *combo;
1179 dialog = gtk_dialog_new_with_buttons("Connection details",
1180 GTK_WINDOW(ui.window),
1181 GTK_DIALOG_DESTROY_WITH_PARENT,
1182 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1183 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
1185 frame = gtk_frame_new("Hostname / socket name");
1186 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
1187 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1189 box = gtk_vbox_new(FALSE, 6);
1190 gtk_container_add(GTK_CONTAINER(frame), box);
1192 hbox = gtk_hbox_new(TRUE, 10);
1193 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1194 hentry = gtk_entry_new();
1195 gtk_entry_set_text(GTK_ENTRY(hentry), "localhost");
1196 gtk_box_pack_start(GTK_BOX(hbox), hentry, TRUE, TRUE, 0);
1198 frame = gtk_frame_new("Port");
1199 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1200 box = gtk_vbox_new(FALSE, 10);
1201 gtk_container_add(GTK_CONTAINER(frame), box);
1203 hbox = gtk_hbox_new(TRUE, 4);
1204 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1205 pentry = create_spinbutton(hbox, 1, 65535, FIO_NET_PORT);
1207 frame = gtk_frame_new("Type");
1208 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1209 box = gtk_vbox_new(FALSE, 10);
1210 gtk_container_add(GTK_CONTAINER(frame), box);
1212 hbox = gtk_hbox_new(TRUE, 4);
1213 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1215 combo = gtk_combo_box_text_new();
1216 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "IPv4");
1217 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "IPv6");
1218 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "local socket");
1219 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
1221 gtk_container_add(GTK_CONTAINER(hbox), combo);
1223 frame = gtk_frame_new("Options");
1224 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1225 box = gtk_vbox_new(FALSE, 10);
1226 gtk_container_add(GTK_CONTAINER(frame), box);
1228 hbox = gtk_hbox_new(TRUE, 4);
1229 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1231 button = gtk_check_button_new_with_label("Auto-spawn fio backend");
1232 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), 1);
1233 gtk_widget_set_tooltip_text(button, "When running fio locally, it is necessary to have the backend running on the same system. If this is checked, gfio will start the backend automatically for you if it isn't already running.");
1234 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 6);
1236 gtk_widget_show_all(dialog);
1238 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
1239 gtk_widget_destroy(dialog);
1243 *host = strdup(gtk_entry_get_text(GTK_ENTRY(hentry)));
1244 *port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pentry));
1246 typeentry = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo));
1247 if (!typeentry || !strncmp(typeentry, "IPv4", 4))
1248 *type = Fio_client_ipv4;
1249 else if (!strncmp(typeentry, "IPv6", 4))
1250 *type = Fio_client_ipv6;
1252 *type = Fio_client_socket;
1255 *server_start = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
1257 gtk_widget_destroy(dialog);
1261 static void file_open(GtkWidget *w, gpointer data)
1264 GSList *filenames, *fn_glist;
1265 GtkFileFilter *filter;
1267 int port, type, server_start;
1269 dialog = gtk_file_chooser_dialog_new("Open File",
1270 GTK_WINDOW(ui.window),
1271 GTK_FILE_CHOOSER_ACTION_OPEN,
1272 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1273 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1275 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
1277 filter = gtk_file_filter_new();
1278 gtk_file_filter_add_pattern(filter, "*.fio");
1279 gtk_file_filter_add_pattern(filter, "*.job");
1280 gtk_file_filter_add_mime_type(filter, "text/fio");
1281 gtk_file_filter_set_name(filter, "Fio job file");
1282 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
1284 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
1285 gtk_widget_destroy(dialog);
1289 fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
1291 gtk_widget_destroy(dialog);
1293 if (get_connection_details(&host, &port, &type, &server_start))
1296 filenames = fn_glist;
1297 while (filenames != NULL) {
1298 ui.job_files = realloc(ui.job_files, (ui.nr_job_files + 1) * sizeof(char *));
1299 ui.job_files[ui.nr_job_files] = strdup(filenames->data);
1302 ui.client = fio_client_add_explicit(&gfio_client_ops, host, type, port);
1306 error = g_error_new(g_quark_from_string("fio"), 1,
1307 "Failed to add client %s", host);
1308 report_error(error);
1309 g_error_free(error);
1311 ui.client->client_data = &ui;
1313 g_free(filenames->data);
1314 filenames = g_slist_next(filenames);
1318 g_slist_free(fn_glist);
1321 static void file_save(GtkWidget *w, gpointer data)
1325 dialog = gtk_file_chooser_dialog_new("Save File",
1326 GTK_WINDOW(ui.window),
1327 GTK_FILE_CHOOSER_ACTION_SAVE,
1328 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1329 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1332 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
1333 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document");
1335 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1338 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
1339 // save_job_file(filename);
1342 gtk_widget_destroy(dialog);
1345 static void preferences(GtkWidget *w, gpointer data)
1347 GtkWidget *dialog, *frame, *box, **buttons;
1350 dialog = gtk_dialog_new_with_buttons("Preferences",
1351 GTK_WINDOW(ui.window),
1352 GTK_DIALOG_DESTROY_WITH_PARENT,
1353 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1354 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1357 frame = gtk_frame_new("Debug logging");
1358 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
1359 box = gtk_hbox_new(FALSE, 6);
1360 gtk_container_add(GTK_CONTAINER(frame), box);
1362 buttons = malloc(sizeof(GtkWidget *) * FD_DEBUG_MAX);
1364 for (i = 0; i < FD_DEBUG_MAX; i++) {
1365 buttons[i] = gtk_check_button_new_with_label(debug_levels[i].name);
1366 gtk_widget_set_tooltip_text(buttons[i], debug_levels[i].help);
1367 gtk_box_pack_start(GTK_BOX(box), buttons[i], FALSE, FALSE, 6);
1370 gtk_widget_show_all(dialog);
1372 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
1373 gtk_widget_destroy(dialog);
1377 for (i = 0; i < FD_DEBUG_MAX; i++) {
1380 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(buttons[i]));
1382 fio_debug |= (1UL << i);
1385 gtk_widget_destroy(dialog);
1388 static void about_dialog(GtkWidget *w, gpointer data)
1390 gtk_show_about_dialog(NULL,
1391 "program-name", "gfio",
1392 "comments", "Gtk2 UI for fio",
1394 "version", fio_version_string,
1395 "copyright", "Jens Axboe <axboe@kernel.dk> 2012",
1396 "logo-icon-name", "fio",
1402 static GtkActionEntry menu_items[] = {
1403 { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
1404 { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
1405 { "OpenFile", GTK_STOCK_OPEN, NULL, "<Control>O", NULL, G_CALLBACK(file_open) },
1406 { "SaveFile", GTK_STOCK_SAVE, NULL, "<Control>S", NULL, G_CALLBACK(file_save) },
1407 { "Preferences", GTK_STOCK_PREFERENCES, NULL, "<Control>p", NULL, G_CALLBACK(preferences) },
1408 { "Quit", GTK_STOCK_QUIT, NULL, "<Control>Q", NULL, G_CALLBACK(quit_clicked) },
1409 { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) },
1411 static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
1413 static const gchar *ui_string = " \
1415 <menubar name=\"MainMenu\"> \
1416 <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
1417 <menuitem name=\"Open\" action=\"OpenFile\" /> \
1418 <menuitem name=\"Save\" action=\"SaveFile\" /> \
1419 <separator name=\"Separator\"/> \
1420 <menuitem name=\"Preferences\" action=\"Preferences\" /> \
1421 <separator name=\"Separator2\"/> \
1422 <menuitem name=\"Quit\" action=\"Quit\" /> \
1424 <menu name=\"Help\" action=\"HelpMenuAction\"> \
1425 <menuitem name=\"About\" action=\"About\" /> \
1431 static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
1433 GtkActionGroup *action_group = gtk_action_group_new("Menu");
1436 action_group = gtk_action_group_new("Menu");
1437 gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
1439 gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
1440 gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
1442 gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
1443 return gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
1446 void gfio_ui_setup(GtkSettings *settings, GtkWidget *menubar,
1447 GtkWidget *vbox, GtkUIManager *ui_manager)
1449 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
1452 static void init_ui(int *argc, char **argv[], struct gui *ui)
1454 GtkSettings *settings;
1455 GtkUIManager *uimanager;
1456 GtkWidget *menu, *probe, *probe_frame, *probe_box;
1458 memset(ui, 0, sizeof(*ui));
1460 /* Magical g*thread incantation, you just need this thread stuff.
1461 * Without it, the update that happens in gfio_update_thread_status
1462 * doesn't really happen in a timely fashion, you need expose events
1464 if (!g_thread_supported())
1465 g_thread_init(NULL);
1468 gtk_init(argc, argv);
1469 settings = gtk_settings_get_default();
1470 gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "gfio setting");
1473 ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1474 gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
1475 gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500);
1477 g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), NULL);
1478 g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), NULL);
1480 ui->vbox = gtk_vbox_new(FALSE, 0);
1481 gtk_container_add(GTK_CONTAINER (ui->window), ui->vbox);
1483 uimanager = gtk_ui_manager_new();
1484 menu = get_menubar_menu(ui->window, uimanager);
1485 gfio_ui_setup(settings, menu, ui->vbox, uimanager);
1488 * Set up alignments for widgets at the top of ui,
1489 * align top left, expand horizontally but not vertically
1491 ui->topalign = gtk_alignment_new(0, 0, 1, 0);
1492 ui->topvbox = gtk_vbox_new(FALSE, 3);
1493 gtk_container_add(GTK_CONTAINER(ui->topalign), ui->topvbox);
1494 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->topalign, FALSE, FALSE, 0);
1496 probe = gtk_frame_new("Job");
1497 gtk_box_pack_start(GTK_BOX(ui->topvbox), probe, TRUE, FALSE, 3);
1498 probe_frame = gtk_vbox_new(FALSE, 3);
1499 gtk_container_add(GTK_CONTAINER(probe), probe_frame);
1501 probe_box = gtk_hbox_new(FALSE, 3);
1502 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
1503 ui->probe.hostname = new_info_label_in_frame(probe_box, "Host");
1504 ui->probe.os = new_info_label_in_frame(probe_box, "OS");
1505 ui->probe.arch = new_info_label_in_frame(probe_box, "Architecture");
1506 ui->probe.fio_ver = new_info_label_in_frame(probe_box, "Fio version");
1508 probe_box = gtk_hbox_new(FALSE, 3);
1509 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
1511 ui->eta.name = new_info_entry_in_frame(probe_box, "Name");
1512 ui->eta.iotype = new_info_entry_in_frame(probe_box, "IO");
1513 ui->eta.ioengine = new_info_entry_in_frame(probe_box, "IO Engine");
1514 ui->eta.iodepth = new_info_entry_in_frame(probe_box, "IO Depth");
1515 ui->eta.jobs = new_info_entry_in_frame(probe_box, "Jobs");
1516 ui->eta.files = new_info_entry_in_frame(probe_box, "Open files");
1518 probe_box = gtk_hbox_new(FALSE, 3);
1519 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
1520 ui->eta.read_bw = new_info_entry_in_frame(probe_box, "Read BW");
1521 ui->eta.read_iops = new_info_entry_in_frame(probe_box, "IOPS");
1522 ui->eta.write_bw = new_info_entry_in_frame(probe_box, "Write BW");
1523 ui->eta.write_iops = new_info_entry_in_frame(probe_box, "IOPS");
1526 * Only add this if we have a commit rate
1529 probe_box = gtk_hbox_new(FALSE, 3);
1530 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
1532 ui->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW");
1533 ui->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
1535 ui->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW");
1536 ui->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
1540 * Add a text box for text op messages
1542 ui->textview = gtk_text_view_new();
1543 ui->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui->textview));
1544 gtk_text_buffer_set_text(ui->text, "", -1);
1545 gtk_text_view_set_editable(GTK_TEXT_VIEW(ui->textview), FALSE);
1546 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(ui->textview), FALSE);
1547 ui->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
1548 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui->scrolled_window),
1549 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1550 gtk_container_add(GTK_CONTAINER(ui->scrolled_window), ui->textview);
1551 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->scrolled_window,
1555 * Set up alignments for widgets at the bottom of ui,
1556 * align bottom left, expand horizontally but not vertically
1558 ui->bottomalign = gtk_alignment_new(0, 1, 1, 0);
1559 ui->buttonbox = gtk_hbox_new(FALSE, 0);
1560 gtk_container_add(GTK_CONTAINER(ui->bottomalign), ui->buttonbox);
1561 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->bottomalign,
1564 add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist));
1567 * Set up thread status progress bar
1569 ui->thread_status_pb = gtk_progress_bar_new();
1570 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), 0.0);
1571 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No connections");
1572 gtk_container_add(GTK_CONTAINER(ui->buttonbox), ui->thread_status_pb);
1575 gtk_widget_show_all(ui->window);
1578 int main(int argc, char *argv[], char *envp[])
1580 if (initialize_fio(envp))
1582 if (fio_init_options())
1585 init_ui(&argc, &argv, &ui);
1587 gdk_threads_enter();
1589 gdk_threads_leave();