Merge branch 'master' into gfio
authorJens Axboe <axboe@kernel.dk>
Thu, 31 Jan 2013 12:23:40 +0000 (13:23 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 31 Jan 2013 12:23:40 +0000 (13:23 +0100)
Conflicts:
Makefile
client.c
configure
fio.c
fio.h
server.c
server.h

Signed-off-by: Jens Axboe <axboe@kernel.dk>
96 files changed:
GFIO-TODO [new file with mode: 0644]
HOWTO
Makefile
backend.c
cairo_text_helpers.c [new file with mode: 0644]
cairo_text_helpers.h [new file with mode: 0644]
cconv.c [new file with mode: 0644]
client.c
client.h [new file with mode: 0644]
configure
debug.h
engines/cpu.c
engines/libaio.c
engines/net.c
eta.c
examples/1mbs_clients [deleted file]
examples/1mbs_clients.fio [new file with mode: 0644]
examples/aio-read [deleted file]
examples/aio-read.fio [new file with mode: 0644]
examples/disk-zone-profile [deleted file]
examples/disk-zone-profile.fio [new file with mode: 0644]
examples/flow [deleted file]
examples/flow.fio [new file with mode: 0644]
examples/fsx [deleted file]
examples/fsx.fio [new file with mode: 0644]
examples/iometer-file-access-server [deleted file]
examples/iometer-file-access-server.fio [new file with mode: 0644]
examples/netio [deleted file]
examples/netio.fio [new file with mode: 0644]
examples/null [deleted file]
examples/null.fio [new file with mode: 0644]
examples/rdmaio-client [deleted file]
examples/rdmaio-client.fio [new file with mode: 0644]
examples/rdmaio-server [deleted file]
examples/rdmaio-server.fio [new file with mode: 0644]
examples/ssd-test [deleted file]
examples/ssd-test.fio [new file with mode: 0644]
examples/surface-scan [deleted file]
examples/surface-scan.fio [new file with mode: 0644]
examples/tiobench-example [deleted file]
examples/tiobench-example.fio [new file with mode: 0644]
filesetup.c
fio.1
fio.c
fio.h
gclient.c [new file with mode: 0644]
gclient.h [new file with mode: 0644]
gcompat.c [new file with mode: 0644]
gcompat.h [new file with mode: 0644]
gerror.c [new file with mode: 0644]
gerror.h [new file with mode: 0644]
gfio.c [new file with mode: 0644]
gfio.h [new file with mode: 0644]
ghelpers.c [new file with mode: 0644]
ghelpers.h [new file with mode: 0644]
goptions.c [new file with mode: 0644]
goptions.h [new file with mode: 0644]
graph.c [new file with mode: 0644]
graph.h [new file with mode: 0644]
init.c
io_ddir.h
ioengine.h
ioengines.c
iolog.c
iolog.h
lib/prio_tree.c [new file with mode: 0644]
lib/prio_tree.h [new file with mode: 0644]
lib/rbtree.c [new file with mode: 0644]
lib/rbtree.h [new file with mode: 0644]
libfio.c
log.c
log.h
memory.c
options.c
options.h
os/os-linux.h
os/os.h
parse.c
parse.h
printing.c [new file with mode: 0644]
printing.h [new file with mode: 0644]
profile.c
profiles/tiobench.c
rbtree.c [deleted file]
rbtree.h [deleted file]
server.c
server.h
stat.c
stat.h
t/jobs/t0001-52c58027 [deleted file]
t/jobs/t0001-52c58027.fio [new file with mode: 0644]
thread_options.h [new file with mode: 0644]
tickmarks.c [new file with mode: 0644]
tickmarks.h [new file with mode: 0644]
verify.c
verify.h

diff --git a/GFIO-TODO b/GFIO-TODO
new file mode 100644 (file)
index 0000000..885ffcb
--- /dev/null
+++ b/GFIO-TODO
@@ -0,0 +1,52 @@
+In no particular order:
+
+- Ability to save job files. Probably in an extended gfio format,
+  so we can include options/settings outside of a fio job file.
+
+- End view improvements:
+
+       - Cleanup the layout
+       - Add ability to save the results
+       - Add ability to load end-results as well
+       - Add ability to request graphs of whatever graphing options
+         the fio job included.
+       - Add ability to graph completion latencies, percentiles, etc.
+
+- Add ability to edit job options:
+
+       - We need an options view after sending a job, that allows us to
+         visually see what was parsed, make changes, resubmit.
+
+       - Job options are already converted across the network and
+         are available in gfio_client->o for view/edit. We'll need
+         a FIO_NET_CMD_UPDATE_OPTIONS command to send them back,
+         and backend support for updating an existing set of options.
+
+- Add support for printing end results, graphs, etc.
+
+- Improve the auto-start backend functionality, it's quite buggy.
+
+- Ensure that it works on OSX and Windows. We'll need a bit of porting
+  work there.
+
+- Persistent store of prefences set. This will need a per-OS bit as well,
+  using gfonf on Linux, registry on Windows, ?? on OSX.
+
+- Ensure that local errors go to our log, instead of being displayed on
+  the console.
+
+- Ensure that the whole connect/send/start button logic is sane. Right
+  now it works when you perform the right sequence, but if you connect
+  and disconnect, things can get confused. We'll need to improve how
+  we store and send job files. Right now they are in ge->job_files[]
+  and are always emptied on send. Keep them around?
+
+- Commit rate display is not enabled.
+
+- Group status reporting is not enabled.
+
+- Split gfio.c a bit. Add gfio/ sub directory, and split it into
+  files based on functionality. It's already ~3000 lines long.
+
+- Attempt to ensure that we work with gtk 2.10 and newer. Right
+  now the required version is ~2.18 (not quite known).
diff --git a/HOWTO b/HOWTO
index c46b883..f7948c3 100644 (file)
--- a/HOWTO
+++ b/HOWTO
@@ -1229,12 +1229,6 @@ exec_postrun=str After the job completes, issue the command specified
 ioscheduler=str        Attempt to switch the device hosting the file to the specified
                io scheduler before running.
 
-cpuload=int    If the job is a CPU cycle eater, attempt to use the specified
-               percentage of CPU cycles.
-
-cpuchunks=int  If the job is a CPU cycle eater, split the load into
-               cycles of the given time. In microseconds.
-
 disk_util=bool Generate disk utilization statistics, if the platform
                supports it. Defaults to on.
 
@@ -1394,6 +1388,11 @@ that defines them is selected.
                enabled when polling for a minimum of 0 events (eg when
                iodepth_batch_complete=0).
 
+[cpu] cpuload=int Attempt to use the specified percentage of CPU cycles.
+
+[cpu] cpuchunks=int Split the load into cycles of the given time. In
+               microseconds.
+
 [netsplice] hostname=str
 [net] hostname=str The host name or IP address to use for TCP or UDP based IO.
                If the job is a TCP listener or UDP reader, the hostname is not
index a4a478d..0e79720 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@ DEBUGFLAGS = -D_FORTIFY_SOURCE=2 -DFIO_INC_DEBUG
 CPPFLAGS= -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 $(DEBUGFLAGS)
 OPTFLAGS= -O3 -g -ffast-math $(EXTFLAGS)
 CFLAGS = -std=gnu99 -Wwrite-strings -Wall $(OPTFLAGS)
-LIBS   = -lm $(EXTLIBS)
+LIBS   = -lm -lz $(EXTLIBS)
 PROGS  = fio
 SCRIPTS = fio_generate_plots
 UNAME  := $(shell uname)
@@ -21,15 +21,19 @@ all:
 include config-host.mak
 endif
 
-SOURCE := gettime.c fio.c ioengines.c init.c stat.c log.c time.c filesetup.c \
+ifdef CONFIG_GFIO
+  PROGS += gfio
+endif
+
+SOURCE := gettime.c ioengines.c init.c stat.c log.c time.c filesetup.c \
                eta.c verify.c memory.c io_u.c parse.c mutex.c options.c \
-               rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
+               lib/rbtree.c smalloc.c filehash.c profile.c debug.c lib/rand.c \
                lib/num2str.c lib/ieee754.c $(wildcard crc/*.c) engines/cpu.c \
                engines/mmap.c engines/sync.c engines/null.c engines/net.c \
                memalign.c server.c client.c iolog.c backend.c libfio.c flow.c \
-               json.c lib/zipf.c lib/axmap.c lib/lfsr.c gettime-thread.c \
-               helpers.c lib/flist_sort.c lib/hweight.c lib/getrusage.c \
-               idletime.c
+               cconv.c lib/prio_tree.c json.c lib/zipf.c lib/axmap.c \
+               lib/lfsr.c gettime-thread.c helpers.c lib/flist_sort.c \
+               lib/hweight.c lib/getrusage.c idletime.c
 
 ifdef CONFIG_64BIT_LLP64
   CFLAGS += -DBITS_PER_LONG=32
@@ -124,6 +128,9 @@ ifneq (,$(findstring CYGWIN,$(UNAME)))
 endif
 
 OBJS = $(SOURCE:.c=.o)
+FIO_OBJS = $(OBJS) fio.o
+GFIO_OBJS = $(OBJS) gfio.o graph.o tickmarks.o ghelpers.o goptions.o gerror.o \
+                       gclient.o gcompat.o cairo_text_helpers.o printing.o
 
 T_SMALLOC_OBJS = t/stest.o
 T_SMALLOC_OBJS += gettime.o mutex.o smalloc.o t/log.o
@@ -185,28 +192,58 @@ CFLAGS += -DFIO_VERSION='"$(FIO_VERSION)"'
 init.o: FIO-VERSION-FILE
        $(QUIET_CC)$(CC) -o init.o $(CFLAGS) $(CPPFLAGS) -c init.c
 
+gcompat.o: gcompat.c gcompat.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c gcompat.c
+
+goptions.o: goptions.c goptions.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c goptions.c
+
+ghelpers.o: ghelpers.c ghelpers.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c ghelpers.c
+
+gerror.o: gerror.c gerror.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c gerror.c
+
+gclient.o: gclient.c gclient.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c gclient.c
+
+gfio.o: gfio.c ghelpers.c
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c gfio.c
+
+graph.o: graph.c graph.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c graph.c
+
+cairo_text_helpers.o: cairo_text_helpers.c cairo_text_helpers.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c cairo_text_helpers.c
+
+printing.o: printing.c printing.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c printing.c
+
 t/stest: $(T_SMALLOC_OBJS)
        $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_SMALLOC_OBJS) $(LIBS) $(LDFLAGS)
 
 t/ieee754: $(T_IEEE_OBJS)
        $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_IEEE_OBJS) $(LIBS) $(LDFLAGS)
 
+fio: $(FIO_OBJS)
+       $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(FIO_OBJS) $(LIBS) $(LDFLAGS)
+
+gfio: $(GFIO_OBJS)
+       $(QUIET_CC)$(CC) $(LIBS) -o gfio $(GFIO_OBJS) $(LIBS) $(GTK_LDFLAGS)
+
 t/genzipf: $(T_ZIPF_OBJS)
        $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_ZIPF_OBJS) $(LIBS) $(LDFLAGS)
 
 t/axmap: $(T_AXMAP_OBJS)
        $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(T_AXMAP_OBJS) $(LIBS) $(LDFLAGS)
 
-fio: $(OBJS)
-       $(QUIET_CC)$(CC) $(LDFLAGS) $(CFLAGS) -o $@ $(OBJS) $(LIBS) $(LDFLAGS)
-
 .depend: $(SOURCE)
        $(QUIET_DEP)$(CC) -MM $(CFLAGS) $(CPPFLAGS) $(SOURCE) 1> .depend
 
 $(PROGS): .depend
 
 clean: FORCE
-       -rm -f .depend $(OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core FIO-VERSION-FILE config-host.mak cscope.out
+       -rm -f .depend $(GFIO_OBJS) $(OBJS) $(T_OBJS) $(PROGS) $(T_PROGS) core.* core gfio FIO-VERSION-FILE config-host.mak cscope.out
 
 cscope:
        @cscope -b -R
@@ -221,3 +258,5 @@ install: $(PROGS) $(SCRIPTS) FORCE
 ifneq ($(wildcard .depend),)
 include .depend
 endif
+
+
index 218ae25..49d6bc7 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -61,14 +61,14 @@ static struct flist_head *cgroup_list;
 static char *cgroup_mnt;
 static int exit_value;
 static volatile int fio_abort;
+static unsigned int nr_process = 0;
+static unsigned int nr_thread = 0;
 
 struct io_log *agg_io_log[DDIR_RWDIR_CNT];
 
 int groupid = 0;
 unsigned int thread_number = 0;
 unsigned int stat_number = 0;
-unsigned int nr_process = 0;
-unsigned int nr_thread = 0;
 int shm_id = 0;
 int temp_stall_ts;
 unsigned long done_secs = 0;
@@ -1047,10 +1047,12 @@ static void *thread_main(void *data)
 {
        unsigned long long elapsed;
        struct thread_data *td = data;
+       struct thread_options *o = &td->o;
        pthread_condattr_t attr;
        int clear_state;
+       int ret;
 
-       if (!td->o.use_thread) {
+       if (!o->use_thread) {
                setsid();
                td->pid = getpid();
        } else
@@ -1060,6 +1062,9 @@ static void *thread_main(void *data)
 
        dprint(FD_PROCESS, "jobs pid=%d started\n", (int) td->pid);
 
+       if (is_backend)
+               fio_server_send_start(td);
+
        INIT_FLIST_HEAD(&td->io_u_freelist);
        INIT_FLIST_HEAD(&td->io_u_busylist);
        INIT_FLIST_HEAD(&td->io_u_requeues);
@@ -1087,16 +1092,17 @@ static void *thread_main(void *data)
         * eating a file descriptor
         */
        fio_mutex_remove(td->mutex);
+       td->mutex = NULL;
 
        /*
         * A new gid requires privilege, so we need to do this before setting
         * the uid.
         */
-       if (td->o.gid != -1U && setgid(td->o.gid)) {
+       if (o->gid != -1U && setgid(o->gid)) {
                td_verror(td, errno, "setgid");
                goto err;
        }
-       if (td->o.uid != -1U && setuid(td->o.uid)) {
+       if (o->uid != -1U && setuid(o->uid)) {
                td_verror(td, errno, "setuid");
                goto err;
        }
@@ -1105,16 +1111,19 @@ static void *thread_main(void *data)
         * If we have a gettimeofday() thread, make sure we exclude that
         * thread from this job
         */
-       if (td->o.gtod_cpu)
-               fio_cpu_clear(&td->o.cpumask, td->o.gtod_cpu);
+       if (o->gtod_cpu)
+               fio_cpu_clear(&o->cpumask, o->gtod_cpu);
 
        /*
         * Set affinity first, in case it has an impact on the memory
         * allocations.
         */
-       if (td->o.cpumask_set && fio_setaffinity(td->pid, td->o.cpumask) == -1) {
-               td_verror(td, errno, "cpu_set_affinity");
-               goto err;
+       if (o->cpumask_set) {
+               ret = fio_setaffinity(td->pid, o->cpumask);
+               if (ret == -1) {
+                       td_verror(td, errno, "cpu_set_affinity");
+                       goto err;
+               }
        }
 
 #ifdef CONFIG_LIBNUMA
@@ -1170,11 +1179,12 @@ static void *thread_main(void *data)
        if (init_io_u(td))
                goto err;
 
-       if (td->o.verify_async && verify_async_init(td))
+       if (o->verify_async && verify_async_init(td))
                goto err;
 
-       if (td->ioprio_set) {
-               if (ioprio_set(IOPRIO_WHO_PROCESS, 0, td->ioprio) == -1) {
+       if (o->ioprio) {
+               ret = ioprio_set(IOPRIO_WHO_PROCESS, 0, o->ioprio_class, o->ioprio);
+               if (ret == -1) {
                        td_verror(td, errno, "ioprio_set");
                        goto err;
                }
@@ -1184,15 +1194,15 @@ static void *thread_main(void *data)
                goto err;
 
        errno = 0;
-       if (nice(td->o.nice) == -1 && errno != 0) {
+       if (nice(o->nice) == -1 && errno != 0) {
                td_verror(td, errno, "nice");
                goto err;
        }
 
-       if (td->o.ioscheduler && switch_ioscheduler(td))
+       if (o->ioscheduler && switch_ioscheduler(td))
                goto err;
 
-       if (!td->o.create_serialize && setup_files(td))
+       if (!o->create_serialize && setup_files(td))
                goto err;
 
        if (td_io_init(td))
@@ -1201,16 +1211,16 @@ static void *thread_main(void *data)
        if (init_random_map(td))
                goto err;
 
-       if (td->o.exec_prerun) {
-               if (exec_string(td->o.exec_prerun))
-                       goto err;
-       }
+       if (o->exec_prerun && exec_string(o->exec_prerun))
+               goto err;
 
-       if (td->o.pre_read) {
+       if (o->pre_read) {
                if (pre_read_files(td) < 0)
                        goto err;
        }
 
+       fio_verify_init(td);
+
        fio_gettime(&td->epoch, NULL);
        fio_getrusage(&td->ru_start);
        clear_state = 0;
@@ -1283,6 +1293,8 @@ static void *thread_main(void *data)
        td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
        td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
 
+       fio_unpin_memory(td);
+
        fio_mutex_down(writeout_mutex);
        if (td->bw_log) {
                if (td->o.bw_log_file) {
@@ -1340,8 +1352,8 @@ err:
        close_ioengine(td);
        cgroup_shutdown(td, &cgroup_mnt);
 
-       if (td->o.cpumask_set) {
-               int ret = fio_cpuset_exit(&td->o.cpumask);
+       if (o->cpumask_set) {
+               int ret = fio_cpuset_exit(&o->cpumask);
 
                td_verror(td, ret, "fio_cpuset_exit");
        }
@@ -1495,9 +1507,6 @@ static void run_threads(void)
        unsigned long spent;
        unsigned int i, todo, nr_running, m_rate, t_rate, nr_started;
 
-       if (fio_pin_memory())
-               return;
-
        if (fio_gtod_offload && fio_start_gtod_thread())
                return;
        
@@ -1505,6 +1514,14 @@ static void run_threads(void)
 
        set_sig_handlers();
 
+       nr_thread = nr_process = 0;
+       for_each_td(td, i) {
+               if (td->o.use_thread)
+                       nr_thread++;
+               else
+                       nr_process++;
+       }
+
        if (output_format == FIO_OUTPUT_NORMAL) {
                log_info("Starting ");
                if (nr_thread)
@@ -1707,27 +1724,18 @@ static void run_threads(void)
 
                reap_threads(&nr_running, &t_rate, &m_rate);
 
-               if (todo) {
-                       if (is_backend)
-                               fio_server_idle_loop();
-                       else
-                               usleep(100000);
-               }
+               if (todo)
+                       usleep(100000);
        }
 
        while (nr_running) {
                reap_threads(&nr_running, &t_rate, &m_rate);
-
-               if (is_backend)
-                       fio_server_idle_loop();
-               else
-                       usleep(10000);
+               usleep(10000);
        }
 
        fio_idle_prof_stop();
 
        update_io_ticks();
-       fio_unpin_memory();
 }
 
 void wait_for_disk_thread_exit(void)
@@ -1805,9 +1813,9 @@ int fio_backend(void)
                return 0;
 
        if (write_bw_log) {
-               setup_log(&agg_io_log[DDIR_READ], 0);
-               setup_log(&agg_io_log[DDIR_WRITE], 0);
-               setup_log(&agg_io_log[DDIR_TRIM], 0);
+               setup_log(&agg_io_log[DDIR_READ], 0, IO_LOG_TYPE_BW);
+               setup_log(&agg_io_log[DDIR_WRITE], 0, IO_LOG_TYPE_BW);
+               setup_log(&agg_io_log[DDIR_TRIM], 0, IO_LOG_TYPE_BW);
        }
 
        startup_mutex = fio_mutex_init(FIO_MUTEX_LOCKED);
diff --git a/cairo_text_helpers.c b/cairo_text_helpers.c
new file mode 100644 (file)
index 0000000..19fb8e0
--- /dev/null
@@ -0,0 +1,85 @@
+#include <cairo.h>
+#include <gtk/gtk.h>
+#include <math.h>
+
+static void draw_aligned_text(cairo_t *cr, const char *font, double x, double y,
+                              double fontsize, const char *text, int alignment)
+{
+#define CENTERED 0
+#define LEFT_JUSTIFIED 1
+#define RIGHT_JUSTIFIED 2
+
+       double factor, direction;
+       cairo_text_extents_t extents;
+
+       switch (alignment) {
+               case CENTERED:
+                       direction = -1.0;
+                       factor = 0.5;
+                       break;
+               case RIGHT_JUSTIFIED:
+                       direction = -1.0;
+                       factor = 1.0;
+                       break;
+               case LEFT_JUSTIFIED:
+               default:
+                       direction = 1.0;
+                       factor = 0.0;
+                       break;
+       }
+       cairo_select_font_face(cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+
+       cairo_set_font_size(cr, fontsize);
+       cairo_text_extents(cr, text, &extents);
+       x = x + direction * (factor * extents.width  + extents.x_bearing);
+       y = y - (extents.height / 2 + extents.y_bearing);
+
+       cairo_move_to(cr, x, y);
+       cairo_show_text(cr, text);
+}
+
+void draw_centered_text(cairo_t *cr, const char *font, double x, double y,
+                              double fontsize, const char *text)
+{
+       draw_aligned_text(cr, font, x, y, fontsize, text, CENTERED);
+}
+
+void draw_right_justified_text(cairo_t *cr, const char *font,
+                               double x, double y,
+                               double fontsize, const char *text)
+{
+       draw_aligned_text(cr, font, x, y, fontsize, text, RIGHT_JUSTIFIED);
+}
+
+void draw_left_justified_text(cairo_t *cr, const char *font,
+                               double x, double y,
+                               double fontsize, const char *text)
+{
+       draw_aligned_text(cr, font, x, y, fontsize, text, LEFT_JUSTIFIED);
+}
+
+void draw_vertical_centered_text(cairo_t *cr, const char *font, double x,
+                                       double y, double fontsize,
+                                       const char *text)
+{
+       double sx, sy;
+       cairo_text_extents_t extents;
+
+       cairo_select_font_face(cr, font, CAIRO_FONT_SLANT_NORMAL, CAIRO_FONT_WEIGHT_NORMAL);
+
+       cairo_set_font_size(cr, fontsize);
+       cairo_text_extents(cr, text, &extents);
+       sx = x;
+       sy = y;
+       y = y + (extents.width / 2.0 + extents.x_bearing);
+       x = x - (extents.height / 2.0 + extents.y_bearing);
+
+       cairo_move_to(cr, x, y);
+       cairo_save(cr);
+       cairo_translate(cr, -sx, -sy);
+       cairo_rotate(cr, -90.0 * M_PI / 180.0);
+       cairo_translate(cr, sx, sy);
+       cairo_show_text(cr, text);
+       cairo_restore(cr);
+}
+
diff --git a/cairo_text_helpers.h b/cairo_text_helpers.h
new file mode 100644 (file)
index 0000000..014001a
--- /dev/null
@@ -0,0 +1,18 @@
+#ifndef CAIRO_TEXT_HELPERS_H
+#define CAIRO_TEXT_HELPERS_H
+
+void draw_centered_text(cairo_t *cr, const char *font, double x, double y,
+                              double fontsize, const char *text);
+
+void draw_right_justified_text(cairo_t *cr, const char *font,
+                               double x, double y,
+                               double fontsize, const char *text);
+
+void draw_left_justified_text(cairo_t *cr, const char *font,
+                               double x, double y,
+                               double fontsize, const char *text);
+
+void draw_vertical_centered_text(cairo_t *cr, const char *font, double x,
+                                       double y, double fontsize,
+                                       const char *text);
+#endif
diff --git a/cconv.c b/cconv.c
new file mode 100644 (file)
index 0000000..3a8572e
--- /dev/null
+++ b/cconv.c
@@ -0,0 +1,418 @@
+#include <string.h>
+
+#include "thread_options.h"
+
+static void string_to_cpu(char **dst, const uint8_t *src)
+{
+       const char *__src = (const char *) src;
+
+       if (strlen(__src))
+               *dst = strdup(__src);
+}
+
+static void string_to_net(uint8_t *dst, const char *src)
+{
+       if (src)
+               strcpy((char *) dst, src);
+       else
+               dst[0] = '\0';
+}
+
+void convert_thread_options_to_cpu(struct thread_options *o,
+                                  struct thread_options_pack *top)
+{
+       int i, j;
+
+       string_to_cpu(&o->description, top->description);
+       string_to_cpu(&o->name, top->name);
+       string_to_cpu(&o->directory, top->directory);
+       string_to_cpu(&o->filename, top->filename);
+       string_to_cpu(&o->opendir, top->opendir);
+       string_to_cpu(&o->ioengine, top->ioengine);
+       string_to_cpu(&o->mmapfile, top->mmapfile);
+       string_to_cpu(&o->read_iolog_file, top->read_iolog_file);
+       string_to_cpu(&o->write_iolog_file, top->write_iolog_file);
+       string_to_cpu(&o->bw_log_file, top->bw_log_file);
+       string_to_cpu(&o->lat_log_file, top->lat_log_file);
+       string_to_cpu(&o->iops_log_file, top->iops_log_file);
+       string_to_cpu(&o->replay_redirect, top->replay_redirect);
+       string_to_cpu(&o->exec_prerun, top->exec_prerun);
+       string_to_cpu(&o->exec_postrun, top->exec_postrun);
+       string_to_cpu(&o->ioscheduler, top->ioscheduler);
+       string_to_cpu(&o->profile, top->profile);
+       string_to_cpu(&o->cgroup, top->cgroup);
+
+       o->td_ddir = le32_to_cpu(top->td_ddir);
+       o->rw_seq = le32_to_cpu(top->rw_seq);
+       o->kb_base = le32_to_cpu(top->kb_base);
+       o->ddir_seq_nr = le32_to_cpu(top->ddir_seq_nr);
+       o->ddir_seq_add = le64_to_cpu(top->ddir_seq_add);
+       o->iodepth = le32_to_cpu(top->iodepth);
+       o->iodepth_low = le32_to_cpu(top->iodepth_low);
+       o->iodepth_batch = le32_to_cpu(top->iodepth_batch);
+       o->iodepth_batch_complete = le32_to_cpu(top->iodepth_batch_complete);
+       o->size = le64_to_cpu(top->size);
+       o->size_percent = le32_to_cpu(top->size_percent);
+       o->fill_device = le32_to_cpu(top->fill_device);
+       o->file_size_low = le64_to_cpu(top->file_size_low);
+       o->file_size_high = le64_to_cpu(top->file_size_high);
+       o->start_offset = le64_to_cpu(top->start_offset);
+
+       for (i = 0; i < DDIR_RWDIR_CNT; i++) {
+               o->bs[i] = le32_to_cpu(top->bs[i]);
+               o->ba[i] = le32_to_cpu(top->ba[i]);
+               o->min_bs[i] = le32_to_cpu(top->min_bs[i]);
+               o->max_bs[i] = le32_to_cpu(top->max_bs[i]);
+               o->bssplit_nr[i] = le32_to_cpu(top->bssplit_nr[i]);
+
+               if (o->bssplit_nr[i]) {
+                       o->bssplit[i] = malloc(o->bssplit_nr[i] * sizeof(struct bssplit));
+                       for (j = 0; j < o->bssplit_nr[i]; j++) {
+                               o->bssplit[i][j].bs = le32_to_cpu(top->bssplit[i][j].bs);
+                               o->bssplit[i][j].perc = le32_to_cpu(top->bssplit[i][j].perc);
+                       }
+               }
+
+               o->rwmix[i] = le32_to_cpu(top->rwmix[i]);
+               o->rate[i] = le32_to_cpu(top->rate[i]);
+               o->ratemin[i] = le32_to_cpu(top->ratemin[i]);
+               o->rate_iops[i] = le32_to_cpu(top->rate_iops[i]);
+               o->rate_iops_min[i] = le32_to_cpu(top->rate_iops_min[i]);
+       }
+
+       o->ratecycle = le32_to_cpu(top->ratecycle);
+       o->nr_files = le32_to_cpu(top->nr_files);
+       o->open_files = le32_to_cpu(top->open_files);
+       o->file_lock_mode = le32_to_cpu(top->file_lock_mode);
+       o->lockfile_batch = le32_to_cpu(top->lockfile_batch);
+       o->odirect = le32_to_cpu(top->odirect);
+       o->invalidate_cache = le32_to_cpu(top->invalidate_cache);
+       o->create_serialize = le32_to_cpu(top->create_serialize);
+       o->create_fsync = le32_to_cpu(top->create_fsync);
+       o->create_on_open = le32_to_cpu(top->create_on_open);
+       o->create_only = le32_to_cpu(top->create_only);
+       o->end_fsync = le32_to_cpu(top->end_fsync);
+       o->pre_read = le32_to_cpu(top->pre_read);
+       o->sync_io = le32_to_cpu(top->sync_io);
+       o->verify = le32_to_cpu(top->verify);
+       o->do_verify = le32_to_cpu(top->do_verify);
+       o->verifysort = le32_to_cpu(top->verifysort);
+       o->verifysort_nr = le32_to_cpu(top->verifysort_nr);
+       o->experimental_verify = le32_to_cpu(top->experimental_verify);
+       o->verify_interval = le32_to_cpu(top->verify_interval);
+       o->verify_offset = le32_to_cpu(top->verify_offset);
+
+       memcpy(o->verify_pattern, top->verify_pattern, MAX_PATTERN_SIZE);
+
+       o->verify_pattern_bytes = le32_to_cpu(top->verify_pattern_bytes);
+       o->verify_fatal = le32_to_cpu(top->verify_fatal);
+       o->verify_dump = le32_to_cpu(top->verify_dump);
+       o->verify_async = le32_to_cpu(top->verify_async);
+       o->verify_batch = le32_to_cpu(top->verify_batch);
+       o->use_thread = le32_to_cpu(top->use_thread);
+       o->unlink = le32_to_cpu(top->unlink);
+       o->do_disk_util = le32_to_cpu(top->do_disk_util);
+       o->override_sync = le32_to_cpu(top->override_sync);
+       o->rand_repeatable = le32_to_cpu(top->rand_repeatable);
+       o->use_os_rand = le32_to_cpu(top->use_os_rand);
+       o->log_avg_msec = le32_to_cpu(top->log_avg_msec);
+       o->norandommap = le32_to_cpu(top->norandommap);
+       o->softrandommap = le32_to_cpu(top->softrandommap);
+       o->bs_unaligned = le32_to_cpu(top->bs_unaligned);
+       o->fsync_on_close = le32_to_cpu(top->fsync_on_close);
+       o->random_distribution = le32_to_cpu(top->random_distribution);
+       o->zipf_theta.u.f = fio_uint64_to_double(le64_to_cpu(top->zipf_theta.u.i));
+       o->pareto_h.u.f = fio_uint64_to_double(le64_to_cpu(top->pareto_h.u.i));
+       o->random_generator = le32_to_cpu(top->random_generator);
+       o->hugepage_size = le32_to_cpu(top->hugepage_size);
+       o->rw_min_bs = le32_to_cpu(top->rw_min_bs);
+       o->thinktime = le32_to_cpu(top->thinktime);
+       o->thinktime_spin = le32_to_cpu(top->thinktime_spin);
+       o->thinktime_blocks = le32_to_cpu(top->thinktime_blocks);
+       o->fsync_blocks = le32_to_cpu(top->fsync_blocks);
+       o->fdatasync_blocks = le32_to_cpu(top->fdatasync_blocks);
+       o->barrier_blocks = le32_to_cpu(top->barrier_blocks);
+
+       o->verify_backlog = le64_to_cpu(top->verify_backlog);
+       o->start_delay = le64_to_cpu(top->start_delay);
+       o->timeout = le64_to_cpu(top->timeout);
+       o->ramp_time = le64_to_cpu(top->ramp_time);
+       o->zone_range = le64_to_cpu(top->zone_range);
+       o->zone_size = le64_to_cpu(top->zone_size);
+       o->zone_skip = le64_to_cpu(top->zone_skip);
+       o->lockmem = le64_to_cpu(top->lockmem);
+       o->offset_increment = le64_to_cpu(top->offset_increment);
+
+       o->overwrite = le32_to_cpu(top->overwrite);
+       o->bw_avg_time = le32_to_cpu(top->bw_avg_time);
+       o->iops_avg_time = le32_to_cpu(top->iops_avg_time);
+       o->loops = le32_to_cpu(top->loops);
+       o->mem_type = le32_to_cpu(top->mem_type);
+       o->mem_align = le32_to_cpu(top->mem_align);
+       o->max_latency = le32_to_cpu(top->max_latency);
+       o->stonewall = le32_to_cpu(top->stonewall);
+       o->new_group = le32_to_cpu(top->new_group);
+       o->numjobs = le32_to_cpu(top->numjobs);
+       o->cpumask_set = le32_to_cpu(top->cpumask_set);
+       o->verify_cpumask_set = le32_to_cpu(top->verify_cpumask_set);
+       o->iolog = le32_to_cpu(top->iolog);
+       o->rwmixcycle = le32_to_cpu(top->rwmixcycle);
+       o->nice = le32_to_cpu(top->nice);
+       o->ioprio = le32_to_cpu(top->ioprio);
+       o->ioprio_class = le32_to_cpu(top->ioprio_class);
+       o->file_service_type = le32_to_cpu(top->file_service_type);
+       o->group_reporting = le32_to_cpu(top->group_reporting);
+       o->fadvise_hint = le32_to_cpu(top->fadvise_hint);
+       o->fallocate_mode = le32_to_cpu(top->fallocate_mode);
+       o->zero_buffers = le32_to_cpu(top->zero_buffers);
+       o->refill_buffers = le32_to_cpu(top->refill_buffers);
+       o->scramble_buffers = le32_to_cpu(top->scramble_buffers);
+       o->time_based = le32_to_cpu(top->time_based);
+       o->disable_lat = le32_to_cpu(top->disable_lat);
+       o->disable_clat = le32_to_cpu(top->disable_clat);
+       o->disable_slat = le32_to_cpu(top->disable_slat);
+       o->disable_bw = le32_to_cpu(top->disable_bw);
+       o->unified_rw_rep = le32_to_cpu(top->unified_rw_rep);
+       o->gtod_reduce = le32_to_cpu(top->gtod_reduce);
+       o->gtod_cpu = le32_to_cpu(top->gtod_cpu);
+       o->gtod_offload = le32_to_cpu(top->gtod_offload);
+       o->clocksource = le32_to_cpu(top->clocksource);
+       o->no_stall = le32_to_cpu(top->no_stall);
+       o->trim_percentage = le32_to_cpu(top->trim_percentage);
+       o->trim_batch = le32_to_cpu(top->trim_batch);
+       o->trim_zero = le32_to_cpu(top->trim_zero);
+       o->clat_percentiles = le32_to_cpu(top->clat_percentiles);
+       o->overwrite_plist = le32_to_cpu(top->overwrite_plist);
+       o->continue_on_error = le32_to_cpu(top->continue_on_error);
+       o->cgroup_weight = le32_to_cpu(top->cgroup_weight);
+       o->cgroup_nodelete = le32_to_cpu(top->cgroup_nodelete);
+       o->uid = le32_to_cpu(top->uid);
+       o->gid = le32_to_cpu(top->gid);
+       o->flow_id = __le32_to_cpu(top->flow_id);
+       o->flow = __le32_to_cpu(top->flow);
+       o->flow_watermark = __le32_to_cpu(top->flow_watermark);
+       o->flow_sleep = le32_to_cpu(top->flow_sleep);
+       o->sync_file_range = le32_to_cpu(top->sync_file_range);
+       o->compress_percentage = le32_to_cpu(top->compress_percentage);
+       o->compress_chunk = le32_to_cpu(top->compress_chunk);
+
+       o->trim_backlog = le64_to_cpu(top->trim_backlog);
+
+       for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++)
+               o->percentile_list[i].u.f = fio_uint64_to_double(le64_to_cpu(top->percentile_list[i].u.i));
+#if 0
+       uint8_t cpumask[FIO_TOP_STR_MAX];
+       uint8_t verify_cpumask[FIO_TOP_STR_MAX];
+#endif
+}
+
+void convert_thread_options_to_net(struct thread_options_pack *top,
+                                  struct thread_options *o)
+{
+       int i, j;
+
+       string_to_net(top->description, o->description);
+       string_to_net(top->name, o->name);
+       string_to_net(top->directory, o->directory);
+       string_to_net(top->filename, o->filename);
+       string_to_net(top->opendir, o->opendir);
+       string_to_net(top->ioengine, o->ioengine);
+       string_to_net(top->mmapfile, o->mmapfile);
+       string_to_net(top->read_iolog_file, o->read_iolog_file);
+       string_to_net(top->write_iolog_file, o->write_iolog_file);
+       string_to_net(top->bw_log_file, o->bw_log_file);
+       string_to_net(top->lat_log_file, o->lat_log_file);
+       string_to_net(top->iops_log_file, o->iops_log_file);
+       string_to_net(top->replay_redirect, o->replay_redirect);
+       string_to_net(top->exec_prerun, o->exec_prerun);
+       string_to_net(top->exec_postrun, o->exec_postrun);
+       string_to_net(top->ioscheduler, o->ioscheduler);
+       string_to_net(top->profile, o->profile);
+       string_to_net(top->cgroup, o->cgroup);
+
+       top->td_ddir = cpu_to_le32(o->td_ddir);
+       top->rw_seq = cpu_to_le32(o->rw_seq);
+       top->kb_base = cpu_to_le32(o->kb_base);
+       top->ddir_seq_nr = cpu_to_le32(o->ddir_seq_nr);
+       top->iodepth = cpu_to_le32(o->iodepth);
+       top->iodepth_low = cpu_to_le32(o->iodepth_low);
+       top->iodepth_batch = cpu_to_le32(o->iodepth_batch);
+       top->iodepth_batch_complete = cpu_to_le32(o->iodepth_batch_complete);
+       top->size_percent = cpu_to_le32(o->size_percent);
+       top->fill_device = cpu_to_le32(o->fill_device);
+       top->ratecycle = cpu_to_le32(o->ratecycle);
+       top->nr_files = cpu_to_le32(o->nr_files);
+       top->open_files = cpu_to_le32(o->open_files);
+       top->file_lock_mode = cpu_to_le32(o->file_lock_mode);
+       top->lockfile_batch = cpu_to_le32(o->lockfile_batch);
+       top->odirect = cpu_to_le32(o->odirect);
+       top->invalidate_cache = cpu_to_le32(o->invalidate_cache);
+       top->create_serialize = cpu_to_le32(o->create_serialize);
+       top->create_fsync = cpu_to_le32(o->create_fsync);
+       top->create_on_open = cpu_to_le32(o->create_on_open);
+       top->create_only = cpu_to_le32(o->create_only);
+       top->end_fsync = cpu_to_le32(o->end_fsync);
+       top->pre_read = cpu_to_le32(o->pre_read);
+       top->sync_io = cpu_to_le32(o->sync_io);
+       top->verify = cpu_to_le32(o->verify);
+       top->do_verify = cpu_to_le32(o->do_verify);
+       top->verifysort = cpu_to_le32(o->verifysort);
+       top->verifysort_nr = cpu_to_le32(o->verifysort_nr);
+       top->experimental_verify = cpu_to_le32(o->experimental_verify);
+       top->verify_interval = cpu_to_le32(o->verify_interval);
+       top->verify_offset = cpu_to_le32(o->verify_offset);
+       top->verify_pattern_bytes = cpu_to_le32(o->verify_pattern_bytes);
+       top->verify_fatal = cpu_to_le32(o->verify_fatal);
+       top->verify_dump = cpu_to_le32(o->verify_dump);
+       top->verify_async = cpu_to_le32(o->verify_async);
+       top->verify_batch = cpu_to_le32(o->verify_batch);
+       top->use_thread = cpu_to_le32(o->use_thread);
+       top->unlink = cpu_to_le32(o->unlink);
+       top->do_disk_util = cpu_to_le32(o->do_disk_util);
+       top->override_sync = cpu_to_le32(o->override_sync);
+       top->rand_repeatable = cpu_to_le32(o->rand_repeatable);
+       top->use_os_rand = cpu_to_le32(o->use_os_rand);
+       top->log_avg_msec = cpu_to_le32(o->log_avg_msec);
+       top->norandommap = cpu_to_le32(o->norandommap);
+       top->softrandommap = cpu_to_le32(o->softrandommap);
+       top->bs_unaligned = cpu_to_le32(o->bs_unaligned);
+       top->fsync_on_close = cpu_to_le32(o->fsync_on_close);
+       top->random_distribution = cpu_to_le32(o->random_distribution);
+       top->zipf_theta.u.i = __cpu_to_le64(fio_double_to_uint64(o->zipf_theta.u.f));
+       top->pareto_h.u.i = __cpu_to_le64(fio_double_to_uint64(o->pareto_h.u.f));
+       top->random_generator = cpu_to_le32(o->random_generator);
+       top->hugepage_size = cpu_to_le32(o->hugepage_size);
+       top->rw_min_bs = cpu_to_le32(o->rw_min_bs);
+       top->thinktime = cpu_to_le32(o->thinktime);
+       top->thinktime_spin = cpu_to_le32(o->thinktime_spin);
+       top->thinktime_blocks = cpu_to_le32(o->thinktime_blocks);
+       top->fsync_blocks = cpu_to_le32(o->fsync_blocks);
+       top->fdatasync_blocks = cpu_to_le32(o->fdatasync_blocks);
+       top->barrier_blocks = cpu_to_le32(o->barrier_blocks);
+       top->overwrite = cpu_to_le32(o->overwrite);
+       top->bw_avg_time = cpu_to_le32(o->bw_avg_time);
+       top->iops_avg_time = cpu_to_le32(o->iops_avg_time);
+       top->loops = cpu_to_le32(o->loops);
+       top->mem_type = cpu_to_le32(o->mem_type);
+       top->mem_align = cpu_to_le32(o->mem_align);
+       top->max_latency = cpu_to_le32(o->max_latency);
+       top->stonewall = cpu_to_le32(o->stonewall);
+       top->new_group = cpu_to_le32(o->new_group);
+       top->numjobs = cpu_to_le32(o->numjobs);
+       top->cpumask_set = cpu_to_le32(o->cpumask_set);
+       top->verify_cpumask_set = cpu_to_le32(o->verify_cpumask_set);
+       top->iolog = cpu_to_le32(o->iolog);
+       top->rwmixcycle = cpu_to_le32(o->rwmixcycle);
+       top->nice = cpu_to_le32(o->nice);
+       top->ioprio = cpu_to_le32(o->ioprio);
+       top->ioprio_class = cpu_to_le32(o->ioprio_class);
+       top->file_service_type = cpu_to_le32(o->file_service_type);
+       top->group_reporting = cpu_to_le32(o->group_reporting);
+       top->fadvise_hint = cpu_to_le32(o->fadvise_hint);
+       top->fallocate_mode = cpu_to_le32(o->fallocate_mode);
+       top->zero_buffers = cpu_to_le32(o->zero_buffers);
+       top->refill_buffers = cpu_to_le32(o->refill_buffers);
+       top->scramble_buffers = cpu_to_le32(o->scramble_buffers);
+       top->time_based = cpu_to_le32(o->time_based);
+       top->disable_lat = cpu_to_le32(o->disable_lat);
+       top->disable_clat = cpu_to_le32(o->disable_clat);
+       top->disable_slat = cpu_to_le32(o->disable_slat);
+       top->disable_bw = cpu_to_le32(o->disable_bw);
+       top->unified_rw_rep = cpu_to_le32(o->unified_rw_rep);
+       top->gtod_reduce = cpu_to_le32(o->gtod_reduce);
+       top->gtod_cpu = cpu_to_le32(o->gtod_cpu);
+       top->gtod_offload = cpu_to_le32(o->gtod_offload);
+       top->clocksource = cpu_to_le32(o->clocksource);
+       top->no_stall = cpu_to_le32(o->no_stall);
+       top->trim_percentage = cpu_to_le32(o->trim_percentage);
+       top->trim_batch = cpu_to_le32(o->trim_batch);
+       top->trim_zero = cpu_to_le32(o->trim_zero);
+       top->clat_percentiles = cpu_to_le32(o->clat_percentiles);
+       top->overwrite_plist = cpu_to_le32(o->overwrite_plist);
+       top->continue_on_error = cpu_to_le32(o->continue_on_error);
+       top->cgroup_weight = cpu_to_le32(o->cgroup_weight);
+       top->cgroup_nodelete = cpu_to_le32(o->cgroup_nodelete);
+       top->uid = cpu_to_le32(o->uid);
+       top->gid = cpu_to_le32(o->gid);
+       top->flow_id = __cpu_to_le32(o->flow_id);
+       top->flow = __cpu_to_le32(o->flow);
+       top->flow_watermark = __cpu_to_le32(o->flow_watermark);
+       top->flow_sleep = cpu_to_le32(o->flow_sleep);
+       top->sync_file_range = cpu_to_le32(o->sync_file_range);
+       top->compress_percentage = cpu_to_le32(o->compress_percentage);
+       top->compress_chunk = cpu_to_le32(o->compress_chunk);
+
+       for (i = 0; i < DDIR_RWDIR_CNT; i++) {
+               top->bs[i] = cpu_to_le32(o->bs[i]);
+               top->ba[i] = cpu_to_le32(o->ba[i]);
+               top->min_bs[i] = cpu_to_le32(o->min_bs[i]);
+               top->max_bs[i] = cpu_to_le32(o->max_bs[i]);
+               top->bssplit_nr[i] = cpu_to_le32(o->bssplit_nr[i]);
+
+               if (o->bssplit_nr[i]) {
+                       unsigned int bssplit_nr = o->bssplit_nr[i];
+
+                       if (bssplit_nr > BSSPLIT_MAX) {
+                               log_err("fio: BSSPLIT_MAX is too small\n");
+                               bssplit_nr = BSSPLIT_MAX;
+                       }
+                       for (j = 0; j < bssplit_nr; j++) {
+                               top->bssplit[i][j].bs = cpu_to_le32(o->bssplit[i][j].bs);
+                               top->bssplit[i][j].perc = cpu_to_le32(o->bssplit[i][j].perc);
+                       }
+               }
+
+               top->rwmix[i] = cpu_to_le32(o->rwmix[i]);
+               top->rate[i] = cpu_to_le32(o->rate[i]);
+               top->ratemin[i] = cpu_to_le32(o->ratemin[i]);
+               top->rate_iops[i] = cpu_to_le32(o->rate_iops[i]);
+               top->rate_iops_min[i] = cpu_to_le32(o->rate_iops_min[i]);
+       }
+
+       memcpy(top->verify_pattern, o->verify_pattern, MAX_PATTERN_SIZE);
+
+       top->size = __cpu_to_le64(o->size);
+       top->verify_backlog = __cpu_to_le64(o->verify_backlog);
+       top->start_delay = __cpu_to_le64(o->start_delay);
+       top->timeout = __cpu_to_le64(o->timeout);
+       top->ramp_time = __cpu_to_le64(o->ramp_time);
+       top->zone_range = __cpu_to_le64(o->zone_range);
+       top->zone_size = __cpu_to_le64(o->zone_size);
+       top->zone_skip = __cpu_to_le64(o->zone_skip);
+       top->lockmem = __cpu_to_le64(o->lockmem);
+       top->ddir_seq_add = __cpu_to_le64(o->ddir_seq_add);
+       top->file_size_low = __cpu_to_le64(o->file_size_low);
+       top->file_size_high = __cpu_to_le64(o->file_size_high);
+       top->start_offset = __cpu_to_le64(o->start_offset);
+       top->trim_backlog = __cpu_to_le64(o->trim_backlog);
+       top->offset_increment = __cpu_to_le64(o->offset_increment);
+
+       for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++)
+               top->percentile_list[i].u.i = __cpu_to_le64(fio_double_to_uint64(o->percentile_list[i].u.f));
+#if 0
+       uint8_t cpumask[FIO_TOP_STR_MAX];
+       uint8_t verify_cpumask[FIO_TOP_STR_MAX];
+#endif
+
+}
+
+/*
+ * Basic conversion test. We'd really need to fill in more of the options
+ * to have a thorough test. Even better, we should auto-generate the
+ * converter functions...
+ */
+int fio_test_cconv(struct thread_options *__o)
+{
+       struct thread_options o;
+       struct thread_options_pack top1, top2;
+
+       memset(&top1, 0, sizeof(top1));
+       memset(&top2, 0, sizeof(top2));
+
+       convert_thread_options_to_net(&top1, __o);
+       memset(&o, 0, sizeof(o));
+       convert_thread_options_to_cpu(&o, &top1);
+       convert_thread_options_to_net(&top2, &o);
+
+       return memcmp(&top1, &top2, sizeof(top1));
+}
index 0dc620d..fe6d75e 100644 (file)
--- a/client.c
+++ b/client.c
 #include <arpa/inet.h>
 #include <netdb.h>
 #include <signal.h>
+#include <zlib.h>
 
 #include "fio.h"
+#include "client.h"
 #include "server.h"
 #include "flist.h"
 #include "hash.h"
 
-struct client_eta {
-       unsigned int pending;
-       struct jobs_eta eta;
-};
-
-struct fio_client {
-       struct flist_head list;
-       struct flist_head hash_list;
-       struct flist_head arg_list;
-       union {
-               struct sockaddr_in addr;
-               struct sockaddr_in6 addr6;
-               struct sockaddr_un addr_un;
-       };
-       char *hostname;
-       int port;
-       int fd;
-       unsigned int refs;
-
-       char *name;
-
-       int state;
-
-       int skip_newline;
-       int is_sock;
-       int disk_stats_shown;
-       unsigned int jobs;
-       unsigned int nr_stat;
-       int error;
-       int ipv6;
-       int sent_job;
-       int did_stat;
-
-       struct flist_head eta_list;
-       struct client_eta *eta_in_flight;
-
-       struct flist_head cmd_list;
-
-       uint16_t argc;
-       char **argv;
-
-       char **ini_file;
-       unsigned int nr_ini_file;
+static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd);
+static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd);
+static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd);
+static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd);
+static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd);
+static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd);
+static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd);
+
+struct client_ops fio_client_ops = {
+       .text           = handle_text,
+       .disk_util      = handle_du,
+       .thread_status  = handle_ts,
+       .group_stats    = handle_gs,
+       .stop           = handle_stop,
+       .start          = handle_start,
+       .eta            = display_thread_status,
+       .probe          = handle_probe,
+       .eta_msec       = FIO_CLIENT_DEF_ETA_MSEC,
+       .client_type    = FIO_CLIENT_TYPE_CLI,
 };
 
 static struct timeval eta_tv;
 
-enum {
-       Client_created          = 0,
-       Client_connected        = 1,
-       Client_started          = 2,
-       Client_running          = 3,
-       Client_stopped          = 4,
-       Client_exited           = 5,
-};
-
 static FLIST_HEAD(client_list);
 static FLIST_HEAD(eta_list);
 
 static FLIST_HEAD(arg_list);
 
-static struct thread_stat client_ts;
-static struct group_run_stats client_gs;
-static int sum_stat_clients = 0;
+struct thread_stat client_ts;
+struct group_run_stats client_gs;
+int sum_stat_clients;
+
 static int sum_stat_nr;
 static int do_output_all_clients;
 
@@ -92,9 +62,6 @@ static int do_output_all_clients;
 #define FIO_CLIENT_HASH_MASK   (FIO_CLIENT_HASH_SZ - 1)
 static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
 
-static int handle_client(struct fio_client *client);
-static void dec_jobs_eta(struct client_eta *eta);
-
 static void fio_client_add_hash(struct fio_client *client)
 {
        int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
@@ -135,23 +102,11 @@ static struct fio_client *find_client_by_fd(int fd)
        return NULL;
 }
 
-static void remove_client(struct fio_client *client)
+void fio_put_client(struct fio_client *client)
 {
-       assert(client->refs);
-
        if (--client->refs)
                return;
 
-       dprint(FD_NET, "client: removed <%s>\n", client->hostname);
-       flist_del(&client->list);
-
-       fio_client_remove_hash(client);
-
-       if (!flist_empty(&client->eta_list)) {
-               flist_del_init(&client->eta_list);
-               dec_jobs_eta(client->eta_in_flight);
-       }
-
        free(client->hostname);
        if (client->argv)
                free(client->argv);
@@ -166,12 +121,38 @@ static void remove_client(struct fio_client *client)
                sum_stat_clients -= client->nr_stat;
 
        free(client);
+}
+
+static void remove_client(struct fio_client *client)
+{
+       assert(client->refs);
+
+       dprint(FD_NET, "client: removed <%s>\n", client->hostname);
+
+       if (!flist_empty(&client->list))
+               flist_del_init(&client->list);
+
+       fio_client_remove_hash(client);
+
+       if (!flist_empty(&client->eta_list)) {
+               flist_del_init(&client->eta_list);
+               fio_client_dec_jobs_eta(client->eta_in_flight, client->ops->eta);
+       }
+
+       close(client->fd);
+       client->fd = -1;
+
+       if (client->ops->removed)
+               client->ops->removed(client);
+
        nr_clients--;
+       fio_put_client(client);
 }
 
-static void put_client(struct fio_client *client)
+struct fio_client *fio_get_client(struct fio_client *client)
 {
-       remove_client(client);
+       client->refs++;
+       return client;
 }
 
 static void __fio_client_add_cmd_option(struct fio_client *client,
@@ -205,6 +186,53 @@ void fio_client_add_cmd_option(void *cookie, const char *opt)
        }
 }
 
+struct fio_client *fio_client_add_explicit(struct client_ops *ops,
+                                          const char *hostname, int type,
+                                          int port)
+{
+       struct fio_client *client;
+
+       client = malloc(sizeof(*client));
+       memset(client, 0, sizeof(*client));
+
+       INIT_FLIST_HEAD(&client->list);
+       INIT_FLIST_HEAD(&client->hash_list);
+       INIT_FLIST_HEAD(&client->arg_list);
+       INIT_FLIST_HEAD(&client->eta_list);
+       INIT_FLIST_HEAD(&client->cmd_list);
+
+       client->hostname = strdup(hostname);
+
+       if (type == Fio_client_socket)
+               client->is_sock = 1;
+       else {
+               int ipv6;
+
+               ipv6 = type == Fio_client_ipv6;
+               if (fio_server_parse_host(hostname, &ipv6,
+                                               &client->addr.sin_addr,
+                                               &client->addr6.sin6_addr))
+                       goto err;
+
+               client->port = port;
+       }
+
+       client->fd = -1;
+       client->ops = ops;
+       client->refs = 1;
+       client->type = ops->client_type;
+
+       __fio_client_add_cmd_option(client, "fio");
+
+       flist_add(&client->list, &client_list);
+       nr_clients++;
+       dprint(FD_NET, "client: added <%s>\n", client->hostname);
+       return client;
+err:
+       free(client);
+       return NULL;
+}
+
 void fio_client_add_ini_file(void *cookie, const char *ini_file)
 {
        struct fio_client *client = cookie;
@@ -218,7 +246,7 @@ void fio_client_add_ini_file(void *cookie, const char *ini_file)
        client->nr_ini_file++;
 }
 
-int fio_client_add(const char *hostname, void **cookie)
+int fio_client_add(struct client_ops *ops, const char *hostname, void **cookie)
 {
        struct fio_client *existing = *cookie;
        struct fio_client *client;
@@ -253,7 +281,9 @@ int fio_client_add(const char *hostname, void **cookie)
                return -1;
 
        client->fd = -1;
+       client->ops = ops;
        client->refs = 1;
+       client->type = ops->client_type;
 
        __fio_client_add_cmd_option(client, "fio");
 
@@ -264,6 +294,13 @@ int fio_client_add(const char *hostname, void **cookie)
        return 0;
 }
 
+static void probe_client(struct fio_client *client)
+{
+       dprint(FD_NET, "client: send probe\n");
+
+       fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list);
+}
+
 static int fio_client_connect_ip(struct fio_client *client)
 {
        struct sockaddr *addr;
@@ -286,16 +323,20 @@ static int fio_client_connect_ip(struct fio_client *client)
 
        fd = socket(domain, SOCK_STREAM, 0);
        if (fd < 0) {
+               int ret = -errno;
+
                log_err("fio: socket: %s\n", strerror(errno));
-               return -1;
+               return ret;
        }
 
        if (connect(fd, addr, socklen) < 0) {
+               int ret = -errno;
+
                log_err("fio: connect: %s\n", strerror(errno));
                log_err("fio: failed to connect to %s:%u\n", client->hostname,
                                                                client->port);
                close(fd);
-               return -1;
+               return ret;
        }
 
        return fd;
@@ -313,21 +354,25 @@ static int fio_client_connect_sock(struct fio_client *client)
 
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
        if (fd < 0) {
+               int ret = -errno;
+
                log_err("fio: socket: %s\n", strerror(errno));
-               return -1;
+               return ret;
        }
 
        len = sizeof(addr->sun_family) + strlen(addr->sun_path) + 1;
        if (connect(fd, (struct sockaddr *) addr, len) < 0) {
+               int ret = -errno;
+
                log_err("fio: connect; %s\n", strerror(errno));
                close(fd);
-               return -1;
+               return ret;
        }
 
        return fd;
 }
 
-static int fio_client_connect(struct fio_client *client)
+int fio_client_connect(struct fio_client *client)
 {
        int fd;
 
@@ -341,14 +386,21 @@ static int fio_client_connect(struct fio_client *client)
        dprint(FD_NET, "client: %s connected %d\n", client->hostname, fd);
 
        if (fd < 0)
-               return 1;
+               return fd;
 
        client->fd = fd;
        fio_client_add_hash(client);
        client->state = Client_connected;
+
+       probe_client(client);
        return 0;
 }
 
+int fio_client_terminate(struct fio_client *client)
+{
+       return fio_net_send_quit(client->fd);
+}
+
 void fio_clients_terminate(void)
 {
        struct flist_head *entry;
@@ -358,8 +410,7 @@ void fio_clients_terminate(void)
 
        flist_for_each(entry, &client_list) {
                client = flist_entry(entry, struct fio_client, list);
-
-               fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_QUIT, 0, NULL);
+               fio_client_terminate(client);
        }
 }
 
@@ -402,13 +453,6 @@ static void client_signal_handler(void)
        sigaction(SIGUSR1, &act, NULL);
 }
 
-static void probe_client(struct fio_client *client)
-{
-       dprint(FD_NET, "client: send probe\n");
-
-       fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_PROBE, 0, &client->cmd_list);
-}
-
 static int send_client_cmd_line(struct fio_client *client)
 {
        struct cmd_single_line_pdu *cslp;
@@ -451,7 +495,8 @@ static int send_client_cmd_line(struct fio_client *client)
 
        free(lens);
        clp->lines = cpu_to_le16(client->argc);
-       ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, 0);
+       clp->client_type = __cpu_to_le16(client->type);
+       ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOBLINE, pdu, mem, NULL, NULL);
        free(pdu);
        return ret;
 }
@@ -464,7 +509,7 @@ int fio_clients_connect(void)
 
 #ifdef WIN32
        WSADATA wsd;
-       WSAStartup(MAKEWORD(2,2), &wsd);
+       WSAStartup(MAKEWORD(2, 2), &wsd);
 #endif
 
        dprint(FD_NET, "client: connect all\n");
@@ -480,8 +525,6 @@ int fio_clients_connect(void)
                        continue;
                }
 
-               probe_client(client);
-
                if (client->argc > 1)
                        send_client_cmd_line(client);
        }
@@ -489,14 +532,44 @@ int fio_clients_connect(void)
        return !nr_clients;
 }
 
+int fio_start_client(struct fio_client *client)
+{
+       dprint(FD_NET, "client: start %s\n", client->hostname);
+       return fio_net_send_simple_cmd(client->fd, FIO_NET_CMD_RUN, 0, NULL);
+}
+
+int fio_start_all_clients(void)
+{
+       struct fio_client *client;
+       struct flist_head *entry, *tmp;
+       int ret;
+
+       dprint(FD_NET, "client: start all\n");
+
+       flist_for_each_safe(entry, tmp, &client_list) {
+               client = flist_entry(entry, struct fio_client, list);
+
+               ret = fio_start_client(client);
+               if (ret) {
+                       remove_client(client);
+                       continue;
+               }
+       }
+
+       return flist_empty(&client_list);
+}
+
 /*
  * Send file contents to server backend. We could use sendfile(), but to remain
  * more portable lets just read/write the darn thing.
  */
-static int fio_client_send_ini(struct fio_client *client, const char *filename)
+static int __fio_client_send_ini(struct fio_client *client, const char *filename)
 {
+       struct cmd_job_pdu *pdu;
+       size_t p_size;
        struct stat sb;
-       char *p, *buf;
+       char *p;
+       void *buf;
        off_t len;
        int fd, ret;
 
@@ -504,17 +577,23 @@ static int fio_client_send_ini(struct fio_client *client, const char *filename)
 
        fd = open(filename, O_RDONLY);
        if (fd < 0) {
+               int ret = -errno;
+
                log_err("fio: job file <%s> open: %s\n", filename, strerror(errno));
-               return 1;
+               return ret;
        }
 
        if (fstat(fd, &sb) < 0) {
+               int ret = -errno;
+
                log_err("fio: job file stat: %s\n", strerror(errno));
                close(fd);
-               return 1;
+               return ret;
        }
 
-       buf = malloc(sb.st_size);
+       p_size = sb.st_size + sizeof(*pdu);
+       pdu = malloc(p_size);
+       buf = pdu->buf;
 
        len = sb.st_size;
        p = buf;
@@ -539,13 +618,27 @@ static int fio_client_send_ini(struct fio_client *client, const char *filename)
                return 1;
        }
 
+       pdu->buf_len = __cpu_to_le32(sb.st_size);
+       pdu->client_type = cpu_to_le32(client->type);
+
        client->sent_job = 1;
-       ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, buf, sb.st_size, 0);
-       free(buf);
+       ret = fio_net_send_cmd(client->fd, FIO_NET_CMD_JOB, pdu, p_size, NULL, NULL);
+       free(pdu);
        close(fd);
        return ret;
 }
 
+int fio_client_send_ini(struct fio_client *client, const char *filename)
+{
+       int ret;
+
+       ret = __fio_client_send_ini(client, filename);
+       if (!ret)
+               client->sent_job = 1;
+
+       return ret;
+}
+
 int fio_clients_send_ini(const char *filename)
 {
        struct fio_client *client;
@@ -567,13 +660,23 @@ int fio_clients_send_ini(const char *filename)
                        }
                } else if (!filename || fio_client_send_ini(client, filename))
                        remove_client(client);
-
-               client->sent_job = 1;
        }
 
        return !nr_clients;
 }
 
+int fio_client_update_options(struct fio_client *client,
+                             struct thread_options *o, uint64_t *tag)
+{
+       struct cmd_add_job_pdu pdu;
+
+       pdu.thread_number = cpu_to_le32(client->thread_number);
+       pdu.groupid = cpu_to_le32(client->groupid);
+       convert_thread_options_to_net(&pdu.top, o);
+       
+       return fio_net_send_cmd(client->fd, FIO_NET_CMD_UPDATE_JOB, &pdu, sizeof(pdu), tag, &client->cmd_list);
+}
+
 static void convert_io_stat(struct io_stat *dst, struct io_stat *src)
 {
        dst->max_val    = le64_to_cpu(src->max_val);
@@ -591,10 +694,11 @@ static void convert_ts(struct thread_stat *dst, struct thread_stat *src)
 {
        int i, j;
 
-       dst->error      = le32_to_cpu(src->error);
-       dst->groupid    = le32_to_cpu(src->groupid);
-       dst->pid        = le32_to_cpu(src->pid);
-       dst->members    = le32_to_cpu(src->members);
+       dst->error              = le32_to_cpu(src->error);
+       dst->thread_number      = le32_to_cpu(src->thread_number);
+       dst->groupid            = le32_to_cpu(src->groupid);
+       dst->pid                = le32_to_cpu(src->pid);
+       dst->members            = le32_to_cpu(src->members);
        dst->unified_rw_rep     = le32_to_cpu(src->unified_rw_rep);
 
        for (i = 0; i < DDIR_RWDIR_CNT; i++) {
@@ -675,9 +779,6 @@ static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
 {
        struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
 
-       convert_ts(&p->ts, &p->ts);
-       convert_gs(&p->rs, &p->rs);
-
        show_thread_status(&p->ts, &p->rs);
        client->did_stat = 1;
 
@@ -688,6 +789,7 @@ static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
        sum_group_stats(&client_gs, &p->rs);
 
        client_ts.members++;
+       client_ts.thread_number = p->ts.thread_number;
        client_ts.groupid = p->ts.groupid;
        client_ts.unified_rw_rep = p->ts.unified_rw_rep;
 
@@ -697,14 +799,29 @@ static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
        }
 }
 
-static void handle_gs(struct fio_net_cmd *cmd)
+static void handle_gs(struct fio_client *client, struct fio_net_cmd *cmd)
 {
        struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
 
-       convert_gs(gs, gs);
        show_group_stats(gs);
 }
 
+static void handle_text(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
+       const char *buf = (const char *) pdu->buf;
+       const char *name;
+       int fio_unused ret;
+
+       name = client->name ? client->name : client->hostname;
+
+       if (!client->skip_newline)
+               fprintf(f_out, "<%s> ", name);
+       ret = fwrite(buf, pdu->buf_len, 1, f_out);
+       fflush(f_out);
+       client->skip_newline = strchr(buf, '\n') == NULL;
+}
+
 static void convert_agg(struct disk_util_agg *agg)
 {
        int i;
@@ -742,9 +859,6 @@ static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd)
 {
        struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
 
-       convert_dus(&du->dus);
-       convert_agg(&du->agg);
-
        if (!client->disk_stats_shown) {
                client->disk_stats_shown = 1;
                log_info("\nDisk stats (read/write):\n");
@@ -761,22 +875,21 @@ static void convert_jobs_eta(struct jobs_eta *je)
        je->nr_ramp             = le32_to_cpu(je->nr_ramp);
        je->nr_pending          = le32_to_cpu(je->nr_pending);
        je->files_open          = le32_to_cpu(je->files_open);
-       je->m_rate              = le32_to_cpu(je->m_rate);
-       je->t_rate              = le32_to_cpu(je->t_rate);
-       je->m_iops              = le32_to_cpu(je->m_iops);
-       je->t_iops              = le32_to_cpu(je->t_iops);
 
        for (i = 0; i < DDIR_RWDIR_CNT; i++) {
-               je->rate[i]     = le32_to_cpu(je->rate[i]);
-               je->iops[i]     = le32_to_cpu(je->iops[i]);
+               je->m_rate[i]   = le32_to_cpu(je->m_rate[i]);
+               je->t_rate[i]   = le32_to_cpu(je->t_rate[i]);
+               je->m_iops[i]   = le32_to_cpu(je->m_iops[i]);
+               je->t_iops[i]   = le32_to_cpu(je->t_iops[i]);
        }
 
        je->elapsed_sec         = le64_to_cpu(je->elapsed_sec);
        je->eta_sec             = le64_to_cpu(je->eta_sec);
+       je->nr_threads          = le32_to_cpu(je->nr_threads);
        je->is_pow2             = le32_to_cpu(je->is_pow2);
 }
 
-static void sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
+void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
 {
        int i;
 
@@ -784,52 +897,77 @@ static void sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je)
        dst->nr_ramp            += je->nr_ramp;
        dst->nr_pending         += je->nr_pending;
        dst->files_open         += je->files_open;
-       dst->m_rate             += je->m_rate;
-       dst->t_rate             += je->t_rate;
-       dst->m_iops             += je->m_iops;
-       dst->t_iops             += je->t_iops;
 
        for (i = 0; i < DDIR_RWDIR_CNT; i++) {
-               dst->rate[i]    += je->rate[i];
-               dst->iops[i]    += je->iops[i];
+               dst->m_rate[i]  += je->m_rate[i];
+               dst->t_rate[i]  += je->t_rate[i];
+               dst->m_iops[i]  += je->m_iops[i];
+               dst->t_iops[i]  += je->t_iops[i];
        }
 
        dst->elapsed_sec        += je->elapsed_sec;
 
        if (je->eta_sec > dst->eta_sec)
                dst->eta_sec = je->eta_sec;
+
+       dst->nr_threads         += je->nr_threads;
+       /* we need to handle je->run_str too ... */
 }
 
-static void dec_jobs_eta(struct client_eta *eta)
+void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn)
 {
        if (!--eta->pending) {
-               display_thread_status(&eta->eta);
+               eta_fn(&eta->eta);
                free(eta);
        }
 }
 
 static void remove_reply_cmd(struct fio_client *client, struct fio_net_cmd *cmd)
 {
-       struct fio_net_int_cmd *icmd = NULL;
+       struct fio_net_cmd_reply *reply = NULL;
        struct flist_head *entry;
 
        flist_for_each(entry, &client->cmd_list) {
-               icmd = flist_entry(entry, struct fio_net_int_cmd, list);
+               reply = flist_entry(entry, struct fio_net_cmd_reply, list);
 
-               if (cmd->tag == (uintptr_t) icmd)
+               if (cmd->tag == (uintptr_t) reply)
                        break;
 
-               icmd = NULL;
+               reply = NULL;
        }
 
-       if (!icmd) {
-               log_err("fio: client: unable to find matching tag\n");
+       if (!reply) {
+               log_err("fio: client: unable to find matching tag (%lx)\n", cmd->tag);
                return;
        }
 
-       flist_del(&icmd->list);
-       cmd->tag = icmd->saved_tag;
-       free(icmd);
+       flist_del(&reply->list);
+       cmd->tag = reply->saved_tag;
+       free(reply);
+}
+
+int fio_client_wait_for_reply(struct fio_client *client, uint64_t tag)
+{
+       do {
+               struct fio_net_cmd_reply *reply = NULL;
+               struct flist_head *entry;
+
+               flist_for_each(entry, &client->cmd_list) {
+                       reply = flist_entry(entry, struct fio_net_cmd_reply, list);
+
+                       if (tag == (uintptr_t) reply)
+                               break;
+
+                       reply = NULL;
+               }
+
+               if (!reply)
+                       break;
+
+               usleep(1000);
+       } while (1);
+
+       return 0;
 }
 
 static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
@@ -844,9 +982,11 @@ static void handle_eta(struct fio_client *client, struct fio_net_cmd *cmd)
        client->eta_in_flight = NULL;
        flist_del_init(&client->eta_list);
 
-       convert_jobs_eta(je);
-       sum_jobs_eta(&eta->eta, je);
-       dec_jobs_eta(eta);
+       if (client->ops->jobs_eta)
+               client->ops->jobs_eta(client, je);
+
+       fio_client_sum_jobs_eta(&eta->eta, je);
+       fio_client_dec_jobs_eta(eta, client->ops->eta);
 }
 
 static void handle_probe(struct fio_client *client, struct fio_net_cmd *cmd)
@@ -888,18 +1028,108 @@ static void handle_start(struct fio_client *client, struct fio_net_cmd *cmd)
 }
 
 static void handle_stop(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       if (client->error)
+               log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
+}
+
+static void convert_stop(struct fio_net_cmd *cmd)
 {
        struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
 
-       client->state = Client_stopped;
-       client->error = le32_to_cpu(pdu->error);
+       pdu->error = le32_to_cpu(pdu->error);
+}
 
-       if (client->error)
-               log_info("client <%s>: exited with error %d\n", client->hostname, client->error);
+static void convert_text(struct fio_net_cmd *cmd)
+{
+       struct cmd_text_pdu *pdu = (struct cmd_text_pdu *) cmd->payload;
+
+       pdu->level      = le32_to_cpu(pdu->level);
+       pdu->buf_len    = le32_to_cpu(pdu->buf_len);
+       pdu->log_sec    = le64_to_cpu(pdu->log_sec);
+       pdu->log_usec   = le64_to_cpu(pdu->log_usec);
+}
+
+/*
+ * This has been compressed on the server side, since it can be big.
+ * Uncompress here.
+ */
+static struct cmd_iolog_pdu *convert_iolog(struct fio_net_cmd *cmd)
+{
+       struct cmd_iolog_pdu *pdu = (struct cmd_iolog_pdu *) cmd->payload;
+       struct cmd_iolog_pdu *ret;
+       uint32_t nr_samples;
+       unsigned long total;
+       z_stream stream;
+       void *p;
+       int i;
+
+       stream.zalloc = Z_NULL;
+       stream.zfree = Z_NULL;
+       stream.opaque = Z_NULL;
+       stream.avail_in = 0;
+       stream.next_in = Z_NULL;
+
+       if (inflateInit(&stream) != Z_OK)
+               return NULL;
+
+       /*
+        * Get header first, it's not compressed
+        */
+       nr_samples = le32_to_cpu(pdu->nr_samples);
+
+       total = nr_samples * sizeof(struct io_sample);
+       ret = malloc(total + sizeof(*pdu));
+       ret->thread_number = le32_to_cpu(pdu->thread_number);
+       ret->nr_samples = nr_samples;
+       ret->log_type = le32_to_cpu(pdu->log_type);
+       strcpy((char *) ret->name, (char *) pdu->name);
+
+       p = (void *) ret + sizeof(*pdu);
+
+       stream.avail_in = cmd->pdu_len - sizeof(*pdu);
+       stream.next_in = (void *) pdu + sizeof(*pdu);
+       while (stream.avail_in) {
+               unsigned int this_chunk = 65536;
+               unsigned int this_len;
+               int err;
+
+               if (this_chunk > total)
+                       this_chunk = total;
+
+               stream.avail_out = this_chunk;
+               stream.next_out = p;
+               err = inflate(&stream, Z_NO_FLUSH);
+               /* may be Z_OK, or Z_STREAM_END */
+               if (err < 0) {
+                       log_err("fio: inflate error %d\n", err);
+                       free(ret);
+                       ret = NULL;
+                       goto out;
+               }
+
+               this_len = this_chunk - stream.avail_out;
+               p += this_len;
+               total -= this_len;
+       }
+
+       for (i = 0; i < ret->nr_samples; i++) {
+               struct io_sample *s = &ret->samples[i];
+
+               s->time = le64_to_cpu(s->time);
+               s->val  = le64_to_cpu(s->val);
+               s->ddir = le32_to_cpu(s->ddir);
+               s->bs   = le32_to_cpu(s->bs);
+       }
+
+out:
+       inflateEnd(&stream);
+       return ret;
 }
 
-static int handle_client(struct fio_client *client)
+int fio_handle_client(struct fio_client *client)
 {
+       struct client_ops *ops = client->ops;
        struct fio_net_cmd *cmd;
 
        dprint(FD_NET, "client: handle %s\n", client->hostname);
@@ -908,61 +1138,112 @@ static int handle_client(struct fio_client *client)
        if (!cmd)
                return 0;
 
-       dprint(FD_NET, "client: got cmd op %s from %s\n",
-                               fio_server_op(cmd->opcode), client->hostname);
+       dprint(FD_NET, "client: got cmd op %s from %s (pdu=%u)\n",
+               fio_server_op(cmd->opcode), client->hostname, cmd->pdu_len);
 
        switch (cmd->opcode) {
        case FIO_NET_CMD_QUIT:
+               if (ops->quit)
+                       ops->quit(client, cmd);
                remove_client(client);
                free(cmd);
                break;
-       case FIO_NET_CMD_TEXT: {
-               const char *buf = (const char *) cmd->payload;
-               const char *name;
-               int fio_unused ret;
-
-               name = client->name ? client->name : client->hostname;
-
-               if (!client->skip_newline)
-                       fprintf(f_out, "<%s> ", name);
-               ret = fwrite(buf, cmd->pdu_len, 1, f_out);
-               fflush(f_out);
-               client->skip_newline = strchr(buf, '\n') == NULL;
+       case FIO_NET_CMD_TEXT:
+               convert_text(cmd);
+               ops->text(client, cmd);
                free(cmd);
                break;
-               }
-       case FIO_NET_CMD_DU:
-               handle_du(client, cmd);
+       case FIO_NET_CMD_DU: {
+               struct cmd_du_pdu *du = (struct cmd_du_pdu *) cmd->payload;
+
+               convert_dus(&du->dus);
+               convert_agg(&du->agg);
+
+               ops->disk_util(client, cmd);
                free(cmd);
                break;
-       case FIO_NET_CMD_TS:
-               handle_ts(client, cmd);
+               }
+       case FIO_NET_CMD_TS: {
+               struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
+
+               convert_ts(&p->ts, &p->ts);
+               convert_gs(&p->rs, &p->rs);
+
+               ops->thread_status(client, cmd);
                free(cmd);
                break;
-       case FIO_NET_CMD_GS:
-               handle_gs(cmd);
+               }
+       case FIO_NET_CMD_GS: {
+               struct group_run_stats *gs = (struct group_run_stats *) cmd->payload;
+
+               convert_gs(gs, gs);
+
+               ops->group_stats(client, cmd);
                free(cmd);
                break;
-       case FIO_NET_CMD_ETA:
+               }
+       case FIO_NET_CMD_ETA: {
+               struct jobs_eta *je = (struct jobs_eta *) cmd->payload;
+
                remove_reply_cmd(client, cmd);
+               convert_jobs_eta(je);
                handle_eta(client, cmd);
                free(cmd);
                break;
+               }
        case FIO_NET_CMD_PROBE:
                remove_reply_cmd(client, cmd);
-               handle_probe(client, cmd);
+               ops->probe(client, cmd);
                free(cmd);
                break;
-       case FIO_NET_CMD_RUN:
+       case FIO_NET_CMD_SERVER_START:
                client->state = Client_running;
+               if (ops->job_start)
+                       ops->job_start(client, cmd);
                free(cmd);
                break;
-       case FIO_NET_CMD_START:
-               handle_start(client, cmd);
+       case FIO_NET_CMD_START: {
+               struct cmd_start_pdu *pdu = (struct cmd_start_pdu *) cmd->payload;
+
+               pdu->jobs = le32_to_cpu(pdu->jobs);
+               ops->start(client, cmd);
                free(cmd);
                break;
-       case FIO_NET_CMD_STOP:
-               handle_stop(client, cmd);
+               }
+       case FIO_NET_CMD_STOP: {
+               struct cmd_end_pdu *pdu = (struct cmd_end_pdu *) cmd->payload;
+
+               convert_stop(cmd);
+               client->state = Client_stopped;
+               client->error = le32_to_cpu(pdu->error);
+               client->signal = le32_to_cpu(pdu->signal);
+               ops->stop(client, cmd);
+               free(cmd);
+               break;
+               }
+       case FIO_NET_CMD_ADD_JOB: {
+               struct cmd_add_job_pdu *pdu = (struct cmd_add_job_pdu *) cmd->payload;
+
+               client->thread_number = le32_to_cpu(pdu->thread_number);
+               client->groupid = le32_to_cpu(pdu->groupid);
+
+               if (ops->add_job)
+                       ops->add_job(client, cmd);
+               free(cmd);
+               break;
+               }
+       case FIO_NET_CMD_IOLOG:
+               if (ops->iolog) {
+                       struct cmd_iolog_pdu *pdu;
+
+                       pdu = convert_iolog(cmd);
+                       ops->iolog(client, pdu);
+               }
+               free(cmd);
+               break;
+       case FIO_NET_CMD_UPDATE_JOB:
+               ops->update_job(client, cmd);
+               remove_reply_cmd(client, cmd);
                free(cmd);
                break;
        default:
@@ -974,7 +1255,7 @@ static int handle_client(struct fio_client *client)
        return 1;
 }
 
-static void request_client_etas(void)
+static void request_client_etas(struct client_ops *ops)
 {
        struct fio_client *client;
        struct flist_head *entry;
@@ -1005,7 +1286,7 @@ static void request_client_etas(void)
        }
 
        while (skipped--)
-               dec_jobs_eta(eta);
+               fio_client_dec_jobs_eta(eta, ops->eta);
 
        dprint(FD_NET, "client: requested eta tag %p\n", eta);
 }
@@ -1013,27 +1294,27 @@ static void request_client_etas(void)
 static int client_check_cmd_timeout(struct fio_client *client,
                                    struct timeval *now)
 {
-       struct fio_net_int_cmd *cmd;
+       struct fio_net_cmd_reply *reply;
        struct flist_head *entry, *tmp;
        int ret = 0;
 
        flist_for_each_safe(entry, tmp, &client->cmd_list) {
-               cmd = flist_entry(entry, struct fio_net_int_cmd, list);
+               reply = flist_entry(entry, struct fio_net_cmd_reply, list);
 
-               if (mtime_since(&cmd->tv, now) < FIO_NET_CLIENT_TIMEOUT)
+               if (mtime_since(&reply->tv, now) < FIO_NET_CLIENT_TIMEOUT)
                        continue;
 
                log_err("fio: client %s, timeout on cmd %s\n", client->hostname,
-                                               fio_server_op(cmd->cmd.opcode));
-               flist_del(&cmd->list);
-               free(cmd);
+                                               fio_server_op(reply->opcode));
+               flist_del(&reply->list);
+               free(reply);
                ret = 1;
        }
 
        return flist_empty(&client->cmd_list) && ret;
 }
 
-static int fio_client_timed_out(void)
+static int fio_check_clients_timed_out(void)
 {
        struct fio_client *client;
        struct flist_head *entry, *tmp;
@@ -1051,7 +1332,11 @@ static int fio_client_timed_out(void)
                if (!client_check_cmd_timeout(client, &tv))
                        continue;
 
-               log_err("fio: client %s timed out\n", client->hostname);
+               if (client->ops->timed_out)
+                       client->ops->timed_out(client);
+               else
+                       log_err("fio: client %s timed out\n", client->hostname);
+
                remove_client(client);
                ret = 1;
        }
@@ -1059,7 +1344,7 @@ static int fio_client_timed_out(void)
        return ret;
 }
 
-int fio_handle_clients(void)
+int fio_handle_clients(struct client_ops *ops)
 {
        struct pollfd *pfds;
        int i, ret = 0, retval = 0;
@@ -1079,7 +1364,7 @@ int fio_handle_clients(void)
                flist_for_each_safe(entry, tmp, &client_list) {
                        client = flist_entry(entry, struct fio_client, list);
 
-                       if (!client->sent_job &&
+                       if (!client->sent_job && !client->ops->stay_connected &&
                            flist_empty(&client->cmd_list)) {
                                remove_client(client);
                                continue;
@@ -1100,14 +1385,14 @@ int fio_handle_clients(void)
 
                        fio_gettime(&tv, NULL);
                        if (mtime_since(&eta_tv, &tv) >= 900) {
-                               request_client_etas();
+                               request_client_etas(ops);
                                memcpy(&eta_tv, &tv, sizeof(tv));
 
-                               if (fio_client_timed_out())
+                               if (fio_check_clients_timed_out())
                                        break;
                        }
 
-                       ret = poll(pfds, nr_clients, 100);
+                       ret = poll(pfds, nr_clients, ops->eta_msec);
                        if (ret < 0) {
                                if (errno == EINTR)
                                        continue;
@@ -1126,14 +1411,14 @@ int fio_handle_clients(void)
                                log_err("fio: unknown client fd %d\n", pfds[i].fd);
                                continue;
                        }
-                       if (!handle_client(client)) {
+                       if (!fio_handle_client(client)) {
                                log_info("client: host=%s disconnected\n",
                                                client->hostname);
                                remove_client(client);
                                retval = 1;
                        } else if (client->error)
                                retval = 1;
-                       put_client(client);
+                       fio_put_client(client);
                }
        }
 
diff --git a/client.h b/client.h
new file mode 100644 (file)
index 0000000..10d6ec3
--- /dev/null
+++ b/client.h
@@ -0,0 +1,144 @@
+#ifndef CLIENT_H
+#define CLIENT_H
+
+#include <sys/socket.h>
+#include <sys/un.h>
+#include <netinet/in.h>
+#include <arpa/inet.h>
+
+#include "stat.h"
+
+struct fio_net_cmd;
+struct client_ops;
+
+enum {
+       Client_created          = 0,
+       Client_connected        = 1,
+       Client_started          = 2,
+       Client_running          = 3,
+       Client_stopped          = 4,
+       Client_exited           = 5,
+};
+
+struct fio_client {
+       struct flist_head list;
+       struct flist_head hash_list;
+       struct flist_head arg_list;
+       union {
+               struct sockaddr_in addr;
+               struct sockaddr_in6 addr6;
+               struct sockaddr_un addr_un;
+       };
+       char *hostname;
+       int port;
+       int fd;
+       unsigned int refs;
+
+       char *name;
+
+       int state;
+
+       int skip_newline;
+       int is_sock;
+       int disk_stats_shown;
+       unsigned int jobs;
+       unsigned int nr_stat;
+       int error;
+       int signal;
+       int ipv6;
+       int sent_job;
+       int did_stat;
+       uint32_t type;
+
+       uint32_t thread_number;
+       uint32_t groupid;
+
+       struct flist_head eta_list;
+       struct client_eta *eta_in_flight;
+
+       struct flist_head cmd_list;
+
+       uint16_t argc;
+       char **argv;
+
+       struct client_ops *ops;
+       void *client_data;
+
+       char **ini_file;
+       unsigned int nr_ini_file;
+};
+
+struct cmd_iolog_pdu;
+typedef void (client_cmd_op)(struct fio_client *, struct fio_net_cmd *);
+typedef void (client_eta_op)(struct jobs_eta *je);
+typedef void (client_timed_out_op)(struct fio_client *);
+typedef void (client_jobs_eta_op)(struct fio_client *client, struct jobs_eta *je);
+typedef void (client_iolog_op)(struct fio_client *client, struct cmd_iolog_pdu *);
+
+struct client_ops {
+       client_cmd_op           *text;
+       client_cmd_op           *disk_util;
+       client_cmd_op           *thread_status;
+       client_cmd_op           *group_stats;
+       client_jobs_eta_op      *jobs_eta;
+       client_eta_op           *eta;
+       client_cmd_op           *probe;
+       client_cmd_op           *quit;
+       client_cmd_op           *add_job;
+       client_cmd_op           *update_job;
+       client_timed_out_op     *timed_out;
+       client_cmd_op           *stop;
+       client_cmd_op           *start;
+       client_cmd_op           *job_start;
+       client_iolog_op         *iolog;
+       client_timed_out_op     *removed;
+
+       unsigned int eta_msec;
+       int stay_connected;
+       uint32_t client_type;
+};
+
+extern struct client_ops fio_client_ops;
+
+struct client_eta {
+       struct jobs_eta eta;
+       unsigned int pending;
+};
+
+extern int fio_handle_client(struct fio_client *);
+extern void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op fn);
+extern void fio_client_sum_jobs_eta(struct jobs_eta *dst, struct jobs_eta *je);
+
+enum {
+       Fio_client_ipv4 = 1,
+       Fio_client_ipv6,
+       Fio_client_socket,
+};
+
+extern int fio_client_connect(struct fio_client *);
+extern int fio_clients_connect(void);
+extern int fio_start_client(struct fio_client *);
+extern int fio_start_all_clients(void);
+extern int fio_client_send_ini(struct fio_client *, const char *);
+extern int fio_clients_send_ini(const char *);
+extern int fio_handle_clients(struct client_ops *);
+extern int fio_client_add(struct client_ops *, const char *, void **);
+extern struct fio_client *fio_client_add_explicit(struct client_ops *, const char *, int, int);
+extern void fio_client_add_cmd_option(void *, const char *);
+extern void fio_client_add_ini_file(void *, const char *);
+extern int fio_client_terminate(struct fio_client *);
+extern void fio_clients_terminate(void);
+extern struct fio_client *fio_get_client(struct fio_client *);
+extern void fio_put_client(struct fio_client *);
+extern int fio_client_update_options(struct fio_client *, struct thread_options *, uint64_t *);
+extern int fio_client_wait_for_reply(struct fio_client *, uint64_t);
+
+#define FIO_CLIENT_DEF_ETA_MSEC                900
+
+enum {
+       FIO_CLIENT_TYPE_CLI             = 1,
+       FIO_CLIENT_TYPE_GUI             = 2,
+};
+
+#endif
+
index d332c5e..880d113 100755 (executable)
--- a/configure
+++ b/configure
@@ -122,20 +122,27 @@ cpu=""
 
 cc="${CC-${cross_prefix}gcc}"
 
+# default options
 show_help="no"
 exit_val=0
+gfio="no"
 
 # parse options
 for opt do
   optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'`
   case "$opt" in
-  --cc=*) CC="$optarg"
-  ;;
-  --extra-cflags=*) CFLAGS="$CFLAGS $optarg"
+  --cc=*)
+    CC="$optarg"
+    ;;
+  --extra-cflags=*)
+  CFLAGS="$CFLAGS $optarg"
   ;;
+  --enable-gfio)
+    gfio="yes"
+    ;;
   --help)
-  show_help="yes"
-  ;;
+    show_help="yes"
+    ;;
   *)
   echo "Bad option $opt"
   show_help="yes"
@@ -144,9 +151,10 @@ for opt do
 done
 
 if test "$show_help" = "yes" ; then
-  echo "--cc=                  Specify compiler to use"
+    echo "--cc=                  Specify compiler to use"
   echo "--extra-cflags=        Specify extra CFLAGS to pass to compiler"
-  exit $exit_val
+    echo "--enable-gfio          Enable building of gtk gfio"
+    exit $exit_val
 fi
 
 if check_define __linux__ ; then
@@ -829,6 +837,42 @@ fi
 echo "__thread                      $tls_thread"
 
 ##########################################
+# Whether or not __thread is supported for TLS
+if test "$gfio" = "yes" ; then
+  cat > $TMPC << EOF
+#include <glib.h>
+#include <cairo.h>
+#include <gtk/gtk.h>
+int main(void)
+{
+  gdk_threads_enter();
+  gtk_main();
+  gdk_threads_leave();
+  return 0;
+}
+EOF
+GTK_CFLAGS=$(pkg-config --cflags gtk+-2.0 gthread-2.0)
+if test "$?" != "0" ; then
+  echo "configure: gtk and gthread not found"
+  exit 1
+fi
+GTK_LIBS=$(pkg-config --libs gtk+-2.0 gthread-2.0)
+if test "$?" != "0" ; then
+  echo "configure: gtk and gthread not found"
+  exit 1
+fi
+if compile_prog "$GTK_CFLAGS" "$GTK_LIBS" "gfio"; then
+  gfio="yes"
+  LIBS="$LIBS $GTK_LIBS"
+  CFLAGS="$CFLAGS $GTK_CFLAGS"
+else
+  echo "Please install gtk and gdk libraries"
+  gfio="no"
+fi
+fi
+
+echo "gfio                          $gfio"
+
 # Check whether we have getrusage(RUSAGE_THREAD)
 rusage_thread="no"
 cat > $TMPC << EOF
@@ -983,6 +1027,9 @@ fi
 if test "$rusage_thread" = "yes" ; then
   output_sym "CONFIG_RUSAGE_THREAD"
 fi
+if test "$gfio" = "yes" ; then
+  echo "CONFIG_GFIO=y" >> $config_host_mak
+fi
 if test "$sched_idle" = "yes" ; then
   output_sym "CONFIG_SCHED_IDLE"
 fi
@@ -991,5 +1038,6 @@ if test "$tcp_nodelay" = "yes" ; then
 fi
 
 echo "LIBS+=$LIBS" >> $config_host_mak
+echo "CFLAGS+=$CFLAGS" >> $config_host_mak
 echo "CC=$cc" >> $config_host_mak
 echo "EXTFLAGS=$EXTFLAGS $CFLAGS" >> $config_host_mak
diff --git a/debug.h b/debug.h
index af71d62..b55a1e4 100644 (file)
--- a/debug.h
+++ b/debug.h
@@ -27,6 +27,7 @@ extern unsigned int fio_debug_jobno, *fio_debug_jobp;
 #ifdef FIO_INC_DEBUG
 struct debug_level {
        const char *name;
+       const char *help;
        unsigned long shift;
        unsigned int jobno;
 };
index 8bc9fd5..c798f18 100644 (file)
@@ -7,32 +7,73 @@
  */
 #include "../fio.h"
 
+struct cpu_options {
+       struct thread_data *td;
+       unsigned int cpuload;
+       unsigned int cpucycle;
+};
+
+static struct fio_option options[] = {
+       {
+               .name   = "cpuload",
+               .lname  = "CPU load",
+               .type   = FIO_OPT_INT,
+               .off1   = offsetof(struct cpu_options, cpuload),
+               .help   = "Use this percentage of CPU",
+               .category = FIO_OPT_C_GENERAL,
+               .group  = FIO_OPT_G_INVALID,
+       },
+       {
+               .name   = "cpuchunks",
+               .lname  = "CPU chunk",
+               .type   = FIO_OPT_INT,
+               .off1   = offsetof(struct cpu_options, cpucycle),
+               .help   = "Length of the CPU burn cycles (usecs)",
+               .def    = "50000",
+               .parent = "cpuload",
+               .hide   = 1,
+               .category = FIO_OPT_C_GENERAL,
+               .group  = FIO_OPT_G_INVALID,
+       },
+       {
+               .name   = NULL,
+       },
+};
+
+
 static int fio_cpuio_queue(struct thread_data *td, struct io_u fio_unused *io_u)
 {
-       usec_spin(td->o.cpucycle);
+       struct cpu_options *co = td->eo;
+
+       usec_spin(co->cpucycle);
        return FIO_Q_COMPLETED;
 }
 
 static int fio_cpuio_init(struct thread_data *td)
 {
        struct thread_options *o = &td->o;
+       struct cpu_options *co = td->eo;
 
-       if (!o->cpuload) {
+       if (!co->cpuload) {
                td_vmsg(td, EINVAL, "cpu thread needs rate (cpuload=)","cpuio");
                return 1;
        }
 
-       if (o->cpuload > 100)
-               o->cpuload = 100;
+       if (co->cpuload > 100)
+               co->cpuload = 100;
 
        /*
         * set thinktime_sleep and thinktime_spin appropriately
         */
        o->thinktime_blocks = 1;
        o->thinktime_spin = 0;
-       o->thinktime = (o->cpucycle * (100 - o->cpuload)) / o->cpuload;
+       o->thinktime = (co->cpucycle * (100 - co->cpuload)) / co->cpuload;
 
        o->nr_files = o->open_files = 1;
+
+       log_info("%s: ioengine=cpu, cpuload=%u, cpucycle=%u\n", td->o.name,
+                                               co->cpuload, co->cpucycle);
+
        return 0;
 }
 
@@ -49,6 +90,8 @@ static struct ioengine_ops ioengine = {
        .init           = fio_cpuio_init,
        .open_file      = fio_cpuio_open,
        .flags          = FIO_SYNCIO | FIO_DISKLESSIO | FIO_NOIO,
+       .options                = options,
+       .option_struct_size     = sizeof(struct cpu_options),
 };
 
 static void fio_init fio_cpuio_register(void)
index 4d1f3a3..d668325 100644 (file)
@@ -29,9 +29,11 @@ struct libaio_options {
 static struct fio_option options[] = {
        {
                .name   = "userspace_reap",
+               .lname  = "Libaio userspace reaping",
                .type   = FIO_OPT_STR_SET,
                .off1   = offsetof(struct libaio_options, userspace_reap),
                .help   = "Use alternative user-space reap implementation",
+               .category = FIO_OPT_C_IO,
        },
        {
                .name   = NULL,
index 3e03bc9..12f49a2 100644 (file)
@@ -58,25 +58,31 @@ static int str_hostname_cb(void *data, const char *input);
 static struct fio_option options[] = {
        {
                .name   = "hostname",
+               .lname  = "net engine hostname",
                .type   = FIO_OPT_STR_STORE,
                .cb     = str_hostname_cb,
                .help   = "Hostname for net IO engine",
+               .category = FIO_OPT_C_IO,
        },
        {
                .name   = "port",
+               .lname  = "net engine port",
                .type   = FIO_OPT_INT,
                .off1   = offsetof(struct netio_options, port),
                .minval = 1,
                .maxval = 65535,
                .help   = "Port to use for TCP or UDP net connections",
+               .category = FIO_OPT_C_IO,
        },
        {
                .name   = "protocol",
+               .lname  = "net engine protocol",
                .alias  = "proto",
                .type   = FIO_OPT_STR,
                .off1   = offsetof(struct netio_options, proto),
                .help   = "Network protocol to use",
                .def    = "tcp",
+               .category = FIO_OPT_C_IO,
                .posval = {
                          { .ival = "tcp",
                            .oval = FIO_TYPE_TCP,
@@ -102,9 +108,11 @@ static struct fio_option options[] = {
 #endif
        {
                .name   = "listen",
+               .lname  = "net engine listen",
                .type   = FIO_OPT_STR_SET,
                .off1   = offsetof(struct netio_options, listen),
                .help   = "Listen for incoming TCP connections",
+               .category = FIO_OPT_C_IO,
        },
        {
                .name   = "pingpong",
diff --git a/eta.c b/eta.c
index 39fe10f..238a0af 100644 (file)
--- a/eta.c
+++ b/eta.c
@@ -94,7 +94,7 @@ static void check_str_update(struct thread_data *td)
 /*
  * Convert seconds to a printable string.
  */
-static void eta_to_str(char *str, unsigned long eta_sec)
+void eta_to_str(char *str, unsigned long eta_sec)
 {
        unsigned int d, h, m, s;
        int disp_hour = 0;
@@ -319,22 +319,22 @@ int calc_thread_status(struct jobs_eta *je, int force)
                    || td->runstate == TD_PRE_READING) {
                        je->nr_running++;
                        if (td_read(td)) {
-                               je->t_rate += td->o.rate[DDIR_READ];
-                               je->t_iops += td->o.rate_iops[DDIR_READ];
-                               je->m_rate += td->o.ratemin[DDIR_READ];
-                               je->m_iops += td->o.rate_iops_min[DDIR_READ];
+                               je->t_rate[0] += td->o.rate[DDIR_READ];
+                               je->t_iops[0] += td->o.rate_iops[DDIR_READ];
+                               je->m_rate[0] += td->o.ratemin[DDIR_READ];
+                               je->m_iops[0] += td->o.rate_iops_min[DDIR_READ];
                        }
                        if (td_write(td)) {
-                               je->t_rate += td->o.rate[DDIR_WRITE];
-                               je->t_iops += td->o.rate_iops[DDIR_WRITE];
-                               je->m_rate += td->o.ratemin[DDIR_WRITE];
-                               je->m_iops += td->o.rate_iops_min[DDIR_WRITE];
+                               je->t_rate[1] += td->o.rate[DDIR_WRITE];
+                               je->t_iops[1] += td->o.rate_iops[DDIR_WRITE];
+                               je->m_rate[1] += td->o.ratemin[DDIR_WRITE];
+                               je->m_iops[1] += td->o.rate_iops_min[DDIR_WRITE];
                        }
                        if (td_trim(td)) {
-                               je->t_rate += td->o.rate[DDIR_TRIM];
-                               je->t_iops += td->o.rate_iops[DDIR_TRIM];
-                               je->m_rate += td->o.ratemin[DDIR_TRIM];
-                               je->m_iops += td->o.rate_iops_min[DDIR_TRIM];
+                               je->t_rate[2] += td->o.rate[DDIR_TRIM];
+                               je->t_iops[2] += td->o.rate_iops[DDIR_TRIM];
+                               je->m_rate[2] += td->o.ratemin[DDIR_TRIM];
+                               je->m_iops[2] += td->o.rate_iops_min[DDIR_TRIM];
                        }
 
                        je->files_open += td->nr_open_files;
@@ -433,16 +433,19 @@ void display_thread_status(struct jobs_eta *je)
        }
 
        p += sprintf(p, "Jobs: %d (f=%d)", je->nr_running, je->files_open);
-       if (je->m_rate || je->t_rate) {
+       if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
                char *tr, *mr;
 
-               mr = num2str(je->m_rate, 4, 0, je->is_pow2);
-               tr = num2str(je->t_rate, 4, 0, je->is_pow2);
+               mr = num2str(je->m_rate[0] + je->m_rate[1], 4, 0, je->is_pow2);
+               tr = num2str(je->t_rate[0] + je->t_rate[1], 4, 0, je->is_pow2);
                p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
                free(tr);
                free(mr);
-       } else if (je->m_iops || je->t_iops)
-               p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
+       } else if (je->m_iops[0] || je->m_iops[1] || je->t_iops[0] || je->t_iops[1]) {
+               p += sprintf(p, ", CR=%d/%d IOPS",
+                                       je->t_iops[0] + je->t_iops[1],
+                                       je->m_iops[0] + je->m_iops[1]);
+       }
        if (je->eta_sec != INT_MAX && je->nr_running) {
                char perc_str[32];
                char *iops_str[DDIR_RWDIR_CNT];
diff --git a/examples/1mbs_clients b/examples/1mbs_clients
deleted file mode 100644 (file)
index 505cd87..0000000
+++ /dev/null
@@ -1,104 +0,0 @@
-; Keep adding 1024kb/s reading clients at 4 seconds
-[global]
-size=32m
-rw=read
-directory=tmp
-rate=1250
-ratemin=1024
-
-[file1]
-startdelay=0
-
-[file2]
-startdelay=4
-
-[file3]
-startdelay=8
-
-[file4]
-startdelay=12
-
-[file5]
-startdelay=16
-
-[file6]
-startdelay=20
-
-[file7]
-startdelay=24
-
-[file8]
-startdelay=28
-
-[file9]
-startdelay=32
-
-[file10]
-startdelay=36
-
-[file11]
-startdelay=40
-
-[file12]
-startdelay=44
-
-[file13]
-startdelay=48
-
-[file14]
-startdelay=52
-
-[file15]
-startdelay=56
-
-[file16]
-startdelay=60
-
-[file17]
-startdelay=64
-
-[file18]
-startdelay=68
-
-[file19]
-startdelay=72
-
-[file20]
-startdelay=76
-
-[file21]
-startdelay=80
-
-[file22]
-startdelay=84
-
-[file23]
-startdelay=88
-
-[file24]
-startdelay=92
-
-[file25]
-startdelay=96
-
-[file26]
-startdelay=100
-
-[file27]
-startdelay=104
-
-[file28]
-startdelay=108
-
-[file29]
-startdelay=112
-
-[file30]
-startdelay=116
-
-[file31]
-startdelay=120
-
-[file32]
-startdelay=124
-
diff --git a/examples/1mbs_clients.fio b/examples/1mbs_clients.fio
new file mode 100644 (file)
index 0000000..505cd87
--- /dev/null
@@ -0,0 +1,104 @@
+; Keep adding 1024kb/s reading clients at 4 seconds
+[global]
+size=32m
+rw=read
+directory=tmp
+rate=1250
+ratemin=1024
+
+[file1]
+startdelay=0
+
+[file2]
+startdelay=4
+
+[file3]
+startdelay=8
+
+[file4]
+startdelay=12
+
+[file5]
+startdelay=16
+
+[file6]
+startdelay=20
+
+[file7]
+startdelay=24
+
+[file8]
+startdelay=28
+
+[file9]
+startdelay=32
+
+[file10]
+startdelay=36
+
+[file11]
+startdelay=40
+
+[file12]
+startdelay=44
+
+[file13]
+startdelay=48
+
+[file14]
+startdelay=52
+
+[file15]
+startdelay=56
+
+[file16]
+startdelay=60
+
+[file17]
+startdelay=64
+
+[file18]
+startdelay=68
+
+[file19]
+startdelay=72
+
+[file20]
+startdelay=76
+
+[file21]
+startdelay=80
+
+[file22]
+startdelay=84
+
+[file23]
+startdelay=88
+
+[file24]
+startdelay=92
+
+[file25]
+startdelay=96
+
+[file26]
+startdelay=100
+
+[file27]
+startdelay=104
+
+[file28]
+startdelay=108
+
+[file29]
+startdelay=112
+
+[file30]
+startdelay=116
+
+[file31]
+startdelay=120
+
+[file32]
+startdelay=124
+
diff --git a/examples/aio-read b/examples/aio-read
deleted file mode 100644 (file)
index 173a4e1..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-; Read 4 files with aio at different depths
-[global]
-ioengine=libaio
-buffered=0
-rw=randread
-bs=128k
-size=512m
-directory=/data1
-
-[file1]
-iodepth=4
-
-[file2]
-iodepth=32
-
-[file3]
-iodepth=8
-
-[file4]
-iodepth=16
diff --git a/examples/aio-read.fio b/examples/aio-read.fio
new file mode 100644 (file)
index 0000000..173a4e1
--- /dev/null
@@ -0,0 +1,20 @@
+; Read 4 files with aio at different depths
+[global]
+ioengine=libaio
+buffered=0
+rw=randread
+bs=128k
+size=512m
+directory=/data1
+
+[file1]
+iodepth=4
+
+[file2]
+iodepth=32
+
+[file3]
+iodepth=8
+
+[file4]
+iodepth=16
diff --git a/examples/disk-zone-profile b/examples/disk-zone-profile
deleted file mode 100644 (file)
index 96e5669..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-; Read disk in zones of 128m/2g, generating a plot of that afterwards
-; should give a nice picture of the zoning of this drive
-
-[global]
-bs=64k
-direct=1
-rw=read
-ioengine=libaio
-iodepth=2
-zonesize=256m
-zoneskip=2g
-write_bw_log
-
-[/dev/sdb]
diff --git a/examples/disk-zone-profile.fio b/examples/disk-zone-profile.fio
new file mode 100644 (file)
index 0000000..96e5669
--- /dev/null
@@ -0,0 +1,14 @@
+; Read disk in zones of 128m/2g, generating a plot of that afterwards
+; should give a nice picture of the zoning of this drive
+
+[global]
+bs=64k
+direct=1
+rw=read
+ioengine=libaio
+iodepth=2
+zonesize=256m
+zoneskip=2g
+write_bw_log
+
+[/dev/sdb]
diff --git a/examples/flow b/examples/flow
deleted file mode 100644 (file)
index 4b078cf..0000000
+++ /dev/null
@@ -1,25 +0,0 @@
-# Example usage of flows. The below will have roughly a 1:8 difference
-# between job2 and job1.
-[global]
-norandommap
-thread
-time_based
-runtime=30
-direct=1
-ioengine=libaio
-iodepth=256
-size=100g
-bs=8k
-filename=/tmp/testfile
-flow_watermark=100
-flow_sleep=1000
-
-[job2]
-numjobs=1
-rw=write
-flow=-8
-
-[job1]
-numjobs=1
-rw=randread
-flow=1
diff --git a/examples/flow.fio b/examples/flow.fio
new file mode 100644 (file)
index 0000000..4b078cf
--- /dev/null
@@ -0,0 +1,25 @@
+# Example usage of flows. The below will have roughly a 1:8 difference
+# between job2 and job1.
+[global]
+norandommap
+thread
+time_based
+runtime=30
+direct=1
+ioengine=libaio
+iodepth=256
+size=100g
+bs=8k
+filename=/tmp/testfile
+flow_watermark=100
+flow_sleep=1000
+
+[job2]
+numjobs=1
+rw=write
+flow=-8
+
+[job1]
+numjobs=1
+rw=randread
+flow=1
diff --git a/examples/fsx b/examples/fsx
deleted file mode 100644 (file)
index 6b48c6f..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-; This job file works pretty works similarly to running fsx-linux
-; with -r 4096 -w 4096 -Z -N 500000
-[file]
-ioengine=libaio
-iodepth=1
-rw=randrw
-size=256k
-bs=4k
-norandommap
-direct=1
-loops=500000
-rwmixcycle=40
diff --git a/examples/fsx.fio b/examples/fsx.fio
new file mode 100644 (file)
index 0000000..6b48c6f
--- /dev/null
@@ -0,0 +1,12 @@
+; This job file works pretty works similarly to running fsx-linux
+; with -r 4096 -w 4096 -Z -N 500000
+[file]
+ioengine=libaio
+iodepth=1
+rw=randrw
+size=256k
+bs=4k
+norandommap
+direct=1
+loops=500000
+rwmixcycle=40
diff --git a/examples/iometer-file-access-server b/examples/iometer-file-access-server
deleted file mode 100644 (file)
index 291bace..0000000
+++ /dev/null
@@ -1,18 +0,0 @@
-# This job file tries to mimic the Intel IOMeter File Server Access Pattern
-[global]
-description=Emulation of Intel IOmeter File Server Access Pattern
-
-[iometer]
-bssplit=512/10:1k/5:2k/5:4k/60:8k/2:16k/4:32k/4:64k/10
-rw=randrw
-rwmixread=80
-direct=1
-size=4g
-ioengine=libaio
-# IOMeter defines the server loads as the following:
-# iodepth=1    Linear
-# iodepth=4    Very Light
-# iodepth=8    Light
-# iodepth=64   Moderate
-# iodepth=256  Heavy
-iodepth=64
diff --git a/examples/iometer-file-access-server.fio b/examples/iometer-file-access-server.fio
new file mode 100644 (file)
index 0000000..291bace
--- /dev/null
@@ -0,0 +1,18 @@
+# This job file tries to mimic the Intel IOMeter File Server Access Pattern
+[global]
+description=Emulation of Intel IOmeter File Server Access Pattern
+
+[iometer]
+bssplit=512/10:1k/5:2k/5:4k/60:8k/2:16k/4:32k/4:64k/10
+rw=randrw
+rwmixread=80
+direct=1
+size=4g
+ioengine=libaio
+# IOMeter defines the server loads as the following:
+# iodepth=1    Linear
+# iodepth=4    Very Light
+# iodepth=8    Light
+# iodepth=64   Moderate
+# iodepth=256  Heavy
+iodepth=64
diff --git a/examples/netio b/examples/netio
deleted file mode 100644 (file)
index 3b1a7cd..0000000
+++ /dev/null
@@ -1,20 +0,0 @@
-# Example network job, just defines two clients that send/recv data
-[global]
-ioengine=net
-#Use hostname=/tmp.fio.sock for local unix domain sockets
-port=8888
-#Use =udp for UDP, =unix for local unix domain socket
-protocol=tcp
-bs=4k
-size=10g
-#set the below option to enable end-to-end data integrity tests
-#verify=md5
-
-[receiver]
-listen
-rw=read
-
-[sender]
-hostname=localhost
-startdelay=1
-rw=write
diff --git a/examples/netio.fio b/examples/netio.fio
new file mode 100644 (file)
index 0000000..0c5c77c
--- /dev/null
@@ -0,0 +1,20 @@
+# Example network job, just defines two clients that send/recv data
+[global]
+ioengine=net
+#Use hostname=/tmp.fio.sock for local unix domain sockets
+port=8888
+#Use =udp for UDP, =unix for local unix domain socket
+protocol=tcp
+bs=4k
+size=100g
+#set the below option to enable end-to-end data integrity tests
+#verify=md5
+
+[receiver]
+listen
+rw=read
+
+[sender]
+hostname=localhost
+startdelay=1
+rw=write
diff --git a/examples/null b/examples/null
deleted file mode 100644 (file)
index 9d2f3e0..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-[global]
-bs=4k
-gtod_reduce=1
-
-[null]
-ioengine=null
-size=100g
-rw=randread
-norandommap
-time_based=0
diff --git a/examples/null.fio b/examples/null.fio
new file mode 100644 (file)
index 0000000..9d2f3e0
--- /dev/null
@@ -0,0 +1,10 @@
+[global]
+bs=4k
+gtod_reduce=1
+
+[null]
+ioengine=null
+size=100g
+rw=randread
+norandommap
+time_based=0
diff --git a/examples/rdmaio-client b/examples/rdmaio-client
deleted file mode 100644 (file)
index 7c660c9..0000000
+++ /dev/null
@@ -1,11 +0,0 @@
-# Example rdma client job
-[global]
-ioengine=rdma
-filename=[ip_addr]/[port]/[RDMA_WRITE/RDMA_READ/SEND]
-bs=1m
-size=100g
-
-[sender]
-rw=write
-iodepth=1
-iodepth_batch_complete=1
\ No newline at end of file
diff --git a/examples/rdmaio-client.fio b/examples/rdmaio-client.fio
new file mode 100644 (file)
index 0000000..7c660c9
--- /dev/null
@@ -0,0 +1,11 @@
+# Example rdma client job
+[global]
+ioengine=rdma
+filename=[ip_addr]/[port]/[RDMA_WRITE/RDMA_READ/SEND]
+bs=1m
+size=100g
+
+[sender]
+rw=write
+iodepth=1
+iodepth_batch_complete=1
\ No newline at end of file
diff --git a/examples/rdmaio-server b/examples/rdmaio-server
deleted file mode 100644 (file)
index 9348859..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-# Example rdma server job
-[global]
-ioengine=rdma
-filename=[ip_addr]/[port]
-bs=1m
-size=100g
-
-[receiver]
-rw=read
-iodepth=16
\ No newline at end of file
diff --git a/examples/rdmaio-server.fio b/examples/rdmaio-server.fio
new file mode 100644 (file)
index 0000000..9348859
--- /dev/null
@@ -0,0 +1,10 @@
+# Example rdma server job
+[global]
+ioengine=rdma
+filename=[ip_addr]/[port]
+bs=1m
+size=100g
+
+[receiver]
+rw=read
+iodepth=16
\ No newline at end of file
diff --git a/examples/ssd-test b/examples/ssd-test
deleted file mode 100644 (file)
index c84cf50..0000000
+++ /dev/null
@@ -1,37 +0,0 @@
-# Do some important numbers on SSD drives, to gauge what kind of
-# performance you might get out of them.
-#
-# Sequential read and write speeds are tested, these are expected to be
-# high. Random reads should also be fast, random writes are where crap
-# drives are usually separated from the good drives.
-#
-# This uses a queue depth of 4. New SATA SSD's will support up to 32
-# in flight commands, so it may also be interesting to increase the queue
-# depth and compare. Note that most real-life usage will not see that
-# large of a queue depth, so 4 is more representative of normal use.
-#
-[global]
-bs=4k
-ioengine=libaio
-iodepth=4
-size=1g
-direct=1
-runtime=60
-directory=/mount-point-of-ssd
-filename=ssd.test.file
-
-[seq-read]
-rw=read
-stonewall
-
-[rand-read]
-rw=randread
-stonewall
-
-[seq-write]
-rw=write
-stonewall
-
-[rand-write]
-rw=randwrite
-stonewall
diff --git a/examples/ssd-test.fio b/examples/ssd-test.fio
new file mode 100644 (file)
index 0000000..c84cf50
--- /dev/null
@@ -0,0 +1,37 @@
+# Do some important numbers on SSD drives, to gauge what kind of
+# performance you might get out of them.
+#
+# Sequential read and write speeds are tested, these are expected to be
+# high. Random reads should also be fast, random writes are where crap
+# drives are usually separated from the good drives.
+#
+# This uses a queue depth of 4. New SATA SSD's will support up to 32
+# in flight commands, so it may also be interesting to increase the queue
+# depth and compare. Note that most real-life usage will not see that
+# large of a queue depth, so 4 is more representative of normal use.
+#
+[global]
+bs=4k
+ioengine=libaio
+iodepth=4
+size=1g
+direct=1
+runtime=60
+directory=/mount-point-of-ssd
+filename=ssd.test.file
+
+[seq-read]
+rw=read
+stonewall
+
+[rand-read]
+rw=randread
+stonewall
+
+[seq-write]
+rw=write
+stonewall
+
+[rand-write]
+rw=randwrite
+stonewall
diff --git a/examples/surface-scan b/examples/surface-scan
deleted file mode 100644 (file)
index dc3373a..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-; writes 512 byte verification blocks until the disk is full,
-; then verifies written data
-[global]
-thread=1
-bs=64k
-direct=1
-ioengine=sync
-verify=meta
-verify_pattern=0xaa555aa5
-verify_interval=512
-
-[write-phase]
-filename=datafile.tmp  ; or use a full disk, for example /dev/sda
-rw=write
-fill_device=1
-do_verify=0
-
-[verify-phase]
-stonewall
-create_serialize=0
-filename=datafile.tmp
-rw=read
-do_verify=1
diff --git a/examples/surface-scan.fio b/examples/surface-scan.fio
new file mode 100644 (file)
index 0000000..dc3373a
--- /dev/null
@@ -0,0 +1,23 @@
+; writes 512 byte verification blocks until the disk is full,
+; then verifies written data
+[global]
+thread=1
+bs=64k
+direct=1
+ioengine=sync
+verify=meta
+verify_pattern=0xaa555aa5
+verify_interval=512
+
+[write-phase]
+filename=datafile.tmp  ; or use a full disk, for example /dev/sda
+rw=write
+fill_device=1
+do_verify=0
+
+[verify-phase]
+stonewall
+create_serialize=0
+filename=datafile.tmp
+rw=read
+do_verify=1
diff --git a/examples/tiobench-example b/examples/tiobench-example
deleted file mode 100644 (file)
index 5a4493e..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-; tiobench like setup, add more fX files between the stonewalls to
-; create more threads
-
-[global]
-direct=1
-size=512m
-bsrange=4k-4k
-timeout=60
-numjobs=4      ; 4 simultaneous threads for each job
-
-[f1]
-rw=write
-
-[f2]
-stonewall
-rw=randwrite
-
-[f3]
-stonewall
-rw=read
-
-[f4]
-stonewall
-rw=randread
diff --git a/examples/tiobench-example.fio b/examples/tiobench-example.fio
new file mode 100644 (file)
index 0000000..5a4493e
--- /dev/null
@@ -0,0 +1,24 @@
+; tiobench like setup, add more fX files between the stonewalls to
+; create more threads
+
+[global]
+direct=1
+size=512m
+bsrange=4k-4k
+timeout=60
+numjobs=4      ; 4 simultaneous threads for each job
+
+[f1]
+rw=write
+
+[f2]
+stonewall
+rw=randwrite
+
+[f3]
+stonewall
+rw=read
+
+[f4]
+stonewall
+rw=randread
index 5aadf12..3054d9d 100644 (file)
@@ -96,9 +96,9 @@ static int extend_file(struct thread_data *td, struct fio_file *f)
 
                        r = fallocate(f->fd, FALLOC_FL_KEEP_SIZE, 0,
                                        f->real_file_size);
-                       if (r != 0) {
+                       if (r != 0)
                                td_verror(td, errno, "fallocate");
-                       }
+
                        break;
 #endif /* CONFIG_LINUX_FALLOCATE */
                default:
@@ -919,9 +919,9 @@ static int __init_rand_distribution(struct thread_data *td, struct fio_file *f)
                seed = td->rand_seeds[4];
 
        if (td->o.random_distribution == FIO_RAND_DIST_ZIPF)
-               zipf_init(&f->zipf, nranges, td->o.zipf_theta, seed);
+               zipf_init(&f->zipf, nranges, td->o.zipf_theta.u.f, seed);
        else
-               pareto_init(&f->zipf, nranges, td->o.pareto_h, seed);
+               pareto_init(&f->zipf, nranges, td->o.pareto_h.u.f, seed);
 
        return 1;
 }
diff --git a/fio.1 b/fio.1
index 6b7e945..c665591 100644 (file)
--- a/fio.1
+++ b/fio.1
@@ -1146,6 +1146,12 @@ Some parameters are only valid when a specific ioengine is in use. These are
 used identically to normal parameters, with the caveat that when used on the
 command line, the must come after the ioengine that defines them is selected.
 .TP
+.BI (cpu)cpuload \fR=\fPint
+Attempt to use the specified percentage of CPU cycles.
+.TP
+.BI (cpu)cpuchunks \fR=\fPint
+Split the load into cycles of the given time. In microseconds.
+.TP
 .BI (libaio)userspace_reap
 Normally, with the libaio engine in use, fio will use
 the io_getevents system call to reap newly returned events.
diff --git a/fio.c b/fio.c
index af4c12c..7e6b06d 100644 (file)
--- a/fio.c
+++ b/fio.c
 #include "fio.h"
 #include "smalloc.h"
 
-uintptr_t page_mask;
-uintptr_t page_size;
-
-static int endian_check(void)
-{
-       union {
-               uint8_t c[8];
-               uint64_t v;
-       } u;
-       int le = 0, be = 0;
-
-       u.v = 0x12;
-       if (u.c[7] == 0x12)
-               be = 1;
-       else if (u.c[0] == 0x12)
-               le = 1;
-
-#if defined(CONFIG_LITTLE_ENDIAN)
-       if (be)
-               return 1;
-#elif defined(CONFIG_BIG_ENDIAN)
-       if (le)
-               return 1;
-#else
-       return 1;
-#endif
-
-       if (!le && !be)
-               return 1;
-
-       return 0;
-}
-
 int main(int argc, char *argv[], char *envp[])
 {
-       long ps;
-
-       if (endian_check()) {
-               log_err("fio: endianness settings appear wrong.\n");
-               log_err("fio: please report this to fio@vger.kernel.org\n");
+       if (initialize_fio(envp))
                return 1;
-       }
 
 #if !defined(CONFIG_GETTIMEOFDAY) && !defined(CONFIG_CLOCK_GETTIME)
 #error "No available clock source!"
 #endif
 
-       arch_init(envp);
-
-       sinit();
-
-       /*
-        * We need locale for number printing, if it isn't set then just
-        * go with the US format.
-        */
-       if (!getenv("LC_NUMERIC"))
-               setlocale(LC_NUMERIC, "en_US");
-
-       ps = sysconf(_SC_PAGESIZE);
-       if (ps < 0) {
-               log_err("Failed to get page size\n");
-               return 1;
-       }
-
-       page_size = ps;
-       page_mask = ps - 1;
-
-       fio_keywords_init();
-
        if (parse_options(argc, argv))
                return 1;
 
        fio_time_init();
 
-       if (nr_clients)
-               return fio_handle_clients();
-       else
+       if (nr_clients) {
+               if (fio_start_all_clients())
+                       return 1;
+               return fio_handle_clients(&fio_client_ops);
+       } else
                return fio_backend();
 }
diff --git a/fio.h b/fio.h
index d18029a..5bfa438 100644 (file)
--- a/fio.h
+++ b/fio.h
 struct thread_data;
 
 #include "compiler/compiler.h"
+#include "thread_options.h"
 #include "flist.h"
 #include "fifo.h"
-#include "rbtree.h"
+#include "lib/rbtree.h"
 #include "arch/arch.h"
 #include "os/os.h"
 #include "mutex.h"
@@ -36,6 +37,7 @@ struct thread_data;
 #include "gettime.h"
 #include "lib/getopt.h"
 #include "lib/rand.h"
+#include "client.h"
 #include "server.h"
 #include "stat.h"
 #include "flow.h"
@@ -54,17 +56,6 @@ struct thread_data;
 #define MPOL_LOCAL MPOL_MAX
 #endif
 
-/*
- * What type of allocation to use for io buffers
- */
-enum fio_memtype {
-       MEM_MALLOC = 0, /* ordinary malloc */
-       MEM_SHM,        /* use shared memory segments */
-       MEM_SHMHUGE,    /* use shared memory segments with huge pages */
-       MEM_MMAP,       /* use anonynomous mmap */
-       MEM_MMAPHUGE,   /* memory mapped huge file */
-};
-
 /*
  * offset generator types
  */
@@ -73,241 +64,6 @@ enum {
        RW_SEQ_IDENT,
 };
 
-/*
- * What type of errors to continue on when continue_on_error is used
- */
-enum error_type_bit {
-       ERROR_TYPE_READ_BIT = 0,
-       ERROR_TYPE_WRITE_BIT = 1,
-       ERROR_TYPE_VERIFY_BIT = 2,
-       ERROR_TYPE_CNT = 3,
-};
-
-enum error_type {
-        ERROR_TYPE_NONE = 0,
-        ERROR_TYPE_READ = 1 << ERROR_TYPE_READ_BIT,
-        ERROR_TYPE_WRITE = 1 << ERROR_TYPE_WRITE_BIT,
-        ERROR_TYPE_VERIFY = 1 << ERROR_TYPE_VERIFY_BIT,
-        ERROR_TYPE_ANY = 0xffff,
-};
-
-struct bssplit {
-       unsigned int bs;
-       unsigned char perc;
-};
-
-struct thread_options {
-       int pad;
-       char *description;
-       char *name;
-       char *directory;
-       char *filename;
-       char *opendir;
-       char *ioengine;
-       enum td_ddir td_ddir;
-       unsigned int rw_seq;
-       unsigned int kb_base;
-       unsigned int ddir_seq_nr;
-       long ddir_seq_add;
-       unsigned int iodepth;
-       unsigned int iodepth_low;
-       unsigned int iodepth_batch;
-       unsigned int iodepth_batch_complete;
-
-       unsigned long long size;
-       unsigned int size_percent;
-       unsigned int fill_device;
-       unsigned long long file_size_low;
-       unsigned long long file_size_high;
-       unsigned long long start_offset;
-
-       unsigned int bs[DDIR_RWDIR_CNT];
-       unsigned int ba[DDIR_RWDIR_CNT];
-       unsigned int min_bs[DDIR_RWDIR_CNT];
-       unsigned int max_bs[DDIR_RWDIR_CNT];
-       struct bssplit *bssplit[DDIR_RWDIR_CNT];
-       unsigned int bssplit_nr[DDIR_RWDIR_CNT];
-
-       int *ignore_error[ERROR_TYPE_CNT];
-       unsigned int ignore_error_nr[ERROR_TYPE_CNT];
-       unsigned int error_dump;
-
-       unsigned int nr_files;
-       unsigned int open_files;
-       enum file_lock_mode file_lock_mode;
-       unsigned int lockfile_batch;
-
-       unsigned int odirect;
-       unsigned int invalidate_cache;
-       unsigned int create_serialize;
-       unsigned int create_fsync;
-       unsigned int create_on_open;
-       unsigned int create_only;
-       unsigned int end_fsync;
-       unsigned int pre_read;
-       unsigned int sync_io;
-       unsigned int verify;
-       unsigned int do_verify;
-       unsigned int verifysort;
-       unsigned int verifysort_nr;
-       unsigned int verify_interval;
-       unsigned int verify_offset;
-       char verify_pattern[MAX_PATTERN_SIZE];
-       unsigned int verify_pattern_bytes;
-       unsigned int verify_fatal;
-       unsigned int verify_dump;
-       unsigned int verify_async;
-       unsigned long long verify_backlog;
-       unsigned int verify_batch;
-       unsigned int experimental_verify;
-       unsigned int use_thread;
-       unsigned int unlink;
-       unsigned int do_disk_util;
-       unsigned int override_sync;
-       unsigned int rand_repeatable;
-       unsigned int use_os_rand;
-       unsigned int write_lat_log;
-       unsigned int write_bw_log;
-       unsigned int write_iops_log;
-       unsigned int log_avg_msec;
-       unsigned int norandommap;
-       unsigned int softrandommap;
-       unsigned int bs_unaligned;
-       unsigned int fsync_on_close;
-
-       unsigned int random_distribution;
-       double zipf_theta;
-       double pareto_h;
-
-       unsigned int random_generator;
-
-       unsigned int hugepage_size;
-       unsigned int rw_min_bs;
-       unsigned int thinktime;
-       unsigned int thinktime_spin;
-       unsigned int thinktime_blocks;
-       unsigned int fsync_blocks;
-       unsigned int fdatasync_blocks;
-       unsigned int barrier_blocks;
-       unsigned long long start_delay;
-       unsigned long long timeout;
-       unsigned long long ramp_time;
-       unsigned int overwrite;
-       unsigned int bw_avg_time;
-       unsigned int iops_avg_time;
-       unsigned int loops;
-       unsigned long long zone_range;
-       unsigned long long zone_size;
-       unsigned long long zone_skip;
-       enum fio_memtype mem_type;
-       unsigned int mem_align;
-
-       unsigned int max_latency;
-
-       unsigned int stonewall;
-       unsigned int new_group;
-       unsigned int numjobs;
-       os_cpu_mask_t cpumask;
-       unsigned int cpumask_set;
-       os_cpu_mask_t verify_cpumask;
-       unsigned int verify_cpumask_set;
-#ifdef CONFIG_LIBNUMA
-       struct bitmask *numa_cpunodesmask;
-       unsigned int numa_cpumask_set;
-       unsigned short numa_mem_mode;
-       unsigned int numa_mem_prefer_node;
-       struct bitmask *numa_memnodesmask;
-       unsigned int numa_memmask_set;
-#endif
-       unsigned int iolog;
-       unsigned int rwmixcycle;
-       unsigned int rwmix[2];
-       unsigned int nice;
-       unsigned int file_service_type;
-       unsigned int group_reporting;
-       unsigned int fadvise_hint;
-       enum fio_fallocate_mode fallocate_mode;
-       unsigned int zero_buffers;
-       unsigned int refill_buffers;
-       unsigned int scramble_buffers;
-       unsigned int compress_percentage;
-       unsigned int compress_chunk;
-       unsigned int time_based;
-       unsigned int disable_lat;
-       unsigned int disable_clat;
-       unsigned int disable_slat;
-       unsigned int disable_bw;
-       unsigned int unified_rw_rep;
-       unsigned int gtod_reduce;
-       unsigned int gtod_cpu;
-       unsigned int gtod_offload;
-       enum fio_cs clocksource;
-       unsigned int no_stall;
-       unsigned int trim_percentage;
-       unsigned int trim_batch;
-       unsigned int trim_zero;
-       unsigned long long trim_backlog;
-       unsigned int clat_percentiles;
-       unsigned int overwrite_plist;
-       fio_fp64_t percentile_list[FIO_IO_U_LIST_MAX_LEN];
-
-       char *read_iolog_file;
-       char *write_iolog_file;
-       char *bw_log_file;
-       char *lat_log_file;
-       char *iops_log_file;
-       char *replay_redirect;
-
-       /*
-        * Pre-run and post-run shell
-        */
-       char *exec_prerun;
-       char *exec_postrun;
-
-       unsigned int rate[DDIR_RWDIR_CNT];
-       unsigned int ratemin[DDIR_RWDIR_CNT];
-       unsigned int ratecycle;
-       unsigned int rate_iops[DDIR_RWDIR_CNT];
-       unsigned int rate_iops_min[DDIR_RWDIR_CNT];
-
-       char *ioscheduler;
-
-       /*
-        * CPU "io" cycle burner
-        */
-       unsigned int cpuload;
-       unsigned int cpucycle;
-
-       /*
-        * I/O Error handling
-        */
-       enum error_type continue_on_error;
-
-       /*
-        * Benchmark profile type
-        */
-       char *profile;
-
-       /*
-        * blkio cgroup support
-        */
-       char *cgroup;
-       unsigned int cgroup_weight;
-       unsigned int cgroup_nodelete;
-
-       unsigned int uid;
-       unsigned int gid;
-
-       int flow_id;
-       int flow;
-       int flow_watermark;
-       unsigned int flow_sleep;
-
-       unsigned long long offset_increment;
-
-       unsigned int sync_file_range;
-};
-
 enum {
        TD_F_VER_BACKLOG        = 1,
        TD_F_TRIM_BACKLOG       = 2,
@@ -339,10 +95,12 @@ struct thread_data {
        void *eo;
        char verror[FIO_VERROR_SIZE];
        pthread_t thread;
-       int thread_number;
-       int groupid;
+       unsigned int thread_number;
+       unsigned int groupid;
        struct thread_stat ts;
 
+       int client_type;
+
        struct io_log *slat_log;
        struct io_log *clat_log;
        struct io_log *lat_log;
@@ -377,12 +135,9 @@ struct thread_data {
        size_t orig_buffer_size;
        volatile int terminate;
        volatile int runstate;
-       unsigned int ioprio;
-       unsigned int ioprio_set;
        unsigned int last_was_sync;
        enum fio_ddir last_ddir;
 
-       char *mmapfile;
        int mmapfd;
 
        void *iolog_buf;
@@ -550,6 +305,8 @@ struct thread_data {
         */
        struct prof_io_ops prof_io_ops;
        void *prof_data;
+
+       void *pinned_mem;
 };
 
 /*
@@ -585,12 +342,10 @@ enum {
 extern int exitall_on_terminate;
 extern unsigned int thread_number;
 extern unsigned int stat_number;
-extern unsigned int nr_process, nr_thread;
 extern int shm_id;
 extern int groupid;
 extern int output_format;
 extern int temp_stall_ts;
-extern unsigned long long mlock_size;
 extern uintptr_t page_mask, page_size;
 extern int read_only;
 extern int eta_print;
@@ -665,9 +420,10 @@ static inline int should_fsync(struct thread_data *td)
 /*
  * Init/option functions
  */
+extern int __must_check fio_init_options(void);
 extern int __must_check parse_options(int, char **);
-extern int parse_jobs_ini(char *, int, int);
-extern int parse_cmd_line(int, char **);
+extern int parse_jobs_ini(char *, int, int, int);
+extern int parse_cmd_line(int, char **, int);
 extern int fio_backend(void);
 extern void reset_fio_state(void);
 extern void clear_io_state(struct thread_data *);
@@ -682,10 +438,14 @@ extern void fio_options_dup_and_init(struct option *);
 extern void fio_options_mem_dupe(struct thread_data *);
 extern void options_mem_dupe(void *data, struct fio_option *options);
 extern void td_fill_rand_seeds(struct thread_data *);
-extern void add_job_opts(const char **);
+extern void add_job_opts(const char **, int);
 extern char *num2str(unsigned long, int, int, int);
 extern int ioengine_load(struct thread_data *);
 
+extern unsigned long page_mask;
+extern unsigned long page_size;
+extern int initialize_fio(char *envp[]);
+
 #define FIO_GETOPT_JOB         0x89000000
 #define FIO_GETOPT_IOENGINE    0x98000000
 #define FIO_NR_OPTIONS         (FIO_MAX_OPTS + 128)
@@ -695,6 +455,7 @@ extern int ioengine_load(struct thread_data *);
  */
 extern void print_thread_status(void);
 extern void print_status_init(int);
+extern char *fio_uint_to_kmg(unsigned int val);
 
 /*
  * Thread life cycle. Once a thread has a runstate beyond TD_INITIALIZED, it
@@ -723,10 +484,11 @@ extern void fio_terminate_threads(int);
 /*
  * Memory helpers
  */
-extern int __must_check fio_pin_memory(void);
-extern void fio_unpin_memory(void);
+extern int __must_check fio_pin_memory(struct thread_data *);
+extern void fio_unpin_memory(struct thread_data *);
 extern int __must_check allocate_io_mem(struct thread_data *);
 extern void free_io_mem(struct thread_data *);
+extern void free_threads_shm(void);
 
 /*
  * Reset stats after ramp time completes
@@ -835,6 +597,8 @@ static inline void td_io_u_free_notify(struct thread_data *td)
 extern const char *fio_get_arch_string(int);
 extern const char *fio_get_os_string(int);
 
+#define ARRAY_SIZE(x) (sizeof((x)) / (sizeof((x)[0])))
+
 enum {
        FIO_OUTPUT_TERSE        = 0,
        FIO_OUTPUT_JSON,
diff --git a/gclient.c b/gclient.c
new file mode 100644 (file)
index 0000000..b8c681a
--- /dev/null
+++ b/gclient.c
@@ -0,0 +1,1401 @@
+#include <malloc.h>
+#include <string.h>
+
+#include <glib.h>
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+#include "fio.h"
+#include "gfio.h"
+#include "ghelpers.h"
+#include "goptions.h"
+#include "gerror.h"
+#include "graph.h"
+#include "gclient.h"
+#include "printing.h"
+
+static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts,
+                           struct group_run_stats *rs);
+
+static gboolean results_window_delete(GtkWidget *w, gpointer data)
+{
+       struct gui_entry *ge = (struct gui_entry *) data;
+
+       gtk_widget_destroy(w);
+       ge->results_window = NULL;
+       ge->results_notebook = NULL;
+       return TRUE;
+}
+
+static void results_close(GtkWidget *w, gpointer *data)
+{
+       struct gui_entry *ge = (struct gui_entry *) data;
+
+       gtk_widget_destroy(ge->results_window);
+}
+
+static void results_print(GtkWidget *w, gpointer *data)
+{
+       struct gui_entry *ge = (struct gui_entry *) data;
+
+       gfio_print_results(ge);
+}
+
+static GtkActionEntry results_menu_items[] = {
+       { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
+       { "GraphMenuAction", GTK_STOCK_FILE, "Graph", NULL, NULL, NULL},
+       { "PrintFile", GTK_STOCK_PRINT, "Print", "<Control>P", NULL, G_CALLBACK(results_print) },
+       { "CloseFile", GTK_STOCK_CLOSE, "Close", "<Control>W", NULL, G_CALLBACK(results_close) },
+};
+static gint results_nmenu_items = sizeof(results_menu_items) / sizeof(results_menu_items[0]);
+
+static const gchar *results_ui_string = " \
+       <ui> \
+               <menubar name=\"MainMenu\"> \
+                       <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
+                               <menuitem name=\"Print\" action=\"PrintFile\" /> \
+                               <menuitem name=\"Close\" action=\"CloseFile\" /> \
+                       </menu> \
+                       <menu name=\"GraphMenu\" action=\"GraphMenuAction\"> \
+                       </menu>\
+               </menubar> \
+       </ui> \
+";
+
+static GtkWidget *get_results_menubar(GtkWidget *window, struct gui_entry *ge)
+{
+       GtkActionGroup *action_group;
+       GtkWidget *widget;
+       GError *error = 0;
+
+       ge->results_uimanager = gtk_ui_manager_new();
+
+       action_group = gtk_action_group_new("ResultsMenu");
+       gtk_action_group_add_actions(action_group, results_menu_items, results_nmenu_items, ge);
+
+       gtk_ui_manager_insert_action_group(ge->results_uimanager, action_group, 0);
+       gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ge->results_uimanager), results_ui_string, -1, &error);
+
+       gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ge->results_uimanager));
+
+       widget = gtk_ui_manager_get_widget(ge->results_uimanager, "/MainMenu");
+       return widget;
+}
+
+static GtkWidget *get_results_window(struct gui_entry *ge)
+{
+       GtkWidget *win, *notebook, *vbox;
+
+       if (ge->results_window)
+               return ge->results_notebook;
+
+       win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_title(GTK_WINDOW(win), "Results");
+       gtk_window_set_default_size(GTK_WINDOW(win), 1024, 768);
+       g_signal_connect(win, "delete-event", G_CALLBACK(results_window_delete), ge);
+       g_signal_connect(win, "destroy", G_CALLBACK(results_window_delete), ge);
+
+       vbox = gtk_vbox_new(FALSE, 0);
+       gtk_container_add(GTK_CONTAINER(win), vbox);
+
+       ge->results_menu = get_results_menubar(win, ge);
+       gtk_box_pack_start(GTK_BOX(vbox), ge->results_menu, FALSE, FALSE, 0);
+
+       notebook = gtk_notebook_new();
+       gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1);
+       gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
+       gtk_container_add(GTK_CONTAINER(vbox), notebook);
+
+       ge->results_window = win;
+       ge->results_notebook = notebook;
+       return ge->results_notebook;
+}
+
+static void gfio_text_op(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct cmd_text_pdu *p = (struct cmd_text_pdu *) cmd->payload;
+       struct gfio_client *gc = client->client_data;
+       struct gui_entry *ge = gc->ge;
+       struct gui *ui = ge->ui;
+       GtkTreeIter iter;
+       struct tm *tm;
+       time_t sec;
+       char tmp[64], timebuf[80];
+
+       sec = p->log_sec;
+       tm = localtime(&sec);
+       strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", tm);
+       sprintf(timebuf, "%s.%03ld", tmp, (long) p->log_usec / 1000);
+
+       gdk_threads_enter();
+
+       gtk_list_store_append(ui->log_model, &iter);
+       gtk_list_store_set(ui->log_model, &iter, 0, timebuf, -1);
+       gtk_list_store_set(ui->log_model, &iter, 1, client->hostname, -1);
+       gtk_list_store_set(ui->log_model, &iter, 2, log_get_level(p->level), -1);
+       gtk_list_store_set(ui->log_model, &iter, 3, p->buf, -1);
+
+       if (p->level == FIO_LOG_ERR)
+               gfio_view_log(ui);
+
+       gdk_threads_leave();
+}
+
+static void disk_util_destroy(GtkWidget *w, gpointer data)
+{
+       struct gui_entry *ge = (struct gui_entry *) data;
+
+       ge->disk_util_vbox = NULL;
+       gtk_widget_destroy(w);
+}
+
+static GtkWidget *gfio_disk_util_get_vbox(struct gui_entry *ge)
+{
+       GtkWidget *vbox, *box, *scroll, *res_notebook;
+
+       if (ge->disk_util_vbox)
+               return ge->disk_util_vbox;
+
+       scroll = get_scrolled_window(5);
+       vbox = gtk_vbox_new(FALSE, 3);
+       box = gtk_hbox_new(FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
+
+       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
+       res_notebook = get_results_window(ge);
+
+       gtk_notebook_append_page(GTK_NOTEBOOK(res_notebook), scroll, gtk_label_new("Disk utilization"));
+       ge->disk_util_vbox = box;
+       g_signal_connect(vbox, "destroy", G_CALLBACK(disk_util_destroy), ge);
+
+       return ge->disk_util_vbox;
+}
+
+static int __gfio_disk_util_show(GtkWidget *res_notebook,
+                                struct gfio_client *gc, struct cmd_du_pdu *p)
+{
+       GtkWidget *box, *frame, *entry, *vbox, *util_vbox;
+       struct gui_entry *ge = gc->ge;
+       double util;
+       char tmp[16];
+
+       util_vbox = gfio_disk_util_get_vbox(ge);
+
+       vbox = gtk_vbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(util_vbox), vbox);
+
+       frame = gtk_frame_new((char *) p->dus.name);
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 2);
+
+       box = gtk_vbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), box);
+
+       frame = gtk_frame_new("Read");
+       gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 2);
+       vbox = gtk_hbox_new(TRUE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), vbox);
+       entry = new_info_entry_in_frame(vbox, "IOs");
+       entry_set_int_value(entry, p->dus.ios[0]);
+       entry = new_info_entry_in_frame(vbox, "Merges");
+       entry_set_int_value(entry, p->dus.merges[0]);
+       entry = new_info_entry_in_frame(vbox, "Sectors");
+       entry_set_int_value(entry, p->dus.sectors[0]);
+       entry = new_info_entry_in_frame(vbox, "Ticks");
+       entry_set_int_value(entry, p->dus.ticks[0]);
+
+       frame = gtk_frame_new("Write");
+       gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 2);
+       vbox = gtk_hbox_new(TRUE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), vbox);
+       entry = new_info_entry_in_frame(vbox, "IOs");
+       entry_set_int_value(entry, p->dus.ios[1]);
+       entry = new_info_entry_in_frame(vbox, "Merges");
+       entry_set_int_value(entry, p->dus.merges[1]);
+       entry = new_info_entry_in_frame(vbox, "Sectors");
+       entry_set_int_value(entry, p->dus.sectors[1]);
+       entry = new_info_entry_in_frame(vbox, "Ticks");
+       entry_set_int_value(entry, p->dus.ticks[1]);
+
+       frame = gtk_frame_new("Shared");
+       gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 2);
+       vbox = gtk_hbox_new(TRUE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), vbox);
+       entry = new_info_entry_in_frame(vbox, "IO ticks");
+       entry_set_int_value(entry, p->dus.io_ticks);
+       entry = new_info_entry_in_frame(vbox, "Time in queue");
+       entry_set_int_value(entry, p->dus.time_in_queue);
+
+       util = 0.0;
+       if (p->dus.msec)
+               util = (double) 100 * p->dus.io_ticks / (double) p->dus.msec;
+       if (util > 100.0)
+               util = 100.0;
+
+       sprintf(tmp, "%3.2f%%", util);
+       entry = new_info_entry_in_frame(vbox, "Disk utilization");
+       gtk_entry_set_text(GTK_ENTRY(entry), tmp);
+
+       gtk_widget_show_all(ge->results_window);
+       return 0;
+}
+
+static int gfio_disk_util_show(struct gfio_client *gc)
+{
+       struct gui_entry *ge = gc->ge;
+       GtkWidget *res_notebook;
+       int i;
+
+       if (!gc->nr_du)
+               return 1;
+
+       res_notebook = get_results_window(ge);
+
+       for (i = 0; i < gc->nr_du; i++) {
+               struct cmd_du_pdu *p = &gc->du[i];
+
+               __gfio_disk_util_show(res_notebook, gc, p);
+       }
+
+       gtk_widget_show_all(ge->results_window);
+       return 0;
+}
+
+static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct cmd_du_pdu *p = (struct cmd_du_pdu *) cmd->payload;
+       struct gfio_client *gc = client->client_data;
+       struct gui_entry *ge = gc->ge;
+       unsigned int nr = gc->nr_du;
+
+       gc->du = realloc(gc->du, (nr + 1) * sizeof(struct cmd_du_pdu));
+       memcpy(&gc->du[nr], p, sizeof(*p));
+       gc->nr_du++;
+
+       gdk_threads_enter();
+       if (ge->results_window)
+               __gfio_disk_util_show(ge->results_notebook, gc, p);
+       else
+               gfio_disk_util_show(gc);
+       gdk_threads_leave();
+}
+
+extern int sum_stat_clients;
+extern struct thread_stat client_ts;
+extern struct group_run_stats client_gs;
+
+static int sum_stat_nr;
+
+static void gfio_thread_status_op(struct fio_client *client,
+                                 struct fio_net_cmd *cmd)
+{
+       struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
+
+       gfio_display_ts(client, &p->ts, &p->rs);
+
+       if (sum_stat_clients == 1)
+               return;
+
+       sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
+       sum_group_stats(&client_gs, &p->rs);
+
+       client_ts.members++;
+       client_ts.thread_number = p->ts.thread_number;
+       client_ts.groupid = p->ts.groupid;
+
+       if (++sum_stat_nr == sum_stat_clients) {
+               strcpy(client_ts.name, "All clients");
+               gfio_display_ts(client, &client_ts, &client_gs);
+       }
+}
+
+static void gfio_group_stats_op(struct fio_client *client,
+                               struct fio_net_cmd *cmd)
+{
+       /* We're ignoring group stats for now */
+}
+
+static void gfio_update_thread_status(struct gui_entry *ge,
+                                     char *status_message, double perc)
+{
+       static char message[100];
+       const char *m = message;
+
+       strncpy(message, status_message, sizeof(message) - 1);
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), m);
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), perc / 100.0);
+       gtk_widget_queue_draw(ge->ui->window);
+}
+
+static void gfio_update_thread_status_all(struct gui *ui, char *status_message,
+                                         double perc)
+{
+       static char message[100];
+       const char *m = message;
+
+       strncpy(message, status_message, sizeof(message) - 1);
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), m);
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), perc / 100.0);
+       gtk_widget_queue_draw(ui->window);
+}
+
+/*
+ * Client specific ETA
+ */
+static void gfio_update_client_eta(struct fio_client *client, struct jobs_eta *je)
+{
+       struct gfio_client *gc = client->client_data;
+       struct gui_entry *ge = gc->ge;
+       static int eta_good;
+       char eta_str[128];
+       char output[256];
+       char tmp[32];
+       double perc = 0.0;
+       int i2p = 0;
+
+       gdk_threads_enter();
+
+       eta_str[0] = '\0';
+       output[0] = '\0';
+
+       if (je->eta_sec != INT_MAX && je->elapsed_sec) {
+               perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
+               eta_to_str(eta_str, je->eta_sec);
+       }
+
+       sprintf(tmp, "%u", je->nr_running);
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.jobs), tmp);
+       sprintf(tmp, "%u", je->files_open);
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.files), tmp);
+
+#if 0
+       if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
+       if (je->m_rate || je->t_rate) {
+               char *tr, *mr;
+
+               mr = num2str(je->m_rate, 4, 0, i2p);
+               tr = num2str(je->t_rate, 4, 0, i2p);
+               gtk_entry_set_text(GTK_ENTRY(ge->eta);
+               p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
+               free(tr);
+               free(mr);
+       } else if (je->m_iops || je->t_iops)
+               p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
+
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.cr_bw), "---");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.cr_iops), "---");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.cw_bw), "---");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.cw_iops), "---");
+#endif
+
+       if (je->eta_sec != INT_MAX && je->nr_running) {
+               char *iops_str[DDIR_RWDIR_CNT];
+               char *rate_str[DDIR_RWDIR_CNT];
+               int i;
+
+               if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
+                       strcpy(output, "-.-% done");
+               else {
+                       eta_good = 1;
+                       perc *= 100.0;
+                       sprintf(output, "%3.1f%% done", perc);
+               }
+
+               rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
+               rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
+               rate_str[2] = num2str(je->rate[2], 5, 10, i2p);
+
+               iops_str[0] = num2str(je->iops[0], 4, 1, 0);
+               iops_str[1] = num2str(je->iops[1], 4, 1, 0);
+               iops_str[2] = num2str(je->iops[2], 4, 1, 0);
+
+               gtk_entry_set_text(GTK_ENTRY(ge->eta.read_bw), rate_str[0]);
+               gtk_entry_set_text(GTK_ENTRY(ge->eta.read_iops), iops_str[0]);
+               gtk_entry_set_text(GTK_ENTRY(ge->eta.write_bw), rate_str[1]);
+               gtk_entry_set_text(GTK_ENTRY(ge->eta.write_iops), iops_str[1]);
+               gtk_entry_set_text(GTK_ENTRY(ge->eta.trim_bw), rate_str[2]);
+               gtk_entry_set_text(GTK_ENTRY(ge->eta.trim_iops), iops_str[2]);
+
+               graph_add_xy_data(ge->graphs.iops_graph, ge->graphs.read_iops, je->elapsed_sec, je->iops[0], iops_str[0]);
+               graph_add_xy_data(ge->graphs.iops_graph, ge->graphs.write_iops, je->elapsed_sec, je->iops[1], iops_str[1]);
+               graph_add_xy_data(ge->graphs.iops_graph, ge->graphs.trim_iops, je->elapsed_sec, je->iops[2], iops_str[2]);
+               graph_add_xy_data(ge->graphs.bandwidth_graph, ge->graphs.read_bw, je->elapsed_sec, je->rate[0], rate_str[0]);
+               graph_add_xy_data(ge->graphs.bandwidth_graph, ge->graphs.write_bw, je->elapsed_sec, je->rate[1], rate_str[1]);
+               graph_add_xy_data(ge->graphs.bandwidth_graph, ge->graphs.trim_bw, je->elapsed_sec, je->rate[2], rate_str[2]);
+
+               for (i = 0; i < DDIR_RWDIR_CNT; i++) {
+                       free(rate_str[i]);
+                       free(iops_str[i]);
+               }
+       }
+
+       if (eta_str[0]) {
+               char *dst = output + strlen(output);
+
+               sprintf(dst, " - %s", eta_str);
+       }
+
+       gfio_update_thread_status(ge, output, perc);
+       gdk_threads_leave();
+}
+
+/*
+ * Update ETA in main window for all clients
+ */
+static void gfio_update_all_eta(struct jobs_eta *je)
+{
+       struct gui *ui = &main_ui;
+       static int eta_good;
+       char eta_str[128];
+       char output[256];
+       double perc = 0.0;
+       int i, i2p = 0;
+
+       gdk_threads_enter();
+
+       eta_str[0] = '\0';
+       output[0] = '\0';
+
+       if (je->eta_sec != INT_MAX && je->elapsed_sec) {
+               perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
+               eta_to_str(eta_str, je->eta_sec);
+       }
+
+#if 0
+       if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
+       if (je->m_rate || je->t_rate) {
+               char *tr, *mr;
+
+               mr = num2str(je->m_rate, 4, 0, i2p);
+               tr = num2str(je->t_rate, 4, 0, i2p);
+               gtk_entry_set_text(GTK_ENTRY(ui->eta);
+               p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
+               free(tr);
+               free(mr);
+       } else if (je->m_iops || je->t_iops)
+               p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
+
+       gtk_entry_set_text(GTK_ENTRY(ui->eta.cr_bw), "---");
+       gtk_entry_set_text(GTK_ENTRY(ui->eta.cr_iops), "---");
+       gtk_entry_set_text(GTK_ENTRY(ui->eta.cw_bw), "---");
+       gtk_entry_set_text(GTK_ENTRY(ui->eta.cw_iops), "---");
+#endif
+
+       entry_set_int_value(ui->eta.jobs, je->nr_running);
+
+       if (je->eta_sec != INT_MAX && je->nr_running) {
+               char *iops_str[3];
+               char *rate_str[3];
+
+               if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
+                       strcpy(output, "-.-% done");
+               else {
+                       eta_good = 1;
+                       perc *= 100.0;
+                       sprintf(output, "%3.1f%% done", perc);
+               }
+
+               rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
+               rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
+               rate_str[2] = num2str(je->rate[2], 5, 10, i2p);
+
+               iops_str[0] = num2str(je->iops[0], 4, 1, 0);
+               iops_str[1] = num2str(je->iops[1], 4, 1, 0);
+               iops_str[2] = num2str(je->iops[2], 4, 1, 0);
+
+               gtk_entry_set_text(GTK_ENTRY(ui->eta.read_bw), rate_str[0]);
+               gtk_entry_set_text(GTK_ENTRY(ui->eta.read_iops), iops_str[0]);
+               gtk_entry_set_text(GTK_ENTRY(ui->eta.write_bw), rate_str[1]);
+               gtk_entry_set_text(GTK_ENTRY(ui->eta.write_iops), iops_str[1]);
+               gtk_entry_set_text(GTK_ENTRY(ui->eta.trim_bw), rate_str[2]);
+               gtk_entry_set_text(GTK_ENTRY(ui->eta.trim_iops), iops_str[2]);
+
+               graph_add_xy_data(ui->graphs.iops_graph, ui->graphs.read_iops, je->elapsed_sec, je->iops[0], iops_str[0]);
+               graph_add_xy_data(ui->graphs.iops_graph, ui->graphs.write_iops, je->elapsed_sec, je->iops[1], iops_str[1]);
+               graph_add_xy_data(ui->graphs.iops_graph, ui->graphs.trim_iops, je->elapsed_sec, je->iops[2], iops_str[2]);
+               graph_add_xy_data(ui->graphs.bandwidth_graph, ui->graphs.read_bw, je->elapsed_sec, je->rate[0], rate_str[0]);
+               graph_add_xy_data(ui->graphs.bandwidth_graph, ui->graphs.write_bw, je->elapsed_sec, je->rate[1], rate_str[1]);
+               graph_add_xy_data(ui->graphs.bandwidth_graph, ui->graphs.trim_bw, je->elapsed_sec, je->rate[2], rate_str[2]);
+
+               for (i = 0; i < DDIR_RWDIR_CNT; i++) {
+                       free(rate_str[i]);
+                       free(iops_str[i]);
+               }
+       }
+
+       if (eta_str[0]) {
+               char *dst = output + strlen(output);
+
+               sprintf(dst, " - %s", eta_str);
+       }
+
+       gfio_update_thread_status_all(ui, output, perc);
+       gdk_threads_leave();
+}
+
+static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
+       struct gfio_client *gc = client->client_data;
+       struct gui_entry *ge = gc->ge;
+       const char *os, *arch;
+
+       os = fio_get_os_string(probe->os);
+       if (!os)
+               os = "unknown";
+
+       arch = fio_get_arch_string(probe->arch);
+       if (!arch)
+               os = "unknown";
+
+       if (!client->name)
+               client->name = strdup((char *) probe->hostname);
+
+       gc->client_cpus = le32_to_cpu(probe->cpus);
+       gc->client_flags = le64_to_cpu(probe->flags);
+
+       gdk_threads_enter();
+
+       gtk_label_set_text(GTK_LABEL(ge->probe.hostname), (char *) probe->hostname);
+       gtk_label_set_text(GTK_LABEL(ge->probe.os), os);
+       gtk_label_set_text(GTK_LABEL(ge->probe.arch), arch);
+       gtk_label_set_text(GTK_LABEL(ge->probe.fio_ver), (char *) probe->fio_version);
+
+       gfio_set_state(ge, GE_STATE_CONNECTED);
+
+       gdk_threads_leave();
+}
+
+static void gfio_quit_op(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct gfio_client *gc = client->client_data;
+
+       gdk_threads_enter();
+       gfio_set_state(gc->ge, GE_STATE_NEW);
+       gdk_threads_leave();
+}
+
+static struct thread_options *gfio_client_add_job(struct gfio_client *gc,
+                       struct thread_options_pack *top)
+{
+       struct gfio_client_options *gco;
+
+       gco = calloc(1, sizeof(*gco));
+       convert_thread_options_to_cpu(&gco->o, top);
+       INIT_FLIST_HEAD(&gco->list);
+       flist_add_tail(&gco->list, &gc->o_list);
+       gc->o_list_nr = 1;
+       return &gco->o;
+}
+
+static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload;
+       struct gfio_client *gc = client->client_data;
+       struct gui_entry *ge = gc->ge;
+       struct thread_options *o;
+       char *c1, *c2, *c3, *c4;
+       char tmp[80];
+
+       p->thread_number = le32_to_cpu(p->thread_number);
+       p->groupid = le32_to_cpu(p->groupid);
+       o = gfio_client_add_job(gc, &p->top);
+
+       gdk_threads_enter();
+
+       gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ge->eta.names), (gchar *) o->name);
+       gtk_combo_box_set_active(GTK_COMBO_BOX(ge->eta.names), 0);
+
+       sprintf(tmp, "%s %s", o->odirect ? "direct" : "buffered", ddir_str(o->td_ddir));
+       multitext_add_entry(&ge->eta.iotype, tmp);
+
+       c1 = fio_uint_to_kmg(o->min_bs[DDIR_READ]);
+       c2 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]);
+       c3 = fio_uint_to_kmg(o->min_bs[DDIR_READ]);
+       c4 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]);
+       sprintf(tmp, "%s-%s/%s-%s", c1, c2, c3, c4);
+       free(c1);
+       free(c2);
+       free(c3);
+       free(c4);
+       multitext_add_entry(&ge->eta.bs, tmp);
+
+       multitext_add_entry(&ge->eta.ioengine, (const char *) o->ioengine);
+
+       sprintf(tmp, "%u", o->iodepth);
+       multitext_add_entry(&ge->eta.iodepth, tmp);
+
+       multitext_set_entry(&ge->eta.iotype, 0);
+       multitext_set_entry(&ge->eta.bs, 0);
+       multitext_set_entry(&ge->eta.ioengine, 0);
+       multitext_set_entry(&ge->eta.iodepth, 0);
+
+       gfio_set_state(ge, GE_STATE_JOB_SENT);
+
+       gdk_threads_leave();
+}
+
+static void gfio_update_job_op(struct fio_client *client,
+                              struct fio_net_cmd *cmd)
+{
+       uint32_t *pdu_error = (uint32_t *) cmd->payload;
+       struct gfio_client *gc = client->client_data;
+
+       gc->update_job_status = le32_to_cpu(*pdu_error);
+       gc->update_job_done = 1;
+}
+
+static void gfio_client_timed_out(struct fio_client *client)
+{
+       struct gfio_client *gc = client->client_data;
+       char buf[256];
+
+       gdk_threads_enter();
+
+       gfio_set_state(gc->ge, GE_STATE_NEW);
+       clear_ge_ui_info(gc->ge);
+
+       sprintf(buf, "Client %s: timeout talking to server.\n", client->hostname);
+       gfio_report_info(gc->ge->ui, "Network timeout", buf);
+
+       gdk_threads_leave();
+}
+
+static void gfio_client_stop(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct gfio_client *gc = client->client_data;
+
+       gdk_threads_enter();
+
+       gfio_set_state(gc->ge, GE_STATE_JOB_DONE);
+
+       if (gc->err_entry)
+               entry_set_int_value(gc->err_entry, client->error);
+
+       gdk_threads_leave();
+}
+
+static void gfio_client_start(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct gfio_client *gc = client->client_data;
+
+       gdk_threads_enter();
+       gfio_set_state(gc->ge, GE_STATE_JOB_STARTED);
+       gdk_threads_leave();
+}
+
+static void gfio_client_job_start(struct fio_client *client, struct fio_net_cmd *cmd)
+{
+       struct gfio_client *gc = client->client_data;
+
+       gdk_threads_enter();
+       gfio_set_state(gc->ge, GE_STATE_JOB_RUNNING);
+       gdk_threads_leave();
+}
+
+static void gfio_client_iolog(struct fio_client *client, struct cmd_iolog_pdu *pdu)
+{
+       printf("got iolog: name=%s, type=%u, entries=%u\n", pdu->name, pdu->log_type, pdu->nr_samples);
+       free(pdu);
+}
+
+static void gfio_add_total_depths_tree(GtkListStore *model,
+                                      struct thread_stat *ts, unsigned int len)
+{
+       double io_u_dist[FIO_IO_U_MAP_NR];
+       GtkTreeIter iter;
+       /* Bits 1-6, and 8 */
+       const int add_mask = 0x17e;
+       int i, j;
+
+       stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
+
+       gtk_list_store_append(model, &iter);
+
+       gtk_list_store_set(model, &iter, 0, "Total", -1);
+
+       for (i = 1, j = 0; i < len; i++) {
+               char fbuf[32];
+
+               if (!(add_mask & (1UL << (i - 1))))
+                       sprintf(fbuf, "0.0%%");
+               else {
+                       sprintf(fbuf, "%3.1f%%", io_u_dist[j]);
+                       j++;
+               }
+
+               gtk_list_store_set(model, &iter, i, fbuf, -1);
+       }
+
+}
+
+static void gfio_add_end_results(struct gfio_client *gc, struct thread_stat *ts,
+                                struct group_run_stats *rs)
+{
+       unsigned int nr = gc->nr_results;
+
+       gc->results = realloc(gc->results, (nr + 1) * sizeof(struct end_results));
+       memcpy(&gc->results[nr].ts, ts, sizeof(*ts));
+       memcpy(&gc->results[nr].gs, rs, sizeof(*rs));
+       gc->nr_results++;
+}
+
+static void gfio_add_sc_depths_tree(GtkListStore *model,
+                                   struct thread_stat *ts, unsigned int len,
+                                   int submit)
+{
+       double io_u_dist[FIO_IO_U_MAP_NR];
+       GtkTreeIter iter;
+       /* Bits 0, and 3-8 */
+       const int add_mask = 0x1f9;
+       int i, j;
+
+       if (submit)
+               stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
+       else
+               stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
+
+       gtk_list_store_append(model, &iter);
+
+       gtk_list_store_set(model, &iter, 0, submit ? "Submit" : "Complete", -1);
+
+       for (i = 1, j = 0; i < len; i++) {
+               char fbuf[32];
+
+               if (!(add_mask & (1UL << (i - 1))))
+                       sprintf(fbuf, "0.0%%");
+               else {
+                       sprintf(fbuf, "%3.1f%%", io_u_dist[j]);
+                       j++;
+               }
+
+               gtk_list_store_set(model, &iter, i, fbuf, -1);
+       }
+
+}
+
+static void gfio_show_io_depths(GtkWidget *vbox, struct thread_stat *ts)
+{
+       GtkWidget *frame, *box, *tree_view = NULL;
+       GtkTreeSelection *selection;
+       GtkListStore *model;
+       int i;
+       const char *labels[] = { "Depth", "0", "1", "2", "4", "8", "16", "32", "64", ">= 64" };
+       const int nr_labels = ARRAY_SIZE(labels);
+       GType types[nr_labels];
+
+       frame = gtk_frame_new("IO depths");
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+
+       box = gtk_hbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), box);
+
+       for (i = 0; i < nr_labels; i++)
+               types[i] = G_TYPE_STRING;
+
+       model = gtk_list_store_newv(nr_labels, types);
+
+       tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+       gtk_widget_set_can_focus(tree_view, FALSE);
+
+       g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
+               "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH, NULL);
+
+       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
+       gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
+
+       for (i = 0; i < nr_labels; i++)
+               tree_view_column(tree_view, i, labels[i], ALIGN_RIGHT | UNSORTABLE);
+
+       gfio_add_total_depths_tree(model, ts, nr_labels);
+       gfio_add_sc_depths_tree(model, ts, nr_labels, 1);
+       gfio_add_sc_depths_tree(model, ts, nr_labels, 0);
+
+       gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, TRUE, 3);
+}
+
+static void gfio_show_cpu_usage(GtkWidget *vbox, struct thread_stat *ts)
+{
+       GtkWidget *box, *frame, *entry;
+       double usr_cpu, sys_cpu;
+       unsigned long runtime;
+       char tmp[32];
+
+       runtime = ts->total_run_time;
+       if (runtime) {
+               double runt = (double) runtime;
+
+               usr_cpu = (double) ts->usr_time * 100 / runt;
+               sys_cpu = (double) ts->sys_time * 100 / runt;
+       } else {
+               usr_cpu = 0;
+               sys_cpu = 0;
+       }
+
+       frame = gtk_frame_new("OS resources");
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+
+       box = gtk_hbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), box);
+
+       entry = new_info_entry_in_frame(box, "User CPU");
+       sprintf(tmp, "%3.2f%%", usr_cpu);
+       gtk_entry_set_text(GTK_ENTRY(entry), tmp);
+       entry = new_info_entry_in_frame(box, "System CPU");
+       sprintf(tmp, "%3.2f%%", sys_cpu);
+       gtk_entry_set_text(GTK_ENTRY(entry), tmp);
+       entry = new_info_entry_in_frame(box, "Context switches");
+       entry_set_int_value(entry, ts->ctx);
+       entry = new_info_entry_in_frame(box, "Major faults");
+       entry_set_int_value(entry, ts->majf);
+       entry = new_info_entry_in_frame(box, "Minor faults");
+       entry_set_int_value(entry, ts->minf);
+}
+
+static GtkWidget *gfio_output_lat_buckets(double *lat, const char **labels,
+                                         int num)
+{
+       GtkWidget *tree_view;
+       GtkTreeSelection *selection;
+       GtkListStore *model;
+       GtkTreeIter iter;
+       GType *types;
+       int i;
+
+       types = malloc(num * sizeof(GType));
+
+       for (i = 0; i < num; i++)
+               types[i] = G_TYPE_STRING;
+
+       model = gtk_list_store_newv(num, types);
+       free(types);
+       types = NULL;
+
+       tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+       gtk_widget_set_can_focus(tree_view, FALSE);
+
+       g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
+               "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH, NULL);
+
+       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
+       gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
+
+       for (i = 0; i < num; i++)
+               tree_view_column(tree_view, i, labels[i], ALIGN_RIGHT | UNSORTABLE);
+
+       gtk_list_store_append(model, &iter);
+
+       for (i = 0; i < num; i++) {
+               char fbuf[32];
+
+               if (lat[i] <= 0.0)
+                       sprintf(fbuf, "0.00");
+               else
+                       sprintf(fbuf, "%3.2f%%", lat[i]);
+
+               gtk_list_store_set(model, &iter, i, fbuf, -1);
+       }
+
+       return tree_view;
+}
+
+static struct graph *setup_lat_bucket_graph(const char *title, double *lat,
+                                           const char **labels,
+                                           unsigned int len,
+                                           double xdim, double ydim)
+{
+       struct graph *g;
+       int i;
+
+       g = graph_new(xdim, ydim, gfio_graph_font);
+       graph_title(g, title);
+       graph_x_title(g, "Buckets");
+       graph_y_title(g, "Percent");
+
+       for (i = 0; i < len; i++) {
+               graph_label_t l;
+
+               l = graph_add_label(g, labels[i]);
+               graph_add_data(g, l, lat[i]);
+       }
+
+       return g;
+}
+
+static int on_expose_lat_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p)
+{
+       struct graph *g = p;
+       cairo_t *cr;
+
+       cr = gdk_cairo_create(gtk_widget_get_window(w));
+#if 0
+       if (graph_has_tooltips(g)) {
+               g_object_set(w, "has-tooltip", TRUE, NULL);
+               g_signal_connect(w, "query-tooltip", G_CALLBACK(clat_graph_tooltip), g);
+       }
+#endif
+       cairo_set_source_rgb(cr, 0, 0, 0);
+       bar_graph_draw(g, cr);
+       cairo_destroy(cr);
+
+       return FALSE;
+}
+
+static gint on_config_lat_drawing_area(GtkWidget *w, GdkEventConfigure *event,
+                                      gpointer data)
+{
+       guint width = gtk_widget_get_allocated_width(w);
+       guint height = gtk_widget_get_allocated_height(w);
+       struct graph *g = data;
+
+       graph_set_size(g, width, height);
+       graph_set_size(g, width, height);
+       graph_set_position(g, 0, 0);
+       return TRUE;
+}
+
+static void gfio_show_latency_buckets(struct gfio_client *gc, GtkWidget *vbox,
+                                     struct thread_stat *ts)
+{
+       double io_u_lat[FIO_IO_U_LAT_U_NR + FIO_IO_U_LAT_M_NR];
+       const char *ranges[] = { "2u", "4u", "10u", "20u", "50u", "100u",
+                                "250u", "500u", "750u", "1m", "2m",
+                                "4m", "10m", "20m", "50m", "100m",
+                                "250m", "500m", "750m", "1s", "2s", ">= 2s" };
+       int start, end, i;
+       const int total = FIO_IO_U_LAT_U_NR + FIO_IO_U_LAT_M_NR;
+       GtkWidget *frame, *tree_view, *hbox, *completion_vbox, *drawing_area;
+       struct gui_entry *ge = gc->ge;
+
+       stat_calc_lat_u(ts, io_u_lat);
+       stat_calc_lat_m(ts, &io_u_lat[FIO_IO_U_LAT_U_NR]);
+
+       /*
+        * Found out which first bucket has entries, and which last bucket
+        */
+       start = end = -1U;
+       for (i = 0; i < total; i++) {
+               if (io_u_lat[i] == 0.00)
+                       continue;
+
+               if (start == -1U)
+                       start = i;
+               end = i;
+       }
+
+       /*
+        * No entries...
+        */
+       if (start == -1U)
+               return;
+
+       tree_view = gfio_output_lat_buckets(&io_u_lat[start], &ranges[start], end - start + 1);
+       ge->lat_bucket_graph = setup_lat_bucket_graph("Latency Buckets", &io_u_lat[start], &ranges[start], end - start + 1, 700.0, 300.0);
+
+       frame = gtk_frame_new("Latency buckets");
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+
+       completion_vbox = gtk_vbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), completion_vbox);
+       hbox = gtk_hbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(completion_vbox), hbox);
+
+       drawing_area = gtk_drawing_area_new();
+       gtk_widget_set_size_request(GTK_WIDGET(drawing_area), 700, 300);
+       gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &gfio_color_white);
+       gtk_container_add(GTK_CONTAINER(completion_vbox), drawing_area);
+       g_signal_connect(G_OBJECT(drawing_area), GFIO_DRAW_EVENT, G_CALLBACK(on_expose_lat_drawing_area), ge->lat_bucket_graph);
+       g_signal_connect(G_OBJECT(drawing_area), "configure_event", G_CALLBACK(on_config_lat_drawing_area), ge->lat_bucket_graph);
+
+       gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, TRUE, 3);
+}
+
+static void gfio_show_lat(GtkWidget *vbox, const char *name, unsigned long min,
+                         unsigned long max, double mean, double dev)
+{
+       const char *base = "(usec)";
+       GtkWidget *hbox, *label, *frame;
+       char *minp, *maxp;
+       char tmp[64];
+
+       if (!usec_to_msec(&min, &max, &mean, &dev))
+               base = "(msec)";
+
+       minp = num2str(min, 6, 1, 0);
+       maxp = num2str(max, 6, 1, 0);
+
+       sprintf(tmp, "%s %s", name, base);
+       frame = gtk_frame_new(tmp);
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+
+       hbox = gtk_hbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), hbox);
+
+       label = new_info_label_in_frame(hbox, "Minimum");
+       gtk_label_set_text(GTK_LABEL(label), minp);
+       label = new_info_label_in_frame(hbox, "Maximum");
+       gtk_label_set_text(GTK_LABEL(label), maxp);
+       label = new_info_label_in_frame(hbox, "Average");
+       sprintf(tmp, "%5.02f", mean);
+       gtk_label_set_text(GTK_LABEL(label), tmp);
+       label = new_info_label_in_frame(hbox, "Standard deviation");
+       sprintf(tmp, "%5.02f", dev);
+       gtk_label_set_text(GTK_LABEL(label), tmp);
+
+       free(minp);
+       free(maxp);
+}
+
+static GtkWidget *gfio_output_clat_percentiles(unsigned int *ovals,
+                                              fio_fp64_t *plist,
+                                              unsigned int len,
+                                              const char *base,
+                                              unsigned int scale)
+{
+       GType types[FIO_IO_U_LIST_MAX_LEN];
+       GtkWidget *tree_view;
+       GtkTreeSelection *selection;
+       GtkListStore *model;
+       GtkTreeIter iter;
+       int i;
+
+       for (i = 0; i < len; i++)
+               types[i] = G_TYPE_INT;
+
+       model = gtk_list_store_newv(len, types);
+
+       tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+       gtk_widget_set_can_focus(tree_view, FALSE);
+
+       g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
+               "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH, NULL);
+
+       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
+       gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
+
+       for (i = 0; i < len; i++) {
+               char fbuf[8];
+
+               sprintf(fbuf, "%2.2f%%", plist[i].u.f);
+               tree_view_column(tree_view, i, fbuf, ALIGN_RIGHT | UNSORTABLE);
+       }
+
+       gtk_list_store_append(model, &iter);
+
+       for (i = 0; i < len; i++) {
+               if (scale)
+                       ovals[i] = (ovals[i] + 999) / 1000;
+               gtk_list_store_set(model, &iter, i, ovals[i], -1);
+       }
+
+       return tree_view;
+}
+
+static struct graph *setup_clat_graph(char *title, unsigned int *ovals,
+                                     fio_fp64_t *plist,
+                                     unsigned int len,
+                                     double xdim, double ydim)
+{
+       struct graph *g;
+       int i;
+
+       g = graph_new(xdim, ydim, gfio_graph_font);
+       graph_title(g, title);
+       graph_x_title(g, "Percentile");
+       graph_y_title(g, "Time");
+
+       for (i = 0; i < len; i++) {
+               graph_label_t l;
+               char fbuf[8];
+
+               sprintf(fbuf, "%2.2f%%", plist[i].u.f);
+               l = graph_add_label(g, fbuf);
+               graph_add_data(g, l, (double) ovals[i]);
+       }
+
+       return g;
+}
+
+static void gfio_show_clat_percentiles(struct gfio_client *gc,
+                                      GtkWidget *vbox, struct thread_stat *ts,
+                                      int ddir)
+{
+       unsigned int *io_u_plat = ts->io_u_plat[ddir];
+       unsigned long nr = ts->clat_stat[ddir].samples;
+       fio_fp64_t *plist = ts->percentile_list;
+       unsigned int *ovals, len, minv, maxv, scale_down;
+       const char *base;
+       GtkWidget *tree_view, *frame, *hbox, *drawing_area, *completion_vbox;
+       struct gui_entry *ge = gc->ge;
+       char tmp[64];
+
+       len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
+       if (!len)
+               goto out;
+
+       /*
+        * We default to usecs, but if the value range is such that we
+        * should scale down to msecs, do that.
+        */
+       if (minv > 2000 && maxv > 99999) {
+               scale_down = 1;
+               base = "msec";
+       } else {
+               scale_down = 0;
+               base = "usec";
+       }
+
+       sprintf(tmp, "Completion percentiles (%s)", base);
+       tree_view = gfio_output_clat_percentiles(ovals, plist, len, base, scale_down);
+       ge->clat_graph = setup_clat_graph(tmp, ovals, plist, len, 700.0, 300.0);
+
+       frame = gtk_frame_new(tmp);
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+
+       completion_vbox = gtk_vbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), completion_vbox);
+       hbox = gtk_hbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(completion_vbox), hbox);
+       drawing_area = gtk_drawing_area_new();
+       gtk_widget_set_size_request(GTK_WIDGET(drawing_area), 700, 300);
+       gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &gfio_color_white);
+       gtk_container_add(GTK_CONTAINER(completion_vbox), drawing_area);
+       g_signal_connect(G_OBJECT(drawing_area), GFIO_DRAW_EVENT, G_CALLBACK(on_expose_lat_drawing_area), ge->clat_graph);
+       g_signal_connect(G_OBJECT(drawing_area), "configure_event", G_CALLBACK(on_config_lat_drawing_area), ge->clat_graph);
+
+       gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, TRUE, 3);
+out:
+       if (ovals)
+               free(ovals);
+}
+
+#define GFIO_CLAT      1
+#define GFIO_SLAT      2
+#define GFIO_LAT       4
+
+static void gfio_show_ddir_status(struct gfio_client *gc, GtkWidget *mbox,
+                                 struct group_run_stats *rs,
+                                 struct thread_stat *ts, int ddir)
+{
+       const char *ddir_label[3] = { "Read", "Write", "Trim" };
+       GtkWidget *frame, *label, *box, *vbox, *main_vbox;
+       unsigned long min[3], max[3], runt;
+       unsigned long long bw, iops;
+       unsigned int flags = 0;
+       double mean[3], dev[3];
+       char *io_p, *bw_p, *iops_p;
+       int i2p;
+
+       if (!ts->runtime[ddir])
+               return;
+
+       i2p = is_power_of_2(rs->kb_base);
+       runt = ts->runtime[ddir];
+
+       bw = (1000 * ts->io_bytes[ddir]) / runt;
+       io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
+       bw_p = num2str(bw, 6, 1, i2p);
+
+       iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
+       iops_p = num2str(iops, 6, 1, 0);
+
+       box = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(mbox), box, TRUE, FALSE, 3);
+
+       frame = gtk_frame_new(ddir_label[ddir]);
+       gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 5);
+
+       main_vbox = gtk_vbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), main_vbox);
+
+       box = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(main_vbox), box, TRUE, FALSE, 3);
+
+       label = new_info_label_in_frame(box, "IO");
+       gtk_label_set_text(GTK_LABEL(label), io_p);
+       label = new_info_label_in_frame(box, "Bandwidth");
+       gtk_label_set_text(GTK_LABEL(label), bw_p);
+       label = new_info_label_in_frame(box, "IOPS");
+       gtk_label_set_text(GTK_LABEL(label), iops_p);
+       label = new_info_label_in_frame(box, "Runtime (msec)");
+       label_set_int_value(label, ts->runtime[ddir]);
+
+       if (calc_lat(&ts->bw_stat[ddir], &min[0], &max[0], &mean[0], &dev[0])) {
+               double p_of_agg = 100.0;
+               const char *bw_str = "KB";
+               char tmp[32];
+
+               if (rs->agg[ddir]) {
+                       p_of_agg = mean[0] * 100 / (double) rs->agg[ddir];
+                       if (p_of_agg > 100.0)
+                               p_of_agg = 100.0;
+               }
+
+               if (mean[0] > 999999.9) {
+                       min[0] /= 1000.0;
+                       max[0] /= 1000.0;
+                       mean[0] /= 1000.0;
+                       dev[0] /= 1000.0;
+                       bw_str = "MB";
+               }
+
+               sprintf(tmp, "Bandwidth (%s)", bw_str);
+               frame = gtk_frame_new(tmp);
+               gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 5);
+
+               box = gtk_hbox_new(FALSE, 3);
+               gtk_container_add(GTK_CONTAINER(frame), box);
+
+               label = new_info_label_in_frame(box, "Minimum");
+               label_set_int_value(label, min[0]);
+               label = new_info_label_in_frame(box, "Maximum");
+               label_set_int_value(label, max[0]);
+               label = new_info_label_in_frame(box, "Percentage of jobs");
+               sprintf(tmp, "%3.2f%%", p_of_agg);
+               gtk_label_set_text(GTK_LABEL(label), tmp);
+               label = new_info_label_in_frame(box, "Average");
+               sprintf(tmp, "%5.02f", mean[0]);
+               gtk_label_set_text(GTK_LABEL(label), tmp);
+               label = new_info_label_in_frame(box, "Standard deviation");
+               sprintf(tmp, "%5.02f", dev[0]);
+               gtk_label_set_text(GTK_LABEL(label), tmp);
+       }
+
+       if (calc_lat(&ts->slat_stat[ddir], &min[0], &max[0], &mean[0], &dev[0]))
+               flags |= GFIO_SLAT;
+       if (calc_lat(&ts->clat_stat[ddir], &min[1], &max[1], &mean[1], &dev[1]))
+               flags |= GFIO_CLAT;
+       if (calc_lat(&ts->lat_stat[ddir], &min[2], &max[2], &mean[2], &dev[2]))
+               flags |= GFIO_LAT;
+
+       if (flags) {
+               frame = gtk_frame_new("Latency");
+               gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 5);
+
+               vbox = gtk_vbox_new(FALSE, 3);
+               gtk_container_add(GTK_CONTAINER(frame), vbox);
+
+               if (flags & GFIO_SLAT)
+                       gfio_show_lat(vbox, "Submission latency", min[0], max[0], mean[0], dev[0]);
+               if (flags & GFIO_CLAT)
+                       gfio_show_lat(vbox, "Completion latency", min[1], max[1], mean[1], dev[1]);
+               if (flags & GFIO_LAT)
+                       gfio_show_lat(vbox, "Total latency", min[2], max[2], mean[2], dev[2]);
+       }
+
+       if (ts->clat_percentiles)
+               gfio_show_clat_percentiles(gc, main_vbox, ts, ddir);
+
+       free(io_p);
+       free(bw_p);
+       free(iops_p);
+}
+
+static void __gfio_display_end_results(GtkWidget *win, struct gfio_client *gc,
+                                      struct thread_stat *ts,
+                                      struct group_run_stats *rs)
+{
+       GtkWidget *box, *vbox, *entry, *scroll;
+       int i;
+
+       scroll = gtk_scrolled_window_new(NULL, NULL);
+       gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+       vbox = gtk_vbox_new(FALSE, 3);
+
+       box = gtk_hbox_new(FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(vbox), box, TRUE, FALSE, 5);
+
+       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
+
+       gtk_notebook_append_page(GTK_NOTEBOOK(win), scroll, gtk_label_new(ts->name));
+
+       entry = new_info_entry_in_frame(box, "Name");
+       gtk_entry_set_text(GTK_ENTRY(entry), ts->name);
+       if (strlen(ts->description)) {
+               entry = new_info_entry_in_frame(box, "Description");
+               gtk_entry_set_text(GTK_ENTRY(entry), ts->description);
+       }
+       entry = new_info_entry_in_frame(box, "Group ID");
+       entry_set_int_value(entry, ts->groupid);
+       entry = new_info_entry_in_frame(box, "Jobs");
+       entry_set_int_value(entry, ts->members);
+       gc->err_entry = entry = new_info_entry_in_frame(box, "Error");
+       entry_set_int_value(entry, ts->error);
+       entry = new_info_entry_in_frame(box, "PID");
+       entry_set_int_value(entry, ts->pid);
+
+       for (i = 0; i < DDIR_RWDIR_CNT; i++) {
+               if (ts->io_bytes[i])
+                       gfio_show_ddir_status(gc, vbox, rs, ts, i);
+       }
+
+       gfio_show_latency_buckets(gc, vbox, ts);
+       gfio_show_cpu_usage(vbox, ts);
+       gfio_show_io_depths(vbox, ts);
+}
+
+void gfio_display_end_results(struct gfio_client *gc)
+{
+       struct gui_entry *ge = gc->ge;
+       GtkWidget *res_notebook;
+       int i;
+
+       res_notebook = get_results_window(ge);
+
+       for (i = 0; i < gc->nr_results; i++) {
+               struct end_results *e = &gc->results[i];
+
+               __gfio_display_end_results(res_notebook, gc, &e->ts, &e->gs);
+       }
+
+       if (gfio_disk_util_show(gc))
+               gtk_widget_show_all(ge->results_window);
+}
+
+static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts,
+                           struct group_run_stats *rs)
+{
+       struct gfio_client *gc = client->client_data;
+       struct gui_entry *ge = gc->ge;
+
+       gfio_add_end_results(gc, ts, rs);
+
+       gdk_threads_enter();
+       if (ge->results_window)
+               __gfio_display_end_results(ge->results_notebook, gc, ts, rs);
+       else
+               gfio_display_end_results(gc);
+       gdk_threads_leave();
+}
+
+static void gfio_client_removed(struct fio_client *client)
+{
+       struct gfio_client *gc = client->client_data;
+
+       assert(gc->client == client);
+       fio_put_client(gc->client);
+       gc->client = NULL;
+}
+
+struct client_ops gfio_client_ops = {
+       .text                   = gfio_text_op,
+       .disk_util              = gfio_disk_util_op,
+       .thread_status          = gfio_thread_status_op,
+       .group_stats            = gfio_group_stats_op,
+       .jobs_eta               = gfio_update_client_eta,
+       .eta                    = gfio_update_all_eta,
+       .probe                  = gfio_probe_op,
+       .quit                   = gfio_quit_op,
+       .add_job                = gfio_add_job_op,
+       .update_job             = gfio_update_job_op,
+       .timed_out              = gfio_client_timed_out,
+       .stop                   = gfio_client_stop,
+       .start                  = gfio_client_start,
+       .job_start              = gfio_client_job_start,
+       .iolog                  = gfio_client_iolog,
+       .removed                = gfio_client_removed,
+       .eta_msec               = FIO_CLIENT_DEF_ETA_MSEC,
+       .stay_connected         = 1,
+       .client_type            = FIO_CLIENT_TYPE_GUI,
+};
diff --git a/gclient.h b/gclient.h
new file mode 100644 (file)
index 0000000..4038365
--- /dev/null
+++ b/gclient.h
@@ -0,0 +1,18 @@
+#ifndef GFIO_CLIENT_H
+#define GFIO_CLIENT_H
+
+extern struct client_ops gfio_client_ops;
+
+extern void gfio_display_end_results(struct gfio_client *);
+
+#define GFIO_READ_R    0.13
+#define GFIO_READ_G    0.54
+#define GFIO_READ_B    0.13
+#define GFIO_WRITE_R   1.00
+#define GFIO_WRITE_G   0.00
+#define GFIO_WRITE_B   0.00
+#define GFIO_TRIM_R    0.24
+#define GFIO_TRIM_G    0.18
+#define GFIO_TRIM_B    0.52
+
+#endif
diff --git a/gcompat.c b/gcompat.c
new file mode 100644 (file)
index 0000000..5944df0
--- /dev/null
+++ b/gcompat.c
@@ -0,0 +1,59 @@
+#include <gtk/gtk.h>
+
+#include "gcompat.h"
+
+#if GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 24
+
+GtkWidget *gtk_combo_box_text_new(void)
+{
+       return gtk_combo_box_new();
+}
+
+void gtk_combo_box_text_append_text(GtkComboBoxText *combo_box,
+                                   const gchar *text)
+{
+       gtk_combo_box_append_text(GTK_COMBO_BOX(combo_box), text);
+}
+
+void gtk_combo_box_text_insert_text(GtkComboBoxText *combo_box, gint position,
+                                   const gchar *text)
+{
+       gtk_combo_box_insert_text(GTK_COMBO_BOX(combo_box), position, text);
+}
+
+void gtk_combo_box_text_prepend_text(GtkComboBoxText *combo_box,
+                                    const gchar *text)
+{
+       gtk_combo_box_prepend_text(GTK_COMBO_BOX(combo_box), text);
+}
+
+gchar *gtk_combo_box_text_get_active_text(GtkComboBoxText *combo_box)
+{
+       return gtk_combo_box_get_active_text(GTK_COMBO_BOX(combo_box));
+}
+
+#endif
+
+#if GTK_MAJOR_VERSION < 3
+
+guint gtk_widget_get_allocated_width(GtkWidget *w)
+{
+       return w->allocation.width;
+}
+
+guint gtk_widget_get_allocated_height(GtkWidget *w)
+{
+       return w->allocation.height;
+}
+
+#endif
+
+#if GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 18
+void gtk_widget_set_can_focus(GtkWidget *widget, gboolean can_focus)
+{
+       if (can_focus)
+               GTK_WIDGET_SET_FLAGS(widget, GTK_CAN_FOCUS);
+       else
+               GTK_WIDGET_UNSET_FLAGS(widget, GTK_CAN_FOCUS);
+}
+#endif
diff --git a/gcompat.h b/gcompat.h
new file mode 100644 (file)
index 0000000..e0f7444
--- /dev/null
+++ b/gcompat.h
@@ -0,0 +1,46 @@
+#ifndef GFIO_GTK_COMPAT
+#define GFIO_GTK_COMPAT
+
+#include <gtk/gtk.h>
+
+#if GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 24
+struct GtkComboBoxText;
+typedef GtkComboBox GtkComboBoxText;
+GtkWidget *gtk_combo_box_text_new(void);
+GtkWidget *gtk_combo_box_text_new_with_entry(void);
+void gtk_combo_box_text_append_text(GtkComboBoxText *combo_box, const gchar *text);
+void gtk_combo_box_text_insert_text(GtkComboBoxText *combo_box, gint position, const gchar *text);
+void gtk_combo_box_text_prepend_text(GtkComboBoxText *combo_box, const gchar *text);
+void gtk_combo_box_text_remove(GtkComboBoxText *combo_box, gint position);
+gchar *gtk_combo_box_text_get_active_text(GtkComboBoxText *combo_box);
+
+#define GTK_COMBO_BOX_TEXT     GTK_COMBO_BOX
+#endif /* GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 24 */
+
+#if GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 14
+static inline GtkWidget *gtk_dialog_get_content_area(GtkDialog *dialog)
+{
+       return dialog->vbox;
+}
+static inline GdkWindow *gtk_widget_get_window(GtkWidget *w)
+{
+       return w->window;
+}
+#endif
+
+#if GTK_MAJOR_VERSION < 3
+guint gtk_widget_get_allocated_width(GtkWidget *w);
+guint gtk_widget_get_allocated_height(GtkWidget *w);
+#endif
+
+#if GTK_MAJOR_VERSION == 3
+#define GFIO_DRAW_EVENT                "draw"
+#elif GTK_MAJOR_VERSION == 2
+#define GFIO_DRAW_EVENT                "expose_event"
+#endif
+
+#if GTK_MAJOR_VERSION <= 2 && GTK_MINOR_VERSION < 18
+void gtk_widget_set_can_focus(GtkWidget *widget, gboolean can_focus);
+#endif
+
+#endif
diff --git a/gerror.c b/gerror.c
new file mode 100644 (file)
index 0000000..3036738
--- /dev/null
+++ b/gerror.c
@@ -0,0 +1,74 @@
+#include <locale.h>
+#include <malloc.h>
+#include <string.h>
+#include <stdarg.h>
+
+#include <gtk/gtk.h>
+
+#include "gfio.h"
+#include "gerror.h"
+
+static void on_info_bar_response(GtkWidget *widget, gint response,
+                                gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+
+       if (response == GTK_RESPONSE_OK) {
+               gtk_widget_destroy(widget);
+               ui->error_info_bar = NULL;
+       }
+}
+
+static void report_error(struct gui_entry *ge, GError *error)
+{
+       struct gui *ui = ge->ui;
+
+       if (ui->error_info_bar == NULL) {
+               ui->error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK,
+                                               GTK_RESPONSE_OK, NULL);
+               g_signal_connect(ui->error_info_bar, "response", G_CALLBACK(on_info_bar_response), ui);
+               gtk_info_bar_set_message_type(GTK_INFO_BAR(ui->error_info_bar),
+                                               GTK_MESSAGE_ERROR);
+
+               ui->error_label = gtk_label_new(error->message);
+               GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui->error_info_bar));
+               gtk_container_add(GTK_CONTAINER(container), ui->error_label);
+
+               gtk_box_pack_start(GTK_BOX(ui->vbox), ui->error_info_bar, FALSE, FALSE, 0);
+               gtk_widget_show_all(ui->vbox);
+       } else {
+               char buffer[256];
+               snprintf(buffer, sizeof(buffer), "Failed to open file.");
+               gtk_label_set_text(GTK_LABEL(ui->error_label), buffer);
+       }
+}
+
+void gfio_report_error(struct gui_entry *ge, const char *format, ...)
+{
+       va_list args;
+       GError *error;
+
+       va_start(args, format);
+       error = g_error_new_valist(g_quark_from_string("fio"), 1, format, args);
+       va_end(args);
+
+       report_error(ge, error);
+       g_error_free(error);
+}
+
+void gfio_report_info(struct gui *ui, const char *title, const char *message)
+{
+       GtkWidget *dialog, *content, *label;
+
+       dialog = gtk_dialog_new_with_buttons(title, GTK_WINDOW(ui->window),
+                       GTK_DIALOG_MODAL | GTK_DIALOG_DESTROY_WITH_PARENT,
+                       GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
+
+       content = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+       label = gtk_label_new(message);
+       gtk_container_add(GTK_CONTAINER(content), label);
+       gtk_widget_show_all(dialog);
+       gtk_dialog_set_default_response(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT);
+       gtk_dialog_run(GTK_DIALOG(dialog));
+       gtk_widget_destroy(dialog);
+}
diff --git a/gerror.h b/gerror.h
new file mode 100644 (file)
index 0000000..3767f92
--- /dev/null
+++ b/gerror.h
@@ -0,0 +1,7 @@
+#ifndef GFIO_ERROR_H
+#define GFIO_ERROR_H
+
+extern void gfio_report_error(struct gui_entry *ge, const char *format, ...);
+extern void gfio_report_info(struct gui *ui, const char *title, const char *message);
+
+#endif
diff --git a/gfio.c b/gfio.c
new file mode 100644 (file)
index 0000000..65302e6
--- /dev/null
+++ b/gfio.c
@@ -0,0 +1,1751 @@
+/*
+ * gfio - gui front end for fio - the flexible io tester
+ *
+ * Copyright (C) 2012 Stephen M. Cameron <stephenmcameron@gmail.com>
+ * Copyright (C) 2012 Jens Axboe <axboe@kernel.dk>
+ *
+ * The license below covers all files distributed with fio unless otherwise
+ * noted in the file itself.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+ *
+ */
+#include <locale.h>
+#include <malloc.h>
+#include <string.h>
+
+#include <glib.h>
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+#include "fio.h"
+#include "gfio.h"
+#include "ghelpers.h"
+#include "goptions.h"
+#include "gerror.h"
+#include "gclient.h"
+#include "graph.h"
+
+static int gfio_server_running;
+static unsigned int gfio_graph_limit = 100;
+
+GdkColor gfio_color_white;
+GdkColor gfio_color_lightyellow;
+const char *gfio_graph_font = GRAPH_DEFAULT_FONT;
+
+typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
+
+static void connect_clicked(GtkWidget *widget, gpointer data);
+static void start_job_clicked(GtkWidget *widget, gpointer data);
+static void send_clicked(GtkWidget *widget, gpointer data);
+
+static struct button_spec {
+       const char *buttontext;
+       clickfunction f;
+       const char *tooltiptext[2];
+       const int start_sensitive;
+} buttonspeclist[] = {
+       {
+         .buttontext           = "Connect",
+         .f                    = connect_clicked,
+         .tooltiptext          = { "Disconnect from host", "Connect to host" },
+         .start_sensitive      = 1,
+       },
+       {
+         .buttontext           = "Send",
+         .f                    = send_clicked,
+         .tooltiptext          = { "Send job description to host", NULL },
+         .start_sensitive      = 0,
+       },
+       {
+         .buttontext           = "Start Job",
+         .f                    = start_job_clicked,
+         .tooltiptext          = { "Start the current job on the server", NULL },
+         .start_sensitive      = 0,
+       },
+};
+
+static void setup_iops_graph(struct gfio_graphs *gg)
+{
+       struct graph *g;
+
+       g = graph_new(DRAWING_AREA_XDIM / 2.0, DRAWING_AREA_YDIM, gfio_graph_font);
+       graph_title(g, "IOPS (IOs/sec)");
+       graph_x_title(g, "Time (secs)");
+       gg->read_iops = graph_add_label(g, "Read IOPS");
+       gg->write_iops = graph_add_label(g, "Write IOPS");
+       gg->trim_iops = graph_add_label(g, "Trim IOPS");
+       graph_set_color(g, gg->read_iops, GFIO_READ_R, GFIO_READ_G, GFIO_READ_B);
+       graph_set_color(g, gg->write_iops, GFIO_WRITE_R, GFIO_WRITE_G, GFIO_WRITE_B);
+       graph_set_color(g, gg->trim_iops, GFIO_TRIM_R, GFIO_TRIM_G, GFIO_TRIM_B);
+       line_graph_set_data_count_limit(g, gfio_graph_limit);
+       graph_add_extra_space(g, 0.0, 0.0, 0.0, 0.0);
+       graph_set_graph_all_zeroes(g, 0);
+       gg->iops_graph = g;
+}
+
+static void setup_bandwidth_graph(struct gfio_graphs *gg)
+{
+       struct graph *g;
+
+       g = graph_new(DRAWING_AREA_XDIM / 2.0, DRAWING_AREA_YDIM, gfio_graph_font);
+       graph_title(g, "Bandwidth (bytes/sec)");
+       graph_x_title(g, "Time (secs)");
+       gg->read_bw = graph_add_label(g, "Read Bandwidth");
+       gg->write_bw = graph_add_label(g, "Write Bandwidth");
+       gg->trim_bw = graph_add_label(g, "Trim Bandwidth");
+       graph_set_color(g, gg->read_bw, GFIO_READ_R, GFIO_READ_G, GFIO_READ_B);
+       graph_set_color(g, gg->write_bw, GFIO_WRITE_R, GFIO_WRITE_G, GFIO_WRITE_B);
+       graph_set_color(g, gg->trim_bw, GFIO_TRIM_R, GFIO_TRIM_G, GFIO_TRIM_B);
+       graph_set_base_offset(g, 1);
+       line_graph_set_data_count_limit(g, 100);
+       graph_add_extra_space(g, 0.0, 0.0, 0.0, 0.0);
+       graph_set_graph_all_zeroes(g, 0);
+       gg->bandwidth_graph = g;
+}
+
+static void setup_graphs(struct gfio_graphs *g)
+{
+       setup_iops_graph(g);
+       setup_bandwidth_graph(g);
+}
+
+void clear_ge_ui_info(struct gui_entry *ge)
+{
+       gtk_label_set_text(GTK_LABEL(ge->probe.hostname), "");
+       gtk_label_set_text(GTK_LABEL(ge->probe.os), "");
+       gtk_label_set_text(GTK_LABEL(ge->probe.arch), "");
+       gtk_label_set_text(GTK_LABEL(ge->probe.fio_ver), "");
+#if 0
+       /* should we empty it... */
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.name), "");
+#endif
+       multitext_update_entry(&ge->eta.iotype, 0, "");
+       multitext_update_entry(&ge->eta.bs, 0, "");
+       multitext_update_entry(&ge->eta.ioengine, 0, "");
+       multitext_update_entry(&ge->eta.iodepth, 0, "");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.jobs), "");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.files), "");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.read_bw), "");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.read_iops), "");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.write_bw), "");
+       gtk_entry_set_text(GTK_ENTRY(ge->eta.write_iops), "");
+}
+
+static void set_menu_entry_text(struct gui *ui, const char *path,
+                               const char *text)
+{
+       GtkWidget *w;
+
+       w = gtk_ui_manager_get_widget(ui->uimanager, path);
+       if (w)
+               gtk_menu_item_set_label(GTK_MENU_ITEM(w), text);
+       else
+               fprintf(stderr, "gfio: can't find path %s\n", path);
+}
+
+
+static void set_menu_entry_visible(struct gui *ui, const char *path, int show)
+{
+       GtkWidget *w;
+
+       w = gtk_ui_manager_get_widget(ui->uimanager, path);
+       if (w)
+               gtk_widget_set_sensitive(w, show);
+       else
+               fprintf(stderr, "gfio: can't find path %s\n", path);
+}
+
+static void set_job_menu_visible(struct gui *ui, int visible)
+{
+       set_menu_entry_visible(ui, "/MainMenu/JobMenu", visible);
+}
+
+static void set_view_results_visible(struct gui *ui, int visible)
+{
+       set_menu_entry_visible(ui, "/MainMenu/ViewMenu/Results", visible);
+}
+
+static const char *get_button_tooltip(struct button_spec *s, int sensitive)
+{
+       if (s->tooltiptext[sensitive])
+               return s->tooltiptext[sensitive];
+
+       return s->tooltiptext[0];
+}
+
+static GtkWidget *add_button(GtkWidget *buttonbox,
+                            struct button_spec *buttonspec, gpointer data)
+{
+       GtkWidget *button = gtk_button_new_with_label(buttonspec->buttontext);
+       gboolean sens = buttonspec->start_sensitive;
+
+       g_signal_connect(button, "clicked", G_CALLBACK(buttonspec->f), data);
+       gtk_box_pack_start(GTK_BOX(buttonbox), button, FALSE, FALSE, 3);
+
+       sens = buttonspec->start_sensitive;
+       gtk_widget_set_tooltip_text(button, get_button_tooltip(buttonspec, sens));
+       gtk_widget_set_sensitive(button, sens);
+
+       return button;
+}
+
+static void add_buttons(struct gui_entry *ge, struct button_spec *buttonlist,
+                       int nbuttons)
+{
+       int i;
+
+       for (i = 0; i < nbuttons; i++)
+               ge->button[i] = add_button(ge->buttonbox, &buttonlist[i], ge);
+}
+
+/*
+ * Update sensitivity of job buttons and job menu items, based on the
+ * state of the client.
+ */
+static void update_button_states(struct gui *ui, struct gui_entry *ge)
+{
+       unsigned int connect_state, send_state, start_state, edit_state;
+       const char *connect_str = NULL;
+
+       switch (ge->state) {
+       default:
+               gfio_report_error(ge, "Bad client state: %u\n", ge->state);
+               /* fall through to new state */
+       case GE_STATE_NEW:
+               connect_state = 1;
+               edit_state = 1;
+               connect_str = "Connect";
+               send_state = 0;
+               start_state = 0;
+               break;
+       case GE_STATE_CONNECTED:
+               connect_state = 1;
+               edit_state = 1;
+               connect_str = "Disconnect";
+               send_state = 1;
+               start_state = 0;
+               break;
+       case GE_STATE_JOB_SENT:
+               connect_state = 1;
+               edit_state = 1;
+               connect_str = "Disconnect";
+               send_state = 0;
+               start_state = 1;
+               break;
+       case GE_STATE_JOB_STARTED:
+               connect_state = 1;
+               edit_state = 1;
+               connect_str = "Disconnect";
+               send_state = 0;
+               start_state = 1;
+               break;
+       case GE_STATE_JOB_RUNNING:
+               connect_state = 1;
+               edit_state = 0;
+               connect_str = "Disconnect";
+               send_state = 0;
+               start_state = 0;
+               break;
+       case GE_STATE_JOB_DONE:
+               connect_state = 1;
+               edit_state = 0;
+               connect_str = "Connect";
+               send_state = 0;
+               start_state = 0;
+               break;
+       }
+
+       gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_CONNECT], connect_state);
+       gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_SEND], send_state);
+       gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_START], start_state);
+       gtk_button_set_label(GTK_BUTTON(ge->button[GFIO_BUTTON_CONNECT]), connect_str);
+       gtk_widget_set_tooltip_text(ge->button[GFIO_BUTTON_CONNECT], get_button_tooltip(&buttonspeclist[GFIO_BUTTON_CONNECT], connect_state));
+
+       set_menu_entry_visible(ui, "/MainMenu/JobMenu/Connect", connect_state);
+       set_menu_entry_text(ui, "/MainMenu/JobMenu/Connect", connect_str);
+
+       set_menu_entry_visible(ui, "/MainMenu/JobMenu/Edit job", edit_state);
+       set_menu_entry_visible(ui, "/MainMenu/JobMenu/Send job", send_state);
+       set_menu_entry_visible(ui, "/MainMenu/JobMenu/Start job", start_state);
+
+       if (ge->client && ge->client->nr_results)
+               set_view_results_visible(ui, 1);
+       else
+               set_view_results_visible(ui, 0);
+}
+
+void gfio_set_state(struct gui_entry *ge, unsigned int state)
+{
+       ge->state = state;
+       update_button_states(ge->ui, ge);
+}
+
+static void gfio_ui_setup_log(struct gui *ui)
+{
+       GtkTreeSelection *selection;
+       GtkListStore *model;
+       GtkWidget *tree_view;
+
+       model = gtk_list_store_new(4, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING);
+
+       tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
+       gtk_widget_set_can_focus(tree_view, FALSE);
+
+       selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
+       gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
+       g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
+               "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH, NULL);
+
+       tree_view_column(tree_view, 0, "Time", ALIGN_RIGHT | UNSORTABLE);
+       tree_view_column(tree_view, 1, "Host", ALIGN_RIGHT | UNSORTABLE);
+       tree_view_column(tree_view, 2, "Level", ALIGN_RIGHT | UNSORTABLE);
+       tree_view_column(tree_view, 3, "Text", ALIGN_LEFT | UNSORTABLE);
+
+       ui->log_model = model;
+       ui->log_tree = tree_view;
+}
+
+static gint on_config_drawing_area(GtkWidget *w, GdkEventConfigure *event,
+                                  gpointer data)
+{
+       guint width = gtk_widget_get_allocated_width(w);
+       guint height = gtk_widget_get_allocated_height(w);
+       struct gfio_graphs *g = data;
+
+       graph_set_size(g->iops_graph, width / 2.0, height);
+       graph_set_position(g->iops_graph, width / 2.0, 0.0);
+       graph_set_size(g->bandwidth_graph, width / 2.0, height);
+       graph_set_position(g->bandwidth_graph, 0, 0);
+       return TRUE;
+}
+
+static void draw_graph(struct graph *g, cairo_t *cr)
+{
+       line_graph_draw(g, cr);
+       cairo_stroke(cr);
+}
+
+static gboolean graph_tooltip(GtkWidget *w, gint x, gint y,
+                             gboolean keyboard_mode, GtkTooltip *tooltip,
+                             gpointer data)
+{
+       struct gfio_graphs *g = data;
+       const char *text = NULL;
+
+       if (graph_contains_xy(g->iops_graph, x, y))
+               text = graph_find_tooltip(g->iops_graph, x, y);
+       else if (graph_contains_xy(g->bandwidth_graph, x, y))
+               text = graph_find_tooltip(g->bandwidth_graph, x, y);
+
+       if (text) {
+               gtk_tooltip_set_text(tooltip, text);
+               return TRUE;
+       }
+
+       return FALSE;
+}
+
+static int on_expose_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p)
+{
+       struct gfio_graphs *g = p;
+       cairo_t *cr;
+
+       cr = gdk_cairo_create(gtk_widget_get_window(w));
+
+       if (graph_has_tooltips(g->iops_graph) ||
+           graph_has_tooltips(g->bandwidth_graph)) {
+               g_object_set(w, "has-tooltip", TRUE, NULL);
+               g_signal_connect(w, "query-tooltip", G_CALLBACK(graph_tooltip), g);
+       }
+
+       cairo_set_source_rgb(cr, 0, 0, 0);
+       draw_graph(g->iops_graph, cr);
+       draw_graph(g->bandwidth_graph, cr);
+       cairo_destroy(cr);
+
+       return FALSE;
+}
+
+/*
+ * FIXME: need more handling here
+ */
+static void ge_destroy(struct gui_entry *ge)
+{
+       struct gfio_client *gc = ge->client;
+
+       if (gc) {
+               if (gc->client) {
+                       if (ge->state >= GE_STATE_CONNECTED)
+                               fio_client_terminate(gc->client);
+
+                       fio_put_client(gc->client);
+               }
+               free(gc);
+       }
+
+       g_hash_table_remove(ge->ui->ge_hash, &ge->page_num);
+
+       free(ge->job_file);
+       free(ge->host);
+       free(ge);
+}
+
+static void ge_widget_destroy(GtkWidget *w, gpointer data)
+{
+       struct gui_entry *ge = (struct gui_entry *) data;
+
+       ge_destroy(ge);
+}
+
+static void gfio_quit(struct gui *ui)
+{
+       gtk_main_quit();
+}
+
+static void quit_clicked(__attribute__((unused)) GtkWidget *widget,
+                        gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+
+       gfio_quit(ui);
+}
+
+static void *job_thread(void *arg)
+{
+       struct gui *ui = arg;
+
+       ui->handler_running = 1;
+       fio_handle_clients(&gfio_client_ops);
+       ui->handler_running = 0;
+       return NULL;
+}
+
+static int send_job_file(struct gui_entry *ge)
+{
+       struct gfio_client *gc = ge->client;
+       int ret = 0;
+
+       /*
+        * Prune old options, we are expecting the return options
+        * when the job file is parsed remotely and returned to us.
+        */
+       while (!flist_empty(&gc->o_list)) {
+               struct gfio_client_options *gco;
+
+               gco = flist_entry(gc->o_list.next, struct gfio_client_options, list);
+               flist_del(&gco->list);
+               free(gco);
+       }
+
+       ret = fio_client_send_ini(gc->client, ge->job_file);
+       if (!ret)
+               return 0;
+
+       gfio_report_error(ge, "Failed to send file %s: %s\n", ge->job_file, strerror(-ret));
+       return 1;
+}
+
+static void *server_thread(void *arg)
+{
+       is_backend = 1;
+       gfio_server_running = 1;
+       fio_start_server(NULL);
+       gfio_server_running = 0;
+       return NULL;
+}
+
+static void gfio_start_server(struct gui *ui)
+{
+       if (!gfio_server_running) {
+               gfio_server_running = 1;
+               pthread_create(&ui->server_t, NULL, server_thread, NULL);
+               pthread_detach(ui->server_t);
+       }
+}
+
+static void start_job_clicked(__attribute__((unused)) GtkWidget *widget,
+                             gpointer data)
+{
+       struct gui_entry *ge = data;
+       struct gfio_client *gc = ge->client;
+
+       if (gc)
+               fio_start_client(gc->client);
+}
+
+static void file_open(GtkWidget *w, gpointer data);
+
+struct connection_widgets
+{
+       GtkWidget *hentry;
+       GtkWidget *combo;
+       GtkWidget *button;
+};
+
+static void hostname_cb(GtkEntry *entry, gpointer data)
+{
+       struct connection_widgets *cw = data;
+       int uses_net = 0, is_localhost = 0;
+       const gchar *text;
+       gchar *ctext;
+
+       /*
+        * Check whether to display the 'auto start backend' box
+        * or not. Show it if we are a localhost and using network,
+        * or using a socket.
+        */
+       ctext = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(cw->combo));
+       if (!ctext || !strncmp(ctext, "IPv4", 4) || !strncmp(ctext, "IPv6", 4))
+               uses_net = 1;
+       g_free(ctext);
+
+       if (uses_net) {
+               text = gtk_entry_get_text(GTK_ENTRY(cw->hentry));
+               if (!strcmp(text, "127.0.0.1") || !strcmp(text, "localhost") ||
+                   !strcmp(text, "::1") || !strcmp(text, "ip6-localhost") ||
+                   !strcmp(text, "ip6-loopback"))
+                       is_localhost = 1;
+       }
+
+       if (!uses_net || is_localhost) {
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cw->button), 1);
+               gtk_widget_set_sensitive(cw->button, 1);
+       } else {
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cw->button), 0);
+               gtk_widget_set_sensitive(cw->button, 0);
+       }
+}
+
+static int get_connection_details(struct gui_entry *ge)
+{
+       GtkWidget *dialog, *box, *vbox, *hbox, *frame, *pentry;
+       struct connection_widgets cw;
+       struct gui *ui = ge->ui;
+       char *typeentry;
+
+       if (ge->host)
+               return 0;
+
+       dialog = gtk_dialog_new_with_buttons("Connection details",
+                       GTK_WINDOW(ui->window),
+                       GTK_DIALOG_DESTROY_WITH_PARENT,
+                       GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+                       GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
+
+       frame = gtk_frame_new("Hostname / socket name");
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+
+       box = gtk_vbox_new(FALSE, 6);
+       gtk_container_add(GTK_CONTAINER(frame), box);
+
+       hbox = gtk_hbox_new(TRUE, 10);
+       gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
+       cw.hentry = gtk_entry_new();
+       gtk_entry_set_text(GTK_ENTRY(cw.hentry), "localhost");
+       gtk_box_pack_start(GTK_BOX(hbox), cw.hentry, TRUE, TRUE, 0);
+
+       frame = gtk_frame_new("Port");
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+       box = gtk_vbox_new(FALSE, 10);
+       gtk_container_add(GTK_CONTAINER(frame), box);
+
+       hbox = gtk_hbox_new(TRUE, 4);
+       gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
+       pentry = create_spinbutton(hbox, 1, 65535, FIO_NET_PORT);
+
+       frame = gtk_frame_new("Type");
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+       box = gtk_vbox_new(FALSE, 10);
+       gtk_container_add(GTK_CONTAINER(frame), box);
+
+       hbox = gtk_hbox_new(TRUE, 4);
+       gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
+
+       cw.combo = gtk_combo_box_text_new();
+       gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cw.combo), "IPv4");
+       gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cw.combo), "IPv6");
+       gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(cw.combo), "local socket");
+       gtk_combo_box_set_active(GTK_COMBO_BOX(cw.combo), 0);
+
+       gtk_container_add(GTK_CONTAINER(hbox), cw.combo);
+
+       frame = gtk_frame_new("Options");
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+       box = gtk_vbox_new(FALSE, 10);
+       gtk_container_add(GTK_CONTAINER(frame), box);
+
+       hbox = gtk_hbox_new(TRUE, 4);
+       gtk_box_pack_start(GTK_BOX(box), hbox, FALSE, FALSE, 0);
+
+       cw.button = gtk_check_button_new_with_label("Auto-spawn fio backend");
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(cw.button), 1);
+       gtk_widget_set_tooltip_text(cw.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.");
+       gtk_box_pack_start(GTK_BOX(hbox), cw.button, FALSE, FALSE, 6);
+
+       /*
+        * Connect edit signal, so we can show/not-show the auto start button
+        */
+       g_signal_connect(G_OBJECT(cw.hentry), "changed", G_CALLBACK(hostname_cb), &cw);
+       g_signal_connect(G_OBJECT(cw.combo), "changed", G_CALLBACK(hostname_cb), &cw);
+
+       gtk_widget_show_all(dialog);
+
+       if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
+               gtk_widget_destroy(dialog);
+               return 1;
+       }
+
+       ge->host = strdup(gtk_entry_get_text(GTK_ENTRY(cw.hentry)));
+       ge->port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(pentry));
+
+       typeentry = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(cw.combo));
+       if (!typeentry || !strncmp(typeentry, "IPv4", 4))
+               ge->type = Fio_client_ipv4;
+       else if (!strncmp(typeentry, "IPv6", 4))
+               ge->type = Fio_client_ipv6;
+       else
+               ge->type = Fio_client_socket;
+       g_free(typeentry);
+
+       ge->server_start = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(cw.button));
+
+       gtk_widget_destroy(dialog);
+       return 0;
+}
+
+static void gfio_set_client(struct gfio_client *gc, struct fio_client *client)
+{
+       gc->client = fio_get_client(client);
+       client->client_data = gc;
+}
+
+static void gfio_client_added(struct gui_entry *ge, struct fio_client *client)
+{
+       struct gfio_client_options *gco;
+       struct gfio_client *gc;
+
+       gc = calloc(1, sizeof(*gc));
+       INIT_FLIST_HEAD(&gc->o_list);
+       gc->ge = ge;
+       ge->client = gc;
+       gfio_set_client(gc, client);
+
+       /*
+        * Just add a default set of options, need to consider how best
+        * to handle this
+        */
+       gco = calloc(1, sizeof(*gco));
+       INIT_FLIST_HEAD(&gco->list);
+       options_default_fill(&gco->o);
+       flist_add_tail(&gco->list, &gc->o_list);
+       gc->o_list_nr++;
+}
+
+static void gfio_clear_graph_data(struct gfio_graphs *g)
+{
+       graph_clear_values(g->iops_graph);
+       graph_clear_values(g->bandwidth_graph);
+}
+
+static void connect_clicked(GtkWidget *widget, gpointer data)
+{
+       struct gui_entry *ge = data;
+       struct gfio_client *gc = ge->client;
+
+       if (ge->state == GE_STATE_NEW) {
+               int ret;
+
+               if (!ge->job_file)
+                       file_open(widget, ge->ui);
+               if (!ge->job_file)
+                       return;
+
+               gc = ge->client;
+
+               if (!gc->client) {
+                       struct fio_client *client;
+
+                       if (get_connection_details(ge)) {
+                               gfio_report_error(ge, "Failed to get connection details\n");
+                               return;
+                       }
+
+                       client = fio_client_add_explicit(&gfio_client_ops, ge->host, ge->type, ge->port);
+                       if (!client) {
+                               gfio_report_error(ge, "Failed to add client %s\n", ge->host);
+                               free(ge->host);
+                               ge->host = NULL;
+                               return;
+                       }
+                       gfio_set_client(gc, client);
+               }
+
+               gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), "No jobs running");
+               gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), 0.0);
+               ret = fio_client_connect(gc->client);
+               if (!ret) {
+                       if (!ge->ui->handler_running)
+                               pthread_create(&ge->ui->t, NULL, job_thread, ge->ui);
+                       gfio_set_state(ge, GE_STATE_CONNECTED);
+                       gfio_clear_graph_data(&ge->graphs);
+               } else {
+                       gfio_report_error(ge, "Failed to connect to %s: %s\n", ge->client->client->hostname, strerror(-ret));
+               }
+       } else {
+               fio_client_terminate(gc->client);
+               gfio_set_state(ge, GE_STATE_NEW);
+               clear_ge_ui_info(ge);
+       }
+}
+
+static void send_clicked(GtkWidget *widget, gpointer data)
+{
+       struct gui_entry *ge = data;
+
+       if (send_job_file(ge))
+               gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_START], 1);
+}
+
+static GtkWidget *new_client_page(struct gui_entry *ge);
+
+static struct gui_entry *alloc_new_gui_entry(struct gui *ui)
+{
+       struct gui_entry *ge;
+
+       ge = malloc(sizeof(*ge));
+       memset(ge, 0, sizeof(*ge));
+       ge->state = GE_STATE_NEW;
+       ge->ui = ui;
+       return ge;
+}
+
+static struct gui_entry *get_new_ge_with_tab(struct gui *ui, const char *name)
+{
+       struct gui_entry *ge;
+
+       ge = alloc_new_gui_entry(ui);
+
+       ge->vbox = new_client_page(ge);
+       g_signal_connect(ge->vbox, "destroy", G_CALLBACK(ge_widget_destroy), ge);
+
+       ge->page_label = gtk_label_new(name);
+       ge->page_num = gtk_notebook_append_page(GTK_NOTEBOOK(ui->notebook), ge->vbox, ge->page_label);
+
+       g_hash_table_insert(ui->ge_hash, &ge->page_num, ge);
+
+       gtk_widget_show_all(ui->window);
+       return ge;
+}
+
+static void file_new(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+       struct gui_entry *ge;
+
+       ge = get_new_ge_with_tab(ui, "Untitled");
+       gtk_notebook_set_current_page(GTK_NOTEBOOK(ui->notebook), ge->page_num);
+}
+
+/*
+ * Return the 'ge' corresponding to the tab. If the active tab is the
+ * main tab, open a new tab.
+ */
+static struct gui_entry *get_ge_from_page(struct gui *ui, gint cur_page,
+                                         int *created)
+{
+       if (!cur_page) {
+               if (created)
+                       *created = 1;
+               return get_new_ge_with_tab(ui, "Untitled");
+       }
+
+       if (created)
+               *created = 0;
+
+       return g_hash_table_lookup(ui->ge_hash, &cur_page);
+}
+
+static struct gui_entry *get_ge_from_cur_tab(struct gui *ui)
+{
+       gint cur_page;
+
+       /*
+        * Main tab is tab 0, so any current page other than 0 holds
+        * a ge entry.
+        */
+       cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(ui->notebook));
+       if (cur_page)
+               return get_ge_from_page(ui, cur_page, NULL);
+
+       return NULL;
+}
+
+static void file_close(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+       struct gui_entry *ge;
+
+       /*
+        * Can't close the main tab
+        */
+       ge = get_ge_from_cur_tab(ui);
+       if (ge) {
+               gtk_widget_destroy(ge->vbox);
+               return;
+       }
+
+       if (g_hash_table_size(ui->ge_hash)) {
+               gfio_report_info(ui, "Error", "The main page view cannot be closed\n");
+               return;
+       }
+
+       gfio_quit(ui);
+}
+
+static void file_add_recent(struct gui *ui, const gchar *uri)
+{
+       GtkRecentData grd;
+
+       memset(&grd, 0, sizeof(grd));
+       grd.display_name = strdup("gfio");
+       grd.description = strdup("Fio job file");
+       grd.mime_type = strdup(GFIO_MIME);
+       grd.app_name = strdup(g_get_application_name());
+       grd.app_exec = strdup("gfio %f/%u");
+
+       gtk_recent_manager_add_full(ui->recentmanager, uri, &grd);
+}
+
+static gchar *get_filename_from_uri(const gchar *uri)
+{
+       if (strncmp(uri, "file://", 7))
+               return strdup(uri);
+
+       return strdup(uri + 7);
+}
+
+static int do_file_open(struct gui_entry *ge, const gchar *uri)
+{
+       struct fio_client *client;
+
+       assert(!ge->job_file);
+
+       ge->job_file = get_filename_from_uri(uri);
+
+       client = fio_client_add_explicit(&gfio_client_ops, ge->host, ge->type, ge->port);
+       if (client) {
+               char *label = strdup(uri);
+
+               basename(label);
+               gtk_label_set_text(GTK_LABEL(ge->page_label), basename(label));
+               free(label);
+
+               gfio_client_added(ge, client);
+               file_add_recent(ge->ui, uri);
+               return 0;
+       }
+
+       gfio_report_error(ge, "Failed to add client %s\n", ge->host);
+       free(ge->host);
+       ge->host = NULL;
+       free(ge->job_file);
+       ge->job_file = NULL;
+       return 1;
+}
+
+static int do_file_open_with_tab(struct gui *ui, const gchar *uri)
+{
+       struct gui_entry *ge;
+       gint cur_page;
+       int ret, ge_is_new = 0;
+
+       /*
+        * Creates new tab if current tab is the main window, or the
+        * current tab already has a client.
+        */
+       cur_page = gtk_notebook_get_current_page(GTK_NOTEBOOK(ui->notebook));
+       ge = get_ge_from_page(ui, cur_page, &ge_is_new);
+       if (ge->client) {
+               ge = get_new_ge_with_tab(ui, "Untitled");
+               ge_is_new = 1;
+       }
+
+       gtk_notebook_set_current_page(GTK_NOTEBOOK(ui->notebook), ge->page_num);
+
+       if (get_connection_details(ge)) {
+               if (ge_is_new)
+                       gtk_widget_destroy(ge->vbox);
+
+               return 1;
+       }
+
+       ret = do_file_open(ge, uri);
+
+       if (!ret) {
+               if (ge->server_start)
+                       gfio_start_server(ui);
+       } else {
+               if (ge_is_new)
+                       gtk_widget_destroy(ge->vbox);
+       }
+
+       return ret;
+}
+
+static void recent_open(GtkAction *action, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+       GtkRecentInfo *info;
+       const gchar *uri;
+
+       info = g_object_get_data(G_OBJECT(action), "gtk-recent-info");
+       uri = gtk_recent_info_get_uri(info);
+
+       do_file_open_with_tab(ui, uri);
+}
+
+static void file_open(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = data;
+       GtkWidget *dialog;
+       GtkFileFilter *filter;
+       gchar *filename;
+
+       dialog = gtk_file_chooser_dialog_new("Open File",
+               GTK_WINDOW(ui->window),
+               GTK_FILE_CHOOSER_ACTION_OPEN,
+               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+               GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT,
+               NULL);
+       gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), FALSE);
+
+       filter = gtk_file_filter_new();
+       gtk_file_filter_add_pattern(filter, "*.fio");
+       gtk_file_filter_add_pattern(filter, "*.job");
+       gtk_file_filter_add_pattern(filter, "*.ini");
+       gtk_file_filter_add_mime_type(filter, GFIO_MIME);
+       gtk_file_filter_set_name(filter, "Fio job file");
+       gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter);
+
+       if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
+               gtk_widget_destroy(dialog);
+               return;
+       }
+
+       filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+
+       gtk_widget_destroy(dialog);
+
+       do_file_open_with_tab(ui, filename);
+       g_free(filename);
+}
+
+static void file_save(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = data;
+       GtkWidget *dialog;
+
+       dialog = gtk_file_chooser_dialog_new("Save File",
+               GTK_WINDOW(ui->window),
+               GTK_FILE_CHOOSER_ACTION_SAVE,
+               GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+               GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT,
+               NULL);
+
+       gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE);
+       gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document");
+
+       if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) {
+               char *filename;
+
+               filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+               // save_job_file(filename);
+               g_free(filename);
+       }
+       gtk_widget_destroy(dialog);
+}
+
+static void view_log_destroy(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+
+       g_object_ref(G_OBJECT(ui->log_tree));
+       gtk_container_remove(GTK_CONTAINER(w), ui->log_tree);
+       gtk_widget_destroy(w);
+       ui->log_view = NULL;
+}
+
+void gfio_view_log(struct gui *ui)
+{
+       GtkWidget *win, *scroll, *vbox, *box;
+
+       if (ui->log_view)
+               return;
+
+       ui->log_view = win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_title(GTK_WINDOW(win), "Log");
+       gtk_window_set_default_size(GTK_WINDOW(win), 700, 500);
+
+       scroll = gtk_scrolled_window_new(NULL, NULL);
+
+       gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
+
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+       box = gtk_hbox_new(TRUE, 0);
+       gtk_box_pack_start(GTK_BOX(box), ui->log_tree, TRUE, TRUE, 0);
+       g_signal_connect(box, "destroy", G_CALLBACK(view_log_destroy), ui);
+       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), box);
+
+       vbox = gtk_vbox_new(TRUE, 5);
+       gtk_box_pack_start(GTK_BOX(vbox), scroll, TRUE, TRUE, 0);
+
+       gtk_container_add(GTK_CONTAINER(win), vbox);
+       gtk_widget_show_all(win);
+}
+
+static void view_log(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+
+       gfio_view_log(ui);
+}
+
+static void connect_job_entry(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+       struct gui_entry *ge;
+
+       ge = get_ge_from_cur_tab(ui);
+       if (ge)
+               connect_clicked(w, ge);
+}
+
+static void send_job_entry(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+       struct gui_entry *ge;
+
+       ge = get_ge_from_cur_tab(ui);
+       if (ge)
+               send_clicked(w, ge);
+}
+
+static void edit_job_entry(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+       struct gui_entry *ge;
+
+       ge = get_ge_from_cur_tab(ui);
+       if (ge && ge->client)
+               gopt_get_options_window(ui->window, ge->client);
+}
+
+static void start_job_entry(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+       struct gui_entry *ge;
+
+       ge = get_ge_from_cur_tab(ui);
+       if (ge)
+               start_job_clicked(w, ge);
+}
+
+static void view_results(GtkWidget *w, gpointer data)
+{
+       struct gui *ui = (struct gui *) data;
+       struct gfio_client *gc;
+       struct gui_entry *ge;
+
+       ge = get_ge_from_cur_tab(ui);
+       if (!ge)
+               return;
+
+       if (ge->results_window)
+               return;
+
+       gc = ge->client;
+       if (gc && gc->nr_results)
+               gfio_display_end_results(gc);
+}
+
+static void __update_graph_settings(struct gfio_graphs *g)
+{
+       line_graph_set_data_count_limit(g->iops_graph, gfio_graph_limit);
+       graph_set_font(g->iops_graph, gfio_graph_font);
+       line_graph_set_data_count_limit(g->bandwidth_graph, gfio_graph_limit);
+       graph_set_font(g->bandwidth_graph, gfio_graph_font);
+}
+
+static void ge_update_settings_fn(gpointer key, gpointer value, gpointer data)
+{
+       struct gui_entry *ge = (struct gui_entry *) value;
+       GdkEvent *ev;
+
+       __update_graph_settings(&ge->graphs);
+
+       ev = gdk_event_new(GDK_EXPOSE);
+       g_signal_emit_by_name(G_OBJECT(ge->graphs.drawing_area), GFIO_DRAW_EVENT, GTK_WIDGET(ge->graphs.drawing_area), ev, &ge->graphs);
+       gdk_event_free(ev);
+}
+
+static void update_graph_limits(void)
+{
+       struct gui *ui = &main_ui;
+       GdkEvent *ev;
+
+       __update_graph_settings(&ui->graphs);
+
+       ev = gdk_event_new(GDK_EXPOSE);
+       g_signal_emit_by_name(G_OBJECT(ui->graphs.drawing_area), GFIO_DRAW_EVENT, GTK_WIDGET(ui->graphs.drawing_area), ev, &ui->graphs);
+       gdk_event_free(ev);
+
+       g_hash_table_foreach(ui->ge_hash, ge_update_settings_fn, NULL);
+}
+
+static void preferences(GtkWidget *w, gpointer data)
+{
+       GtkWidget *dialog, *frame, *box, **buttons, *vbox, *font;
+       GtkWidget *hbox, *spin, *entry, *spin_int;
+       struct gui *ui = (struct gui *) data;
+       int i;
+
+       dialog = gtk_dialog_new_with_buttons("Preferences",
+               GTK_WINDOW(ui->window),
+               GTK_DIALOG_DESTROY_WITH_PARENT,
+               GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
+               GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
+               NULL);
+
+       frame = gtk_frame_new("Graphing");
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+       vbox = gtk_vbox_new(FALSE, 6);
+       gtk_container_add(GTK_CONTAINER(frame), vbox);
+
+       hbox = gtk_hbox_new(FALSE, 5);
+       gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
+       entry = gtk_label_new("Font face to use for graph labels");
+       gtk_box_pack_start(GTK_BOX(hbox), entry, TRUE, TRUE, 5);
+
+       font = gtk_font_button_new_with_font(gfio_graph_font);
+       gtk_box_pack_start(GTK_BOX(hbox), font, FALSE, FALSE, 5);
+
+       box = gtk_vbox_new(FALSE, 6);
+       gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
+
+       hbox = gtk_hbox_new(FALSE, 5);
+       gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, TRUE, 5);
+       entry = gtk_label_new("Maximum number of data points in graph (seconds)");
+       gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
+
+       spin = create_spinbutton(hbox, 10, 1000000, gfio_graph_limit);
+
+       box = gtk_vbox_new(FALSE, 6);
+       gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
+
+       hbox = gtk_hbox_new(FALSE, 5);
+       gtk_box_pack_start(GTK_BOX(box), hbox, TRUE, TRUE, 5);
+       entry = gtk_label_new("Client ETA request interval (msec)");
+       gtk_box_pack_start(GTK_BOX(hbox), entry, FALSE, FALSE, 5);
+
+       spin_int = create_spinbutton(hbox, 100, 100000, gfio_client_ops.eta_msec);
+       frame = gtk_frame_new("Debug logging");
+       vbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
+       gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
+       vbox = gtk_vbox_new(FALSE, 6);
+       gtk_container_add(GTK_CONTAINER(frame), vbox);
+
+       box = gtk_hbox_new(FALSE, 6);
+       gtk_container_add(GTK_CONTAINER(vbox), box);
+
+       buttons = malloc(sizeof(GtkWidget *) * FD_DEBUG_MAX);
+
+       for (i = 0; i < FD_DEBUG_MAX; i++) {
+               if (i == 7) {
+                       box = gtk_hbox_new(FALSE, 6);
+                       gtk_container_add(GTK_CONTAINER(vbox), box);
+               }
+
+
+               buttons[i] = gtk_check_button_new_with_label(debug_levels[i].name);
+               gtk_widget_set_tooltip_text(buttons[i], debug_levels[i].help);
+               gtk_box_pack_start(GTK_BOX(box), buttons[i], FALSE, FALSE, 6);
+       }
+
+       gtk_widget_show_all(dialog);
+
+       if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) {
+               gtk_widget_destroy(dialog);
+               return;
+       }
+
+       for (i = 0; i < FD_DEBUG_MAX; i++) {
+               int set;
+
+               set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(buttons[i]));
+               if (set)
+                       fio_debug |= (1UL << i);
+       }
+
+       gfio_graph_font = strdup(gtk_font_button_get_font_name(GTK_FONT_BUTTON(font)));
+       gfio_graph_limit = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin));
+       update_graph_limits();
+       gfio_client_ops.eta_msec = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(spin_int));
+
+       gtk_widget_destroy(dialog);
+}
+
+static void about_dialog(GtkWidget *w, gpointer data)
+{
+       const char *authors[] = {
+               "Jens Axboe <axboe@kernel.dk>",
+               "Stephen Carmeron <stephenmcameron@gmail.com>",
+               NULL
+       };
+       const char *license[] = {
+               "Fio is free software; you can redistribute it and/or modify "
+               "it under the terms of the GNU General Public License as published by "
+               "the Free Software Foundation; either version 2 of the License, or "
+               "(at your option) any later version.\n",
+               "Fio is distributed in the hope that it will be useful, "
+               "but WITHOUT ANY WARRANTY; without even the implied warranty of "
+               "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the "
+               "GNU General Public License for more details.\n",
+               "You should have received a copy of the GNU General Public License "
+               "along with Fio; if not, write to the Free Software Foundation, Inc., "
+               "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301  USA\n"
+       };
+       char *license_trans;
+
+       license_trans = g_strconcat(license[0], "\n", license[1], "\n",
+                                    license[2], "\n", NULL);
+
+       gtk_show_about_dialog(NULL,
+               "program-name", "gfio",
+               "comments", "Gtk2 UI for fio",
+               "license", license_trans,
+               "website", "http://git.kernel.dk/?p=fio.git;a=summary",
+               "authors", authors,
+               "version", fio_version_string,
+               "copyright", "© 2012 Jens Axboe <axboe@kernel.dk>",
+               "logo-icon-name", "fio",
+               /* Must be last: */
+               "wrap-license", TRUE,
+               NULL);
+
+       g_free(license_trans);
+}
+
+static GtkActionEntry menu_items[] = {
+       { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
+       { "ViewMenuAction", GTK_STOCK_FILE, "View", NULL, NULL, NULL},
+       { "JobMenuAction", GTK_STOCK_FILE, "Job", NULL, NULL, NULL},
+       { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL},
+       { "NewFile", GTK_STOCK_NEW, "New", "<Control>N", NULL, G_CALLBACK(file_new) },
+       { "CloseFile", GTK_STOCK_CLOSE, "Close", "<Control>W", NULL, G_CALLBACK(file_close) },
+       { "OpenFile", GTK_STOCK_OPEN, NULL,   "<Control>O", NULL, G_CALLBACK(file_open) },
+       { "SaveFile", GTK_STOCK_SAVE, NULL,   "<Control>S", NULL, G_CALLBACK(file_save) },
+       { "Preferences", GTK_STOCK_PREFERENCES, NULL, "<Control>p", NULL, G_CALLBACK(preferences) },
+       { "ViewLog", NULL, "Log", "<Control>l", NULL, G_CALLBACK(view_log) },
+       { "ViewResults", NULL, "Results", "<Control>R", NULL, G_CALLBACK(view_results) },
+       { "ConnectJob", NULL, "Connect", "<Control>D", NULL, G_CALLBACK(connect_job_entry) },
+       { "EditJob", NULL, "Edit job", "<Control>E", NULL, G_CALLBACK(edit_job_entry) },
+       { "SendJob", NULL, "Send job", "<Control>X", NULL, G_CALLBACK(send_job_entry) },
+       { "StartJob", NULL, "Start job", "<Control>L", NULL, G_CALLBACK(start_job_entry) },
+       { "Quit", GTK_STOCK_QUIT, NULL,   "<Control>Q", NULL, G_CALLBACK(quit_clicked) },
+       { "About", GTK_STOCK_ABOUT, NULL,  NULL, NULL, G_CALLBACK(about_dialog) },
+};
+static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]);
+
+static const gchar *ui_string = " \
+       <ui> \
+               <menubar name=\"MainMenu\"> \
+                       <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
+                               <menuitem name=\"New\" action=\"NewFile\" /> \
+                               <menuitem name=\"Open\" action=\"OpenFile\" /> \
+                               <menuitem name=\"Close\" action=\"CloseFile\" /> \
+                               <separator name=\"Separator1\"/> \
+                               <menuitem name=\"Save\" action=\"SaveFile\" /> \
+                               <separator name=\"Separator2\"/> \
+                               <menuitem name=\"Preferences\" action=\"Preferences\" /> \
+                               <separator name=\"Separator3\"/> \
+                               <placeholder name=\"FileRecentFiles\"/> \
+                               <separator name=\"Separator4\"/> \
+                               <menuitem name=\"Quit\" action=\"Quit\" /> \
+                       </menu> \
+                       <menu name=\"JobMenu\" action=\"JobMenuAction\"> \
+                               <menuitem name=\"Connect\" action=\"ConnectJob\" /> \
+                               <separator name=\"Separator5\"/> \
+                               <menuitem name=\"Edit job\" action=\"EditJob\" /> \
+                               <menuitem name=\"Send job\" action=\"SendJob\" /> \
+                               <separator name=\"Separator6\"/> \
+                               <menuitem name=\"Start job\" action=\"StartJob\" /> \
+                       </menu>\
+                       <menu name=\"ViewMenu\" action=\"ViewMenuAction\"> \
+                               <menuitem name=\"Results\" action=\"ViewResults\" /> \
+                               <separator name=\"Separator7\"/> \
+                               <menuitem name=\"Log\" action=\"ViewLog\" /> \
+                       </menu>\
+                       <menu name=\"Help\" action=\"HelpMenuAction\"> \
+                               <menuitem name=\"About\" action=\"About\" /> \
+                       </menu> \
+               </menubar> \
+       </ui> \
+";
+
+static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager,
+                                  struct gui *ui)
+{
+       GtkActionGroup *action_group;
+       GError *error = 0;
+
+       action_group = gtk_action_group_new("Menu");
+       gtk_action_group_add_actions(action_group, menu_items, nmenu_items, ui);
+
+       gtk_ui_manager_insert_action_group(ui_manager, action_group, 0);
+       gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error);
+
+       gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager));
+
+       return gtk_ui_manager_get_widget(ui_manager, "/MainMenu");
+}
+
+void gfio_ui_setup(GtkSettings *settings, GtkWidget *menubar,
+                  GtkWidget *vbox, GtkUIManager *ui_manager)
+{
+       gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0);
+}
+
+static void combo_entry_changed(GtkComboBox *box, gpointer data)
+{
+       struct gui_entry *ge = (struct gui_entry *) data;
+       gint index;
+
+       index = gtk_combo_box_get_active(box);
+
+       multitext_set_entry(&ge->eta.iotype, index);
+       multitext_set_entry(&ge->eta.bs, index);
+       multitext_set_entry(&ge->eta.ioengine, index);
+       multitext_set_entry(&ge->eta.iodepth, index);
+}
+
+static void combo_entry_destroy(GtkWidget *widget, gpointer data)
+{
+       struct gui_entry *ge = (struct gui_entry *) data;
+
+       multitext_free(&ge->eta.iotype);
+       multitext_free(&ge->eta.bs);
+       multitext_free(&ge->eta.ioengine);
+       multitext_free(&ge->eta.iodepth);
+}
+
+static GtkWidget *new_client_page(struct gui_entry *ge)
+{
+       GtkWidget *main_vbox, *probe, *probe_frame, *probe_box;
+       GtkWidget *scrolled_window, *bottom_align, *top_align, *top_vbox;
+
+       main_vbox = gtk_vbox_new(FALSE, 3);
+
+       top_align = gtk_alignment_new(0, 0, 1, 0);
+       top_vbox = gtk_vbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(top_align), top_vbox);
+       gtk_box_pack_start(GTK_BOX(main_vbox), top_align, FALSE, FALSE, 0);
+
+       probe = gtk_frame_new("Job");
+       gtk_box_pack_start(GTK_BOX(main_vbox), probe, FALSE, FALSE, 3);
+       probe_frame = gtk_vbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(probe), probe_frame);
+
+       probe_box = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, FALSE, FALSE, 3);
+       ge->probe.hostname = new_info_label_in_frame(probe_box, "Host");
+       ge->probe.os = new_info_label_in_frame(probe_box, "OS");
+       ge->probe.arch = new_info_label_in_frame(probe_box, "Architecture");
+       ge->probe.fio_ver = new_info_label_in_frame(probe_box, "Fio version");
+
+       probe_box = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, FALSE, FALSE, 3);
+
+       ge->eta.names = new_combo_entry_in_frame(probe_box, "Jobs");
+       g_signal_connect(ge->eta.names, "changed", G_CALLBACK(combo_entry_changed), ge);
+       g_signal_connect(ge->eta.names, "destroy", G_CALLBACK(combo_entry_destroy), ge);
+       ge->eta.iotype.entry = new_info_entry_in_frame(probe_box, "IO");
+       ge->eta.bs.entry = new_info_entry_in_frame(probe_box, "Blocksize (Read/Write)");
+       ge->eta.ioengine.entry = new_info_entry_in_frame(probe_box, "IO Engine");
+       ge->eta.iodepth.entry = new_info_entry_in_frame(probe_box, "IO Depth");
+       ge->eta.jobs = new_info_entry_in_frame(probe_box, "Jobs");
+       ge->eta.files = new_info_entry_in_frame(probe_box, "Open files");
+
+       probe_box = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, FALSE, FALSE, 3);
+       ge->eta.read_bw = new_info_entry_in_frame_rgb(probe_box, "Read BW", GFIO_READ_R, GFIO_READ_G, GFIO_READ_B);
+       ge->eta.read_iops = new_info_entry_in_frame_rgb(probe_box, "IOPS", GFIO_READ_R, GFIO_READ_G, GFIO_READ_B);
+       ge->eta.write_bw = new_info_entry_in_frame_rgb(probe_box, "Write BW", GFIO_WRITE_R, GFIO_WRITE_G, GFIO_WRITE_B);
+       ge->eta.write_iops = new_info_entry_in_frame_rgb(probe_box, "IOPS", GFIO_WRITE_R, GFIO_WRITE_G, GFIO_WRITE_B);
+       ge->eta.trim_bw = new_info_entry_in_frame_rgb(probe_box, "Trim BW", GFIO_TRIM_R, GFIO_TRIM_G, GFIO_TRIM_B);
+       ge->eta.trim_iops = new_info_entry_in_frame_rgb(probe_box, "IOPS", GFIO_TRIM_R, GFIO_TRIM_G, GFIO_TRIM_B);
+
+       /*
+        * Only add this if we have a commit rate
+        */
+#if 0
+       probe_box = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
+
+       ge->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW");
+       ge->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
+
+       ge->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW");
+       ge->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
+#endif
+
+       /*
+        * Set up a drawing area and IOPS and bandwidth graphs
+        */
+       ge->graphs.drawing_area = gtk_drawing_area_new();
+       gtk_widget_set_size_request(GTK_WIDGET(ge->graphs.drawing_area),
+               DRAWING_AREA_XDIM, DRAWING_AREA_YDIM);
+       gtk_widget_modify_bg(ge->graphs.drawing_area, GTK_STATE_NORMAL, &gfio_color_lightyellow);
+       g_signal_connect(G_OBJECT(ge->graphs.drawing_area), GFIO_DRAW_EVENT,
+                               G_CALLBACK(on_expose_drawing_area), &ge->graphs);
+       g_signal_connect(G_OBJECT(ge->graphs.drawing_area), "configure_event",
+                               G_CALLBACK(on_config_drawing_area), &ge->graphs);
+       scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
+                                       ge->graphs.drawing_area);
+       gtk_box_pack_start(GTK_BOX(main_vbox), scrolled_window, TRUE, TRUE, 0);
+
+       setup_graphs(&ge->graphs);
+
+       /*
+        * Set up alignments for widgets at the bottom of ui,
+        * align bottom left, expand horizontally but not vertically
+        */
+       bottom_align = gtk_alignment_new(0, 1, 1, 0);
+       ge->buttonbox = gtk_hbox_new(FALSE, 0);
+       gtk_container_add(GTK_CONTAINER(bottom_align), ge->buttonbox);
+       gtk_box_pack_start(GTK_BOX(main_vbox), bottom_align, FALSE, FALSE, 0);
+
+       add_buttons(ge, buttonspeclist, ARRAY_SIZE(buttonspeclist));
+
+       /*
+        * Set up thread status progress bar
+        */
+       ge->thread_status_pb = gtk_progress_bar_new();
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), 0.0);
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), "No connections");
+       gtk_container_add(GTK_CONTAINER(ge->buttonbox), ge->thread_status_pb);
+
+
+       return main_vbox;
+}
+
+static GtkWidget *new_main_page(struct gui *ui)
+{
+       GtkWidget *main_vbox, *probe, *probe_frame, *probe_box;
+       GtkWidget *scrolled_window, *bottom_align, *top_align, *top_vbox;
+
+       main_vbox = gtk_vbox_new(FALSE, 3);
+
+       /*
+        * Set up alignments for widgets at the top of ui,
+        * align top left, expand horizontally but not vertically
+        */
+       top_align = gtk_alignment_new(0, 0, 1, 0);
+       top_vbox = gtk_vbox_new(FALSE, 0);
+       gtk_container_add(GTK_CONTAINER(top_align), top_vbox);
+       gtk_box_pack_start(GTK_BOX(main_vbox), top_align, FALSE, FALSE, 0);
+
+       probe = gtk_frame_new("Run statistics");
+       gtk_box_pack_start(GTK_BOX(main_vbox), probe, FALSE, FALSE, 3);
+       probe_frame = gtk_vbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(probe), probe_frame);
+
+       probe_box = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, FALSE, FALSE, 3);
+       ui->eta.jobs = new_info_entry_in_frame(probe_box, "Running");
+       ui->eta.read_bw = new_info_entry_in_frame_rgb(probe_box, "Read BW", GFIO_READ_R, GFIO_READ_G, GFIO_READ_B);
+       ui->eta.read_iops = new_info_entry_in_frame_rgb(probe_box, "IOPS", GFIO_READ_R, GFIO_READ_G, GFIO_READ_B);
+       ui->eta.write_bw = new_info_entry_in_frame_rgb(probe_box, "Write BW", GFIO_WRITE_R, GFIO_WRITE_G, GFIO_WRITE_B);
+       ui->eta.write_iops = new_info_entry_in_frame_rgb(probe_box, "IOPS", GFIO_WRITE_R, GFIO_WRITE_G, GFIO_WRITE_B);
+       ui->eta.trim_bw = new_info_entry_in_frame_rgb(probe_box, "Trim BW", GFIO_TRIM_R, GFIO_TRIM_G, GFIO_TRIM_B);
+       ui->eta.trim_iops = new_info_entry_in_frame_rgb(probe_box, "IOPS", GFIO_TRIM_R, GFIO_TRIM_G, GFIO_TRIM_B);
+
+       /*
+        * Only add this if we have a commit rate
+        */
+#if 0
+       probe_box = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3);
+
+       ui->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW");
+       ui->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
+
+       ui->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW");
+       ui->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS");
+#endif
+
+       /*
+        * Set up a drawing area and IOPS and bandwidth graphs
+        */
+       ui->graphs.drawing_area = gtk_drawing_area_new();
+       gtk_widget_set_size_request(GTK_WIDGET(ui->graphs.drawing_area),
+               DRAWING_AREA_XDIM, DRAWING_AREA_YDIM);
+       gtk_widget_modify_bg(ui->graphs.drawing_area, GTK_STATE_NORMAL, &gfio_color_lightyellow);
+       g_signal_connect(G_OBJECT(ui->graphs.drawing_area), GFIO_DRAW_EVENT,
+                       G_CALLBACK(on_expose_drawing_area), &ui->graphs);
+       g_signal_connect(G_OBJECT(ui->graphs.drawing_area), "configure_event",
+                       G_CALLBACK(on_config_drawing_area), &ui->graphs);
+       scrolled_window = gtk_scrolled_window_new(NULL, NULL);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window),
+                                       GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+       gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scrolled_window),
+                                       ui->graphs.drawing_area);
+       gtk_box_pack_start(GTK_BOX(main_vbox), scrolled_window,
+                       TRUE, TRUE, 0);
+
+       setup_graphs(&ui->graphs);
+
+       /*
+        * Set up alignments for widgets at the bottom of ui,
+        * align bottom left, expand horizontally but not vertically
+        */
+       bottom_align = gtk_alignment_new(0, 1, 1, 0);
+       ui->buttonbox = gtk_hbox_new(FALSE, 0);
+       gtk_container_add(GTK_CONTAINER(bottom_align), ui->buttonbox);
+       gtk_box_pack_start(GTK_BOX(main_vbox), bottom_align, FALSE, FALSE, 0);
+
+       /*
+        * Set up thread status progress bar
+        */
+       ui->thread_status_pb = gtk_progress_bar_new();
+       gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), 0.0);
+       gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No connections");
+       gtk_container_add(GTK_CONTAINER(ui->buttonbox), ui->thread_status_pb);
+
+       return main_vbox;
+}
+
+static gboolean notebook_switch_page(GtkNotebook *notebook, GtkWidget *widget,
+                                    guint page, gpointer data)
+
+{
+       struct gui *ui = (struct gui *) data;
+       struct gui_entry *ge;
+
+       if (!page) {
+               set_job_menu_visible(ui, 0);
+               set_view_results_visible(ui, 0);
+               return TRUE;
+       }
+
+       set_job_menu_visible(ui, 1);
+       ge = get_ge_from_page(ui, page, NULL);
+       if (ge)
+               update_button_states(ui, ge);
+
+       return TRUE;
+}
+
+static gint compare_recent_items(GtkRecentInfo *a, GtkRecentInfo *b)
+{
+       time_t time_a = gtk_recent_info_get_visited(a);
+       time_t time_b = gtk_recent_info_get_visited(b);
+
+       return time_b - time_a;
+}
+
+static void add_recent_file_items(struct gui *ui)
+{
+       const gchar *gfio = g_get_application_name();
+       GList *items, *item;
+       int i = 0;
+
+       if (ui->recent_ui_id) {
+               gtk_ui_manager_remove_ui(ui->uimanager, ui->recent_ui_id);
+               gtk_ui_manager_ensure_update(ui->uimanager);
+       }
+       ui->recent_ui_id = gtk_ui_manager_new_merge_id(ui->uimanager);
+
+       if (ui->actiongroup) {
+               gtk_ui_manager_remove_action_group(ui->uimanager, ui->actiongroup);
+               g_object_unref(ui->actiongroup);
+       }
+       ui->actiongroup = gtk_action_group_new("RecentFileActions");
+
+       gtk_ui_manager_insert_action_group(ui->uimanager, ui->actiongroup, -1);
+
+       items = gtk_recent_manager_get_items(ui->recentmanager);
+       items = g_list_sort(items, (GCompareFunc) compare_recent_items);
+
+       for (item = items; item && item->data; item = g_list_next(item)) {
+               GtkRecentInfo *info = (GtkRecentInfo *) item->data;
+               gchar *action_name;
+               const gchar *label;
+               GtkAction *action;
+
+               if (!gtk_recent_info_has_application(info, gfio))
+                       continue;
+
+               /*
+                * We only support local files for now
+                */
+               if (!gtk_recent_info_is_local(info) || !gtk_recent_info_exists(info))
+                       continue;
+
+               action_name = g_strdup_printf("RecentFile%u", i++);
+               label = gtk_recent_info_get_display_name(info);
+
+               action = g_object_new(GTK_TYPE_ACTION,
+                                       "name", action_name,
+                                       "label", label, NULL);
+
+               g_object_set_data_full(G_OBJECT(action), "gtk-recent-info",
+                                       gtk_recent_info_ref(info),
+                                       (GDestroyNotify) gtk_recent_info_unref);
+
+
+               g_signal_connect(action, "activate", G_CALLBACK(recent_open), ui);
+
+               gtk_action_group_add_action(ui->actiongroup, action);
+               g_object_unref(action);
+
+               gtk_ui_manager_add_ui(ui->uimanager, ui->recent_ui_id,
+                                       "/MainMenu/FileMenu/FileRecentFiles",
+                                       label, action_name,
+                                       GTK_UI_MANAGER_MENUITEM, FALSE);
+
+               g_free(action_name);
+
+               if (i == 8)
+                       break;
+       }
+
+       g_list_foreach(items, (GFunc) gtk_recent_info_unref, NULL);
+       g_list_free(items);
+}
+
+static void drag_and_drop_received(GtkWidget *widget, GdkDragContext *ctx,
+                                  gint x, gint y, GtkSelectionData *seldata,
+                                  guint info, guint time, gpointer *data)
+{
+       struct gui *ui = (struct gui *) data;
+       gchar **uris;
+       GtkWidget *source;
+
+       source = gtk_drag_get_source_widget(ctx);
+       if (source && widget == gtk_widget_get_toplevel(source)) {
+               gtk_drag_finish(ctx, FALSE, FALSE, time);
+               return;
+       }
+
+       uris = gtk_selection_data_get_uris(seldata);
+       if (!uris) {
+               gtk_drag_finish(ctx, FALSE, FALSE, time);
+               return;
+       }
+
+       if (uris[0])
+               do_file_open_with_tab(ui, uris[0]);
+
+       gtk_drag_finish(ctx, TRUE, FALSE, time);
+       g_strfreev(uris);
+}
+
+static void init_ui(int *argc, char **argv[], struct gui *ui)
+{
+       GtkSettings *settings;
+       GtkWidget *vbox;
+
+       /* Magical g*thread incantation, you just need this thread stuff.
+        * Without it, the update that happens in gfio_update_thread_status
+        * doesn't really happen in a timely fashion, you need expose events
+        */
+#if !GTK_CHECK_VERSION(2, 24, 0)
+       if (!g_thread_supported())
+               g_thread_init(NULL);
+#endif
+
+       gdk_threads_init();
+
+       gtk_init(argc, argv);
+       settings = gtk_settings_get_default();
+       gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "gfio setting");
+       g_type_init();
+       gdk_color_parse("#fffff4", &gfio_color_lightyellow);
+       gdk_color_parse("white", &gfio_color_white);
+
+       ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
+       gtk_window_set_title(GTK_WINDOW(ui->window), "fio");
+       gtk_window_set_default_size(GTK_WINDOW(ui->window), 1024, 768);
+
+       g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), ui);
+       g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), ui);
+
+       ui->vbox = gtk_vbox_new(FALSE, 0);
+       gtk_container_add(GTK_CONTAINER(ui->window), ui->vbox);
+
+       ui->uimanager = gtk_ui_manager_new();
+       ui->menu = get_menubar_menu(ui->window, ui->uimanager, ui);
+       gfio_ui_setup(settings, ui->menu, ui->vbox, ui->uimanager);
+
+       ui->recentmanager = gtk_recent_manager_get_default();
+       add_recent_file_items(ui);
+
+       ui->notebook = gtk_notebook_new();
+       g_signal_connect(ui->notebook, "switch-page", G_CALLBACK(notebook_switch_page), ui);
+       gtk_notebook_set_scrollable(GTK_NOTEBOOK(ui->notebook), 1);
+       gtk_notebook_popup_enable(GTK_NOTEBOOK(ui->notebook));
+       gtk_container_add(GTK_CONTAINER(ui->vbox), ui->notebook);
+
+       vbox = new_main_page(ui);
+       gtk_drag_dest_set(GTK_WIDGET(ui->window), GTK_DEST_DEFAULT_ALL, NULL, 1, GDK_ACTION_COPY);
+       gtk_drag_dest_add_uri_targets(GTK_WIDGET(ui->window));
+       g_signal_connect(ui->window, "drag-data-received", G_CALLBACK(drag_and_drop_received), ui);
+
+       gtk_notebook_append_page(GTK_NOTEBOOK(ui->notebook), vbox, gtk_label_new("Main"));
+
+       gfio_ui_setup_log(ui);
+
+       gtk_widget_show_all(ui->window);
+}
+
+int main(int argc, char *argv[], char *envp[])
+{
+       if (initialize_fio(envp))
+               return 1;
+       if (fio_init_options())
+               return 1;
+
+       gopt_init();
+
+       memset(&main_ui, 0, sizeof(main_ui));
+       main_ui.ge_hash = g_hash_table_new(g_int_hash, g_int_equal);
+
+       init_ui(&argc, &argv, &main_ui);
+
+       gdk_threads_enter();
+       gtk_main();
+       gdk_threads_leave();
+
+       g_hash_table_destroy(main_ui.ge_hash);
+
+       gopt_exit();
+       return 0;
+}
diff --git a/gfio.h b/gfio.h
new file mode 100644 (file)
index 0000000..aa14e3c
--- /dev/null
+++ b/gfio.h
@@ -0,0 +1,179 @@
+#ifndef GFIO_H
+#define GFIO_H
+
+#include <gtk/gtk.h>
+
+#include "gcompat.h"
+#include "stat.h"
+#include "thread_options.h"
+#include "ghelpers.h"
+#include "graph.h"
+
+struct probe_widget {
+       GtkWidget *hostname;
+       GtkWidget *os;
+       GtkWidget *arch;
+       GtkWidget *fio_ver;
+};
+
+struct eta_widget {
+       GtkWidget *names;
+       struct multitext_widget iotype;
+       struct multitext_widget bs;
+       struct multitext_widget ioengine;
+       struct multitext_widget iodepth;
+       GtkWidget *jobs;
+       GtkWidget *files;
+       GtkWidget *read_bw;
+       GtkWidget *read_iops;
+       GtkWidget *cr_bw;
+       GtkWidget *cr_iops;
+       GtkWidget *write_bw;
+       GtkWidget *write_iops;
+       GtkWidget *cw_bw;
+       GtkWidget *cw_iops;
+       GtkWidget *trim_bw;
+       GtkWidget *trim_iops;
+};
+
+struct gfio_graphs {
+#define DRAWING_AREA_XDIM 1000
+#define DRAWING_AREA_YDIM 400
+       GtkWidget *drawing_area;
+       struct graph *iops_graph;
+       graph_label_t read_iops;
+       graph_label_t write_iops;
+       graph_label_t trim_iops;
+       struct graph *bandwidth_graph;
+       graph_label_t read_bw;
+       graph_label_t write_bw;
+       graph_label_t trim_bw;
+};
+
+/*
+ * Main window widgets and data
+ */
+struct gui {
+       GtkUIManager *uimanager;
+       GtkRecentManager *recentmanager;
+       GtkActionGroup *actiongroup;
+       guint recent_ui_id;
+       GtkWidget *menu;
+       GtkWidget *window;
+       GtkWidget *vbox;
+       GtkWidget *thread_status_pb;
+       GtkWidget *buttonbox;
+       GtkWidget *notebook;
+       GtkWidget *error_info_bar;
+       GtkWidget *error_label;
+       GtkListStore *log_model;
+       GtkWidget *log_tree;
+       GtkWidget *log_view;
+       struct gfio_graphs graphs;
+       struct probe_widget probe;
+       struct eta_widget eta;
+       pthread_t server_t;
+
+       pthread_t t;
+       int handler_running;
+
+       GHashTable *ge_hash;
+} main_ui;
+
+enum {
+       GE_STATE_NEW = 1,
+       GE_STATE_CONNECTED,
+       GE_STATE_JOB_SENT,
+       GE_STATE_JOB_STARTED,
+       GE_STATE_JOB_RUNNING,
+       GE_STATE_JOB_DONE,
+};
+
+enum {
+       GFIO_BUTTON_CONNECT = 0,
+       GFIO_BUTTON_SEND,
+       GFIO_BUTTON_START,
+       GFIO_BUTTON_NR,
+};
+
+/*
+ * Notebook entry
+ */
+struct gui_entry {
+       struct gui *ui;
+
+       GtkWidget *vbox;
+       GtkWidget *job_notebook;
+       GtkWidget *thread_status_pb;
+       GtkWidget *buttonbox;
+       GtkWidget *button[GFIO_BUTTON_NR];
+       GtkWidget *notebook;
+       GtkWidget *error_info_bar;
+       GtkWidget *error_label;
+       GtkWidget *results_window;
+       GtkWidget *results_notebook;
+       GtkUIManager *results_uimanager;
+       GtkWidget *results_menu;
+       GtkWidget *disk_util_vbox;
+       GtkListStore *log_model;
+       GtkWidget *log_tree;
+       GtkWidget *log_view;
+       struct gfio_graphs graphs;
+       struct probe_widget probe;
+       struct eta_widget eta;
+       GtkWidget *page_label;
+       gint page_num;
+       unsigned int state;
+
+       struct graph *clat_graph;
+       struct graph *lat_bucket_graph;
+
+       struct gfio_client *client;
+       char *job_file;
+       char *host;
+       int port;
+       int type;
+       int server_start;
+};
+
+struct end_results {
+       struct group_run_stats gs;
+       struct thread_stat ts;
+};
+
+struct gfio_client_options {
+       struct flist_head list;
+       struct thread_options o;
+};
+
+struct gfio_client {
+       struct gui_entry *ge;
+       struct fio_client *client;
+       GtkWidget *err_entry;
+       uint32_t client_cpus;
+       uint64_t client_flags;
+
+       struct flist_head o_list;
+       unsigned int o_list_nr;
+
+       struct end_results *results;
+       unsigned int nr_results;
+
+       uint32_t update_job_status;
+       volatile uint32_t update_job_done;
+
+       struct cmd_du_pdu *du;
+       unsigned int nr_du;
+};
+
+#define GFIO_MIME      "text/fio"
+
+extern void gfio_view_log(struct gui *ui);
+extern void gfio_set_state(struct gui_entry *ge, unsigned int state);
+extern void clear_ge_ui_info(struct gui_entry *ge);
+
+extern const char *gfio_graph_font;
+extern GdkColor gfio_color_white;
+extern GdkColor gfio_color_lightyellow;
+
+#endif
diff --git a/ghelpers.c b/ghelpers.c
new file mode 100644 (file)
index 0000000..7acf588
--- /dev/null
@@ -0,0 +1,201 @@
+#include <stdlib.h>
+#include <string.h>
+#include <gtk/gtk.h>
+
+#include "gcompat.h"
+#include "ghelpers.h"
+
+GtkWidget *new_combo_entry_in_frame(GtkWidget *box, const char *label)
+{
+       GtkWidget *entry, *frame;
+
+       frame = gtk_frame_new(label);
+       entry = gtk_combo_box_text_new();
+       gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), entry);
+
+       return entry;
+}
+
+GtkWidget *new_info_entry_in_frame(GtkWidget *box, const char *label)
+{
+       GtkWidget *entry, *frame;
+
+       frame = gtk_frame_new(label);
+       entry = gtk_entry_new();
+       gtk_editable_set_editable(GTK_EDITABLE(entry), 0);
+       gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), entry);
+
+       return entry;
+}
+
+static void fill_color_from_rgb(GdkColor *c, gfloat r, gfloat g, gfloat b)
+{
+       gint R, G, B;
+       gchar tmp[8];
+
+       memset(c, 0, sizeof(*c));
+       R = r * 255;
+       G = g * 255;
+       B = b * 255;
+       snprintf(tmp, sizeof(tmp), "#%02x%02x%02x", R, G, B);
+       gdk_color_parse(tmp, c);
+}
+
+GtkWidget *new_info_entry_in_frame_rgb(GtkWidget *box, const char *label,
+                                       gfloat r, gfloat g, gfloat b)
+{
+       GtkWidget *entry;
+       GdkColor c;
+
+       entry = new_info_entry_in_frame(box, label);
+       fill_color_from_rgb(&c, r, g, b);
+       gtk_widget_modify_text(entry, GTK_STATE_NORMAL, &c);
+       return entry;
+}
+
+GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label)
+{
+       GtkWidget *label_widget;
+       GtkWidget *frame;
+
+       frame = gtk_frame_new(label);
+       label_widget = gtk_label_new(NULL);
+       gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), label_widget);
+
+       return label_widget;
+}
+
+GtkWidget *create_spinbutton(GtkWidget *hbox, double min, double max, double defval)
+{
+       GtkWidget *button, *box;
+
+       box = gtk_hbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(hbox), box);
+
+       button = gtk_spin_button_new_with_range(min, max, 1.0);
+       gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0);
+
+       gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID);
+       gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), defval);
+
+       return button;
+}
+
+void label_set_int_value(GtkWidget *entry, unsigned int val)
+{
+       char tmp[80];
+
+       sprintf(tmp, "%u", val);
+       gtk_label_set_text(GTK_LABEL(entry), tmp);
+}
+
+void entry_set_int_value(GtkWidget *entry, unsigned int val)
+{
+       char tmp[80];
+
+       sprintf(tmp, "%u", val);
+       gtk_entry_set_text(GTK_ENTRY(entry), tmp);
+}
+
+GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, unsigned int flags)
+{
+       GtkCellRenderer *renderer;
+       GtkTreeViewColumn *col;
+       double xalign = 0.0; /* left as default */
+       PangoAlignment align;
+       gboolean visible;
+
+       align = (flags & ALIGN_LEFT) ? PANGO_ALIGN_LEFT :
+               (flags & ALIGN_RIGHT) ? PANGO_ALIGN_RIGHT :
+               PANGO_ALIGN_CENTER;
+       visible = !(flags & INVISIBLE);
+
+       renderer = gtk_cell_renderer_text_new();
+       col = gtk_tree_view_column_new();
+
+       gtk_tree_view_column_set_title(col, title);
+       if (!(flags & UNSORTABLE))
+               gtk_tree_view_column_set_sort_column_id(col, index);
+       gtk_tree_view_column_set_resizable(col, TRUE);
+       gtk_tree_view_column_pack_start(col, renderer, TRUE);
+       gtk_tree_view_column_set_expand(col, TRUE);
+       gtk_tree_view_column_add_attribute(col, renderer, "text", index);
+       g_object_set(G_OBJECT(renderer), "alignment", align, NULL);
+       switch (align) {
+       case PANGO_ALIGN_LEFT:
+               xalign = 0.0;
+               break;
+       case PANGO_ALIGN_CENTER:
+               xalign = 0.5;
+               break;
+       case PANGO_ALIGN_RIGHT:
+               xalign = 1.0;
+               break;
+       }
+       gtk_cell_renderer_set_alignment(GTK_CELL_RENDERER(renderer), xalign, 0.5);
+       gtk_tree_view_column_set_visible(col, visible);
+       gtk_tree_view_append_column(GTK_TREE_VIEW(tree_view), col);
+       return col;
+}
+
+void multitext_add_entry(struct multitext_widget *mt, const char *text)
+{
+       mt->text = realloc(mt->text, (mt->max_text + 1) * sizeof(char *));
+       mt->text[mt->max_text] = strdup(text);
+       mt->max_text++;
+}
+
+void multitext_set_entry(struct multitext_widget *mt, unsigned int index)
+{
+       if (index >= mt->max_text)
+               return;
+       if (!mt->text || !mt->text[index])
+               return;
+
+       mt->cur_text = index;
+       gtk_entry_set_text(GTK_ENTRY(mt->entry), mt->text[index]);
+}
+
+void multitext_update_entry(struct multitext_widget *mt, unsigned int index,
+                           const char *text)
+{
+       if (!mt->text)
+               return;
+
+       if (mt->text[index])
+               free(mt->text[index]);
+
+       mt->text[index] = strdup(text);
+       if (mt->cur_text == index)
+               gtk_entry_set_text(GTK_ENTRY(mt->entry), mt->text[index]);
+}
+
+void multitext_free(struct multitext_widget *mt)
+{
+       int i;
+
+       gtk_entry_set_text(GTK_ENTRY(mt->entry), "");
+
+       for (i = 0; i < mt->max_text; i++) {
+               if (mt->text[i])
+                       free(mt->text[i]);
+       }
+
+       free(mt->text);
+       mt->cur_text = -1;
+       mt->max_text = 0;
+}
+
+GtkWidget *get_scrolled_window(gint border_width)
+{
+       GtkWidget *scroll;
+
+       scroll = gtk_scrolled_window_new(NULL, NULL);
+       gtk_container_set_border_width(GTK_CONTAINER(scroll), border_width);
+       gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
+
+       return scroll;
+}
diff --git a/ghelpers.h b/ghelpers.h
new file mode 100644 (file)
index 0000000..39a994b
--- /dev/null
@@ -0,0 +1,35 @@
+#ifndef GFIO_HELPERS_H
+#define GFIO_HELPERS_H
+
+GtkWidget *new_combo_entry_in_frame(GtkWidget *box, const char *label);
+GtkWidget *new_info_entry_in_frame(GtkWidget *box, const char *label);
+GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label);
+GtkWidget *new_info_entry_in_frame_rgb(GtkWidget *box, const char *label,
+                                       gfloat r, gfloat g, gfloat b);
+GtkWidget *create_spinbutton(GtkWidget *hbox, double min, double max, double defval);
+void label_set_int_value(GtkWidget *entry, unsigned int val);
+void entry_set_int_value(GtkWidget *entry, unsigned int val);
+
+GtkWidget *get_scrolled_window(gint border_width);
+
+struct multitext_widget {
+       GtkWidget *entry;
+       char **text;
+       unsigned int cur_text;
+       unsigned int max_text;
+};
+
+void multitext_add_entry(struct multitext_widget *mt, const char *text);
+void multitext_set_entry(struct multitext_widget *mt, unsigned int index);
+void multitext_update_entry(struct multitext_widget *mt, unsigned int index,
+                           const char *text);
+void multitext_free(struct multitext_widget *mt);
+
+#define ALIGN_LEFT 1
+#define ALIGN_RIGHT 2
+#define INVISIBLE 4
+#define UNSORTABLE 8
+
+GtkTreeViewColumn *tree_view_column(GtkWidget *tree_view, int index, const char *title, unsigned int flags);
+
+#endif
diff --git a/goptions.c b/goptions.c
new file mode 100644 (file)
index 0000000..b78accd
--- /dev/null
@@ -0,0 +1,1618 @@
+#include <locale.h>
+#include <malloc.h>
+#include <string.h>
+
+#include <glib.h>
+#include <cairo.h>
+#include <gtk/gtk.h>
+
+#include "fio.h"
+#include "gfio.h"
+#include "ghelpers.h"
+#include "gerror.h"
+#include "parse.h"
+
+struct gopt {
+       GtkWidget *box;
+       unsigned int opt_index;
+       unsigned int opt_type;
+       gulong sig_handler;
+       struct gopt_job_view *gjv;
+       struct flist_head changed_list;
+};
+
+struct gopt_combo {
+       struct gopt gopt;
+       GtkWidget *combo;
+};
+
+struct gopt_int {
+       struct gopt gopt;
+       unsigned long long lastval;
+       GtkWidget *spin;
+};
+
+struct gopt_bool {
+       struct gopt gopt;
+       GtkWidget *check;
+};
+
+struct gopt_str {
+       struct gopt gopt;
+       GtkWidget *entry;
+};
+
+struct gopt_str_val {
+       struct gopt gopt;
+       GtkWidget *spin;
+       GtkWidget *combo;
+       unsigned int maxindex;
+};
+
+#define GOPT_RANGE_SPIN        4
+
+struct gopt_range {
+       struct gopt gopt;
+       GtkWidget *spins[GOPT_RANGE_SPIN];
+};
+
+struct gopt_str_multi {
+       struct gopt gopt;
+       GtkWidget *checks[PARSE_MAX_VP];
+};
+
+enum {
+       GOPT_COMBO_INT = 1,
+       GOPT_COMBO_STR,
+       GOPT_INT,
+       GOPT_BOOL,
+       GOPT_STR,
+       GOPT_STR_VAL,
+       GOPT_RANGE,
+       GOPT_STR_MULTI,
+};
+
+struct gopt_frame_widget {
+       GtkWidget *vbox[2];
+       unsigned int nr;
+};
+
+struct gopt_job_view {
+       struct gopt_frame_widget g_widgets[__FIO_OPT_G_NR];
+       GtkWidget *vboxes[__FIO_OPT_C_NR];
+       struct gopt *gopts[FIO_MAX_OPTS];
+       GtkWidget *dialog;
+       GtkWidget *job_combo;
+       struct gfio_client *client;
+       struct flist_head changed_list;
+       struct thread_options *o;
+       int in_job_switch;
+};
+
+static GNode *gopt_dep_tree;
+
+static GtkWidget *gopt_get_group_frame(struct gopt_job_view *gjv,
+                                      GtkWidget *box, unsigned int groupmask)
+{
+       unsigned int mask, group;
+       struct opt_group *og;
+       GtkWidget *frame, *hbox;
+       struct gopt_frame_widget *gfw;
+
+       if (!groupmask)
+               return 0;
+
+       mask = groupmask;
+       og = opt_group_cat_from_mask(&mask);
+       if (!og)
+               return NULL;
+
+       group = ffz(~groupmask);
+       gfw = &gjv->g_widgets[group];
+       if (!gfw->vbox[0]) {
+               frame = gtk_frame_new(og->name);
+               gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3);
+               hbox = gtk_hbox_new(FALSE, 0);
+               gtk_container_add(GTK_CONTAINER(frame), hbox);
+               gfw->vbox[0] = gtk_vbox_new(TRUE, 5);
+               gfw->vbox[1] = gtk_vbox_new(TRUE, 5);
+               gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[0], TRUE, TRUE, 5);
+               gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[1], TRUE, TRUE, 5);
+       }
+
+       hbox = gtk_hbox_new(FALSE, 3);
+       gtk_box_pack_start(GTK_BOX(gfw->vbox[gfw->nr++ & 1]), hbox, FALSE, FALSE, 5);
+       return hbox;
+}
+
+/*
+ * Mark children as invisible, if needed.
+ */
+static void gopt_set_children_visible(struct gopt_job_view *gjv,
+                                     struct fio_option *parent,
+                                     gboolean visible)
+{
+       GNode *child, *node;
+
+       if (parent->hide_on_set)
+               visible = !visible;
+
+       node = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
+       child = g_node_first_child(node);
+       while (child) {
+               struct fio_option *o = child->data;
+               struct gopt *g = o->gui_data;
+               GtkWidget *widget = g->box;
+
+               /*
+                * Recurse into child, if it also has children
+                */
+               if (g_node_n_children(child))
+                       gopt_set_children_visible(gjv, o, visible);
+
+               gtk_widget_set_sensitive(widget, visible);
+               child = g_node_next_sibling(child);
+       }
+}
+
+static void gopt_mark_index(struct gopt_job_view *gjv, struct gopt *gopt,
+                           unsigned int idx, int type)
+{
+       INIT_FLIST_HEAD(&gopt->changed_list);
+
+       assert(!gjv->gopts[idx]);
+       gopt->opt_index = idx;
+       gopt->opt_type = type;
+       gopt->gjv = gjv;
+       gjv->gopts[idx] = gopt;
+}
+
+static void gopt_dialog_update_apply_button(struct gopt_job_view *gjv)
+{
+       GtkDialog *dialog = GTK_DIALOG(gjv->dialog);
+       gboolean set;
+
+       set = !flist_empty(&gjv->changed_list);
+       gtk_dialog_set_response_sensitive(dialog, GTK_RESPONSE_APPLY, set);
+
+       if (set) {
+               gtk_widget_set_sensitive(gjv->job_combo, 0);
+               gtk_widget_set_tooltip_text(gjv->job_combo, "Apply option changes before switching to a new job");
+       } else {
+               gtk_widget_set_sensitive(gjv->job_combo, 1);
+               gtk_widget_set_tooltip_text(gjv->job_combo, "Change current job");
+       }
+}
+
+static void gopt_changed(struct gopt *gopt)
+{
+       struct gopt_job_view *gjv = gopt->gjv;
+
+       if (gjv->in_job_switch)
+               return;
+
+       /*
+        * Add to changed list. This also prevents the option from being
+        * freed when the widget is destroyed.
+        */
+       if (flist_empty(&gopt->changed_list)) {
+               flist_add_tail(&gopt->changed_list, &gjv->changed_list);
+               gopt_dialog_update_apply_button(gjv);
+       }
+}
+
+static void gopt_str_changed(GtkEntry *entry, gpointer data)
+{
+       struct gopt_str *s = (struct gopt_str *) data;
+       struct fio_option *o = &fio_options[s->gopt.opt_index];
+       const gchar *text;
+       int set;
+
+       gopt_changed(&s->gopt);
+
+       text = gtk_entry_get_text(GTK_ENTRY(s->entry));
+       set = strcmp(text, "") != 0;
+
+       gopt_set_children_visible(s->gopt.gjv, o, set);
+}
+
+static void gopt_str_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_str *s = (struct gopt_str *) data;
+
+       free(s);
+       gtk_widget_destroy(w);
+}
+
+static void gopt_str_store_set_val(struct gopt_str *s, const char *text)
+{
+       if (text)
+               gtk_entry_set_text(GTK_ENTRY(s->entry), text);
+}
+
+static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv,
+                                      struct fio_option *o, const char *text,
+                                      unsigned int idx)
+{
+       struct gopt_str *s;
+       GtkWidget *label;
+
+       s = calloc(1, sizeof(*s));
+
+       s->gopt.box = gtk_hbox_new(FALSE, 3);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
+
+       s->entry = gtk_entry_new();
+       gopt_mark_index(gjv, &s->gopt, idx, GOPT_STR);
+       gtk_editable_set_editable(GTK_EDITABLE(s->entry), 1);
+
+       if (text)
+               gopt_str_store_set_val(s, text);
+       else if (o->def)
+               gopt_str_store_set_val(s, o->def);
+
+       s->gopt.sig_handler = g_signal_connect(G_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
+       g_signal_connect(G_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s);
+
+       gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0);
+       return &s->gopt;
+}
+
+static void gopt_combo_changed(GtkComboBox *box, gpointer data)
+{
+       struct gopt_combo *c = (struct gopt_combo *) data;
+       struct fio_option *o = &fio_options[c->gopt.opt_index];
+       unsigned int index;
+
+       gopt_changed(&c->gopt);
+
+       index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
+
+       gopt_set_children_visible(c->gopt.gjv, o, index);
+}
+
+static void gopt_combo_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_combo *c = (struct gopt_combo *) data;
+
+       free(c);
+       gtk_widget_destroy(w);
+}
+
+static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv,
+                                          struct fio_option *o,
+                                          unsigned int idx, int type)
+{
+       struct gopt_combo *c;
+       GtkWidget *label;
+
+       c = calloc(1, sizeof(*c));
+
+       c->gopt.box = gtk_hbox_new(FALSE, 3);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
+
+       c->combo = gtk_combo_box_text_new();
+       gopt_mark_index(gjv, &c->gopt, idx, type);
+       g_signal_connect(G_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c);
+
+       gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0);
+
+       return c;
+}
+
+static void gopt_combo_str_set_val(struct gopt_combo *c, const char *text)
+{
+       struct fio_option *o = &fio_options[c->gopt.opt_index];
+       struct value_pair *vp;
+       int i;
+
+       i = 0;
+       vp = &o->posval[0];
+       while (vp->ival) {
+               if (!strcmp(vp->ival, text)) {
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), i);
+                       break;
+               }
+               vp++;
+               i++;
+       }
+}
+
+static struct gopt *gopt_new_combo_str(struct gopt_job_view *gjv,
+                                      struct fio_option *o, const char *text,
+                                      unsigned int idx)
+{
+       struct gopt_combo *c;
+       struct value_pair *vp;
+       int i, active = 0;
+
+       c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_STR);
+
+       i = 0;
+       vp = &o->posval[0];
+       while (vp->ival) {
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival);
+               if (o->def && !strcmp(vp->ival, o->def))
+                       active = i;
+               vp++;
+               i++;
+       }
+
+       gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
+       if (text)
+               gopt_combo_str_set_val(c, text);
+       c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
+       return &c->gopt;
+}
+
+static void gopt_combo_int_set_val(struct gopt_combo *c, unsigned int ip)
+{
+       struct fio_option *o = &fio_options[c->gopt.opt_index];
+       struct value_pair *vp;
+       int i;
+
+       i = 0;
+       vp = &o->posval[0];
+       while (vp->ival) {
+               if (vp->oval == ip) {
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), i);
+                       break;
+               }
+               vp++;
+               i++;
+       }
+}
+
+static struct gopt *gopt_new_combo_int(struct gopt_job_view *gjv,
+                                      struct fio_option *o, unsigned int *ip,
+                                      unsigned int idx)
+{
+       struct gopt_combo *c;
+       struct value_pair *vp;
+       int i, active = 0;
+
+       c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_INT);
+
+       i = 0;
+       vp = &o->posval[0];
+       while (vp->ival) {
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival);
+               if (ip && vp->oval == *ip)
+                       active = i;
+               vp++;
+               i++;
+       }
+
+       gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
+       if (ip)
+               gopt_combo_int_set_val(c, *ip);
+       c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
+       return &c->gopt;
+}
+
+static void gopt_str_multi_toggled(GtkToggleButton *button, gpointer data)
+{
+       struct gopt_str_multi *m = (struct gopt_str_multi *) data;
+
+       gopt_changed(&m->gopt);
+}
+
+static void gopt_str_multi_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_str_multi *m = (struct gopt_str_multi *) data;
+
+       free(m);
+       gtk_widget_destroy(w);
+}
+
+static void gopt_str_multi_set_val(struct gopt_str_multi *m, int val)
+{
+}
+
+static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv,
+                                      struct fio_option *o, unsigned int idx)
+{
+       struct gopt_str_multi *m;
+       struct value_pair *vp;
+       GtkWidget *frame, *hbox;
+       int i;
+
+       m = calloc(1, sizeof(*m));
+       m->gopt.box = gtk_hbox_new(FALSE, 3);
+       gopt_mark_index(gjv, &m->gopt, idx, GOPT_STR_MULTI);
+
+       if (!o->lname)
+               frame = gtk_frame_new(o->name);
+       else
+               frame = gtk_frame_new(o->lname);
+       gtk_box_pack_start(GTK_BOX(m->gopt.box), frame, FALSE, FALSE, 3);
+
+       hbox = gtk_hbox_new(FALSE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), hbox);
+
+       i = 0;
+       vp = &o->posval[0];
+       while (vp->ival) {
+               m->checks[i] = gtk_check_button_new_with_label(vp->ival);
+               gtk_widget_set_tooltip_text(m->checks[i], vp->help);
+               gtk_box_pack_start(GTK_BOX(hbox), m->checks[i], FALSE, FALSE, 3);
+               g_signal_connect(G_OBJECT(m->checks[i]), "toggled", G_CALLBACK(gopt_str_multi_toggled), m);
+               vp++;
+               i++;
+       }
+
+       gopt_str_multi_set_val(m, 0);
+       g_signal_connect(G_OBJECT(m->gopt.box), "destroy", G_CALLBACK(gopt_str_multi_destroy), m);
+       return &m->gopt;
+}
+
+static void gopt_int_changed(GtkSpinButton *spin, gpointer data)
+{
+       struct gopt_int *i = (struct gopt_int *) data;
+       struct fio_option *o = &fio_options[i->gopt.opt_index];
+       GtkAdjustment *adj;
+       int value, delta;
+
+       gopt_changed(&i->gopt);
+
+       adj = gtk_spin_button_get_adjustment(spin);
+       value = gtk_adjustment_get_value(adj);
+       delta = value - i->lastval;
+       i->lastval = value;
+
+       if (o->inv_opt) {
+               struct gopt *b_inv = o->inv_opt->gui_data;
+               struct gopt_int *i_inv = container_of(b_inv, struct gopt_int, gopt);
+               int cur_val;
+
+               assert(o->type == o->inv_opt->type);
+
+               cur_val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(i_inv->spin));
+               cur_val -= delta;
+               g_signal_handler_block(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler);
+               gtk_spin_button_set_value(GTK_SPIN_BUTTON(i_inv->spin), cur_val);
+               g_signal_handler_unblock(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler);
+       }
+}
+
+static void gopt_int_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_int *i = (struct gopt_int *) data;
+
+       free(i);
+       gtk_widget_destroy(w);
+}
+
+static void gopt_int_set_val(struct gopt_int *i, unsigned long long p)
+{
+       gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), p);
+       i->lastval = p;
+}
+
+static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv,
+                                      struct fio_option *o,
+                                      unsigned long long *p, unsigned int idx)
+{
+       unsigned long long defval;
+       struct gopt_int *i;
+       guint maxval, interval;
+       GtkWidget *label;
+
+       i = calloc(1, sizeof(*i));
+       i->gopt.box = gtk_hbox_new(FALSE, 3);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
+
+       maxval = o->maxval;
+       if (!maxval)
+               maxval = UINT_MAX;
+
+       defval = 0;
+       if (p)
+               defval = *p;
+       else if (o->def) {
+               long long val;
+
+               check_str_bytes(o->def, &val, o);
+               defval = val;
+       }
+
+       interval = 1.0;
+       if (o->interval)
+               interval = o->interval;
+
+       i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval);
+       gopt_mark_index(gjv, &i->gopt, idx, GOPT_INT);
+       gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(i->spin), GTK_UPDATE_IF_VALID);
+       if (p)
+               gopt_int_set_val(i, *p);
+       else
+               gopt_int_set_val(i, defval);
+       i->gopt.sig_handler = g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i);
+       g_signal_connect(G_OBJECT(i->spin), "destroy", G_CALLBACK(gopt_int_destroy), i);
+
+       gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
+
+       return i;
+}
+
+static struct gopt *gopt_new_int(struct gopt_job_view *gjv,
+                                struct fio_option *o, unsigned int *ip,
+                                unsigned int idx)
+{
+       unsigned long long ullp;
+       struct gopt_int *i;
+
+       if (ip) {
+               ullp = *ip;
+               i = __gopt_new_int(gjv, o, &ullp, idx);
+       } else
+               i = __gopt_new_int(gjv, o, NULL, idx);
+
+       return &i->gopt;
+}
+
+static struct gopt *gopt_new_ullong(struct gopt_job_view *gjv,
+                                   struct fio_option *o, unsigned long long *p,
+                                   unsigned int idx)
+{
+       struct gopt_int *i;
+
+       i = __gopt_new_int(gjv, o, p, idx);
+       return &i->gopt;
+}
+
+static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
+{
+       struct gopt_bool *b = (struct gopt_bool *) data;
+       struct fio_option *o = &fio_options[b->gopt.opt_index];
+       gboolean set;
+
+       gopt_changed(&b->gopt);
+
+       set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
+
+       if (o->inv_opt) {
+               struct gopt *g_inv = o->inv_opt->gui_data;
+               struct gopt_bool *b_inv = container_of(g_inv, struct gopt_bool, gopt);
+
+               assert(o->type == o->inv_opt->type);
+
+               g_signal_handler_block(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b_inv->check), !set);
+               g_signal_handler_unblock(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
+       }
+
+       gopt_set_children_visible(b->gopt.gjv, o, set);
+}
+
+static void gopt_bool_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_bool *b = (struct gopt_bool *) data;
+
+       free(b);
+       gtk_widget_destroy(w);
+}
+
+static void gopt_bool_set_val(struct gopt_bool *b, unsigned int val)
+{
+       gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), val);
+}
+
+static struct gopt *gopt_new_bool(struct gopt_job_view *gjv,
+                                 struct fio_option *o, unsigned int *val,
+                                 unsigned int idx)
+{
+       struct gopt_bool *b;
+       GtkWidget *label;
+       int defstate = 0;
+
+       b = calloc(1, sizeof(*b));
+       b->gopt.box = gtk_hbox_new(FALSE, 3);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
+
+       b->check = gtk_check_button_new();
+       gopt_mark_index(gjv, &b->gopt, idx, GOPT_BOOL);
+       if (o->def && !strcmp(o->def, "1"))
+               defstate = 1;
+
+       if (o->neg)
+               defstate = !defstate;
+
+       if (val)
+               gopt_bool_set_val(b, *val);
+       else
+               gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate);
+       b->gopt.sig_handler = g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b);
+       g_signal_connect(G_OBJECT(b->check), "destroy", G_CALLBACK(gopt_bool_destroy), b);
+
+       gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0);
+       return &b->gopt;
+}
+
+/*
+ * These are paired 0/1 and 2/3. 0/2 are min values, 1/3 are max values.
+ * If the max is made smaller than min, adjust min down.
+ * If the min is made larger than max, adjust the max.
+ */
+static void range_value_changed(GtkSpinButton *spin, gpointer data)
+{
+       struct gopt_range *r = (struct gopt_range *) data;
+       int changed = -1, i;
+       gint val, mval;
+
+       gopt_changed(&r->gopt);
+
+       for (i = 0; i < GOPT_RANGE_SPIN; i++) {
+               if (GTK_SPIN_BUTTON(r->spins[i]) == spin) {
+                       changed = i;
+                       break;
+               }
+       }
+
+       assert(changed != -1);
+
+       /*
+        * Min changed
+        */
+       if (changed == 0 || changed == 2) {
+               GtkWidget *mspin = r->spins[changed + 1];
+
+               val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
+               mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
+               if (val > mval)
+                       gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
+       } else {
+               GtkWidget *mspin = r->spins[changed - 1];
+
+               val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
+               mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
+               if (val < mval)
+                       gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
+       }
+}
+
+static void gopt_range_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_range *r = (struct gopt_range *) data;
+
+       free(r);
+       gtk_widget_destroy(w);
+}
+
+static void gopt_int_range_set_val(struct gopt_range *r, unsigned int *vals)
+{
+       int i;
+
+       for (i = 0; i < GOPT_RANGE_SPIN; i++)
+               gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), vals[i]);
+}
+
+static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv,
+                                      struct fio_option *o, unsigned int **ip,
+                                      unsigned int idx)
+{
+       struct gopt_range *r;
+       GtkWidget *label;
+       guint interval;
+       unsigned int defvals[GOPT_RANGE_SPIN];
+       gint maxval;
+       int i;
+
+       r = calloc(1, sizeof(*r));
+       r->gopt.box = gtk_hbox_new(FALSE, 3);
+       gopt_mark_index(gjv, &r->gopt, idx, GOPT_RANGE);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
+
+       maxval = o->maxval;
+       if (!maxval)
+               maxval = INT_MAX;
+
+       memset(defvals, 0, sizeof(defvals));
+       if (o->def) {
+               long long val;
+
+               check_str_bytes(o->def, &val, o);
+               for (i = 0; i < GOPT_RANGE_SPIN; i++)
+                       defvals[i] = val;
+       }
+
+       interval = 1.0;
+       if (o->interval)
+               interval = o->interval;
+
+       for (i = 0; i < GOPT_RANGE_SPIN; i++) {
+               r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval);
+               gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID);
+               gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0);
+       }
+
+       if (ip)
+               gopt_int_range_set_val(r, *ip);
+       else
+               gopt_int_range_set_val(r, defvals);
+
+       for (i = 0; i < GOPT_RANGE_SPIN; i++)
+               g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r);
+
+       gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0);
+       g_signal_connect(G_OBJECT(r->gopt.box), "destroy", G_CALLBACK(gopt_range_destroy), r);
+       return &r->gopt;
+}
+
+static void gopt_str_val_destroy(GtkWidget *w, gpointer data)
+{
+       struct gopt_str_val *g = (struct gopt_str_val *) data;
+
+       free(g);
+       gtk_widget_destroy(w);
+}
+
+static void gopt_str_val_spin_wrapped(GtkSpinButton *spin, gpointer data)
+{
+       struct gopt_str_val *g = (struct gopt_str_val *) data;
+       unsigned int val;
+       GtkAdjustment *adj;
+       gint index;
+
+       adj = gtk_spin_button_get_adjustment(spin);
+       val = gtk_adjustment_get_value(adj);
+
+       /*
+        * Can't rely on exact value, as fast changes increment >= 1
+        */
+       if (!val) {
+               index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
+               if (index + 1 <= g->maxindex) {
+                       val = 1;
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index);
+               } else
+                       val = 1023;
+               gtk_spin_button_set_value(spin, val);
+       } else {
+               index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
+               if (index) {
+                       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), --index);
+                       gtk_spin_button_set_value(spin, 1023);
+               } else
+                       gtk_spin_button_set_value(spin, 0);
+       }
+}
+
+static void gopt_str_val_changed(GtkSpinButton *spin, gpointer data)
+{
+       struct gopt_str_val *g = (struct gopt_str_val *) data;
+
+       gopt_changed(&g->gopt);
+}
+
+static void gopt_str_val_set_val(struct gopt_str_val *g, unsigned long long val)
+{
+       int i = 0;
+
+       do {
+               if (!val || (val % 1024))
+                       break;
+
+               i++;
+               val /= 1024;
+       } while (1);
+
+       gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), val);
+       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), i);
+}
+
+static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv,
+                                    struct fio_option *o,
+                                    unsigned long long *p, unsigned int idx)
+{
+       struct gopt_str_val *g;
+       const gchar *postfix[] = { "B", "KB", "MB", "GB", "PB", "TB", "" };
+       GtkWidget *label;
+       int i;
+
+       g = calloc(1, sizeof(*g));
+       g->gopt.box = gtk_hbox_new(FALSE, 3);
+       if (!o->lname)
+               label = gtk_label_new(o->name);
+       else
+               label = gtk_label_new(o->lname);
+       gopt_mark_index(gjv, &g->gopt, idx, GOPT_STR_VAL);
+
+       g->spin = gtk_spin_button_new_with_range(0.0, 1023.0, 1.0);
+       gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(g->spin), GTK_UPDATE_IF_VALID);
+       gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), 0);
+       gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(g->spin), 1);
+       gtk_box_pack_start(GTK_BOX(g->gopt.box), g->spin, FALSE, FALSE, 0);
+       g_signal_connect(G_OBJECT(g->spin), "wrapped", G_CALLBACK(gopt_str_val_spin_wrapped), g);
+       g_signal_connect(G_OBJECT(g->spin), "changed", G_CALLBACK(gopt_str_val_changed), g);
+
+       g->combo = gtk_combo_box_text_new();
+       i = 0;
+       while (strlen(postfix[i])) {
+               gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(g->combo), postfix[i]);
+               i++;
+       }
+       g->maxindex = i - 1;
+       gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), 0);
+       gtk_box_pack_start(GTK_BOX(g->gopt.box), g->combo, FALSE, FALSE, 0);
+       gtk_box_pack_start(GTK_BOX(g->gopt.box), label, FALSE, FALSE, 3);
+
+       if (p)
+               gopt_str_val_set_val(g, *p);
+
+       g_signal_connect(G_OBJECT(g->combo), "changed", G_CALLBACK(gopt_str_val_changed), g);
+
+       g_signal_connect(G_OBJECT(g->gopt.box), "destroy", G_CALLBACK(gopt_str_val_destroy), g);
+       return &g->gopt;
+}
+
+static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
+                           struct gopt *gopt, struct thread_options *to)
+{
+       switch (o->type) {
+       case FIO_OPT_STR_VAL: {
+               unsigned long long *ullp = NULL;
+               struct gopt_str_val *g;
+
+               if (o->off1)
+                       ullp = td_var(to, o->off1);
+
+               g = container_of(gopt, struct gopt_str_val, gopt);
+               if (ullp)
+                       gopt_str_val_set_val(g, *ullp);
+               break;
+               }
+       case FIO_OPT_STR_VAL_TIME: {
+               unsigned long long *ullp = NULL;
+               struct gopt_int *i;
+
+               if (o->off1)
+                       ullp = td_var(to, o->off1);
+
+               i = container_of(gopt, struct gopt_int, gopt);
+               if (ullp)
+                       gopt_int_set_val(i, *ullp);
+               break;
+               }
+       case FIO_OPT_INT: {
+               unsigned int *ip = NULL;
+               struct gopt_int *i;
+
+               if (o->off1)
+                       ip = td_var(to, o->off1);
+
+               i = container_of(gopt, struct gopt_int, gopt);
+               if (ip)
+                       gopt_int_set_val(i, *ip);
+               break;
+               }
+       case FIO_OPT_STR_SET:
+       case FIO_OPT_BOOL: {
+               unsigned int *ip = NULL;
+               struct gopt_bool *b;
+
+               if (o->off1)
+                       ip = td_var(to, o->off1);
+
+               b = container_of(gopt, struct gopt_bool, gopt);
+               if (ip)
+                       gopt_bool_set_val(b, *ip);
+               break;
+               }
+       case FIO_OPT_STR: {
+               if (o->posval[0].ival) {
+                       unsigned int *ip = NULL;
+                       struct gopt_combo *c;
+
+                       if (o->off1)
+                               ip = td_var(to, o->off1);
+
+                       c = container_of(gopt, struct gopt_combo, gopt);
+                       if (ip)
+                               gopt_combo_int_set_val(c, *ip);
+               } else {
+                       struct gopt_str *s;
+                       char *text = NULL;
+
+                       if (o->off1) {
+                               char **p = td_var(to, o->off1);
+
+                               text = *p;
+                       }
+
+                       s = container_of(gopt, struct gopt_str, gopt);
+                       gopt_str_store_set_val(s, text);
+               }
+
+               break;
+               }
+       case FIO_OPT_STR_STORE: {
+               struct gopt_combo *c;
+               char *text = NULL;
+
+               if (o->off1) {
+                       char **p = td_var(to, o->off1);
+                       text = *p;
+               }
+
+               if (!o->posval[0].ival) {
+                       struct gopt_str *s;
+
+                       s = container_of(gopt, struct gopt_str, gopt);
+                       gopt_str_store_set_val(s, text);
+                       break;
+               }
+
+