Skip to content

Instantly share code, notes, and snippets.

@asomers
Last active December 20, 2015 09:09
Show Gist options
  • Save asomers/6105396 to your computer and use it in GitHub Desktop.
Save asomers/6105396 to your computer and use it in GitHub Desktop.
Make --minimal work in client/server mode in fio The second revision makes --output-format=json work in client/server mode
--- ../../work/fio-2.1.1/client.c 2013-06-05 08:55:53.000000000 -0600
+++ client.c 2013-08-29 16:01:10.978230695 -0600
@@ -23,6 +23,7 @@
#include "server.h"
#include "flist.h"
#include "hash.h"
+#include "json.h"
static void handle_du(struct fio_client *client, struct fio_net_cmd *cmd);
static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd);
@@ -64,6 +65,9 @@
#define FIO_CLIENT_HASH_MASK (FIO_CLIENT_HASH_SZ - 1)
static struct flist_head client_hash[FIO_CLIENT_HASH_SZ];
+struct json_object *json_root;
+struct json_array *json_array;
+
static void fio_client_add_hash(struct fio_client *client)
{
int bucket = hash_long(client->fd, FIO_CLIENT_HASH_BITS);
@@ -788,11 +792,12 @@
dst->unified_rw_rep = le32_to_cpu(src->unified_rw_rep);
}
+
static void handle_ts(struct fio_client *client, struct fio_net_cmd *cmd)
{
struct cmd_ts_pdu *p = (struct cmd_ts_pdu *) cmd->payload;
- show_thread_status(&p->ts, &p->rs);
+ show_thread_status_all(&p->ts, &p->rs, json_array);
client->did_stat = 1;
if (!do_output_all_clients)
@@ -808,7 +813,7 @@
if (++sum_stat_nr == sum_stat_clients) {
strcpy(client_ts.name, "All clients");
- show_thread_status(&client_ts, &client_gs);
+ show_thread_status_all(&client_ts, &client_gs, json_array);
}
}
@@ -937,7 +942,8 @@
void fio_client_dec_jobs_eta(struct client_eta *eta, client_eta_op eta_fn)
{
if (!--eta->pending) {
- eta_fn(&eta->eta);
+ if (calc_thread_status(&eta->eta, 0))
+ eta_fn(&eta->eta);
free(eta);
}
}
@@ -1026,9 +1032,10 @@
sprintf(bit, "%d-bit", probe->bpp * 8);
probe->flags = le64_to_cpu(probe->flags);
- log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s, flags=%lx\n",
- probe->hostname, probe->bigendian, bit, os, arch,
- probe->fio_version, (unsigned long) probe->flags);
+ if (output_format == FIO_OUTPUT_NORMAL)
+ log_info("hostname=%s, be=%u, %s, os=%s, arch=%s, fio=%s, flags=%lx\n",
+ probe->hostname, probe->bigendian, bit, os, arch,
+ probe->fio_version, (unsigned long) probe->flags);
if (!client->name)
client->name = strdup((char *) probe->hostname);
@@ -1410,6 +1417,14 @@
init_thread_stat(&client_ts);
init_group_run_stat(&client_gs);
+ if (output_format == FIO_OUTPUT_JSON) {
+ json_root = json_create_object();
+ json_object_add_value_string(json_root, "fio version",
+ fio_version_string);
+ json_array = json_create_array();
+ json_object_add_value_array(json_root, "jobs", json_array);
+ }
+
while (!exit_backend && nr_clients) {
struct flist_head *entry, *tmp;
struct fio_client *client;
@@ -1476,6 +1491,12 @@
}
}
+ if (output_format == FIO_OUTPUT_JSON) {
+ json_print_object(json_root);
+ log_info("\n");
+ json_free_object(json_root);
+ }
+
free(pfds);
return retval;
}
--- ../../work/fio-2.1.1/stat.c 2013-06-05 08:55:53.000000000 -0600
+++ stat.c 2013-08-29 15:40:10.843230186 -0600
@@ -499,7 +499,7 @@
show_lat_m(io_u_lat_m);
}
-void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
+static void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
{
double usr_cpu, sys_cpu;
unsigned long runtime;
@@ -885,7 +885,8 @@
log_info(";%3.2f%%", io_u_lat_m[i]);
/* disk util stats, if any */
- show_disk_util(1, NULL);
+ if (is_backend)
+ show_disk_util(1, NULL);
/* Additional output if continue_on_error set - default off*/
if (ts->continue_on_error)
@@ -993,6 +994,21 @@
log_err("fio: bad terse version!? %d\n", terse_version);
}
+void show_thread_status_all(struct thread_stat *ts, struct group_run_stats *rs, struct json_array* array)
+{
+ if (is_backend)
+ fio_server_send_ts(ts, rs);
+ else if (output_format == FIO_OUTPUT_TERSE)
+ show_thread_status_terse(ts, rs);
+ else if ((output_format == FIO_OUTPUT_JSON) && (array != NULL)){
+ struct json_object *tmp = show_thread_status_json(ts, rs);
+
+ json_array_add_value_object(array, tmp);
+ } else
+ show_thread_status(ts, rs);
+}
+
+
static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
{
double mean, S;
@@ -1317,16 +1333,7 @@
for (i = 0; i < nr_ts; i++) {
ts = &threadstats[i];
rs = &runstats[ts->groupid];
-
- if (is_backend)
- fio_server_send_ts(ts, rs);
- else if (output_format == FIO_OUTPUT_TERSE)
- show_thread_status_terse(ts, rs);
- else if (output_format == FIO_OUTPUT_JSON) {
- struct json_object *tmp = show_thread_status_json(ts, rs);
- json_array_add_value_object(array, tmp);
- } else
- show_thread_status(ts, rs);
+ show_thread_status_all(ts, rs, array);
}
if (output_format == FIO_OUTPUT_JSON) {
/* disk util stats, if any */
--- ../../work/fio-2.1.1/stat.h 2013-06-05 08:55:53.000000000 -0600
+++ stat.h 2013-08-29 16:07:52.067230164 -0600
@@ -2,6 +2,7 @@
#define FIO_STAT_H
#include "iolog.h"
+#include "json.h"
struct group_run_stats {
uint64_t max_run[DDIR_RWDIR_CNT], min_run[DDIR_RWDIR_CNT];
@@ -202,7 +203,9 @@
extern void stat_init(void);
extern void stat_exit(void);
-extern void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs);
+extern void show_thread_status_all(struct thread_stat *ts,
+ struct group_run_stats *rs,
+ struct json_array*);
extern void show_group_stats(struct group_run_stats *rs);
extern int calc_thread_status(struct jobs_eta *je, int force);
extern void display_thread_status(struct jobs_eta *je);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment