gfio: start of splitting up the source a bit
authorJens Axboe <axboe@kernel.dk>
Thu, 15 Mar 2012 18:38:01 +0000 (19:38 +0100)
committerJens Axboe <axboe@kernel.dk>
Thu, 15 Mar 2012 18:38:01 +0000 (19:38 +0100)
Signed-off-by: Jens Axboe <axboe@kernel.dk>
Makefile
gfio.c
gfio.h [new file with mode: 0644]
ghelpers.c [new file with mode: 0644]
ghelpers.h [new file with mode: 0644]

index 4a9e718..a114a2e 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -69,7 +69,7 @@ endif
 
 OBJS = $(SOURCE:.c=.o)
 FIO_OBJS = $(OBJS) fio.o
-GFIO_OBJS = $(OBJS) gfio.o graph.o tickmarks.o
+GFIO_OBJS = $(OBJS) gfio.o graph.o tickmarks.o ghelpers.o
 
 T_SMALLOC_OBJS = t/stest.o
 T_SMALLOC_OBJS += mutex.o smalloc.o t/log.o
@@ -104,10 +104,13 @@ all: .depend $(PROGS) $(SCRIPTS)
 .c.o: .depend
        $(QUIET_CC)$(CC) -o $@ -c $(CFLAGS) $(CPPFLAGS) $<
 
-gfio.o: gfio.c
+ghelpers.o: ghelpers.c ghelpers.h
+       $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c ghelpers.c
+
+gfio.o: gfio.c ghelpers.c
        $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c gfio.c
 
-graph.o:       graph.c graph.h
+graph.o: graph.c graph.h
        $(QUIET_CC)$(CC) $(CFLAGS) $(GTK_CFLAGS) $(CPPFLAGS) -c graph.c
 
 t/stest: $(T_SMALLOC_OBJS)
diff --git a/gfio.c b/gfio.c
index 14ec1d5..9998077 100644 (file)
--- a/gfio.c
+++ b/gfio.c
 #include <gtk/gtk.h>
 
 #include "fio.h"
+#include "gfio.h"
+#include "ghelpers.h"
 #include "graph.h"
 
-#define GFIO_MIME      "text/fio"
-
 static int gfio_server_running;
 static const char *gfio_graph_font;
 static unsigned int gfio_graph_limit = 100;
@@ -41,8 +41,6 @@ static GdkColor white;
 
 static void view_log(GtkWidget *w, gpointer data);
 
-#define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
-
 typedef void (*clickfunction)(GtkWidget *widget, gpointer data);
 
 static void connect_clicked(GtkWidget *widget, gpointer data);
@@ -55,148 +53,24 @@ static struct button_spec {
        const char *tooltiptext[2];
        const int start_sensitive;
 } buttonspeclist[] = {
-#define CONNECT_BUTTON 0
-#define SEND_BUTTON 1
-#define START_JOB_BUTTON 2
-       { "Connect", connect_clicked, { "Disconnect from host", "Connect to host" }, 1 },
-       { "Send", send_clicked, { "Send job description to host", NULL }, 0 },
-       { "Start Job", start_job_clicked,
-               { "Start the current job on the server", NULL }, 0 },
-};
-
-struct probe_widget {
-       GtkWidget *hostname;
-       GtkWidget *os;
-       GtkWidget *arch;
-       GtkWidget *fio_ver;
-};
-
-struct multitext_widget {
-       GtkWidget *entry;
-       char **text;
-       unsigned int cur_text;
-       unsigned int max_text;
-};
-
-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;
-};
-
-struct gfio_graphs {
-#define DRAWING_AREA_XDIM 1000
-#define DRAWING_AREA_YDIM 400
-       GtkWidget *drawing_area;
-       struct graph *iops_graph;
-       struct graph *bandwidth_graph;
-};
-
-/*
- * 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;
-
-       struct flist_head list;
-} 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,
-};
-
-/*
- * Notebook entry
- */
-struct gui_entry {
-       struct flist_head list;
-       struct gui *ui;
-
-       GtkWidget *vbox;
-       GtkWidget *job_notebook;
-       GtkWidget *thread_status_pb;
-       GtkWidget *buttonbox;
-       GtkWidget *button[ARRAYSIZE(buttonspeclist)];
-       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;
-       int nr_job_files;
-       char **job_files;
-};
-
-struct end_results {
-       struct group_run_stats gs;
-       struct thread_stat ts;
-};
-
-struct gfio_client {
-       struct gui_entry *ge;
-       struct fio_client *client;
-       GtkWidget *err_entry;
-       struct thread_options o;
-
-       struct end_results *results;
-       unsigned int nr_results;
-
-       struct cmd_du_pdu *du;
-       unsigned int nr_du;
+       {
+         .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 gfio_update_thread_status(struct gui_entry *ge, char *status_message, double perc);
@@ -312,76 +186,6 @@ static void clear_ge_ui_info(struct gui_entry *ge)
        gtk_entry_set_text(GTK_ENTRY(ge->eta.write_iops), "");
 }
 
-static GtkWidget *new_combo_entry_in_frame(GtkWidget *box, const char *label)
-{
-       GtkWidget *entry, *frame;
-
-       frame = gtk_frame_new(label);
-       entry = gtk_combo_box_new_text();
-       gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
-       gtk_container_add(GTK_CONTAINER(frame), entry);
-
-       return entry;
-}
-
-static GtkWidget *new_info_entry_in_frame(GtkWidget *box, const char *label)
-{
-       GtkWidget *entry, *frame;
-
-       frame = gtk_frame_new(label);
-       entry = gtk_entry_new();
-       gtk_entry_set_editable(GTK_ENTRY(entry), 0);
-       gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
-       gtk_container_add(GTK_CONTAINER(frame), entry);
-
-       return entry;
-}
-
-static 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;
-}
-
-static 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;
-}
-
-static 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);
-}
-
-static 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);
-}
-
 static void show_info_dialog(struct gui *ui, const char *title,
                             const char *message)
 {
@@ -529,11 +333,11 @@ static void update_button_states(struct gui *ui, struct gui_entry *ge)
                break;
        }
 
-       gtk_widget_set_sensitive(ge->button[CONNECT_BUTTON], connect_state);
-       gtk_widget_set_sensitive(ge->button[SEND_BUTTON], send_state);
-       gtk_widget_set_sensitive(ge->button[START_JOB_BUTTON], start_state);
-       gtk_button_set_label(GTK_BUTTON(ge->button[CONNECT_BUTTON]), connect_str);
-       gtk_widget_set_tooltip_text(ge->button[CONNECT_BUTTON], get_button_tooltip(&buttonspeclist[CONNECT_BUTTON], connect_state));
+       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);
@@ -2173,7 +1977,7 @@ static void send_clicked(GtkWidget *widget, gpointer data)
                report_error(error);
                g_error_free(error);
 
-               gtk_widget_set_sensitive(ge->button[START_JOB_BUTTON], 1);
+               gtk_widget_set_sensitive(ge->button[GFIO_BUTTON_START], 1);
        }
 }
 
diff --git a/gfio.h b/gfio.h
new file mode 100644 (file)
index 0000000..3b57204
--- /dev/null
+++ b/gfio.h
@@ -0,0 +1,152 @@
+#ifndef GFIO_H
+#define GFIO_H
+
+#include <gtk/gtk.h>
+
+struct probe_widget {
+       GtkWidget *hostname;
+       GtkWidget *os;
+       GtkWidget *arch;
+       GtkWidget *fio_ver;
+};
+
+struct multitext_widget {
+       GtkWidget *entry;
+       char **text;
+       unsigned int cur_text;
+       unsigned int max_text;
+};
+
+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;
+};
+
+struct gfio_graphs {
+#define DRAWING_AREA_XDIM 1000
+#define DRAWING_AREA_YDIM 400
+       GtkWidget *drawing_area;
+       struct graph *iops_graph;
+       struct graph *bandwidth_graph;
+};
+
+/*
+ * 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;
+
+       struct flist_head list;
+} 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 flist_head list;
+       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;
+       int nr_job_files;
+       char **job_files;
+};
+
+struct end_results {
+       struct group_run_stats gs;
+       struct thread_stat ts;
+};
+
+struct gfio_client {
+       struct gui_entry *ge;
+       struct fio_client *client;
+       GtkWidget *err_entry;
+       struct thread_options o;
+
+       struct end_results *results;
+       unsigned int nr_results;
+
+       struct cmd_du_pdu *du;
+       unsigned int nr_du;
+};
+
+#define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0])))
+
+#define GFIO_MIME      "text/fio"
+
+#endif
diff --git a/ghelpers.c b/ghelpers.c
new file mode 100644 (file)
index 0000000..d49af10
--- /dev/null
@@ -0,0 +1,71 @@
+#include <gtk/gtk.h>
+
+GtkWidget *new_combo_entry_in_frame(GtkWidget *box, const char *label)
+{
+       GtkWidget *entry, *frame;
+
+       frame = gtk_frame_new(label);
+       entry = gtk_combo_box_new_text();
+       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_entry_set_editable(GTK_ENTRY(entry), 0);
+       gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3);
+       gtk_container_add(GTK_CONTAINER(frame), entry);
+
+       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);
+}
diff --git a/ghelpers.h b/ghelpers.h
new file mode 100644 (file)
index 0000000..c98b612
--- /dev/null
@@ -0,0 +1,11 @@
+#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 *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);
+
+#endif