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 | 23 | #include <locale.h> |
60f6b330 | 24 | #include <malloc.h> |
8232e285 | 25 | |
5b7573ab | 26 | #include <glib.h> |
ff1f3280 SC |
27 | #include <gtk/gtk.h> |
28 | ||
8232e285 SC |
29 | #include "fio.h" |
30 | ||
3e47bd25 JA |
31 | static void gfio_update_thread_status(char *status_message, double perc); |
32 | ||
f3074008 SC |
33 | #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0]))) |
34 | ||
35 | typedef void (*clickfunction)(GtkWidget *widget, gpointer data); | |
36 | ||
3e47bd25 | 37 | static void connect_clicked(GtkWidget *widget, gpointer data); |
f3074008 SC |
38 | static void start_job_clicked(GtkWidget *widget, gpointer data); |
39 | ||
40 | static struct button_spec { | |
41 | const char *buttontext; | |
42 | clickfunction f; | |
43 | const char *tooltiptext; | |
3e47bd25 | 44 | const int start_insensitive; |
f3074008 | 45 | } buttonspeclist[] = { |
3e47bd25 JA |
46 | #define CONNECT_BUTTON 0 |
47 | #define START_JOB_BUTTON 1 | |
48 | { "Connect", connect_clicked, "Connect to host", 0 }, | |
f3074008 SC |
49 | { "Start Job", |
50 | start_job_clicked, | |
3e47bd25 | 51 | "Send current fio job to fio server to be executed", 1 }, |
f3074008 SC |
52 | }; |
53 | ||
843ad237 JA |
54 | struct probe_widget { |
55 | GtkWidget *hostname; | |
56 | GtkWidget *os; | |
57 | GtkWidget *arch; | |
58 | GtkWidget *fio_ver; | |
59 | }; | |
60 | ||
3e47bd25 | 61 | struct eta_widget { |
807f9971 JA |
62 | GtkWidget *name; |
63 | GtkWidget *iotype; | |
64 | GtkWidget *ioengine; | |
65 | GtkWidget *iodepth; | |
3e47bd25 JA |
66 | GtkWidget *jobs; |
67 | GtkWidget *files; | |
68 | GtkWidget *read_bw; | |
69 | GtkWidget *read_iops; | |
70 | GtkWidget *cr_bw; | |
71 | GtkWidget *cr_iops; | |
72 | GtkWidget *write_bw; | |
73 | GtkWidget *write_iops; | |
74 | GtkWidget *cw_bw; | |
75 | GtkWidget *cw_iops; | |
76 | }; | |
77 | ||
ff1f3280 SC |
78 | struct gui { |
79 | GtkWidget *window; | |
5b7573ab | 80 | GtkWidget *vbox; |
c36f98d9 SC |
81 | GtkWidget *topvbox; |
82 | GtkWidget *topalign; | |
83 | GtkWidget *bottomalign; | |
04cc6b77 | 84 | GtkWidget *thread_status_pb; |
f3074008 SC |
85 | GtkWidget *buttonbox; |
86 | GtkWidget *button[ARRAYSIZE(buttonspeclist)]; | |
736f2dff SC |
87 | GtkWidget *scrolled_window; |
88 | GtkWidget *textview; | |
0420ba6a JA |
89 | GtkWidget *error_info_bar; |
90 | GtkWidget *error_label; | |
736f2dff | 91 | GtkTextBuffer *text; |
843ad237 | 92 | struct probe_widget probe; |
3e47bd25 | 93 | struct eta_widget eta; |
3ec62ec4 | 94 | int connected; |
25927259 | 95 | pthread_t t; |
0420ba6a | 96 | |
3ec62ec4 | 97 | struct fio_client *client; |
0420ba6a JA |
98 | int nr_job_files; |
99 | char **job_files; | |
5b7573ab | 100 | } ui; |
ff1f3280 | 101 | |
3ec62ec4 JA |
102 | static void gfio_set_connected(struct gui *ui, int connected) |
103 | { | |
104 | if (connected) { | |
105 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1); | |
106 | ui->connected = 1; | |
107 | gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Disconnect"); | |
108 | } else { | |
109 | ui->connected = 0; | |
110 | gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Connect"); | |
111 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0); | |
112 | } | |
113 | } | |
114 | ||
a1820207 SC |
115 | static void gfio_text_op(struct fio_client *client, |
116 | FILE *f, __u16 pdu_len, const char *buf) | |
117 | { | |
807f9971 | 118 | #if 0 |
736f2dff SC |
119 | GtkTextBuffer *buffer; |
120 | GtkTextIter end; | |
121 | ||
122 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui.textview)); | |
123 | gdk_threads_enter(); | |
124 | gtk_text_buffer_get_end_iter(buffer, &end); | |
125 | gtk_text_buffer_insert(buffer, &end, buf, -1); | |
126 | gdk_threads_leave(); | |
127 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(ui.textview), | |
128 | &end, 0.0, FALSE, 0.0,0.0); | |
807f9971 JA |
129 | #else |
130 | fio_client_ops.text_op(client, f, pdu_len, buf); | |
131 | #endif | |
a1820207 SC |
132 | } |
133 | ||
134 | static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd) | |
135 | { | |
136 | printf("gfio_disk_util_op called\n"); | |
137 | fio_client_ops.disk_util(client, cmd); | |
138 | } | |
139 | ||
140 | static void gfio_thread_status_op(struct fio_net_cmd *cmd) | |
141 | { | |
142 | printf("gfio_thread_status_op called\n"); | |
143 | fio_client_ops.thread_status(cmd); | |
144 | } | |
145 | ||
146 | static void gfio_group_stats_op(struct fio_net_cmd *cmd) | |
147 | { | |
148 | printf("gfio_group_stats_op called\n"); | |
149 | fio_client_ops.group_stats(cmd); | |
150 | } | |
151 | ||
3e47bd25 JA |
152 | static void gfio_update_eta(struct jobs_eta *je) |
153 | { | |
154 | static int eta_good; | |
155 | char eta_str[128]; | |
156 | char output[256]; | |
157 | char tmp[32]; | |
158 | double perc = 0.0; | |
159 | int i2p = 0; | |
160 | ||
161 | eta_str[0] = '\0'; | |
162 | output[0] = '\0'; | |
163 | ||
164 | if (je->eta_sec != INT_MAX && je->elapsed_sec) { | |
165 | perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec); | |
166 | eta_to_str(eta_str, je->eta_sec); | |
167 | } | |
168 | ||
169 | sprintf(tmp, "%u", je->nr_running); | |
170 | gtk_label_set_text(GTK_LABEL(ui.eta.jobs), tmp); | |
171 | sprintf(tmp, "%u", je->files_open); | |
172 | gtk_label_set_text(GTK_LABEL(ui.eta.files), tmp); | |
173 | ||
174 | #if 0 | |
175 | if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) { | |
176 | if (je->m_rate || je->t_rate) { | |
177 | char *tr, *mr; | |
178 | ||
179 | mr = num2str(je->m_rate, 4, 0, i2p); | |
180 | tr = num2str(je->t_rate, 4, 0, i2p); | |
181 | gtk_label_set_text(GTK_LABEL(ui.eta. | |
182 | p += sprintf(p, ", CR=%s/%s KB/s", tr, mr); | |
183 | free(tr); | |
184 | free(mr); | |
185 | } else if (je->m_iops || je->t_iops) | |
186 | p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops); | |
ebbd89cc | 187 | |
3e47bd25 JA |
188 | gtk_label_set_text(GTK_LABEL(ui.eta.cr_bw), "---"); |
189 | gtk_label_set_text(GTK_LABEL(ui.eta.cr_iops), "---"); | |
190 | gtk_label_set_text(GTK_LABEL(ui.eta.cw_bw), "---"); | |
191 | gtk_label_set_text(GTK_LABEL(ui.eta.cw_iops), "---"); | |
192 | #endif | |
193 | ||
194 | if (je->eta_sec != INT_MAX && je->nr_running) { | |
195 | char *iops_str[2]; | |
196 | char *rate_str[2]; | |
197 | ||
198 | if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running) | |
199 | strcpy(output, "-.-% done"); | |
200 | else { | |
201 | eta_good = 1; | |
202 | perc *= 100.0; | |
203 | sprintf(output, "%3.1f%% done", perc); | |
204 | } | |
205 | ||
206 | rate_str[0] = num2str(je->rate[0], 5, 10, i2p); | |
207 | rate_str[1] = num2str(je->rate[1], 5, 10, i2p); | |
208 | ||
209 | iops_str[0] = num2str(je->iops[0], 4, 1, 0); | |
210 | iops_str[1] = num2str(je->iops[1], 4, 1, 0); | |
211 | ||
212 | gtk_label_set_text(GTK_LABEL(ui.eta.read_bw), rate_str[0]); | |
213 | gtk_label_set_text(GTK_LABEL(ui.eta.read_iops), iops_str[0]); | |
214 | gtk_label_set_text(GTK_LABEL(ui.eta.write_bw), rate_str[1]); | |
215 | gtk_label_set_text(GTK_LABEL(ui.eta.write_iops), iops_str[1]); | |
216 | ||
217 | free(rate_str[0]); | |
218 | free(rate_str[1]); | |
219 | free(iops_str[0]); | |
220 | free(iops_str[1]); | |
221 | } | |
222 | ||
223 | if (eta_str[0]) { | |
224 | char *dst = output + strlen(output); | |
225 | ||
226 | sprintf(dst, " - %s", eta_str); | |
227 | } | |
228 | ||
229 | gfio_update_thread_status(output, perc); | |
230 | } | |
231 | ||
a1820207 SC |
232 | static void gfio_eta_op(struct fio_client *client, struct fio_net_cmd *cmd) |
233 | { | |
3e47bd25 JA |
234 | struct jobs_eta *je = (struct jobs_eta *) cmd->payload; |
235 | struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag; | |
236 | ||
237 | client->eta_in_flight = NULL; | |
238 | flist_del_init(&client->eta_list); | |
239 | ||
240 | fio_client_convert_jobs_eta(je); | |
241 | fio_client_sum_jobs_eta(&eta->eta, je); | |
242 | fio_client_dec_jobs_eta(eta, gfio_update_eta); | |
a1820207 SC |
243 | } |
244 | ||
245 | static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd) | |
246 | { | |
843ad237 JA |
247 | struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload; |
248 | const char *os, *arch; | |
249 | char buf[64]; | |
250 | ||
251 | os = fio_get_os_string(probe->os); | |
252 | if (!os) | |
253 | os = "unknown"; | |
254 | ||
255 | arch = fio_get_arch_string(probe->arch); | |
256 | if (!arch) | |
257 | os = "unknown"; | |
258 | ||
259 | if (!client->name) | |
260 | client->name = strdup((char *) probe->hostname); | |
261 | ||
262 | gtk_label_set_text(GTK_LABEL(ui.probe.hostname), (char *) probe->hostname); | |
263 | gtk_label_set_text(GTK_LABEL(ui.probe.os), os); | |
264 | gtk_label_set_text(GTK_LABEL(ui.probe.arch), arch); | |
265 | sprintf(buf, "%u.%u.%u", probe->fio_major, probe->fio_minor, probe->fio_patch); | |
266 | gtk_label_set_text(GTK_LABEL(ui.probe.fio_ver), buf); | |
a1820207 SC |
267 | } |
268 | ||
04cc6b77 | 269 | static void gfio_update_thread_status(char *status_message, double perc) |
5b7573ab SC |
270 | { |
271 | static char message[100]; | |
272 | const char *m = message; | |
273 | ||
274 | strncpy(message, status_message, sizeof(message) - 1); | |
04cc6b77 SC |
275 | gtk_progress_bar_set_text( |
276 | GTK_PROGRESS_BAR(ui.thread_status_pb), m); | |
277 | gtk_progress_bar_set_fraction( | |
278 | GTK_PROGRESS_BAR(ui.thread_status_pb), perc / 100.0); | |
5b7573ab SC |
279 | gdk_threads_enter(); |
280 | gtk_widget_queue_draw(ui.window); | |
281 | gdk_threads_leave(); | |
282 | } | |
283 | ||
3ec62ec4 JA |
284 | static void gfio_quit_op(struct fio_client *client) |
285 | { | |
286 | struct gui *ui = client->client_data; | |
287 | ||
288 | gfio_set_connected(ui, 0); | |
289 | } | |
290 | ||
807f9971 JA |
291 | static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd) |
292 | { | |
293 | struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload; | |
294 | struct gui *ui = client->client_data; | |
295 | char tmp[8]; | |
296 | int i; | |
297 | ||
298 | p->iodepth = le32_to_cpu(p->iodepth); | |
299 | p->rw = le32_to_cpu(p->rw); | |
300 | ||
301 | for (i = 0; i < 2; i++) { | |
302 | p->min_bs[i] = le32_to_cpu(p->min_bs[i]); | |
303 | p->max_bs[i] = le32_to_cpu(p->max_bs[i]); | |
304 | } | |
305 | ||
306 | p->numjobs = le32_to_cpu(p->numjobs); | |
307 | p->group_reporting = le32_to_cpu(p->group_reporting); | |
308 | ||
309 | gtk_label_set_text(GTK_LABEL(ui->eta.name), (gchar *) p->jobname); | |
310 | gtk_label_set_text(GTK_LABEL(ui->eta.iotype), ddir_str(p->rw)); | |
311 | gtk_label_set_text(GTK_LABEL(ui->eta.ioengine), (gchar *) p->ioengine); | |
312 | ||
313 | sprintf(tmp, "%u", p->iodepth); | |
314 | gtk_label_set_text(GTK_LABEL(ui->eta.iodepth), tmp); | |
315 | } | |
316 | ||
ed727a46 JA |
317 | static void gfio_client_timed_out(struct fio_client *client) |
318 | { | |
319 | struct gui *ui = client->client_data; | |
320 | GtkWidget *dialog, *label, *content; | |
321 | char buf[256]; | |
322 | ||
323 | gdk_threads_enter(); | |
324 | ||
325 | gfio_set_connected(ui, 0); | |
326 | ||
327 | sprintf(buf, "Client %s: timeout talking to server.\n", client->hostname); | |
328 | ||
329 | dialog = gtk_dialog_new_with_buttons("Timed out!", | |
330 | GTK_WINDOW(ui->window), | |
331 | GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT, | |
332 | GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); | |
333 | ||
334 | content = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | |
335 | label = gtk_label_new((const gchar *) buf); | |
336 | gtk_container_add(GTK_CONTAINER(content), label); | |
337 | gtk_widget_show_all(dialog); | |
338 | gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT); | |
339 | ||
340 | gtk_dialog_run(GTK_DIALOG(dialog)); | |
341 | gtk_widget_destroy(dialog); | |
342 | ||
343 | gdk_threads_leave(); | |
344 | } | |
345 | ||
a1820207 | 346 | struct client_ops gfio_client_ops = { |
0420ba6a JA |
347 | .text_op = gfio_text_op, |
348 | .disk_util = gfio_disk_util_op, | |
349 | .thread_status = gfio_thread_status_op, | |
350 | .group_stats = gfio_group_stats_op, | |
351 | .eta = gfio_eta_op, | |
352 | .probe = gfio_probe_op, | |
3ec62ec4 | 353 | .quit = gfio_quit_op, |
807f9971 | 354 | .add_job = gfio_add_job_op, |
ed727a46 | 355 | .timed_out = gfio_client_timed_out, |
3ec62ec4 | 356 | .stay_connected = 1, |
a1820207 SC |
357 | }; |
358 | ||
ff1f3280 SC |
359 | static void quit_clicked(__attribute__((unused)) GtkWidget *widget, |
360 | __attribute__((unused)) gpointer data) | |
361 | { | |
362 | gtk_main_quit(); | |
363 | } | |
364 | ||
25927259 SC |
365 | static void *job_thread(void *arg) |
366 | { | |
25927259 | 367 | fio_handle_clients(&gfio_client_ops); |
25927259 SC |
368 | return NULL; |
369 | } | |
370 | ||
0420ba6a | 371 | static int send_job_files(struct gui *ui) |
60f6b330 | 372 | { |
441013b4 | 373 | int i, ret = 0; |
0420ba6a JA |
374 | |
375 | for (i = 0; i < ui->nr_job_files; i++) { | |
376 | ret = fio_clients_send_ini(ui->job_files[i]); | |
441013b4 JA |
377 | if (ret) |
378 | break; | |
379 | ||
0420ba6a JA |
380 | free(ui->job_files[i]); |
381 | ui->job_files[i] = NULL; | |
441013b4 JA |
382 | } |
383 | while (i < ui->nr_job_files) { | |
384 | free(ui->job_files[i]); | |
385 | ui->job_files[i] = NULL; | |
386 | i++; | |
0420ba6a JA |
387 | } |
388 | ||
441013b4 | 389 | return ret; |
60f6b330 SC |
390 | } |
391 | ||
3ec62ec4 | 392 | static void start_job_thread(struct gui *ui) |
25927259 | 393 | { |
0420ba6a | 394 | if (send_job_files(ui)) { |
60f6b330 | 395 | printf("Yeah, I didn't really like those options too much.\n"); |
60f6b330 SC |
396 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1); |
397 | return; | |
398 | } | |
25927259 SC |
399 | } |
400 | ||
a7a42ce1 JA |
401 | static GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label) |
402 | { | |
403 | GtkWidget *label_widget; | |
404 | GtkWidget *frame; | |
405 | ||
406 | frame = gtk_frame_new(label); | |
407 | label_widget = gtk_label_new(NULL); | |
408 | gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3); | |
409 | gtk_container_add(GTK_CONTAINER(frame), label_widget); | |
410 | ||
411 | return label_widget; | |
412 | } | |
413 | ||
414 | static GtkWidget *create_text_entry(GtkWidget *hbox, const char *defval) | |
415 | { | |
416 | GtkWidget *text, *box; | |
417 | ||
418 | box = gtk_hbox_new(FALSE, 3); | |
419 | gtk_container_add(GTK_CONTAINER(hbox), box); | |
420 | ||
421 | text = gtk_entry_new(); | |
422 | gtk_box_pack_start(GTK_BOX(box), text, TRUE, TRUE, 0); | |
423 | gtk_entry_set_text(GTK_ENTRY(text), defval); | |
424 | ||
425 | return text; | |
426 | } | |
427 | ||
428 | static GtkWidget *create_spinbutton(GtkWidget *hbox, double min, double max, double defval) | |
429 | { | |
430 | GtkWidget *button, *box; | |
431 | ||
432 | box = gtk_hbox_new(FALSE, 3); | |
433 | gtk_container_add(GTK_CONTAINER(hbox), box); | |
434 | ||
435 | button = gtk_spin_button_new_with_range(min, max, 1.0); | |
436 | gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0); | |
437 | ||
438 | gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID); | |
439 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), defval); | |
440 | ||
441 | return button; | |
442 | } | |
443 | ||
f3074008 | 444 | static void start_job_clicked(__attribute__((unused)) GtkWidget *widget, |
25927259 | 445 | gpointer data) |
f3074008 | 446 | { |
25927259 SC |
447 | struct gui *ui = data; |
448 | ||
25927259 | 449 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0); |
3ec62ec4 | 450 | start_job_thread(ui); |
f3074008 SC |
451 | } |
452 | ||
3e47bd25 JA |
453 | static void connect_clicked(__attribute__((unused)) GtkWidget *widget, |
454 | gpointer data) | |
455 | { | |
3ec62ec4 JA |
456 | struct gui *ui = data; |
457 | ||
458 | if (!ui->connected) { | |
459 | fio_clients_connect(); | |
460 | pthread_create(&ui->t, NULL, job_thread, NULL); | |
461 | gfio_set_connected(ui, 1); | |
462 | } else | |
463 | gfio_set_connected(ui, 0); | |
3e47bd25 JA |
464 | } |
465 | ||
f3074008 SC |
466 | static void add_button(struct gui *ui, int i, GtkWidget *buttonbox, |
467 | struct button_spec *buttonspec) | |
468 | { | |
469 | ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext); | |
470 | g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui); | |
3ec62ec4 | 471 | gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], FALSE, FALSE, 3); |
f3074008 | 472 | gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext); |
3e47bd25 | 473 | gtk_widget_set_sensitive(ui->button[i], !buttonspec->start_insensitive); |
f3074008 SC |
474 | } |
475 | ||
476 | static void add_buttons(struct gui *ui, | |
477 | struct button_spec *buttonlist, | |
478 | int nbuttons) | |
479 | { | |
480 | int i; | |
481 | ||
f3074008 SC |
482 | for (i = 0; i < nbuttons; i++) |
483 | add_button(ui, i, ui->buttonbox, &buttonlist[i]); | |
484 | } | |
485 | ||
0420ba6a JA |
486 | static void on_info_bar_response(GtkWidget *widget, gint response, |
487 | gpointer data) | |
488 | { | |
489 | if (response == GTK_RESPONSE_OK) { | |
490 | gtk_widget_destroy(widget); | |
491 | ui.error_info_bar = NULL; | |
492 | } | |
493 | } | |
494 | ||
495 | void report_error(GError* error) | |
496 | { | |
497 | if (ui.error_info_bar == NULL) { | |
498 | ui.error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK, | |
499 | GTK_RESPONSE_OK, | |
500 | NULL); | |
501 | g_signal_connect(ui.error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL); | |
502 | gtk_info_bar_set_message_type(GTK_INFO_BAR(ui.error_info_bar), | |
503 | GTK_MESSAGE_ERROR); | |
504 | ||
505 | ui.error_label = gtk_label_new(error->message); | |
506 | GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui.error_info_bar)); | |
507 | gtk_container_add(GTK_CONTAINER(container), ui.error_label); | |
508 | ||
509 | gtk_box_pack_start(GTK_BOX(ui.vbox), ui.error_info_bar, FALSE, FALSE, 0); | |
510 | gtk_widget_show_all(ui.vbox); | |
511 | } else { | |
512 | char buffer[256]; | |
513 | snprintf(buffer, sizeof(buffer), "Failed to open file."); | |
514 | gtk_label_set(GTK_LABEL(ui.error_label), buffer); | |
515 | } | |
516 | } | |
517 | ||
a7a42ce1 JA |
518 | static int get_connection_details(char **host, int *port, int *type) |
519 | { | |
520 | GtkWidget *dialog, *box, *vbox, *hentry, *hbox, *frame, *pentry, *combo; | |
521 | char *typeentry; | |
522 | ||
523 | dialog = gtk_dialog_new_with_buttons("Connection details", | |
524 | GTK_WINDOW(ui.window), | |
525 | GTK_DIALOG_DESTROY_WITH_PARENT, | |
526 | GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, | |
527 | GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL); | |
528 | ||
529 | frame = gtk_frame_new("Hostname / socket name"); | |
530 | vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog)); | |
531 | gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); | |
532 | ||
533 | box = gtk_vbox_new(FALSE, 6); | |
534 | gtk_container_add(GTK_CONTAINER(frame), box); | |
535 | ||
536 | hbox = gtk_hbox_new(TRUE, 10); | |
537 | gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); | |
538 | hentry = gtk_entry_new(); | |
539 | gtk_entry_set_text(GTK_ENTRY(hentry), "localhost"); | |
540 | gtk_box_pack_start(GTK_BOX(hbox), hentry, TRUE, TRUE, 0); | |
541 | ||
542 | frame = gtk_frame_new("Port"); | |
543 | gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); | |
544 | box = gtk_vbox_new(FALSE, 10); | |
545 | gtk_container_add(GTK_CONTAINER(frame), box); | |
546 | ||
547 | hbox = gtk_hbox_new(TRUE, 4); | |
548 | gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); | |
549 | pentry = create_spinbutton(hbox, 1, 65535, FIO_NET_PORT); | |
550 | ||
551 | frame = gtk_frame_new("Type"); | |
552 | gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5); | |
553 | box = gtk_vbox_new(FALSE, 10); | |
554 | gtk_container_add(GTK_CONTAINER(frame), box); | |
555 | ||
556 | hbox = gtk_hbox_new(TRUE, 4); | |
557 | gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0); | |
558 | ||
559 | combo = gtk_combo_box_text_new(); | |
560 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "IPv4"); | |
561 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "IPv6"); | |
562 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "local socket"); | |
563 | gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0); | |
564 | ||
565 | gtk_container_add(GTK_CONTAINER(hbox), combo); | |
566 | ||
567 | gtk_widget_show_all(dialog); | |
568 | ||
569 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) { | |
570 | gtk_widget_destroy(dialog); | |
571 | return 1; | |
572 | } | |
573 | ||
574 | *host = strdup(gtk_entry_get_text(GTK_ENTRY(hentry))); | |
575 | *port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pentry)); | |
576 | ||
577 | typeentry = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo)); | |
578 | if (!typeentry || !strncmp(typeentry, "IPv4", 4)) | |
579 | *type = Fio_client_ipv4; | |
580 | else if (!strncmp(typeentry, "IPv6", 4)) | |
581 | *type = Fio_client_ipv6; | |
582 | else | |
583 | *type = Fio_client_socket; | |
584 | g_free(typeentry); | |
585 | ||
586 | gtk_widget_destroy(dialog); | |
587 | return 0; | |
588 | } | |
589 | ||
0420ba6a JA |
590 | static void file_open(GtkWidget *w, gpointer data) |
591 | { | |
592 | GtkWidget *dialog; | |
593 | GSList *filenames, *fn_glist; | |
594 | GtkFileFilter *filter; | |
a7a42ce1 JA |
595 | char *host; |
596 | int port, type; | |
0420ba6a JA |
597 | |
598 | dialog = gtk_file_chooser_dialog_new("Open File", | |
599 | GTK_WINDOW(ui.window), | |
600 | GTK_FILE_CHOOSER_ACTION_OPEN, | |
601 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
602 | GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | |
603 | NULL); | |
604 | gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
605 | ||
606 | filter = gtk_file_filter_new(); | |
607 | gtk_file_filter_add_pattern(filter, "*.fio"); | |
608 | gtk_file_filter_add_pattern(filter, "*.job"); | |
609 | gtk_file_filter_add_mime_type(filter, "text/fio"); | |
610 | gtk_file_filter_set_name(filter, "Fio job file"); | |
611 | gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); | |
612 | ||
613 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) { | |
614 | gtk_widget_destroy(dialog); | |
615 | return; | |
616 | } | |
617 | ||
618 | fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); | |
a7a42ce1 JA |
619 | |
620 | gtk_widget_destroy(dialog); | |
621 | ||
622 | if (get_connection_details(&host, &port, &type)) | |
623 | goto err; | |
624 | ||
0420ba6a JA |
625 | filenames = fn_glist; |
626 | while (filenames != NULL) { | |
0420ba6a JA |
627 | ui.job_files = realloc(ui.job_files, (ui.nr_job_files + 1) * sizeof(char *)); |
628 | ui.job_files[ui.nr_job_files] = strdup(filenames->data); | |
629 | ui.nr_job_files++; | |
630 | ||
a7a42ce1 | 631 | ui.client = fio_client_add_explicit(host, type, port); |
3ec62ec4 | 632 | ui.client->client_data = &ui; |
0420ba6a JA |
633 | #if 0 |
634 | if (error) { | |
635 | report_error(error); | |
636 | g_error_free(error); | |
637 | error = NULL; | |
638 | } | |
639 | #endif | |
640 | ||
641 | g_free(filenames->data); | |
642 | filenames = g_slist_next(filenames); | |
643 | } | |
a7a42ce1 JA |
644 | free(host); |
645 | err: | |
0420ba6a | 646 | g_slist_free(fn_glist); |
0420ba6a JA |
647 | } |
648 | ||
649 | static void file_save(GtkWidget *w, gpointer data) | |
650 | { | |
651 | GtkWidget *dialog; | |
652 | ||
653 | dialog = gtk_file_chooser_dialog_new("Save File", | |
654 | GTK_WINDOW(ui.window), | |
655 | GTK_FILE_CHOOSER_ACTION_SAVE, | |
656 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
657 | GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | |
658 | NULL); | |
659 | ||
660 | gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); | |
661 | gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document"); | |
662 | ||
663 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { | |
664 | char *filename; | |
665 | ||
666 | filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
667 | // save_job_file(filename); | |
668 | g_free(filename); | |
669 | } | |
670 | gtk_widget_destroy(dialog); | |
671 | } | |
672 | ||
673 | static void about_dialog(GtkWidget *w, gpointer data) | |
674 | { | |
675 | gtk_show_about_dialog(NULL, | |
676 | "program-name", "gfio", | |
677 | "comments", "Gtk2 UI for fio", | |
678 | "license", "GPLv2", | |
679 | "version", fio_version_string, | |
680 | "copyright", "Jens Axboe <axboe@kernel.dk> 2012", | |
681 | "logo-icon-name", "fio", | |
682 | /* Must be last: */ | |
683 | NULL, NULL, | |
684 | NULL); | |
685 | } | |
686 | ||
687 | static GtkActionEntry menu_items[] = { | |
688 | { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL}, | |
689 | { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL}, | |
690 | { "OpenFile", GTK_STOCK_OPEN, NULL, "<Control>O", NULL, G_CALLBACK(file_open) }, | |
691 | { "SaveFile", GTK_STOCK_SAVE, NULL, "<Control>S", NULL, G_CALLBACK(file_save) }, | |
692 | { "Quit", GTK_STOCK_QUIT, NULL, "<Control>Q", NULL, G_CALLBACK(quit_clicked) }, | |
693 | { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) }, | |
694 | }; | |
3e47bd25 | 695 | static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]); |
0420ba6a JA |
696 | |
697 | static const gchar *ui_string = " \ | |
698 | <ui> \ | |
699 | <menubar name=\"MainMenu\"> \ | |
700 | <menu name=\"FileMenu\" action=\"FileMenuAction\"> \ | |
701 | <menuitem name=\"Open\" action=\"OpenFile\" /> \ | |
702 | <menuitem name=\"Save\" action=\"SaveFile\" /> \ | |
703 | <separator name=\"Separator\"/> \ | |
704 | <menuitem name=\"Quit\" action=\"Quit\" /> \ | |
705 | </menu> \ | |
706 | <menu name=\"Help\" action=\"HelpMenuAction\"> \ | |
707 | <menuitem name=\"About\" action=\"About\" /> \ | |
708 | </menu> \ | |
709 | </menubar> \ | |
710 | </ui> \ | |
711 | "; | |
712 | ||
713 | static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager) | |
714 | { | |
715 | GtkActionGroup *action_group = gtk_action_group_new("Menu"); | |
716 | GError *error = 0; | |
717 | ||
718 | action_group = gtk_action_group_new("Menu"); | |
719 | gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0); | |
720 | ||
721 | gtk_ui_manager_insert_action_group(ui_manager, action_group, 0); | |
722 | gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error); | |
723 | ||
724 | gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager)); | |
725 | return gtk_ui_manager_get_widget(ui_manager, "/MainMenu"); | |
726 | } | |
727 | ||
728 | void gfio_ui_setup(GtkSettings *settings, GtkWidget *menubar, | |
729 | GtkWidget *vbox, GtkUIManager *ui_manager) | |
730 | { | |
731 | gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0); | |
732 | } | |
733 | ||
ff1f3280 SC |
734 | static void init_ui(int *argc, char **argv[], struct gui *ui) |
735 | { | |
0420ba6a JA |
736 | GtkSettings *settings; |
737 | GtkUIManager *uimanager; | |
843ad237 | 738 | GtkWidget *menu, *probe, *probe_frame, *probe_box; |
0420ba6a JA |
739 | |
740 | memset(ui, 0, sizeof(*ui)); | |
45032dd8 | 741 | |
2839f0c6 | 742 | /* Magical g*thread incantation, you just need this thread stuff. |
04cc6b77 | 743 | * Without it, the update that happens in gfio_update_thread_status |
2839f0c6 SC |
744 | * doesn't really happen in a timely fashion, you need expose events |
745 | */ | |
ed727a46 | 746 | if (!g_thread_supported()) |
2839f0c6 SC |
747 | g_thread_init(NULL); |
748 | gdk_threads_init(); | |
749 | ||
ff1f3280 | 750 | gtk_init(argc, argv); |
0420ba6a JA |
751 | settings = gtk_settings_get_default(); |
752 | gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "gfio setting"); | |
753 | g_type_init(); | |
ff1f3280 SC |
754 | |
755 | ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
756 | gtk_window_set_title(GTK_WINDOW(ui->window), "fio"); | |
757 | gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500); | |
758 | ||
0420ba6a JA |
759 | g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), NULL); |
760 | g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), NULL); | |
ff1f3280 | 761 | |
5b7573ab SC |
762 | ui->vbox = gtk_vbox_new(FALSE, 0); |
763 | gtk_container_add(GTK_CONTAINER (ui->window), ui->vbox); | |
04cc6b77 | 764 | |
0420ba6a JA |
765 | uimanager = gtk_ui_manager_new(); |
766 | menu = get_menubar_menu(ui->window, uimanager); | |
767 | gfio_ui_setup(settings, menu, ui->vbox, uimanager); | |
768 | ||
c36f98d9 SC |
769 | /* |
770 | * Set up alignments for widgets at the top of ui, | |
771 | * align top left, expand horizontally but not vertically | |
772 | */ | |
773 | ui->topalign = gtk_alignment_new(0, 0, 1, 0); | |
3ec62ec4 | 774 | ui->topvbox = gtk_vbox_new(FALSE, 3); |
c36f98d9 | 775 | gtk_container_add(GTK_CONTAINER(ui->topalign), ui->topvbox); |
e164534f | 776 | gtk_box_pack_start(GTK_BOX(ui->vbox), ui->topalign, FALSE, FALSE, 0); |
c36f98d9 | 777 | |
3e47bd25 | 778 | probe = gtk_frame_new("Job"); |
843ad237 JA |
779 | gtk_box_pack_start(GTK_BOX(ui->topvbox), probe, TRUE, FALSE, 3); |
780 | probe_frame = gtk_vbox_new(FALSE, 3); | |
781 | gtk_container_add(GTK_CONTAINER(probe), probe_frame); | |
782 | ||
783 | probe_box = gtk_hbox_new(FALSE, 3); | |
784 | gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3); | |
843ad237 JA |
785 | ui->probe.hostname = new_info_label_in_frame(probe_box, "Host"); |
786 | ui->probe.os = new_info_label_in_frame(probe_box, "OS"); | |
787 | ui->probe.arch = new_info_label_in_frame(probe_box, "Architecture"); | |
788 | ui->probe.fio_ver = new_info_label_in_frame(probe_box, "Fio version"); | |
789 | ||
3e47bd25 JA |
790 | probe_box = gtk_hbox_new(FALSE, 3); |
791 | gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3); | |
807f9971 JA |
792 | |
793 | ui->eta.name = new_info_label_in_frame(probe_box, "Name"); | |
794 | ui->eta.iotype = new_info_label_in_frame(probe_box, "IO"); | |
795 | ui->eta.ioengine = new_info_label_in_frame(probe_box, "IO Engine"); | |
796 | ui->eta.iodepth = new_info_label_in_frame(probe_box, "IO Depth"); | |
3e47bd25 JA |
797 | ui->eta.jobs = new_info_label_in_frame(probe_box, "Jobs"); |
798 | ui->eta.files = new_info_label_in_frame(probe_box, "Open files"); | |
799 | ||
800 | probe_box = gtk_hbox_new(FALSE, 3); | |
801 | gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3); | |
802 | ui->eta.read_bw = new_info_label_in_frame(probe_box, "Read BW"); | |
803 | ui->eta.read_iops = new_info_label_in_frame(probe_box, "IOPS"); | |
807f9971 JA |
804 | ui->eta.write_bw = new_info_label_in_frame(probe_box, "Write BW"); |
805 | ui->eta.write_iops = new_info_label_in_frame(probe_box, "IOPS"); | |
3e47bd25 | 806 | |
807f9971 JA |
807 | /* |
808 | * Only add this if we have a commit rate | |
809 | */ | |
810 | #if 0 | |
3e47bd25 JA |
811 | probe_box = gtk_hbox_new(FALSE, 3); |
812 | gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3); | |
807f9971 JA |
813 | |
814 | ui->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW"); | |
815 | ui->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS"); | |
816 | ||
3e47bd25 JA |
817 | ui->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW"); |
818 | ui->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS"); | |
807f9971 | 819 | #endif |
3e47bd25 | 820 | |
736f2dff SC |
821 | /* |
822 | * Add a text box for text op messages | |
823 | */ | |
824 | ui->textview = gtk_text_view_new(); | |
825 | ui->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui->textview)); | |
826 | gtk_text_buffer_set_text(ui->text, "", -1); | |
827 | gtk_text_view_set_editable(GTK_TEXT_VIEW(ui->textview), FALSE); | |
828 | gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(ui->textview), FALSE); | |
829 | ui->scrolled_window = gtk_scrolled_window_new(NULL, NULL); | |
830 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui->scrolled_window), | |
831 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
832 | gtk_container_add(GTK_CONTAINER(ui->scrolled_window), ui->textview); | |
e164534f SC |
833 | gtk_box_pack_start(GTK_BOX(ui->vbox), ui->scrolled_window, |
834 | TRUE, TRUE, 0); | |
736f2dff | 835 | |
c36f98d9 SC |
836 | /* |
837 | * Set up alignments for widgets at the bottom of ui, | |
838 | * align bottom left, expand horizontally but not vertically | |
839 | */ | |
840 | ui->bottomalign = gtk_alignment_new(0, 1, 1, 0); | |
841 | ui->buttonbox = gtk_hbox_new(FALSE, 0); | |
842 | gtk_container_add(GTK_CONTAINER(ui->bottomalign), ui->buttonbox); | |
e164534f SC |
843 | gtk_box_pack_start(GTK_BOX(ui->vbox), ui->bottomalign, |
844 | FALSE, FALSE, 0); | |
c36f98d9 | 845 | |
f3074008 | 846 | add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist)); |
3ec62ec4 JA |
847 | |
848 | /* | |
849 | * Set up thread status progress bar | |
850 | */ | |
851 | ui->thread_status_pb = gtk_progress_bar_new(); | |
852 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), 0.0); | |
853 | gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No jobs running"); | |
854 | gtk_container_add(GTK_CONTAINER(ui->buttonbox), ui->thread_status_pb); | |
855 | ||
856 | ||
ff1f3280 SC |
857 | gtk_widget_show_all(ui->window); |
858 | } | |
859 | ||
8232e285 | 860 | int main(int argc, char *argv[], char *envp[]) |
ff1f3280 | 861 | { |
8232e285 SC |
862 | if (initialize_fio(envp)) |
863 | return 1; | |
0420ba6a JA |
864 | if (fio_init_options()) |
865 | return 1; | |
a1820207 | 866 | |
3ec62ec4 | 867 | fio_debug = ~0UL; |
ff1f3280 | 868 | init_ui(&argc, &argv, &ui); |
5b7573ab | 869 | |
2839f0c6 | 870 | gdk_threads_enter(); |
ff1f3280 | 871 | gtk_main(); |
2839f0c6 | 872 | gdk_threads_leave(); |
ff1f3280 SC |
873 | return 0; |
874 | } |