12 #include "lib/ieee754.h"
14 #include "lib/getrusage.h"
17 void update_rusage_stat(struct thread_data *td)
19 struct thread_stat *ts = &td->ts;
21 fio_getrusage(&td->ru_end);
22 ts->usr_time += mtime_since(&td->ru_start.ru_utime,
23 &td->ru_end.ru_utime);
24 ts->sys_time += mtime_since(&td->ru_start.ru_stime,
25 &td->ru_end.ru_stime);
26 ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw
27 - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
28 ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt;
29 ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt;
31 memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
35 * Given a latency, return the index of the corresponding bucket in
36 * the structure tracking percentiles.
38 * (1) find the group (and error bits) that the value (latency)
39 * belongs to by looking at its MSB. (2) find the bucket number in the
40 * group by looking at the index bits.
43 static unsigned int plat_val_to_idx(unsigned int val)
45 unsigned int msb, error_bits, base, offset, idx;
47 /* Find MSB starting from bit 0 */
51 msb = (sizeof(val)*8) - __builtin_clz(val) - 1;
54 * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
55 * all bits of the sample as index
57 if (msb <= FIO_IO_U_PLAT_BITS)
60 /* Compute the number of error bits to discard*/
61 error_bits = msb - FIO_IO_U_PLAT_BITS;
63 /* Compute the number of buckets before the group */
64 base = (error_bits + 1) << FIO_IO_U_PLAT_BITS;
67 * Discard the error bits and apply the mask to find the
68 * index for the buckets in the group
70 offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits);
72 /* Make sure the index does not exceed (array size - 1) */
73 idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1) ?
74 (base + offset) : (FIO_IO_U_PLAT_NR - 1);
80 * Convert the given index of the bucket array to the value
81 * represented by the bucket
83 static unsigned int plat_idx_to_val(unsigned int idx)
85 unsigned int error_bits, k, base;
87 assert(idx < FIO_IO_U_PLAT_NR);
89 /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
90 * all bits of the sample as index */
91 if (idx < (FIO_IO_U_PLAT_VAL << 1))
94 /* Find the group and compute the minimum value of that group */
95 error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1;
96 base = 1 << (error_bits + FIO_IO_U_PLAT_BITS);
98 /* Find its bucket number of the group */
99 k = idx % FIO_IO_U_PLAT_VAL;
101 /* Return the mean of the range of the bucket */
102 return base + ((k + 0.5) * (1 << error_bits));
105 static int double_cmp(const void *a, const void *b)
107 const fio_fp64_t fa = *(const fio_fp64_t *) a;
108 const fio_fp64_t fb = *(const fio_fp64_t *) b;
113 else if (fa.u.f < fb.u.f)
119 unsigned int calc_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
120 fio_fp64_t *plist, unsigned int **output,
121 unsigned int *maxv, unsigned int *minv)
123 unsigned long sum = 0;
124 unsigned int len, i, j = 0;
125 unsigned int oval_len = 0;
126 unsigned int *ovals = NULL;
133 while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
140 * Sort the percentile list. Note that it may already be sorted if
141 * we are using the default values, but since it's a short list this
142 * isn't a worry. Also note that this does not work for NaN values.
145 qsort((void *)plist, len, sizeof(plist[0]), double_cmp);
148 * Calculate bucket values, note down max and min values
151 for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) {
153 while (sum >= (plist[j].u.f / 100.0 * nr)) {
154 assert(plist[j].u.f <= 100.0);
158 ovals = realloc(ovals, oval_len * sizeof(unsigned int));
161 ovals[j] = plat_idx_to_val(i);
162 if (ovals[j] < *minv)
164 if (ovals[j] > *maxv)
167 is_last = (j == len - 1);
180 * Find and display the p-th percentile of clat
182 static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr,
183 fio_fp64_t *plist, unsigned int precision)
185 unsigned int len, j = 0, minv, maxv;
187 int is_last, per_line, scale_down;
190 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
195 * We default to usecs, but if the value range is such that we
196 * should scale down to msecs, do that.
198 if (minv > 2000 && maxv > 99999) {
200 log_info(" clat percentiles (msec):\n |");
203 log_info(" clat percentiles (usec):\n |");
206 snprintf(fmt, sizeof(fmt), "%%1.%uf", precision);
207 per_line = (80 - 7) / (precision + 14);
209 for (j = 0; j < len; j++) {
210 char fbuf[16], *ptr = fbuf;
213 if (j != 0 && (j % per_line) == 0)
216 /* end of the list */
217 is_last = (j == len - 1);
219 if (plist[j].u.f < 10.0)
220 ptr += sprintf(fbuf, " ");
222 snprintf(ptr, sizeof(fbuf), fmt, plist[j].u.f);
225 ovals[j] = (ovals[j] + 999) / 1000;
227 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
232 if ((j % per_line) == per_line - 1) /* for formatting */
241 int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
242 double *mean, double *dev)
244 double n = is->samples;
246 if (is->samples == 0)
252 n = (double) is->samples;
253 *mean = is->mean.u.f;
256 *dev = sqrt(is->S.u.f / (n - 1.0));
263 void show_group_stats(struct group_run_stats *rs)
265 char *p1, *p2, *p3, *p4;
266 const char *ddir_str[] = { " READ", " WRITE" , " TRIM"};
269 log_info("\nRun status group %d (all jobs):\n", rs->groupid);
271 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
272 const int i2p = is_power_of_2(rs->kb_base);
277 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
278 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
279 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
280 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
282 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
283 " mint=%llumsec, maxt=%llumsec\n",
284 rs->unified_rw_rep ? " MIXED" : ddir_str[i],
285 p1, p2, p3, p4, rs->min_run[i], rs->max_run[i]);
294 void stat_calc_dist(unsigned int *map, unsigned long total, double *io_u_dist)
299 * Do depth distribution calculations
301 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
303 io_u_dist[i] = (double) map[i] / (double) total;
304 io_u_dist[i] *= 100.0;
305 if (io_u_dist[i] < 0.1 && map[i])
312 static void stat_calc_lat(struct thread_stat *ts, double *dst,
313 unsigned int *src, int nr)
315 unsigned long total = ddir_rw_sum(ts->total_io_u);
319 * Do latency distribution calculations
321 for (i = 0; i < nr; i++) {
323 dst[i] = (double) src[i] / (double) total;
325 if (dst[i] < 0.01 && src[i])
332 void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
334 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
337 void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
339 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
342 static void display_lat(const char *name, unsigned long min, unsigned long max,
343 double mean, double dev)
345 const char *base = "(usec)";
348 if (!usec_to_msec(&min, &max, &mean, &dev))
351 minp = num2str(min, 6, 1, 0);
352 maxp = num2str(max, 6, 1, 0);
354 log_info(" %s %s: min=%s, max=%s, avg=%5.02f,"
355 " stdev=%5.02f\n", name, base, minp, maxp, mean, dev);
361 static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
364 const char *ddir_str[] = { "read ", "write", "trim" };
365 unsigned long min, max, runt;
366 unsigned long long bw, iops;
368 char *io_p, *bw_p, *iops_p;
371 assert(ddir_rw(ddir));
373 if (!ts->runtime[ddir])
376 i2p = is_power_of_2(rs->kb_base);
377 runt = ts->runtime[ddir];
379 bw = (1000 * ts->io_bytes[ddir]) / runt;
380 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
381 bw_p = num2str(bw, 6, 1, i2p);
383 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
384 iops_p = num2str(iops, 6, 1, 0);
386 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
387 rs->unified_rw_rep ? "mixed" : ddir_str[ddir],
388 io_p, bw_p, iops_p, ts->runtime[ddir]);
394 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
395 display_lat("slat", min, max, mean, dev);
396 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
397 display_lat("clat", min, max, mean, dev);
398 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
399 display_lat(" lat", min, max, mean, dev);
401 if (ts->clat_percentiles) {
402 show_clat_percentiles(ts->io_u_plat[ddir],
403 ts->clat_stat[ddir].samples,
405 ts->percentile_precision);
407 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
408 double p_of_agg = 100.0;
409 const char *bw_str = "KB";
412 p_of_agg = mean * 100 / (double) rs->agg[ddir];
413 if (p_of_agg > 100.0)
417 if (mean > 999999.9) {
425 log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
426 " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max,
427 p_of_agg, mean, dev);
431 static int show_lat(double *io_u_lat, int nr, const char **ranges,
434 int new_line = 1, i, line = 0, shown = 0;
436 for (i = 0; i < nr; i++) {
437 if (io_u_lat[i] <= 0.0)
443 log_info(" lat (%s) : ", msg);
449 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
461 static void show_lat_u(double *io_u_lat_u)
463 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
464 "250=", "500=", "750=", "1000=", };
466 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
469 static void show_lat_m(double *io_u_lat_m)
471 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
472 "250=", "500=", "750=", "1000=", "2000=",
475 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
478 static void show_latencies(struct thread_stat *ts)
480 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
481 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
483 stat_calc_lat_u(ts, io_u_lat_u);
484 stat_calc_lat_m(ts, io_u_lat_m);
486 show_lat_u(io_u_lat_u);
487 show_lat_m(io_u_lat_m);
490 void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
492 double usr_cpu, sys_cpu;
493 unsigned long runtime;
494 double io_u_dist[FIO_IO_U_MAP_NR];
498 if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] +
499 ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] +
500 ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM]))
504 os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf));
507 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s",
508 ts->name, ts->groupid, ts->members,
509 ts->error, (int) ts->pid, time_buf);
511 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s",
512 ts->name, ts->groupid, ts->members,
513 ts->error, ts->verror, (int) ts->pid,
517 if (strlen(ts->description))
518 log_info(" Description : [%s]\n", ts->description);
520 if (ts->io_bytes[DDIR_READ])
521 show_ddir_status(rs, ts, DDIR_READ);
522 if (ts->io_bytes[DDIR_WRITE])
523 show_ddir_status(rs, ts, DDIR_WRITE);
524 if (ts->io_bytes[DDIR_TRIM])
525 show_ddir_status(rs, ts, DDIR_TRIM);
529 runtime = ts->total_run_time;
531 double runt = (double) runtime;
533 usr_cpu = (double) ts->usr_time * 100 / runt;
534 sys_cpu = (double) ts->sys_time * 100 / runt;
540 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
541 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
543 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
544 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
545 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
546 io_u_dist[1], io_u_dist[2],
547 io_u_dist[3], io_u_dist[4],
548 io_u_dist[5], io_u_dist[6]);
550 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
551 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
552 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
553 io_u_dist[1], io_u_dist[2],
554 io_u_dist[3], io_u_dist[4],
555 io_u_dist[5], io_u_dist[6]);
556 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
557 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
558 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
559 io_u_dist[1], io_u_dist[2],
560 io_u_dist[3], io_u_dist[4],
561 io_u_dist[5], io_u_dist[6]);
562 log_info(" issued : total=r=%lu/w=%lu/d=%lu,"
563 " short=r=%lu/w=%lu/d=%lu\n",
564 ts->total_io_u[0], ts->total_io_u[1],
566 ts->short_io_u[0], ts->short_io_u[1],
568 if (ts->continue_on_error) {
569 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
572 strerror(ts->first_error));
576 static void show_ddir_status_terse(struct thread_stat *ts,
577 struct group_run_stats *rs, int ddir)
579 unsigned long min, max;
580 unsigned long long bw, iops;
581 unsigned int *ovals = NULL;
583 unsigned int len, minv, maxv;
586 assert(ddir_rw(ddir));
589 if (ts->runtime[ddir]) {
590 uint64_t runt = ts->runtime[ddir];
592 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
593 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
596 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
599 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
600 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
602 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
604 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
605 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
607 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
609 if (ts->clat_percentiles) {
610 len = calc_clat_percentiles(ts->io_u_plat[ddir],
611 ts->clat_stat[ddir].samples,
612 ts->percentile_list, &ovals, &maxv,
617 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
622 log_info(";%f%%=%u", ts->percentile_list[i].u.f, ovals[i]);
625 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
626 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
628 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
633 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
634 double p_of_agg = 100.0;
637 p_of_agg = mean * 100 / (double) rs->agg[ddir];
638 if (p_of_agg > 100.0)
642 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
644 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
647 static void add_ddir_status_json(struct thread_stat *ts,
648 struct group_run_stats *rs, int ddir, struct json_object *parent)
650 unsigned long min, max;
651 unsigned long long bw, iops;
652 unsigned int *ovals = NULL;
654 unsigned int len, minv, maxv;
656 const char *ddirname[] = {"read", "write", "trim"};
657 struct json_object *dir_object, *tmp_object, *percentile_object;
659 double p_of_agg = 100.0;
661 assert(ddir_rw(ddir));
663 if (ts->unified_rw_rep && ddir != DDIR_READ)
666 dir_object = json_create_object();
667 json_object_add_value_object(parent,
668 ts->unified_rw_rep ? "mixed" : ddirname[ddir], dir_object);
671 if (ts->runtime[ddir]) {
672 uint64_t runt = ts->runtime[ddir];
674 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
675 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
678 json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10);
679 json_object_add_value_int(dir_object, "bw", bw);
680 json_object_add_value_int(dir_object, "iops", iops);
681 json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]);
683 if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
687 tmp_object = json_create_object();
688 json_object_add_value_object(dir_object, "slat", tmp_object);
689 json_object_add_value_int(tmp_object, "min", min);
690 json_object_add_value_int(tmp_object, "max", max);
691 json_object_add_value_float(tmp_object, "mean", mean);
692 json_object_add_value_float(tmp_object, "stddev", dev);
694 if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
698 tmp_object = json_create_object();
699 json_object_add_value_object(dir_object, "clat", tmp_object);
700 json_object_add_value_int(tmp_object, "min", min);
701 json_object_add_value_int(tmp_object, "max", max);
702 json_object_add_value_float(tmp_object, "mean", mean);
703 json_object_add_value_float(tmp_object, "stddev", dev);
705 if (ts->clat_percentiles) {
706 len = calc_clat_percentiles(ts->io_u_plat[ddir],
707 ts->clat_stat[ddir].samples,
708 ts->percentile_list, &ovals, &maxv,
713 percentile_object = json_create_object();
714 json_object_add_value_object(tmp_object, "percentile", percentile_object);
715 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
717 json_object_add_value_int(percentile_object, "0.00", 0);
720 snprintf(buf, sizeof(buf), "%f", ts->percentile_list[i].u.f);
721 json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]);
724 if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
728 tmp_object = json_create_object();
729 json_object_add_value_object(dir_object, "lat", tmp_object);
730 json_object_add_value_int(tmp_object, "min", min);
731 json_object_add_value_int(tmp_object, "max", max);
732 json_object_add_value_float(tmp_object, "mean", mean);
733 json_object_add_value_float(tmp_object, "stddev", dev);
737 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
739 p_of_agg = mean * 100 / (double) rs->agg[ddir];
740 if (p_of_agg > 100.0)
745 p_of_agg = mean = dev = 0.0;
747 json_object_add_value_int(dir_object, "bw_min", min);
748 json_object_add_value_int(dir_object, "bw_max", max);
749 json_object_add_value_float(dir_object, "bw_agg", mean);
750 json_object_add_value_float(dir_object, "bw_mean", mean);
751 json_object_add_value_float(dir_object, "bw_dev", dev);
754 static void show_thread_status_terse_v2(struct thread_stat *ts,
755 struct group_run_stats *rs)
757 double io_u_dist[FIO_IO_U_MAP_NR];
758 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
759 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
760 double usr_cpu, sys_cpu;
764 log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error);
765 /* Log Read Status */
766 show_ddir_status_terse(ts, rs, DDIR_READ);
767 /* Log Write Status */
768 show_ddir_status_terse(ts, rs, DDIR_WRITE);
769 /* Log Trim Status */
770 show_ddir_status_terse(ts, rs, DDIR_TRIM);
773 if (ts->total_run_time) {
774 double runt = (double) ts->total_run_time;
776 usr_cpu = (double) ts->usr_time * 100 / runt;
777 sys_cpu = (double) ts->sys_time * 100 / runt;
783 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
786 /* Calc % distribution of IO depths, usecond, msecond latency */
787 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
788 stat_calc_lat_u(ts, io_u_lat_u);
789 stat_calc_lat_m(ts, io_u_lat_m);
791 /* Only show fixed 7 I/O depth levels*/
792 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
793 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
794 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
796 /* Microsecond latency */
797 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
798 log_info(";%3.2f%%", io_u_lat_u[i]);
799 /* Millisecond latency */
800 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
801 log_info(";%3.2f%%", io_u_lat_m[i]);
802 /* Additional output if continue_on_error set - default off*/
803 if (ts->continue_on_error)
804 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
807 /* Additional output if description is set */
809 log_info(";%s", ts->description);
814 static void show_thread_status_terse_v3_v4(struct thread_stat *ts,
815 struct group_run_stats *rs, int ver)
817 double io_u_dist[FIO_IO_U_MAP_NR];
818 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
819 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
820 double usr_cpu, sys_cpu;
824 log_info("%d;%s;%s;%d;%d", ver, fio_version_string,
825 ts->name, ts->groupid, ts->error);
826 /* Log Read Status */
827 show_ddir_status_terse(ts, rs, DDIR_READ);
828 /* Log Write Status */
829 show_ddir_status_terse(ts, rs, DDIR_WRITE);
830 /* Log Trim Status */
832 show_ddir_status_terse(ts, rs, DDIR_TRIM);
835 if (ts->total_run_time) {
836 double runt = (double) ts->total_run_time;
838 usr_cpu = (double) ts->usr_time * 100 / runt;
839 sys_cpu = (double) ts->sys_time * 100 / runt;
845 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
848 /* Calc % distribution of IO depths, usecond, msecond latency */
849 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
850 stat_calc_lat_u(ts, io_u_lat_u);
851 stat_calc_lat_m(ts, io_u_lat_m);
853 /* Only show fixed 7 I/O depth levels*/
854 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
855 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
856 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
858 /* Microsecond latency */
859 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
860 log_info(";%3.2f%%", io_u_lat_u[i]);
861 /* Millisecond latency */
862 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
863 log_info(";%3.2f%%", io_u_lat_m[i]);
865 /* disk util stats, if any */
866 show_disk_util(1, NULL);
868 /* Additional output if continue_on_error set - default off*/
869 if (ts->continue_on_error)
870 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
872 /* Additional output if description is set */
873 if (strlen(ts->description))
874 log_info(";%s", ts->description);
879 static struct json_object *show_thread_status_json(struct thread_stat *ts,
880 struct group_run_stats *rs)
882 struct json_object *root, *tmp;
883 double io_u_dist[FIO_IO_U_MAP_NR];
884 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
885 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
886 double usr_cpu, sys_cpu;
889 root = json_create_object();
890 json_object_add_value_string(root, "jobname", ts->name);
891 json_object_add_value_int(root, "groupid", ts->groupid);
892 json_object_add_value_int(root, "error", ts->error);
894 add_ddir_status_json(ts, rs, DDIR_READ, root);
895 add_ddir_status_json(ts, rs, DDIR_WRITE, root);
896 add_ddir_status_json(ts, rs, DDIR_TRIM, root);
899 if (ts->total_run_time) {
900 double runt = (double) ts->total_run_time;
902 usr_cpu = (double) ts->usr_time * 100 / runt;
903 sys_cpu = (double) ts->sys_time * 100 / runt;
908 json_object_add_value_float(root, "usr_cpu", usr_cpu);
909 json_object_add_value_float(root, "sys_cpu", sys_cpu);
910 json_object_add_value_int(root, "ctx", ts->ctx);
911 json_object_add_value_int(root, "majf", ts->majf);
912 json_object_add_value_int(root, "minf", ts->minf);
915 /* Calc % distribution of IO depths, usecond, msecond latency */
916 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
917 stat_calc_lat_u(ts, io_u_lat_u);
918 stat_calc_lat_m(ts, io_u_lat_m);
920 tmp = json_create_object();
921 json_object_add_value_object(root, "iodepth_level", tmp);
922 /* Only show fixed 7 I/O depth levels*/
923 for (i = 0; i < 7; i++) {
926 snprintf(name, 20, "%d", 1 << i);
928 snprintf(name, 20, ">=%d", 1 << i);
929 json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
932 tmp = json_create_object();
933 json_object_add_value_object(root, "latency_us", tmp);
934 /* Microsecond latency */
935 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
936 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
937 "250", "500", "750", "1000", };
938 json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]);
940 /* Millisecond latency */
941 tmp = json_create_object();
942 json_object_add_value_object(root, "latency_ms", tmp);
943 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) {
944 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
945 "250", "500", "750", "1000", "2000",
947 json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]);
950 /* Additional output if continue_on_error set - default off*/
951 if (ts->continue_on_error) {
952 json_object_add_value_int(root, "total_err", ts->total_err_count);
953 json_object_add_value_int(root, "total_err", ts->first_error);
956 /* Additional output if description is set */
957 if (strlen(ts->description))
958 json_object_add_value_string(root, "desc", ts->description);
963 static void show_thread_status_terse(struct thread_stat *ts,
964 struct group_run_stats *rs)
966 if (terse_version == 2)
967 show_thread_status_terse_v2(ts, rs);
968 else if (terse_version == 3 || terse_version == 4)
969 show_thread_status_terse_v3_v4(ts, rs, terse_version);
971 log_err("fio: bad terse version!? %d\n", terse_version);
974 static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
978 if (src->samples == 0)
981 dst->min_val = min(dst->min_val, src->min_val);
982 dst->max_val = max(dst->max_val, src->max_val);
985 * Compute new mean and S after the merge
986 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
987 * #Parallel_algorithm>
990 mean = src->mean.u.f;
993 double delta = src->mean.u.f - dst->mean.u.f;
995 mean = ((src->mean.u.f * src->samples) +
996 (dst->mean.u.f * dst->samples)) /
997 (dst->samples + src->samples);
999 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
1000 (dst->samples * src->samples) /
1001 (dst->samples + src->samples);
1004 dst->samples += src->samples;
1005 dst->mean.u.f = mean;
1009 void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
1013 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1014 if (dst->max_run[i] < src->max_run[i])
1015 dst->max_run[i] = src->max_run[i];
1016 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
1017 dst->min_run[i] = src->min_run[i];
1018 if (dst->max_bw[i] < src->max_bw[i])
1019 dst->max_bw[i] = src->max_bw[i];
1020 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
1021 dst->min_bw[i] = src->min_bw[i];
1023 dst->io_kb[i] += src->io_kb[i];
1024 dst->agg[i] += src->agg[i];
1029 void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
1033 for (l = 0; l < DDIR_RWDIR_CNT; l++) {
1034 if (!dst->unified_rw_rep) {
1035 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
1036 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
1037 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
1038 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
1040 dst->io_bytes[l] += src->io_bytes[l];
1042 if (dst->runtime[l] < src->runtime[l])
1043 dst->runtime[l] = src->runtime[l];
1045 sum_stat(&dst->clat_stat[0], &src->clat_stat[l], nr);
1046 sum_stat(&dst->slat_stat[0], &src->slat_stat[l], nr);
1047 sum_stat(&dst->lat_stat[0], &src->lat_stat[l], nr);
1048 sum_stat(&dst->bw_stat[0], &src->bw_stat[l], nr);
1050 dst->io_bytes[0] += src->io_bytes[l];
1052 if (dst->runtime[0] < src->runtime[l])
1053 dst->runtime[0] = src->runtime[l];
1057 dst->usr_time += src->usr_time;
1058 dst->sys_time += src->sys_time;
1059 dst->ctx += src->ctx;
1060 dst->majf += src->majf;
1061 dst->minf += src->minf;
1063 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1064 dst->io_u_map[k] += src->io_u_map[k];
1065 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1066 dst->io_u_submit[k] += src->io_u_submit[k];
1067 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1068 dst->io_u_complete[k] += src->io_u_complete[k];
1069 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
1070 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
1071 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
1072 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
1074 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
1075 if (!dst->unified_rw_rep) {
1076 dst->total_io_u[k] += src->total_io_u[k];
1077 dst->short_io_u[k] += src->short_io_u[k];
1079 dst->total_io_u[0] += src->total_io_u[k];
1080 dst->short_io_u[0] += src->short_io_u[k];
1084 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
1087 for (m = 0; m < FIO_IO_U_PLAT_NR; m++) {
1088 if (!dst->unified_rw_rep)
1089 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
1091 dst->io_u_plat[0][m] += src->io_u_plat[k][m];
1095 dst->total_run_time += src->total_run_time;
1096 dst->total_submit += src->total_submit;
1097 dst->total_complete += src->total_complete;
1100 void init_group_run_stat(struct group_run_stats *gs)
1103 memset(gs, 0, sizeof(*gs));
1105 for (i = 0; i < DDIR_RWDIR_CNT; i++)
1106 gs->min_bw[i] = gs->min_run[i] = ~0UL;
1109 void init_thread_stat(struct thread_stat *ts)
1113 memset(ts, 0, sizeof(*ts));
1115 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
1116 ts->lat_stat[j].min_val = -1UL;
1117 ts->clat_stat[j].min_val = -1UL;
1118 ts->slat_stat[j].min_val = -1UL;
1119 ts->bw_stat[j].min_val = -1UL;
1124 void show_run_stats(void)
1126 struct group_run_stats *runstats, *rs;
1127 struct thread_data *td;
1128 struct thread_stat *threadstats, *ts;
1129 int i, j, nr_ts, last_ts, idx;
1130 int kb_base_warned = 0;
1131 struct json_object *root = NULL;
1132 struct json_array *array = NULL;
1134 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
1136 for (i = 0; i < groupid + 1; i++)
1137 init_group_run_stat(&runstats[i]);
1140 * find out how many threads stats we need. if group reporting isn't
1141 * enabled, it's one-per-td.
1145 for_each_td(td, i) {
1146 if (!td->o.group_reporting) {
1150 if (last_ts == td->groupid)
1153 last_ts = td->groupid;
1157 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
1159 for (i = 0; i < nr_ts; i++)
1160 init_thread_stat(&threadstats[i]);
1165 for_each_td(td, i) {
1166 if (idx && (!td->o.group_reporting ||
1167 (td->o.group_reporting && last_ts != td->groupid))) {
1172 last_ts = td->groupid;
1174 ts = &threadstats[j];
1176 ts->clat_percentiles = td->o.clat_percentiles;
1177 ts->percentile_precision = td->o.percentile_precision;
1178 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
1183 if (ts->groupid == -1) {
1185 * These are per-group shared already
1187 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
1188 if (td->o.description)
1189 strncpy(ts->description, td->o.description,
1192 memset(ts->description, 0, FIO_JOBNAME_SIZE);
1195 * If multiple entries in this group, this is
1198 ts->thread_number = td->thread_number;
1199 ts->groupid = td->groupid;
1202 * first pid in group, not very useful...
1206 ts->kb_base = td->o.kb_base;
1207 ts->unified_rw_rep = td->o.unified_rw_rep;
1208 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
1209 log_info("fio: kb_base differs for jobs in group, using"
1210 " %u as the base\n", ts->kb_base);
1214 ts->continue_on_error = td->o.continue_on_error;
1215 ts->total_err_count += td->total_err_count;
1216 ts->first_error = td->first_error;
1218 if (!td->error && td->o.continue_on_error &&
1220 ts->error = td->first_error;
1221 strcpy(ts->verror, td->verror);
1222 } else if (td->error) {
1223 ts->error = td->error;
1224 strcpy(ts->verror, td->verror);
1228 sum_thread_stats(ts, &td->ts, idx);
1231 for (i = 0; i < nr_ts; i++) {
1232 unsigned long long bw;
1234 ts = &threadstats[i];
1235 rs = &runstats[ts->groupid];
1236 rs->kb_base = ts->kb_base;
1237 rs->unified_rw_rep += ts->unified_rw_rep;
1239 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
1240 if (!ts->runtime[j])
1242 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
1243 rs->min_run[j] = ts->runtime[j];
1244 if (ts->runtime[j] > rs->max_run[j])
1245 rs->max_run[j] = ts->runtime[j];
1248 if (ts->runtime[j]) {
1249 unsigned long runt = ts->runtime[j];
1250 unsigned long long kb;
1252 kb = ts->io_bytes[j] / rs->kb_base;
1253 bw = kb * 1000 / runt;
1255 if (bw < rs->min_bw[j])
1257 if (bw > rs->max_bw[j])
1260 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
1264 for (i = 0; i < groupid + 1; i++) {
1269 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
1270 if (rs->max_run[ddir])
1271 rs->agg[ddir] = (rs->io_kb[ddir] * 1000) /
1277 * don't overwrite last signal output
1279 if (output_format == FIO_OUTPUT_NORMAL)
1281 else if (output_format == FIO_OUTPUT_JSON) {
1282 root = json_create_object();
1283 json_object_add_value_string(root, "fio version", fio_version_string);
1284 array = json_create_array();
1285 json_object_add_value_array(root, "jobs", array);
1288 for (i = 0; i < nr_ts; i++) {
1289 ts = &threadstats[i];
1290 rs = &runstats[ts->groupid];
1293 fio_server_send_ts(ts, rs);
1294 else if (output_format == FIO_OUTPUT_TERSE)
1295 show_thread_status_terse(ts, rs);
1296 else if (output_format == FIO_OUTPUT_JSON) {
1297 struct json_object *tmp = show_thread_status_json(ts, rs);
1298 json_array_add_value_object(array, tmp);
1300 show_thread_status(ts, rs);
1302 if (output_format == FIO_OUTPUT_JSON) {
1303 /* disk util stats, if any */
1304 show_disk_util(1, root);
1306 show_idle_prof_stats(FIO_OUTPUT_JSON, root);
1308 json_print_object(root);
1310 json_free_object(root);
1313 for (i = 0; i < groupid + 1; i++) {
1318 fio_server_send_gs(rs);
1319 else if (output_format == FIO_OUTPUT_NORMAL)
1320 show_group_stats(rs);
1324 fio_server_send_du();
1325 else if (output_format == FIO_OUTPUT_NORMAL) {
1326 show_disk_util(0, NULL);
1327 show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL);
1334 static void *__show_running_run_stats(void *arg)
1336 struct thread_data *td;
1337 unsigned long long *rt;
1341 rt = malloc(thread_number * sizeof(unsigned long long));
1342 fio_gettime(&tv, NULL);
1344 for_each_td(td, i) {
1345 rt[i] = mtime_since(&td->start, &tv);
1346 if (td_read(td) && td->io_bytes[DDIR_READ])
1347 td->ts.runtime[DDIR_READ] += rt[i];
1348 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1349 td->ts.runtime[DDIR_WRITE] += rt[i];
1350 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1351 td->ts.runtime[DDIR_TRIM] += rt[i];
1353 td->update_rusage = 1;
1354 td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
1355 td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
1356 td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
1357 td->ts.total_run_time = mtime_since(&td->epoch, &tv);
1360 for_each_td(td, i) {
1361 if (td->rusage_sem) {
1362 td->update_rusage = 1;
1363 fio_mutex_down(td->rusage_sem);
1365 td->update_rusage = 0;
1370 for_each_td(td, i) {
1371 if (td_read(td) && td->io_bytes[DDIR_READ])
1372 td->ts.runtime[DDIR_READ] -= rt[i];
1373 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1374 td->ts.runtime[DDIR_WRITE] -= rt[i];
1375 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1376 td->ts.runtime[DDIR_TRIM] -= rt[i];
1384 * Called from signal handler. It _should_ be safe to just run this inline
1385 * in the sig handler, but we should be disturbing the system less by just
1386 * creating a thread to do it.
1388 void show_running_run_stats(void)
1392 pthread_create(&thread, NULL, __show_running_run_stats, NULL);
1393 pthread_detach(thread);
1396 static inline void add_stat_sample(struct io_stat *is, unsigned long data)
1401 if (data > is->max_val)
1403 if (data < is->min_val)
1406 delta = val - is->mean.u.f;
1408 is->mean.u.f += delta / (is->samples + 1.0);
1409 is->S.u.f += delta * (val - is->mean.u.f);
1415 static void __add_log_sample(struct io_log *iolog, unsigned long val,
1416 enum fio_ddir ddir, unsigned int bs,
1419 const int nr_samples = iolog->nr_samples;
1421 if (!iolog->nr_samples)
1422 iolog->avg_last = t;
1424 if (iolog->nr_samples == iolog->max_samples) {
1425 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1427 iolog->log = realloc(iolog->log, new_size);
1428 iolog->max_samples <<= 1;
1431 iolog->log[nr_samples].val = val;
1432 iolog->log[nr_samples].time = t;
1433 iolog->log[nr_samples].ddir = ddir;
1434 iolog->log[nr_samples].bs = bs;
1435 iolog->nr_samples++;
1438 static inline void reset_io_stat(struct io_stat *ios)
1440 ios->max_val = ios->min_val = ios->samples = 0;
1441 ios->mean.u.f = ios->S.u.f = 0;
1444 static void add_log_sample(struct thread_data *td, struct io_log *iolog,
1445 unsigned long val, enum fio_ddir ddir,
1448 unsigned long elapsed, this_window;
1453 elapsed = mtime_since_now(&td->epoch);
1456 * If no time averaging, just add the log sample.
1458 if (!iolog->avg_msec) {
1459 __add_log_sample(iolog, val, ddir, bs, elapsed);
1464 * Add the sample. If the time period has passed, then
1465 * add that entry to the log and clear.
1467 add_stat_sample(&iolog->avg_window[ddir], val);
1470 * If period hasn't passed, adding the above sample is all we
1473 this_window = elapsed - iolog->avg_last;
1474 if (this_window < iolog->avg_msec)
1478 * Note an entry in the log. Use the mean from the logged samples,
1479 * making sure to properly round up. Only write a log entry if we
1480 * had actual samples done.
1482 if (iolog->avg_window[DDIR_READ].samples) {
1485 mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
1486 __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
1488 if (iolog->avg_window[DDIR_WRITE].samples) {
1491 mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
1492 __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
1494 if (iolog->avg_window[DDIR_TRIM].samples) {
1497 mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50;
1498 __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed);
1502 reset_io_stat(&iolog->avg_window[DDIR_READ]);
1503 reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
1504 reset_io_stat(&iolog->avg_window[DDIR_TRIM]);
1505 iolog->avg_last = elapsed;
1508 void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
1510 struct io_log *iolog;
1515 iolog = agg_io_log[ddir];
1516 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
1519 static void add_clat_percentile_sample(struct thread_stat *ts,
1520 unsigned long usec, enum fio_ddir ddir)
1522 unsigned int idx = plat_val_to_idx(usec);
1523 assert(idx < FIO_IO_U_PLAT_NR);
1525 ts->io_u_plat[ddir][idx]++;
1528 void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
1529 unsigned long usec, unsigned int bs)
1531 struct thread_stat *ts = &td->ts;
1536 add_stat_sample(&ts->clat_stat[ddir], usec);
1539 add_log_sample(td, td->clat_log, usec, ddir, bs);
1541 if (ts->clat_percentiles)
1542 add_clat_percentile_sample(ts, usec, ddir);
1545 void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
1546 unsigned long usec, unsigned int bs)
1548 struct thread_stat *ts = &td->ts;
1553 add_stat_sample(&ts->slat_stat[ddir], usec);
1556 add_log_sample(td, td->slat_log, usec, ddir, bs);
1559 void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1560 unsigned long usec, unsigned int bs)
1562 struct thread_stat *ts = &td->ts;
1567 add_stat_sample(&ts->lat_stat[ddir], usec);
1570 add_log_sample(td, td->lat_log, usec, ddir, bs);
1573 void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
1576 struct thread_stat *ts = &td->ts;
1577 unsigned long spent, rate;
1582 spent = mtime_since(&td->bw_sample_time, t);
1583 if (spent < td->o.bw_avg_time)
1587 * Compute both read and write rates for the interval.
1589 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
1592 delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
1594 continue; /* No entries for interval */
1596 rate = delta * 1000 / spent / 1024;
1597 add_stat_sample(&ts->bw_stat[ddir], rate);
1600 add_log_sample(td, td->bw_log, rate, ddir, bs);
1602 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
1605 fio_gettime(&td->bw_sample_time, NULL);
1608 void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1611 struct thread_stat *ts = &td->ts;
1612 unsigned long spent, iops;
1617 spent = mtime_since(&td->iops_sample_time, t);
1618 if (spent < td->o.iops_avg_time)
1622 * Compute both read and write rates for the interval.
1624 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
1627 delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
1629 continue; /* No entries for interval */
1631 iops = (delta * 1000) / spent;
1632 add_stat_sample(&ts->iops_stat[ddir], iops);
1635 add_log_sample(td, td->iops_log, iops, ddir, 0);
1637 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
1640 fio_gettime(&td->iops_sample_time, NULL);