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,
185 unsigned int len, j = 0, minv, maxv;
187 int is_last, scale_down;
189 len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
194 * We default to usecs, but if the value range is such that we
195 * should scale down to msecs, do that.
197 if (minv > 2000 && maxv > 99999) {
199 log_info(" clat percentiles (msec):\n |");
202 log_info(" clat percentiles (usec):\n |");
205 for (j = 0; j < len; j++) {
209 if (j != 0 && (j % 4) == 0)
212 /* end of the list */
213 is_last = (j == len - 1);
215 if (plist[j].u.f < 10.0)
216 sprintf(fbuf, " %2.2f", plist[j].u.f);
218 sprintf(fbuf, "%2.2f", plist[j].u.f);
221 ovals[j] = (ovals[j] + 999) / 1000;
223 log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ',');
228 if (j % 4 == 3) /* for formatting */
237 int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
238 double *mean, double *dev)
240 double n = is->samples;
242 if (is->samples == 0)
248 n = (double) is->samples;
249 *mean = is->mean.u.f;
252 *dev = sqrt(is->S.u.f / (n - 1.0));
259 void show_group_stats(struct group_run_stats *rs)
261 char *p1, *p2, *p3, *p4;
262 const char *ddir_str[] = { " READ", " WRITE" , " TRIM"};
265 log_info("\nRun status group %d (all jobs):\n", rs->groupid);
267 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
268 const int i2p = is_power_of_2(rs->kb_base);
273 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
274 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
275 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
276 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
278 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
279 " mint=%llumsec, maxt=%llumsec\n",
280 rs->unified_rw_rep ? " MIXED" : ddir_str[i],
281 p1, p2, p3, p4, rs->min_run[i], rs->max_run[i]);
290 void stat_calc_dist(unsigned int *map, unsigned long total, double *io_u_dist)
295 * Do depth distribution calculations
297 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
299 io_u_dist[i] = (double) map[i] / (double) total;
300 io_u_dist[i] *= 100.0;
301 if (io_u_dist[i] < 0.1 && map[i])
308 static void stat_calc_lat(struct thread_stat *ts, double *dst,
309 unsigned int *src, int nr)
311 unsigned long total = ddir_rw_sum(ts->total_io_u);
315 * Do latency distribution calculations
317 for (i = 0; i < nr; i++) {
319 dst[i] = (double) src[i] / (double) total;
321 if (dst[i] < 0.01 && src[i])
328 void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
330 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
333 void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
335 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
338 static void display_lat(const char *name, unsigned long min, unsigned long max,
339 double mean, double dev)
341 const char *base = "(usec)";
344 if (!usec_to_msec(&min, &max, &mean, &dev))
347 minp = num2str(min, 6, 1, 0);
348 maxp = num2str(max, 6, 1, 0);
350 log_info(" %s %s: min=%s, max=%s, avg=%5.02f,"
351 " stdev=%5.02f\n", name, base, minp, maxp, mean, dev);
357 static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
360 const char *ddir_str[] = { "read ", "write", "trim" };
361 unsigned long min, max, runt;
362 unsigned long long bw, iops;
364 char *io_p, *bw_p, *iops_p;
367 assert(ddir_rw(ddir));
369 if (!ts->runtime[ddir])
372 i2p = is_power_of_2(rs->kb_base);
373 runt = ts->runtime[ddir];
375 bw = (1000 * ts->io_bytes[ddir]) / runt;
376 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
377 bw_p = num2str(bw, 6, 1, i2p);
379 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
380 iops_p = num2str(iops, 6, 1, 0);
382 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
383 rs->unified_rw_rep ? "mixed" : ddir_str[ddir],
384 io_p, bw_p, iops_p, ts->runtime[ddir]);
390 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
391 display_lat("slat", min, max, mean, dev);
392 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
393 display_lat("clat", min, max, mean, dev);
394 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
395 display_lat(" lat", min, max, mean, dev);
397 if (ts->clat_percentiles) {
398 show_clat_percentiles(ts->io_u_plat[ddir],
399 ts->clat_stat[ddir].samples,
400 ts->percentile_list);
402 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
403 double p_of_agg = 100.0;
404 const char *bw_str = "KB";
407 p_of_agg = mean * 100 / (double) rs->agg[ddir];
408 if (p_of_agg > 100.0)
412 if (mean > 999999.9) {
420 log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
421 " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max,
422 p_of_agg, mean, dev);
426 static int show_lat(double *io_u_lat, int nr, const char **ranges,
429 int new_line = 1, i, line = 0, shown = 0;
431 for (i = 0; i < nr; i++) {
432 if (io_u_lat[i] <= 0.0)
438 log_info(" lat (%s) : ", msg);
444 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
456 static void show_lat_u(double *io_u_lat_u)
458 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
459 "250=", "500=", "750=", "1000=", };
461 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
464 static void show_lat_m(double *io_u_lat_m)
466 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
467 "250=", "500=", "750=", "1000=", "2000=",
470 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
473 static void show_latencies(struct thread_stat *ts)
475 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
476 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
478 stat_calc_lat_u(ts, io_u_lat_u);
479 stat_calc_lat_m(ts, io_u_lat_m);
481 show_lat_u(io_u_lat_u);
482 show_lat_m(io_u_lat_m);
485 void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs)
487 double usr_cpu, sys_cpu;
488 unsigned long runtime;
489 double io_u_dist[FIO_IO_U_MAP_NR];
493 if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] +
494 ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] +
495 ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM]))
499 os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf));
502 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s",
503 ts->name, ts->groupid, ts->members,
504 ts->error, (int) ts->pid, time_buf);
506 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s",
507 ts->name, ts->groupid, ts->members,
508 ts->error, ts->verror, (int) ts->pid,
512 if (strlen(ts->description))
513 log_info(" Description : [%s]\n", ts->description);
515 if (ts->io_bytes[DDIR_READ])
516 show_ddir_status(rs, ts, DDIR_READ);
517 if (ts->io_bytes[DDIR_WRITE])
518 show_ddir_status(rs, ts, DDIR_WRITE);
519 if (ts->io_bytes[DDIR_TRIM])
520 show_ddir_status(rs, ts, DDIR_TRIM);
524 runtime = ts->total_run_time;
526 double runt = (double) runtime;
528 usr_cpu = (double) ts->usr_time * 100 / runt;
529 sys_cpu = (double) ts->sys_time * 100 / runt;
535 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
536 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
538 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
539 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
540 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
541 io_u_dist[1], io_u_dist[2],
542 io_u_dist[3], io_u_dist[4],
543 io_u_dist[5], io_u_dist[6]);
545 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
546 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
547 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
548 io_u_dist[1], io_u_dist[2],
549 io_u_dist[3], io_u_dist[4],
550 io_u_dist[5], io_u_dist[6]);
551 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
552 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
553 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
554 io_u_dist[1], io_u_dist[2],
555 io_u_dist[3], io_u_dist[4],
556 io_u_dist[5], io_u_dist[6]);
557 log_info(" issued : total=r=%lu/w=%lu/d=%lu,"
558 " short=r=%lu/w=%lu/d=%lu\n",
559 ts->total_io_u[0], ts->total_io_u[1],
561 ts->short_io_u[0], ts->short_io_u[1],
563 if (ts->continue_on_error) {
564 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
567 strerror(ts->first_error));
571 static void show_ddir_status_terse(struct thread_stat *ts,
572 struct group_run_stats *rs, int ddir)
574 unsigned long min, max;
575 unsigned long long bw, iops;
576 unsigned int *ovals = NULL;
578 unsigned int len, minv, maxv;
581 assert(ddir_rw(ddir));
584 if (ts->runtime[ddir]) {
585 uint64_t runt = ts->runtime[ddir];
587 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
588 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
591 log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops,
594 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
595 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
597 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
599 if (calc_lat(&ts->clat_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 (ts->clat_percentiles) {
605 len = calc_clat_percentiles(ts->io_u_plat[ddir],
606 ts->clat_stat[ddir].samples,
607 ts->percentile_list, &ovals, &maxv,
612 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
617 log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]);
620 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
621 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
623 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
628 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
629 double p_of_agg = 100.0;
632 p_of_agg = mean * 100 / (double) rs->agg[ddir];
633 if (p_of_agg > 100.0)
637 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
639 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
642 static void add_ddir_status_json(struct thread_stat *ts,
643 struct group_run_stats *rs, int ddir, struct json_object *parent)
645 unsigned long min, max;
646 unsigned long long bw, iops;
647 unsigned int *ovals = NULL;
649 unsigned int len, minv, maxv;
651 const char *ddirname[] = {"read", "write", "trim"};
652 struct json_object *dir_object, *tmp_object, *percentile_object;
654 double p_of_agg = 100.0;
656 assert(ddir_rw(ddir));
658 if (ts->unified_rw_rep && ddir != DDIR_READ)
661 dir_object = json_create_object();
662 json_object_add_value_object(parent,
663 ts->unified_rw_rep ? "mixed" : ddirname[ddir], dir_object);
666 if (ts->runtime[ddir]) {
667 uint64_t runt = ts->runtime[ddir];
669 bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024;
670 iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt;
673 json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10);
674 json_object_add_value_int(dir_object, "bw", bw);
675 json_object_add_value_int(dir_object, "iops", iops);
676 json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]);
678 if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
682 tmp_object = json_create_object();
683 json_object_add_value_object(dir_object, "slat", tmp_object);
684 json_object_add_value_int(tmp_object, "min", min);
685 json_object_add_value_int(tmp_object, "max", max);
686 json_object_add_value_float(tmp_object, "mean", mean);
687 json_object_add_value_float(tmp_object, "stddev", dev);
689 if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
693 tmp_object = json_create_object();
694 json_object_add_value_object(dir_object, "clat", tmp_object);
695 json_object_add_value_int(tmp_object, "min", min);
696 json_object_add_value_int(tmp_object, "max", max);
697 json_object_add_value_float(tmp_object, "mean", mean);
698 json_object_add_value_float(tmp_object, "stddev", dev);
700 if (ts->clat_percentiles) {
701 len = calc_clat_percentiles(ts->io_u_plat[ddir],
702 ts->clat_stat[ddir].samples,
703 ts->percentile_list, &ovals, &maxv,
708 percentile_object = json_create_object();
709 json_object_add_value_object(tmp_object, "percentile", percentile_object);
710 for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) {
712 json_object_add_value_int(percentile_object, "0.00", 0);
715 snprintf(buf, sizeof(buf), "%2.2f", ts->percentile_list[i].u.f);
716 json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]);
719 if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
723 tmp_object = json_create_object();
724 json_object_add_value_object(dir_object, "lat", tmp_object);
725 json_object_add_value_int(tmp_object, "min", min);
726 json_object_add_value_int(tmp_object, "max", max);
727 json_object_add_value_float(tmp_object, "mean", mean);
728 json_object_add_value_float(tmp_object, "stddev", dev);
732 if (!calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
734 p_of_agg = mean * 100 / (double) rs->agg[ddir];
735 if (p_of_agg > 100.0)
740 p_of_agg = mean = dev = 0.0;
742 json_object_add_value_int(dir_object, "bw_min", min);
743 json_object_add_value_int(dir_object, "bw_max", max);
744 json_object_add_value_float(dir_object, "bw_agg", mean);
745 json_object_add_value_float(dir_object, "bw_mean", mean);
746 json_object_add_value_float(dir_object, "bw_dev", dev);
749 static void show_thread_status_terse_v2(struct thread_stat *ts,
750 struct group_run_stats *rs)
752 double io_u_dist[FIO_IO_U_MAP_NR];
753 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
754 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
755 double usr_cpu, sys_cpu;
759 log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error);
760 /* Log Read Status */
761 show_ddir_status_terse(ts, rs, DDIR_READ);
762 /* Log Write Status */
763 show_ddir_status_terse(ts, rs, DDIR_WRITE);
764 /* Log Trim Status */
765 show_ddir_status_terse(ts, rs, DDIR_TRIM);
768 if (ts->total_run_time) {
769 double runt = (double) ts->total_run_time;
771 usr_cpu = (double) ts->usr_time * 100 / runt;
772 sys_cpu = (double) ts->sys_time * 100 / runt;
778 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
781 /* Calc % distribution of IO depths, usecond, msecond latency */
782 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
783 stat_calc_lat_u(ts, io_u_lat_u);
784 stat_calc_lat_m(ts, io_u_lat_m);
786 /* Only show fixed 7 I/O depth levels*/
787 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
788 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
789 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
791 /* Microsecond latency */
792 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
793 log_info(";%3.2f%%", io_u_lat_u[i]);
794 /* Millisecond latency */
795 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
796 log_info(";%3.2f%%", io_u_lat_m[i]);
797 /* Additional output if continue_on_error set - default off*/
798 if (ts->continue_on_error)
799 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
802 /* Additional output if description is set */
804 log_info(";%s", ts->description);
809 static void show_thread_status_terse_v3_v4(struct thread_stat *ts,
810 struct group_run_stats *rs, int ver)
812 double io_u_dist[FIO_IO_U_MAP_NR];
813 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
814 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
815 double usr_cpu, sys_cpu;
819 log_info("%d;%s;%s;%d;%d", ver, fio_version_string,
820 ts->name, ts->groupid, ts->error);
821 /* Log Read Status */
822 show_ddir_status_terse(ts, rs, DDIR_READ);
823 /* Log Write Status */
824 show_ddir_status_terse(ts, rs, DDIR_WRITE);
825 /* Log Trim Status */
827 show_ddir_status_terse(ts, rs, DDIR_TRIM);
830 if (ts->total_run_time) {
831 double runt = (double) ts->total_run_time;
833 usr_cpu = (double) ts->usr_time * 100 / runt;
834 sys_cpu = (double) ts->sys_time * 100 / runt;
840 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
843 /* Calc % distribution of IO depths, usecond, msecond latency */
844 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
845 stat_calc_lat_u(ts, io_u_lat_u);
846 stat_calc_lat_m(ts, io_u_lat_m);
848 /* Only show fixed 7 I/O depth levels*/
849 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
850 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
851 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
853 /* Microsecond latency */
854 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
855 log_info(";%3.2f%%", io_u_lat_u[i]);
856 /* Millisecond latency */
857 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
858 log_info(";%3.2f%%", io_u_lat_m[i]);
860 /* disk util stats, if any */
861 show_disk_util(1, NULL);
863 /* Additional output if continue_on_error set - default off*/
864 if (ts->continue_on_error)
865 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
867 /* Additional output if description is set */
868 if (strlen(ts->description))
869 log_info(";%s", ts->description);
874 static struct json_object *show_thread_status_json(struct thread_stat *ts,
875 struct group_run_stats *rs)
877 struct json_object *root, *tmp;
878 double io_u_dist[FIO_IO_U_MAP_NR];
879 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
880 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
881 double usr_cpu, sys_cpu;
884 root = json_create_object();
885 json_object_add_value_string(root, "jobname", ts->name);
886 json_object_add_value_int(root, "groupid", ts->groupid);
887 json_object_add_value_int(root, "error", ts->error);
889 add_ddir_status_json(ts, rs, DDIR_READ, root);
890 add_ddir_status_json(ts, rs, DDIR_WRITE, root);
891 add_ddir_status_json(ts, rs, DDIR_TRIM, root);
894 if (ts->total_run_time) {
895 double runt = (double) ts->total_run_time;
897 usr_cpu = (double) ts->usr_time * 100 / runt;
898 sys_cpu = (double) ts->sys_time * 100 / runt;
903 json_object_add_value_float(root, "usr_cpu", usr_cpu);
904 json_object_add_value_float(root, "sys_cpu", sys_cpu);
905 json_object_add_value_int(root, "ctx", ts->ctx);
906 json_object_add_value_int(root, "majf", ts->majf);
907 json_object_add_value_int(root, "minf", ts->minf);
910 /* Calc % distribution of IO depths, usecond, msecond latency */
911 stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist);
912 stat_calc_lat_u(ts, io_u_lat_u);
913 stat_calc_lat_m(ts, io_u_lat_m);
915 tmp = json_create_object();
916 json_object_add_value_object(root, "iodepth_level", tmp);
917 /* Only show fixed 7 I/O depth levels*/
918 for (i = 0; i < 7; i++) {
921 snprintf(name, 20, "%d", 1 << i);
923 snprintf(name, 20, ">=%d", 1 << i);
924 json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]);
927 tmp = json_create_object();
928 json_object_add_value_object(root, "latency_us", tmp);
929 /* Microsecond latency */
930 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) {
931 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
932 "250", "500", "750", "1000", };
933 json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]);
935 /* Millisecond latency */
936 tmp = json_create_object();
937 json_object_add_value_object(root, "latency_ms", tmp);
938 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) {
939 const char *ranges[] = { "2", "4", "10", "20", "50", "100",
940 "250", "500", "750", "1000", "2000",
942 json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]);
945 /* Additional output if continue_on_error set - default off*/
946 if (ts->continue_on_error) {
947 json_object_add_value_int(root, "total_err", ts->total_err_count);
948 json_object_add_value_int(root, "total_err", ts->first_error);
951 /* Additional output if description is set */
952 if (strlen(ts->description))
953 json_object_add_value_string(root, "desc", ts->description);
958 static void show_thread_status_terse(struct thread_stat *ts,
959 struct group_run_stats *rs)
961 if (terse_version == 2)
962 show_thread_status_terse_v2(ts, rs);
963 else if (terse_version == 3 || terse_version == 4)
964 show_thread_status_terse_v3_v4(ts, rs, terse_version);
966 log_err("fio: bad terse version!? %d\n", terse_version);
969 static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
973 if (src->samples == 0)
976 dst->min_val = min(dst->min_val, src->min_val);
977 dst->max_val = max(dst->max_val, src->max_val);
980 * Compute new mean and S after the merge
981 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
982 * #Parallel_algorithm>
985 mean = src->mean.u.f;
988 double delta = src->mean.u.f - dst->mean.u.f;
990 mean = ((src->mean.u.f * src->samples) +
991 (dst->mean.u.f * dst->samples)) /
992 (dst->samples + src->samples);
994 S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) *
995 (dst->samples * src->samples) /
996 (dst->samples + src->samples);
999 dst->samples += src->samples;
1000 dst->mean.u.f = mean;
1004 void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src)
1008 for (i = 0; i < DDIR_RWDIR_CNT; i++) {
1009 if (dst->max_run[i] < src->max_run[i])
1010 dst->max_run[i] = src->max_run[i];
1011 if (dst->min_run[i] && dst->min_run[i] > src->min_run[i])
1012 dst->min_run[i] = src->min_run[i];
1013 if (dst->max_bw[i] < src->max_bw[i])
1014 dst->max_bw[i] = src->max_bw[i];
1015 if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i])
1016 dst->min_bw[i] = src->min_bw[i];
1018 dst->io_kb[i] += src->io_kb[i];
1019 dst->agg[i] += src->agg[i];
1024 void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr)
1028 for (l = 0; l < DDIR_RWDIR_CNT; l++) {
1029 if (!dst->unified_rw_rep) {
1030 sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr);
1031 sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr);
1032 sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr);
1033 sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr);
1035 dst->io_bytes[l] += src->io_bytes[l];
1037 if (dst->runtime[l] < src->runtime[l])
1038 dst->runtime[l] = src->runtime[l];
1040 sum_stat(&dst->clat_stat[0], &src->clat_stat[l], nr);
1041 sum_stat(&dst->slat_stat[0], &src->slat_stat[l], nr);
1042 sum_stat(&dst->lat_stat[0], &src->lat_stat[l], nr);
1043 sum_stat(&dst->bw_stat[0], &src->bw_stat[l], nr);
1045 dst->io_bytes[0] += src->io_bytes[l];
1047 if (dst->runtime[0] < src->runtime[l])
1048 dst->runtime[0] = src->runtime[l];
1052 dst->usr_time += src->usr_time;
1053 dst->sys_time += src->sys_time;
1054 dst->ctx += src->ctx;
1055 dst->majf += src->majf;
1056 dst->minf += src->minf;
1058 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1059 dst->io_u_map[k] += src->io_u_map[k];
1060 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1061 dst->io_u_submit[k] += src->io_u_submit[k];
1062 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
1063 dst->io_u_complete[k] += src->io_u_complete[k];
1064 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
1065 dst->io_u_lat_u[k] += src->io_u_lat_u[k];
1066 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
1067 dst->io_u_lat_m[k] += src->io_u_lat_m[k];
1069 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
1070 if (!dst->unified_rw_rep) {
1071 dst->total_io_u[k] += src->total_io_u[k];
1072 dst->short_io_u[k] += src->short_io_u[k];
1074 dst->total_io_u[0] += src->total_io_u[k];
1075 dst->short_io_u[0] += src->short_io_u[k];
1079 for (k = 0; k < DDIR_RWDIR_CNT; k++) {
1082 for (m = 0; m < FIO_IO_U_PLAT_NR; m++) {
1083 if (!dst->unified_rw_rep)
1084 dst->io_u_plat[k][m] += src->io_u_plat[k][m];
1086 dst->io_u_plat[0][m] += src->io_u_plat[k][m];
1090 dst->total_run_time += src->total_run_time;
1091 dst->total_submit += src->total_submit;
1092 dst->total_complete += src->total_complete;
1095 void init_group_run_stat(struct group_run_stats *gs)
1098 memset(gs, 0, sizeof(*gs));
1100 for (i = 0; i < DDIR_RWDIR_CNT; i++)
1101 gs->min_bw[i] = gs->min_run[i] = ~0UL;
1104 void init_thread_stat(struct thread_stat *ts)
1108 memset(ts, 0, sizeof(*ts));
1110 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
1111 ts->lat_stat[j].min_val = -1UL;
1112 ts->clat_stat[j].min_val = -1UL;
1113 ts->slat_stat[j].min_val = -1UL;
1114 ts->bw_stat[j].min_val = -1UL;
1119 void show_run_stats(void)
1121 struct group_run_stats *runstats, *rs;
1122 struct thread_data *td;
1123 struct thread_stat *threadstats, *ts;
1124 int i, j, nr_ts, last_ts, idx;
1125 int kb_base_warned = 0;
1126 struct json_object *root = NULL;
1127 struct json_array *array = NULL;
1129 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
1131 for (i = 0; i < groupid + 1; i++)
1132 init_group_run_stat(&runstats[i]);
1135 * find out how many threads stats we need. if group reporting isn't
1136 * enabled, it's one-per-td.
1140 for_each_td(td, i) {
1141 if (!td->o.group_reporting) {
1145 if (last_ts == td->groupid)
1148 last_ts = td->groupid;
1152 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
1154 for (i = 0; i < nr_ts; i++)
1155 init_thread_stat(&threadstats[i]);
1160 for_each_td(td, i) {
1161 if (idx && (!td->o.group_reporting ||
1162 (td->o.group_reporting && last_ts != td->groupid))) {
1167 last_ts = td->groupid;
1169 ts = &threadstats[j];
1171 ts->clat_percentiles = td->o.clat_percentiles;
1172 if (td->o.overwrite_plist)
1173 memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list));
1175 memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list));
1180 if (ts->groupid == -1) {
1182 * These are per-group shared already
1184 strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE);
1185 if (td->o.description)
1186 strncpy(ts->description, td->o.description,
1189 memset(ts->description, 0, FIO_JOBNAME_SIZE);
1192 * If multiple entries in this group, this is
1195 ts->thread_number = td->thread_number;
1196 ts->groupid = td->groupid;
1199 * first pid in group, not very useful...
1203 ts->kb_base = td->o.kb_base;
1204 ts->unified_rw_rep = td->o.unified_rw_rep;
1205 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
1206 log_info("fio: kb_base differs for jobs in group, using"
1207 " %u as the base\n", ts->kb_base);
1211 ts->continue_on_error = td->o.continue_on_error;
1212 ts->total_err_count += td->total_err_count;
1213 ts->first_error = td->first_error;
1215 if (!td->error && td->o.continue_on_error &&
1217 ts->error = td->first_error;
1218 strcpy(ts->verror, td->verror);
1219 } else if (td->error) {
1220 ts->error = td->error;
1221 strcpy(ts->verror, td->verror);
1225 sum_thread_stats(ts, &td->ts, idx);
1228 for (i = 0; i < nr_ts; i++) {
1229 unsigned long long bw;
1231 ts = &threadstats[i];
1232 rs = &runstats[ts->groupid];
1233 rs->kb_base = ts->kb_base;
1234 rs->unified_rw_rep += ts->unified_rw_rep;
1236 for (j = 0; j < DDIR_RWDIR_CNT; j++) {
1237 if (!ts->runtime[j])
1239 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
1240 rs->min_run[j] = ts->runtime[j];
1241 if (ts->runtime[j] > rs->max_run[j])
1242 rs->max_run[j] = ts->runtime[j];
1245 if (ts->runtime[j]) {
1246 unsigned long runt = ts->runtime[j];
1247 unsigned long long kb;
1249 kb = ts->io_bytes[j] / rs->kb_base;
1250 bw = kb * 1000 / runt;
1252 if (bw < rs->min_bw[j])
1254 if (bw > rs->max_bw[j])
1257 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
1261 for (i = 0; i < groupid + 1; i++) {
1266 for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) {
1267 if (rs->max_run[ddir])
1268 rs->agg[ddir] = (rs->io_kb[ddir] * 1000) /
1274 * don't overwrite last signal output
1276 if (output_format == FIO_OUTPUT_NORMAL)
1278 else if (output_format == FIO_OUTPUT_JSON) {
1279 root = json_create_object();
1280 json_object_add_value_string(root, "fio version", fio_version_string);
1281 array = json_create_array();
1282 json_object_add_value_array(root, "jobs", array);
1285 for (i = 0; i < nr_ts; i++) {
1286 ts = &threadstats[i];
1287 rs = &runstats[ts->groupid];
1290 fio_server_send_ts(ts, rs);
1291 else if (output_format == FIO_OUTPUT_TERSE)
1292 show_thread_status_terse(ts, rs);
1293 else if (output_format == FIO_OUTPUT_JSON) {
1294 struct json_object *tmp = show_thread_status_json(ts, rs);
1295 json_array_add_value_object(array, tmp);
1297 show_thread_status(ts, rs);
1299 if (output_format == FIO_OUTPUT_JSON) {
1300 /* disk util stats, if any */
1301 show_disk_util(1, root);
1303 show_idle_prof_stats(FIO_OUTPUT_JSON, root);
1305 json_print_object(root);
1307 json_free_object(root);
1310 for (i = 0; i < groupid + 1; i++) {
1315 fio_server_send_gs(rs);
1316 else if (output_format == FIO_OUTPUT_NORMAL)
1317 show_group_stats(rs);
1321 fio_server_send_du();
1322 else if (output_format == FIO_OUTPUT_NORMAL)
1323 show_disk_util(0, NULL);
1325 show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL);
1331 static void *__show_running_run_stats(void *arg)
1333 struct thread_data *td;
1334 unsigned long long *rt;
1338 rt = malloc(thread_number * sizeof(unsigned long long));
1339 fio_gettime(&tv, NULL);
1341 for_each_td(td, i) {
1342 rt[i] = mtime_since(&td->start, &tv);
1343 if (td_read(td) && td->io_bytes[DDIR_READ])
1344 td->ts.runtime[DDIR_READ] += rt[i];
1345 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1346 td->ts.runtime[DDIR_WRITE] += rt[i];
1347 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1348 td->ts.runtime[DDIR_TRIM] += rt[i];
1350 update_rusage_stat(td);
1351 td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ];
1352 td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE];
1353 td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM];
1354 td->ts.total_run_time = mtime_since(&td->epoch, &tv);
1359 for_each_td(td, i) {
1360 if (td_read(td) && td->io_bytes[DDIR_READ])
1361 td->ts.runtime[DDIR_READ] -= rt[i];
1362 if (td_write(td) && td->io_bytes[DDIR_WRITE])
1363 td->ts.runtime[DDIR_WRITE] -= rt[i];
1364 if (td_trim(td) && td->io_bytes[DDIR_TRIM])
1365 td->ts.runtime[DDIR_TRIM] -= rt[i];
1373 * Called from signal handler. It _should_ be safe to just run this inline
1374 * in the sig handler, but we should be disturbing the system less by just
1375 * creating a thread to do it.
1377 void show_running_run_stats(void)
1381 pthread_create(&thread, NULL, __show_running_run_stats, NULL);
1382 pthread_detach(thread);
1385 static inline void add_stat_sample(struct io_stat *is, unsigned long data)
1390 if (data > is->max_val)
1392 if (data < is->min_val)
1395 delta = val - is->mean.u.f;
1397 is->mean.u.f += delta / (is->samples + 1.0);
1398 is->S.u.f += delta * (val - is->mean.u.f);
1404 static void __add_log_sample(struct io_log *iolog, unsigned long val,
1405 enum fio_ddir ddir, unsigned int bs,
1408 const int nr_samples = iolog->nr_samples;
1410 if (!iolog->nr_samples)
1411 iolog->avg_last = t;
1413 if (iolog->nr_samples == iolog->max_samples) {
1414 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
1416 iolog->log = realloc(iolog->log, new_size);
1417 iolog->max_samples <<= 1;
1420 iolog->log[nr_samples].val = val;
1421 iolog->log[nr_samples].time = t;
1422 iolog->log[nr_samples].ddir = ddir;
1423 iolog->log[nr_samples].bs = bs;
1424 iolog->nr_samples++;
1427 static inline void reset_io_stat(struct io_stat *ios)
1429 ios->max_val = ios->min_val = ios->samples = 0;
1430 ios->mean.u.f = ios->S.u.f = 0;
1433 static void add_log_sample(struct thread_data *td, struct io_log *iolog,
1434 unsigned long val, enum fio_ddir ddir,
1437 unsigned long elapsed, this_window;
1442 elapsed = mtime_since_now(&td->epoch);
1445 * If no time averaging, just add the log sample.
1447 if (!iolog->avg_msec) {
1448 __add_log_sample(iolog, val, ddir, bs, elapsed);
1453 * Add the sample. If the time period has passed, then
1454 * add that entry to the log and clear.
1456 add_stat_sample(&iolog->avg_window[ddir], val);
1459 * If period hasn't passed, adding the above sample is all we
1462 this_window = elapsed - iolog->avg_last;
1463 if (this_window < iolog->avg_msec)
1467 * Note an entry in the log. Use the mean from the logged samples,
1468 * making sure to properly round up. Only write a log entry if we
1469 * had actual samples done.
1471 if (iolog->avg_window[DDIR_READ].samples) {
1474 mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50;
1475 __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed);
1477 if (iolog->avg_window[DDIR_WRITE].samples) {
1480 mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50;
1481 __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed);
1483 if (iolog->avg_window[DDIR_TRIM].samples) {
1486 mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50;
1487 __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed);
1491 reset_io_stat(&iolog->avg_window[DDIR_READ]);
1492 reset_io_stat(&iolog->avg_window[DDIR_WRITE]);
1493 reset_io_stat(&iolog->avg_window[DDIR_TRIM]);
1494 iolog->avg_last = elapsed;
1497 void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
1499 struct io_log *iolog;
1504 iolog = agg_io_log[ddir];
1505 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
1508 static void add_clat_percentile_sample(struct thread_stat *ts,
1509 unsigned long usec, enum fio_ddir ddir)
1511 unsigned int idx = plat_val_to_idx(usec);
1512 assert(idx < FIO_IO_U_PLAT_NR);
1514 ts->io_u_plat[ddir][idx]++;
1517 void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
1518 unsigned long usec, unsigned int bs)
1520 struct thread_stat *ts = &td->ts;
1525 add_stat_sample(&ts->clat_stat[ddir], usec);
1528 add_log_sample(td, td->clat_log, usec, ddir, bs);
1530 if (ts->clat_percentiles)
1531 add_clat_percentile_sample(ts, usec, ddir);
1534 void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
1535 unsigned long usec, unsigned int bs)
1537 struct thread_stat *ts = &td->ts;
1542 add_stat_sample(&ts->slat_stat[ddir], usec);
1545 add_log_sample(td, td->slat_log, usec, ddir, bs);
1548 void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
1549 unsigned long usec, unsigned int bs)
1551 struct thread_stat *ts = &td->ts;
1556 add_stat_sample(&ts->lat_stat[ddir], usec);
1559 add_log_sample(td, td->lat_log, usec, ddir, bs);
1562 void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
1565 struct thread_stat *ts = &td->ts;
1566 unsigned long spent, rate;
1571 spent = mtime_since(&td->bw_sample_time, t);
1572 if (spent < td->o.bw_avg_time)
1576 * Compute both read and write rates for the interval.
1578 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
1581 delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir];
1583 continue; /* No entries for interval */
1585 rate = delta * 1000 / spent / 1024;
1586 add_stat_sample(&ts->bw_stat[ddir], rate);
1589 add_log_sample(td, td->bw_log, rate, ddir, bs);
1591 td->stat_io_bytes[ddir] = td->this_io_bytes[ddir];
1594 fio_gettime(&td->bw_sample_time, NULL);
1597 void add_iops_sample(struct thread_data *td, enum fio_ddir ddir,
1600 struct thread_stat *ts = &td->ts;
1601 unsigned long spent, iops;
1606 spent = mtime_since(&td->iops_sample_time, t);
1607 if (spent < td->o.iops_avg_time)
1611 * Compute both read and write rates for the interval.
1613 for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) {
1616 delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir];
1618 continue; /* No entries for interval */
1620 iops = (delta * 1000) / spent;
1621 add_stat_sample(&ts->iops_stat[ddir], iops);
1624 add_log_sample(td, td->iops_log, iops, ddir, 0);
1626 td->stat_io_blocks[ddir] = td->this_io_blocks[ddir];
1629 fio_gettime(&td->iops_sample_time, NULL);