+static void client_flush_hist_samples(FILE *f, int hist_coarseness, void *samples,
+ uint64_t sample_size)
+{
+ struct io_sample *s;
+ int log_offset;
+ uint64_t i, j, nr_samples;
+ struct io_u_plat_entry *entry;
+ unsigned int *io_u_plat;
+
+ int stride = 1 << hist_coarseness;
+
+ if (!sample_size)
+ return;
+
+ s = __get_sample(samples, 0, 0);
+ log_offset = (s->__ddir & LOG_OFFSET_SAMPLE_BIT) != 0;
+
+ nr_samples = sample_size / __log_entry_sz(log_offset);
+
+ for (i = 0; i < nr_samples; i++) {
+
+ s = (struct io_sample *)((char *)__get_sample(samples, log_offset, i) +
+ i * sizeof(struct io_u_plat_entry));
+
+ entry = s->data.plat_entry;
+ io_u_plat = entry->io_u_plat;
+
+ fprintf(f, "%lu, %u, %u, ", (unsigned long) s->time,
+ io_sample_ddir(s), s->bs);
+ for (j = 0; j < FIO_IO_U_PLAT_NR - stride; j += stride) {
+ fprintf(f, "%lu, ", hist_sum(j, stride, io_u_plat, NULL));
+ }
+ fprintf(f, "%lu\n", (unsigned long)
+ hist_sum(FIO_IO_U_PLAT_NR - stride, stride, io_u_plat, NULL));
+
+ }
+}
+
+static int fio_client_handle_iolog(struct fio_client *client,
+ struct fio_net_cmd *cmd)
+{
+ struct cmd_iolog_pdu *pdu;
+ bool store_direct;
+ char *log_pathname;
+
+ pdu = convert_iolog(cmd, &store_direct);
+ if (!pdu) {
+ log_err("fio: failed converting IO log\n");
+ return 1;
+ }
+
+ /* allocate buffer big enough for next sprintf() call */
+ log_pathname = malloc(10 + strlen((char *)pdu->name) +
+ strlen(client->hostname));
+ if (!log_pathname) {
+ log_err("fio: memory allocation of unique pathname failed\n");
+ return -1;
+ }
+ /* generate a unique pathname for the log file using hostname */
+ sprintf(log_pathname, "%s.%s", pdu->name, client->hostname);
+
+ if (store_direct) {
+ ssize_t ret;
+ size_t sz;
+ int fd;
+
+ fd = open((const char *) log_pathname,
+ O_WRONLY | O_CREAT | O_TRUNC, 0644);
+ if (fd < 0) {
+ log_err("fio: open log %s: %s\n",
+ log_pathname, strerror(errno));
+ return 1;
+ }
+
+ sz = cmd->pdu_len - sizeof(*pdu);
+ ret = write(fd, pdu->samples, sz);
+ close(fd);
+
+ if (ret != sz) {
+ log_err("fio: short write on compressed log\n");
+ return 1;
+ }
+
+ return 0;
+ } else {
+ FILE *f;
+ f = fopen((const char *) log_pathname, "w");
+ if (!f) {
+ log_err("fio: fopen log %s : %s\n",
+ log_pathname, strerror(errno));
+ return 1;
+ }
+
+ if (pdu->log_type == IO_LOG_TYPE_HIST) {
+ client_flush_hist_samples(f, pdu->log_hist_coarseness, pdu->samples,
+ pdu->nr_samples * sizeof(struct io_sample));
+ } else {
+ flush_samples(f, pdu->samples,
+ pdu->nr_samples * sizeof(struct io_sample));
+ }
+ fclose(f);
+ return 0;
+ }
+}
+