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