gcompat: get closer to working with gtk3
[fio.git] / gclient.c
1 #include <malloc.h>
2 #include <string.h>
3
4 #include <glib.h>
5 #include <cairo.h>
6 #include <gtk/gtk.h>
7
8 #include "fio.h"
9 #include "gfio.h"
10 #include "ghelpers.h"
11 #include "goptions.h"
12 #include "gerror.h"
13 #include "graph.h"
14 #include "gclient.h"
15
16 static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts,
17                             struct group_run_stats *rs);
18
19 static gboolean results_window_delete(GtkWidget *w, gpointer data)
20 {
21         struct gui_entry *ge = (struct gui_entry *) data;
22
23         gtk_widget_destroy(w);
24         ge->results_window = NULL;
25         ge->results_notebook = NULL;
26         return TRUE;
27 }
28
29 static void results_close(GtkWidget *w, gpointer *data)
30 {
31         struct gui_entry *ge = (struct gui_entry *) data;
32
33         gtk_widget_destroy(ge->results_window);
34 }
35
36 static GtkActionEntry results_menu_items[] = {
37         { "FileMenuAction", GTK_STOCK_FILE, "File", NULL, NULL, NULL},
38         { "GraphMenuAction", GTK_STOCK_FILE, "Graph", NULL, NULL, NULL},
39         { "CloseFile", GTK_STOCK_CLOSE, "Close", "<Control>W", NULL, G_CALLBACK(results_close) },
40 };
41 static gint results_nmenu_items = sizeof(results_menu_items) / sizeof(results_menu_items[0]);
42
43 static const gchar *results_ui_string = " \
44         <ui> \
45                 <menubar name=\"MainMenu\"> \
46                         <menu name=\"FileMenu\" action=\"FileMenuAction\"> \
47                                 <menuitem name=\"Close\" action=\"CloseFile\" /> \
48                         </menu> \
49                         <menu name=\"GraphMenu\" action=\"GraphMenuAction\"> \
50                         </menu>\
51                 </menubar> \
52         </ui> \
53 ";
54
55 static GtkWidget *get_results_menubar(GtkWidget *window, struct gui_entry *ge)
56 {
57         GtkActionGroup *action_group;
58         GtkWidget *widget;
59         GError *error = 0;
60
61         ge->results_uimanager = gtk_ui_manager_new();
62
63         action_group = gtk_action_group_new("ResultsMenu");
64         gtk_action_group_add_actions(action_group, results_menu_items, results_nmenu_items, ge);
65
66         gtk_ui_manager_insert_action_group(ge->results_uimanager, action_group, 0);
67         gtk_ui_manager_add_ui_from_string(GTK_UI_MANAGER(ge->results_uimanager), results_ui_string, -1, &error);
68
69         gtk_window_add_accel_group(GTK_WINDOW(window), gtk_ui_manager_get_accel_group(ge->results_uimanager));
70
71         widget = gtk_ui_manager_get_widget(ge->results_uimanager, "/MainMenu");
72         return widget;
73 }
74
75 static GtkWidget *get_results_window(struct gui_entry *ge)
76 {
77         GtkWidget *win, *notebook, *vbox;
78
79         if (ge->results_window)
80                 return ge->results_notebook;
81
82         win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
83         gtk_window_set_title(GTK_WINDOW(win), "Results");
84         gtk_window_set_default_size(GTK_WINDOW(win), 1024, 768);
85         g_signal_connect(win, "delete-event", G_CALLBACK(results_window_delete), ge);
86         g_signal_connect(win, "destroy", G_CALLBACK(results_window_delete), ge);
87
88         vbox = gtk_vbox_new(FALSE, 0);
89         gtk_container_add(GTK_CONTAINER(win), vbox);
90
91         ge->results_menu = get_results_menubar(win, ge);
92         gtk_box_pack_start(GTK_BOX(vbox), ge->results_menu, FALSE, FALSE, 0);
93
94         notebook = gtk_notebook_new();
95         gtk_notebook_set_scrollable(GTK_NOTEBOOK(notebook), 1);
96         gtk_notebook_popup_enable(GTK_NOTEBOOK(notebook));
97         gtk_container_add(GTK_CONTAINER(vbox), notebook);
98
99         ge->results_window = win;
100         ge->results_notebook = notebook;
101         return ge->results_notebook;
102 }
103
104 static void gfio_text_op(struct fio_client *client, struct fio_net_cmd *cmd)
105 {
106         struct cmd_text_pdu *p = (struct cmd_text_pdu *) cmd->payload;
107         struct gfio_client *gc = client->client_data;
108         struct gui_entry *ge = gc->ge;
109         struct gui *ui = ge->ui;
110         GtkTreeIter iter;
111         struct tm *tm;
112         time_t sec;
113         char tmp[64], timebuf[80];
114
115         sec = p->log_sec;
116         tm = localtime(&sec);
117         strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", tm);
118         sprintf(timebuf, "%s.%03ld", tmp, (long) p->log_usec / 1000);
119
120         gdk_threads_enter();
121
122         gtk_list_store_append(ui->log_model, &iter);
123         gtk_list_store_set(ui->log_model, &iter, 0, timebuf, -1);
124         gtk_list_store_set(ui->log_model, &iter, 1, client->hostname, -1);
125         gtk_list_store_set(ui->log_model, &iter, 2, p->level, -1);
126         gtk_list_store_set(ui->log_model, &iter, 3, p->buf, -1);
127
128         if (p->level == FIO_LOG_ERR)
129                 gfio_view_log(ui);
130
131         gdk_threads_leave();
132 }
133
134 static void disk_util_destroy(GtkWidget *w, gpointer data)
135 {
136         struct gui_entry *ge = (struct gui_entry *) data;
137
138         ge->disk_util_vbox = NULL;
139         gtk_widget_destroy(w);
140 }
141
142 static GtkWidget *gfio_disk_util_get_vbox(struct gui_entry *ge)
143 {
144         GtkWidget *vbox, *box, *scroll, *res_notebook;
145
146         if (ge->disk_util_vbox)
147                 return ge->disk_util_vbox;
148
149         scroll = get_scrolled_window(5);
150         vbox = gtk_vbox_new(FALSE, 3);
151         box = gtk_hbox_new(FALSE, 0);
152         gtk_box_pack_start(GTK_BOX(vbox), box, FALSE, FALSE, 5);
153
154         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
155         res_notebook = get_results_window(ge);
156
157         gtk_notebook_append_page(GTK_NOTEBOOK(res_notebook), scroll, gtk_label_new("Disk utilization"));
158         ge->disk_util_vbox = box;
159         g_signal_connect(vbox, "destroy", G_CALLBACK(disk_util_destroy), ge);
160
161         return ge->disk_util_vbox;
162 }
163
164 static int __gfio_disk_util_show(GtkWidget *res_notebook,
165                                  struct gfio_client *gc, struct cmd_du_pdu *p)
166 {
167         GtkWidget *box, *frame, *entry, *vbox, *util_vbox;
168         struct gui_entry *ge = gc->ge;
169         double util;
170         char tmp[16];
171
172         util_vbox = gfio_disk_util_get_vbox(ge);
173
174         vbox = gtk_vbox_new(FALSE, 3);
175         gtk_container_add(GTK_CONTAINER(util_vbox), vbox);
176
177         frame = gtk_frame_new((char *) p->dus.name);
178         gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 2);
179
180         box = gtk_vbox_new(FALSE, 3);
181         gtk_container_add(GTK_CONTAINER(frame), box);
182
183         frame = gtk_frame_new("Read");
184         gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 2);
185         vbox = gtk_hbox_new(TRUE, 3);
186         gtk_container_add(GTK_CONTAINER(frame), vbox);
187         entry = new_info_entry_in_frame(vbox, "IOs");
188         entry_set_int_value(entry, p->dus.ios[0]);
189         entry = new_info_entry_in_frame(vbox, "Merges");
190         entry_set_int_value(entry, p->dus.merges[0]);
191         entry = new_info_entry_in_frame(vbox, "Sectors");
192         entry_set_int_value(entry, p->dus.sectors[0]);
193         entry = new_info_entry_in_frame(vbox, "Ticks");
194         entry_set_int_value(entry, p->dus.ticks[0]);
195
196         frame = gtk_frame_new("Write");
197         gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 2);
198         vbox = gtk_hbox_new(TRUE, 3);
199         gtk_container_add(GTK_CONTAINER(frame), vbox);
200         entry = new_info_entry_in_frame(vbox, "IOs");
201         entry_set_int_value(entry, p->dus.ios[1]);
202         entry = new_info_entry_in_frame(vbox, "Merges");
203         entry_set_int_value(entry, p->dus.merges[1]);
204         entry = new_info_entry_in_frame(vbox, "Sectors");
205         entry_set_int_value(entry, p->dus.sectors[1]);
206         entry = new_info_entry_in_frame(vbox, "Ticks");
207         entry_set_int_value(entry, p->dus.ticks[1]);
208
209         frame = gtk_frame_new("Shared");
210         gtk_box_pack_start(GTK_BOX(box), frame, FALSE, FALSE, 2);
211         vbox = gtk_hbox_new(TRUE, 3);
212         gtk_container_add(GTK_CONTAINER(frame), vbox);
213         entry = new_info_entry_in_frame(vbox, "IO ticks");
214         entry_set_int_value(entry, p->dus.io_ticks);
215         entry = new_info_entry_in_frame(vbox, "Time in queue");
216         entry_set_int_value(entry, p->dus.time_in_queue);
217
218         util = 0.0;
219         if (p->dus.msec)
220                 util = (double) 100 * p->dus.io_ticks / (double) p->dus.msec;
221         if (util > 100.0)
222                 util = 100.0;
223
224         sprintf(tmp, "%3.2f%%", util);
225         entry = new_info_entry_in_frame(vbox, "Disk utilization");
226         gtk_entry_set_text(GTK_ENTRY(entry), tmp);
227
228         gtk_widget_show_all(ge->results_window);
229         return 0;
230 }
231
232 static int gfio_disk_util_show(struct gfio_client *gc)
233 {
234         struct gui_entry *ge = gc->ge;
235         GtkWidget *res_notebook;
236         int i;
237
238         if (!gc->nr_du)
239                 return 1;
240
241         res_notebook = get_results_window(ge);
242
243         for (i = 0; i < gc->nr_du; i++) {
244                 struct cmd_du_pdu *p = &gc->du[i];
245
246                 __gfio_disk_util_show(res_notebook, gc, p);
247         }
248
249         gtk_widget_show_all(ge->results_window);
250         return 0;
251 }
252
253 static void gfio_disk_util_op(struct fio_client *client, struct fio_net_cmd *cmd)
254 {
255         struct cmd_du_pdu *p = (struct cmd_du_pdu *) cmd->payload;
256         struct gfio_client *gc = client->client_data;
257         struct gui_entry *ge = gc->ge;
258         unsigned int nr = gc->nr_du;
259
260         gc->du = realloc(gc->du, (nr + 1) * sizeof(struct cmd_du_pdu));
261         memcpy(&gc->du[nr], p, sizeof(*p));
262         gc->nr_du++;
263
264         gdk_threads_enter();
265         if (ge->results_window)
266                 __gfio_disk_util_show(ge->results_notebook, gc, p);
267         else
268                 gfio_disk_util_show(gc);
269         gdk_threads_leave();
270 }
271
272 extern int sum_stat_clients;
273 extern struct thread_stat client_ts;
274 extern struct group_run_stats client_gs;
275
276 static int sum_stat_nr;
277
278 static void gfio_thread_status_op(struct fio_client *client,
279                                   struct fio_net_cmd *cmd)
280 {
281         struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
282
283         gfio_display_ts(client, &p->ts, &p->rs);
284
285         if (sum_stat_clients == 1)
286                 return;
287
288         sum_thread_stats(&client_ts, &p->ts, sum_stat_nr);
289         sum_group_stats(&client_gs, &p->rs);
290
291         client_ts.members++;
292         client_ts.thread_number = p->ts.thread_number;
293         client_ts.groupid = p->ts.groupid;
294
295         if (++sum_stat_nr == sum_stat_clients) {
296                 strcpy(client_ts.name, "All clients");
297                 gfio_display_ts(client, &client_ts, &client_gs);
298         }
299 }
300
301 static void gfio_group_stats_op(struct fio_client *client,
302                                 struct fio_net_cmd *cmd)
303 {
304         /* We're ignoring group stats for now */
305 }
306
307 static void gfio_update_thread_status(struct gui_entry *ge,
308                                       char *status_message, double perc)
309 {
310         static char message[100];
311         const char *m = message;
312
313         strncpy(message, status_message, sizeof(message) - 1);
314         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ge->thread_status_pb), m);
315         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ge->thread_status_pb), perc / 100.0);
316         gtk_widget_queue_draw(ge->ui->window);
317 }
318
319 static void gfio_update_thread_status_all(struct gui *ui, char *status_message,
320                                           double perc)
321 {
322         static char message[100];
323         const char *m = message;
324
325         strncpy(message, status_message, sizeof(message) - 1);
326         gtk_progress_bar_set_text(GTK_PROGRESS_BAR(ui->thread_status_pb), m);
327         gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(ui->thread_status_pb), perc / 100.0);
328         gtk_widget_queue_draw(ui->window);
329 }
330
331 /*
332  * Client specific ETA
333  */
334 static void gfio_update_client_eta(struct fio_client *client, struct jobs_eta *je)
335 {
336         struct gfio_client *gc = client->client_data;
337         struct gui_entry *ge = gc->ge;
338         static int eta_good;
339         char eta_str[128];
340         char output[256];
341         char tmp[32];
342         double perc = 0.0;
343         int i2p = 0;
344
345         gdk_threads_enter();
346
347         eta_str[0] = '\0';
348         output[0] = '\0';
349
350         if (je->eta_sec != INT_MAX && je->elapsed_sec) {
351                 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
352                 eta_to_str(eta_str, je->eta_sec);
353         }
354
355         sprintf(tmp, "%u", je->nr_running);
356         gtk_entry_set_text(GTK_ENTRY(ge->eta.jobs), tmp);
357         sprintf(tmp, "%u", je->files_open);
358         gtk_entry_set_text(GTK_ENTRY(ge->eta.files), tmp);
359
360 #if 0
361         if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
362         if (je->m_rate || je->t_rate) {
363                 char *tr, *mr;
364
365                 mr = num2str(je->m_rate, 4, 0, i2p);
366                 tr = num2str(je->t_rate, 4, 0, i2p);
367                 gtk_entry_set_text(GTK_ENTRY(ge->eta);
368                 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
369                 free(tr);
370                 free(mr);
371         } else if (je->m_iops || je->t_iops)
372                 p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
373
374         gtk_entry_set_text(GTK_ENTRY(ge->eta.cr_bw), "---");
375         gtk_entry_set_text(GTK_ENTRY(ge->eta.cr_iops), "---");
376         gtk_entry_set_text(GTK_ENTRY(ge->eta.cw_bw), "---");
377         gtk_entry_set_text(GTK_ENTRY(ge->eta.cw_iops), "---");
378 #endif
379
380         if (je->eta_sec != INT_MAX && je->nr_running) {
381                 char *iops_str[2];
382                 char *rate_str[2];
383
384                 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
385                         strcpy(output, "-.-% done");
386                 else {
387                         eta_good = 1;
388                         perc *= 100.0;
389                         sprintf(output, "%3.1f%% done", perc);
390                 }
391
392                 rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
393                 rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
394
395                 iops_str[0] = num2str(je->iops[0], 4, 1, 0);
396                 iops_str[1] = num2str(je->iops[1], 4, 1, 0);
397
398                 gtk_entry_set_text(GTK_ENTRY(ge->eta.read_bw), rate_str[0]);
399                 gtk_entry_set_text(GTK_ENTRY(ge->eta.read_iops), iops_str[0]);
400                 gtk_entry_set_text(GTK_ENTRY(ge->eta.write_bw), rate_str[1]);
401                 gtk_entry_set_text(GTK_ENTRY(ge->eta.write_iops), iops_str[1]);
402
403                 graph_add_xy_data(ge->graphs.iops_graph, ge->graphs.read_iops, je->elapsed_sec, je->iops[0], iops_str[0]);
404                 graph_add_xy_data(ge->graphs.iops_graph, ge->graphs.write_iops, je->elapsed_sec, je->iops[1], iops_str[1]);
405                 graph_add_xy_data(ge->graphs.bandwidth_graph, ge->graphs.read_bw, je->elapsed_sec, je->rate[0], rate_str[0]);
406                 graph_add_xy_data(ge->graphs.bandwidth_graph, ge->graphs.write_bw, je->elapsed_sec, je->rate[1], rate_str[1]);
407
408                 free(rate_str[0]);
409                 free(rate_str[1]);
410                 free(iops_str[0]);
411                 free(iops_str[1]);
412         }
413
414         if (eta_str[0]) {
415                 char *dst = output + strlen(output);
416
417                 sprintf(dst, " - %s", eta_str);
418         }
419                 
420         gfio_update_thread_status(ge, output, perc);
421         gdk_threads_leave();
422 }
423
424 /*
425  * Update ETA in main window for all clients
426  */
427 static void gfio_update_all_eta(struct jobs_eta *je)
428 {
429         struct gui *ui = &main_ui;
430         static int eta_good;
431         char eta_str[128];
432         char output[256];
433         double perc = 0.0;
434         int i2p = 0;
435
436         gdk_threads_enter();
437
438         eta_str[0] = '\0';
439         output[0] = '\0';
440
441         if (je->eta_sec != INT_MAX && je->elapsed_sec) {
442                 perc = (double) je->elapsed_sec / (double) (je->elapsed_sec + je->eta_sec);
443                 eta_to_str(eta_str, je->eta_sec);
444         }
445
446 #if 0
447         if (je->m_rate[0] || je->m_rate[1] || je->t_rate[0] || je->t_rate[1]) {
448         if (je->m_rate || je->t_rate) {
449                 char *tr, *mr;
450
451                 mr = num2str(je->m_rate, 4, 0, i2p);
452                 tr = num2str(je->t_rate, 4, 0, i2p);
453                 gtk_entry_set_text(GTK_ENTRY(ui->eta);
454                 p += sprintf(p, ", CR=%s/%s KB/s", tr, mr);
455                 free(tr);
456                 free(mr);
457         } else if (je->m_iops || je->t_iops)
458                 p += sprintf(p, ", CR=%d/%d IOPS", je->t_iops, je->m_iops);
459
460         gtk_entry_set_text(GTK_ENTRY(ui->eta.cr_bw), "---");
461         gtk_entry_set_text(GTK_ENTRY(ui->eta.cr_iops), "---");
462         gtk_entry_set_text(GTK_ENTRY(ui->eta.cw_bw), "---");
463         gtk_entry_set_text(GTK_ENTRY(ui->eta.cw_iops), "---");
464 #endif
465
466         entry_set_int_value(ui->eta.jobs, je->nr_running);
467
468         if (je->eta_sec != INT_MAX && je->nr_running) {
469                 char *iops_str[2];
470                 char *rate_str[2];
471
472                 if ((!je->eta_sec && !eta_good) || je->nr_ramp == je->nr_running)
473                         strcpy(output, "-.-% done");
474                 else {
475                         eta_good = 1;
476                         perc *= 100.0;
477                         sprintf(output, "%3.1f%% done", perc);
478                 }
479
480                 rate_str[0] = num2str(je->rate[0], 5, 10, i2p);
481                 rate_str[1] = num2str(je->rate[1], 5, 10, i2p);
482
483                 iops_str[0] = num2str(je->iops[0], 4, 1, 0);
484                 iops_str[1] = num2str(je->iops[1], 4, 1, 0);
485
486                 gtk_entry_set_text(GTK_ENTRY(ui->eta.read_bw), rate_str[0]);
487                 gtk_entry_set_text(GTK_ENTRY(ui->eta.read_iops), iops_str[0]);
488                 gtk_entry_set_text(GTK_ENTRY(ui->eta.write_bw), rate_str[1]);
489                 gtk_entry_set_text(GTK_ENTRY(ui->eta.write_iops), iops_str[1]);
490
491                 graph_add_xy_data(ui->graphs.iops_graph, ui->graphs.read_iops, je->elapsed_sec, je->iops[0], iops_str[0]);
492                 graph_add_xy_data(ui->graphs.iops_graph, ui->graphs.write_iops, je->elapsed_sec, je->iops[1], iops_str[1]);
493                 graph_add_xy_data(ui->graphs.bandwidth_graph, ui->graphs.read_bw, je->elapsed_sec, je->rate[0], rate_str[0]);
494                 graph_add_xy_data(ui->graphs.bandwidth_graph, ui->graphs.write_bw, je->elapsed_sec, je->rate[1], rate_str[1]);
495
496                 free(rate_str[0]);
497                 free(rate_str[1]);
498                 free(iops_str[0]);
499                 free(iops_str[1]);
500         }
501
502         if (eta_str[0]) {
503                 char *dst = output + strlen(output);
504
505                 sprintf(dst, " - %s", eta_str);
506         }
507                 
508         gfio_update_thread_status_all(ui, output, perc);
509         gdk_threads_leave();
510 }
511
512 static void gfio_probe_op(struct fio_client *client, struct fio_net_cmd *cmd)
513 {
514         struct cmd_probe_pdu *probe = (struct cmd_probe_pdu *) cmd->payload;
515         struct gfio_client *gc = client->client_data;
516         struct gui_entry *ge = gc->ge;
517         const char *os, *arch;
518         char buf[64];
519
520         os = fio_get_os_string(probe->os);
521         if (!os)
522                 os = "unknown";
523
524         arch = fio_get_arch_string(probe->arch);
525         if (!arch)
526                 os = "unknown";
527
528         if (!client->name)
529                 client->name = strdup((char *) probe->hostname);
530
531         gdk_threads_enter();
532
533         gtk_label_set_text(GTK_LABEL(ge->probe.hostname), (char *) probe->hostname);
534         gtk_label_set_text(GTK_LABEL(ge->probe.os), os);
535         gtk_label_set_text(GTK_LABEL(ge->probe.arch), arch);
536         sprintf(buf, "%u.%u.%u", probe->fio_major, probe->fio_minor, probe->fio_patch);
537         gtk_label_set_text(GTK_LABEL(ge->probe.fio_ver), buf);
538
539         gfio_set_state(ge, GE_STATE_CONNECTED);
540
541         gdk_threads_leave();
542 }
543
544 static void gfio_quit_op(struct fio_client *client, struct fio_net_cmd *cmd)
545 {
546         struct gfio_client *gc = client->client_data;
547
548         gdk_threads_enter();
549         gfio_set_state(gc->ge, GE_STATE_NEW);
550         gdk_threads_leave();
551 }
552
553 static struct thread_options *gfio_client_add_job(struct gfio_client *gc,
554                         struct thread_options_pack *top)
555 {
556         struct gfio_client_options *gco;
557
558         gco = calloc(1, sizeof(*gco));
559         convert_thread_options_to_cpu(&gco->o, top);
560         INIT_FLIST_HEAD(&gco->list);
561         flist_add_tail(&gco->list, &gc->o_list);
562         gc->o_list_nr = 1;
563         return &gco->o;
564 }
565
566 static void gfio_add_job_op(struct fio_client *client, struct fio_net_cmd *cmd)
567 {
568         struct cmd_add_job_pdu *p = (struct cmd_add_job_pdu *) cmd->payload;
569         struct gfio_client *gc = client->client_data;
570         struct gui_entry *ge = gc->ge;
571         struct thread_options *o;
572         char *c1, *c2, *c3, *c4;
573         char tmp[80];
574
575         p->thread_number = le32_to_cpu(p->thread_number);
576         p->groupid = le32_to_cpu(p->groupid);
577         o = gfio_client_add_job(gc, &p->top);
578
579         gdk_threads_enter();
580
581         gtk_combo_box_text_append_text(GTK_COMBO_BOX_TEXT(ge->eta.names), (gchar *) o->name);
582         gtk_combo_box_set_active(GTK_COMBO_BOX(ge->eta.names), 0);
583
584         sprintf(tmp, "%s %s", o->odirect ? "direct" : "buffered", ddir_str(o->td_ddir));
585         multitext_add_entry(&ge->eta.iotype, tmp);
586
587         c1 = fio_uint_to_kmg(o->min_bs[DDIR_READ]);
588         c2 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]);
589         c3 = fio_uint_to_kmg(o->min_bs[DDIR_READ]);
590         c4 = fio_uint_to_kmg(o->max_bs[DDIR_WRITE]);
591         sprintf(tmp, "%s-%s/%s-%s", c1, c2, c3, c4);
592         free(c1);
593         free(c2);
594         free(c3);
595         free(c4);
596         multitext_add_entry(&ge->eta.bs, tmp);
597
598         multitext_add_entry(&ge->eta.ioengine, (const char *) o->ioengine);
599
600         sprintf(tmp, "%u", o->iodepth);
601         multitext_add_entry(&ge->eta.iodepth, tmp);
602
603         multitext_set_entry(&ge->eta.iotype, 0);
604         multitext_set_entry(&ge->eta.bs, 0);
605         multitext_set_entry(&ge->eta.ioengine, 0);
606         multitext_set_entry(&ge->eta.iodepth, 0);
607
608         gfio_set_state(ge, GE_STATE_JOB_SENT);
609
610         gdk_threads_leave();
611 }
612
613 static void gfio_client_timed_out(struct fio_client *client)
614 {
615         struct gfio_client *gc = client->client_data;
616         char buf[256];
617
618         gdk_threads_enter();
619
620         gfio_set_state(gc->ge, GE_STATE_NEW);
621         clear_ge_ui_info(gc->ge);
622
623         sprintf(buf, "Client %s: timeout talking to server.\n", client->hostname);
624         gfio_report_info(gc->ge->ui, "Network timeout", buf);
625
626         gdk_threads_leave();
627 }
628
629 static void gfio_client_stop(struct fio_client *client, struct fio_net_cmd *cmd)
630 {
631         struct gfio_client *gc = client->client_data;
632
633         gdk_threads_enter();
634
635         gfio_set_state(gc->ge, GE_STATE_JOB_DONE);
636
637         if (gc->err_entry)
638                 entry_set_int_value(gc->err_entry, client->error);
639
640         gdk_threads_leave();
641 }
642
643 static void gfio_client_start(struct fio_client *client, struct fio_net_cmd *cmd)
644 {
645         struct gfio_client *gc = client->client_data;
646
647         gdk_threads_enter();
648         gfio_set_state(gc->ge, GE_STATE_JOB_STARTED);
649         gdk_threads_leave();
650 }
651
652 static void gfio_client_job_start(struct fio_client *client, struct fio_net_cmd *cmd)
653 {
654         struct gfio_client *gc = client->client_data;
655
656         gdk_threads_enter();
657         gfio_set_state(gc->ge, GE_STATE_JOB_RUNNING);
658         gdk_threads_leave();
659 }
660
661 static void gfio_client_iolog(struct fio_client *client, struct cmd_iolog_pdu *pdu)
662 {
663         printf("got iolog: name=%s, type=%u, entries=%u\n", pdu->name, pdu->log_type, pdu->nr_samples);
664         free(pdu);
665 }
666
667 static void gfio_add_total_depths_tree(GtkListStore *model,
668                                        struct thread_stat *ts, unsigned int len)
669 {
670         double io_u_dist[FIO_IO_U_MAP_NR];
671         GtkTreeIter iter;
672         /* Bits 1-6, and 8 */
673         const int add_mask = 0x17e;
674         int i, j;
675
676         stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
677
678         gtk_list_store_append(model, &iter);
679
680         gtk_list_store_set(model, &iter, 0, "Total", -1);
681
682         for (i = 1, j = 0; i < len; i++) {
683                 char fbuf[32];
684
685                 if (!(add_mask & (1UL << (i - 1))))
686                         sprintf(fbuf, "0.0%%");
687                 else {
688                         sprintf(fbuf, "%3.1f%%", io_u_dist[j]);
689                         j++;
690                 }
691
692                 gtk_list_store_set(model, &iter, i, fbuf, -1);
693         }
694
695 }
696
697 static void gfio_add_end_results(struct gfio_client *gc, struct thread_stat *ts,
698                                  struct group_run_stats *rs)
699 {
700         unsigned int nr = gc->nr_results;
701
702         gc->results = realloc(gc->results, (nr + 1) * sizeof(struct end_results));
703         memcpy(&gc->results[nr].ts, ts, sizeof(*ts));
704         memcpy(&gc->results[nr].gs, rs, sizeof(*rs));
705         gc->nr_results++;
706 }
707
708 static void gfio_add_sc_depths_tree(GtkListStore *model,
709                                     struct thread_stat *ts, unsigned int len,
710                                     int submit)
711 {
712         double io_u_dist[FIO_IO_U_MAP_NR];
713         GtkTreeIter iter;
714         /* Bits 0, and 3-8 */
715         const int add_mask = 0x1f9;
716         int i, j;
717
718         if (submit)
719                 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
720         else
721                 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
722
723         gtk_list_store_append(model, &iter);
724
725         gtk_list_store_set(model, &iter, 0, submit ? "Submit" : "Complete", -1);
726
727         for (i = 1, j = 0; i < len; i++) {
728                 char fbuf[32];
729
730                 if (!(add_mask & (1UL << (i - 1))))
731                         sprintf(fbuf, "0.0%%");
732                 else {
733                         sprintf(fbuf, "%3.1f%%", io_u_dist[j]);
734                         j++;
735                 }
736
737                 gtk_list_store_set(model, &iter, i, fbuf, -1);
738         }
739
740 }
741
742 static void gfio_show_io_depths(GtkWidget *vbox, struct thread_stat *ts)
743 {
744         GtkWidget *frame, *box, *tree_view = NULL;
745         GtkTreeSelection *selection;
746         GtkListStore *model;
747         int i;
748         const char *labels[] = { "Depth", "0", "1", "2", "4", "8", "16", "32", "64", ">= 64" };
749         const int nr_labels = ARRAY_SIZE(labels);
750         GType types[nr_labels];
751
752         frame = gtk_frame_new("IO depths");
753         gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
754
755         box = gtk_hbox_new(FALSE, 3);
756         gtk_container_add(GTK_CONTAINER(frame), box);
757
758         for (i = 0; i < nr_labels; i++)
759                 types[i] = G_TYPE_STRING;
760
761         model = gtk_list_store_newv(nr_labels, types);
762
763         tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
764         gtk_widget_set_can_focus(tree_view, FALSE);
765
766         g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
767                 "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH, NULL);
768
769         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
770         gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
771
772         for (i = 0; i < nr_labels; i++)
773                 tree_view_column(tree_view, i, labels[i], ALIGN_RIGHT | UNSORTABLE);
774
775         gfio_add_total_depths_tree(model, ts, nr_labels);
776         gfio_add_sc_depths_tree(model, ts, nr_labels, 1);
777         gfio_add_sc_depths_tree(model, ts, nr_labels, 0);
778
779         gtk_box_pack_start(GTK_BOX(box), tree_view, TRUE, TRUE, 3);
780 }
781
782 static void gfio_show_cpu_usage(GtkWidget *vbox, struct thread_stat *ts)
783 {
784         GtkWidget *box, *frame, *entry;
785         double usr_cpu, sys_cpu;
786         unsigned long runtime;
787         char tmp[32];
788
789         runtime = ts->total_run_time;
790         if (runtime) {
791                 double runt = (double) runtime;
792
793                 usr_cpu = (double) ts->usr_time * 100 / runt;
794                 sys_cpu = (double) ts->sys_time * 100 / runt;
795         } else {
796                 usr_cpu = 0;
797                 sys_cpu = 0;
798         }
799
800         frame = gtk_frame_new("OS resources");
801         gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
802
803         box = gtk_hbox_new(FALSE, 3);
804         gtk_container_add(GTK_CONTAINER(frame), box);
805
806         entry = new_info_entry_in_frame(box, "User CPU");
807         sprintf(tmp, "%3.2f%%", usr_cpu);
808         gtk_entry_set_text(GTK_ENTRY(entry), tmp);
809         entry = new_info_entry_in_frame(box, "System CPU");
810         sprintf(tmp, "%3.2f%%", sys_cpu);
811         gtk_entry_set_text(GTK_ENTRY(entry), tmp);
812         entry = new_info_entry_in_frame(box, "Context switches");
813         entry_set_int_value(entry, ts->ctx);
814         entry = new_info_entry_in_frame(box, "Major faults");
815         entry_set_int_value(entry, ts->majf);
816         entry = new_info_entry_in_frame(box, "Minor faults");
817         entry_set_int_value(entry, ts->minf);
818 }
819
820 static GtkWidget *gfio_output_lat_buckets(double *lat, const char **labels,
821                                           int num)
822 {
823         GtkWidget *tree_view;
824         GtkTreeSelection *selection;
825         GtkListStore *model;
826         GtkTreeIter iter;
827         GType *types;
828         int i;
829
830         types = malloc(num * sizeof(GType));
831
832         for (i = 0; i < num; i++)
833                 types[i] = G_TYPE_STRING;
834
835         model = gtk_list_store_newv(num, types);
836         free(types);
837         types = NULL;
838
839         tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
840         gtk_widget_set_can_focus(tree_view, FALSE);
841
842         g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
843                 "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH, NULL);
844
845         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
846         gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
847
848         for (i = 0; i < num; i++)
849                 tree_view_column(tree_view, i, labels[i], ALIGN_RIGHT | UNSORTABLE);
850
851         gtk_list_store_append(model, &iter);
852
853         for (i = 0; i < num; i++) {
854                 char fbuf[32];
855
856                 if (lat[i] <= 0.0)
857                         sprintf(fbuf, "0.00");
858                 else
859                         sprintf(fbuf, "%3.2f%%", lat[i]);
860
861                 gtk_list_store_set(model, &iter, i, fbuf, -1);
862         }
863
864         return tree_view;
865 }
866
867 static struct graph *setup_lat_bucket_graph(const char *title, double *lat,
868                                             const char **labels,
869                                             unsigned int len,
870                                             double xdim, double ydim)
871 {
872         struct graph *g;
873         int i;
874
875         g = graph_new(xdim, ydim, gfio_graph_font);
876         graph_title(g, title);
877         graph_x_title(g, "Buckets");
878         graph_y_title(g, "Percent");
879
880         for (i = 0; i < len; i++) {
881                 graph_label_t l;
882
883                 l = graph_add_label(g, labels[i]);
884                 graph_add_data(g, l, lat[i]);
885         }
886
887         return g;
888 }
889
890 static int on_expose_lat_drawing_area(GtkWidget *w, GdkEvent *event, gpointer p)
891 {
892         struct graph *g = p;
893         cairo_t *cr;
894
895         cr = gdk_cairo_create(gtk_widget_get_window(w));
896 #if 0
897         if (graph_has_tooltips(g)) {
898                 g_object_set(w, "has-tooltip", TRUE, NULL);
899                 g_signal_connect(w, "query-tooltip", G_CALLBACK(clat_graph_tooltip), g);
900         }
901 #endif
902         cairo_set_source_rgb(cr, 0, 0, 0);
903         bar_graph_draw(g, cr);
904         cairo_destroy(cr);
905
906         return FALSE;
907 }
908
909 static gint on_config_lat_drawing_area(GtkWidget *w, GdkEventConfigure *event,
910                                        gpointer data)
911 {
912         guint width = gtk_widget_get_allocated_width(w);
913         guint height = gtk_widget_get_allocated_height(w);
914         struct graph *g = data;
915
916         graph_set_size(g, width, height);
917         graph_set_size(g, width, height);
918         graph_set_position(g, 0, 0);
919         return TRUE;
920 }
921
922 static void gfio_show_latency_buckets(struct gfio_client *gc, GtkWidget *vbox,
923                                       struct thread_stat *ts)
924 {
925         double io_u_lat[FIO_IO_U_LAT_U_NR + FIO_IO_U_LAT_M_NR];
926         const char *ranges[] = { "2u", "4u", "10u", "20u", "50u", "100u",
927                                  "250u", "500u", "750u", "1m", "2m",
928                                  "4m", "10m", "20m", "50m", "100m",
929                                  "250m", "500m", "750m", "1s", "2s", ">= 2s" };
930         int start, end, i;
931         const int total = FIO_IO_U_LAT_U_NR + FIO_IO_U_LAT_M_NR;
932         GtkWidget *frame, *tree_view, *hbox, *completion_vbox, *drawing_area;
933         struct gui_entry *ge = gc->ge;
934
935         stat_calc_lat_u(ts, io_u_lat);
936         stat_calc_lat_m(ts, &io_u_lat[FIO_IO_U_LAT_U_NR]);
937
938         /*
939          * Found out which first bucket has entries, and which last bucket
940          */
941         start = end = -1U;
942         for (i = 0; i < total; i++) {
943                 if (io_u_lat[i] == 0.00)
944                         continue;
945
946                 if (start == -1U)
947                         start = i;
948                 end = i;
949         }
950
951         /*
952          * No entries...
953          */
954         if (start == -1U)
955                 return;
956                 
957         tree_view = gfio_output_lat_buckets(&io_u_lat[start], &ranges[start], end - start + 1);
958         ge->lat_bucket_graph = setup_lat_bucket_graph("Latency Buckets", &io_u_lat[start], &ranges[start], end - start + 1, 700.0, 300.0);
959
960         frame = gtk_frame_new("Latency buckets");
961         gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
962
963         completion_vbox = gtk_vbox_new(FALSE, 3);
964         gtk_container_add(GTK_CONTAINER(frame), completion_vbox);
965         hbox = gtk_hbox_new(FALSE, 3);
966         gtk_container_add(GTK_CONTAINER(completion_vbox), hbox);
967
968         drawing_area = gtk_drawing_area_new();
969         gtk_widget_set_size_request(GTK_WIDGET(drawing_area), 700, 300);
970         gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &gfio_color_white);
971         gtk_container_add(GTK_CONTAINER(completion_vbox), drawing_area);
972         g_signal_connect(G_OBJECT(drawing_area), "expose_event", G_CALLBACK(on_expose_lat_drawing_area), ge->lat_bucket_graph);
973         g_signal_connect(G_OBJECT(drawing_area), "configure_event", G_CALLBACK(on_config_lat_drawing_area), ge->lat_bucket_graph);
974
975         gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, TRUE, 3);
976 }
977
978 static void gfio_show_lat(GtkWidget *vbox, const char *name, unsigned long min,
979                           unsigned long max, double mean, double dev)
980 {
981         const char *base = "(usec)";
982         GtkWidget *hbox, *label, *frame;
983         char *minp, *maxp;
984         char tmp[64];
985
986         if (!usec_to_msec(&min, &max, &mean, &dev))
987                 base = "(msec)";
988
989         minp = num2str(min, 6, 1, 0);
990         maxp = num2str(max, 6, 1, 0);
991
992         sprintf(tmp, "%s %s", name, base);
993         frame = gtk_frame_new(tmp);
994         gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
995
996         hbox = gtk_hbox_new(FALSE, 3);
997         gtk_container_add(GTK_CONTAINER(frame), hbox);
998
999         label = new_info_label_in_frame(hbox, "Minimum");
1000         gtk_label_set_text(GTK_LABEL(label), minp);
1001         label = new_info_label_in_frame(hbox, "Maximum");
1002         gtk_label_set_text(GTK_LABEL(label), maxp);
1003         label = new_info_label_in_frame(hbox, "Average");
1004         sprintf(tmp, "%5.02f", mean);
1005         gtk_label_set_text(GTK_LABEL(label), tmp);
1006         label = new_info_label_in_frame(hbox, "Standard deviation");
1007         sprintf(tmp, "%5.02f", dev);
1008         gtk_label_set_text(GTK_LABEL(label), tmp);
1009
1010         free(minp);
1011         free(maxp);
1012 }
1013
1014 static GtkWidget *gfio_output_clat_percentiles(unsigned int *ovals,
1015                                                fio_fp64_t *plist,
1016                                                unsigned int len,
1017                                                const char *base,
1018                                                unsigned int scale)
1019 {
1020         GType types[FIO_IO_U_LIST_MAX_LEN];
1021         GtkWidget *tree_view;
1022         GtkTreeSelection *selection;
1023         GtkListStore *model;
1024         GtkTreeIter iter;
1025         int i;
1026
1027         for (i = 0; i < len; i++)
1028                 types[i] = G_TYPE_INT;
1029
1030         model = gtk_list_store_newv(len, types);
1031
1032         tree_view = gtk_tree_view_new_with_model(GTK_TREE_MODEL(model));
1033         gtk_widget_set_can_focus(tree_view, FALSE);
1034
1035         g_object_set(G_OBJECT(tree_view), "headers-visible", TRUE,
1036                 "enable-grid-lines", GTK_TREE_VIEW_GRID_LINES_BOTH, NULL);
1037
1038         selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(tree_view));
1039         gtk_tree_selection_set_mode(GTK_TREE_SELECTION(selection), GTK_SELECTION_BROWSE);
1040
1041         for (i = 0; i < len; i++) {
1042                 char fbuf[8];
1043
1044                 sprintf(fbuf, "%2.2f%%", plist[i].u.f);
1045                 tree_view_column(tree_view, i, fbuf, ALIGN_RIGHT | UNSORTABLE);
1046         }
1047
1048         gtk_list_store_append(model, &iter);
1049
1050         for (i = 0; i < len; i++) {
1051                 if (scale)
1052                         ovals[i] = (ovals[i] + 999) / 1000;
1053                 gtk_list_store_set(model, &iter, i, ovals[i], -1);
1054         }
1055
1056         return tree_view;
1057 }
1058
1059 static struct graph *setup_clat_graph(char *title, unsigned int *ovals,
1060                                       fio_fp64_t *plist,
1061                                       unsigned int len,
1062                                       double xdim, double ydim)
1063 {
1064         struct graph *g;
1065         int i;
1066
1067         g = graph_new(xdim, ydim, gfio_graph_font);
1068         graph_title(g, title);
1069         graph_x_title(g, "Percentile");
1070         graph_y_title(g, "Time");
1071
1072         for (i = 0; i < len; i++) {
1073                 graph_label_t l;
1074                 char fbuf[8];
1075
1076                 sprintf(fbuf, "%2.2f%%", plist[i].u.f);
1077                 l = graph_add_label(g, fbuf);
1078                 graph_add_data(g, l, (double) ovals[i]);
1079         }
1080
1081         return g;
1082 }
1083
1084 static void gfio_show_clat_percentiles(struct gfio_client *gc,
1085                                        GtkWidget *vbox, struct thread_stat *ts,
1086                                        int ddir)
1087 {
1088         unsigned int *io_u_plat = ts->io_u_plat[ddir];
1089         unsigned long nr = ts->clat_stat[ddir].samples;
1090         fio_fp64_t *plist = ts->percentile_list;
1091         unsigned int *ovals, len, minv, maxv, scale_down;
1092         const char *base;
1093         GtkWidget *tree_view, *frame, *hbox, *drawing_area, *completion_vbox;
1094         struct gui_entry *ge = gc->ge;
1095         char tmp[64];
1096
1097         len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
1098         if (!len)
1099                 goto out;
1100
1101         /*
1102          * We default to usecs, but if the value range is such that we
1103          * should scale down to msecs, do that.
1104          */
1105         if (minv > 2000 && maxv > 99999) {
1106                 scale_down = 1;
1107                 base = "msec";
1108         } else {
1109                 scale_down = 0;
1110                 base = "usec";
1111         }
1112
1113         sprintf(tmp, "Completion percentiles (%s)", base);
1114         tree_view = gfio_output_clat_percentiles(ovals, plist, len, base, scale_down);
1115         ge->clat_graph = setup_clat_graph(tmp, ovals, plist, len, 700.0, 300.0);
1116
1117         frame = gtk_frame_new(tmp);
1118         gtk_box_pack_start(GTK_BOX(vbox), frame, FALSE, FALSE, 5);
1119
1120         completion_vbox = gtk_vbox_new(FALSE, 3);
1121         gtk_container_add(GTK_CONTAINER(frame), completion_vbox);
1122         hbox = gtk_hbox_new(FALSE, 3);
1123         gtk_container_add(GTK_CONTAINER(completion_vbox), hbox);
1124         drawing_area = gtk_drawing_area_new();
1125         gtk_widget_set_size_request(GTK_WIDGET(drawing_area), 700, 300);
1126         gtk_widget_modify_bg(drawing_area, GTK_STATE_NORMAL, &gfio_color_white);
1127         gtk_container_add(GTK_CONTAINER(completion_vbox), drawing_area);
1128         g_signal_connect(G_OBJECT(drawing_area), "expose_event", G_CALLBACK(on_expose_lat_drawing_area), ge->clat_graph);
1129         g_signal_connect(G_OBJECT(drawing_area), "configure_event", G_CALLBACK(on_config_lat_drawing_area), ge->clat_graph);
1130
1131         gtk_box_pack_start(GTK_BOX(hbox), tree_view, TRUE, TRUE, 3);
1132 out:
1133         if (ovals)
1134                 free(ovals);
1135 }
1136
1137 #define GFIO_CLAT       1
1138 #define GFIO_SLAT       2
1139 #define GFIO_LAT        4
1140
1141 static void gfio_show_ddir_status(struct gfio_client *gc, GtkWidget *mbox,
1142                                   struct group_run_stats *rs,
1143                                   struct thread_stat *ts, int ddir)
1144 {
1145         const char *ddir_label[2] = { "Read", "Write" };
1146         GtkWidget *frame, *label, *box, *vbox, *main_vbox;
1147         unsigned long min[3], max[3], runt;
1148         unsigned long long bw, iops;
1149         unsigned int flags = 0;
1150         double mean[3], dev[3];
1151         char *io_p, *bw_p, *iops_p;
1152         int i2p;
1153
1154         if (!ts->runtime[ddir])
1155                 return;
1156
1157         i2p = is_power_of_2(rs->kb_base);
1158         runt = ts->runtime[ddir];
1159
1160         bw = (1000 * ts->io_bytes[ddir]) / runt;
1161         io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
1162         bw_p = num2str(bw, 6, 1, i2p);
1163
1164         iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
1165         iops_p = num2str(iops, 6, 1, 0);
1166
1167         box = gtk_hbox_new(FALSE, 3);
1168         gtk_box_pack_start(GTK_BOX(mbox), box, TRUE, FALSE, 3);
1169
1170         frame = gtk_frame_new(ddir_label[ddir]);
1171         gtk_box_pack_start(GTK_BOX(box), frame, TRUE, TRUE, 5);
1172
1173         main_vbox = gtk_vbox_new(FALSE, 3);
1174         gtk_container_add(GTK_CONTAINER(frame), main_vbox);
1175
1176         box = gtk_hbox_new(FALSE, 3);
1177         gtk_box_pack_start(GTK_BOX(main_vbox), box, TRUE, FALSE, 3);
1178
1179         label = new_info_label_in_frame(box, "IO");
1180         gtk_label_set_text(GTK_LABEL(label), io_p);
1181         label = new_info_label_in_frame(box, "Bandwidth");
1182         gtk_label_set_text(GTK_LABEL(label), bw_p);
1183         label = new_info_label_in_frame(box, "IOPS");
1184         gtk_label_set_text(GTK_LABEL(label), iops_p);
1185         label = new_info_label_in_frame(box, "Runtime (msec)");
1186         label_set_int_value(label, ts->runtime[ddir]);
1187
1188         if (calc_lat(&ts->bw_stat[ddir], &min[0], &max[0], &mean[0], &dev[0])) {
1189                 double p_of_agg = 100.0;
1190                 const char *bw_str = "KB";
1191                 char tmp[32];
1192
1193                 if (rs->agg[ddir]) {
1194                         p_of_agg = mean[0] * 100 / (double) rs->agg[ddir];
1195                         if (p_of_agg > 100.0)
1196                                 p_of_agg = 100.0;
1197                 }
1198
1199                 if (mean[0] > 999999.9) {
1200                         min[0] /= 1000.0;
1201                         max[0] /= 1000.0;
1202                         mean[0] /= 1000.0;
1203                         dev[0] /= 1000.0;
1204                         bw_str = "MB";
1205                 }
1206
1207                 sprintf(tmp, "Bandwidth (%s)", bw_str);
1208                 frame = gtk_frame_new(tmp);
1209                 gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 5);
1210
1211                 box = gtk_hbox_new(FALSE, 3);
1212                 gtk_container_add(GTK_CONTAINER(frame), box);
1213
1214                 label = new_info_label_in_frame(box, "Minimum");
1215                 label_set_int_value(label, min[0]);
1216                 label = new_info_label_in_frame(box, "Maximum");
1217                 label_set_int_value(label, max[0]);
1218                 label = new_info_label_in_frame(box, "Percentage of jobs");
1219                 sprintf(tmp, "%3.2f%%", p_of_agg);
1220                 gtk_label_set_text(GTK_LABEL(label), tmp);
1221                 label = new_info_label_in_frame(box, "Average");
1222                 sprintf(tmp, "%5.02f", mean[0]);
1223                 gtk_label_set_text(GTK_LABEL(label), tmp);
1224                 label = new_info_label_in_frame(box, "Standard deviation");
1225                 sprintf(tmp, "%5.02f", dev[0]);
1226                 gtk_label_set_text(GTK_LABEL(label), tmp);
1227         }
1228
1229         if (calc_lat(&ts->slat_stat[ddir], &min[0], &max[0], &mean[0], &dev[0]))
1230                 flags |= GFIO_SLAT;
1231         if (calc_lat(&ts->clat_stat[ddir], &min[1], &max[1], &mean[1], &dev[1]))
1232                 flags |= GFIO_CLAT;
1233         if (calc_lat(&ts->lat_stat[ddir], &min[2], &max[2], &mean[2], &dev[2]))
1234                 flags |= GFIO_LAT;
1235
1236         if (flags) {
1237                 frame = gtk_frame_new("Latency");
1238                 gtk_box_pack_start(GTK_BOX(main_vbox), frame, FALSE, FALSE, 5);
1239
1240                 vbox = gtk_vbox_new(FALSE, 3);
1241                 gtk_container_add(GTK_CONTAINER(frame), vbox);
1242
1243                 if (flags & GFIO_SLAT)
1244                         gfio_show_lat(vbox, "Submission latency", min[0], max[0], mean[0], dev[0]);
1245                 if (flags & GFIO_CLAT)
1246                         gfio_show_lat(vbox, "Completion latency", min[1], max[1], mean[1], dev[1]);
1247                 if (flags & GFIO_LAT)
1248                         gfio_show_lat(vbox, "Total latency", min[2], max[2], mean[2], dev[2]);
1249         }
1250
1251         if (ts->clat_percentiles)
1252                 gfio_show_clat_percentiles(gc, main_vbox, ts, ddir);
1253
1254         free(io_p);
1255         free(bw_p);
1256         free(iops_p);
1257 }
1258
1259 static void __gfio_display_end_results(GtkWidget *win, struct gfio_client *gc,
1260                                        struct thread_stat *ts,
1261                                        struct group_run_stats *rs)
1262 {
1263         GtkWidget *box, *vbox, *entry, *scroll;
1264
1265         scroll = gtk_scrolled_window_new(NULL, NULL);
1266         gtk_container_set_border_width(GTK_CONTAINER(scroll), 5);
1267         gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC);
1268
1269         vbox = gtk_vbox_new(FALSE, 3);
1270
1271         box = gtk_hbox_new(FALSE, 0);
1272         gtk_box_pack_start(GTK_BOX(vbox), box, TRUE, FALSE, 5);
1273
1274         gtk_scrolled_window_add_with_viewport(GTK_SCROLLED_WINDOW(scroll), vbox);
1275
1276         gtk_notebook_append_page(GTK_NOTEBOOK(win), scroll, gtk_label_new(ts->name));
1277
1278         entry = new_info_entry_in_frame(box, "Name");
1279         gtk_entry_set_text(GTK_ENTRY(entry), ts->name);
1280         if (strlen(ts->description)) {
1281                 entry = new_info_entry_in_frame(box, "Description");
1282                 gtk_entry_set_text(GTK_ENTRY(entry), ts->description);
1283         }
1284         entry = new_info_entry_in_frame(box, "Group ID");
1285         entry_set_int_value(entry, ts->groupid);
1286         entry = new_info_entry_in_frame(box, "Jobs");
1287         entry_set_int_value(entry, ts->members);
1288         gc->err_entry = entry = new_info_entry_in_frame(box, "Error");
1289         entry_set_int_value(entry, ts->error);
1290         entry = new_info_entry_in_frame(box, "PID");
1291         entry_set_int_value(entry, ts->pid);
1292
1293         if (ts->io_bytes[DDIR_READ])
1294                 gfio_show_ddir_status(gc, vbox, rs, ts, DDIR_READ);
1295         if (ts->io_bytes[DDIR_WRITE])
1296                 gfio_show_ddir_status(gc, vbox, rs, ts, DDIR_WRITE);
1297
1298         gfio_show_latency_buckets(gc, vbox, ts);
1299         gfio_show_cpu_usage(vbox, ts);
1300         gfio_show_io_depths(vbox, ts);
1301 }
1302
1303 void gfio_display_end_results(struct gfio_client *gc)
1304 {
1305         struct gui_entry *ge = gc->ge;
1306         GtkWidget *res_notebook;
1307         int i;
1308
1309         res_notebook = get_results_window(ge);
1310
1311         for (i = 0; i < gc->nr_results; i++) {
1312                 struct end_results *e = &gc->results[i];
1313
1314                 __gfio_display_end_results(res_notebook, gc, &e->ts, &e->gs);
1315         }
1316
1317         if (gfio_disk_util_show(gc))
1318                 gtk_widget_show_all(ge->results_window);
1319 }
1320
1321 static void gfio_display_ts(struct fio_client *client, struct thread_stat *ts,
1322                             struct group_run_stats *rs)
1323 {
1324         struct gfio_client *gc = client->client_data;
1325         struct gui_entry *ge = gc->ge;
1326
1327         gfio_add_end_results(gc, ts, rs);
1328
1329         gdk_threads_enter();
1330         if (ge->results_window)
1331                 __gfio_display_end_results(ge->results_notebook, gc, ts, rs);
1332         else
1333                 gfio_display_end_results(gc);
1334         gdk_threads_leave();
1335 }
1336
1337 static void gfio_client_removed(struct fio_client *client)
1338 {
1339         struct gfio_client *gc = client->client_data;
1340
1341         assert(gc->client == client);
1342         fio_put_client(gc->client);
1343         gc->client = NULL;
1344 }
1345
1346 struct client_ops gfio_client_ops = {
1347         .text                   = gfio_text_op,
1348         .disk_util              = gfio_disk_util_op,
1349         .thread_status          = gfio_thread_status_op,
1350         .group_stats            = gfio_group_stats_op,
1351         .jobs_eta               = gfio_update_client_eta,
1352         .eta                    = gfio_update_all_eta,
1353         .probe                  = gfio_probe_op,
1354         .quit                   = gfio_quit_op,
1355         .add_job                = gfio_add_job_op,
1356         .timed_out              = gfio_client_timed_out,
1357         .stop                   = gfio_client_stop,
1358         .start                  = gfio_client_start,
1359         .job_start              = gfio_client_job_start,
1360         .iolog                  = gfio_client_iolog,
1361         .removed                = gfio_client_removed,
1362         .eta_msec               = FIO_CLIENT_DEF_ETA_MSEC,
1363         .stay_connected         = 1,
1364         .client_type            = FIO_CLIENT_TYPE_GUI,
1365 };