Commit | Line | Data |
---|---|---|
ff1f3280 SC |
1 | /* |
2 | * gfio - gui front end for fio - the flexible io tester | |
3 | * | |
4 | * Copyright (C) 2012 Stephen M. Cameron <stephenmcameron@gmail.com> | |
5 | * | |
6 | * The license below covers all files distributed with fio unless otherwise | |
7 | * noted in the file itself. | |
8 | * | |
9 | * This program is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License version 2 as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This program is distributed in the hope that it will be useful, | |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 | * GNU General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with this program; if not, write to the Free Software | |
20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 | * | |
22 | */ | |
8232e285 | 23 | #include <locale.h> |
60f6b330 | 24 | #include <malloc.h> |
8232e285 | 25 | |
5b7573ab | 26 | #include <glib.h> |
ff1f3280 SC |
27 | #include <gtk/gtk.h> |
28 | ||
8232e285 SC |
29 | #include "fio.h" |
30 | ||
3e47bd25 JA |
31 | static void gfio_update_thread_status(char *status_message, double perc); |
32 | ||
f3074008 SC |
33 | #define ARRAYSIZE(x) (sizeof((x)) / (sizeof((x)[0]))) |
34 | ||
35 | typedef void (*clickfunction)(GtkWidget *widget, gpointer data); | |
36 | ||
3e47bd25 | 37 | static void connect_clicked(GtkWidget *widget, gpointer data); |
f3074008 SC |
38 | static void start_job_clicked(GtkWidget *widget, gpointer data); |
39 | ||
40 | static struct button_spec { | |
41 | const char *buttontext; | |
42 | clickfunction f; | |
43 | const char *tooltiptext; | |
3e47bd25 | 44 | const int start_insensitive; |
f3074008 | 45 | } buttonspeclist[] = { |
3e47bd25 JA |
46 | #define CONNECT_BUTTON 0 |
47 | #define START_JOB_BUTTON 1 | |
48 | { "Connect", connect_clicked, "Connect to host", 0 }, | |
f3074008 SC |
49 | { "Start Job", |
50 | start_job_clicked, | |
3e47bd25 | 51 | "Send current fio job to fio server to be executed", 1 }, |
f3074008 SC |
52 | }; |
53 | ||
843ad237 JA |
54 | struct probe_widget { |
55 | GtkWidget *hostname; | |
56 | GtkWidget *os; | |
57 | GtkWidget *arch; | |
58 | GtkWidget *fio_ver; | |
59 | }; | |
60 | ||
3e47bd25 | 61 | struct eta_widget { |
807f9971 JA |
62 | GtkWidget *name; |
63 | GtkWidget *iotype; | |
64 | GtkWidget *ioengine; | |
65 | GtkWidget *iodepth; | |
3e47bd25 JA |
66 | GtkWidget *jobs; |
67 | GtkWidget *files; | |
68 | GtkWidget *read_bw; | |
69 | GtkWidget *read_iops; | |
70 | GtkWidget *cr_bw; | |
71 | GtkWidget *cr_iops; | |
72 | GtkWidget *write_bw; | |
73 | GtkWidget *write_iops; | |
74 | GtkWidget *cw_bw; | |
75 | GtkWidget *cw_iops; | |
76 | }; | |
77 | ||
ff1f3280 SC |
78 | struct gui { |
79 | GtkWidget *window; | |
5b7573ab | 80 | GtkWidget *vbox; |
c36f98d9 SC |
81 | GtkWidget *topvbox; |
82 | GtkWidget *topalign; | |
83 | GtkWidget *bottomalign; | |
04cc6b77 | 84 | GtkWidget *thread_status_pb; |
f3074008 SC |
85 | GtkWidget *buttonbox; |
86 | GtkWidget *button[ARRAYSIZE(buttonspeclist)]; | |
45032dd8 SC |
87 | GtkWidget *hostname_hbox; |
88 | GtkWidget *hostname_label; | |
89 | GtkWidget *hostname_entry; | |
3ec62ec4 | 90 | GtkWidget *port_button; |
45032dd8 | 91 | GtkWidget *port_label; |
45032dd8 | 92 | GtkWidget *hostname_combo_box; /* ipv4, ipv6 or socket */ |
736f2dff SC |
93 | GtkWidget *scrolled_window; |
94 | GtkWidget *textview; | |
0420ba6a JA |
95 | GtkWidget *error_info_bar; |
96 | GtkWidget *error_label; | |
736f2dff | 97 | GtkTextBuffer *text; |
843ad237 | 98 | struct probe_widget probe; |
3e47bd25 | 99 | struct eta_widget eta; |
3ec62ec4 | 100 | int connected; |
25927259 | 101 | pthread_t t; |
0420ba6a | 102 | |
3ec62ec4 | 103 | struct fio_client *client; |
0420ba6a JA |
104 | int nr_job_files; |
105 | char **job_files; | |
5b7573ab | 106 | } ui; |
ff1f3280 | 107 | |
3ec62ec4 JA |
108 | static void gfio_set_connected(struct gui *ui, int connected) |
109 | { | |
110 | if (connected) { | |
111 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1); | |
112 | ui->connected = 1; | |
113 | gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Disconnect"); | |
114 | } else { | |
115 | ui->connected = 0; | |
116 | gtk_button_set_label(GTK_BUTTON(ui->button[CONNECT_BUTTON]), "Connect"); | |
117 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0); | |
118 | } | |
119 | } | |
120 | ||
a1820207 SC |
121 | static void gfio_text_op(struct fio_client *client, |
122 | FILE *f, __u16 pdu_len, const char *buf) | |
123 | { | |
807f9971 | 124 | #if 0 |
736f2dff SC |
125 | GtkTextBuffer *buffer; |
126 | GtkTextIter end; | |
127 | ||
128 | buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui.textview)); | |
129 | gdk_threads_enter(); | |
130 | gtk_text_buffer_get_end_iter(buffer, &end); | |
131 | gtk_text_buffer_insert(buffer, &end, buf, -1); | |
132 | gdk_threads_leave(); | |
133 | gtk_text_view_scroll_to_iter(GTK_TEXT_VIEW(ui.textview), | |
134 | &end, 0.0, FALSE, 0.0,0.0); | |
807f9971 JA |
135 | #else |
136 | fio_client_ops.text_op(client, f, pdu_len, buf); | |
137 | #endif | |
a1820207 SC |
138 | } |
139 | ||
140 | static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd) | |
141 | { | |
142 | printf("gfio_disk_util_op called\n"); | |
143 | fio_client_ops.disk_util(client, cmd); | |
144 | } | |
145 | ||
146 | static void gfio_thread_status_op(struct fio_net_cmd *cmd) | |
147 | { | |
148 | printf("gfio_thread_status_op called\n"); | |
149 | fio_client_ops.thread_status(cmd); | |
150 | } | |
151 | ||
152 | static void gfio_group_stats_op(struct fio_net_cmd *cmd) | |
153 | { | |
154 | printf("gfio_group_stats_op called\n"); | |
155 | fio_client_ops.group_stats(cmd); | |
156 | } | |
157 | ||
3e47bd25 JA |
158 | static void gfio_update_eta(struct jobs_eta *je) |
159 | { | |
160 | static int eta_good; | |
161 | char eta_str[128]; | |
162 | char output[256]; | |
163 | char tmp[32]; | |
164 | double perc = 0.0; | |
165 | int i2p = 0; | |
166 | ||
167 | eta_str[0] = '\0'; | |
168 | output[0] = '\0'; | |
169 | ||
170 | if (je->eta_sec != INT_MAX && je->elapsed_sec) { | |
171 | perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec); | |
172 | eta_to_str(eta_str, je->eta_sec); | |
173 | } | |
174 | ||
175 | sprintf(tmp, "%u", je->nr_running); | |
176 | gtk_label_set_text(GTK_LABEL(ui.eta.jobs), tmp); | |
177 | sprintf(tmp, "%u", je->files_open); | |
178 | gtk_label_set_text(GTK_LABEL(ui.eta.files), tmp); | |
179 | ||
180 | #if 0 | |
181 | if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) { | |
182 | if (je->m_rate || je->t_rate) { | |
183 | char *tr, *mr; | |
184 | ||
185 | mr = num2str(je->m_rate, 4, 0, i2p); | |
186 | tr = num2str(je->t_rate, 4, 0, i2p); | |
187 | gtk_label_set_text(GTK_LABEL(ui.eta. | |
188 | p += sprintf(p, ", CR=%s/%s KB/s", tr, mr); | |
189 | free(tr); | |
190 | free(mr); | |
191 | } else if (je->m_iops || je->t_iops) | |
192 | p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops); | |
ebbd89cc | 193 | |
3e47bd25 JA |
194 | gtk_label_set_text(GTK_LABEL(ui.eta.cr_bw), "---"); |
195 | gtk_label_set_text(GTK_LABEL(ui.eta.cr_iops), "---"); | |
196 | gtk_label_set_text(GTK_LABEL(ui.eta.cw_bw), "---"); | |
197 | gtk_label_set_text(GTK_LABEL(ui.eta.cw_iops), "---"); | |
198 | #endif | |
199 | ||
200 | if (je->eta_sec != INT_MAX && je->nr_running) { | |
201 | char *iops_str[2]; | |
202 | char *rate_str[2]; | |
203 | ||
204 | if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running) | |
205 | strcpy(output, "-.-% done"); | |
206 | else { | |
207 | eta_good = 1; | |
208 | perc *= 100.0; | |
209 | sprintf(output, "%3.1f%% done", perc); | |
210 | } | |
211 | ||
212 | rate_str[0] = num2str(je->rate[0], 5, 10, i2p); | |
213 | rate_str[1] = num2str(je->rate[1], 5, 10, i2p); | |
214 | ||
215 | iops_str[0] = num2str(je->iops[0], 4, 1, 0); | |
216 | iops_str[1] = num2str(je->iops[1], 4, 1, 0); | |
217 | ||
218 | gtk_label_set_text(GTK_LABEL(ui.eta.read_bw), rate_str[0]); | |
219 | gtk_label_set_text(GTK_LABEL(ui.eta.read_iops), iops_str[0]); | |
220 | gtk_label_set_text(GTK_LABEL(ui.eta.write_bw), rate_str[1]); | |
221 | gtk_label_set_text(GTK_LABEL(ui.eta.write_iops), iops_str[1]); | |
222 | ||
223 | free(rate_str[0]); | |
224 | free(rate_str[1]); | |
225 | free(iops_str[0]); | |
226 | free(iops_str[1]); | |
227 | } | |
228 | ||
229 | if (eta_str[0]) { | |
230 | char *dst = output + strlen(output); | |
231 | ||
232 | sprintf(dst, " - %s", eta_str); | |
233 | } | |
234 | ||
235 | gfio_update_thread_status(output, perc); | |
236 | } | |
237 | ||
a1820207 SC |
238 | static void gfio_eta_op(struct fio_client *client, struct fio_net_cmd *cmd) |
239 | { | |
3e47bd25 JA |
240 | struct jobs_eta *je = (struct jobs_eta *) cmd->payload; |
241 | struct client_eta *eta = (struct client_eta *) (uintptr_t) cmd->tag; | |
242 | ||
243 | client->eta_in_flight = NULL; | |
244 | flist_del_init(&client->eta_list); | |
245 | ||
246 | fio_client_convert_jobs_eta(je); | |
247 | fio_client_sum_jobs_eta(&eta->eta, je); | |
248 | fio_client_dec_jobs_eta(eta, gfio_update_eta); | |
a1820207 SC |
249 | } |
250 | ||
251 | static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd) | |
252 | { | |
843ad237 JA |
253 | struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload; |
254 | const char *os, *arch; | |
255 | char buf[64]; | |
256 | ||
257 | os = fio_get_os_string(probe->os); | |
258 | if (!os) | |
259 | os = "unknown"; | |
260 | ||
261 | arch = fio_get_arch_string(probe->arch); | |
262 | if (!arch) | |
263 | os = "unknown"; | |
264 | ||
265 | if (!client->name) | |
266 | client->name = strdup((char *) probe->hostname); | |
267 | ||
268 | gtk_label_set_text(GTK_LABEL(ui.probe.hostname), (char *) probe->hostname); | |
269 | gtk_label_set_text(GTK_LABEL(ui.probe.os), os); | |
270 | gtk_label_set_text(GTK_LABEL(ui.probe.arch), arch); | |
271 | sprintf(buf, "%u.%u.%u", probe->fio_major, probe->fio_minor, probe->fio_patch); | |
272 | gtk_label_set_text(GTK_LABEL(ui.probe.fio_ver), buf); | |
a1820207 SC |
273 | } |
274 | ||
04cc6b77 | 275 | static void gfio_update_thread_status(char *status_message, double perc) |
5b7573ab SC |
276 | { |
277 | static char message[100]; | |
278 | const char *m = message; | |
279 | ||
280 | strncpy(message, status_message, sizeof(message) - 1); | |
04cc6b77 SC |
281 | gtk_progress_bar_set_text( |
282 | GTK_PROGRESS_BAR(ui.thread_status_pb), m); | |
283 | gtk_progress_bar_set_fraction( | |
284 | GTK_PROGRESS_BAR(ui.thread_status_pb), perc / 100.0); | |
5b7573ab SC |
285 | gdk_threads_enter(); |
286 | gtk_widget_queue_draw(ui.window); | |
287 | gdk_threads_leave(); | |
288 | } | |
289 | ||
3ec62ec4 JA |
290 | static void gfio_quit_op(struct fio_client *client) |
291 | { | |
292 | struct gui *ui = client->client_data; | |
293 | ||
294 | gfio_set_connected(ui, 0); | |
295 | } | |
296 | ||
807f9971 JA |
297 | static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd) |
298 | { | |
299 | struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload; | |
300 | struct gui *ui = client->client_data; | |
301 | char tmp[8]; | |
302 | int i; | |
303 | ||
304 | p->iodepth = le32_to_cpu(p->iodepth); | |
305 | p->rw = le32_to_cpu(p->rw); | |
306 | ||
307 | for (i = 0; i < 2; i++) { | |
308 | p->min_bs[i] = le32_to_cpu(p->min_bs[i]); | |
309 | p->max_bs[i] = le32_to_cpu(p->max_bs[i]); | |
310 | } | |
311 | ||
312 | p->numjobs = le32_to_cpu(p->numjobs); | |
313 | p->group_reporting = le32_to_cpu(p->group_reporting); | |
314 | ||
315 | gtk_label_set_text(GTK_LABEL(ui->eta.name), (gchar *) p->jobname); | |
316 | gtk_label_set_text(GTK_LABEL(ui->eta.iotype), ddir_str(p->rw)); | |
317 | gtk_label_set_text(GTK_LABEL(ui->eta.ioengine), (gchar *) p->ioengine); | |
318 | ||
319 | sprintf(tmp, "%u", p->iodepth); | |
320 | gtk_label_set_text(GTK_LABEL(ui->eta.iodepth), tmp); | |
321 | } | |
322 | ||
a1820207 | 323 | struct client_ops gfio_client_ops = { |
0420ba6a JA |
324 | .text_op = gfio_text_op, |
325 | .disk_util = gfio_disk_util_op, | |
326 | .thread_status = gfio_thread_status_op, | |
327 | .group_stats = gfio_group_stats_op, | |
328 | .eta = gfio_eta_op, | |
329 | .probe = gfio_probe_op, | |
3ec62ec4 | 330 | .quit = gfio_quit_op, |
807f9971 | 331 | .add_job = gfio_add_job_op, |
3ec62ec4 | 332 | .stay_connected = 1, |
a1820207 SC |
333 | }; |
334 | ||
ff1f3280 SC |
335 | static void quit_clicked(__attribute__((unused)) GtkWidget *widget, |
336 | __attribute__((unused)) gpointer data) | |
337 | { | |
338 | gtk_main_quit(); | |
339 | } | |
340 | ||
25927259 SC |
341 | static void *job_thread(void *arg) |
342 | { | |
3ec62ec4 | 343 | printf("job thread starts\n"); |
25927259 | 344 | fio_handle_clients(&gfio_client_ops); |
3ec62ec4 | 345 | printf("job thread exits\n"); |
25927259 SC |
346 | return NULL; |
347 | } | |
348 | ||
0420ba6a | 349 | static int send_job_files(struct gui *ui) |
60f6b330 | 350 | { |
441013b4 | 351 | int i, ret = 0; |
0420ba6a JA |
352 | |
353 | for (i = 0; i < ui->nr_job_files; i++) { | |
354 | ret = fio_clients_send_ini(ui->job_files[i]); | |
441013b4 JA |
355 | if (ret) |
356 | break; | |
357 | ||
0420ba6a JA |
358 | free(ui->job_files[i]); |
359 | ui->job_files[i] = NULL; | |
441013b4 JA |
360 | } |
361 | while (i < ui->nr_job_files) { | |
362 | free(ui->job_files[i]); | |
363 | ui->job_files[i] = NULL; | |
364 | i++; | |
0420ba6a JA |
365 | } |
366 | ||
441013b4 | 367 | return ret; |
60f6b330 SC |
368 | } |
369 | ||
3ec62ec4 | 370 | static void start_job_thread(struct gui *ui) |
25927259 | 371 | { |
0420ba6a | 372 | if (send_job_files(ui)) { |
60f6b330 | 373 | printf("Yeah, I didn't really like those options too much.\n"); |
60f6b330 SC |
374 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 1); |
375 | return; | |
376 | } | |
25927259 SC |
377 | } |
378 | ||
f3074008 | 379 | static void start_job_clicked(__attribute__((unused)) GtkWidget *widget, |
25927259 | 380 | gpointer data) |
f3074008 | 381 | { |
25927259 SC |
382 | struct gui *ui = data; |
383 | ||
25927259 | 384 | gtk_widget_set_sensitive(ui->button[START_JOB_BUTTON], 0); |
3ec62ec4 | 385 | start_job_thread(ui); |
f3074008 SC |
386 | } |
387 | ||
3e47bd25 JA |
388 | static void connect_clicked(__attribute__((unused)) GtkWidget *widget, |
389 | gpointer data) | |
390 | { | |
3ec62ec4 JA |
391 | struct gui *ui = data; |
392 | ||
393 | if (!ui->connected) { | |
394 | fio_clients_connect(); | |
395 | pthread_create(&ui->t, NULL, job_thread, NULL); | |
396 | gfio_set_connected(ui, 1); | |
397 | } else | |
398 | gfio_set_connected(ui, 0); | |
3e47bd25 JA |
399 | } |
400 | ||
f3074008 SC |
401 | static void add_button(struct gui *ui, int i, GtkWidget *buttonbox, |
402 | struct button_spec *buttonspec) | |
403 | { | |
404 | ui->button[i] = gtk_button_new_with_label(buttonspec->buttontext); | |
405 | g_signal_connect(ui->button[i], "clicked", G_CALLBACK (buttonspec->f), ui); | |
3ec62ec4 | 406 | gtk_box_pack_start(GTK_BOX (ui->buttonbox), ui->button[i], FALSE, FALSE, 3); |
f3074008 | 407 | gtk_widget_set_tooltip_text(ui->button[i], buttonspeclist[i].tooltiptext); |
3e47bd25 | 408 | gtk_widget_set_sensitive(ui->button[i], !buttonspec->start_insensitive); |
f3074008 SC |
409 | } |
410 | ||
411 | static void add_buttons(struct gui *ui, | |
412 | struct button_spec *buttonlist, | |
413 | int nbuttons) | |
414 | { | |
415 | int i; | |
416 | ||
f3074008 SC |
417 | for (i = 0; i < nbuttons; i++) |
418 | add_button(ui, i, ui->buttonbox, &buttonlist[i]); | |
419 | } | |
420 | ||
0420ba6a JA |
421 | static void on_info_bar_response(GtkWidget *widget, gint response, |
422 | gpointer data) | |
423 | { | |
424 | if (response == GTK_RESPONSE_OK) { | |
425 | gtk_widget_destroy(widget); | |
426 | ui.error_info_bar = NULL; | |
427 | } | |
428 | } | |
429 | ||
430 | void report_error(GError* error) | |
431 | { | |
432 | if (ui.error_info_bar == NULL) { | |
433 | ui.error_info_bar = gtk_info_bar_new_with_buttons(GTK_STOCK_OK, | |
434 | GTK_RESPONSE_OK, | |
435 | NULL); | |
436 | g_signal_connect(ui.error_info_bar, "response", G_CALLBACK(on_info_bar_response), NULL); | |
437 | gtk_info_bar_set_message_type(GTK_INFO_BAR(ui.error_info_bar), | |
438 | GTK_MESSAGE_ERROR); | |
439 | ||
440 | ui.error_label = gtk_label_new(error->message); | |
441 | GtkWidget *container = gtk_info_bar_get_content_area(GTK_INFO_BAR(ui.error_info_bar)); | |
442 | gtk_container_add(GTK_CONTAINER(container), ui.error_label); | |
443 | ||
444 | gtk_box_pack_start(GTK_BOX(ui.vbox), ui.error_info_bar, FALSE, FALSE, 0); | |
445 | gtk_widget_show_all(ui.vbox); | |
446 | } else { | |
447 | char buffer[256]; | |
448 | snprintf(buffer, sizeof(buffer), "Failed to open file."); | |
449 | gtk_label_set(GTK_LABEL(ui.error_label), buffer); | |
450 | } | |
451 | } | |
452 | ||
453 | static void file_open(GtkWidget *w, gpointer data) | |
454 | { | |
455 | GtkWidget *dialog; | |
456 | GSList *filenames, *fn_glist; | |
457 | GtkFileFilter *filter; | |
458 | ||
459 | dialog = gtk_file_chooser_dialog_new("Open File", | |
460 | GTK_WINDOW(ui.window), | |
461 | GTK_FILE_CHOOSER_ACTION_OPEN, | |
462 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
463 | GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, | |
464 | NULL); | |
465 | gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(dialog), TRUE); | |
466 | ||
467 | filter = gtk_file_filter_new(); | |
468 | gtk_file_filter_add_pattern(filter, "*.fio"); | |
469 | gtk_file_filter_add_pattern(filter, "*.job"); | |
470 | gtk_file_filter_add_mime_type(filter, "text/fio"); | |
471 | gtk_file_filter_set_name(filter, "Fio job file"); | |
472 | gtk_file_chooser_set_filter(GTK_FILE_CHOOSER(dialog), filter); | |
473 | ||
474 | if (gtk_dialog_run(GTK_DIALOG(dialog)) != GTK_RESPONSE_ACCEPT) { | |
475 | gtk_widget_destroy(dialog); | |
476 | return; | |
477 | } | |
478 | ||
479 | fn_glist = gtk_file_chooser_get_filenames(GTK_FILE_CHOOSER(dialog)); | |
480 | filenames = fn_glist; | |
481 | while (filenames != NULL) { | |
482 | const char *hostname; | |
3ec62ec4 JA |
483 | char *typeentry; |
484 | gint port; | |
485 | int type; | |
0420ba6a JA |
486 | |
487 | ui.job_files = realloc(ui.job_files, (ui.nr_job_files + 1) * sizeof(char *)); | |
488 | ui.job_files[ui.nr_job_files] = strdup(filenames->data); | |
489 | ui.nr_job_files++; | |
490 | ||
491 | hostname = gtk_entry_get_text(GTK_ENTRY(ui.hostname_entry)); | |
3ec62ec4 JA |
492 | port = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(ui.port_button)); |
493 | typeentry = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX_TEXT(ui.hostname_combo_box)); | |
494 | if (!typeentry || !strncmp(typeentry, "IPv4", 4)) | |
495 | type = Fio_client_ipv4; | |
496 | else if (!strncmp(typeentry, "IPv6", 4)) | |
497 | type = Fio_client_ipv6; | |
498 | else | |
499 | type = Fio_client_socket; | |
500 | g_free(typeentry); | |
501 | ||
502 | ui.client = fio_client_add_explicit(hostname, type, port); | |
503 | ui.client->client_data = &ui; | |
0420ba6a JA |
504 | #if 0 |
505 | if (error) { | |
506 | report_error(error); | |
507 | g_error_free(error); | |
508 | error = NULL; | |
509 | } | |
510 | #endif | |
511 | ||
512 | g_free(filenames->data); | |
513 | filenames = g_slist_next(filenames); | |
514 | } | |
515 | g_slist_free(fn_glist); | |
516 | gtk_widget_destroy(dialog); | |
517 | } | |
518 | ||
519 | static void file_save(GtkWidget *w, gpointer data) | |
520 | { | |
521 | GtkWidget *dialog; | |
522 | ||
523 | dialog = gtk_file_chooser_dialog_new("Save File", | |
524 | GTK_WINDOW(ui.window), | |
525 | GTK_FILE_CHOOSER_ACTION_SAVE, | |
526 | GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
527 | GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | |
528 | NULL); | |
529 | ||
530 | gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(dialog), TRUE); | |
531 | gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(dialog), "Untitled document"); | |
532 | ||
533 | if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT) { | |
534 | char *filename; | |
535 | ||
536 | filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog)); | |
537 | // save_job_file(filename); | |
538 | g_free(filename); | |
539 | } | |
540 | gtk_widget_destroy(dialog); | |
541 | } | |
542 | ||
543 | static void about_dialog(GtkWidget *w, gpointer data) | |
544 | { | |
545 | gtk_show_about_dialog(NULL, | |
546 | "program-name", "gfio", | |
547 | "comments", "Gtk2 UI for fio", | |
548 | "license", "GPLv2", | |
549 | "version", fio_version_string, | |
550 | "copyright", "Jens Axboe <axboe@kernel.dk> 2012", | |
551 | "logo-icon-name", "fio", | |
552 | /* Must be last: */ | |
553 | NULL, NULL, | |
554 | NULL); | |
555 | } | |
556 | ||
557 | static GtkActionEntry menu_items[] = { | |
558 | { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL}, | |
559 | { "HelpMenuAction", GTK_STOCK_HELP, "Help", NULL, NULL, NULL}, | |
560 | { "OpenFile", GTK_STOCK_OPEN, NULL, "<Control>O", NULL, G_CALLBACK(file_open) }, | |
561 | { "SaveFile", GTK_STOCK_SAVE, NULL, "<Control>S", NULL, G_CALLBACK(file_save) }, | |
562 | { "Quit", GTK_STOCK_QUIT, NULL, "<Control>Q", NULL, G_CALLBACK(quit_clicked) }, | |
563 | { "About", GTK_STOCK_ABOUT, NULL, NULL, NULL, G_CALLBACK(about_dialog) }, | |
564 | }; | |
3e47bd25 | 565 | static gint nmenu_items = sizeof(menu_items) / sizeof(menu_items[0]); |
0420ba6a JA |
566 | |
567 | static const gchar *ui_string = " \ | |
568 | <ui> \ | |
569 | <menubar name=\"MainMenu\"> \ | |
570 | <menu name=\"FileMenu\" action=\"FileMenuAction\"> \ | |
571 | <menuitem name=\"Open\" action=\"OpenFile\" /> \ | |
572 | <menuitem name=\"Save\" action=\"SaveFile\" /> \ | |
573 | <separator name=\"Separator\"/> \ | |
574 | <menuitem name=\"Quit\" action=\"Quit\" /> \ | |
575 | </menu> \ | |
576 | <menu name=\"Help\" action=\"HelpMenuAction\"> \ | |
577 | <menuitem name=\"About\" action=\"About\" /> \ | |
578 | </menu> \ | |
579 | </menubar> \ | |
580 | </ui> \ | |
581 | "; | |
582 | ||
583 | static GtkWidget *get_menubar_menu(GtkWidget *window, GtkUIManager *ui_manager) | |
584 | { | |
585 | GtkActionGroup *action_group = gtk_action_group_new("Menu"); | |
586 | GError *error = 0; | |
587 | ||
588 | action_group = gtk_action_group_new("Menu"); | |
589 | gtk_action_group_add_actions(action_group, menu_items, nmenu_items, 0); | |
590 | ||
591 | gtk_ui_manager_insert_action_group(ui_manager, action_group, 0); | |
592 | gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ui_manager), ui_string, -1, &error); | |
593 | ||
594 | gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ui_manager)); | |
595 | return gtk_ui_manager_get_widget(ui_manager, "/MainMenu"); | |
596 | } | |
597 | ||
598 | void gfio_ui_setup(GtkSettings *settings, GtkWidget *menubar, | |
599 | GtkWidget *vbox, GtkUIManager *ui_manager) | |
600 | { | |
601 | gtk_box_pack_start(GTK_BOX(vbox), menubar, FALSE, FALSE, 0); | |
602 | } | |
603 | ||
843ad237 JA |
604 | static GtkWidget *new_info_label_in_frame(GtkWidget *box, const char *label) |
605 | { | |
606 | GtkWidget *label_widget; | |
607 | GtkWidget *frame; | |
608 | ||
609 | frame = gtk_frame_new(label); | |
610 | label_widget = gtk_label_new(NULL); | |
611 | gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 3); | |
612 | gtk_container_add(GTK_CONTAINER(frame), label_widget); | |
613 | ||
614 | return label_widget; | |
615 | } | |
616 | ||
3ec62ec4 JA |
617 | static GtkWidget *create_text_entry(GtkWidget *hbox, GtkWidget *label, const char *defval) |
618 | { | |
619 | GtkWidget *text, *box; | |
620 | ||
621 | gtk_container_add(GTK_CONTAINER(hbox), label); | |
622 | ||
623 | box = gtk_hbox_new(FALSE, 3); | |
624 | gtk_container_add(GTK_CONTAINER(hbox), box); | |
625 | ||
626 | text = gtk_entry_new(); | |
627 | gtk_box_pack_start(GTK_BOX(box), text, TRUE, TRUE, 0); | |
628 | gtk_entry_set_text(GTK_ENTRY(text), "localhost"); | |
629 | ||
630 | return text; | |
631 | } | |
632 | ||
633 | static GtkWidget *create_spinbutton(GtkWidget *hbox, GtkWidget *label, double min, double max, double defval) | |
634 | { | |
635 | GtkWidget *button, *box; | |
636 | ||
637 | gtk_container_add(GTK_CONTAINER(hbox), label); | |
638 | ||
639 | box = gtk_hbox_new(FALSE, 3); | |
640 | gtk_container_add(GTK_CONTAINER(hbox), box); | |
641 | ||
642 | button = gtk_spin_button_new_with_range(min, max, 1.0); | |
643 | gtk_box_pack_start(GTK_BOX(box), button, TRUE, TRUE, 0); | |
644 | ||
645 | gtk_spin_button_set_update_policy(GTK_SPIN_BUTTON(button), GTK_UPDATE_IF_VALID); | |
646 | gtk_spin_button_set_value(GTK_SPIN_BUTTON(button), defval); | |
647 | ||
648 | return button; | |
649 | } | |
650 | ||
ff1f3280 SC |
651 | static void init_ui(int *argc, char **argv[], struct gui *ui) |
652 | { | |
0420ba6a JA |
653 | GtkSettings *settings; |
654 | GtkUIManager *uimanager; | |
843ad237 | 655 | GtkWidget *menu, *probe, *probe_frame, *probe_box; |
0420ba6a JA |
656 | |
657 | memset(ui, 0, sizeof(*ui)); | |
45032dd8 | 658 | |
2839f0c6 | 659 | /* Magical g*thread incantation, you just need this thread stuff. |
04cc6b77 | 660 | * Without it, the update that happens in gfio_update_thread_status |
2839f0c6 SC |
661 | * doesn't really happen in a timely fashion, you need expose events |
662 | */ | |
663 | if (!g_thread_supported ()) | |
664 | g_thread_init(NULL); | |
665 | gdk_threads_init(); | |
666 | ||
ff1f3280 | 667 | gtk_init(argc, argv); |
0420ba6a JA |
668 | settings = gtk_settings_get_default(); |
669 | gtk_settings_set_long_property(settings, "gtk_tooltip_timeout", 10, "gfio setting"); | |
670 | g_type_init(); | |
ff1f3280 SC |
671 | |
672 | ui->window = gtk_window_new(GTK_WINDOW_TOPLEVEL); | |
673 | gtk_window_set_title(GTK_WINDOW(ui->window), "fio"); | |
674 | gtk_window_set_default_size(GTK_WINDOW(ui->window), 700, 500); | |
675 | ||
0420ba6a JA |
676 | g_signal_connect(ui->window, "delete-event", G_CALLBACK(quit_clicked), NULL); |
677 | g_signal_connect(ui->window, "destroy", G_CALLBACK(quit_clicked), NULL); | |
ff1f3280 | 678 | |
5b7573ab SC |
679 | ui->vbox = gtk_vbox_new(FALSE, 0); |
680 | gtk_container_add(GTK_CONTAINER (ui->window), ui->vbox); | |
04cc6b77 | 681 | |
0420ba6a JA |
682 | uimanager = gtk_ui_manager_new(); |
683 | menu = get_menubar_menu(ui->window, uimanager); | |
684 | gfio_ui_setup(settings, menu, ui->vbox, uimanager); | |
685 | ||
c36f98d9 SC |
686 | /* |
687 | * Set up alignments for widgets at the top of ui, | |
688 | * align top left, expand horizontally but not vertically | |
689 | */ | |
690 | ui->topalign = gtk_alignment_new(0, 0, 1, 0); | |
3ec62ec4 | 691 | ui->topvbox = gtk_vbox_new(FALSE, 3); |
c36f98d9 | 692 | gtk_container_add(GTK_CONTAINER(ui->topalign), ui->topvbox); |
e164534f | 693 | gtk_box_pack_start(GTK_BOX(ui->vbox), ui->topalign, FALSE, FALSE, 0); |
c36f98d9 | 694 | |
45032dd8 SC |
695 | /* |
696 | * Set up hostname label + entry, port label + entry, | |
697 | */ | |
698 | ui->hostname_hbox = gtk_hbox_new(FALSE, 0); | |
3ec62ec4 JA |
699 | |
700 | ui->hostname_label = gtk_label_new("Hostname:"); | |
701 | ui->hostname_entry = create_text_entry(ui->hostname_hbox, ui->hostname_label, "localhost"); | |
702 | ||
45032dd8 | 703 | ui->port_label = gtk_label_new("Port:"); |
3ec62ec4 | 704 | ui->port_button = create_spinbutton(ui->hostname_hbox, ui->port_label, 1, 65535, FIO_NET_PORT); |
45032dd8 SC |
705 | |
706 | /* | |
707 | * Set up combo box for address type | |
708 | */ | |
3ec62ec4 JA |
709 | ui->hostname_combo_box = gtk_combo_box_text_new(); |
710 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ui->hostname_combo_box), "IPv4"); | |
711 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ui->hostname_combo_box), "IPv6"); | |
712 | gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ui->hostname_combo_box), "local socket"); | |
713 | gtk_combo_box_set_active(GTK_COMBO_BOX(ui->hostname_combo_box), 0); | |
714 | ||
715 | gtk_container_add(GTK_CONTAINER(ui->hostname_hbox), ui->hostname_combo_box); | |
716 | gtk_container_add(GTK_CONTAINER(ui->topvbox), ui->hostname_hbox); | |
45032dd8 | 717 | |
3e47bd25 | 718 | probe = gtk_frame_new("Job"); |
843ad237 JA |
719 | gtk_box_pack_start(GTK_BOX(ui->topvbox), probe, TRUE, FALSE, 3); |
720 | probe_frame = gtk_vbox_new(FALSE, 3); | |
721 | gtk_container_add(GTK_CONTAINER(probe), probe_frame); | |
722 | ||
723 | probe_box = gtk_hbox_new(FALSE, 3); | |
724 | gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3); | |
843ad237 JA |
725 | ui->probe.hostname = new_info_label_in_frame(probe_box, "Host"); |
726 | ui->probe.os = new_info_label_in_frame(probe_box, "OS"); | |
727 | ui->probe.arch = new_info_label_in_frame(probe_box, "Architecture"); | |
728 | ui->probe.fio_ver = new_info_label_in_frame(probe_box, "Fio version"); | |
729 | ||
3e47bd25 JA |
730 | probe_box = gtk_hbox_new(FALSE, 3); |
731 | gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3); | |
807f9971 JA |
732 | |
733 | ui->eta.name = new_info_label_in_frame(probe_box, "Name"); | |
734 | ui->eta.iotype = new_info_label_in_frame(probe_box, "IO"); | |
735 | ui->eta.ioengine = new_info_label_in_frame(probe_box, "IO Engine"); | |
736 | ui->eta.iodepth = new_info_label_in_frame(probe_box, "IO Depth"); | |
3e47bd25 JA |
737 | ui->eta.jobs = new_info_label_in_frame(probe_box, "Jobs"); |
738 | ui->eta.files = new_info_label_in_frame(probe_box, "Open files"); | |
739 | ||
740 | probe_box = gtk_hbox_new(FALSE, 3); | |
741 | gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3); | |
742 | ui->eta.read_bw = new_info_label_in_frame(probe_box, "Read BW"); | |
743 | ui->eta.read_iops = new_info_label_in_frame(probe_box, "IOPS"); | |
807f9971 JA |
744 | ui->eta.write_bw = new_info_label_in_frame(probe_box, "Write BW"); |
745 | ui->eta.write_iops = new_info_label_in_frame(probe_box, "IOPS"); | |
3e47bd25 | 746 | |
807f9971 JA |
747 | /* |
748 | * Only add this if we have a commit rate | |
749 | */ | |
750 | #if 0 | |
3e47bd25 JA |
751 | probe_box = gtk_hbox_new(FALSE, 3); |
752 | gtk_box_pack_start(GTK_BOX(probe_frame), probe_box, TRUE, FALSE, 3); | |
807f9971 JA |
753 | |
754 | ui->eta.cr_bw = new_info_label_in_frame(probe_box, "Commit BW"); | |
755 | ui->eta.cr_iops = new_info_label_in_frame(probe_box, "Commit IOPS"); | |
756 | ||
3e47bd25 JA |
757 | ui->eta.cw_bw = new_info_label_in_frame(probe_box, "Commit BW"); |
758 | ui->eta.cw_iops = new_info_label_in_frame(probe_box, "Commit IOPS"); | |
807f9971 | 759 | #endif |
3e47bd25 | 760 | |
736f2dff SC |
761 | /* |
762 | * Add a text box for text op messages | |
763 | */ | |
764 | ui->textview = gtk_text_view_new(); | |
765 | ui->text = gtk_text_view_get_buffer(GTK_TEXT_VIEW(ui->textview)); | |
766 | gtk_text_buffer_set_text(ui->text, "", -1); | |
767 | gtk_text_view_set_editable(GTK_TEXT_VIEW(ui->textview), FALSE); | |
768 | gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(ui->textview), FALSE); | |
769 | ui->scrolled_window = gtk_scrolled_window_new(NULL, NULL); | |
770 | gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(ui->scrolled_window), | |
771 | GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); | |
772 | gtk_container_add(GTK_CONTAINER(ui->scrolled_window), ui->textview); | |
e164534f SC |
773 | gtk_box_pack_start(GTK_BOX(ui->vbox), ui->scrolled_window, |
774 | TRUE, TRUE, 0); | |
736f2dff | 775 | |
c36f98d9 SC |
776 | /* |
777 | * Set up alignments for widgets at the bottom of ui, | |
778 | * align bottom left, expand horizontally but not vertically | |
779 | */ | |
780 | ui->bottomalign = gtk_alignment_new(0, 1, 1, 0); | |
781 | ui->buttonbox = gtk_hbox_new(FALSE, 0); | |
782 | gtk_container_add(GTK_CONTAINER(ui->bottomalign), ui->buttonbox); | |
e164534f SC |
783 | gtk_box_pack_start(GTK_BOX(ui->vbox), ui->bottomalign, |
784 | FALSE, FALSE, 0); | |
c36f98d9 | 785 | |
f3074008 | 786 | add_buttons(ui, buttonspeclist, ARRAYSIZE(buttonspeclist)); |
3ec62ec4 JA |
787 | |
788 | /* | |
789 | * Set up thread status progress bar | |
790 | */ | |
791 | ui->thread_status_pb = gtk_progress_bar_new(); | |
792 | gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), 0.0); | |
793 | gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), "No jobs running"); | |
794 | gtk_container_add(GTK_CONTAINER(ui->buttonbox), ui->thread_status_pb); | |
795 | ||
796 | ||
ff1f3280 SC |
797 | gtk_widget_show_all(ui->window); |
798 | } | |
799 | ||
8232e285 | 800 | int main(int argc, char *argv[], char *envp[]) |
ff1f3280 | 801 | { |
8232e285 SC |
802 | if (initialize_fio(envp)) |
803 | return 1; | |
0420ba6a JA |
804 | if (fio_init_options()) |
805 | return 1; | |
a1820207 | 806 | |
3ec62ec4 | 807 | fio_debug = ~0UL; |
ff1f3280 | 808 | init_ui(&argc, &argv, &ui); |
5b7573ab | 809 | |
2839f0c6 | 810 | gdk_threads_enter(); |
ff1f3280 | 811 | gtk_main(); |
2839f0c6 | 812 | gdk_threads_leave(); |
ff1f3280 SC |
813 | return 0; |
814 | } |