-}
-
-static void gfio_group_stats_op(struct fio_client *client,
- struct fio_net_cmd *cmd)
-{
- /* We're ignoring group stats for now */
-}
-
-static gint on_config_drawing_area(GtkWidget *w, GdkEventConfigure *event,
- gpointer data)
-{
- struct gfio_graphs *g = data;
-
- graph_set_size(g->iops_graph, w->allocation.width / 2.0, w->allocation.height);
- graph_set_position(g->iops_graph, w->allocation.width / 2.0, 0.0);
- graph_set_size(g->bandwidth_graph, w->allocation.width / 2.0, w->allocation.height);
- graph_set_position(g->bandwidth_graph, 0, 0);
- return TRUE;
-}
-
-static void draw_graph(struct graph *g, cairo_t *cr)
-{
- line_graph_draw(g, cr);
- cairo_stroke(cr);
-}
-
-static int on_expose_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p)
-{
- struct gfio_graphs *g = p;
- cairo_t *cr;
-
- cr = gdk_cairo_create(w->window);
- cairo_set_source_rgb(cr, 0, 0, 0);
- draw_graph(g->iops_graph, cr);
- draw_graph(g->bandwidth_graph, cr);
- cairo_destroy(cr);
-
- return FALSE;
-}
-
-/*
- * Client specific ETA
- */
-static void gfio_update_client_eta(struct fio_client *client, struct jobs_eta *je)
-{
- struct gfio_client *gc = client->client_data;
- struct gui_entry *ge = gc->ge;
- static int eta_good;
- char eta_str[128];
- char output[256];
- char tmp[32];
- double perc = 0.0;
- int i2p = 0;
-
- gdk_threads_enter();
-
- eta_str[0] = '\0';
- output[0] = '\0';
-
- if (je->eta_sec != INT_MAX && je->elapsed_sec) {
- perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
- eta_to_str(eta_str, je->eta_sec);
- }
-
- sprintf(tmp, "%u", je->nr_running);
- gtk_entry_set_text(GTK_ENTRY(ge->eta.jobs), tmp);
- sprintf(tmp, "%u", je->files_open);
- gtk_entry_set_text(GTK_ENTRY(ge->eta.files), tmp);
-
-#if 0
- if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
- if (je->m_rate || je->t_rate) {
- char *tr, *mr;
-
- mr = num2str(je->m_rate, 4, 0, i2p);
- tr = num2str(je->t_rate, 4, 0, i2p);
- gtk_entry_set_text(GTK_ENTRY(ge->eta);
- p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
- free(tr);
- free(mr);
- } else if (je->m_iops || je->t_iops)
- p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
-
- gtk_entry_set_text(GTK_ENTRY(ge->eta.cr_bw), "---");
- gtk_entry_set_text(GTK_ENTRY(ge->eta.cr_iops), "---");
- gtk_entry_set_text(GTK_ENTRY(ge->eta.cw_bw), "---");
- gtk_entry_set_text(GTK_ENTRY(ge->eta.cw_iops), "---");
-#endif
-
- if (je->eta_sec != INT_MAX && je->nr_running) {
- char *iops_str[2];
- char *rate_str[2];
-
- if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
- strcpy(output, "-.-% done");
- else {
- eta_good = 1;
- perc *= 100.0;
- sprintf(output, "%3.1f%% done", perc);
- }
-
- rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
- rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
-
- iops_str[0] = num2str(je->iops[0], 4, 1, 0);
- iops_str[1] = num2str(je->iops[1], 4, 1, 0);
-
- gtk_entry_set_text(GTK_ENTRY(ge->eta.read_bw), rate_str[0]);
- gtk_entry_set_text(GTK_ENTRY(ge->eta.read_iops), iops_str[0]);
- gtk_entry_set_text(GTK_ENTRY(ge->eta.write_bw), rate_str[1]);
- gtk_entry_set_text(GTK_ENTRY(ge->eta.write_iops), iops_str[1]);
-
- graph_add_xy_data(ge->graphs.iops_graph, "Read IOPS", je->elapsed_sec, je->iops[0]);
- graph_add_xy_data(ge->graphs.iops_graph, "Write IOPS", je->elapsed_sec, je->iops[1]);
- graph_add_xy_data(ge->graphs.bandwidth_graph, "Read Bandwidth", je->elapsed_sec, je->rate[0]);
- graph_add_xy_data(ge->graphs.bandwidth_graph, "Write Bandwidth", je->elapsed_sec, je->rate[1]);
-
- free(rate_str[0]);
- free(rate_str[1]);
- free(iops_str[0]);
- free(iops_str[1]);
- }
-
- if (eta_str[0]) {
- char *dst = output + strlen(output);
-
- sprintf(dst, " - %s", eta_str);
- }
-
- gfio_update_thread_status(ge, output, perc);
- gdk_threads_leave();
-}
-
-/*
- * Update ETA in main window for all clients
- */
-static void gfio_update_all_eta(struct jobs_eta *je)
-{
- struct gui *ui = &main_ui;
- static int eta_good;
- char eta_str[128];
- char output[256];
- double perc = 0.0;
- int i2p = 0;
-
- gdk_threads_enter();
-
- eta_str[0] = '\0';
- output[0] = '\0';
-
- if (je->eta_sec != INT_MAX && je->elapsed_sec) {
- perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
- eta_to_str(eta_str, je->eta_sec);
- }
-
-#if 0
- if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
- if (je->m_rate || je->t_rate) {
- char *tr, *mr;
-
- mr = num2str(je->m_rate, 4, 0, i2p);
- tr = num2str(je->t_rate, 4, 0, i2p);
- gtk_entry_set_text(GTK_ENTRY(ui->eta);
- p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
- free(tr);
- free(mr);
- } else if (je->m_iops || je->t_iops)
- p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
-
- gtk_entry_set_text(GTK_ENTRY(ui->eta.cr_bw), "---");
- gtk_entry_set_text(GTK_ENTRY(ui->eta.cr_iops), "---");
- gtk_entry_set_text(GTK_ENTRY(ui->eta.cw_bw), "---");
- gtk_entry_set_text(GTK_ENTRY(ui->eta.cw_iops), "---");
-#endif
-
- entry_set_int_value(ui->eta.jobs, je->nr_running);
-
- if (je->eta_sec != INT_MAX && je->nr_running) {
- char *iops_str[2];
- char *rate_str[2];
-
- if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
- strcpy(output, "-.-% done");
- else {
- eta_good = 1;
- perc *= 100.0;
- sprintf(output, "%3.1f%% done", perc);
- }
-
- rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
- rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
-
- iops_str[0] = num2str(je->iops[0], 4, 1, 0);
- iops_str[1] = num2str(je->iops[1], 4, 1, 0);
-
- gtk_entry_set_text(GTK_ENTRY(ui->eta.read_bw), rate_str[0]);
- gtk_entry_set_text(GTK_ENTRY(ui->eta.read_iops), iops_str[0]);
- gtk_entry_set_text(GTK_ENTRY(ui->eta.write_bw), rate_str[1]);
- gtk_entry_set_text(GTK_ENTRY(ui->eta.write_iops), iops_str[1]);
-
- graph_add_xy_data(ui->graphs.iops_graph, "Read IOPS", je->elapsed_sec, je->iops[0]);
- graph_add_xy_data(ui->graphs.iops_graph, "Write IOPS", je->elapsed_sec, je->iops[1]);
- graph_add_xy_data(ui->graphs.bandwidth_graph, "Read Bandwidth", je->elapsed_sec, je->rate[0]);
- graph_add_xy_data(ui->graphs.bandwidth_graph, "Write Bandwidth", je->elapsed_sec, je->rate[1]);
-
- free(rate_str[0]);
- free(rate_str[1]);
- free(iops_str[0]);
- free(iops_str[1]);
- }
-
- if (eta_str[0]) {
- char *dst = output + strlen(output);
-
- sprintf(dst, " - %s", eta_str);
- }
-
- gfio_update_thread_status_all(output, perc);
- gdk_threads_leave();
-}
-
-static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
-{
- struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
- struct gfio_client *gc = client->client_data;
- struct gui_entry *ge = gc->ge;
- const char *os, *arch;
- char buf[64];
-
- os = fio_get_os_string(probe->os);
- if (!os)
- os = "unknown";
-
- arch = fio_get_arch_string(probe->arch);
- if (!arch)
- os = "unknown";
-
- if (!client->name)
- client->name = strdup((char *) probe->hostname);
-
- gdk_threads_enter();
-
- gtk_label_set_text(GTK_LABEL(ge->probe.hostname), (char *) probe->hostname);
- gtk_label_set_text(GTK_LABEL(ge->probe.os), os);
- gtk_label_set_text(GTK_LABEL(ge->probe.arch), arch);
- sprintf(buf, "%u.%u.%u", probe->fio_major, probe->fio_minor, probe->fio_patch);
- gtk_label_set_text(GTK_LABEL(ge->probe.fio_ver), buf);
-
- gfio_set_state(ge, GE_STATE_CONNECTED);
-
- gdk_threads_leave();
-}
-
-static void gfio_update_thread_status(struct gui_entry *ge,
- char *status_message, double perc)
-{
- static char message[100];
- const char *m = message;
-
- 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);
-}
-
-static void gfio_update_thread_status_all(char *status_message, double perc)
-{
- struct gui *ui = &main_ui;
- static char message[100];
- const char *m = message;
-
- strncpy(message, status_message, sizeof(message) - 1);
- gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), m);
- gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), perc / 100.0);
- gtk_widget_queue_draw(ui->window);
-}
-
-static void gfio_quit_op(struct fio_client *client)
-{
- struct gfio_client *gc = client->client_data;
-
- gdk_threads_enter();
- gfio_set_state(gc->ge, GE_STATE_NEW);
- gdk_threads_leave();
-}
-
-static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd)
-{
- struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload;
- struct gfio_client *gc = client->client_data;
- struct thread_options *o = &gc->o;
- struct gui_entry *ge = gc->ge;
- char tmp[8];
-
- convert_thread_options_to_cpu(o, &p->top);
-
- gdk_threads_enter();
-
- gtk_label_set_text(GTK_LABEL(ge->page_label), (gchar *) o->name);
-
- 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));
- 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.ioengine, 0);
- multitext_set_entry(&ge->eta.iodepth, 0);
-
- gc->job_added++;
-
- gfio_set_state(ge, GE_STATE_JOB_SENT);
-
- gdk_threads_leave();
-}
-
-static void gfio_client_timed_out(struct fio_client *client)
-{
- struct gfio_client *gc = client->client_data;
- char buf[256];
-
- gdk_threads_enter();
-
- gfio_set_state(gc->ge, GE_STATE_NEW);
- clear_ge_ui_info(gc->ge);
-
- sprintf(buf, "Client %s: timeout talking to server.\n", client->hostname);
- show_info_dialog(gc->ge->ui, "Network timeout", buf);
-
- gdk_threads_leave();
-}
-
-static void gfio_client_stop(struct fio_client *client, struct fio_net_cmd *cmd)
-{
- struct gfio_client *gc = client->client_data;
-
- gdk_threads_enter();
-
- gfio_set_state(gc->ge, GE_STATE_JOB_DONE);
-
- if (gc->err_entry)
- entry_set_int_value(gc->err_entry, client->error);
-
- gdk_threads_leave();
-}
-
-static void gfio_client_start(struct fio_client *client, struct fio_net_cmd *cmd)
-{
- struct gfio_client *gc = client->client_data;
-
- gdk_threads_enter();
- gfio_set_state(gc->ge, GE_STATE_JOB_STARTED);
- gdk_threads_leave();
-}
-
-static void gfio_client_job_start(struct fio_client *client, struct fio_net_cmd *cmd)
-{
- struct gfio_client *gc = client->client_data;
-
- gdk_threads_enter();
- gfio_set_state(gc->ge, GE_STATE_JOB_RUNNING);
- gdk_threads_leave();
-}
-
-struct client_ops gfio_client_ops = {
- .text_op = gfio_text_op,
- .disk_util = gfio_disk_util_op,
- .thread_status = gfio_thread_status_op,
- .group_stats = gfio_group_stats_op,
- .jobs_eta = gfio_update_client_eta,
- .eta = gfio_update_all_eta,
- .probe = gfio_probe_op,
- .quit = gfio_quit_op,
- .add_job = gfio_add_job_op,
- .timed_out = gfio_client_timed_out,
- .stop = gfio_client_stop,
- .start = gfio_client_start,
- .job_start = gfio_client_job_start,
- .eta_msec = FIO_CLIENT_DEF_ETA_MSEC,
- .stay_connected = 1,
-};
-
-static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
- __attribute__((unused)) gpointer data)
-{
- gtk_main_quit();
-}
-
-static void *job_thread(void *arg)
-{
- struct gui *ui = arg;
-
- ui->handler_running = 1;
- fio_handle_clients(&gfio_client_ops);
- ui->handler_running = 0;
- return NULL;
-}
-
-static int send_job_files(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;
-
- 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++;
- }
-
- return ret;
-}
-
-static void *server_thread(void *arg)
-{
- is_backend = 1;
- gfio_server_running = 1;
- fio_start_server(NULL);
- gfio_server_running = 0;
- return NULL;
-}
-
-static void gfio_start_server(void)
-{
- struct gui *ui = &main_ui;
-
- if (!gfio_server_running) {
- gfio_server_running = 1;
- pthread_create(&ui->server_t, NULL, server_thread, NULL);
- pthread_detach(ui->server_t);
- }
-}
-
-static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
- gpointer data)
-{
- struct gui_entry *ge = data;
- struct gfio_client *gc = ge->client;
-
- gtk_widget_set_sensitive(ge->button[START_JOB_BUTTON], 0);
- fio_start_client(gc->client);
-}
-
-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);