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