Update GUI to attempt to graphically handle ETA output
[fio.git] / gfio.c
CommitLineData
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
31static void gfio_update_thread_status(char *status_message, double perc);
32
f3074008
SC
33#define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
34
35typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
36
3e47bd25 37static void connect_clicked(GtkWidget *widget, gpointer data);
f3074008
SC
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;
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
54struct probe_widget {
55 GtkWidget *hostname;
56 GtkWidget *os;
57 GtkWidget *arch;
58 GtkWidget *fio_ver;
59};
60
3e47bd25
JA
61struct 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
ff1f3280
SC
74struct gui {
75 GtkWidget *window;
5b7573ab 76 GtkWidget *vbox;
c36f98d9
SC
77 GtkWidget *topvbox;
78 GtkWidget *topalign;
79 GtkWidget *bottomalign;
04cc6b77 80 GtkWidget *thread_status_pb;
f3074008
SC
81 GtkWidget *buttonbox;
82 GtkWidget *button[ARRAYSIZE(buttonspeclist)];
45032dd8
SC
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 */
736f2dff
SC
89 GtkWidget *scrolled_window;
90 GtkWidget *textview;
0420ba6a
JA
91 GtkWidget *error_info_bar;
92 GtkWidget *error_label;
736f2dff 93 GtkTextBuffer *text;
843ad237 94 struct probe_widget probe;
3e47bd25 95 struct eta_widget eta;
25927259 96 pthread_t t;
0420ba6a
JA
97
98 void *cookie;
99 int nr_job_files;
100 char **job_files;
5b7573ab 101} ui;
ff1f3280 102
a1820207
SC
103static void gfio_text_op(struct fio_client *client,
104 FILE *f, __u16 pdu_len, const char *buf)
105{
736f2dff
SC
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);
a1820207
SC
116}
117
118static 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
124static 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
130static 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
3e47bd25
JA
136static 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
a1820207
SC
216static void gfio_eta_op(struct fio_client *client, struct fio_net_cmd *cmd)
217{
3e47bd25
JA
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);
a1820207
SC
227}
228
229static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
230{
843ad237
JA
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);
a1820207
SC
251}
252
04cc6b77 253static void gfio_update_thread_status(char *status_message, double perc)
5b7573ab
SC
254{
255 static char message[100];
256 const char *m = message;
257
258 strncpy(message, status_message, sizeof(message) - 1);
04cc6b77
SC
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);
5b7573ab
SC
263 gdk_threads_enter();
264 gtk_widget_queue_draw(ui.window);
265 gdk_threads_leave();
266}
267
a1820207 268struct client_ops gfio_client_ops = {
0420ba6a
JA
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,
a1820207
SC
275};
276
ff1f3280
SC
277static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
278 __attribute__((unused)) gpointer data)
279{
280 gtk_main_quit();
281}
282
25927259
SC
283static 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
0420ba6a 292static int send_job_files(struct gui *ui)
60f6b330 293{
0420ba6a
JA
294 int i, ret;
295
296 for (i = 0; i < ui->nr_job_files; i++) {
297 ret = fio_clients_send_ini(ui->job_files[i]);
298 free(ui->job_files[i]);
299 ui->job_files[i] = NULL;
300 if (ret)
301 return ret;
302 }
303
304 return 0;
60f6b330
SC
305}
306
25927259
SC
307static void start_job_thread(pthread_t *t, struct gui *ui)
308{
0420ba6a 309 if (send_job_files(ui)) {
60f6b330 310 printf("Yeah, I didn't really like those options too much.\n");
60f6b330
SC
311 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1);
312 return;
313 }
0420ba6a 314
25927259
SC
315 pthread_create(t, NULL, job_thread, ui);
316}
317
f3074008 318static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
25927259 319 gpointer data)
f3074008 320{
25927259
SC
321 struct gui *ui = data;
322
25927259
SC
323 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0);
324 start_job_thread(&ui->t, ui);
f3074008
SC
325}
326
3e47bd25
JA
327static void connect_clicked(__attribute__((unused)) GtkWidget *widget,
328 gpointer data)
329{
330 fio_clients_connect();
331 gtk_widget_set_sensitive(ui.button[START_JOB_BUTTON], 1);
332}
333
f3074008
SC
334static void add_button(struct gui *ui, int i, GtkWidget *buttonbox,
335 struct button_spec *buttonspec)
336{
337 ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext);
338 g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui);
339 gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], TRUE, TRUE, 0);
340 gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext);
3e47bd25 341 gtk_widget_set_sensitive(ui->button[i], !buttonspec->start_insensitive);
f3074008
SC
342}
343
344static void add_buttons(struct gui *ui,
345 struct button_spec *buttonlist,
346 int nbuttons)
347{
348 int i;
349
f3074008
SC
350 for (i = 0; i < nbuttons; i++)
351 add_button(ui, i, ui->buttonbox, &buttonlist[i]);
352}
353
0420ba6a
JA
354static void on_info_bar_response(GtkWidget *widget, gint response,
355 gpointer data)
356{
357 if (response == GTK_RESPONSE_OK) {
358 gtk_widget_destroy(widget);
359 ui.error_info_bar = NULL;
360 }
361}
362
363void report_error(GError* error)
364{
365 if (ui.error_info_bar == NULL) {
366 ui.error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
367 GTK_RESPONSE_OK,
368 NULL);
369 g_signal_connect(ui.error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL);
370 gtk_info_bar_set_message_type(GTK_INFO_BAR(ui.error_info_bar),
371 GTK_MESSAGE_ERROR);
372
373 ui.error_label = gtk_label_new(error->message);
374 GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui.error_info_bar));
375 gtk_container_add(GTK_CONTAINER(container), ui.error_label);
376
377 gtk_box_pack_start(GTK_BOX(ui.vbox), ui.error_info_bar, FALSE, FALSE, 0);
378 gtk_widget_show_all(ui.vbox);
379 } else {
380 char buffer[256];
381 snprintf(buffer, sizeof(buffer), "Failed to open file.");
382 gtk_label_set(GTK_LABEL(ui.error_label), buffer);
383 }
384}
385
386static void file_open(GtkWidget *w, gpointer data)
387{
388 GtkWidget *dialog;
389 GSList *filenames, *fn_glist;
390 GtkFileFilter *filter;
391
392 dialog = gtk_file_chooser_dialog_new("Open File",
393 GTK_WINDOW(ui.window),
394 GTK_FILE_CHOOSER_ACTION_OPEN,
395 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
396 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
397 NULL);
398 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
399
400 filter = gtk_file_filter_new();
401 gtk_file_filter_add_pattern(filter, "*.fio");
402 gtk_file_filter_add_pattern(filter, "*.job");
403 gtk_file_filter_add_mime_type(filter, "text/fio");
404 gtk_file_filter_set_name(filter, "Fio job file");
405 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
406
407 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
408 gtk_widget_destroy(dialog);
409 return;
410 }
411
412 fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
413 filenames = fn_glist;
414 while (filenames != NULL) {
415 const char *hostname;
416
417 ui.job_files = realloc(ui.job_files, (ui.nr_job_files + 1) * sizeof(char *));
418 ui.job_files[ui.nr_job_files] = strdup(filenames->data);
419 ui.nr_job_files++;
420
421 hostname = gtk_entry_get_text(GTK_ENTRY(ui.hostname_entry));
422 fio_client_add(hostname, &ui.cookie);
423#if 0
424 if (error) {
425 report_error(error);
426 g_error_free(error);
427 error = NULL;
428 }
429#endif
430
431 g_free(filenames->data);
432 filenames = g_slist_next(filenames);
433 }
434 g_slist_free(fn_glist);
435 gtk_widget_destroy(dialog);
436}
437
438static void file_save(GtkWidget *w, gpointer data)
439{
440 GtkWidget *dialog;
441
442 dialog = gtk_file_chooser_dialog_new("Save File",
443 GTK_WINDOW(ui.window),
444 GTK_FILE_CHOOSER_ACTION_SAVE,
445 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
446 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
447 NULL);
448
449 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
450 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document");
451
452 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
453 char *filename;
454
455 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
456 // save_job_file(filename);
457 g_free(filename);
458 }
459 gtk_widget_destroy(dialog);
460}
461
462static void about_dialog(GtkWidget *w, gpointer data)
463{
464 gtk_show_about_dialog(NULL,
465 "program-name", "gfio",
466 "comments", "Gtk2 UI for fio",
467 "license", "GPLv2",
468 "version", fio_version_string,
469 "copyright", "Jens Axboe <axboe@kernel.dk> 2012",
470 "logo-icon-name", "fio",
471 /* Must be last: */
472 NULL, NULL,
473 NULL);
474}
475
476static GtkActionEntry menu_items[] = {
477 { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
478 { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
479 { "OpenFile", GTK_STOCK_OPEN, NULL, "<Control>O", NULL, G_CALLBACK(file_open) },
480 { "SaveFile", GTK_STOCK_SAVE, NULL, "<Control>S", NULL, G_CALLBACK(file_save) },
481 { "Quit", GTK_STOCK_QUIT, NULL, "<Control>Q", NULL, G_CALLBACK(quit_clicked) },
482 { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) },
483};
3e47bd25 484static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
0420ba6a
JA
485
486static const gchar *ui_string = " \
487 <ui> \
488 <menubar name=\"MainMenu\"> \
489 <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
490 <menuitem name=\"Open\" action=\"OpenFile\" /> \
491 <menuitem name=\"Save\" action=\"SaveFile\" /> \
492 <separator name=\"Separator\"/> \
493 <menuitem name=\"Quit\" action=\"Quit\" /> \
494 </menu> \
495 <menu name=\"Help\" action=\"HelpMenuAction\"> \
496 <menuitem name=\"About\" action=\"About\" /> \
497 </menu> \
498 </menubar> \
499 </ui> \
500";
501
502static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
503{
504 GtkActionGroup *action_group = gtk_action_group_new("Menu");
505 GError *error = 0;
506
507 action_group = gtk_action_group_new("Menu");
508 gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
509
510 gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
511 gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
512
513 gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
514 return gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
515}
516
517void gfio_ui_setup(GtkSettings *settings, GtkWidget *menubar,
518 GtkWidget *vbox, GtkUIManager *ui_manager)
519{
520 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
521}
522
843ad237
JA
523static GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label)
524{
525 GtkWidget *label_widget;
526 GtkWidget *frame;
527
528 frame = gtk_frame_new(label);
529 label_widget = gtk_label_new(NULL);
530 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
531 gtk_container_add(GTK_CONTAINER(frame), label_widget);
532
533 return label_widget;
534}
535
ff1f3280
SC
536static void init_ui(int *argc, char **argv[], struct gui *ui)
537{
45032dd8
SC
538 GList *hostname_type_list = NULL;
539 char portnum[20];
0420ba6a
JA
540 GtkSettings *settings;
541 GtkUIManager *uimanager;
843ad237 542 GtkWidget *menu, *probe, *probe_frame, *probe_box;
0420ba6a
JA
543
544 memset(ui, 0, sizeof(*ui));
45032dd8 545
2839f0c6 546 /* Magical g*thread incantation, you just need this thread stuff.
04cc6b77 547 * Without it, the update that happens in gfio_update_thread_status
2839f0c6
SC
548 * doesn't really happen in a timely fashion, you need expose events
549 */
550 if (!g_thread_supported ())
551 g_thread_init(NULL);
552 gdk_threads_init();
553
ff1f3280 554 gtk_init(argc, argv);
0420ba6a
JA
555 settings = gtk_settings_get_default();
556 gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "gfio setting");
557 g_type_init();
ff1f3280
SC
558
559 ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
560 gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
561 gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500);
562
0420ba6a
JA
563 g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), NULL);
564 g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), NULL);
ff1f3280 565
5b7573ab
SC
566 ui->vbox = gtk_vbox_new(FALSE, 0);
567 gtk_container_add(GTK_CONTAINER (ui->window), ui->vbox);
04cc6b77 568
0420ba6a
JA
569 uimanager = gtk_ui_manager_new();
570 menu = get_menubar_menu(ui->window, uimanager);
571 gfio_ui_setup(settings, menu, ui->vbox, uimanager);
572
c36f98d9
SC
573 /*
574 * Set up alignments for widgets at the top of ui,
575 * align top left, expand horizontally but not vertically
576 */
577 ui->topalign = gtk_alignment_new(0, 0, 1, 0);
578 ui->topvbox = gtk_vbox_new(FALSE, 0);
579 gtk_container_add(GTK_CONTAINER(ui->topalign), ui->topvbox);
e164534f 580 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->topalign, FALSE, FALSE, 0);
c36f98d9 581
45032dd8
SC
582 /*
583 * Set up hostname label + entry, port label + entry,
584 */
585 ui->hostname_hbox = gtk_hbox_new(FALSE, 0);
586 ui->hostname_label = gtk_label_new("Host:");
587 ui->hostname_entry = gtk_entry_new();
588 gtk_entry_set_text(GTK_ENTRY(ui->hostname_entry), "localhost");
589 ui->port_label = gtk_label_new("Port:");
590 ui->port_entry = gtk_entry_new();
591 snprintf(portnum, sizeof(portnum) - 1, "%d", FIO_NET_PORT);
592 gtk_entry_set_text(GTK_ENTRY(ui->port_entry), (gchar *) portnum);
593
594 /*
595 * Set up combo box for address type
596 */
597 ui->hostname_combo_box = gtk_combo_new();
0420ba6a 598 gtk_entry_set_text(GTK_ENTRY(GTK_COMBO(ui->hostname_combo_box)->entry), "IPv4");
45032dd8
SC
599 hostname_type_list = g_list_append(hostname_type_list, (gpointer) "IPv4");
600 hostname_type_list = g_list_append(hostname_type_list, (gpointer) "local socket");
601 hostname_type_list = g_list_append(hostname_type_list, (gpointer) "IPv6");
0420ba6a 602 gtk_combo_set_popdown_strings(GTK_COMBO(ui->hostname_combo_box), hostname_type_list);
45032dd8
SC
603 g_list_free(hostname_type_list);
604
605 gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->hostname_label);
606 gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->hostname_entry);
607 gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->port_label);
608 gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->port_entry);
609 gtk_container_add(GTK_CONTAINER (ui->hostname_hbox), ui->hostname_combo_box);
c36f98d9 610 gtk_container_add(GTK_CONTAINER (ui->topvbox), ui->hostname_hbox);
45032dd8 611
3e47bd25 612 probe = gtk_frame_new("Job");
843ad237
JA
613 gtk_box_pack_start(GTK_BOX(ui->topvbox), probe, TRUE, FALSE, 3);
614 probe_frame = gtk_vbox_new(FALSE, 3);
615 gtk_container_add(GTK_CONTAINER(probe), probe_frame);
616
617 probe_box = gtk_hbox_new(FALSE, 3);
618 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
843ad237
JA
619 ui->probe.hostname = new_info_label_in_frame(probe_box, "Host");
620 ui->probe.os = new_info_label_in_frame(probe_box, "OS");
621 ui->probe.arch = new_info_label_in_frame(probe_box, "Architecture");
622 ui->probe.fio_ver = new_info_label_in_frame(probe_box, "Fio version");
623
3e47bd25
JA
624 probe_box = gtk_hbox_new(FALSE, 3);
625 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
626 ui->eta.jobs = new_info_label_in_frame(probe_box, "Jobs");
627 ui->eta.files = new_info_label_in_frame(probe_box, "Open files");
628
629 probe_box = gtk_hbox_new(FALSE, 3);
630 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
631 ui->eta.read_bw = new_info_label_in_frame(probe_box, "Read BW");
632 ui->eta.read_iops = new_info_label_in_frame(probe_box, "IOPS");
633 ui->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW");
634 ui->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
635
636 probe_box = gtk_hbox_new(FALSE, 3);
637 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
638 ui->eta.write_bw = new_info_label_in_frame(probe_box, "Write BW");
639 ui->eta.write_iops = new_info_label_in_frame(probe_box, "IOPS");
640 ui->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW");
641 ui->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
642
04cc6b77
SC
643 /*
644 * Set up thread status progress bar
645 */
646 ui->thread_status_pb = gtk_progress_bar_new();
3e47bd25
JA
647 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), 0.0);
648 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No jobs running");
649 gtk_container_add(GTK_CONTAINER(ui->topvbox), ui->thread_status_pb);
5b7573ab 650
736f2dff
SC
651 /*
652 * Add a text box for text op messages
653 */
654 ui->textview = gtk_text_view_new();
655 ui->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui->textview));
656 gtk_text_buffer_set_text(ui->text, "", -1);
657 gtk_text_view_set_editable(GTK_TEXT_VIEW(ui->textview), FALSE);
658 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(ui->textview), FALSE);
659 ui->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
660 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui->scrolled_window),
661 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
662 gtk_container_add(GTK_CONTAINER(ui->scrolled_window), ui->textview);
e164534f
SC
663 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->scrolled_window,
664 TRUE, TRUE, 0);
736f2dff 665
c36f98d9
SC
666 /*
667 * Set up alignments for widgets at the bottom of ui,
668 * align bottom left, expand horizontally but not vertically
669 */
670 ui->bottomalign = gtk_alignment_new(0, 1, 1, 0);
671 ui->buttonbox = gtk_hbox_new(FALSE, 0);
672 gtk_container_add(GTK_CONTAINER(ui->bottomalign), ui->buttonbox);
e164534f
SC
673 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->bottomalign,
674 FALSE, FALSE, 0);
c36f98d9 675
f3074008 676 add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist));
ff1f3280
SC
677 gtk_widget_show_all(ui->window);
678}
679
8232e285 680int main(int argc, char *argv[], char *envp[])
ff1f3280 681{
8232e285
SC
682 if (initialize_fio(envp))
683 return 1;
0420ba6a
JA
684 if (fio_init_options())
685 return 1;
a1820207 686
ff1f3280 687 init_ui(&argc, &argv, &ui);
5b7573ab 688
2839f0c6 689 gdk_threads_enter();
ff1f3280 690 gtk_main();
2839f0c6 691 gdk_threads_leave();
ff1f3280
SC
692 return 0;
693}