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