Commit | Line | Data |
---|---|---|
ff1f3280 SC |
1 | /* |
2 | * gfio - gui front end for fio - the flexible io tester | |
3 | * | |
4 | * Copyright (C) 2012 Stephen M. Cameron <stephenmcameron@gmail.com> | |
5 | * | |
6 | * The license below covers all files distributed with fio unless otherwise | |
7 | * noted in the file itself. | |
8 | * | |
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. | |
12 | * | |
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. | |
17 | * | |
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 | |
21 | * | |
22 | */ | |
8232e285 SC |
23 | #include <locale.h> |
24 | ||
5b7573ab | 25 | #include <glib.h> |
ff1f3280 SC |
26 | #include <gtk/gtk.h> |
27 | ||
8232e285 SC |
28 | #include "fio_initialization.h" |
29 | #include "fio.h" | |
30 | ||
f3074008 SC |
31 | #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0]))) |
32 | ||
33 | typedef void (*clickfunction)(GtkWidget *widget, gpointer data); | |
34 | ||
35 | static void quit_clicked(GtkWidget *widget, gpointer data); | |
36 | static void start_job_clicked(GtkWidget *widget, gpointer data); | |
37 | ||
38 | static struct button_spec { | |
39 | const char *buttontext; | |
40 | clickfunction f; | |
41 | const char *tooltiptext; | |
42 | } buttonspeclist[] = { | |
43 | #define START_JOB_BUTTON 0 | |
44 | { "Start Job", | |
45 | start_job_clicked, | |
46 | "Send current fio job to fio server to be executed" }, | |
47 | #define QUIT_BUTTON 1 | |
48 | { "Quit", quit_clicked, "Quit gfio" }, | |
49 | }; | |
50 | ||
ff1f3280 SC |
51 | struct gui { |
52 | GtkWidget *window; | |
5b7573ab | 53 | GtkWidget *vbox; |
04cc6b77 | 54 | GtkWidget *thread_status_pb; |
f3074008 SC |
55 | GtkWidget *buttonbox; |
56 | GtkWidget *button[ARRAYSIZE(buttonspeclist)]; | |
45032dd8 SC |
57 | GtkWidget *hostname_hbox; |
58 | GtkWidget *hostname_label; | |
59 | GtkWidget *hostname_entry; | |
60 | GtkWidget *port_label; | |
61 | GtkWidget *port_entry; | |
62 | GtkWidget *hostname_combo_box; /* ipv4, ipv6 or socket */ | |
47066341 SC |
63 | GtkWidget *jobfile_hbox; |
64 | GtkWidget *jobfile_label; | |
65 | GtkWidget *jobfile_entry; | |
25927259 | 66 | pthread_t t; |
5b7573ab | 67 | } ui; |
ff1f3280 | 68 | |
a1820207 SC |
69 | static void gfio_text_op(struct fio_client *client, |
70 | FILE *f, __u16 pdu_len, const char *buf) | |
71 | { | |
72 | printf("gfio_text_op called\n"); | |
73 | fio_client_ops.text_op(client, f, pdu_len, buf); | |
74 | } | |
75 | ||
76 | static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd) | |
77 | { | |
78 | printf("gfio_disk_util_op called\n"); | |
79 | fio_client_ops.disk_util(client, cmd); | |
80 | } | |
81 | ||
82 | static void gfio_thread_status_op(struct fio_net_cmd *cmd) | |
83 | { | |
84 | printf("gfio_thread_status_op called\n"); | |
85 | fio_client_ops.thread_status(cmd); | |
86 | } | |
87 | ||
88 | static void gfio_group_stats_op(struct fio_net_cmd *cmd) | |
89 | { | |
90 | printf("gfio_group_stats_op called\n"); | |
91 | fio_client_ops.group_stats(cmd); | |
92 | } | |
93 | ||
94 | static void gfio_eta_op(struct fio_client *client, struct fio_net_cmd *cmd) | |
95 | { | |
a1820207 SC |
96 | fio_client_ops.eta(client, cmd); |
97 | } | |
98 | ||
99 | static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd) | |
100 | { | |
101 | printf("gfio_probe_op called\n"); | |
102 | fio_client_ops.probe(client, cmd); | |
103 | } | |
104 | ||
04cc6b77 | 105 | static void gfio_update_thread_status(char *status_message, double perc) |
5b7573ab SC |
106 | { |
107 | static char message[100]; | |
108 | const char *m = message; | |
109 | ||
110 | strncpy(message, status_message, sizeof(message) - 1); | |
04cc6b77 SC |
111 | gtk_progress_bar_set_text( |
112 | GTK_PROGRESS_BAR(ui.thread_status_pb), m); | |
113 | gtk_progress_bar_set_fraction( | |
114 | GTK_PROGRESS_BAR(ui.thread_status_pb), perc / 100.0); | |
5b7573ab SC |
115 | gdk_threads_enter(); |
116 | gtk_widget_queue_draw(ui.window); | |
117 | gdk_threads_leave(); | |
118 | } | |
119 | ||
a1820207 SC |
120 | struct client_ops gfio_client_ops = { |
121 | gfio_text_op, | |
122 | gfio_disk_util_op, | |
123 | gfio_thread_status_op, | |
124 | gfio_group_stats_op, | |
125 | gfio_eta_op, | |
126 | gfio_probe_op, | |
5b7573ab | 127 | gfio_update_thread_status, |
a1820207 SC |
128 | }; |
129 | ||
ff1f3280 SC |
130 | static void quit_clicked(__attribute__((unused)) GtkWidget *widget, |
131 | __attribute__((unused)) gpointer data) | |
132 | { | |
133 | gtk_main_quit(); | |
134 | } | |
135 | ||
25927259 SC |
136 | static void *job_thread(void *arg) |
137 | { | |
138 | struct gui *ui = arg; | |
139 | ||
140 | fio_handle_clients(&gfio_client_ops); | |
141 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1); | |
142 | return NULL; | |
143 | } | |
144 | ||
145 | static void start_job_thread(pthread_t *t, struct gui *ui) | |
146 | { | |
147 | pthread_create(t, NULL, job_thread, ui); | |
148 | } | |
149 | ||
f3074008 | 150 | static void start_job_clicked(__attribute__((unused)) GtkWidget *widget, |
25927259 | 151 | gpointer data) |
f3074008 | 152 | { |
25927259 SC |
153 | struct gui *ui = data; |
154 | ||
f3074008 | 155 | printf("Start job button was clicked.\n"); |
25927259 SC |
156 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0); |
157 | start_job_thread(&ui->t, ui); | |
f3074008 SC |
158 | } |
159 | ||
160 | static void add_button(struct gui *ui, int i, GtkWidget *buttonbox, | |
161 | struct button_spec *buttonspec) | |
162 | { | |
163 | ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext); | |
164 | g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui); | |
165 | gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], TRUE, TRUE, 0); | |
166 | gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext); | |
167 | } | |
168 | ||
169 | static void add_buttons(struct gui *ui, | |
170 | struct button_spec *buttonlist, | |
171 | int nbuttons) | |
172 | { | |
173 | int i; | |
174 | ||
175 | ui->buttonbox = gtk_hbox_new(FALSE, 0); | |
5b7573ab | 176 | gtk_container_add(GTK_CONTAINER (ui->vbox), ui->buttonbox); |
f3074008 SC |
177 | for (i = 0; i < nbuttons; i++) |
178 | add_button(ui, i, ui->buttonbox, &buttonlist[i]); | |
179 | } | |
180 | ||
ff1f3280 SC |
181 | static void init_ui(int *argc, char **argv[], struct gui *ui) |
182 | { | |
45032dd8 SC |
183 | GList *hostname_type_list = NULL; |
184 | char portnum[20]; | |
185 | ||
2839f0c6 | 186 | /* Magical g*thread incantation, you just need this thread stuff. |
04cc6b77 | 187 | * Without it, the update that happens in gfio_update_thread_status |
2839f0c6 SC |
188 | * doesn't really happen in a timely fashion, you need expose events |
189 | */ | |
190 | if (!g_thread_supported ()) | |
191 | g_thread_init(NULL); | |
192 | gdk_threads_init(); | |
193 | ||
ff1f3280 SC |
194 | gtk_init(argc, argv); |
195 | ||
196 | ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
197 | gtk_window_set_title(GTK_WINDOW(ui->window), "fio"); | |
198 | gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500); | |
199 | ||
200 | g_signal_connect(ui->window, "delete-event", G_CALLBACK (quit_clicked), NULL); | |
201 | g_signal_connect(ui->window, "destroy", G_CALLBACK (quit_clicked), NULL); | |
202 | ||
5b7573ab SC |
203 | ui->vbox = gtk_vbox_new(FALSE, 0); |
204 | gtk_container_add(GTK_CONTAINER (ui->window), ui->vbox); | |
04cc6b77 | 205 | |
45032dd8 SC |
206 | /* |
207 | * Set up hostname label + entry, port label + entry, | |
208 | */ | |
209 | ui->hostname_hbox = gtk_hbox_new(FALSE, 0); | |
210 | ui->hostname_label = gtk_label_new("Host:"); | |
211 | ui->hostname_entry = gtk_entry_new(); | |
212 | gtk_entry_set_text(GTK_ENTRY(ui->hostname_entry), "localhost"); | |
213 | ui->port_label = gtk_label_new("Port:"); | |
214 | ui->port_entry = gtk_entry_new(); | |
215 | snprintf(portnum, sizeof(portnum) - 1, "%d", FIO_NET_PORT); | |
216 | gtk_entry_set_text(GTK_ENTRY(ui->port_entry), (gchar *) portnum); | |
217 | ||
218 | /* | |
219 | * Set up combo box for address type | |
220 | */ | |
221 | ui->hostname_combo_box = gtk_combo_new(); | |
222 | gtk_entry_set_text(GTK_ENTRY (GTK_COMBO(ui->hostname_combo_box)->entry), "IPv4"); | |
223 | hostname_type_list = g_list_append(hostname_type_list, (gpointer) "IPv4"); | |
224 | hostname_type_list = g_list_append(hostname_type_list, (gpointer) "local socket"); | |
225 | hostname_type_list = g_list_append(hostname_type_list, (gpointer) "IPv6"); | |
226 | gtk_combo_set_popdown_strings (GTK_COMBO (ui->hostname_combo_box), hostname_type_list); | |
227 | g_list_free(hostname_type_list); | |
228 | ||
229 | gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->hostname_label); | |
230 | gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->hostname_entry); | |
231 | gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->port_label); | |
232 | gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->port_entry); | |
233 | gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->hostname_combo_box); | |
234 | gtk_container_add(GTK_CONTAINER (ui->vbox), ui->hostname_hbox); | |
235 | ||
47066341 SC |
236 | /* |
237 | * Set up jobfile text entry (temporary until gui really works) | |
238 | */ | |
239 | ui->jobfile_hbox = gtk_hbox_new(FALSE, 0); | |
240 | ui->jobfile_label = gtk_label_new("Job file:"); | |
241 | ui->jobfile_entry = gtk_entry_new(); | |
242 | gtk_container_add(GTK_CONTAINER (ui->jobfile_hbox), ui->jobfile_label); | |
243 | gtk_container_add(GTK_CONTAINER (ui->jobfile_hbox), ui->jobfile_entry); | |
244 | gtk_container_add(GTK_CONTAINER (ui->vbox), ui->jobfile_hbox); | |
245 | ||
04cc6b77 SC |
246 | /* |
247 | * Set up thread status progress bar | |
248 | */ | |
249 | ui->thread_status_pb = gtk_progress_bar_new(); | |
250 | gtk_progress_bar_set_fraction( | |
251 | GTK_PROGRESS_BAR(ui->thread_status_pb), 0.0); | |
252 | gtk_progress_bar_set_text( | |
253 | GTK_PROGRESS_BAR(ui->thread_status_pb), "No jobs running"); | |
254 | gtk_container_add(GTK_CONTAINER (ui->vbox), ui->thread_status_pb); | |
5b7573ab | 255 | |
f3074008 | 256 | add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist)); |
ff1f3280 SC |
257 | gtk_widget_show_all(ui->window); |
258 | } | |
259 | ||
8232e285 | 260 | int main(int argc, char *argv[], char *envp[]) |
ff1f3280 | 261 | { |
8232e285 SC |
262 | if (initialize_fio(envp)) |
263 | return 1; | |
a1820207 SC |
264 | |
265 | if (parse_options(argc, argv)) | |
266 | return 1; | |
267 | ||
ff1f3280 | 268 | init_ui(&argc, &argv, &ui); |
5b7573ab | 269 | |
2839f0c6 | 270 | gdk_threads_enter(); |
ff1f3280 | 271 | gtk_main(); |
2839f0c6 | 272 | gdk_threads_leave(); |
ff1f3280 SC |
273 | return 0; |
274 | } |