blob: 848e511a8157c975355d36e5a2580fe701e116f4 [file] [log] [blame]
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001/*
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 */
Stephen M. Cameron8232e282012-02-24 08:17:31 +010023#include <locale.h>
Stephen M. Cameron60f6b332012-02-24 08:17:32 +010024#include <malloc.h>
Stephen M. Cameron8232e282012-02-24 08:17:31 +010025
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +010026#include <glib.h>
Stephen M. Cameronff1f3282012-02-24 08:17:30 +010027#include <gtk/gtk.h>
28
Stephen M. Cameron8232e282012-02-24 08:17:31 +010029#include "fio.h"
30
Jens Axboe3e47bd22012-02-29 13:45:02 +010031static void gfio_update_thread_status(char *status_message, double perc);
32
Stephen M. Cameronf3074002012-02-24 08:17:30 +010033#define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
34
35typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
36
Jens Axboe3e47bd22012-02-29 13:45:02 +010037static void connect_clicked(GtkWidget *widget, gpointer data);
Stephen M. Cameronf3074002012-02-24 08:17:30 +010038static void start_job_clicked(GtkWidget *widget, gpointer data);
39
40static struct button_spec {
41 const char *buttontext;
42 clickfunction f;
43 const char *tooltiptext;
Jens Axboe3e47bd22012-02-29 13:45:02 +010044 const int start_insensitive;
Stephen M. Cameronf3074002012-02-24 08:17:30 +010045} buttonspeclist[] = {
Jens Axboe3e47bd22012-02-29 13:45:02 +010046#define CONNECT_BUTTON 0
47#define START_JOB_BUTTON 1
48 { "Connect", connect_clicked, "Connect to host", 0 },
Stephen M. Cameronf3074002012-02-24 08:17:30 +010049 { "Start Job",
50 start_job_clicked,
Jens Axboe3e47bd22012-02-29 13:45:02 +010051 "Send current fio job to fio server to be executed", 1 },
Stephen M. Cameronf3074002012-02-24 08:17:30 +010052};
53
Jens Axboe843ad232012-02-29 11:44:53 +010054struct probe_widget {
55 GtkWidget *hostname;
56 GtkWidget *os;
57 GtkWidget *arch;
58 GtkWidget *fio_ver;
59};
60
Jens Axboe3e47bd22012-02-29 13:45:02 +010061struct 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
Stephen M. Cameronff1f3282012-02-24 08:17:30 +010074struct gui {
75 GtkWidget *window;
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +010076 GtkWidget *vbox;
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +010077 GtkWidget *topvbox;
78 GtkWidget *topalign;
79 GtkWidget *bottomalign;
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +010080 GtkWidget *thread_status_pb;
Stephen M. Cameronf3074002012-02-24 08:17:30 +010081 GtkWidget *buttonbox;
82 GtkWidget *button[ARRAYSIZE(buttonspeclist)];
Stephen M. Cameron45032dd2012-02-24 08:17:31 +010083 GtkWidget *hostname_hbox;
84 GtkWidget *hostname_label;
85 GtkWidget *hostname_entry;
Jens Axboe3ec62ec2012-03-01 12:01:29 +010086 GtkWidget *port_button;
Stephen M. Cameron45032dd2012-02-24 08:17:31 +010087 GtkWidget *port_label;
Stephen M. Cameron45032dd2012-02-24 08:17:31 +010088 GtkWidget *hostname_combo_box; /* ipv4, ipv6 or socket */
Stephen M. Cameron736f2df2012-02-24 08:17:32 +010089 GtkWidget *scrolled_window;
90 GtkWidget *textview;
Jens Axboe0420ba62012-02-29 11:16:52 +010091 GtkWidget *error_info_bar;
92 GtkWidget *error_label;
Stephen M. Cameron736f2df2012-02-24 08:17:32 +010093 GtkTextBuffer *text;
Jens Axboe843ad232012-02-29 11:44:53 +010094 struct probe_widget probe;
Jens Axboe3e47bd22012-02-29 13:45:02 +010095 struct eta_widget eta;
Jens Axboe3ec62ec2012-03-01 12:01:29 +010096 int connected;
Stephen M. Cameron25927252012-02-24 08:17:31 +010097 pthread_t t;
Jens Axboe0420ba62012-02-29 11:16:52 +010098
Jens Axboe3ec62ec2012-03-01 12:01:29 +010099 struct fio_client *client;
Jens Axboe0420ba62012-02-29 11:16:52 +0100100 int nr_job_files;
101 char **job_files;
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +0100102} ui;
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100103
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100104static void gfio_set_connected(struct gui *ui, int connected)
105{
106 if (connected) {
107 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1);
108 ui->connected = 1;
109 gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Disconnect");
110 } else {
111 ui->connected = 0;
112 gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Connect");
113 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0);
114 }
115}
116
Stephen M. Camerona1820202012-02-24 08:17:31 +0100117static void gfio_text_op(struct fio_client *client,
118 FILE *f, __u16 pdu_len, const char *buf)
119{
Stephen M. Cameron736f2df2012-02-24 08:17:32 +0100120 GtkTextBuffer *buffer;
121 GtkTextIter end;
122
123 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui.textview));
124 gdk_threads_enter();
125 gtk_text_buffer_get_end_iter(buffer, &end);
126 gtk_text_buffer_insert(buffer, &end, buf, -1);
127 gdk_threads_leave();
128 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(ui.textview),
129 &end, 0.0, FALSE, 0.0,0.0);
Stephen M. Camerona1820202012-02-24 08:17:31 +0100130}
131
132static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd)
133{
134 printf("gfio_disk_util_op called\n");
135 fio_client_ops.disk_util(client, cmd);
136}
137
138static void gfio_thread_status_op(struct fio_net_cmd *cmd)
139{
140 printf("gfio_thread_status_op called\n");
141 fio_client_ops.thread_status(cmd);
142}
143
144static void gfio_group_stats_op(struct fio_net_cmd *cmd)
145{
146 printf("gfio_group_stats_op called\n");
147 fio_client_ops.group_stats(cmd);
148}
149
Jens Axboe3e47bd22012-02-29 13:45:02 +0100150static void gfio_update_eta(struct jobs_eta *je)
151{
152 static int eta_good;
153 char eta_str[128];
154 char output[256];
155 char tmp[32];
156 double perc = 0.0;
157 int i2p = 0;
158
159 eta_str[0] = '\0';
160 output[0] = '\0';
161
162 if (je->eta_sec != INT_MAX && je->elapsed_sec) {
163 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
164 eta_to_str(eta_str, je->eta_sec);
165 }
166
167 sprintf(tmp, "%u", je->nr_running);
168 gtk_label_set_text(GTK_LABEL(ui.eta.jobs), tmp);
169 sprintf(tmp, "%u", je->files_open);
170 gtk_label_set_text(GTK_LABEL(ui.eta.files), tmp);
171
172#if 0
173 if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
174 if (je->m_rate || je->t_rate) {
175 char *tr, *mr;
176
177 mr = num2str(je->m_rate, 4, 0, i2p);
178 tr = num2str(je->t_rate, 4, 0, i2p);
179 gtk_label_set_text(GTK_LABEL(ui.eta.
180 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
181 free(tr);
182 free(mr);
183 } else if (je->m_iops || je->t_iops)
184 p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
185#else
186 gtk_label_set_text(GTK_LABEL(ui.eta.cr_bw), "---");
187 gtk_label_set_text(GTK_LABEL(ui.eta.cr_iops), "---");
188 gtk_label_set_text(GTK_LABEL(ui.eta.cw_bw), "---");
189 gtk_label_set_text(GTK_LABEL(ui.eta.cw_iops), "---");
190#endif
191
192 if (je->eta_sec != INT_MAX && je->nr_running) {
193 char *iops_str[2];
194 char *rate_str[2];
195
196 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
197 strcpy(output, "-.-% done");
198 else {
199 eta_good = 1;
200 perc *= 100.0;
201 sprintf(output, "%3.1f%% done", perc);
202 }
203
204 rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
205 rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
206
207 iops_str[0] = num2str(je->iops[0], 4, 1, 0);
208 iops_str[1] = num2str(je->iops[1], 4, 1, 0);
209
210 gtk_label_set_text(GTK_LABEL(ui.eta.read_bw), rate_str[0]);
211 gtk_label_set_text(GTK_LABEL(ui.eta.read_iops), iops_str[0]);
212 gtk_label_set_text(GTK_LABEL(ui.eta.write_bw), rate_str[1]);
213 gtk_label_set_text(GTK_LABEL(ui.eta.write_iops), iops_str[1]);
214
215 free(rate_str[0]);
216 free(rate_str[1]);
217 free(iops_str[0]);
218 free(iops_str[1]);
219 }
220
221 if (eta_str[0]) {
222 char *dst = output + strlen(output);
223
224 sprintf(dst, " - %s", eta_str);
225 }
226
227 gfio_update_thread_status(output, perc);
228}
229
Stephen M. Camerona1820202012-02-24 08:17:31 +0100230static void gfio_eta_op(struct fio_client *client, struct fio_net_cmd *cmd)
231{
Jens Axboe3e47bd22012-02-29 13:45:02 +0100232 struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
233 struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag;
234
235 client->eta_in_flight = NULL;
236 flist_del_init(&client->eta_list);
237
238 fio_client_convert_jobs_eta(je);
239 fio_client_sum_jobs_eta(&eta->eta, je);
240 fio_client_dec_jobs_eta(eta, gfio_update_eta);
Stephen M. Camerona1820202012-02-24 08:17:31 +0100241}
242
243static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
244{
Jens Axboe843ad232012-02-29 11:44:53 +0100245 struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
246 const char *os, *arch;
247 char buf[64];
248
249 os = fio_get_os_string(probe->os);
250 if (!os)
251 os = "unknown";
252
253 arch = fio_get_arch_string(probe->arch);
254 if (!arch)
255 os = "unknown";
256
257 if (!client->name)
258 client->name = strdup((char *) probe->hostname);
259
260 gtk_label_set_text(GTK_LABEL(ui.probe.hostname), (char *) probe->hostname);
261 gtk_label_set_text(GTK_LABEL(ui.probe.os), os);
262 gtk_label_set_text(GTK_LABEL(ui.probe.arch), arch);
263 sprintf(buf, "%u.%u.%u", probe->fio_major, probe->fio_minor, probe->fio_patch);
264 gtk_label_set_text(GTK_LABEL(ui.probe.fio_ver), buf);
Stephen M. Camerona1820202012-02-24 08:17:31 +0100265}
266
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +0100267static void gfio_update_thread_status(char *status_message, double perc)
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +0100268{
269 static char message[100];
270 const char *m = message;
271
272 strncpy(message, status_message, sizeof(message) - 1);
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +0100273 gtk_progress_bar_set_text(
274 GTK_PROGRESS_BAR(ui.thread_status_pb), m);
275 gtk_progress_bar_set_fraction(
276 GTK_PROGRESS_BAR(ui.thread_status_pb), perc / 100.0);
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +0100277 gdk_threads_enter();
278 gtk_widget_queue_draw(ui.window);
279 gdk_threads_leave();
280}
281
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100282static void gfio_quit_op(struct fio_client *client)
283{
284 struct gui *ui = client->client_data;
285
286 gfio_set_connected(ui, 0);
287}
288
Stephen M. Camerona1820202012-02-24 08:17:31 +0100289struct client_ops gfio_client_ops = {
Jens Axboe0420ba62012-02-29 11:16:52 +0100290 .text_op = gfio_text_op,
291 .disk_util = gfio_disk_util_op,
292 .thread_status = gfio_thread_status_op,
293 .group_stats = gfio_group_stats_op,
294 .eta = gfio_eta_op,
295 .probe = gfio_probe_op,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100296 .quit = gfio_quit_op,
297 .stay_connected = 1,
Stephen M. Camerona1820202012-02-24 08:17:31 +0100298};
299
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100300static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
301 __attribute__((unused)) gpointer data)
302{
303 gtk_main_quit();
304}
305
Stephen M. Cameron25927252012-02-24 08:17:31 +0100306static void *job_thread(void *arg)
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100307{
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100308 printf("job thread starts\n");
Stephen M. Cameron25927252012-02-24 08:17:31 +0100309 fio_handle_clients(&gfio_client_ops);
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100310 printf("job thread exits\n");
Stephen M. Cameron25927252012-02-24 08:17:31 +0100311 return NULL;
312}
313
Jens Axboe0420ba62012-02-29 11:16:52 +0100314static int send_job_files(struct gui *ui)
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100315{
Jens Axboe441013b2012-03-01 08:01:52 +0100316 int i, ret = 0;
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100317
Jens Axboe0420ba62012-02-29 11:16:52 +0100318 for (i = 0; i < ui->nr_job_files; i++) {
319 ret = fio_clients_send_ini(ui->job_files[i]);
Jens Axboe441013b2012-03-01 08:01:52 +0100320 if (ret)
321 break;
322
Jens Axboe0420ba62012-02-29 11:16:52 +0100323 free(ui->job_files[i]);
324 ui->job_files[i] = NULL;
Jens Axboe441013b2012-03-01 08:01:52 +0100325 }
326 while (i < ui->nr_job_files) {
327 free(ui->job_files[i]);
328 ui->job_files[i] = NULL;
329 i++;
Jens Axboe0420ba62012-02-29 11:16:52 +0100330 }
331
Jens Axboe441013b2012-03-01 08:01:52 +0100332 return ret;
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100333}
334
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100335static void start_job_thread(struct gui *ui)
Stephen M. Cameron25927252012-02-24 08:17:31 +0100336{
Jens Axboe0420ba62012-02-29 11:16:52 +0100337 if (send_job_files(ui)) {
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100338 printf("Yeah, I didn't really like those options too much.\n");
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100339 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1);
340 return;
341 }
Stephen M. Cameron25927252012-02-24 08:17:31 +0100342}
343
344static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
345 gpointer data)
346{
347 struct gui *ui = data;
348
Stephen M. Cameron25927252012-02-24 08:17:31 +0100349 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0);
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100350 start_job_thread(ui);
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100351}
352
Jens Axboe3e47bd22012-02-29 13:45:02 +0100353static void connect_clicked(__attribute__((unused)) GtkWidget *widget,
354 gpointer data)
355{
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100356 struct gui *ui = data;
357
358 if (!ui->connected) {
359 fio_clients_connect();
360 pthread_create(&ui->t, NULL, job_thread, NULL);
361 gfio_set_connected(ui, 1);
362 } else
363 gfio_set_connected(ui, 0);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100364}
365
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100366static void add_button(struct gui *ui, int i, GtkWidget *buttonbox,
367 struct button_spec *buttonspec)
368{
369 ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext);
370 g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui);
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100371 gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], FALSE, FALSE, 3);
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100372 gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100373 gtk_widget_set_sensitive(ui->button[i], !buttonspec->start_insensitive);
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100374}
375
376static void add_buttons(struct gui *ui,
377 struct button_spec *buttonlist,
378 int nbuttons)
379{
380 int i;
381
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100382 for (i = 0; i < nbuttons; i++)
383 add_button(ui, i, ui->buttonbox, &buttonlist[i]);
384}
385
Jens Axboe0420ba62012-02-29 11:16:52 +0100386static void on_info_bar_response(GtkWidget *widget, gint response,
387 gpointer data)
388{
389 if (response == GTK_RESPONSE_OK) {
390 gtk_widget_destroy(widget);
391 ui.error_info_bar = NULL;
392 }
393}
394
395void report_error(GError* error)
396{
397 if (ui.error_info_bar == NULL) {
398 ui.error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
399 GTK_RESPONSE_OK,
400 NULL);
401 g_signal_connect(ui.error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL);
402 gtk_info_bar_set_message_type(GTK_INFO_BAR(ui.error_info_bar),
403 GTK_MESSAGE_ERROR);
404
405 ui.error_label = gtk_label_new(error->message);
406 GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui.error_info_bar));
407 gtk_container_add(GTK_CONTAINER(container), ui.error_label);
408
409 gtk_box_pack_start(GTK_BOX(ui.vbox), ui.error_info_bar, FALSE, FALSE, 0);
410 gtk_widget_show_all(ui.vbox);
411 } else {
412 char buffer[256];
413 snprintf(buffer, sizeof(buffer), "Failed to open file.");
414 gtk_label_set(GTK_LABEL(ui.error_label), buffer);
415 }
416}
417
418static void file_open(GtkWidget *w, gpointer data)
419{
420 GtkWidget *dialog;
421 GSList *filenames, *fn_glist;
422 GtkFileFilter *filter;
423
424 dialog = gtk_file_chooser_dialog_new("Open File",
425 GTK_WINDOW(ui.window),
426 GTK_FILE_CHOOSER_ACTION_OPEN,
427 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
428 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
429 NULL);
430 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
431
432 filter = gtk_file_filter_new();
433 gtk_file_filter_add_pattern(filter, "*.fio");
434 gtk_file_filter_add_pattern(filter, "*.job");
435 gtk_file_filter_add_mime_type(filter, "text/fio");
436 gtk_file_filter_set_name(filter, "Fio job file");
437 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
438
439 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
440 gtk_widget_destroy(dialog);
441 return;
442 }
443
444 fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
445 filenames = fn_glist;
446 while (filenames != NULL) {
447 const char *hostname;
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100448 char *typeentry;
449 gint port;
450 int type;
Jens Axboe0420ba62012-02-29 11:16:52 +0100451
452 ui.job_files = realloc(ui.job_files, (ui.nr_job_files + 1) * sizeof(char *));
453 ui.job_files[ui.nr_job_files] = strdup(filenames->data);
454 ui.nr_job_files++;
455
456 hostname = gtk_entry_get_text(GTK_ENTRY(ui.hostname_entry));
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100457 port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ui.port_button));
458 typeentry = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(ui.hostname_combo_box));
459 if (!typeentry || !strncmp(typeentry, "IPv4", 4))
460 type = Fio_client_ipv4;
461 else if (!strncmp(typeentry, "IPv6", 4))
462 type = Fio_client_ipv6;
463 else
464 type = Fio_client_socket;
465 g_free(typeentry);
466
467 ui.client = fio_client_add_explicit(hostname, type, port);
468 ui.client->client_data = &ui;
Jens Axboe0420ba62012-02-29 11:16:52 +0100469#if 0
470 if (error) {
471 report_error(error);
472 g_error_free(error);
473 error = NULL;
474 }
475#endif
476
477 g_free(filenames->data);
478 filenames = g_slist_next(filenames);
479 }
480 g_slist_free(fn_glist);
481 gtk_widget_destroy(dialog);
482}
483
484static void file_save(GtkWidget *w, gpointer data)
485{
486 GtkWidget *dialog;
487
488 dialog = gtk_file_chooser_dialog_new("Save File",
489 GTK_WINDOW(ui.window),
490 GTK_FILE_CHOOSER_ACTION_SAVE,
491 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
492 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
493 NULL);
494
495 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
496 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document");
497
498 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
499 char *filename;
500
501 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
502 // save_job_file(filename);
503 g_free(filename);
504 }
505 gtk_widget_destroy(dialog);
506}
507
508static void about_dialog(GtkWidget *w, gpointer data)
509{
510 gtk_show_about_dialog(NULL,
511 "program-name", "gfio",
512 "comments", "Gtk2 UI for fio",
513 "license", "GPLv2",
514 "version", fio_version_string,
515 "copyright", "Jens Axboe <axboe@kernel.dk> 2012",
516 "logo-icon-name", "fio",
517 /* Must be last: */
518 NULL, NULL,
519 NULL);
520}
521
522static GtkActionEntry menu_items[] = {
523 { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
524 { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
525 { "OpenFile", GTK_STOCK_OPEN, NULL, "<Control>O", NULL, G_CALLBACK(file_open) },
526 { "SaveFile", GTK_STOCK_SAVE, NULL, "<Control>S", NULL, G_CALLBACK(file_save) },
527 { "Quit", GTK_STOCK_QUIT, NULL, "<Control>Q", NULL, G_CALLBACK(quit_clicked) },
528 { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) },
529};
Jens Axboe3e47bd22012-02-29 13:45:02 +0100530static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
Jens Axboe0420ba62012-02-29 11:16:52 +0100531
532static const gchar *ui_string = " \
533 <ui> \
534 <menubar name=\"MainMenu\"> \
535 <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
536 <menuitem name=\"Open\" action=\"OpenFile\" /> \
537 <menuitem name=\"Save\" action=\"SaveFile\" /> \
538 <separator name=\"Separator\"/> \
539 <menuitem name=\"Quit\" action=\"Quit\" /> \
540 </menu> \
541 <menu name=\"Help\" action=\"HelpMenuAction\"> \
542 <menuitem name=\"About\" action=\"About\" /> \
543 </menu> \
544 </menubar> \
545 </ui> \
546";
547
548static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
549{
550 GtkActionGroup *action_group = gtk_action_group_new("Menu");
551 GError *error = 0;
552
553 action_group = gtk_action_group_new("Menu");
554 gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
555
556 gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
557 gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
558
559 gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
560 return gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
561}
562
563void gfio_ui_setup(GtkSettings *settings, GtkWidget *menubar,
564 GtkWidget *vbox, GtkUIManager *ui_manager)
565{
566 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
567}
568
Jens Axboe843ad232012-02-29 11:44:53 +0100569static GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label)
570{
571 GtkWidget *label_widget;
572 GtkWidget *frame;
573
574 frame = gtk_frame_new(label);
575 label_widget = gtk_label_new(NULL);
576 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
577 gtk_container_add(GTK_CONTAINER(frame), label_widget);
578
579 return label_widget;
580}
581
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100582static GtkWidget *create_text_entry(GtkWidget *hbox, GtkWidget *label, const char *defval)
583{
584 GtkWidget *text, *box;
585
586 gtk_container_add(GTK_CONTAINER(hbox), label);
587
588 box = gtk_hbox_new(FALSE, 3);
589 gtk_container_add(GTK_CONTAINER(hbox), box);
590
591 text = gtk_entry_new();
592 gtk_box_pack_start(GTK_BOX(box), text, TRUE, TRUE, 0);
593 gtk_entry_set_text(GTK_ENTRY(text), "localhost");
594
595 return text;
596}
597
598static GtkWidget *create_spinbutton(GtkWidget *hbox, GtkWidget *label, double min, double max, double defval)
599{
600 GtkWidget *button, *box;
601
602 gtk_container_add(GTK_CONTAINER(hbox), label);
603
604 box = gtk_hbox_new(FALSE, 3);
605 gtk_container_add(GTK_CONTAINER(hbox), box);
606
607 button = gtk_spin_button_new_with_range(min, max, 1.0);
608 gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
609
610 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
611 gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), defval);
612
613 return button;
614}
615
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100616static void init_ui(int *argc, char **argv[], struct gui *ui)
617{
Jens Axboe0420ba62012-02-29 11:16:52 +0100618 GtkSettings *settings;
619 GtkUIManager *uimanager;
Jens Axboe843ad232012-02-29 11:44:53 +0100620 GtkWidget *menu, *probe, *probe_frame, *probe_box;
Jens Axboe0420ba62012-02-29 11:16:52 +0100621
622 memset(ui, 0, sizeof(*ui));
Stephen M. Cameron45032dd2012-02-24 08:17:31 +0100623
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +0100624 /* Magical g*thread incantation, you just need this thread stuff.
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +0100625 * Without it, the update that happens in gfio_update_thread_status
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +0100626 * doesn't really happen in a timely fashion, you need expose events
627 */
628 if (!g_thread_supported ())
629 g_thread_init(NULL);
630 gdk_threads_init();
631
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100632 gtk_init(argc, argv);
Jens Axboe0420ba62012-02-29 11:16:52 +0100633 settings = gtk_settings_get_default();
634 gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "gfio setting");
635 g_type_init();
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100636
637 ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
638 gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
639 gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500);
640
Jens Axboe0420ba62012-02-29 11:16:52 +0100641 g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), NULL);
642 g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), NULL);
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100643
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +0100644 ui->vbox = gtk_vbox_new(FALSE, 0);
645 gtk_container_add(GTK_CONTAINER (ui->window), ui->vbox);
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +0100646
Jens Axboe0420ba62012-02-29 11:16:52 +0100647 uimanager = gtk_ui_manager_new();
648 menu = get_menubar_menu(ui->window, uimanager);
649 gfio_ui_setup(settings, menu, ui->vbox, uimanager);
650
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +0100651 /*
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +0100652 * Set up alignments for widgets at the top of ui,
653 * align top left, expand horizontally but not vertically
654 */
655 ui->topalign = gtk_alignment_new(0, 0, 1, 0);
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100656 ui->topvbox = gtk_vbox_new(FALSE, 3);
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +0100657 gtk_container_add(GTK_CONTAINER(ui->topalign), ui->topvbox);
Stephen M. Camerone1645342012-02-24 08:17:32 +0100658 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->topalign, FALSE, FALSE, 0);
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +0100659
660 /*
Stephen M. Cameron45032dd2012-02-24 08:17:31 +0100661 * Set up hostname label + entry, port label + entry,
662 */
663 ui->hostname_hbox = gtk_hbox_new(FALSE, 0);
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100664
665 ui->hostname_label = gtk_label_new("Hostname:");
666 ui->hostname_entry = create_text_entry(ui->hostname_hbox, ui->hostname_label, "localhost");
667
Stephen M. Cameron45032dd2012-02-24 08:17:31 +0100668 ui->port_label = gtk_label_new("Port:");
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100669 ui->port_button = create_spinbutton(ui->hostname_hbox, ui->port_label, 1, 65535, FIO_NET_PORT);
Stephen M. Cameron45032dd2012-02-24 08:17:31 +0100670
671 /*
672 * Set up combo box for address type
673 */
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100674 ui->hostname_combo_box = gtk_combo_box_text_new();
675 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ui->hostname_combo_box), "IPv4");
676 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ui->hostname_combo_box), "IPv6");
677 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ui->hostname_combo_box), "local socket");
678 gtk_combo_box_set_active(GTK_COMBO_BOX(ui->hostname_combo_box), 0);
Stephen M. Cameron45032dd2012-02-24 08:17:31 +0100679
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100680 gtk_container_add(GTK_CONTAINER(ui->hostname_hbox), ui->hostname_combo_box);
681 gtk_container_add(GTK_CONTAINER(ui->topvbox), ui->hostname_hbox);
Stephen M. Cameron45032dd2012-02-24 08:17:31 +0100682
Jens Axboe3e47bd22012-02-29 13:45:02 +0100683 probe = gtk_frame_new("Job");
Jens Axboe843ad232012-02-29 11:44:53 +0100684 gtk_box_pack_start(GTK_BOX(ui->topvbox), probe, TRUE, FALSE, 3);
685 probe_frame = gtk_vbox_new(FALSE, 3);
686 gtk_container_add(GTK_CONTAINER(probe), probe_frame);
687
688 probe_box = gtk_hbox_new(FALSE, 3);
689 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
Jens Axboe843ad232012-02-29 11:44:53 +0100690 ui->probe.hostname = new_info_label_in_frame(probe_box, "Host");
691 ui->probe.os = new_info_label_in_frame(probe_box, "OS");
692 ui->probe.arch = new_info_label_in_frame(probe_box, "Architecture");
693 ui->probe.fio_ver = new_info_label_in_frame(probe_box, "Fio version");
694
Jens Axboe3e47bd22012-02-29 13:45:02 +0100695 probe_box = gtk_hbox_new(FALSE, 3);
696 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
697 ui->eta.jobs = new_info_label_in_frame(probe_box, "Jobs");
698 ui->eta.files = new_info_label_in_frame(probe_box, "Open files");
699
700 probe_box = gtk_hbox_new(FALSE, 3);
701 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
702 ui->eta.read_bw = new_info_label_in_frame(probe_box, "Read BW");
703 ui->eta.read_iops = new_info_label_in_frame(probe_box, "IOPS");
704 ui->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW");
705 ui->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
706
707 probe_box = gtk_hbox_new(FALSE, 3);
708 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
709 ui->eta.write_bw = new_info_label_in_frame(probe_box, "Write BW");
710 ui->eta.write_iops = new_info_label_in_frame(probe_box, "IOPS");
711 ui->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW");
712 ui->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
713
Stephen M. Cameron45032dd2012-02-24 08:17:31 +0100714 /*
Stephen M. Cameron736f2df2012-02-24 08:17:32 +0100715 * Add a text box for text op messages
716 */
717 ui->textview = gtk_text_view_new();
718 ui->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui->textview));
719 gtk_text_buffer_set_text(ui->text, "", -1);
720 gtk_text_view_set_editable(GTK_TEXT_VIEW(ui->textview), FALSE);
721 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(ui->textview), FALSE);
722 ui->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
723 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui->scrolled_window),
724 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
725 gtk_container_add(GTK_CONTAINER(ui->scrolled_window), ui->textview);
Stephen M. Camerone1645342012-02-24 08:17:32 +0100726 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->scrolled_window,
727 TRUE, TRUE, 0);
Stephen M. Cameron736f2df2012-02-24 08:17:32 +0100728
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +0100729 /*
730 * Set up alignments for widgets at the bottom of ui,
731 * align bottom left, expand horizontally but not vertically
732 */
733 ui->bottomalign = gtk_alignment_new(0, 1, 1, 0);
734 ui->buttonbox = gtk_hbox_new(FALSE, 0);
735 gtk_container_add(GTK_CONTAINER(ui->bottomalign), ui->buttonbox);
Stephen M. Camerone1645342012-02-24 08:17:32 +0100736 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->bottomalign,
737 FALSE, FALSE, 0);
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +0100738
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100739 add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist));
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100740
741 /*
742 * Set up thread status progress bar
743 */
744 ui->thread_status_pb = gtk_progress_bar_new();
745 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), 0.0);
746 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No jobs running");
747 gtk_container_add(GTK_CONTAINER(ui->buttonbox), ui->thread_status_pb);
748
749
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100750 gtk_widget_show_all(ui->window);
751}
752
Stephen M. Cameron8232e282012-02-24 08:17:31 +0100753int main(int argc, char *argv[], char *envp[])
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100754{
Stephen M. Cameron8232e282012-02-24 08:17:31 +0100755 if (initialize_fio(envp))
756 return 1;
Jens Axboe0420ba62012-02-29 11:16:52 +0100757 if (fio_init_options())
758 return 1;
Stephen M. Camerona1820202012-02-24 08:17:31 +0100759
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100760 fio_debug = ~0UL;
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100761 init_ui(&argc, &argv, &ui);
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +0100762
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +0100763 gdk_threads_enter();
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100764 gtk_main();
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +0100765 gdk_threads_leave();
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100766 return 0;
767}