X-Git-Url: https://git.kernel.dk/?p=fio.git;a=blobdiff_plain;f=gfio.c;h=938515905673170d839bb9c835e4ed27684c7d44;hp=90d968aaab869f320d8710b9b0fa763ad59ec332;hb=0cf3ece062d6856bd79b89770780296c99937a98;hpb=814479d5805f49a5c44263c61848874a92dc1caf diff --git a/gfio.c b/gfio.c index 90d968aa..93851590 100644 --- a/gfio.c +++ b/gfio.c @@ -30,10 +30,11 @@ #include #include "fio.h" +#include "gfio.h" +#include "ghelpers.h" +#include "goptions.h" #include "graph.h" -#define GFIO_MIME "text/fio" - static int gfio_server_running; static const char *gfio_graph_font; static unsigned int gfio_graph_limit = 100; @@ -41,8 +42,6 @@ static GdkColor white; static void view_log(GtkWidget *w, gpointer data); -#define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0]))) - typedef void (*clickfunction)(GtkWidget *widget, gpointer data); static void connect_clicked(GtkWidget *widget, gpointer data); @@ -52,144 +51,32 @@ static void send_clicked(GtkWidget *widget, gpointer data); static struct button_spec { const char *buttontext; clickfunction f; - const char *tooltiptext; - const int start_insensitive; + const char *tooltiptext[2]; + const int start_sensitive; } buttonspeclist[] = { -#define CONNECT_BUTTON 0 -#define SEND_BUTTON 1 -#define START_JOB_BUTTON 2 - { "Connect", connect_clicked, "Connect to host", 0 }, - { "Send", send_clicked, "Send job description to host", 1 }, - { "Start Job", start_job_clicked, - "Start the current job on the server", 1 }, -}; - -struct probe_widget { - GtkWidget *hostname; - GtkWidget *os; - GtkWidget *arch; - GtkWidget *fio_ver; -}; - -struct multitext_widget { - GtkWidget *entry; - char **text; - unsigned int cur_text; - unsigned int max_text; -}; - -struct eta_widget { - GtkWidget *names; - struct multitext_widget iotype; - struct multitext_widget ioengine; - struct multitext_widget iodepth; - GtkWidget *jobs; - GtkWidget *files; - GtkWidget *read_bw; - GtkWidget *read_iops; - GtkWidget *cr_bw; - GtkWidget *cr_iops; - GtkWidget *write_bw; - GtkWidget *write_iops; - GtkWidget *cw_bw; - GtkWidget *cw_iops; -}; - -struct gfio_graphs { -#define DRAWING_AREA_XDIM 1000 -#define DRAWING_AREA_YDIM 400 - GtkWidget *drawing_area; - struct graph *iops_graph; - struct graph *bandwidth_graph; -}; - -/* - * Main window widgets and data - */ -struct gui { - GtkUIManager *uimanager; - GtkRecentManager *recentmanager; - GtkActionGroup *actiongroup; - guint recent_ui_id; - GtkWidget *menu; - GtkWidget *window; - GtkWidget *vbox; - GtkWidget *thread_status_pb; - GtkWidget *buttonbox; - GtkWidget *notebook; - GtkWidget *error_info_bar; - GtkWidget *error_label; - GtkListStore *log_model; - GtkWidget *log_tree; - GtkWidget *log_view; - struct gfio_graphs graphs; - struct probe_widget probe; - struct eta_widget eta; - pthread_t server_t; - - pthread_t t; - int handler_running; - - struct flist_head list; -} main_ui; - -enum { - GE_STATE_NEW = 1, - GE_STATE_CONNECTED, - GE_STATE_JOB_SENT, - GE_STATE_JOB_STARTED, - GE_STATE_JOB_RUNNING, - GE_STATE_JOB_DONE, -}; - -/* - * Notebook entry - */ -struct gui_entry { - struct flist_head list; - struct gui *ui; - - GtkWidget *vbox; - GtkWidget *job_notebook; - GtkWidget *thread_status_pb; - GtkWidget *buttonbox; - GtkWidget *button[ARRAYSIZE(buttonspeclist)]; - GtkWidget *notebook; - GtkWidget *error_info_bar; - GtkWidget *error_label; - GtkWidget *results_notebook; - GtkWidget *results_window; - GtkUIManager *results_uimanager; - GtkWidget *results_vbox; - GtkWidget *results_menu; - GtkListStore *log_model; - GtkWidget *log_tree; - GtkWidget *log_view; - struct gfio_graphs graphs; - struct probe_widget probe; - struct eta_widget eta; - GtkWidget *page_label; - gint page_num; - unsigned int state; - - struct gfio_client *client; - int nr_job_files; - char **job_files; -}; - -struct gfio_client { - struct gui_entry *ge; - struct fio_client *client; - GtkWidget *results_widget; - GtkWidget *disk_util_frame; - GtkWidget *err_entry; - unsigned int job_added; - struct thread_options o; + { + .buttontext = "Connect", + .f = connect_clicked, + .tooltiptext = { "Disconnect from host", "Connect to host" }, + .start_sensitive = 1, + }, + { + .buttontext = "Send", + .f = send_clicked, + .tooltiptext = { "Send job description to host", NULL }, + .start_sensitive = 0, + }, + { + .buttontext = "Start Job", + .f = start_job_clicked, + .tooltiptext = { "Start the current job on the server", NULL }, + .start_sensitive = 0, + }, }; static void gfio_update_thread_status(struct gui_entry *ge, char *status_message, double perc); -static void gfio_update_thread_status_all(char *status_message, double perc); -void report_error(GError *error); +static void gfio_update_thread_status_all(struct gui *ui, char *status_message, double perc); +static void report_error(struct gui_entry *ge, GError *error); static struct graph *setup_iops_graph(void) { @@ -230,54 +117,6 @@ static void setup_graphs(struct gfio_graphs *g) g->bandwidth_graph = setup_bandwidth_graph(); } -static void multitext_add_entry(struct multitext_widget *mt, const char *text) -{ - mt->text = realloc(mt->text, (mt->max_text + 1) * sizeof(char *)); - mt->text[mt->max_text] = strdup(text); - mt->max_text++; -} - -static void multitext_set_entry(struct multitext_widget *mt, unsigned int index) -{ - if (index >= mt->max_text) - return; - if (!mt->text || !mt->text[index]) - return; - - mt->cur_text = index; - gtk_entry_set_text(GTK_ENTRY(mt->entry), mt->text[index]); -} - -static void multitext_update_entry(struct multitext_widget *mt, - unsigned int index, const char *text) -{ - if (!mt->text) - return; - - if (mt->text[index]) - free(mt->text[index]); - - mt->text[index] = strdup(text); - if (mt->cur_text == index) - gtk_entry_set_text(GTK_ENTRY(mt->entry), mt->text[index]); -} - -static void multitext_free(struct multitext_widget *mt) -{ - int i; - - gtk_entry_set_text(GTK_ENTRY(mt->entry), ""); - - for (i = 0; i < mt->max_text; i++) { - if (mt->text[i]) - free(mt->text[i]); - } - - free(mt->text); - mt->cur_text = -1; - mt->max_text = 0; -} - static void clear_ge_ui_info(struct gui_entry *ge) { gtk_label_set_text(GTK_LABEL(ge->probe.hostname), ""); @@ -289,6 +128,7 @@ static void clear_ge_ui_info(struct gui_entry *ge) gtk_entry_set_text(GTK_ENTRY(ge->eta.name), ""); #endif multitext_update_entry(&ge->eta.iotype, 0, ""); + multitext_update_entry(&ge->eta.bs, 0, ""); multitext_update_entry(&ge->eta.ioengine, 0, ""); multitext_update_entry(&ge->eta.iodepth, 0, ""); gtk_entry_set_text(GTK_ENTRY(ge->eta.jobs), ""); @@ -299,92 +139,89 @@ static void clear_ge_ui_info(struct gui_entry *ge) gtk_entry_set_text(GTK_ENTRY(ge->eta.write_iops), ""); } -static GtkWidget *new_combo_entry_in_frame(GtkWidget *box, const char *label) +static void show_info_dialog(struct gui *ui, const char *title, + const char *message) { - GtkWidget *entry, *frame; + GtkWidget *dialog, *content, *label; - frame = gtk_frame_new(label); - entry = gtk_combo_box_new_text(); - gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3); - gtk_container_add(GTK_CONTAINER(frame), entry); + dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(ui->window), + GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, + GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); - return entry; + content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); + label = gtk_label_new(message); + gtk_container_add(GTK_CONTAINER(content), label); + gtk_widget_show_all(dialog); + gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); + gtk_dialog_run(GTK_DIALOG(dialog)); + gtk_widget_destroy(dialog); } -static GtkWidget *new_info_entry_in_frame(GtkWidget *box, const char *label) +static void set_menu_entry_text(struct gui *ui, const char *path, + const char *text) { - GtkWidget *entry, *frame; - - frame = gtk_frame_new(label); - entry = gtk_entry_new(); - gtk_entry_set_editable(GTK_ENTRY(entry), 0); - gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3); - gtk_container_add(GTK_CONTAINER(frame), entry); + GtkWidget *w; - return entry; + w = gtk_ui_manager_get_widget(ui->uimanager, path); + if (w) + gtk_menu_item_set_label(GTK_MENU_ITEM(w), text); + else + fprintf(stderr, "gfio: can't find path %s\n", path); } -static GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label) -{ - GtkWidget *label_widget; - GtkWidget *frame; - frame = gtk_frame_new(label); - label_widget = gtk_label_new(NULL); - gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3); - gtk_container_add(GTK_CONTAINER(frame), label_widget); +static void set_menu_entry_visible(struct gui *ui, const char *path, int show) +{ + GtkWidget *w; - return label_widget; + w = gtk_ui_manager_get_widget(ui->uimanager, path); + if (w) + gtk_widget_set_sensitive(w, show); + else + fprintf(stderr, "gfio: can't find path %s\n", path); } -static GtkWidget *create_spinbutton(GtkWidget *hbox, double min, double max, double defval) +static void set_job_menu_visible(struct gui *ui, int visible) { - GtkWidget *button, *box; - - box = gtk_hbox_new(FALSE, 3); - gtk_container_add(GTK_CONTAINER(hbox), box); - - button = gtk_spin_button_new_with_range(min, max, 1.0); - gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0); - - gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID); - gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), defval); + set_menu_entry_visible(ui, "/MainMenu/JobMenu", visible); +} - return button; +static void set_view_results_visible(struct gui *ui, int visible) +{ + set_menu_entry_visible(ui, "/MainMenu/ViewMenu/Results", visible); } -static void label_set_int_value(GtkWidget *entry, unsigned int val) +static const char *get_button_tooltip(struct button_spec *s, int sensitive) { - char tmp[80]; + if (s->tooltiptext[sensitive]) + return s->tooltiptext[sensitive]; - sprintf(tmp, "%u", val); - gtk_label_set_text(GTK_LABEL(entry), tmp); + return s->tooltiptext[0]; } -static void entry_set_int_value(GtkWidget *entry, unsigned int val) +static GtkWidget *add_button(GtkWidget *buttonbox, + struct button_spec *buttonspec, gpointer data) { - char tmp[80]; + GtkWidget *button = gtk_button_new_with_label(buttonspec->buttontext); + gboolean sens = buttonspec->start_sensitive; - sprintf(tmp, "%u", val); - gtk_entry_set_text(GTK_ENTRY(entry), tmp); + g_signal_connect(button, "clicked", G_CALLBACK(buttonspec->f), data); + gtk_box_pack_start(GTK_BOX(buttonbox), button, FALSE, FALSE, 3); + + sens = buttonspec->start_sensitive; + gtk_widget_set_tooltip_text(button, get_button_tooltip(buttonspec, sens)); + gtk_widget_set_sensitive(button, sens); + + return button; } -static void show_info_dialog(struct gui *ui, const char *title, - const char *message) +static void add_buttons(struct gui_entry *ge, struct button_spec *buttonlist, + int nbuttons) { - GtkWidget *dialog, *content, *label; - - dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(ui->window), - GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, - GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); + int i; - content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); - label = gtk_label_new(message); - gtk_container_add(GTK_CONTAINER(content), label); - gtk_widget_show_all(dialog); - gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); - gtk_dialog_run(GTK_DIALOG(dialog)); - gtk_widget_destroy(dialog); + for (i = 0; i < nbuttons; i++) + ge->button[i] = add_button(ge->buttonbox, &buttonlist[i], ge); } /* @@ -395,7 +232,6 @@ static void update_button_states(struct gui *ui, struct gui_entry *ge) { unsigned int connect_state, send_state, start_state, edit_state; const char *connect_str = NULL; - GtkWidget *w; switch (ge->state) { default: { @@ -408,21 +244,21 @@ static void update_button_states(struct gui *ui, struct gui_entry *ge) case GE_STATE_NEW: connect_state = 1; - edit_state = 0; + edit_state = 1; connect_str = "Connect"; send_state = 0; start_state = 0; break; case GE_STATE_CONNECTED: connect_state = 1; - edit_state = 0; + edit_state = 1; connect_str = "Disconnect"; send_state = 1; start_state = 0; break; case GE_STATE_JOB_SENT: connect_state = 1; - edit_state = 0; + edit_state = 1; connect_str = "Disconnect"; send_state = 0; start_state = 1; @@ -450,23 +286,23 @@ static void update_button_states(struct gui *ui, struct gui_entry *ge) break; } - gtk_widget_set_sensitive(ge->button[CONNECT_BUTTON], connect_state); - gtk_widget_set_sensitive(ge->button[SEND_BUTTON], send_state); - gtk_widget_set_sensitive(ge->button[START_JOB_BUTTON], start_state); - gtk_button_set_label(GTK_BUTTON(ge->button[CONNECT_BUTTON]), connect_str); - - w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Connect"); - gtk_widget_set_sensitive(w, connect_state); - gtk_menu_item_set_label(GTK_MENU_ITEM(w), connect_str); + gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_CONNECT], connect_state); + gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_SEND], send_state); + gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_START], start_state); + gtk_button_set_label(GTK_BUTTON(ge->button[GFIO_BUTTON_CONNECT]), connect_str); + gtk_widget_set_tooltip_text(ge->button[GFIO_BUTTON_CONNECT], get_button_tooltip(&buttonspeclist[GFIO_BUTTON_CONNECT], connect_state)); - w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Edit job"); - gtk_widget_set_sensitive(w, edit_state); + set_menu_entry_visible(ui, "/MainMenu/JobMenu/Connect", connect_state); + set_menu_entry_text(ui, "/MainMenu/JobMenu/Connect", connect_str); - w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Send job"); - gtk_widget_set_sensitive(w, send_state); + set_menu_entry_visible(ui, "/MainMenu/JobMenu/Edit job", edit_state); + set_menu_entry_visible(ui, "/MainMenu/JobMenu/Send job", send_state); + set_menu_entry_visible(ui, "/MainMenu/JobMenu/Start job", start_state); - w = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu/Start job"); - gtk_widget_set_sensitive(w, start_state); + if (ge->client && ge->client->nr_results) + set_view_results_visible(ui, 1); + else + set_view_results_visible(ui, 0); } static void gfio_set_state(struct gui_entry *ge, unsigned int state) @@ -475,51 +311,6 @@ static void gfio_set_state(struct gui_entry *ge, unsigned int state) update_button_states(ge->ui, ge); } -#define ALIGN_LEFT 1 -#define ALIGN_RIGHT 2 -#define INVISIBLE 4 -#define UNSORTABLE 8 - -GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, unsigned int flags) -{ - GtkCellRenderer *renderer; - GtkTreeViewColumn *col; - double xalign = 0.0; /* left as default */ - PangoAlignment align; - gboolean visible; - - align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT : - (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT : - PANGO_ALIGN_CENTER; - visible = !(flags & INVISIBLE); - - renderer = gtk_cell_renderer_text_new(); - col = gtk_tree_view_column_new(); - - gtk_tree_view_column_set_title(col, title); - if (!(flags & UNSORTABLE)) - gtk_tree_view_column_set_sort_column_id(col, index); - gtk_tree_view_column_set_resizable(col, TRUE); - gtk_tree_view_column_pack_start(col, renderer, TRUE); - gtk_tree_view_column_add_attribute(col, renderer, "text", index); - gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL); - switch (align) { - case PANGO_ALIGN_LEFT: - xalign = 0.0; - break; - case PANGO_ALIGN_CENTER: - xalign = 0.5; - break; - case PANGO_ALIGN_RIGHT: - xalign = 1.0; - break; - } - gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5); - gtk_tree_view_column_set_visible(col, visible); - gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col); - return col; -} - static void gfio_ui_setup_log(struct gui *ui) { GtkTreeSelection *selection; @@ -545,6 +336,30 @@ static void gfio_ui_setup_log(struct gui *ui) ui->log_tree = tree_view; } +static struct graph *setup_clat_graph(char *title, unsigned int *ovals, + fio_fp64_t *plist, + unsigned int len, + double xdim, double ydim) +{ + struct graph *g; + int i; + + g = graph_new(xdim, ydim, gfio_graph_font); + graph_title(g, title); + graph_x_title(g, "Percentile"); + graph_y_title(g, "Time"); + + for (i = 0; i < len; i++) { + char fbuf[8]; + + sprintf(fbuf, "%2.2f%%", plist[i].u.f); + graph_add_label(g, fbuf); + graph_add_data(g, fbuf, (double) ovals[i]); + } + + return g; +} + static GtkWidget *gfio_output_clat_percentiles(unsigned int *ovals, fio_fp64_t *plist, unsigned int len, @@ -590,7 +405,38 @@ static GtkWidget *gfio_output_clat_percentiles(unsigned int *ovals, return tree_view; } -static void gfio_show_clat_percentiles(GtkWidget *vbox, struct thread_stat *ts, +static int on_expose_lat_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p) +{ + struct graph *g = p; + cairo_t *cr; + + cr = gdk_cairo_create(w->window); +#if 0 + if (graph_has_tooltips(g)) { + g_object_set(w, "has-tooltip", TRUE, NULL); + g_signal_connect(w, "query-tooltip", G_CALLBACK(clat_graph_tooltip), g); + } +#endif + cairo_set_source_rgb(cr, 0, 0, 0); + bar_graph_draw(g, cr); + cairo_destroy(cr); + + return FALSE; +} + +static gint on_config_lat_drawing_area(GtkWidget *w, GdkEventConfigure *event, + gpointer data) +{ + struct graph *g = data; + + graph_set_size(g, w->allocation.width, w->allocation.height); + graph_set_size(g, w->allocation.width, w->allocation.height); + graph_set_position(g, 0, 0); + return TRUE; +} + +static void gfio_show_clat_percentiles(struct gfio_client *gc, + GtkWidget *vbox, struct thread_stat *ts, int ddir) { unsigned int *io_u_plat = ts->io_u_plat[ddir]; @@ -598,7 +444,8 @@ static void gfio_show_clat_percentiles(GtkWidget *vbox, struct thread_stat *ts, fio_fp64_t *plist = ts->percentile_list; unsigned int *ovals, len, minv, maxv, scale_down; const char *base; - GtkWidget *tree_view, *frame, *hbox; + GtkWidget *tree_view, *frame, *hbox, *drawing_area, *completion_vbox; + struct gui_entry *ge = gc->ge; char tmp[64]; len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv); @@ -617,14 +464,23 @@ static void gfio_show_clat_percentiles(GtkWidget *vbox, struct thread_stat *ts, base = "usec"; } + sprintf(tmp, "Completion percentiles (%s)", base); tree_view = gfio_output_clat_percentiles(ovals, plist, len, base, scale_down); + ge->clat_graph = setup_clat_graph(tmp, ovals, plist, len, 700.0, 300.0); - sprintf(tmp, "Completion percentiles (%s)", base); frame = gtk_frame_new(tmp); gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); + completion_vbox = gtk_vbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(frame), completion_vbox); hbox = gtk_hbox_new(FALSE, 3); - gtk_container_add(GTK_CONTAINER(frame), hbox); + gtk_container_add(GTK_CONTAINER(completion_vbox), hbox); + drawing_area = gtk_drawing_area_new(); + gtk_widget_set_size_request(GTK_WIDGET(drawing_area), 700, 300); + gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &white); + gtk_container_add(GTK_CONTAINER(completion_vbox), drawing_area); + g_signal_connect(G_OBJECT(drawing_area), "expose_event", G_CALLBACK(on_expose_lat_drawing_area), ge->clat_graph); + g_signal_connect(G_OBJECT(drawing_area), "configure_event", G_CALLBACK(on_config_lat_drawing_area), ge->clat_graph); gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3); out: @@ -673,7 +529,8 @@ static void gfio_show_lat(GtkWidget *vbox, const char *name, unsigned long min, #define GFIO_SLAT 2 #define GFIO_LAT 4 -static void gfio_show_ddir_status(GtkWidget *mbox, struct group_run_stats *rs, +static void gfio_show_ddir_status(struct gfio_client *gc, GtkWidget *mbox, + struct group_run_stats *rs, struct thread_stat *ts, int ddir) { const char *ddir_label[2] = { "Read", "Write" }; @@ -783,33 +640,43 @@ static void gfio_show_ddir_status(GtkWidget *mbox, struct group_run_stats *rs, } if (ts->clat_percentiles) - gfio_show_clat_percentiles(main_vbox, ts, ddir); - + gfio_show_clat_percentiles(gc, main_vbox, ts, ddir); free(io_p); free(bw_p); free(iops_p); } -static GtkWidget *gfio_output_lat_buckets(double *lat, unsigned int num, - const char **labels) +static struct graph *setup_lat_bucket_graph(const char *title, double *lat, + const char **labels, + unsigned int len, + double xdim, double ydim) +{ + struct graph *g; + int i; + + g = graph_new(xdim, ydim, gfio_graph_font); + graph_title(g, title); + graph_x_title(g, "Buckets"); + graph_y_title(g, "Percent"); + + for (i = 0; i < len; i++) { + graph_add_label(g, labels[i]); + graph_add_data(g, labels[i], lat[i]); + } + + return g; +} + +static GtkWidget *gfio_output_lat_buckets(double *lat, const char **labels, + int num) { GtkWidget *tree_view; GtkTreeSelection *selection; GtkListStore *model; GtkTreeIter iter; GType *types; - int i, skipped; - - /* - * Check if all are empty, in which case don't bother - */ - for (i = 0, skipped = 0; i < num; i++) - if (lat[i] <= 0.0) - skipped++; - - if (skipped == num) - return NULL; + int i; types = malloc(num * sizeof(GType)); @@ -848,39 +715,60 @@ static GtkWidget *gfio_output_lat_buckets(double *lat, unsigned int num, return tree_view; } -static void gfio_show_latency_buckets(GtkWidget *vbox, struct thread_stat *ts) +static void gfio_show_latency_buckets(struct gfio_client *gc, GtkWidget *vbox, + struct thread_stat *ts) { - GtkWidget *box, *frame, *tree_view; - double io_u_lat_u[FIO_IO_U_LAT_U_NR]; - double io_u_lat_m[FIO_IO_U_LAT_M_NR]; - const char *uranges[] = { "2", "4", "10", "20", "50", "100", - "250", "500", "750", "1000", }; - const char *mranges[] = { "2", "4", "10", "20", "50", "100", - "250", "500", "750", "1000", "2000", - ">= 2000", }; + double io_u_lat[FIO_IO_U_LAT_U_NR + FIO_IO_U_LAT_M_NR]; + const char *ranges[] = { "2u", "4u", "10u", "20u", "50u", "100u", + "250u", "500u", "750u", "1m", "2m", + "4m", "10m", "20m", "50m", "100m", + "250m", "500m", "750m", "1s", "2s", ">= 2s" }; + int start, end, i; + const int total = FIO_IO_U_LAT_U_NR + FIO_IO_U_LAT_M_NR; + GtkWidget *frame, *tree_view, *hbox, *completion_vbox, *drawing_area; + struct gui_entry *ge = gc->ge; - stat_calc_lat_u(ts, io_u_lat_u); - stat_calc_lat_m(ts, io_u_lat_m); + stat_calc_lat_u(ts, io_u_lat); + stat_calc_lat_m(ts, &io_u_lat[FIO_IO_U_LAT_U_NR]); - tree_view = gfio_output_lat_buckets(io_u_lat_u, FIO_IO_U_LAT_U_NR, uranges); - if (tree_view) { - frame = gtk_frame_new("Latency buckets (usec)"); - gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); + /* + * Found out which first bucket has entries, and which last bucket + */ + start = end = -1U; + for (i = 0; i < total; i++) { + if (io_u_lat[i] == 0.00) + continue; - box = gtk_hbox_new(FALSE, 3); - gtk_container_add(GTK_CONTAINER(frame), box); - gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, FALSE, 3); + if (start == -1U) + start = i; + end = i; } - tree_view = gfio_output_lat_buckets(io_u_lat_m, FIO_IO_U_LAT_M_NR, mranges); - if (tree_view) { - frame = gtk_frame_new("Latency buckets (msec)"); - gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); + /* + * No entries... + */ + if (start == -1U) + return; + + tree_view = gfio_output_lat_buckets(&io_u_lat[start], &ranges[start], end - start + 1); + ge->lat_bucket_graph = setup_lat_bucket_graph("Latency Buckets", &io_u_lat[start], &ranges[start], end - start + 1, 700.0, 300.0); - box = gtk_hbox_new(FALSE, 3); - gtk_container_add(GTK_CONTAINER(frame), box); - gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, FALSE, 3); - } + frame = gtk_frame_new("Latency buckets"); + gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); + + completion_vbox = gtk_vbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(frame), completion_vbox); + hbox = gtk_hbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(completion_vbox), hbox); + + drawing_area = gtk_drawing_area_new(); + gtk_widget_set_size_request(GTK_WIDGET(drawing_area), 700, 300); + gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &white); + gtk_container_add(GTK_CONTAINER(completion_vbox), drawing_area); + g_signal_connect(G_OBJECT(drawing_area), "expose_event", G_CALLBACK(on_expose_lat_drawing_area), ge->lat_bucket_graph); + g_signal_connect(G_OBJECT(drawing_area), "configure_event", G_CALLBACK(on_config_lat_drawing_area), ge->lat_bucket_graph); + + gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3); } static void gfio_show_cpu_usage(GtkWidget *vbox, struct thread_stat *ts) @@ -986,13 +874,13 @@ static void gfio_add_total_depths_tree(GtkListStore *model, static void gfio_show_io_depths(GtkWidget *vbox, struct thread_stat *ts) { - GtkWidget *frame, *box, *tree_view; + GtkWidget *frame, *box, *tree_view = NULL; GtkTreeSelection *selection; GtkListStore *model; GType types[FIO_IO_U_MAP_NR + 1]; int i; -#define NR_LABELS 10 - const char *labels[NR_LABELS] = { "Depth", "0", "1", "2", "4", "8", "16", "32", "64", ">= 64" }; + const char *labels[] = { "Depth", "0", "1", "2", "4", "8", "16", "32", "64", ">= 64" }; + const int nr_labels = ARRAYSIZE(labels); frame = gtk_frame_new("IO depths"); gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); @@ -1000,10 +888,10 @@ static void gfio_show_io_depths(GtkWidget *vbox, struct thread_stat *ts) box = gtk_hbox_new(FALSE, 3); gtk_container_add(GTK_CONTAINER(frame), box); - for (i = 0; i < NR_LABELS; i++) + for (i = 0; i < nr_labels; i++) types[i] = G_TYPE_STRING; - model = gtk_list_store_newv(NR_LABELS, types); + model = gtk_list_store_newv(nr_labels, types); tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model)); gtk_widget_set_can_focus(tree_view, FALSE); @@ -1014,12 +902,12 @@ static void gfio_show_io_depths(GtkWidget *vbox, struct thread_stat *ts) selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view)); gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE); - for (i = 0; i < NR_LABELS; i++) + for (i = 0; i < nr_labels; i++) tree_view_column(tree_view, i, labels[i], ALIGN_RIGHT | UNSORTABLE); - gfio_add_total_depths_tree(model, ts, NR_LABELS); - gfio_add_sc_depths_tree(model, ts, NR_LABELS, 1); - gfio_add_sc_depths_tree(model, ts, NR_LABELS, 0); + gfio_add_total_depths_tree(model, ts, nr_labels); + gfio_add_sc_depths_tree(model, ts, nr_labels, 1); + gfio_add_sc_depths_tree(model, ts, nr_labels, 0); gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, FALSE, 3); } @@ -1109,107 +997,59 @@ static GtkWidget *get_results_window(struct gui_entry *ge) return ge->results_notebook; } -static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts, - struct group_run_stats *rs) +static void disk_util_destroy(GtkWidget *w, gpointer data) { - GtkWidget *res_win, *box, *vbox, *entry, *scroll; - struct gfio_client *gc = client->client_data; + struct gui_entry *ge = (struct gui_entry *) data; - gdk_threads_enter(); + ge->disk_util_vbox = NULL; + gtk_widget_destroy(w); +} - res_win = get_results_window(gc->ge); +static GtkWidget *get_scrolled_window(gint border_width) +{ + GtkWidget *scroll; scroll = gtk_scrolled_window_new(NULL, NULL); - gtk_container_set_border_width(GTK_CONTAINER(scroll), 5); + gtk_container_set_border_width(GTK_CONTAINER(scroll), border_width); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); - vbox = gtk_vbox_new(FALSE, 3); - - box = gtk_hbox_new(FALSE, 0); - gtk_box_pack_start(GTK_BOX(vbox), box, TRUE, FALSE, 5); - - gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox); - - gtk_notebook_append_page(GTK_NOTEBOOK(res_win), scroll, gtk_label_new(ts->name)); - - gc->results_widget = vbox; - - entry = new_info_entry_in_frame(box, "Name"); - gtk_entry_set_text(GTK_ENTRY(entry), ts->name); - if (strlen(ts->description)) { - entry = new_info_entry_in_frame(box, "Description"); - gtk_entry_set_text(GTK_ENTRY(entry), ts->description); - } - entry = new_info_entry_in_frame(box, "Group ID"); - entry_set_int_value(entry, ts->groupid); - entry = new_info_entry_in_frame(box, "Jobs"); - entry_set_int_value(entry, ts->members); - gc->err_entry = entry = new_info_entry_in_frame(box, "Error"); - entry_set_int_value(entry, ts->error); - entry = new_info_entry_in_frame(box, "PID"); - entry_set_int_value(entry, ts->pid); - - if (ts->io_bytes[DDIR_READ]) - gfio_show_ddir_status(vbox, rs, ts, DDIR_READ); - if (ts->io_bytes[DDIR_WRITE]) - gfio_show_ddir_status(vbox, rs, ts, DDIR_WRITE); - - gfio_show_latency_buckets(vbox, ts); - gfio_show_cpu_usage(vbox, ts); - gfio_show_io_depths(vbox, ts); - - gtk_widget_show_all(gc->ge->results_window); - gdk_threads_leave(); + return scroll; } -static void gfio_text_op(struct fio_client *client, struct fio_net_cmd *cmd) +static GtkWidget *gfio_disk_util_get_vbox(struct gui_entry *ge) { - struct cmd_text_pdu *p = (struct cmd_text_pdu *) cmd->payload; - struct gui *ui = &main_ui; - GtkTreeIter iter; - struct tm *tm; - time_t sec; - char tmp[64], timebuf[80]; + GtkWidget *vbox, *box, *scroll, *res_notebook; - sec = p->log_sec; - tm = localtime(&sec); - strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", tm); - sprintf(timebuf, "%s.%03ld", tmp, p->log_usec / 1000); + if (ge->disk_util_vbox) + return ge->disk_util_vbox; - gdk_threads_enter(); + scroll = get_scrolled_window(5); + vbox = gtk_vbox_new(FALSE, 3); + box = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5); - gtk_list_store_append(ui->log_model, &iter); - gtk_list_store_set(ui->log_model, &iter, 0, timebuf, -1); - gtk_list_store_set(ui->log_model, &iter, 1, client->hostname, -1); - gtk_list_store_set(ui->log_model, &iter, 2, p->level, -1); - gtk_list_store_set(ui->log_model, &iter, 3, p->buf, -1); + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox); + res_notebook = get_results_window(ge); - if (p->level == FIO_LOG_ERR) - view_log(NULL, (gpointer) ui); + gtk_notebook_append_page(GTK_NOTEBOOK(res_notebook), scroll, gtk_label_new("Disk utilization")); + ge->disk_util_vbox = box; + g_signal_connect(vbox, "destroy", G_CALLBACK(disk_util_destroy), ge); - gdk_threads_leave(); + return ge->disk_util_vbox; } -static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd) +static int __gfio_disk_util_show(GtkWidget *res_notebook, + struct gfio_client *gc, struct cmd_du_pdu *p) { - struct cmd_du_pdu *p = (struct cmd_du_pdu *) cmd->payload; - struct gfio_client *gc = client->client_data; - GtkWidget *box, *frame, *entry, *vbox; + GtkWidget *box, *frame, *entry, *vbox, *util_vbox; + struct gui_entry *ge = gc->ge; double util; char tmp[16]; - gdk_threads_enter(); - - if (!gc->results_widget) - goto out; - - if (!gc->disk_util_frame) { - gc->disk_util_frame = gtk_frame_new("Disk utilization"); - gtk_box_pack_start(GTK_BOX(gc->results_widget), gc->disk_util_frame, FALSE, FALSE, 5); - } + util_vbox = gfio_disk_util_get_vbox(ge); vbox = gtk_vbox_new(FALSE, 3); - gtk_container_add(GTK_CONTAINER(gc->disk_util_frame), vbox); + gtk_container_add(GTK_CONTAINER(util_vbox), vbox); frame = gtk_frame_new((char *) p->dus.name); gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 2); @@ -1262,8 +1102,166 @@ static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd entry = new_info_entry_in_frame(vbox, "Disk utilization"); gtk_entry_set_text(GTK_ENTRY(entry), tmp); - gtk_widget_show_all(gc->results_widget); -out: + gtk_widget_show_all(ge->results_window); + return 0; +} + +static int gfio_disk_util_show(struct gfio_client *gc) +{ + struct gui_entry *ge = gc->ge; + GtkWidget *res_notebook; + int i; + + if (!gc->nr_du) + return 1; + + res_notebook = get_results_window(ge); + + for (i = 0; i < gc->nr_du; i++) { + struct cmd_du_pdu *p = &gc->du[i]; + + __gfio_disk_util_show(res_notebook, gc, p); + } + + gtk_widget_show_all(ge->results_window); + return 0; +} + +static void gfio_add_end_results(struct gfio_client *gc, struct thread_stat *ts, + struct group_run_stats *rs) +{ + unsigned int nr = gc->nr_results; + + gc->results = realloc(gc->results, (nr + 1) * sizeof(struct end_results)); + memcpy(&gc->results[nr].ts, ts, sizeof(*ts)); + memcpy(&gc->results[nr].gs, rs, sizeof(*rs)); + gc->nr_results++; +} + +static void __gfio_display_end_results(GtkWidget *win, struct gfio_client *gc, + struct thread_stat *ts, + struct group_run_stats *rs) +{ + GtkWidget *box, *vbox, *entry, *scroll; + + scroll = gtk_scrolled_window_new(NULL, NULL); + gtk_container_set_border_width(GTK_CONTAINER(scroll), 5); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + + vbox = gtk_vbox_new(FALSE, 3); + + box = gtk_hbox_new(FALSE, 0); + gtk_box_pack_start(GTK_BOX(vbox), box, TRUE, FALSE, 5); + + gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox); + + gtk_notebook_append_page(GTK_NOTEBOOK(win), scroll, gtk_label_new(ts->name)); + + entry = new_info_entry_in_frame(box, "Name"); + gtk_entry_set_text(GTK_ENTRY(entry), ts->name); + if (strlen(ts->description)) { + entry = new_info_entry_in_frame(box, "Description"); + gtk_entry_set_text(GTK_ENTRY(entry), ts->description); + } + entry = new_info_entry_in_frame(box, "Group ID"); + entry_set_int_value(entry, ts->groupid); + entry = new_info_entry_in_frame(box, "Jobs"); + entry_set_int_value(entry, ts->members); + gc->err_entry = entry = new_info_entry_in_frame(box, "Error"); + entry_set_int_value(entry, ts->error); + entry = new_info_entry_in_frame(box, "PID"); + entry_set_int_value(entry, ts->pid); + + if (ts->io_bytes[DDIR_READ]) + gfio_show_ddir_status(gc, vbox, rs, ts, DDIR_READ); + if (ts->io_bytes[DDIR_WRITE]) + gfio_show_ddir_status(gc, vbox, rs, ts, DDIR_WRITE); + + gfio_show_latency_buckets(gc, vbox, ts); + gfio_show_cpu_usage(vbox, ts); + gfio_show_io_depths(vbox, ts); +} + +static void gfio_display_end_results(struct gfio_client *gc) +{ + struct gui_entry *ge = gc->ge; + GtkWidget *res_notebook; + int i; + + res_notebook = get_results_window(ge); + + for (i = 0; i < gc->nr_results; i++) { + struct end_results *e = &gc->results[i]; + + __gfio_display_end_results(res_notebook, gc, &e->ts, &e->gs); + } + + if (gfio_disk_util_show(gc)) + gtk_widget_show_all(ge->results_window); +} + +static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts, + struct group_run_stats *rs) +{ + struct gfio_client *gc = client->client_data; + struct gui_entry *ge = gc->ge; + + gfio_add_end_results(gc, ts, rs); + + gdk_threads_enter(); + if (ge->results_window) + __gfio_display_end_results(ge->results_notebook, gc, ts, rs); + else + gfio_display_end_results(gc); + gdk_threads_leave(); +} + +static void gfio_text_op(struct fio_client *client, struct fio_net_cmd *cmd) +{ + struct cmd_text_pdu *p = (struct cmd_text_pdu *) cmd->payload; + struct gfio_client *gc = client->client_data; + struct gui_entry *ge = gc->ge; + struct gui *ui = ge->ui; + GtkTreeIter iter; + struct tm *tm; + time_t sec; + char tmp[64], timebuf[80]; + + sec = p->log_sec; + tm = localtime(&sec); + strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", tm); + sprintf(timebuf, "%s.%03ld", tmp, p->log_usec / 1000); + + gdk_threads_enter(); + + gtk_list_store_append(ui->log_model, &iter); + gtk_list_store_set(ui->log_model, &iter, 0, timebuf, -1); + gtk_list_store_set(ui->log_model, &iter, 1, client->hostname, -1); + gtk_list_store_set(ui->log_model, &iter, 2, p->level, -1); + gtk_list_store_set(ui->log_model, &iter, 3, p->buf, -1); + + if (p->level == FIO_LOG_ERR) + view_log(NULL, (gpointer) ui); + + gdk_threads_leave(); +} + +static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd) +{ + struct cmd_du_pdu *p = (struct cmd_du_pdu *) cmd->payload; + struct gfio_client *gc = client->client_data; + struct gui_entry *ge = gc->ge; + unsigned int nr = gc->nr_du; + + gc->du = realloc(gc->du, (nr + 1) * sizeof(struct cmd_du_pdu)); + memcpy(&gc->du[nr], p, sizeof(*p)); + gc->nr_du++; + + gdk_threads_enter(); + if (ge->results_window) + __gfio_disk_util_show(ge->results_notebook, gc, p); + else + gfio_disk_util_show(gc); gdk_threads_leave(); } @@ -1287,6 +1285,7 @@ static void gfio_thread_status_op(struct fio_client *client, sum_group_stats(&client_gs, &p->rs); client_ts.members++; + client_ts.thread_number = p->ts.thread_number; client_ts.groupid = p->ts.groupid; if (++sum_stat_nr == sum_stat_clients) { @@ -1537,7 +1536,7 @@ static void gfio_update_all_eta(struct jobs_eta *je) sprintf(dst, " - %s", eta_str); } - gfio_update_thread_status_all(output, perc); + gfio_update_thread_status_all(ui, output, perc); gdk_threads_leave(); } @@ -1582,12 +1581,12 @@ static void gfio_update_thread_status(struct gui_entry *ge, strncpy(message, status_message, sizeof(message) - 1); gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), m); gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), perc / 100.0); - gtk_widget_queue_draw(main_ui.window); + gtk_widget_queue_draw(ge->ui->window); } -static void gfio_update_thread_status_all(char *status_message, double perc) +static void gfio_update_thread_status_all(struct gui *ui, char *status_message, + double perc) { - struct gui *ui = &main_ui; static char message[100]; const char *m = message; @@ -1612,8 +1611,11 @@ static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd) struct gfio_client *gc = client->client_data; struct thread_options *o = &gc->o; struct gui_entry *ge = gc->ge; - char tmp[8]; + char *c1, *c2, *c3, *c4; + char tmp[80]; + p->thread_number = le32_to_cpu(p->thread_number); + p->groupid = le32_to_cpu(p->groupid); convert_thread_options_to_cpu(o, &p->top); gdk_threads_enter(); @@ -1623,18 +1625,30 @@ static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd) gtk_combo_box_append_text(GTK_COMBO_BOX(ge->eta.names), (gchar *) o->name); gtk_combo_box_set_active(GTK_COMBO_BOX(ge->eta.names), 0); - multitext_add_entry(&ge->eta.iotype, ddir_str(o->td_ddir)); + sprintf(tmp, "%s %s", o->odirect ? "direct" : "buffered", ddir_str(o->td_ddir)); + multitext_add_entry(&ge->eta.iotype, tmp); + + c1 = fio_uint_to_kmg(o->min_bs[DDIR_READ]); + c2 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]); + c3 = fio_uint_to_kmg(o->min_bs[DDIR_READ]); + c4 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]); + sprintf(tmp, "%s-%s/%s-%s", c1, c2, c3, c4); + free(c1); + free(c2); + free(c3); + free(c4); + multitext_add_entry(&ge->eta.bs, tmp); + multitext_add_entry(&ge->eta.ioengine, (const char *) o->ioengine); sprintf(tmp, "%u", o->iodepth); multitext_add_entry(&ge->eta.iodepth, tmp); multitext_set_entry(&ge->eta.iotype, 0); + multitext_set_entry(&ge->eta.bs, 0); multitext_set_entry(&ge->eta.ioengine, 0); multitext_set_entry(&ge->eta.iodepth, 0); - gc->job_added++; - gfio_set_state(ge, GE_STATE_JOB_SENT); gdk_threads_leave(); @@ -1694,6 +1708,15 @@ static void gfio_client_iolog(struct fio_client *client, struct cmd_iolog_pdu *p free(pdu); } +static void gfio_client_removed(struct fio_client *client) +{ + struct gfio_client *gc = client->client_data; + + assert(gc->client == client); + fio_put_client(gc->client); + gc->client = NULL; +} + struct client_ops gfio_client_ops = { .text = gfio_text_op, .disk_util = gfio_disk_util_op, @@ -1709,6 +1732,7 @@ struct client_ops gfio_client_ops = { .start = gfio_client_start, .job_start = gfio_client_job_start, .iolog = gfio_client_iolog, + .removed = gfio_client_removed, .eta_msec = FIO_CLIENT_DEF_ETA_MSEC, .stay_connected = 1, .client_type = FIO_CLIENT_TYPE_GUI, @@ -1728,12 +1752,17 @@ static void ge_destroy(struct gui_entry *ge) fio_put_client(gc->client); } + free(ge->job_file); + free(ge->host); flist_del(&ge->list); free(ge); } static void ge_widget_destroy(GtkWidget *w, gpointer data) { + struct gui_entry *ge = (struct gui_entry *) data; + + ge_destroy(ge); } static void gfio_quit(struct gui *ui) @@ -1751,7 +1780,9 @@ static void gfio_quit(struct gui *ui) static void quit_clicked(__attribute__((unused)) GtkWidget *widget, __attribute__((unused)) gpointer data) { - gfio_quit(data); + struct gui *ui = (struct gui *) data; + + gfio_quit(ui); } static void *job_thread(void *arg) @@ -1764,36 +1795,20 @@ static void *job_thread(void *arg) return NULL; } -static int send_job_files(struct gui_entry *ge) +static int send_job_file(struct gui_entry *ge) { struct gfio_client *gc = ge->client; - int i, ret = 0; - - for (i = 0; i < ge->nr_job_files; i++) { - ret = fio_client_send_ini(gc->client, ge->job_files[i]); - if (ret < 0) { - GError *error; - - error = g_error_new(g_quark_from_string("fio"), 1, "Failed to send file %s: %s\n", ge->job_files[i], strerror(-ret)); - report_error(error); - g_error_free(error); - break; - } else if (ret) - break; + GError *error; + int ret = 0; - free(ge->job_files[i]); - ge->job_files[i] = NULL; - } - while (i < ge->nr_job_files) { - free(ge->job_files[i]); - ge->job_files[i] = NULL; - i++; - } + ret = fio_client_send_ini(gc->client, ge->job_file); + if (!ret) + return 0; - free(ge->job_files); - ge->job_files = NULL; - ge->nr_job_files = 0; - return ret; + error = g_error_new(g_quark_from_string("fio"), 1, "Failed to send file %s: %s\n", ge->job_file, strerror(-ret)); + report_error(ge, error); + g_error_free(error); + return 1; } static void *server_thread(void *arg) @@ -1805,10 +1820,8 @@ static void *server_thread(void *arg) return NULL; } -static void gfio_start_server(void) +static void gfio_start_server(struct gui *ui) { - struct gui *ui = &main_ui; - if (!gfio_server_running) { gfio_server_running = 1; pthread_create(&ui->server_t, NULL, server_thread, NULL); @@ -1828,113 +1841,6 @@ static void start_job_clicked(__attribute__((unused)) GtkWidget *widget, static void file_open(GtkWidget *w, gpointer data); -static void connect_clicked(GtkWidget *widget, gpointer data) -{ - struct gui_entry *ge = data; - struct gfio_client *gc = ge->client; - - if (ge->state == GE_STATE_NEW) { - int ret; - - if (!ge->nr_job_files) - file_open(widget, ge->ui); - if (!ge->nr_job_files) - return; - - gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), "No jobs running"); - gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), 0.0); - ret = fio_client_connect(gc->client); - if (!ret) { - if (!ge->ui->handler_running) - pthread_create(&ge->ui->t, NULL, job_thread, ge->ui); - gfio_set_state(ge, GE_STATE_CONNECTED); - } else { - GError *error; - - error = g_error_new(g_quark_from_string("fio"), 1, "Failed to connect to %s: %s\n", ge->client->client->hostname, strerror(-ret)); - report_error(error); - g_error_free(error); - } - } else { - fio_client_terminate(gc->client); - gfio_set_state(ge, GE_STATE_NEW); - clear_ge_ui_info(ge); - } -} - -static void send_clicked(GtkWidget *widget, gpointer data) -{ - struct gui_entry *ge = data; - - if (send_job_files(ge)) { - GError *error; - - error = g_error_new(g_quark_from_string("fio"), 1, "Failed to send one or more job files for client %s", ge->client->client->hostname); - report_error(error); - g_error_free(error); - - gtk_widget_set_sensitive(ge->button[START_JOB_BUTTON], 1); - } -} - -static GtkWidget *add_button(GtkWidget *buttonbox, - struct button_spec *buttonspec, gpointer data) -{ - GtkWidget *button = gtk_button_new_with_label(buttonspec->buttontext); - - g_signal_connect(button, "clicked", G_CALLBACK(buttonspec->f), data); - gtk_box_pack_start(GTK_BOX(buttonbox), button, FALSE, FALSE, 3); - gtk_widget_set_tooltip_text(button, buttonspec->tooltiptext); - gtk_widget_set_sensitive(button, !buttonspec->start_insensitive); - - return button; -} - -static void add_buttons(struct gui_entry *ge, struct button_spec *buttonlist, - int nbuttons) -{ - int i; - - for (i = 0; i < nbuttons; i++) - ge->button[i] = add_button(ge->buttonbox, &buttonlist[i], ge); -} - -static void on_info_bar_response(GtkWidget *widget, gint response, - gpointer data) -{ - struct gui *ui = &main_ui; - - if (response == GTK_RESPONSE_OK) { - gtk_widget_destroy(widget); - ui->error_info_bar = NULL; - } -} - -void report_error(GError *error) -{ - struct gui *ui = &main_ui; - - if (ui->error_info_bar == NULL) { - ui->error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK, - GTK_RESPONSE_OK, - NULL); - g_signal_connect(ui->error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL); - gtk_info_bar_set_message_type(GTK_INFO_BAR(ui->error_info_bar), - GTK_MESSAGE_ERROR); - - ui->error_label = gtk_label_new(error->message); - GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui->error_info_bar)); - gtk_container_add(GTK_CONTAINER(container), ui->error_label); - - gtk_box_pack_start(GTK_BOX(ui->vbox), ui->error_info_bar, FALSE, FALSE, 0); - gtk_widget_show_all(ui->vbox); - } else { - char buffer[256]; - snprintf(buffer, sizeof(buffer), "Failed to open file."); - gtk_label_set(GTK_LABEL(ui->error_label), buffer); - } -} - struct connection_widgets { GtkWidget *hentry; @@ -1976,15 +1882,18 @@ static void hostname_cb(GtkEntry *entry, gpointer data) } } -static int get_connection_details(char **host, int *port, int *type, - int *server_start) +static int get_connection_details(struct gui_entry *ge) { GtkWidget *dialog, *box, *vbox, *hbox, *frame, *pentry; struct connection_widgets cw; + struct gui *ui = ge->ui; char *typeentry; + if (ge->host) + return 0; + dialog = gtk_dialog_new_with_buttons("Connection details", - GTK_WINDOW(main_ui.window), + GTK_WINDOW(ui->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); @@ -2054,36 +1963,151 @@ static int get_connection_details(char **host, int *port, int *type, return 1; } - *host = strdup(gtk_entry_get_text(GTK_ENTRY(cw.hentry))); - *port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pentry)); + ge->host = strdup(gtk_entry_get_text(GTK_ENTRY(cw.hentry))); + ge->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pentry)); typeentry = gtk_combo_box_get_active_text(GTK_COMBO_BOX(cw.combo)); if (!typeentry || !strncmp(typeentry, "IPv4", 4)) - *type = Fio_client_ipv4; + ge->type = Fio_client_ipv4; else if (!strncmp(typeentry, "IPv6", 4)) - *type = Fio_client_ipv6; + ge->type = Fio_client_ipv6; else - *type = Fio_client_socket; + ge->type = Fio_client_socket; g_free(typeentry); - *server_start = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw.button)); + ge->server_start = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw.button)); gtk_widget_destroy(dialog); return 0; } +static void gfio_set_client(struct gfio_client *gc, struct fio_client *client) +{ + gc->client = fio_get_client(client); + client->client_data = gc; +} + static void gfio_client_added(struct gui_entry *ge, struct fio_client *client) { struct gfio_client *gc; gc = malloc(sizeof(*gc)); memset(gc, 0, sizeof(*gc)); + options_default_fill(&gc->o); gc->ge = ge; - gc->client = fio_get_client(client); - ge->client = gc; + gfio_set_client(gc, client); +} - client->client_data = gc; +static void gfio_report_error(struct gui_entry *ge, const char *format, ...) +{ + va_list args; + GError *error; + + va_start(args, format); + error = g_error_new_valist(g_quark_from_string("fio"), 1, format, args); + va_end(args); + + report_error(ge, error); + g_error_free(error); +} + +static void connect_clicked(GtkWidget *widget, gpointer data) +{ + struct gui_entry *ge = data; + struct gfio_client *gc = ge->client; + + if (ge->state == GE_STATE_NEW) { + int ret; + + if (!ge->job_file) + file_open(widget, ge->ui); + if (!ge->job_file) + return; + + gc = ge->client; + + if (!gc->client) { + struct fio_client *client; + + if (get_connection_details(ge)) { + gfio_report_error(ge, "Failed to get connection details\n"); + return; + } + + client = fio_client_add_explicit(&gfio_client_ops, ge->host, ge->type, ge->port); + if (!client) { + gfio_report_error(ge, "Failed to add client %s\n", ge->host); + free(ge->host); + ge->host = NULL; + return; + } + gfio_set_client(gc, client); + } + + gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), "No jobs running"); + gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), 0.0); + ret = fio_client_connect(gc->client); + if (!ret) { + if (!ge->ui->handler_running) + pthread_create(&ge->ui->t, NULL, job_thread, ge->ui); + gfio_set_state(ge, GE_STATE_CONNECTED); + } else { + GError *error; + + error = g_error_new(g_quark_from_string("fio"), 1, "Failed to connect to %s: %s\n", ge->client->client->hostname, strerror(-ret)); + report_error(ge, error); + g_error_free(error); + } + } else { + fio_client_terminate(gc->client); + gfio_set_state(ge, GE_STATE_NEW); + clear_ge_ui_info(ge); + } +} + +static void send_clicked(GtkWidget *widget, gpointer data) +{ + struct gui_entry *ge = data; + + if (send_job_file(ge)) + gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_START], 1); +} + +static void on_info_bar_response(GtkWidget *widget, gint response, + gpointer data) +{ + struct gui *ui = (struct gui *) data; + + if (response == GTK_RESPONSE_OK) { + gtk_widget_destroy(widget); + ui->error_info_bar = NULL; + } +} + +static void report_error(struct gui_entry *ge, GError *error) +{ + struct gui *ui = ge->ui; + + if (ui->error_info_bar == NULL) { + ui->error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK, + GTK_RESPONSE_OK, + NULL); + g_signal_connect(ui->error_info_bar, "response", G_CALLBACK(on_info_bar_response), ui); + gtk_info_bar_set_message_type(GTK_INFO_BAR(ui->error_info_bar), + GTK_MESSAGE_ERROR); + + ui->error_label = gtk_label_new(error->message); + GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui->error_info_bar)); + gtk_container_add(GTK_CONTAINER(container), ui->error_label); + + gtk_box_pack_start(GTK_BOX(ui->vbox), ui->error_info_bar, FALSE, FALSE, 0); + gtk_widget_show_all(ui->vbox); + } else { + char buffer[256]; + snprintf(buffer, sizeof(buffer), "Failed to open file."); + gtk_label_set(GTK_LABEL(ui->error_label), buffer); + } } static GtkWidget *new_client_page(struct gui_entry *ge); @@ -2101,19 +2125,19 @@ static struct gui_entry *alloc_new_gui_entry(struct gui *ui) return ge; } -static struct gui_entry *get_new_ge_with_tab(const char *name) +static struct gui_entry *get_new_ge_with_tab(struct gui *ui, const char *name) { struct gui_entry *ge; - ge = alloc_new_gui_entry(&main_ui); + ge = alloc_new_gui_entry(ui); ge->vbox = new_client_page(ge); g_signal_connect(ge->vbox, "destroy", G_CALLBACK(ge_widget_destroy), ge); ge->page_label = gtk_label_new(name); - ge->page_num = gtk_notebook_append_page(GTK_NOTEBOOK(main_ui.notebook), ge->vbox, ge->page_label); + ge->page_num = gtk_notebook_append_page(GTK_NOTEBOOK(ui->notebook), ge->vbox, ge->page_label); - gtk_widget_show_all(main_ui.window); + gtk_widget_show_all(ui->window); return ge; } @@ -2122,7 +2146,7 @@ static void file_new(GtkWidget *w, gpointer data) struct gui *ui = (struct gui *) data; struct gui_entry *ge; - ge = get_new_ge_with_tab("Untitled"); + ge = get_new_ge_with_tab(ui, "Untitled"); gtk_notebook_set_current_page(GTK_NOTEBOOK(ui->notebook), ge->page_num); } @@ -2130,7 +2154,8 @@ static void file_new(GtkWidget *w, gpointer data) * Return the 'ge' corresponding to the tab. If the active tab is the * main tab, open a new tab. */ -static struct gui_entry *get_ge_from_page(gint cur_page, int *created) +static struct gui_entry *get_ge_from_page(struct gui *ui, gint cur_page, + int *created) { struct flist_head *entry; struct gui_entry *ge; @@ -2138,13 +2163,13 @@ static struct gui_entry *get_ge_from_page(gint cur_page, int *created) if (!cur_page) { if (created) *created = 1; - return get_new_ge_with_tab("Untitled"); + return get_new_ge_with_tab(ui, "Untitled"); } if (created) *created = 0; - flist_for_each(entry, &main_ui.list) { + flist_for_each(entry, &ui->list) { ge = flist_entry(entry, struct gui_entry, list); if (ge->page_num == cur_page) return ge; @@ -2163,7 +2188,7 @@ static struct gui_entry *get_ge_from_cur_tab(struct gui *ui) */ cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(ui->notebook)); if (cur_page) - return get_ge_from_page(cur_page, NULL); + return get_ge_from_page(ui, cur_page, NULL); return NULL; } @@ -2212,40 +2237,34 @@ static gchar *get_filename_from_uri(const gchar *uri) return strdup(uri + 7); } -static int do_file_open(struct gui_entry *ge, const gchar *uri, char *host, - int type, int port) +static int do_file_open(struct gui_entry *ge, const gchar *uri) { struct fio_client *client; - gchar *filename; - - filename = get_filename_from_uri(uri); + GError *error; - ge->job_files = realloc(ge->job_files, (ge->nr_job_files + 1) * sizeof(char *)); - ge->job_files[ge->nr_job_files] = strdup(filename); - ge->nr_job_files++; + assert(!ge->job_file); - client = fio_client_add_explicit(&gfio_client_ops, host, type, port); - if (!client) { - GError *error; + ge->job_file = get_filename_from_uri(uri); - error = g_error_new(g_quark_from_string("fio"), 1, - "Failed to add client %s", host); - report_error(error); - g_error_free(error); - return 1; + client = fio_client_add_explicit(&gfio_client_ops, ge->host, ge->type, ge->port); + if (client) { + gfio_client_added(ge, client); + file_add_recent(ge->ui, uri); + return 0; } - gfio_client_added(ge, client); - file_add_recent(ge->ui, uri); - return 0; + error = g_error_new(g_quark_from_string("fio"), 1, "Failed to add client %s", ge->host); + free(ge->host); + ge->host = NULL; + report_error(ge, error); + g_error_free(error); + return 1; } static int do_file_open_with_tab(struct gui *ui, const gchar *uri) { - int port, type, server_start; struct gui_entry *ge; gint cur_page; - char *host; int ret, ge_is_new = 0; /* @@ -2253,28 +2272,26 @@ static int do_file_open_with_tab(struct gui *ui, const gchar *uri) * current tab already has a client. */ cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(ui->notebook)); - ge = get_ge_from_page(cur_page, &ge_is_new); + ge = get_ge_from_page(ui, cur_page, &ge_is_new); if (ge->client) { - ge = get_new_ge_with_tab("Untitled"); + ge = get_new_ge_with_tab(ui, "Untitled"); ge_is_new = 1; } gtk_notebook_set_current_page(GTK_NOTEBOOK(ui->notebook), ge->page_num); - if (get_connection_details(&host, &port, &type, &server_start)) { + if (get_connection_details(ge)) { if (ge_is_new) gtk_widget_destroy(ge->vbox); return 1; } - ret = do_file_open(ge, uri, host, type, port); - - free(host); + ret = do_file_open(ge, uri); if (!ret) { - if (server_start) - gfio_start_server(); + if (ge->server_start) + gfio_start_server(ui); } else { if (ge_is_new) gtk_widget_destroy(ge->vbox); @@ -2299,8 +2316,8 @@ static void file_open(GtkWidget *w, gpointer data) { struct gui *ui = data; GtkWidget *dialog; - GSList *filenames, *fn_glist; GtkFileFilter *filter; + gchar *filename; dialog = gtk_file_chooser_dialog_new("Open File", GTK_WINDOW(ui->window), @@ -2308,7 +2325,7 @@ static void file_open(GtkWidget *w, gpointer data) GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); - gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); + gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE); filter = gtk_file_filter_new(); gtk_file_filter_add_pattern(filter, "*.fio"); @@ -2323,18 +2340,12 @@ static void file_open(GtkWidget *w, gpointer data) return; } - fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); gtk_widget_destroy(dialog); - filenames = fn_glist; - while (filenames != NULL) { - if (do_file_open_with_tab(ui, filenames->data)) - break; - filenames = g_slist_next(filenames); - } - - g_slist_free(fn_glist); + do_file_open_with_tab(ui, filename); + g_free(filename); } static void file_save(GtkWidget *w, gpointer data) @@ -2425,6 +2436,12 @@ static void send_job_entry(GtkWidget *w, gpointer data) static void edit_job_entry(GtkWidget *w, gpointer data) { + struct gui *ui = (struct gui *) data; + struct gui_entry *ge; + + ge = get_ge_from_cur_tab(ui); + if (ge && ge->client) + gopt_get_options_window(ui->window, &ge->client->o); } static void start_job_entry(GtkWidget *w, gpointer data) @@ -2437,6 +2454,24 @@ static void start_job_entry(GtkWidget *w, gpointer data) start_job_clicked(w, ge); } +static void view_results(GtkWidget *w, gpointer data) +{ + struct gui *ui = (struct gui *) data; + struct gfio_client *gc; + struct gui_entry *ge; + + ge = get_ge_from_cur_tab(ui); + if (!ge) + return; + + if (ge->results_window) + return; + + gc = ge->client; + if (gc && gc->nr_results) + gfio_display_end_results(gc); +} + static void __update_graph_limits(struct gfio_graphs *g) { line_graph_set_data_count_limit(g->iops_graph, gfio_graph_limit); @@ -2460,10 +2495,11 @@ static void preferences(GtkWidget *w, gpointer data) { GtkWidget *dialog, *frame, *box, **buttons, *vbox, *font; GtkWidget *hbox, *spin, *entry, *spin_int; + struct gui *ui = (struct gui *) data; int i; dialog = gtk_dialog_new_with_buttons("Preferences", - GTK_WINDOW(main_ui.window), + GTK_WINDOW(ui->window), GTK_DIALOG_DESTROY_WITH_PARENT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, @@ -2598,7 +2634,8 @@ static GtkActionEntry menu_items[] = { { "SaveFile", GTK_STOCK_SAVE, NULL, "S", NULL, G_CALLBACK(file_save) }, { "Preferences", GTK_STOCK_PREFERENCES, NULL, "p", NULL, G_CALLBACK(preferences) }, { "ViewLog", NULL, "Log", "l", NULL, G_CALLBACK(view_log) }, - { "ConnectJob", NULL, "Connect", "E", NULL, G_CALLBACK(connect_job_entry) }, + { "ViewResults", NULL, "Results", "R", NULL, G_CALLBACK(view_results) }, + { "ConnectJob", NULL, "Connect", "D", NULL, G_CALLBACK(connect_job_entry) }, { "EditJob", NULL, "Edit job", "E", NULL, G_CALLBACK(edit_job_entry) }, { "SendJob", NULL, "Send job", "X", NULL, G_CALLBACK(send_job_entry) }, { "StartJob", NULL, "Start job", "L", NULL, G_CALLBACK(start_job_entry) }, @@ -2612,9 +2649,9 @@ static const gchar *ui_string = " \ \ \ \ + \ \ \ - \ \ \ \ @@ -2632,6 +2669,8 @@ static const gchar *ui_string = " \ \ \ \ + \ + \ \ \ \ @@ -2641,14 +2680,6 @@ static const gchar *ui_string = " \ \ "; -static void set_job_menu_visible(struct gui *ui, int visible) -{ - GtkWidget *job; - - job = gtk_ui_manager_get_widget(ui->uimanager, "/MainMenu/JobMenu"); - gtk_widget_set_sensitive(job, visible); -} - static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager, struct gui *ui) { @@ -2680,6 +2711,7 @@ static void combo_entry_changed(GtkComboBox *box, gpointer data) index = gtk_combo_box_get_active(box); multitext_set_entry(&ge->eta.iotype, index); + multitext_set_entry(&ge->eta.bs, index); multitext_set_entry(&ge->eta.ioengine, index); multitext_set_entry(&ge->eta.iodepth, index); } @@ -2689,6 +2721,7 @@ static void combo_entry_destroy(GtkWidget *widget, gpointer data) struct gui_entry *ge = (struct gui_entry *) data; multitext_free(&ge->eta.iotype); + multitext_free(&ge->eta.bs); multitext_free(&ge->eta.ioengine); multitext_free(&ge->eta.iodepth); } @@ -2724,6 +2757,7 @@ static GtkWidget *new_client_page(struct gui_entry *ge) g_signal_connect(ge->eta.names, "changed", G_CALLBACK(combo_entry_changed), ge); g_signal_connect(ge->eta.names, "destroy", G_CALLBACK(combo_entry_destroy), ge); ge->eta.iotype.entry = new_info_entry_in_frame(probe_box, "IO"); + ge->eta.bs.entry = new_info_entry_in_frame(probe_box, "Blocksize (Read/Write)"); ge->eta.ioengine.entry = new_info_entry_in_frame(probe_box, "IO Engine"); ge->eta.iodepth.entry = new_info_entry_in_frame(probe_box, "IO Depth"); ge->eta.jobs = new_info_entry_in_frame(probe_box, "Jobs"); @@ -2886,11 +2920,12 @@ static gboolean notebook_switch_page(GtkNotebook *notebook, GtkWidget *widget, if (!page) { set_job_menu_visible(ui, 0); + set_view_results_visible(ui, 0); return TRUE; } set_job_menu_visible(ui, 1); - ge = get_ge_from_page(page, NULL); + ge = get_ge_from_page(ui, page, NULL); if (ge) update_button_states(ui, ge); @@ -2976,13 +3011,12 @@ static void add_recent_file_items(struct gui *ui) } static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *ctx, - gint x, gint y, GtkSelectionData *data, - guint info, guint time) + gint x, gint y, GtkSelectionData *seldata, + guint info, guint time, gpointer *data) { - struct gui *ui = &main_ui; + struct gui *ui = (struct gui *) data; gchar **uris; GtkWidget *source; - int i; source = gtk_drag_get_source_widget(ctx); if (source && widget == gtk_widget_get_toplevel(source)) { @@ -2990,18 +3024,14 @@ static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *ctx, return; } - uris = gtk_selection_data_get_uris(data); + uris = gtk_selection_data_get_uris(seldata); if (!uris) { gtk_drag_finish(ctx, FALSE, FALSE, time); return; } - i = 0; - while (uris[i]) { - if (do_file_open_with_tab(ui, uris[i])) - break; - i++; - } + if (uris[0]) + do_file_open_with_tab(ui, uris[0]); gtk_drag_finish(ctx, TRUE, FALSE, time); g_strfreev(uris); @@ -3030,8 +3060,8 @@ static void init_ui(int *argc, char **argv[], struct gui *ui) gtk_window_set_title(GTK_WINDOW(ui->window), "fio"); gtk_window_set_default_size(GTK_WINDOW(ui->window), 1024, 768); - g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), NULL); - g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), NULL); + g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), ui); + g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), ui); ui->vbox = gtk_vbox_new(FALSE, 0); gtk_container_add(GTK_CONTAINER(ui->window), ui->vbox); @@ -3050,7 +3080,7 @@ static void init_ui(int *argc, char **argv[], struct gui *ui) gtk_container_add(GTK_CONTAINER(ui->vbox), ui->notebook); vbox = new_main_page(ui); - gtk_drag_dest_set(GTK_WIDGET(ui->window), GTK_DEST_DEFAULT_ALL, NULL, 0, GDK_ACTION_COPY); + gtk_drag_dest_set(GTK_WIDGET(ui->window), GTK_DEST_DEFAULT_ALL, NULL, 1, GDK_ACTION_COPY); gtk_drag_dest_add_uri_targets(GTK_WIDGET(ui->window)); g_signal_connect(ui->window, "drag-data-received", G_CALLBACK(drag_and_drop_received), ui);