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