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
28 #include "fio_initialization.h"
31 #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
33 typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
35 static void quit_clicked(GtkWidget *widget, gpointer data);
36 static void start_job_clicked(GtkWidget *widget, gpointer data);
38 static struct button_spec {
39 const char *buttontext;
41 const char *tooltiptext;
42 } buttonspeclist[] = {
43 #define START_JOB_BUTTON 0
46 "Send current fio job to fio server to be executed" },
48 { "Quit", quit_clicked, "Quit gfio" },
54 GtkWidget *thread_status_label;
56 GtkWidget *button[ARRAYSIZE(buttonspeclist)];
60 static void gfio_text_op(struct fio_client *client,
61 FILE *f, __u16 pdu_len, const char *buf)
63 printf("gfio_text_op called\n");
64 fio_client_ops.text_op(client, f, pdu_len, buf);
67 static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd)
69 printf("gfio_disk_util_op called\n");
70 fio_client_ops.disk_util(client, cmd);
73 static void gfio_thread_status_op(struct fio_net_cmd *cmd)
75 printf("gfio_thread_status_op called\n");
76 fio_client_ops.thread_status(cmd);
79 static void gfio_group_stats_op(struct fio_net_cmd *cmd)
81 printf("gfio_group_stats_op called\n");
82 fio_client_ops.group_stats(cmd);
85 static void gfio_eta_op(struct fio_client *client, struct fio_net_cmd *cmd)
87 fio_client_ops.eta(client, cmd);
90 static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
92 printf("gfio_probe_op called\n");
93 fio_client_ops.probe(client, cmd);
96 static void gfio_update_thread_status(char *status_message)
98 static char message[100];
99 const char *m = message;
101 strncpy(message, status_message, sizeof(message) - 1);
102 gtk_label_set_text(GTK_LABEL(ui.thread_status_label), m);
104 gtk_widget_queue_draw(ui.window);
108 struct client_ops gfio_client_ops = {
111 gfio_thread_status_op,
115 gfio_update_thread_status,
118 static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
119 __attribute__((unused)) gpointer data)
124 static void *job_thread(void *arg)
126 struct gui *ui = arg;
128 fio_handle_clients(&gfio_client_ops);
129 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1);
133 static void start_job_thread(pthread_t *t, struct gui *ui)
135 pthread_create(t, NULL, job_thread, ui);
138 static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
141 struct gui *ui = data;
143 printf("Start job button was clicked.\n");
144 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0);
145 start_job_thread(&ui->t, ui);
148 static void add_button(struct gui *ui, int i, GtkWidget *buttonbox,
149 struct button_spec *buttonspec)
151 ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext);
152 g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui);
153 gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], TRUE, TRUE, 0);
154 gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext);
157 static void add_buttons(struct gui *ui,
158 struct button_spec *buttonlist,
163 ui->buttonbox = gtk_hbox_new(FALSE, 0);
164 gtk_container_add(GTK_CONTAINER (ui->vbox), ui->buttonbox);
165 for (i = 0; i < nbuttons; i++)
166 add_button(ui, i, ui->buttonbox, &buttonlist[i]);
169 static void init_ui(int *argc, char **argv[], struct gui *ui)
171 gtk_init(argc, argv);
173 ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
174 gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
175 gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500);
177 g_signal_connect(ui->window, "delete-event", G_CALLBACK (quit_clicked), NULL);
178 g_signal_connect(ui->window, "destroy", G_CALLBACK (quit_clicked), NULL);
180 ui->vbox = gtk_vbox_new(FALSE, 0);
181 gtk_container_add(GTK_CONTAINER (ui->window), ui->vbox);
182 ui->thread_status_label = gtk_label_new("No jobs currently running.");
183 gtk_container_add(GTK_CONTAINER (ui->vbox), ui->thread_status_label);
185 add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist));
186 gtk_widget_show_all(ui->window);
189 int main(int argc, char *argv[], char *envp[])
191 if (initialize_fio(envp))
194 if (parse_options(argc, argv))
197 init_ui(&argc, &argv, &ui);