17 unsigned int opt_index;
18 unsigned int opt_type;
20 struct gopt_job_view *gjv;
21 struct flist_head changed_list;
31 unsigned long long lastval;
49 unsigned int maxindex;
52 #define GOPT_RANGE_SPIN 4
56 GtkWidget *spins[GOPT_RANGE_SPIN];
59 struct gopt_str_multi {
61 GtkWidget *checks[PARSE_MAX_VP];
75 struct gopt_frame_widget {
80 struct gopt_job_view {
81 struct gopt_frame_widget g_widgets[__FIO_OPT_G_NR];
82 GtkWidget *vboxes[__FIO_OPT_C_NR];
83 struct gopt *gopts[FIO_MAX_OPTS];
86 struct gfio_client *client;
87 struct flist_head changed_list;
88 struct thread_options *o;
92 static GNode *gopt_dep_tree;
94 static GtkWidget *gopt_get_group_frame(struct gopt_job_view *gjv,
95 GtkWidget *box, unsigned int groupmask)
97 unsigned int mask, group;
99 GtkWidget *frame, *hbox;
100 struct gopt_frame_widget *gfw;
106 og = opt_group_cat_from_mask(&mask);
110 group = ffz(~groupmask);
111 gfw = &gjv->g_widgets[group];
113 frame = gtk_frame_new(og->name);
114 gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 3);
115 hbox = gtk_hbox_new(FALSE, 0);
116 gtk_container_add(GTK_CONTAINER(frame), hbox);
117 gfw->vbox[0] = gtk_vbox_new(TRUE, 5);
118 gfw->vbox[1] = gtk_vbox_new(TRUE, 5);
119 gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[0], TRUE, TRUE, 5);
120 gtk_box_pack_start(GTK_BOX(hbox), gfw->vbox[1], TRUE, TRUE, 5);
123 hbox = gtk_hbox_new(FALSE, 3);
124 gtk_box_pack_start(GTK_BOX(gfw->vbox[gfw->nr++ & 1]), hbox, FALSE, FALSE, 5);
129 * Mark children as invisible, if needed.
131 static void gopt_set_children_visible(struct gopt_job_view *gjv,
132 struct fio_option *parent,
137 if (parent->hide_on_set)
140 node = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
141 child = g_node_first_child(node);
143 struct fio_option *o = child->data;
144 struct gopt *g = o->gui_data;
145 GtkWidget *widget = g->box;
148 * Recurse into child, if it also has children
150 if (g_node_n_children(child))
151 gopt_set_children_visible(gjv, o, visible);
153 gtk_widget_set_sensitive(widget, visible);
154 child = g_node_next_sibling(child);
158 static void gopt_mark_index(struct gopt_job_view *gjv, struct gopt *gopt,
159 unsigned int idx, int type)
161 INIT_FLIST_HEAD(&gopt->changed_list);
163 assert(!gjv->gopts[idx]);
164 gopt->opt_index = idx;
165 gopt->opt_type = type;
167 gjv->gopts[idx] = gopt;
170 static void gopt_dialog_update_apply_button(struct gopt_job_view *gjv)
172 GtkDialog *dialog = GTK_DIALOG(gjv->dialog);
175 set = !flist_empty(&gjv->changed_list);
176 gtk_dialog_set_response_sensitive(dialog, GTK_RESPONSE_APPLY, set);
179 gtk_widget_set_sensitive(gjv->job_combo, 0);
180 gtk_widget_set_tooltip_text(gjv->job_combo, "Apply option changes before switching to a new job");
182 gtk_widget_set_sensitive(gjv->job_combo, 1);
183 gtk_widget_set_tooltip_text(gjv->job_combo, "Change current job");
187 static void gopt_changed(struct gopt *gopt)
189 struct gopt_job_view *gjv = gopt->gjv;
191 if (gjv->in_job_switch)
195 * Add to changed list. This also prevents the option from being
196 * freed when the widget is destroyed.
198 if (flist_empty(&gopt->changed_list)) {
199 flist_add_tail(&gopt->changed_list, &gjv->changed_list);
200 gopt_dialog_update_apply_button(gjv);
204 static void gopt_str_changed(GtkEntry *entry, gpointer data)
206 struct gopt_str *s = (struct gopt_str *) data;
207 struct fio_option *o = &fio_options[s->gopt.opt_index];
211 gopt_changed(&s->gopt);
213 text = gtk_entry_get_text(GTK_ENTRY(s->entry));
214 set = strcmp(text, "") != 0;
216 gopt_set_children_visible(s->gopt.gjv, o, set);
219 static void gopt_str_destroy(GtkWidget *w, gpointer data)
221 struct gopt_str *s = (struct gopt_str *) data;
224 gtk_widget_destroy(w);
227 static void gopt_str_store_set_val(struct gopt_str *s, const char *text)
230 gtk_entry_set_text(GTK_ENTRY(s->entry), text);
233 static struct gopt *gopt_new_str_store(struct gopt_job_view *gjv,
234 struct fio_option *o, const char *text,
240 s = calloc(1, sizeof(*s));
242 s->gopt.box = gtk_hbox_new(FALSE, 3);
244 label = gtk_label_new(o->name);
246 label = gtk_label_new(o->lname);
248 s->entry = gtk_entry_new();
249 gopt_mark_index(gjv, &s->gopt, idx, GOPT_STR);
250 gtk_editable_set_editable(GTK_EDITABLE(s->entry), 1);
253 gopt_str_store_set_val(s, text);
255 gopt_str_store_set_val(s, o->def);
257 s->gopt.sig_handler = g_signal_connect(G_OBJECT(s->entry), "changed", G_CALLBACK(gopt_str_changed), s);
258 g_signal_connect(G_OBJECT(s->entry), "destroy", G_CALLBACK(gopt_str_destroy), s);
260 gtk_box_pack_start(GTK_BOX(s->gopt.box), s->entry, FALSE, FALSE, 0);
261 gtk_box_pack_start(GTK_BOX(s->gopt.box), label, FALSE, FALSE, 0);
265 static void gopt_combo_changed(GtkComboBox *box, gpointer data)
267 struct gopt_combo *c = (struct gopt_combo *) data;
268 struct fio_option *o = &fio_options[c->gopt.opt_index];
271 gopt_changed(&c->gopt);
273 index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
275 gopt_set_children_visible(c->gopt.gjv, o, index);
278 static void gopt_combo_destroy(GtkWidget *w, gpointer data)
280 struct gopt_combo *c = (struct gopt_combo *) data;
283 gtk_widget_destroy(w);
286 static struct gopt_combo *__gopt_new_combo(struct gopt_job_view *gjv,
287 struct fio_option *o,
288 unsigned int idx, int type)
290 struct gopt_combo *c;
293 c = calloc(1, sizeof(*c));
295 c->gopt.box = gtk_hbox_new(FALSE, 3);
297 label = gtk_label_new(o->name);
299 label = gtk_label_new(o->lname);
301 c->combo = gtk_combo_box_text_new();
302 gopt_mark_index(gjv, &c->gopt, idx, type);
303 g_signal_connect(G_OBJECT(c->combo), "destroy", G_CALLBACK(gopt_combo_destroy), c);
305 gtk_box_pack_start(GTK_BOX(c->gopt.box), c->combo, FALSE, FALSE, 0);
306 gtk_box_pack_start(GTK_BOX(c->gopt.box), label, FALSE, FALSE, 0);
311 static void gopt_combo_str_set_val(struct gopt_combo *c, const char *text)
313 struct fio_option *o = &fio_options[c->gopt.opt_index];
314 struct value_pair *vp;
320 if (!strcmp(vp->ival, text)) {
321 gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), i);
329 static struct gopt *gopt_new_combo_str(struct gopt_job_view *gjv,
330 struct fio_option *o, const char *text,
333 struct gopt_combo *c;
334 struct value_pair *vp;
337 c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_STR);
342 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival);
343 if (o->def && !strcmp(vp->ival, o->def))
349 gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
351 gopt_combo_str_set_val(c, text);
352 c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
356 static void gopt_combo_int_set_val(struct gopt_combo *c, unsigned int ip)
358 struct fio_option *o = &fio_options[c->gopt.opt_index];
359 struct value_pair *vp;
365 if (vp->oval == ip) {
366 gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), i);
374 static struct gopt *gopt_new_combo_int(struct gopt_job_view *gjv,
375 struct fio_option *o, unsigned int *ip,
378 struct gopt_combo *c;
379 struct value_pair *vp;
382 c = __gopt_new_combo(gjv, o, idx, GOPT_COMBO_INT);
387 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(c->combo), vp->ival);
388 if (ip && vp->oval == *ip)
394 gtk_combo_box_set_active(GTK_COMBO_BOX(c->combo), active);
396 gopt_combo_int_set_val(c, *ip);
397 c->gopt.sig_handler = g_signal_connect(G_OBJECT(c->combo), "changed", G_CALLBACK(gopt_combo_changed), c);
401 static void gopt_str_multi_toggled(GtkToggleButton *button, gpointer data)
403 struct gopt_str_multi *m = (struct gopt_str_multi *) data;
405 gopt_changed(&m->gopt);
408 static void gopt_str_multi_destroy(GtkWidget *w, gpointer data)
410 struct gopt_str_multi *m = (struct gopt_str_multi *) data;
413 gtk_widget_destroy(w);
416 static void gopt_str_multi_set_val(struct gopt_str_multi *m, int val)
420 static struct gopt *gopt_new_str_multi(struct gopt_job_view *gjv,
421 struct fio_option *o, unsigned int idx)
423 struct gopt_str_multi *m;
424 struct value_pair *vp;
425 GtkWidget *frame, *hbox;
428 m = calloc(1, sizeof(*m));
429 m->gopt.box = gtk_hbox_new(FALSE, 3);
430 gopt_mark_index(gjv, &m->gopt, idx, GOPT_STR_MULTI);
433 frame = gtk_frame_new(o->name);
435 frame = gtk_frame_new(o->lname);
436 gtk_box_pack_start(GTK_BOX(m->gopt.box), frame, FALSE, FALSE, 3);
438 hbox = gtk_hbox_new(FALSE, 3);
439 gtk_container_add(GTK_CONTAINER(frame), hbox);
444 m->checks[i] = gtk_check_button_new_with_label(vp->ival);
445 gtk_widget_set_tooltip_text(m->checks[i], vp->help);
446 gtk_box_pack_start(GTK_BOX(hbox), m->checks[i], FALSE, FALSE, 3);
447 g_signal_connect(G_OBJECT(m->checks[i]), "toggled", G_CALLBACK(gopt_str_multi_toggled), m);
452 gopt_str_multi_set_val(m, 0);
453 g_signal_connect(G_OBJECT(m->gopt.box), "destroy", G_CALLBACK(gopt_str_multi_destroy), m);
457 static void gopt_int_changed(GtkSpinButton *spin, gpointer data)
459 struct gopt_int *i = (struct gopt_int *) data;
460 struct fio_option *o = &fio_options[i->gopt.opt_index];
464 gopt_changed(&i->gopt);
466 adj = gtk_spin_button_get_adjustment(spin);
467 value = gtk_adjustment_get_value(adj);
468 delta = value - i->lastval;
472 struct gopt *b_inv = o->inv_opt->gui_data;
473 struct gopt_int *i_inv = container_of(b_inv, struct gopt_int, gopt);
476 assert(o->type == o->inv_opt->type);
478 cur_val = gtk_spin_button_get_value(GTK_SPIN_BUTTON(i_inv->spin));
480 g_signal_handler_block(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler);
481 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i_inv->spin), cur_val);
482 g_signal_handler_unblock(G_OBJECT(i_inv->spin), i_inv->gopt.sig_handler);
486 static void gopt_int_destroy(GtkWidget *w, gpointer data)
488 struct gopt_int *i = (struct gopt_int *) data;
491 gtk_widget_destroy(w);
494 static void gopt_int_set_val(struct gopt_int *i, unsigned long long p)
496 gtk_spin_button_set_value(GTK_SPIN_BUTTON(i->spin), p);
500 static struct gopt_int *__gopt_new_int(struct gopt_job_view *gjv,
501 struct fio_option *o,
502 unsigned long long *p, unsigned int idx)
504 unsigned long long defval;
506 guint maxval, interval;
509 i = calloc(1, sizeof(*i));
510 i->gopt.box = gtk_hbox_new(FALSE, 3);
512 label = gtk_label_new(o->name);
514 label = gtk_label_new(o->lname);
526 check_str_bytes(o->def, &val, o);
532 interval = o->interval;
534 i->spin = gtk_spin_button_new_with_range(o->minval, maxval, interval);
535 gopt_mark_index(gjv, &i->gopt, idx, GOPT_INT);
536 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(i->spin), GTK_UPDATE_IF_VALID);
538 gopt_int_set_val(i, *p);
540 gopt_int_set_val(i, defval);
541 i->gopt.sig_handler = g_signal_connect(G_OBJECT(i->spin), "value-changed", G_CALLBACK(gopt_int_changed), i);
542 g_signal_connect(G_OBJECT(i->spin), "destroy", G_CALLBACK(gopt_int_destroy), i);
544 gtk_box_pack_start(GTK_BOX(i->gopt.box), i->spin, FALSE, FALSE, 0);
545 gtk_box_pack_start(GTK_BOX(i->gopt.box), label, FALSE, FALSE, 0);
550 static struct gopt *gopt_new_int(struct gopt_job_view *gjv,
551 struct fio_option *o, unsigned int *ip,
554 unsigned long long ullp;
559 i = __gopt_new_int(gjv, o, &ullp, idx);
561 i = __gopt_new_int(gjv, o, NULL, idx);
566 static struct gopt *gopt_new_ullong(struct gopt_job_view *gjv,
567 struct fio_option *o, unsigned long long *p,
572 i = __gopt_new_int(gjv, o, p, idx);
576 static void gopt_bool_toggled(GtkToggleButton *button, gpointer data)
578 struct gopt_bool *b = (struct gopt_bool *) data;
579 struct fio_option *o = &fio_options[b->gopt.opt_index];
582 gopt_changed(&b->gopt);
584 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
587 struct gopt *g_inv = o->inv_opt->gui_data;
588 struct gopt_bool *b_inv = container_of(g_inv, struct gopt_bool, gopt);
590 assert(o->type == o->inv_opt->type);
592 g_signal_handler_block(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
593 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b_inv->check), !set);
594 g_signal_handler_unblock(G_OBJECT(b_inv->check), b_inv->gopt.sig_handler);
597 gopt_set_children_visible(b->gopt.gjv, o, set);
600 static void gopt_bool_destroy(GtkWidget *w, gpointer data)
602 struct gopt_bool *b = (struct gopt_bool *) data;
605 gtk_widget_destroy(w);
608 static void gopt_bool_set_val(struct gopt_bool *b, unsigned int val)
610 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), val);
613 static struct gopt *gopt_new_bool(struct gopt_job_view *gjv,
614 struct fio_option *o, unsigned int *val,
621 b = calloc(1, sizeof(*b));
622 b->gopt.box = gtk_hbox_new(FALSE, 3);
624 label = gtk_label_new(o->name);
626 label = gtk_label_new(o->lname);
628 b->check = gtk_check_button_new();
629 gopt_mark_index(gjv, &b->gopt, idx, GOPT_BOOL);
630 if (o->def && !strcmp(o->def, "1"))
634 defstate = !defstate;
637 gopt_bool_set_val(b, *val);
639 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(b->check), defstate);
640 b->gopt.sig_handler = g_signal_connect(G_OBJECT(b->check), "toggled", G_CALLBACK(gopt_bool_toggled), b);
641 g_signal_connect(G_OBJECT(b->check), "destroy", G_CALLBACK(gopt_bool_destroy), b);
643 gtk_box_pack_start(GTK_BOX(b->gopt.box), b->check, FALSE, FALSE, 0);
644 gtk_box_pack_start(GTK_BOX(b->gopt.box), label, FALSE, FALSE, 0);
649 * These are paired 0/1 and 2/3. 0/2 are min values, 1/3 are max values.
650 * If the max is made smaller than min, adjust min down.
651 * If the min is made larger than max, adjust the max.
653 static void range_value_changed(GtkSpinButton *spin, gpointer data)
655 struct gopt_range *r = (struct gopt_range *) data;
659 gopt_changed(&r->gopt);
661 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
662 if (GTK_SPIN_BUTTON(r->spins[i]) == spin) {
668 assert(changed != -1);
673 if (changed == 0 || changed == 2) {
674 GtkWidget *mspin = r->spins[changed + 1];
676 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
677 mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
679 gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
681 GtkWidget *mspin = r->spins[changed - 1];
683 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[changed]));
684 mval = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(mspin));
686 gtk_spin_button_set_value(GTK_SPIN_BUTTON(mspin), val);
690 static void gopt_range_destroy(GtkWidget *w, gpointer data)
692 struct gopt_range *r = (struct gopt_range *) data;
695 gtk_widget_destroy(w);
698 static void gopt_int_range_set_val(struct gopt_range *r, unsigned int *vals)
702 for (i = 0; i < GOPT_RANGE_SPIN; i++)
703 gtk_spin_button_set_value(GTK_SPIN_BUTTON(r->spins[i]), vals[i]);
706 static struct gopt *gopt_new_int_range(struct gopt_job_view *gjv,
707 struct fio_option *o, unsigned int **ip,
710 struct gopt_range *r;
713 unsigned int defvals[GOPT_RANGE_SPIN];
717 r = calloc(1, sizeof(*r));
718 r->gopt.box = gtk_hbox_new(FALSE, 3);
719 gopt_mark_index(gjv, &r->gopt, idx, GOPT_RANGE);
721 label = gtk_label_new(o->name);
723 label = gtk_label_new(o->lname);
729 memset(defvals, 0, sizeof(defvals));
733 check_str_bytes(o->def, &val, o);
734 for (i = 0; i < GOPT_RANGE_SPIN; i++)
740 interval = o->interval;
742 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
743 r->spins[i] = gtk_spin_button_new_with_range(o->minval, maxval, interval);
744 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(r->spins[i]), GTK_UPDATE_IF_VALID);
745 gtk_box_pack_start(GTK_BOX(r->gopt.box), r->spins[i], FALSE, FALSE, 0);
749 gopt_int_range_set_val(r, *ip);
751 gopt_int_range_set_val(r, defvals);
753 for (i = 0; i < GOPT_RANGE_SPIN; i++)
754 g_signal_connect(G_OBJECT(r->spins[i]), "value-changed", G_CALLBACK(range_value_changed), r);
756 gtk_box_pack_start(GTK_BOX(r->gopt.box), label, FALSE, FALSE, 0);
757 g_signal_connect(G_OBJECT(r->gopt.box), "destroy", G_CALLBACK(gopt_range_destroy), r);
761 static void gopt_str_val_destroy(GtkWidget *w, gpointer data)
763 struct gopt_str_val *g = (struct gopt_str_val *) data;
766 gtk_widget_destroy(w);
769 static void gopt_str_val_spin_wrapped(GtkSpinButton *spin, gpointer data)
771 struct gopt_str_val *g = (struct gopt_str_val *) data;
776 adj = gtk_spin_button_get_adjustment(spin);
777 val = gtk_adjustment_get_value(adj);
780 * Can't rely on exact value, as fast changes increment >= 1
783 index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
784 if (index + 1 <= g->maxindex) {
786 gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), ++index);
789 gtk_spin_button_set_value(spin, val);
791 index = gtk_combo_box_get_active(GTK_COMBO_BOX(g->combo));
793 gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), --index);
794 gtk_spin_button_set_value(spin, 1023);
796 gtk_spin_button_set_value(spin, 0);
800 static void gopt_str_val_changed(GtkSpinButton *spin, gpointer data)
802 struct gopt_str_val *g = (struct gopt_str_val *) data;
804 gopt_changed(&g->gopt);
807 static void gopt_str_val_set_val(struct gopt_str_val *g, unsigned long long val)
812 if (!val || (val % 1024))
819 gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), val);
820 gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), i);
823 static struct gopt *gopt_new_str_val(struct gopt_job_view *gjv,
824 struct fio_option *o,
825 unsigned long long *p, unsigned int idx)
827 struct gopt_str_val *g;
828 const gchar *postfix[] = { "B", "KB", "MB", "GB", "PB", "TB", "" };
832 g = calloc(1, sizeof(*g));
833 g->gopt.box = gtk_hbox_new(FALSE, 3);
835 label = gtk_label_new(o->name);
837 label = gtk_label_new(o->lname);
838 gopt_mark_index(gjv, &g->gopt, idx, GOPT_STR_VAL);
840 g->spin = gtk_spin_button_new_with_range(0.0, 1023.0, 1.0);
841 gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(g->spin), GTK_UPDATE_IF_VALID);
842 gtk_spin_button_set_value(GTK_SPIN_BUTTON(g->spin), 0);
843 gtk_spin_button_set_wrap(GTK_SPIN_BUTTON(g->spin), 1);
844 gtk_box_pack_start(GTK_BOX(g->gopt.box), g->spin, FALSE, FALSE, 0);
845 g_signal_connect(G_OBJECT(g->spin), "wrapped", G_CALLBACK(gopt_str_val_spin_wrapped), g);
846 g_signal_connect(G_OBJECT(g->spin), "changed", G_CALLBACK(gopt_str_val_changed), g);
848 g->combo = gtk_combo_box_text_new();
850 while (strlen(postfix[i])) {
851 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(g->combo), postfix[i]);
855 gtk_combo_box_set_active(GTK_COMBO_BOX(g->combo), 0);
856 gtk_box_pack_start(GTK_BOX(g->gopt.box), g->combo, FALSE, FALSE, 0);
857 gtk_box_pack_start(GTK_BOX(g->gopt.box), label, FALSE, FALSE, 3);
860 gopt_str_val_set_val(g, *p);
862 g_signal_connect(G_OBJECT(g->combo), "changed", G_CALLBACK(gopt_str_val_changed), g);
864 g_signal_connect(G_OBJECT(g->gopt.box), "destroy", G_CALLBACK(gopt_str_val_destroy), g);
868 static void gopt_set_option(struct gopt_job_view *gjv, struct fio_option *o,
869 struct gopt *gopt, struct thread_options *to)
872 case FIO_OPT_STR_VAL: {
873 unsigned long long *ullp = NULL;
874 struct gopt_str_val *g;
877 ullp = td_var(to, o->off1);
879 g = container_of(gopt, struct gopt_str_val, gopt);
881 gopt_str_val_set_val(g, *ullp);
884 case FIO_OPT_STR_VAL_TIME: {
885 unsigned long long *ullp = NULL;
890 ullp = td_var(o->prof_opts, o->off1);
892 ullp = td_var(to, o->off1);
895 i = container_of(gopt, struct gopt_int, gopt);
897 gopt_int_set_val(i, *ullp);
901 if (o->posval[0].ival) {
902 unsigned int *ip = NULL;
903 struct gopt_combo *c;
907 ip = td_var(o->prof_opts, o->off1);
909 ip = td_var(to, o->off1);
912 c = container_of(gopt, struct gopt_combo, gopt);
914 gopt_combo_int_set_val(c, *ip);
916 unsigned int *ip = NULL;
921 ip = td_var(o->prof_opts, o->off1);
923 ip = td_var(to, o->off1);
926 i = container_of(gopt, struct gopt_int, gopt);
928 gopt_int_set_val(i, *ip);
931 case FIO_OPT_STR_SET:
933 unsigned int *ip = NULL;
938 ip = td_var(o->prof_opts, o->off1);
940 ip = td_var(to, o->off1);
943 b = container_of(gopt, struct gopt_bool, gopt);
945 gopt_bool_set_val(b, *ip);
949 if (o->posval[0].ival) {
950 unsigned int *ip = NULL;
951 struct gopt_combo *c;
955 ip = td_var(o->prof_opts, o->off1);
957 ip = td_var(to, o->off1);
960 c = container_of(gopt, struct gopt_combo, gopt);
962 gopt_combo_int_set_val(c, *ip);
971 p = td_var(o->prof_opts, o->off1);
973 p = td_var(to, o->off1);
978 s = container_of(gopt, struct gopt_str, gopt);
979 gopt_str_store_set_val(s, text);
984 case FIO_OPT_STR_STORE: {
985 struct gopt_combo *c;
992 p = td_var(o->prof_opts, o->off1);
994 p = td_var(to, o->off1);
999 if (!o->posval[0].ival) {
1002 s = container_of(gopt, struct gopt_str, gopt);
1003 gopt_str_store_set_val(s, text);
1007 c = container_of(gopt, struct gopt_combo, gopt);
1009 gopt_combo_str_set_val(c, text);
1012 case FIO_OPT_STR_MULTI:
1015 case FIO_OPT_RANGE: {
1016 struct gopt_range *r;
1017 unsigned int *ip[4];
1020 ip[0] = td_var(o->prof_opts, o->off1);
1021 ip[1] = td_var(o->prof_opts, o->off2);
1022 ip[2] = td_var(o->prof_opts, o->off3);
1023 ip[3] = td_var(o->prof_opts, o->off4);
1025 ip[0] = td_var(to, o->off1);
1026 ip[1] = td_var(to, o->off2);
1027 ip[2] = td_var(to, o->off3);
1028 ip[3] = td_var(to, o->off4);
1031 r = container_of(gopt, struct gopt_range, gopt);
1032 gopt_int_range_set_val(r, *ip);
1035 /* still need to handle this one */
1036 case FIO_OPT_FLOAT_LIST:
1038 case FIO_OPT_DEPRECATED:
1041 printf("ignore type %u\n", o->type);
1046 static void gopt_add_option(struct gopt_job_view *gjv, GtkWidget *hbox,
1047 struct fio_option *o, unsigned int opt_index,
1048 struct thread_options *to)
1050 struct gopt *go = NULL;
1053 case FIO_OPT_STR_VAL: {
1054 unsigned long long *ullp = NULL;
1058 ullp = td_var(o->prof_opts, o->off1);
1060 ullp = td_var(to, o->off1);
1063 go = gopt_new_str_val(gjv, o, ullp, opt_index);
1066 case FIO_OPT_STR_VAL_TIME: {
1067 unsigned long long *ullp = NULL;
1071 ullp = td_var(o->prof_opts, o->off1);
1073 ullp = td_var(to, o->off1);
1076 go = gopt_new_ullong(gjv, o, ullp, opt_index);
1080 if (o->posval[0].ival) {
1081 unsigned int *ip = NULL;
1085 ip = td_var(o->prof_opts, o->off1);
1087 ip = td_var(to, o->off1);
1090 go = gopt_new_combo_int(gjv, o, ip, opt_index);
1092 unsigned int *ip = NULL;
1096 ip = td_var(o->prof_opts, o->off1);
1098 ip = td_var(to, o->off1);
1101 go = gopt_new_int(gjv, o, ip, opt_index);
1104 case FIO_OPT_STR_SET:
1105 case FIO_OPT_BOOL: {
1106 unsigned int *ip = NULL;
1110 ip = td_var(o->prof_opts, o->off1);
1112 ip = td_var(to, o->off1);
1115 go = gopt_new_bool(gjv, o, ip, opt_index);
1119 if (o->posval[0].ival) {
1120 unsigned int *ip = NULL;
1124 ip = td_var(o->prof_opts, o->off1);
1126 ip = td_var(to, o->off1);
1129 go = gopt_new_combo_int(gjv, o, ip, opt_index);
1131 /* TODO: usually ->cb, or unsigned int pointer */
1132 go = gopt_new_str_store(gjv, o, NULL, opt_index);
1137 case FIO_OPT_STR_STORE: {
1144 p = td_var(o->prof_opts, o->off1);
1146 p = td_var(to, o->off1);
1151 if (!o->posval[0].ival) {
1152 go = gopt_new_str_store(gjv, o, text, opt_index);
1156 go = gopt_new_combo_str(gjv, o, text, opt_index);
1159 case FIO_OPT_STR_MULTI:
1160 go = gopt_new_str_multi(gjv, o, opt_index);
1162 case FIO_OPT_RANGE: {
1163 unsigned int *ip[4];
1166 ip[0] = td_var(o->prof_opts, o->off1);
1167 ip[1] = td_var(o->prof_opts, o->off2);
1168 ip[2] = td_var(o->prof_opts, o->off3);
1169 ip[3] = td_var(o->prof_opts, o->off4);
1171 ip[0] = td_var(to, o->off1);
1172 ip[1] = td_var(to, o->off2);
1173 ip[2] = td_var(to, o->off3);
1174 ip[3] = td_var(to, o->off4);
1177 go = gopt_new_int_range(gjv, o, ip, opt_index);
1180 /* still need to handle this one */
1181 case FIO_OPT_FLOAT_LIST:
1183 case FIO_OPT_DEPRECATED:
1186 printf("ignore type %u\n", o->type);
1194 gtk_widget_set_tooltip_text(go->box, o->help);
1198 dest = gopt_get_group_frame(gjv, hbox, o->group);
1200 gtk_box_pack_start(GTK_BOX(hbox), go->box, FALSE, FALSE, 5);
1202 gtk_box_pack_start(GTK_BOX(dest), go->box, FALSE, FALSE, 5);
1206 static void gopt_add_options(struct gopt_job_view *gjv,
1207 struct thread_options *to)
1209 GtkWidget *hbox = NULL;
1213 * First add all options
1215 for (i = 0; fio_options[i].name; i++) {
1216 struct fio_option *o = &fio_options[i];
1217 unsigned int mask = o->category;
1218 struct opt_group *og;
1220 while ((og = opt_group_from_mask(&mask)) != NULL) {
1221 GtkWidget *vbox = gjv->vboxes[ffz(~og->mask)];
1223 hbox = gtk_hbox_new(FALSE, 3);
1224 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 5);
1225 gopt_add_option(gjv, hbox, o, i, to);
1230 static void gopt_set_options(struct gopt_job_view *gjv,
1231 struct thread_options *to)
1235 for (i = 0; fio_options[i].name; i++) {
1236 struct fio_option *o = &fio_options[i];
1237 struct gopt *gopt = gjv->gopts[i];
1239 gopt_set_option(gjv, o, gopt, to);
1243 static GtkWidget *gopt_add_tab(GtkWidget *notebook, const char *name)
1245 GtkWidget *box, *vbox, *scroll;
1247 scroll = gtk_scrolled_window_new(NULL, NULL);
1248 gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
1249 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1251 vbox = gtk_vbox_new(FALSE, 3);
1252 box = gtk_hbox_new(FALSE, 0);
1253 gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
1254 gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
1255 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), scroll, gtk_label_new(name));
1259 static GtkWidget *gopt_add_group_tab(GtkWidget *notebook, struct opt_group *og)
1261 return gopt_add_tab(notebook, og->name);
1264 static void gopt_add_group_tabs(GtkWidget *notebook, struct gopt_job_view *gjv)
1266 struct opt_group *og;
1271 unsigned int mask = (1U << i);
1273 og = opt_group_from_mask(&mask);
1276 gjv->vboxes[i] = gopt_add_group_tab(notebook, og);
1281 static void gopt_handle_str_multi_changed(struct gopt_job_view *gjv,
1282 struct gopt_str_multi *m,
1283 struct fio_option *o)
1285 struct value_pair *vp;
1292 ip = td_var(o->prof_opts, o->off1);
1294 ip = td_var(gjv->o, o->off1);
1301 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(m->checks[i]));
1316 static void gopt_handle_range_changed(struct gopt_job_view *gjv,
1317 struct gopt_range *r,
1318 struct fio_option *o)
1320 unsigned int *ip[4];
1325 ip[0] = td_var(o->prof_opts, o->off1);
1326 ip[1] = td_var(o->prof_opts, o->off2);
1327 ip[2] = td_var(o->prof_opts, o->off3);
1328 ip[3] = td_var(o->prof_opts, o->off4);
1330 ip[0] = td_var(gjv->o, o->off1);
1331 ip[1] = td_var(gjv->o, o->off2);
1332 ip[2] = td_var(gjv->o, o->off3);
1333 ip[3] = td_var(gjv->o, o->off4);
1336 for (i = 0; i < GOPT_RANGE_SPIN; i++) {
1337 val = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(r->spins[i]));
1342 static void gopt_handle_str_val_changed(struct gopt_job_view *gjv,
1343 struct gopt_str_val *s,
1344 struct fio_option *o)
1346 unsigned long long *ullp;
1351 ullp = td_var(o->prof_opts, o->off1);
1353 ullp = td_var(gjv->o, o->off1);
1361 adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(s->spin));
1362 *ullp = gtk_adjustment_get_value(adj);
1367 index = gtk_combo_box_get_active(GTK_COMBO_BOX(s->combo));
1372 static void gopt_handle_str_changed(struct gopt_job_view *gjv,
1373 struct gopt_str *s, struct fio_option *o)
1378 p = td_var(o->prof_opts, o->off1);
1380 p = td_var(gjv->o, o->off1);
1385 *p = strdup(gtk_entry_get_text(GTK_ENTRY(s->entry)));
1388 static void gopt_handle_bool_changed(struct gopt_job_view *gjv,
1389 struct gopt_bool *b, struct fio_option *o)
1395 ip = td_var(o->prof_opts, o->off1);
1397 ip = td_var(gjv->o, o->off1);
1399 set = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(b->check));
1403 static void gopt_handle_int_changed(struct gopt_job_view *gjv,
1404 struct gopt_int *i, struct fio_option *o)
1411 ip = td_var(o->prof_opts, o->off1);
1413 ip = td_var(gjv->o, o->off1);
1415 adj = gtk_spin_button_get_adjustment(GTK_SPIN_BUTTON(i->spin));
1416 val = gtk_adjustment_get_value(adj);
1420 static void gopt_handle_combo_str_changed(struct gopt_job_view *gjv,
1421 struct gopt_combo *c,
1422 struct fio_option *o)
1427 p = td_var(o->prof_opts, o->off1);
1429 p = td_var(gjv->o, o->off1);
1434 *p = strdup(gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(c->combo)));
1437 static void gopt_handle_combo_int_changed(struct gopt_job_view *gjv,
1438 struct gopt_combo *c,
1439 struct fio_option *o)
1445 ip = td_var(o->prof_opts, o->off1);
1447 ip = td_var(gjv->o, o->off1);
1449 index = gtk_combo_box_get_active(GTK_COMBO_BOX(c->combo));
1450 *ip = o->posval[index].oval;
1453 static void gopt_handle_changed(struct gopt *gopt)
1455 struct fio_option *o = &fio_options[gopt->opt_index];
1456 struct gopt_job_view *gjv = gopt->gjv;
1458 switch (gopt->opt_type) {
1459 case GOPT_COMBO_INT: {
1460 struct gopt_combo *c;
1462 c = container_of(gopt, struct gopt_combo, gopt);
1463 gopt_handle_combo_int_changed(gjv, c, o);
1466 case GOPT_COMBO_STR: {
1467 struct gopt_combo *c;
1469 c = container_of(gopt, struct gopt_combo, gopt);
1470 gopt_handle_combo_str_changed(gjv, c, o);
1476 i = container_of(gopt, struct gopt_int, gopt);
1477 gopt_handle_int_changed(gjv, i, o);
1481 struct gopt_bool *b;
1483 b = container_of(gopt, struct gopt_bool, gopt);
1484 gopt_handle_bool_changed(gjv, b, o);
1490 s = container_of(gopt, struct gopt_str, gopt);
1491 gopt_handle_str_changed(gjv, s, o);
1494 case GOPT_STR_VAL: {
1495 struct gopt_str_val *s;
1497 s = container_of(gopt, struct gopt_str_val, gopt);
1498 gopt_handle_str_val_changed(gjv, s, o);
1502 struct gopt_range *r;
1504 r = container_of(gopt, struct gopt_range, gopt);
1505 gopt_handle_range_changed(gjv, r, o);
1508 case GOPT_STR_MULTI: {
1509 struct gopt_str_multi *m;
1511 m = container_of(gopt, struct gopt_str_multi, gopt);
1512 gopt_handle_str_multi_changed(gjv, m, o);
1516 log_err("gfio: bad option type: %d\n", gopt->opt_type);
1521 static void gopt_report_update_status(struct gopt_job_view *gjv)
1523 struct gfio_client *gc = gjv->client;
1526 sprintf(tmp, "\nCompleted with error: %d\n", gc->update_job_status);
1527 gfio_report_info(gc->ge->ui, "Update job", tmp);
1530 static int gopt_handle_changed_options(struct gopt_job_view *gjv)
1532 struct gfio_client *gc = gjv->client;
1533 struct flist_head *entry;
1534 uint64_t waitid = 0;
1538 flist_for_each(entry, &gjv->changed_list) {
1539 gopt = flist_entry(entry, struct gopt, changed_list);
1540 gopt_handle_changed(gopt);
1543 gc->update_job_status = 0;
1544 gc->update_job_done = 0;
1546 ret = fio_client_update_options(gc->client, gjv->o, &waitid);
1550 ret = fio_client_wait_for_reply(gc->client, waitid);
1554 assert(gc->update_job_done);
1555 if (gc->update_job_status)
1558 while (!flist_empty(&gjv->changed_list)) {
1559 gopt = flist_entry(gjv->changed_list.next, struct gopt, changed_list);
1560 flist_del_init(&gopt->changed_list);
1564 gopt_dialog_update_apply_button(gjv);
1568 static gint gopt_dialog_cancel(gint response)
1571 case GTK_RESPONSE_NONE:
1572 case GTK_RESPONSE_REJECT:
1573 case GTK_RESPONSE_DELETE_EVENT:
1574 case GTK_RESPONSE_CANCEL:
1575 case GTK_RESPONSE_NO:
1582 static gint gopt_dialog_done(gint response)
1585 case GTK_RESPONSE_ACCEPT:
1586 case GTK_RESPONSE_OK:
1587 case GTK_RESPONSE_YES:
1594 static void gopt_handle_option_dialog(struct gopt_job_view *gjv)
1599 response = gtk_dialog_run(GTK_DIALOG(gjv->dialog));
1601 if (gopt_dialog_cancel(response) ||
1602 gopt_dialog_done(response))
1608 gopt_handle_changed_options(gjv);
1609 gopt_report_update_status(gjv);
1612 if (gopt_dialog_cancel(response))
1615 gopt_handle_changed_options(gjv);
1618 static void gopt_job_changed(GtkComboBox *box, gpointer data)
1620 struct gopt_job_view *gjv = (struct gopt_job_view *) data;
1621 struct gfio_client_options *gco = NULL;
1622 struct gfio_client *gc = gjv->client;
1623 struct flist_head *entry;
1627 * The switch act should be sensitized appropriately, so that we
1628 * never get here with modified options.
1630 if (!flist_empty(&gjv->changed_list)) {
1631 gfio_report_info(gc->ge->ui, "Internal Error", "Modified options on job switch.\nThat should not be possible!\n");
1635 job = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(gjv->job_combo));
1636 flist_for_each(entry, &gc->o_list) {
1639 gco = flist_entry(entry, struct gfio_client_options, list);
1641 if (!name || !strlen(name))
1642 name = "Default job";
1644 if (!strcmp(name, job))
1651 gfio_report_info(gc->ge->ui, "Internal Error", "Could not find job description.\nThat should not be possible!\n");
1655 gjv->in_job_switch = 1;
1656 gopt_set_options(gjv, &gco->o);
1657 gjv->in_job_switch = 0;
1660 void gopt_get_options_window(GtkWidget *window, struct gfio_client *gc)
1662 GtkWidget *dialog, *notebook, *vbox, *topvbox, *combo;
1663 struct gfio_client_options *gco;
1664 struct flist_head *entry;
1665 struct gopt_job_view *gjv;
1667 dialog = gtk_dialog_new_with_buttons("Fio options",
1668 GTK_WINDOW(window), GTK_DIALOG_DESTROY_WITH_PARENT,
1669 GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1670 GTK_STOCK_APPLY, GTK_RESPONSE_APPLY,
1671 GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, NULL);
1673 combo = gtk_combo_box_text_new();
1674 flist_for_each(entry, &gc->o_list) {
1675 struct thread_options *o;
1678 gco = flist_entry(entry, struct gfio_client_options, list);
1681 if (!name || !strlen(name))
1682 name = "Default job";
1684 gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(combo), name);
1686 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), 0);
1688 gtk_widget_set_size_request(GTK_WIDGET(dialog), 1024, 768);
1690 topvbox = gtk_dialog_get_content_area(GTK_DIALOG(dialog));
1691 gtk_box_pack_start(GTK_BOX(topvbox), combo, FALSE, FALSE, 5);
1693 vbox = gtk_vbox_new(TRUE, 5);
1694 gtk_box_pack_start(GTK_BOX(topvbox), vbox, TRUE, TRUE, 5);
1696 notebook = gtk_notebook_new();
1697 gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1);
1698 gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
1699 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 5);
1701 gjv = calloc(1, sizeof(*gjv));
1702 INIT_FLIST_HEAD(&gjv->changed_list);
1703 gco = flist_entry(gc->o_list.next, struct gfio_client_options, list);
1705 gjv->dialog = dialog;
1707 gjv->job_combo = combo;
1708 gopt_add_group_tabs(notebook, gjv);
1709 gopt_add_options(gjv, &gco->o);
1710 gopt_dialog_update_apply_button(gjv);
1712 g_signal_connect(G_OBJECT(combo), "changed", G_CALLBACK(gopt_job_changed), gjv);
1714 gtk_widget_show_all(dialog);
1716 gopt_handle_option_dialog(gjv);
1718 gtk_widget_destroy(dialog);
1723 * Build n-ary option dependency tree
1725 void gopt_init(void)
1729 gopt_dep_tree = g_node_new(NULL);
1731 for (i = 0; fio_options[i].name; i++) {
1732 struct fio_option *o = &fio_options[i];
1733 GNode *node, *nparent;
1736 * Insert node with either the root parent, or an
1739 node = g_node_new(o);
1740 nparent = gopt_dep_tree;
1742 struct fio_option *parent;
1744 parent = fio_option_find(o->parent);
1745 nparent = g_node_find(gopt_dep_tree, G_IN_ORDER, G_TRAVERSE_ALL, parent);
1747 log_err("fio: did not find parent %s for opt %s\n", o->name, o->parent);
1748 nparent = gopt_dep_tree;
1752 g_node_insert(nparent, -1, node);
1756 void gopt_exit(void)
1758 g_node_destroy(gopt_dep_tree);
1759 gopt_dep_tree = NULL;