blob: 2c0c2cc5981b9153b31a72595764eb2156c7e638 [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 {
Jens Axboe807f9972012-03-02 10:25:24 +010062 GtkWidget *name;
63 GtkWidget *iotype;
64 GtkWidget *ioengine;
65 GtkWidget *iodepth;
Jens Axboe3e47bd22012-02-29 13:45:02 +010066 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
Stephen M. Cameronff1f3282012-02-24 08:17:30 +010078struct gui {
79 GtkWidget *window;
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +010080 GtkWidget *vbox;
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +010081 GtkWidget *topvbox;
82 GtkWidget *topalign;
83 GtkWidget *bottomalign;
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +010084 GtkWidget *thread_status_pb;
Stephen M. Cameronf3074002012-02-24 08:17:30 +010085 GtkWidget *buttonbox;
86 GtkWidget *button[ARRAYSIZE(buttonspeclist)];
Stephen M. Cameron736f2df2012-02-24 08:17:32 +010087 GtkWidget *scrolled_window;
88 GtkWidget *textview;
Jens Axboe0420ba62012-02-29 11:16:52 +010089 GtkWidget *error_info_bar;
90 GtkWidget *error_label;
Stephen M. Cameron736f2df2012-02-24 08:17:32 +010091 GtkTextBuffer *text;
Jens Axboe843ad232012-02-29 11:44:53 +010092 struct probe_widget probe;
Jens Axboe3e47bd22012-02-29 13:45:02 +010093 struct eta_widget eta;
Jens Axboe3ec62ec2012-03-01 12:01:29 +010094 int connected;
Stephen M. Cameron25927252012-02-24 08:17:31 +010095 pthread_t t;
Jens Axboe0420ba62012-02-29 11:16:52 +010096
Jens Axboe3ec62ec2012-03-01 12:01:29 +010097 struct fio_client *client;
Jens Axboe0420ba62012-02-29 11:16:52 +010098 int nr_job_files;
99 char **job_files;
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +0100100} ui;
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100101
Jens Axboe8663ea62012-03-02 14:04:30 +0100102static void clear_ui_info(struct gui *ui)
103{
104 gtk_label_set_text(GTK_LABEL(ui->probe.hostname), "");
105 gtk_label_set_text(GTK_LABEL(ui->probe.os), "");
106 gtk_label_set_text(GTK_LABEL(ui->probe.arch), "");
107 gtk_label_set_text(GTK_LABEL(ui->probe.fio_ver), "");
Jens Axboeca850992012-03-05 20:04:43 +0100108 gtk_entry_set_text(GTK_ENTRY(ui->eta.name), "");
109 gtk_entry_set_text(GTK_ENTRY(ui->eta.iotype), "");
110 gtk_entry_set_text(GTK_ENTRY(ui->eta.ioengine), "");
111 gtk_entry_set_text(GTK_ENTRY(ui->eta.iodepth), "");
112 gtk_entry_set_text(GTK_ENTRY(ui->eta.jobs), "");
113 gtk_entry_set_text(GTK_ENTRY(ui->eta.files), "");
114 gtk_entry_set_text(GTK_ENTRY(ui->eta.read_bw), "");
115 gtk_entry_set_text(GTK_ENTRY(ui->eta.read_iops), "");
116 gtk_entry_set_text(GTK_ENTRY(ui->eta.write_bw), "");
117 gtk_entry_set_text(GTK_ENTRY(ui->eta.write_iops), "");
Jens Axboe8663ea62012-03-02 14:04:30 +0100118}
119
Jens Axboe3650a3c2012-03-05 14:09:03 +0100120static GtkWidget *new_info_entry_in_frame(GtkWidget *box, const char *label)
121{
122 GtkWidget *entry, *frame;
123
124 frame = gtk_frame_new(label);
125 entry = gtk_entry_new();
Jens Axboe1c1e4a52012-03-05 14:37:38 +0100126 gtk_entry_set_editable(GTK_ENTRY(entry), 0);
Jens Axboe3650a3c2012-03-05 14:09:03 +0100127 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
128 gtk_container_add(GTK_CONTAINER(frame), entry);
129
130 return entry;
131}
132
133static GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label)
134{
135 GtkWidget *label_widget;
136 GtkWidget *frame;
137
138 frame = gtk_frame_new(label);
139 label_widget = gtk_label_new(NULL);
140 gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
141 gtk_container_add(GTK_CONTAINER(frame), label_widget);
142
143 return label_widget;
144}
145
146static GtkWidget *create_spinbutton(GtkWidget *hbox, double min, double max, double defval)
147{
148 GtkWidget *button, *box;
149
150 box = gtk_hbox_new(FALSE, 3);
151 gtk_container_add(GTK_CONTAINER(hbox), box);
152
153 button = gtk_spin_button_new_with_range(min, max, 1.0);
154 gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
155
156 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
157 gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), defval);
158
159 return button;
160}
161
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100162static void gfio_set_connected(struct gui *ui, int connected)
163{
164 if (connected) {
165 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1);
166 ui->connected = 1;
167 gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Disconnect");
168 } else {
169 ui->connected = 0;
170 gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Connect");
171 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0);
172 }
173}
174
Jens Axboe3650a3c2012-03-05 14:09:03 +0100175static void label_set_int_value(GtkWidget *entry, unsigned int val)
176{
177 char tmp[80];
178
179 sprintf(tmp, "%u", val);
180 gtk_label_set_text(GTK_LABEL(entry), tmp);
181}
182
183static void entry_set_int_value(GtkWidget *entry, unsigned int val)
184{
185 char tmp[80];
186
187 sprintf(tmp, "%u", val);
188 gtk_entry_set_text(GTK_ENTRY(entry), tmp);
189}
190
Jens Axboea2697902012-03-05 16:43:49 +0100191#define ALIGN_LEFT 1
192#define ALIGN_RIGHT 2
193#define INVISIBLE 4
194#define UNSORTABLE 8
195
196GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, unsigned int flags)
197{
198 GtkCellRenderer *renderer;
199 GtkTreeViewColumn *col;
200 double xalign = 0.0; /* left as default */
201 PangoAlignment align;
202 gboolean visible;
203
204 align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT :
205 (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT :
206 PANGO_ALIGN_CENTER;
207 visible = !(flags & INVISIBLE);
208
209 renderer = gtk_cell_renderer_text_new();
210 col = gtk_tree_view_column_new();
211
212 gtk_tree_view_column_set_title(col, title);
213 if (!(flags & UNSORTABLE))
214 gtk_tree_view_column_set_sort_column_id(col, index);
215 gtk_tree_view_column_set_resizable(col, TRUE);
216 gtk_tree_view_column_pack_start(col, renderer, TRUE);
217 gtk_tree_view_column_add_attribute(col, renderer, "text", index);
218 gtk_object_set(GTK_OBJECT(renderer), "alignment", align, NULL);
219 switch (align) {
220 case PANGO_ALIGN_LEFT:
221 xalign = 0.0;
222 break;
223 case PANGO_ALIGN_CENTER:
224 xalign = 0.5;
225 break;
226 case PANGO_ALIGN_RIGHT:
227 xalign = 1.0;
228 break;
229 }
230 gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
231 gtk_tree_view_column_set_visible(col, visible);
232 gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
233 return col;
234}
235
236static GtkWidget *gfio_output_clat_percentiles(unsigned int *ovals,
237 fio_fp64_t *plist,
238 unsigned int len,
239 const char *base,
240 unsigned int scale)
241{
242 GType types[FIO_IO_U_LIST_MAX_LEN];
243 GtkWidget *tree_view;
244 GtkTreeSelection *selection;
245 GtkListStore *model;
246 GtkTreeIter iter;
247 int i;
248
249 for (i = 0; i < len; i++)
250 types[i] = G_TYPE_INT;
251
252 model = gtk_list_store_newv(len, types);
253
254 tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
255 gtk_widget_set_can_focus(tree_view, FALSE);
256
257 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
258 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
259
260 for (i = 0; i < len; i++) {
261 char fbuf[8];
262
263 sprintf(fbuf, "%2.2f%%", plist[i].u.f);
264 tree_view_column(tree_view, i, fbuf, ALIGN_RIGHT | UNSORTABLE);
265 }
266
267 gtk_list_store_append(model, &iter);
268
269 for (i = 0; i < len; i++)
270 gtk_list_store_set(model, &iter, i, ovals[i], -1);
271
272 return tree_view;
273}
274
275static void gfio_show_clat_percentiles(GtkWidget *vbox, struct thread_stat *ts,
276 int ddir)
277{
278 unsigned int *io_u_plat = ts->io_u_plat[ddir];
279 unsigned long nr = ts->clat_stat[ddir].samples;
280 fio_fp64_t *plist = ts->percentile_list;
281 unsigned int *ovals, len, minv, maxv, scale_down;
282 const char *base;
283 GtkWidget *tree_view, *frame, *hbox;
284 char tmp[64];
285
286 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
287 if (!len)
288 goto out;
289
290 /*
291 * We default to usecs, but if the value range is such that we
292 * should scale down to msecs, do that.
293 */
294 if (minv > 2000 && maxv > 99999) {
295 scale_down = 1;
296 base = "msec";
297 } else {
298 scale_down = 0;
299 base = "usec";
300 }
301
302 tree_view = gfio_output_clat_percentiles(ovals, plist, len, base, scale_down);
303
304 sprintf(tmp, "Completion percentiles (%s)", base);
305 frame = gtk_frame_new(tmp);
306 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
307
308 hbox = gtk_hbox_new(FALSE, 3);
309 gtk_container_add(GTK_CONTAINER(frame), hbox);
310
311 gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, FALSE, 3);
312out:
313 if (ovals)
314 free(ovals);
315}
316
Jens Axboe3650a3c2012-03-05 14:09:03 +0100317static void gfio_show_lat(GtkWidget *vbox, const char *name, unsigned long min,
318 unsigned long max, double mean, double dev)
319{
320 const char *base = "(usec)";
Jens Axboe1c1e4a52012-03-05 14:37:38 +0100321 GtkWidget *hbox, *label, *frame;
Jens Axboe3650a3c2012-03-05 14:09:03 +0100322 char *minp, *maxp;
323 char tmp[64];
324
325 if (!usec_to_msec(&min, &max, &mean, &dev))
326 base = "(msec)";
327
328 minp = num2str(min, 6, 1, 0);
329 maxp = num2str(max, 6, 1, 0);
330
Jens Axboe3650a3c2012-03-05 14:09:03 +0100331 sprintf(tmp, "%s %s", name, base);
332 frame = gtk_frame_new(tmp);
333 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
334
Jens Axboe3650a3c2012-03-05 14:09:03 +0100335 hbox = gtk_hbox_new(FALSE, 3);
Jens Axboe1c1e4a52012-03-05 14:37:38 +0100336 gtk_container_add(GTK_CONTAINER(frame), hbox);
Jens Axboe3650a3c2012-03-05 14:09:03 +0100337
338 label = new_info_label_in_frame(hbox, "Minimum");
339 gtk_label_set_text(GTK_LABEL(label), minp);
340 label = new_info_label_in_frame(hbox, "Maximum");
341 gtk_label_set_text(GTK_LABEL(label), maxp);
342 label = new_info_label_in_frame(hbox, "Average");
343 sprintf(tmp, "%5.02f", mean);
344 gtk_label_set_text(GTK_LABEL(label), tmp);
345 label = new_info_label_in_frame(hbox, "Standard deviation");
346 sprintf(tmp, "%5.02f", dev);
347 gtk_label_set_text(GTK_LABEL(label), tmp);
348
349 free(minp);
350 free(maxp);
351
352}
353
Jens Axboeca850992012-03-05 20:04:43 +0100354#define GFIO_CLAT 1
355#define GFIO_SLAT 2
356#define GFIO_LAT 4
357
Jens Axboe3650a3c2012-03-05 14:09:03 +0100358static void gfio_show_ddir_status(GtkWidget *mbox, struct group_run_stats *rs,
359 struct thread_stat *ts, int ddir)
360{
361 const char *ddir_label[2] = { "Read", "Write" };
Jens Axboe0b761302012-03-05 20:44:11 +0100362 GtkWidget *frame, *label, *box, *vbox, *main_vbox;
Jens Axboe3650a3c2012-03-05 14:09:03 +0100363 unsigned long min, max, runt;
364 unsigned long long bw, iops;
Jens Axboeca850992012-03-05 20:04:43 +0100365 unsigned int flags = 0;
Jens Axboe3650a3c2012-03-05 14:09:03 +0100366 double mean, dev;
367 char *io_p, *bw_p, *iops_p;
368 int i2p;
369
370 if (!ts->runtime[ddir])
371 return;
372
373 i2p = is_power_of_2(rs->kb_base);
374 runt = ts->runtime[ddir];
375
376 bw = (1000 * ts->io_bytes[ddir]) / runt;
377 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
378 bw_p = num2str(bw, 6, 1, i2p);
379
380 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
381 iops_p = num2str(iops, 6, 1, 0);
382
383 box = gtk_hbox_new(FALSE, 3);
384 gtk_box_pack_start(GTK_BOX(mbox), box, TRUE, FALSE, 3);
385
386 frame = gtk_frame_new(ddir_label[ddir]);
387 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 5);
388
Jens Axboe0b761302012-03-05 20:44:11 +0100389 main_vbox = gtk_vbox_new(FALSE, 3);
390 gtk_container_add(GTK_CONTAINER(frame), main_vbox);
Jens Axboe3650a3c2012-03-05 14:09:03 +0100391
392 box = gtk_hbox_new(FALSE, 3);
Jens Axboe0b761302012-03-05 20:44:11 +0100393 gtk_box_pack_start(GTK_BOX(main_vbox), box, TRUE, FALSE, 3);
Jens Axboe3650a3c2012-03-05 14:09:03 +0100394
395 label = new_info_label_in_frame(box, "IO");
396 gtk_label_set_text(GTK_LABEL(label), io_p);
397 label = new_info_label_in_frame(box, "Bandwidth");
398 gtk_label_set_text(GTK_LABEL(label), bw_p);
399 label = new_info_label_in_frame(box, "IOPS");
400 gtk_label_set_text(GTK_LABEL(label), iops_p);
401 label = new_info_label_in_frame(box, "Runtime (msec)");
402 label_set_int_value(label, ts->runtime[ddir]);
403
Jens Axboe3650a3c2012-03-05 14:09:03 +0100404 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboeca850992012-03-05 20:04:43 +0100405 flags |= GFIO_SLAT;
Jens Axboe3650a3c2012-03-05 14:09:03 +0100406 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboeca850992012-03-05 20:04:43 +0100407 flags |= GFIO_CLAT;
Jens Axboe3650a3c2012-03-05 14:09:03 +0100408 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
Jens Axboeca850992012-03-05 20:04:43 +0100409 flags |= GFIO_LAT;
410
411 if (flags) {
412 frame = gtk_frame_new("Latency");
Jens Axboe0b761302012-03-05 20:44:11 +0100413 gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 5);
Jens Axboeca850992012-03-05 20:04:43 +0100414
415 vbox = gtk_vbox_new(FALSE, 3);
416 gtk_container_add(GTK_CONTAINER(frame), vbox);
417
418 if (flags & GFIO_SLAT)
419 gfio_show_lat(vbox, "Submission latency", min, max, mean, dev);
420 if (flags & GFIO_CLAT)
421 gfio_show_lat(vbox, "Completion latency", min, max, mean, dev);
422 if (flags & GFIO_LAT)
423 gfio_show_lat(vbox, "Total latency", min, max, mean, dev);
424 }
425
Jens Axboea2697902012-03-05 16:43:49 +0100426 if (ts->clat_percentiles)
Jens Axboe0b761302012-03-05 20:44:11 +0100427 gfio_show_clat_percentiles(main_vbox, ts, ddir);
Jens Axboe3650a3c2012-03-05 14:09:03 +0100428
Jens Axboeca850992012-03-05 20:04:43 +0100429 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
430 double p_of_agg = 100.0;
431 const char *bw_str = "KB";
432 char tmp[32];
433
434 if (rs->agg[ddir]) {
435 p_of_agg = mean * 100 / (double) rs->agg[ddir];
436 if (p_of_agg > 100.0)
437 p_of_agg = 100.0;
438 }
439
440 if (mean > 999999.9) {
441 min /= 1000.0;
442 max /= 1000.0;
443 mean /= 1000.0;
444 dev /= 1000.0;
445 bw_str = "MB";
446 }
447
Jens Axboe0b761302012-03-05 20:44:11 +0100448 sprintf(tmp, "Bandwidth (%s)", bw_str);
449 frame = gtk_frame_new(tmp);
450 gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 5);
Jens Axboeca850992012-03-05 20:04:43 +0100451
Jens Axboe0b761302012-03-05 20:44:11 +0100452 box = gtk_hbox_new(FALSE, 3);
453 gtk_container_add(GTK_CONTAINER(frame), box);
Jens Axboeca850992012-03-05 20:04:43 +0100454
Jens Axboe0b761302012-03-05 20:44:11 +0100455 label = new_info_label_in_frame(box, "Minimum");
Jens Axboeca850992012-03-05 20:04:43 +0100456 label_set_int_value(label, min);
Jens Axboe0b761302012-03-05 20:44:11 +0100457 label = new_info_label_in_frame(box, "Maximum");
Jens Axboeca850992012-03-05 20:04:43 +0100458 label_set_int_value(label, max);
Jens Axboe0b761302012-03-05 20:44:11 +0100459 label = new_info_label_in_frame(box, "Percentage of jobs");
Jens Axboeca850992012-03-05 20:04:43 +0100460 sprintf(tmp, "%3.2f%%", p_of_agg);
461 gtk_label_set_text(GTK_LABEL(label), tmp);
Jens Axboe0b761302012-03-05 20:44:11 +0100462 label = new_info_label_in_frame(box, "Average");
Jens Axboeca850992012-03-05 20:04:43 +0100463 sprintf(tmp, "%5.02f", mean);
464 gtk_label_set_text(GTK_LABEL(label), tmp);
Jens Axboe0b761302012-03-05 20:44:11 +0100465 label = new_info_label_in_frame(box, "Standard deviation");
Jens Axboeca850992012-03-05 20:04:43 +0100466 sprintf(tmp, "%5.02f", dev);
467 gtk_label_set_text(GTK_LABEL(label), tmp);
468 }
469
Jens Axboe3650a3c2012-03-05 14:09:03 +0100470 free(io_p);
471 free(bw_p);
472 free(iops_p);
473}
474
Jens Axboee5bd1342012-03-05 21:38:12 +0100475static GtkWidget *gfio_output_lat_buckets(double *lat, unsigned int num,
476 const char **labels)
477{
478 GtkWidget *tree_view;
479 GtkTreeSelection *selection;
480 GtkListStore *model;
481 GtkTreeIter iter;
482 GType *types;
483 int i, skipped;
484
485 /*
486 * Check if all are empty, in which case don't bother
487 */
488 for (i = 0, skipped = 0; i < num; i++)
489 if (lat[i] <= 0.0)
490 skipped++;
491
492 if (skipped == num)
493 return NULL;
494
495 types = malloc(num * sizeof(GType));
496
497 for (i = 0; i < num; i++)
498 types[i] = G_TYPE_STRING;
499
500 model = gtk_list_store_newv(num, types);
501 free(types);
502 types = NULL;
503
504 tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
505 gtk_widget_set_can_focus(tree_view, FALSE);
506
507 selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
508 gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
509
510 for (i = 0; i < num; i++)
511 tree_view_column(tree_view, i, labels[i], ALIGN_RIGHT | UNSORTABLE);
512
513 gtk_list_store_append(model, &iter);
514
515 for (i = 0; i < num; i++) {
516 char fbuf[32];
517
518 if (lat[i] <= 0.0)
519 sprintf(fbuf, "0.00");
520 else
521 sprintf(fbuf, "%3.2f%%", lat[i]);
522
523 gtk_list_store_set(model, &iter, i, fbuf, -1);
524 }
525
526 return tree_view;
527}
528
529static void gfio_show_latency_buckets(GtkWidget *vbox, struct thread_stat *ts)
530{
531 GtkWidget *box, *frame, *tree_view;
532 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
533 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
534 const char *uranges[] = { "2", "4", "10", "20", "50", "100",
535 "250", "500", "750", "1000", };
536 const char *mranges[] = { "2", "4", "10", "20", "50", "100",
537 "250", "500", "750", "1000", "2000",
538 ">= 2000", };
539
540 stat_calc_lat_u(ts, io_u_lat_u);
541 stat_calc_lat_m(ts, io_u_lat_m);
542
543 tree_view = gfio_output_lat_buckets(io_u_lat_u, FIO_IO_U_LAT_U_NR, uranges);
544 if (tree_view) {
545 frame = gtk_frame_new("Latency buckets (usec)");
546 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
547
548 box = gtk_hbox_new(FALSE, 3);
549 gtk_container_add(GTK_CONTAINER(frame), box);
550 gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, FALSE, 3);
551 }
552
553 tree_view = gfio_output_lat_buckets(io_u_lat_m, FIO_IO_U_LAT_M_NR, mranges);
554 if (tree_view) {
555 frame = gtk_frame_new("Latency buckets (msec)");
556 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
557
558 box = gtk_hbox_new(FALSE, 3);
559 gtk_container_add(GTK_CONTAINER(frame), box);
560 gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, FALSE, 3);
561 }
562}
563
Jens Axboe3650a3c2012-03-05 14:09:03 +0100564static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts,
565 struct group_run_stats *rs)
566{
567 GtkWidget *dialog, *box, *vbox, *entry, *content;
568 struct gui *ui = client->client_data;
569
570 gdk_threads_enter();
571
572 dialog = gtk_dialog_new_with_buttons("Results", GTK_WINDOW(ui->window),
573 GTK_DIALOG_DESTROY_WITH_PARENT,
574 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL);
575
576 g_signal_connect_swapped(dialog, "response",
577 G_CALLBACK(gtk_widget_destroy),
578 dialog);
579
580 content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
581
582 vbox = gtk_vbox_new(FALSE, 3);
583 gtk_container_add(GTK_CONTAINER(content), vbox);
584
585 box = gtk_hbox_new(TRUE, 3);
586 gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
587
588 entry = new_info_entry_in_frame(box, "Name");
589 gtk_entry_set_text(GTK_ENTRY(entry), ts->name);
590 if (strlen(ts->description)) {
591 entry = new_info_entry_in_frame(box, "Description");
592 gtk_entry_set_text(GTK_ENTRY(entry), ts->description);
593 }
594 entry = new_info_entry_in_frame(box, "Group ID");
595 entry_set_int_value(entry, ts->groupid);
596 entry = new_info_entry_in_frame(box, "Jobs");
597 entry_set_int_value(entry, ts->members);
598 entry = new_info_entry_in_frame(box, "Error");
599 entry_set_int_value(entry, ts->error);
600 entry = new_info_entry_in_frame(box, "PID");
601 entry_set_int_value(entry, ts->pid);
602
603 if (ts->io_bytes[DDIR_READ])
604 gfio_show_ddir_status(vbox, rs, ts, DDIR_READ);
605 if (ts->io_bytes[DDIR_WRITE])
606 gfio_show_ddir_status(vbox, rs, ts, DDIR_WRITE);
607
Jens Axboee5bd1342012-03-05 21:38:12 +0100608 gfio_show_latency_buckets(vbox, ts);
609
Jens Axboe3650a3c2012-03-05 14:09:03 +0100610 gtk_widget_show_all(dialog);
611
612 gdk_threads_leave();
613}
614
Jens Axboe084d1c62012-03-03 20:28:07 +0100615static void gfio_text_op(struct fio_client *client, struct fio_net_cmd *cmd)
Stephen M. Camerona1820202012-02-24 08:17:31 +0100616{
Jens Axboe807f9972012-03-02 10:25:24 +0100617#if 0
Stephen M. Cameron736f2df2012-02-24 08:17:32 +0100618 GtkTextBuffer *buffer;
619 GtkTextIter end;
620
621 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui.textview));
622 gdk_threads_enter();
623 gtk_text_buffer_get_end_iter(buffer, &end);
624 gtk_text_buffer_insert(buffer, &end, buf, -1);
625 gdk_threads_leave();
626 gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(ui.textview),
627 &end, 0.0, FALSE, 0.0,0.0);
Jens Axboe807f9972012-03-02 10:25:24 +0100628#else
Jens Axboe084d1c62012-03-03 20:28:07 +0100629 fio_client_ops.text_op(client, cmd);
Jens Axboe807f9972012-03-02 10:25:24 +0100630#endif
Stephen M. Camerona1820202012-02-24 08:17:31 +0100631}
632
633static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd)
634{
635 printf("gfio_disk_util_op called\n");
636 fio_client_ops.disk_util(client, cmd);
637}
638
Jens Axboe3650a3c2012-03-05 14:09:03 +0100639extern int sum_stat_clients;
640extern struct thread_stat client_ts;
641extern struct group_run_stats client_gs;
642
643static int sum_stat_nr;
644
Jens Axboe89e5fad2012-03-05 09:21:12 +0100645static void gfio_thread_status_op(struct fio_client *client,
646 struct fio_net_cmd *cmd)
Stephen M. Camerona1820202012-02-24 08:17:31 +0100647{
Jens Axboe3650a3c2012-03-05 14:09:03 +0100648 struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
649
650 gfio_display_ts(client, &p->ts, &p->rs);
651
652 if (sum_stat_clients == 1)
653 return;
654
655 sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
656 sum_group_stats(&client_gs, &p->rs);
657
658 client_ts.members++;
659 client_ts.groupid = p->ts.groupid;
660
661 if (++sum_stat_nr == sum_stat_clients) {
662 strcpy(client_ts.name, "All clients");
663 gfio_display_ts(client, &client_ts, &client_gs);
664 }
Stephen M. Camerona1820202012-02-24 08:17:31 +0100665}
666
Jens Axboe89e5fad2012-03-05 09:21:12 +0100667static void gfio_group_stats_op(struct fio_client *client,
668 struct fio_net_cmd *cmd)
Stephen M. Camerona1820202012-02-24 08:17:31 +0100669{
670 printf("gfio_group_stats_op called\n");
Jens Axboe89e5fad2012-03-05 09:21:12 +0100671 fio_client_ops.group_stats(client, cmd);
Stephen M. Camerona1820202012-02-24 08:17:31 +0100672}
673
Jens Axboe3e47bd22012-02-29 13:45:02 +0100674static void gfio_update_eta(struct jobs_eta *je)
675{
676 static int eta_good;
677 char eta_str[128];
678 char output[256];
679 char tmp[32];
680 double perc = 0.0;
681 int i2p = 0;
682
683 eta_str[0] = '\0';
684 output[0] = '\0';
685
686 if (je->eta_sec != INT_MAX && je->elapsed_sec) {
687 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
688 eta_to_str(eta_str, je->eta_sec);
689 }
690
691 sprintf(tmp, "%u", je->nr_running);
Jens Axboeca850992012-03-05 20:04:43 +0100692 gtk_entry_set_text(GTK_ENTRY(ui.eta.jobs), tmp);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100693 sprintf(tmp, "%u", je->files_open);
Jens Axboeca850992012-03-05 20:04:43 +0100694 gtk_entry_set_text(GTK_ENTRY(ui.eta.files), tmp);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100695
696#if 0
697 if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
698 if (je->m_rate || je->t_rate) {
699 char *tr, *mr;
700
701 mr = num2str(je->m_rate, 4, 0, i2p);
702 tr = num2str(je->t_rate, 4, 0, i2p);
Jens Axboeca850992012-03-05 20:04:43 +0100703 gtk_entry_set_text(GTK_ENTRY(ui.eta);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100704 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
705 free(tr);
706 free(mr);
707 } else if (je->m_iops || je->t_iops)
708 p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
Jens Axboeebbd89c2012-03-02 11:21:13 +0100709
Jens Axboeca850992012-03-05 20:04:43 +0100710 gtk_entry_set_text(GTK_ENTRY(ui.eta.cr_bw), "---");
711 gtk_entry_set_text(GTK_ENTRY(ui.eta.cr_iops), "---");
712 gtk_entry_set_text(GTK_ENTRY(ui.eta.cw_bw), "---");
713 gtk_entry_set_text(GTK_ENTRY(ui.eta.cw_iops), "---");
Jens Axboe3e47bd22012-02-29 13:45:02 +0100714#endif
715
716 if (je->eta_sec != INT_MAX && je->nr_running) {
717 char *iops_str[2];
718 char *rate_str[2];
719
720 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
721 strcpy(output, "-.-% done");
722 else {
723 eta_good = 1;
724 perc *= 100.0;
725 sprintf(output, "%3.1f%% done", perc);
726 }
727
728 rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
729 rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
730
731 iops_str[0] = num2str(je->iops[0], 4, 1, 0);
732 iops_str[1] = num2str(je->iops[1], 4, 1, 0);
733
Jens Axboeca850992012-03-05 20:04:43 +0100734 gtk_entry_set_text(GTK_ENTRY(ui.eta.read_bw), rate_str[0]);
735 gtk_entry_set_text(GTK_ENTRY(ui.eta.read_iops), iops_str[0]);
736 gtk_entry_set_text(GTK_ENTRY(ui.eta.write_bw), rate_str[1]);
737 gtk_entry_set_text(GTK_ENTRY(ui.eta.write_iops), iops_str[1]);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100738
739 free(rate_str[0]);
740 free(rate_str[1]);
741 free(iops_str[0]);
742 free(iops_str[1]);
743 }
744
745 if (eta_str[0]) {
746 char *dst = output + strlen(output);
747
748 sprintf(dst, " - %s", eta_str);
749 }
750
751 gfio_update_thread_status(output, perc);
752}
753
Stephen M. Camerona1820202012-02-24 08:17:31 +0100754static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
755{
Jens Axboe843ad232012-02-29 11:44:53 +0100756 struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
757 const char *os, *arch;
758 char buf[64];
759
760 os = fio_get_os_string(probe->os);
761 if (!os)
762 os = "unknown";
763
764 arch = fio_get_arch_string(probe->arch);
765 if (!arch)
766 os = "unknown";
767
768 if (!client->name)
769 client->name = strdup((char *) probe->hostname);
770
771 gtk_label_set_text(GTK_LABEL(ui.probe.hostname), (char *) probe->hostname);
772 gtk_label_set_text(GTK_LABEL(ui.probe.os), os);
773 gtk_label_set_text(GTK_LABEL(ui.probe.arch), arch);
774 sprintf(buf, "%u.%u.%u", probe->fio_major, probe->fio_minor, probe->fio_patch);
775 gtk_label_set_text(GTK_LABEL(ui.probe.fio_ver), buf);
Stephen M. Camerona1820202012-02-24 08:17:31 +0100776}
777
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +0100778static void gfio_update_thread_status(char *status_message, double perc)
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +0100779{
780 static char message[100];
781 const char *m = message;
782
783 strncpy(message, status_message, sizeof(message) - 1);
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +0100784 gtk_progress_bar_set_text(
785 GTK_PROGRESS_BAR(ui.thread_status_pb), m);
786 gtk_progress_bar_set_fraction(
787 GTK_PROGRESS_BAR(ui.thread_status_pb), perc / 100.0);
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +0100788 gdk_threads_enter();
789 gtk_widget_queue_draw(ui.window);
790 gdk_threads_leave();
791}
792
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100793static void gfio_quit_op(struct fio_client *client)
794{
795 struct gui *ui = client->client_data;
796
797 gfio_set_connected(ui, 0);
798}
799
Jens Axboe807f9972012-03-02 10:25:24 +0100800static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd)
801{
802 struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload;
803 struct gui *ui = client->client_data;
804 char tmp[8];
805 int i;
806
807 p->iodepth = le32_to_cpu(p->iodepth);
808 p->rw = le32_to_cpu(p->rw);
809
810 for (i = 0; i < 2; i++) {
811 p->min_bs[i] = le32_to_cpu(p->min_bs[i]);
812 p->max_bs[i] = le32_to_cpu(p->max_bs[i]);
813 }
814
815 p->numjobs = le32_to_cpu(p->numjobs);
816 p->group_reporting = le32_to_cpu(p->group_reporting);
817
Jens Axboeca850992012-03-05 20:04:43 +0100818 gtk_entry_set_text(GTK_ENTRY(ui->eta.name), (gchar *) p->jobname);
819 gtk_entry_set_text(GTK_ENTRY(ui->eta.iotype), ddir_str(p->rw));
820 gtk_entry_set_text(GTK_ENTRY(ui->eta.ioengine), (gchar *) p->ioengine);
Jens Axboe807f9972012-03-02 10:25:24 +0100821
822 sprintf(tmp, "%u", p->iodepth);
Jens Axboeca850992012-03-05 20:04:43 +0100823 gtk_entry_set_text(GTK_ENTRY(ui->eta.iodepth), tmp);
Jens Axboe807f9972012-03-02 10:25:24 +0100824}
825
Jens Axboeed727a42012-03-02 12:14:40 +0100826static void gfio_client_timed_out(struct fio_client *client)
827{
828 struct gui *ui = client->client_data;
829 GtkWidget *dialog, *label, *content;
830 char buf[256];
831
832 gdk_threads_enter();
833
834 gfio_set_connected(ui, 0);
Jens Axboe88432652012-03-02 19:09:31 +0100835 clear_ui_info(ui);
Jens Axboeed727a42012-03-02 12:14:40 +0100836
837 sprintf(buf, "Client %s: timeout talking to server.\n", client->hostname);
838
839 dialog = gtk_dialog_new_with_buttons("Timed out!",
840 GTK_WINDOW(ui->window),
841 GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
842 GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
843
844 content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
845 label = gtk_label_new((const gchar *) buf);
846 gtk_container_add(GTK_CONTAINER(content), label);
847 gtk_widget_show_all(dialog);
848 gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
849
850 gtk_dialog_run(GTK_DIALOG(dialog));
851 gtk_widget_destroy(dialog);
852
853 gdk_threads_leave();
854}
855
Stephen M. Camerona1820202012-02-24 08:17:31 +0100856struct client_ops gfio_client_ops = {
Jens Axboe0420ba62012-02-29 11:16:52 +0100857 .text_op = gfio_text_op,
858 .disk_util = gfio_disk_util_op,
859 .thread_status = gfio_thread_status_op,
860 .group_stats = gfio_group_stats_op,
Jens Axboea5276612012-03-04 15:15:08 +0100861 .eta = gfio_update_eta,
Jens Axboe0420ba62012-02-29 11:16:52 +0100862 .probe = gfio_probe_op,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100863 .quit = gfio_quit_op,
Jens Axboe807f9972012-03-02 10:25:24 +0100864 .add_job = gfio_add_job_op,
Jens Axboeed727a42012-03-02 12:14:40 +0100865 .timed_out = gfio_client_timed_out,
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100866 .stay_connected = 1,
Stephen M. Camerona1820202012-02-24 08:17:31 +0100867};
868
Stephen M. Cameronff1f3282012-02-24 08:17:30 +0100869static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
870 __attribute__((unused)) gpointer data)
871{
872 gtk_main_quit();
873}
874
Stephen M. Cameron25927252012-02-24 08:17:31 +0100875static void *job_thread(void *arg)
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100876{
Stephen M. Cameron25927252012-02-24 08:17:31 +0100877 fio_handle_clients(&gfio_client_ops);
Stephen M. Cameron25927252012-02-24 08:17:31 +0100878 return NULL;
879}
880
Jens Axboe0420ba62012-02-29 11:16:52 +0100881static int send_job_files(struct gui *ui)
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100882{
Jens Axboe441013b2012-03-01 08:01:52 +0100883 int i, ret = 0;
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100884
Jens Axboe0420ba62012-02-29 11:16:52 +0100885 for (i = 0; i < ui->nr_job_files; i++) {
886 ret = fio_clients_send_ini(ui->job_files[i]);
Jens Axboe441013b2012-03-01 08:01:52 +0100887 if (ret)
888 break;
889
Jens Axboe0420ba62012-02-29 11:16:52 +0100890 free(ui->job_files[i]);
891 ui->job_files[i] = NULL;
Jens Axboe441013b2012-03-01 08:01:52 +0100892 }
893 while (i < ui->nr_job_files) {
894 free(ui->job_files[i]);
895 ui->job_files[i] = NULL;
896 i++;
Jens Axboe0420ba62012-02-29 11:16:52 +0100897 }
898
Jens Axboe441013b2012-03-01 08:01:52 +0100899 return ret;
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100900}
901
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100902static void start_job_thread(struct gui *ui)
Stephen M. Cameron25927252012-02-24 08:17:31 +0100903{
Jens Axboe0420ba62012-02-29 11:16:52 +0100904 if (send_job_files(ui)) {
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100905 printf("Yeah, I didn't really like those options too much.\n");
Stephen M. Cameron60f6b332012-02-24 08:17:32 +0100906 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1);
907 return;
908 }
Stephen M. Cameron25927252012-02-24 08:17:31 +0100909}
910
911static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
912 gpointer data)
913{
914 struct gui *ui = data;
915
Stephen M. Cameron25927252012-02-24 08:17:31 +0100916 gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0);
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100917 start_job_thread(ui);
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100918}
919
Jens Axboedf06f222012-03-02 13:32:04 +0100920static void file_open(GtkWidget *w, gpointer data);
921
922static void connect_clicked(GtkWidget *widget, gpointer data)
Jens Axboe3e47bd22012-02-29 13:45:02 +0100923{
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100924 struct gui *ui = data;
925
926 if (!ui->connected) {
Jens Axboedf06f222012-03-02 13:32:04 +0100927 if (!ui->nr_job_files)
928 file_open(widget, data);
Jens Axboe8663ea62012-03-02 14:04:30 +0100929 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No jobs running");
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100930 fio_clients_connect();
931 pthread_create(&ui->t, NULL, job_thread, NULL);
932 gfio_set_connected(ui, 1);
Jens Axboedf06f222012-03-02 13:32:04 +0100933 } else {
934 fio_clients_terminate();
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100935 gfio_set_connected(ui, 0);
Jens Axboe88432652012-03-02 19:09:31 +0100936 clear_ui_info(ui);
Jens Axboedf06f222012-03-02 13:32:04 +0100937 }
Jens Axboe3e47bd22012-02-29 13:45:02 +0100938}
939
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100940static void add_button(struct gui *ui, int i, GtkWidget *buttonbox,
941 struct button_spec *buttonspec)
942{
943 ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext);
944 g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui);
Jens Axboe3ec62ec2012-03-01 12:01:29 +0100945 gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], FALSE, FALSE, 3);
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100946 gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext);
Jens Axboe3e47bd22012-02-29 13:45:02 +0100947 gtk_widget_set_sensitive(ui->button[i], !buttonspec->start_insensitive);
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100948}
949
950static void add_buttons(struct gui *ui,
951 struct button_spec *buttonlist,
952 int nbuttons)
953{
954 int i;
955
Stephen M. Cameronf3074002012-02-24 08:17:30 +0100956 for (i = 0; i < nbuttons; i++)
957 add_button(ui, i, ui->buttonbox, &buttonlist[i]);
958}
959
Jens Axboe0420ba62012-02-29 11:16:52 +0100960static void on_info_bar_response(GtkWidget *widget, gint response,
961 gpointer data)
962{
963 if (response == GTK_RESPONSE_OK) {
964 gtk_widget_destroy(widget);
965 ui.error_info_bar = NULL;
966 }
967}
968
Jens Axboedf06f222012-03-02 13:32:04 +0100969void report_error(GError *error)
Jens Axboe0420ba62012-02-29 11:16:52 +0100970{
971 if (ui.error_info_bar == NULL) {
972 ui.error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
973 GTK_RESPONSE_OK,
974 NULL);
975 g_signal_connect(ui.error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL);
976 gtk_info_bar_set_message_type(GTK_INFO_BAR(ui.error_info_bar),
977 GTK_MESSAGE_ERROR);
978
979 ui.error_label = gtk_label_new(error->message);
980 GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui.error_info_bar));
981 gtk_container_add(GTK_CONTAINER(container), ui.error_label);
982
983 gtk_box_pack_start(GTK_BOX(ui.vbox), ui.error_info_bar, FALSE, FALSE, 0);
984 gtk_widget_show_all(ui.vbox);
985 } else {
986 char buffer[256];
987 snprintf(buffer, sizeof(buffer), "Failed to open file.");
988 gtk_label_set(GTK_LABEL(ui.error_label), buffer);
989 }
990}
991
Jens Axboeb9f3c7e2012-03-02 14:27:17 +0100992static int get_connection_details(char **host, int *port, int *type,
993 int *server_start)
Jens Axboea7a42ce2012-03-02 13:12:04 +0100994{
995 GtkWidget *dialog, *box, *vbox, *hentry, *hbox, *frame, *pentry, *combo;
Jens Axboeb9f3c7e2012-03-02 14:27:17 +0100996 GtkWidget *button;
Jens Axboea7a42ce2012-03-02 13:12:04 +0100997 char *typeentry;
998
999 dialog = gtk_dialog_new_with_buttons("Connection details",
1000 GTK_WINDOW(ui.window),
1001 GTK_DIALOG_DESTROY_WITH_PARENT,
1002 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1003 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
1004
1005 frame = gtk_frame_new("Hostname / socket name");
1006 vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
1007 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1008
1009 box = gtk_vbox_new(FALSE, 6);
1010 gtk_container_add(GTK_CONTAINER(frame), box);
1011
1012 hbox = gtk_hbox_new(TRUE, 10);
1013 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1014 hentry = gtk_entry_new();
1015 gtk_entry_set_text(GTK_ENTRY(hentry), "localhost");
1016 gtk_box_pack_start(GTK_BOX(hbox), hentry, TRUE, TRUE, 0);
1017
1018 frame = gtk_frame_new("Port");
1019 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1020 box = gtk_vbox_new(FALSE, 10);
1021 gtk_container_add(GTK_CONTAINER(frame), box);
1022
1023 hbox = gtk_hbox_new(TRUE, 4);
1024 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1025 pentry = create_spinbutton(hbox, 1, 65535, FIO_NET_PORT);
1026
1027 frame = gtk_frame_new("Type");
1028 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1029 box = gtk_vbox_new(FALSE, 10);
1030 gtk_container_add(GTK_CONTAINER(frame), box);
1031
1032 hbox = gtk_hbox_new(TRUE, 4);
1033 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1034
1035 combo = gtk_combo_box_text_new();
1036 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "IPv4");
1037 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "IPv6");
1038 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), "local socket");
1039 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
1040
1041 gtk_container_add(GTK_CONTAINER(hbox), combo);
1042
Jens Axboeb9f3c7e2012-03-02 14:27:17 +01001043 frame = gtk_frame_new("Options");
1044 gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1045 box = gtk_vbox_new(FALSE, 10);
1046 gtk_container_add(GTK_CONTAINER(frame), box);
1047
1048 hbox = gtk_hbox_new(TRUE, 4);
1049 gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
1050
1051 button = gtk_check_button_new_with_label("Auto-spawn fio backend");
1052 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), 1);
1053 gtk_widget_set_tooltip_text(button, "When running fio locally, it is necessary to have the backend running on the same system. If this is checked, gfio will start the backend automatically for you if it isn't already running.");
1054 gtk_box_pack_start(GTK_BOX(hbox), button, FALSE, FALSE, 6);
1055
Jens Axboea7a42ce2012-03-02 13:12:04 +01001056 gtk_widget_show_all(dialog);
1057
1058 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
1059 gtk_widget_destroy(dialog);
1060 return 1;
1061 }
1062
1063 *host = strdup(gtk_entry_get_text(GTK_ENTRY(hentry)));
1064 *port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pentry));
1065
1066 typeentry = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(combo));
1067 if (!typeentry || !strncmp(typeentry, "IPv4", 4))
1068 *type = Fio_client_ipv4;
1069 else if (!strncmp(typeentry, "IPv6", 4))
1070 *type = Fio_client_ipv6;
1071 else
1072 *type = Fio_client_socket;
1073 g_free(typeentry);
1074
Jens Axboeb9f3c7e2012-03-02 14:27:17 +01001075 *server_start = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(button));
1076
Jens Axboea7a42ce2012-03-02 13:12:04 +01001077 gtk_widget_destroy(dialog);
1078 return 0;
1079}
1080
Jens Axboe0420ba62012-02-29 11:16:52 +01001081static void file_open(GtkWidget *w, gpointer data)
1082{
1083 GtkWidget *dialog;
1084 GSList *filenames, *fn_glist;
1085 GtkFileFilter *filter;
Jens Axboea7a42ce2012-03-02 13:12:04 +01001086 char *host;
Jens Axboeb9f3c7e2012-03-02 14:27:17 +01001087 int port, type, server_start;
Jens Axboe0420ba62012-02-29 11:16:52 +01001088
1089 dialog = gtk_file_chooser_dialog_new("Open File",
1090 GTK_WINDOW(ui.window),
1091 GTK_FILE_CHOOSER_ACTION_OPEN,
1092 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1093 GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
1094 NULL);
1095 gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE);
1096
1097 filter = gtk_file_filter_new();
1098 gtk_file_filter_add_pattern(filter, "*.fio");
1099 gtk_file_filter_add_pattern(filter, "*.job");
1100 gtk_file_filter_add_mime_type(filter, "text/fio");
1101 gtk_file_filter_set_name(filter, "Fio job file");
1102 gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
1103
1104 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
1105 gtk_widget_destroy(dialog);
1106 return;
1107 }
1108
1109 fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog));
Jens Axboea7a42ce2012-03-02 13:12:04 +01001110
1111 gtk_widget_destroy(dialog);
1112
Jens Axboeb9f3c7e2012-03-02 14:27:17 +01001113 if (get_connection_details(&host, &port, &type, &server_start))
Jens Axboea7a42ce2012-03-02 13:12:04 +01001114 goto err;
1115
Jens Axboe0420ba62012-02-29 11:16:52 +01001116 filenames = fn_glist;
1117 while (filenames != NULL) {
Jens Axboe0420ba62012-02-29 11:16:52 +01001118 ui.job_files = realloc(ui.job_files, (ui.nr_job_files + 1) * sizeof(char *));
1119 ui.job_files[ui.nr_job_files] = strdup(filenames->data);
1120 ui.nr_job_files++;
1121
Jens Axboea5276612012-03-04 15:15:08 +01001122 ui.client = fio_client_add_explicit(&gfio_client_ops, host, type, port);
Jens Axboedf06f222012-03-02 13:32:04 +01001123 if (!ui.client) {
1124 GError *error;
1125
1126 error = g_error_new(g_quark_from_string("fio"), 1,
1127 "Failed to add client %s", host);
Jens Axboe0420ba62012-02-29 11:16:52 +01001128 report_error(error);
1129 g_error_free(error);
Jens Axboe0420ba62012-02-29 11:16:52 +01001130 }
Jens Axboedf06f222012-03-02 13:32:04 +01001131 ui.client->client_data = &ui;
Jens Axboe0420ba62012-02-29 11:16:52 +01001132
1133 g_free(filenames->data);
1134 filenames = g_slist_next(filenames);
1135 }
Jens Axboea7a42ce2012-03-02 13:12:04 +01001136 free(host);
1137err:
Jens Axboe0420ba62012-02-29 11:16:52 +01001138 g_slist_free(fn_glist);
Jens Axboe0420ba62012-02-29 11:16:52 +01001139}
1140
1141static void file_save(GtkWidget *w, gpointer data)
1142{
1143 GtkWidget *dialog;
1144
1145 dialog = gtk_file_chooser_dialog_new("Save File",
1146 GTK_WINDOW(ui.window),
1147 GTK_FILE_CHOOSER_ACTION_SAVE,
1148 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
1149 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
1150 NULL);
1151
1152 gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
1153 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document");
1154
1155 if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
1156 char *filename;
1157
1158 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
1159 // save_job_file(filename);
1160 g_free(filename);
1161 }
1162 gtk_widget_destroy(dialog);
1163}
1164
Jens Axboe46974a72012-03-02 19:34:13 +01001165static void preferences(GtkWidget *w, gpointer data)
1166{
1167 GtkWidget *dialog, *frame, *box, **buttons;
1168 int i;
1169
1170 dialog = gtk_dialog_new_with_buttons("Preferences",
1171 GTK_WINDOW(ui.window),
1172 GTK_DIALOG_DESTROY_WITH_PARENT,
1173 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1174 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1175 NULL);
1176
Jens Axboe0b8d11e2012-03-02 19:44:15 +01001177 frame = gtk_frame_new("Debug logging");
Jens Axboe46974a72012-03-02 19:34:13 +01001178 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), frame, FALSE, FALSE, 5);
1179 box = gtk_hbox_new(FALSE, 6);
1180 gtk_container_add(GTK_CONTAINER(frame), box);
1181
1182 buttons = malloc(sizeof(GtkWidget *) * FD_DEBUG_MAX);
1183
1184 for (i = 0; i < FD_DEBUG_MAX; i++) {
1185 buttons[i] = gtk_check_button_new_with_label(debug_levels[i].name);
Jens Axboe0b8d11e2012-03-02 19:44:15 +01001186 gtk_widget_set_tooltip_text(buttons[i], debug_levels[i].help);
Jens Axboe46974a72012-03-02 19:34:13 +01001187 gtk_box_pack_start(GTK_BOX(box), buttons[i], FALSE, FALSE, 6);
1188 }
1189
1190 gtk_widget_show_all(dialog);
1191
1192 if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
1193 gtk_widget_destroy(dialog);
1194 return;
1195 }
1196
1197 for (i = 0; i < FD_DEBUG_MAX; i++) {
1198 int set;
1199
1200 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(buttons[i]));
1201 if (set)
1202 fio_debug |= (1UL << i);
1203 }
1204
1205 gtk_widget_destroy(dialog);
1206}
1207
Jens Axboe0420ba62012-02-29 11:16:52 +01001208static void about_dialog(GtkWidget *w, gpointer data)
1209{
1210 gtk_show_about_dialog(NULL,
1211 "program-name", "gfio",
1212 "comments", "Gtk2 UI for fio",
1213 "license", "GPLv2",
1214 "version", fio_version_string,
1215 "copyright", "Jens Axboe <axboe@kernel.dk> 2012",
1216 "logo-icon-name", "fio",
1217 /* Must be last: */
1218 NULL, NULL,
1219 NULL);
1220}
1221
1222static GtkActionEntry menu_items[] = {
Jens Axboe46974a72012-03-02 19:34:13 +01001223 { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
1224 { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
1225 { "OpenFile", GTK_STOCK_OPEN, NULL, "<Control>O", NULL, G_CALLBACK(file_open) },
1226 { "SaveFile", GTK_STOCK_SAVE, NULL, "<Control>S", NULL, G_CALLBACK(file_save) },
1227 { "Preferences", GTK_STOCK_PREFERENCES, NULL, "<Control>p", NULL, G_CALLBACK(preferences) },
1228 { "Quit", GTK_STOCK_QUIT, NULL, "<Control>Q", NULL, G_CALLBACK(quit_clicked) },
1229 { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) },
Jens Axboe0420ba62012-02-29 11:16:52 +01001230};
Jens Axboe3e47bd22012-02-29 13:45:02 +01001231static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
Jens Axboe0420ba62012-02-29 11:16:52 +01001232
1233static const gchar *ui_string = " \
1234 <ui> \
1235 <menubar name=\"MainMenu\"> \
1236 <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
1237 <menuitem name=\"Open\" action=\"OpenFile\" /> \
1238 <menuitem name=\"Save\" action=\"SaveFile\" /> \
1239 <separator name=\"Separator\"/> \
Jens Axboe46974a72012-03-02 19:34:13 +01001240 <menuitem name=\"Preferences\" action=\"Preferences\" /> \
1241 <separator name=\"Separator2\"/> \
Jens Axboe0420ba62012-02-29 11:16:52 +01001242 <menuitem name=\"Quit\" action=\"Quit\" /> \
1243 </menu> \
1244 <menu name=\"Help\" action=\"HelpMenuAction\"> \
1245 <menuitem name=\"About\" action=\"About\" /> \
1246 </menu> \
1247 </menubar> \
1248 </ui> \
1249";
1250
1251static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager)
1252{
1253 GtkActionGroup *action_group = gtk_action_group_new("Menu");
1254 GError *error = 0;
1255
1256 action_group = gtk_action_group_new("Menu");
1257 gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0);
1258
1259 gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
1260 gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
1261
1262 gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
1263 return gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
1264}
1265
1266void gfio_ui_setup(GtkSettings *settings, GtkWidget *menubar,
1267 GtkWidget *vbox, GtkUIManager *ui_manager)
1268{
1269 gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
1270}
1271
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001272static void init_ui(int *argc, char **argv[], struct gui *ui)
1273{
Jens Axboe0420ba62012-02-29 11:16:52 +01001274 GtkSettings *settings;
1275 GtkUIManager *uimanager;
Jens Axboe843ad232012-02-29 11:44:53 +01001276 GtkWidget *menu, *probe, *probe_frame, *probe_box;
Jens Axboe0420ba62012-02-29 11:16:52 +01001277
1278 memset(ui, 0, sizeof(*ui));
Stephen M. Cameron45032dd2012-02-24 08:17:31 +01001279
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +01001280 /* Magical g*thread incantation, you just need this thread stuff.
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +01001281 * Without it, the update that happens in gfio_update_thread_status
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +01001282 * doesn't really happen in a timely fashion, you need expose events
1283 */
Jens Axboeed727a42012-03-02 12:14:40 +01001284 if (!g_thread_supported())
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +01001285 g_thread_init(NULL);
1286 gdk_threads_init();
1287
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001288 gtk_init(argc, argv);
Jens Axboe0420ba62012-02-29 11:16:52 +01001289 settings = gtk_settings_get_default();
1290 gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "gfio setting");
1291 g_type_init();
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001292
1293 ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
1294 gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
1295 gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500);
1296
Jens Axboe0420ba62012-02-29 11:16:52 +01001297 g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), NULL);
1298 g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), NULL);
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001299
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +01001300 ui->vbox = gtk_vbox_new(FALSE, 0);
1301 gtk_container_add(GTK_CONTAINER (ui->window), ui->vbox);
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +01001302
Jens Axboe0420ba62012-02-29 11:16:52 +01001303 uimanager = gtk_ui_manager_new();
1304 menu = get_menubar_menu(ui->window, uimanager);
1305 gfio_ui_setup(settings, menu, ui->vbox, uimanager);
1306
Stephen M. Cameron04cc6b72012-02-24 08:17:31 +01001307 /*
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +01001308 * Set up alignments for widgets at the top of ui,
1309 * align top left, expand horizontally but not vertically
1310 */
1311 ui->topalign = gtk_alignment_new(0, 0, 1, 0);
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001312 ui->topvbox = gtk_vbox_new(FALSE, 3);
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +01001313 gtk_container_add(GTK_CONTAINER(ui->topalign), ui->topvbox);
Stephen M. Camerone1645342012-02-24 08:17:32 +01001314 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->topalign, FALSE, FALSE, 0);
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +01001315
Jens Axboe3e47bd22012-02-29 13:45:02 +01001316 probe = gtk_frame_new("Job");
Jens Axboe843ad232012-02-29 11:44:53 +01001317 gtk_box_pack_start(GTK_BOX(ui->topvbox), probe, TRUE, FALSE, 3);
1318 probe_frame = gtk_vbox_new(FALSE, 3);
1319 gtk_container_add(GTK_CONTAINER(probe), probe_frame);
1320
1321 probe_box = gtk_hbox_new(FALSE, 3);
1322 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
Jens Axboe843ad232012-02-29 11:44:53 +01001323 ui->probe.hostname = new_info_label_in_frame(probe_box, "Host");
1324 ui->probe.os = new_info_label_in_frame(probe_box, "OS");
1325 ui->probe.arch = new_info_label_in_frame(probe_box, "Architecture");
1326 ui->probe.fio_ver = new_info_label_in_frame(probe_box, "Fio version");
1327
Jens Axboe3e47bd22012-02-29 13:45:02 +01001328 probe_box = gtk_hbox_new(FALSE, 3);
1329 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
Jens Axboe807f9972012-03-02 10:25:24 +01001330
Jens Axboeca850992012-03-05 20:04:43 +01001331 ui->eta.name = new_info_entry_in_frame(probe_box, "Name");
1332 ui->eta.iotype = new_info_entry_in_frame(probe_box, "IO");
1333 ui->eta.ioengine = new_info_entry_in_frame(probe_box, "IO Engine");
1334 ui->eta.iodepth = new_info_entry_in_frame(probe_box, "IO Depth");
1335 ui->eta.jobs = new_info_entry_in_frame(probe_box, "Jobs");
1336 ui->eta.files = new_info_entry_in_frame(probe_box, "Open files");
Jens Axboe3e47bd22012-02-29 13:45:02 +01001337
1338 probe_box = gtk_hbox_new(FALSE, 3);
1339 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
Jens Axboeca850992012-03-05 20:04:43 +01001340 ui->eta.read_bw = new_info_entry_in_frame(probe_box, "Read BW");
1341 ui->eta.read_iops = new_info_entry_in_frame(probe_box, "IOPS");
1342 ui->eta.write_bw = new_info_entry_in_frame(probe_box, "Write BW");
1343 ui->eta.write_iops = new_info_entry_in_frame(probe_box, "IOPS");
Jens Axboe807f9972012-03-02 10:25:24 +01001344
1345 /*
1346 * Only add this if we have a commit rate
1347 */
1348#if 0
1349 probe_box = gtk_hbox_new(FALSE, 3);
1350 gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
1351
Jens Axboe3e47bd22012-02-29 13:45:02 +01001352 ui->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW");
1353 ui->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
1354
Jens Axboe3e47bd22012-02-29 13:45:02 +01001355 ui->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW");
1356 ui->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
Jens Axboe807f9972012-03-02 10:25:24 +01001357#endif
Jens Axboe3e47bd22012-02-29 13:45:02 +01001358
Stephen M. Cameron45032dd2012-02-24 08:17:31 +01001359 /*
Stephen M. Cameron736f2df2012-02-24 08:17:32 +01001360 * Add a text box for text op messages
1361 */
1362 ui->textview = gtk_text_view_new();
1363 ui->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui->textview));
1364 gtk_text_buffer_set_text(ui->text, "", -1);
1365 gtk_text_view_set_editable(GTK_TEXT_VIEW(ui->textview), FALSE);
1366 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(ui->textview), FALSE);
1367 ui->scrolled_window = gtk_scrolled_window_new(NULL, NULL);
1368 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui->scrolled_window),
1369 GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1370 gtk_container_add(GTK_CONTAINER(ui->scrolled_window), ui->textview);
Stephen M. Camerone1645342012-02-24 08:17:32 +01001371 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->scrolled_window,
1372 TRUE, TRUE, 0);
Stephen M. Cameron736f2df2012-02-24 08:17:32 +01001373
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +01001374 /*
1375 * Set up alignments for widgets at the bottom of ui,
1376 * align bottom left, expand horizontally but not vertically
1377 */
1378 ui->bottomalign = gtk_alignment_new(0, 1, 1, 0);
1379 ui->buttonbox = gtk_hbox_new(FALSE, 0);
1380 gtk_container_add(GTK_CONTAINER(ui->bottomalign), ui->buttonbox);
Stephen M. Camerone1645342012-02-24 08:17:32 +01001381 gtk_box_pack_start(GTK_BOX(ui->vbox), ui->bottomalign,
1382 FALSE, FALSE, 0);
Stephen M. Cameronc36f98d2012-02-24 08:17:32 +01001383
Stephen M. Cameronf3074002012-02-24 08:17:30 +01001384 add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist));
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001385
1386 /*
1387 * Set up thread status progress bar
1388 */
1389 ui->thread_status_pb = gtk_progress_bar_new();
1390 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), 0.0);
Jens Axboe8663ea62012-03-02 14:04:30 +01001391 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No connections");
Jens Axboe3ec62ec2012-03-01 12:01:29 +01001392 gtk_container_add(GTK_CONTAINER(ui->buttonbox), ui->thread_status_pb);
1393
1394
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001395 gtk_widget_show_all(ui->window);
1396}
1397
Stephen M. Cameron8232e282012-02-24 08:17:31 +01001398int main(int argc, char *argv[], char *envp[])
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001399{
Stephen M. Cameron8232e282012-02-24 08:17:31 +01001400 if (initialize_fio(envp))
1401 return 1;
Jens Axboe0420ba62012-02-29 11:16:52 +01001402 if (fio_init_options())
1403 return 1;
Stephen M. Camerona1820202012-02-24 08:17:31 +01001404
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001405 init_ui(&argc, &argv, &ui);
Stephen M. Cameron5b7573a2012-02-24 08:17:31 +01001406
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +01001407 gdk_threads_enter();
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001408 gtk_main();
Stephen M. Cameron2839f0c2012-02-24 08:17:31 +01001409 gdk_threads_leave();
Stephen M. Cameronff1f3282012-02-24 08:17:30 +01001410 return 0;
1411}