13 void update_rusage_stat(struct thread_data *td)
15 struct thread_stat *ts = &td->ts;
17 getrusage(RUSAGE_SELF, &ts->ru_end);
19 ts->usr_time += mtime_since(&ts->ru_start.ru_utime,
20 &ts->ru_end.ru_utime);
21 ts->sys_time += mtime_since(&ts->ru_start.ru_stime,
22 &ts->ru_end.ru_stime);
23 ts->ctx += ts->ru_end.ru_nvcsw + ts->ru_end.ru_nivcsw
24 - (ts->ru_start.ru_nvcsw + ts->ru_start.ru_nivcsw);
25 ts->minf += ts->ru_end.ru_minflt - ts->ru_start.ru_minflt;
26 ts->majf += ts->ru_end.ru_majflt - ts->ru_start.ru_majflt;
28 memcpy(&ts->ru_start, &ts->ru_end, sizeof(ts->ru_end));
32 * Given a latency, return the index of the corresponding bucket in
33 * the structure tracking percentiles.
35 * (1) find the group (and error bits) that the value (latency)
36 * belongs to by looking at its MSB. (2) find the bucket number in the
37 * group by looking at the index bits.
40 static unsigned int plat_val_to_idx(unsigned int val)
42 unsigned int msb, error_bits, base, offset, idx;
44 /* Find MSB starting from bit 0 */
48 msb = (sizeof(val)*8) - __builtin_clz(val) - 1;
50 /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
51 * all bits of the sample as index */
52 if (msb <= FIO_IO_U_PLAT_BITS)
55 /* Compute the number of error bits to discard*/
56 error_bits = msb - FIO_IO_U_PLAT_BITS;
58 /* Compute the number of buckets before the group */
59 base = (error_bits + 1) << FIO_IO_U_PLAT_BITS;
61 /* Discard the error bits and apply the mask to find the
62 * index for the buckets in the group */
63 offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits);
65 /* Make sure the index does not exceed (array size - 1) */
66 idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1)?
67 (base + offset) : (FIO_IO_U_PLAT_NR - 1);
73 * Convert the given index of the bucket array to the value
74 * represented by the bucket
76 static unsigned int plat_idx_to_val(unsigned int idx)
78 unsigned int error_bits, k, base;
80 assert(idx < FIO_IO_U_PLAT_NR);
82 /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
83 * all bits of the sample as index */
84 if (idx < (FIO_IO_U_PLAT_VAL << 1) )
87 /* Find the group and compute the minimum value of that group */
88 error_bits = (idx >> FIO_IO_U_PLAT_BITS) -1;
89 base = 1 << (error_bits + FIO_IO_U_PLAT_BITS);
91 /* Find its bucket number of the group */
92 k = idx % FIO_IO_U_PLAT_VAL;
94 /* Return the mean of the range of the bucket */
95 return base + ((k + 0.5) * (1 << error_bits));
98 static int double_cmp(const void *a, const void *b)
100 const double fa = *(const double *)a;
101 const double fb = *(const double *)b;
113 * Find and display the p-th percentile of clat
115 static void show_clat_percentiles(unsigned int* io_u_plat, unsigned long nr,
118 unsigned long sum = 0;
119 unsigned int len, i, j = 0;
120 static const double def_list[FIO_IO_U_LIST_MAX_LEN] = {
121 1.0, 5.0, 10.0, 20.0, 30.0,
122 40.0, 50.0, 60.0, 70.0, 80.0,
123 90.0, 95.0, 99.0, 99.5, 99.9};
125 const double* plist = user_list? user_list: def_list;
126 for (len = 0; len <FIO_IO_U_LIST_MAX_LEN && plist[len] != 0; len++) {}
128 /* Sort the user-specified list. Note that this does not work
130 if (user_list && len > 1)
131 qsort((void*)user_list, len, sizeof(user_list[0]), double_cmp);
134 log_info(" clat percentiles (usec) :");
136 for (i = 0; i <FIO_IO_U_PLAT_NR && !is_last; i++) {
138 while (sum >= (plist[j]/100 * nr)) {
139 assert(plist[j] <= 100.0);
141 if (j!=0 && (j%4) == 0) /* for formatting */
144 /* end of the list */
145 is_last = (j == len - 1);
147 log_info(" %2.2fth=%u%c", plist[j], plat_idx_to_val(i),
148 (is_last? '\n' : ','));
152 if (j%4 == 3) /* for formatting */
159 static int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max,
160 double *mean, double *dev)
162 double n = is->samples;
164 if (is->samples == 0)
170 n = (double) is->samples;
174 *dev = sqrt(is->S / (n - 1.0));
181 static void show_group_stats(struct group_run_stats *rs, int id)
183 char *p1, *p2, *p3, *p4;
184 const char *ddir_str[] = { " READ", " WRITE" };
187 log_info("\nRun status group %d (all jobs):\n", id);
189 for (i = 0; i <= DDIR_WRITE; i++) {
190 const int i2p = is_power_of_2(rs->kb_base);
195 p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p);
196 p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p);
197 p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p);
198 p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p);
200 log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s,"
201 " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2,
202 p3, p4, rs->min_run[i],
212 #define ts_total_io_u(ts) \
213 ((ts)->total_io_u[0] + (ts)->total_io_u[1])
215 static void stat_calc_dist(unsigned int *map, unsigned long total,
221 * Do depth distribution calculations
223 for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
225 io_u_dist[i] = (double) map[i] / (double) total;
226 io_u_dist[i] *= 100.0;
227 if (io_u_dist[i] < 0.1 && map[i])
234 static void stat_calc_lat(struct thread_stat *ts, double *dst,
235 unsigned int *src, int nr)
237 unsigned long total = ts_total_io_u(ts);
241 * Do latency distribution calculations
243 for (i = 0; i < nr; i++) {
245 dst[i] = (double) src[i] / (double) total;
247 if (dst[i] < 0.01 && src[i])
254 static void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
256 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
259 static void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
261 stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
264 static int usec_to_msec(unsigned long *min, unsigned long *max, double *mean,
267 if (*min > 1000 && *max > 1000 && *mean > 1000.0 && *dev > 1000.0) {
278 static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
281 const char *ddir_str[] = { "read ", "write" };
282 unsigned long min, max, runt;
283 unsigned long long bw, iops;
285 char *io_p, *bw_p, *iops_p;
288 assert(ddir_rw(ddir));
290 if (!ts->runtime[ddir])
293 i2p = is_power_of_2(rs->kb_base);
294 runt = ts->runtime[ddir];
296 bw = (1000 * ts->io_bytes[ddir]) / runt;
297 io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p);
298 bw_p = num2str(bw, 6, 1, i2p);
300 iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
301 iops_p = num2str(iops, 6, 1, 0);
303 log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n",
304 ddir_str[ddir], io_p, bw_p, iops_p,
311 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) {
312 const char *base = "(usec)";
315 if (!usec_to_msec(&min, &max, &mean, &dev))
318 minp = num2str(min, 6, 1, 0);
319 maxp = num2str(max, 6, 1, 0);
321 log_info(" slat %s: min=%s, max=%s, avg=%5.02f,"
322 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
327 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) {
328 const char *base = "(usec)";
331 if (!usec_to_msec(&min, &max, &mean, &dev))
334 minp = num2str(min, 6, 1, 0);
335 maxp = num2str(max, 6, 1, 0);
337 log_info(" clat %s: min=%s, max=%s, avg=%5.02f,"
338 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
343 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) {
344 const char *base = "(usec)";
347 if (!usec_to_msec(&min, &max, &mean, &dev))
350 minp = num2str(min, 6, 1, 0);
351 maxp = num2str(max, 6, 1, 0);
353 log_info(" lat %s: min=%s, max=%s, avg=%5.02f,"
354 " stdev=%5.02f\n", base, minp, maxp, mean, dev);
359 if (ts->clat_percentiles) {
360 show_clat_percentiles(ts->io_u_plat[ddir],
361 ts->clat_stat[ddir].samples,
362 ts->percentile_list);
364 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
367 p_of_agg = mean * 100 / (double) rs->agg[ddir];
368 log_info(" bw (KB/s) : min=%5lu, max=%5lu, per=%3.2f%%,"
369 " avg=%5.02f, stdev=%5.02f\n", min, max, p_of_agg,
374 static void show_lat(double *io_u_lat, int nr, const char **ranges,
377 int new_line = 1, i, line = 0;
379 for (i = 0; i < nr; i++) {
380 if (io_u_lat[i] <= 0.0)
385 log_info(" lat (%s): ", msg);
391 log_info("%s%3.2f%%", ranges[i], io_u_lat[i]);
398 static void show_lat_u(double *io_u_lat_u)
400 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
401 "250=", "500=", "750=", "1000=", };
403 show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec");
406 static void show_lat_m(double *io_u_lat_m)
408 const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
409 "250=", "500=", "750=", "1000=", "2000=",
412 show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec");
415 static void show_latencies(double *io_u_lat_u, double *io_u_lat_m)
417 show_lat_u(io_u_lat_u);
419 show_lat_m(io_u_lat_m);
423 static void show_thread_status(struct thread_stat *ts,
424 struct group_run_stats *rs)
426 double usr_cpu, sys_cpu;
427 unsigned long runtime;
428 double io_u_dist[FIO_IO_U_MAP_NR];
429 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
430 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
432 if (!(ts->io_bytes[0] + ts->io_bytes[1]) &&
433 !(ts->total_io_u[0] + ts->total_io_u[1]))
437 log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d\n",
438 ts->name, ts->groupid, ts->members,
439 ts->error, (int) ts->pid);
441 log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d\n",
442 ts->name, ts->groupid, ts->members,
443 ts->error, ts->verror, (int) ts->pid);
447 log_info(" Description : [%s]\n", ts->description);
449 if (ts->io_bytes[DDIR_READ])
450 show_ddir_status(rs, ts, DDIR_READ);
451 if (ts->io_bytes[DDIR_WRITE])
452 show_ddir_status(rs, ts, DDIR_WRITE);
454 runtime = ts->total_run_time;
456 double runt = (double) runtime;
458 usr_cpu = (double) ts->usr_time * 100 / runt;
459 sys_cpu = (double) ts->sys_time * 100 / runt;
465 log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu,"
466 " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf);
468 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
469 log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%,"
470 " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
471 io_u_dist[1], io_u_dist[2],
472 io_u_dist[3], io_u_dist[4],
473 io_u_dist[5], io_u_dist[6]);
475 stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist);
476 log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
477 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
478 io_u_dist[1], io_u_dist[2],
479 io_u_dist[3], io_u_dist[4],
480 io_u_dist[5], io_u_dist[6]);
481 stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist);
482 log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%,"
483 " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0],
484 io_u_dist[1], io_u_dist[2],
485 io_u_dist[3], io_u_dist[4],
486 io_u_dist[5], io_u_dist[6]);
487 log_info(" issued r/w/d: total=%lu/%lu/%lu, short=%lu/%lu/%lu\n",
488 ts->total_io_u[0], ts->total_io_u[1],
490 ts->short_io_u[0], ts->short_io_u[1],
492 stat_calc_lat_u(ts, io_u_lat_u);
493 stat_calc_lat_m(ts, io_u_lat_m);
494 show_latencies(io_u_lat_u, io_u_lat_m);
495 if (ts->continue_on_error) {
496 log_info(" errors : total=%lu, first_error=%d/<%s>\n",
499 strerror(ts->first_error));
503 static void show_ddir_status_terse(struct thread_stat *ts,
504 struct group_run_stats *rs, int ddir)
506 unsigned long min, max;
507 unsigned long long bw;
510 assert(ddir_rw(ddir));
513 if (ts->runtime[ddir])
514 bw = ts->io_bytes[ddir] / ts->runtime[ddir];
516 log_info(";%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw,
519 if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
520 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
522 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
524 if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
525 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
527 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
529 if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
530 log_info(";%lu;%lu;%f;%f", min, max, mean, dev);
532 log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0);
534 if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
537 p_of_agg = mean * 100 / (double) rs->agg[ddir];
538 log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev);
540 log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0);
543 #define FIO_TERSE_VERSION "2"
545 static void show_thread_status_terse(struct thread_stat *ts,
546 struct group_run_stats *rs)
548 double io_u_dist[FIO_IO_U_MAP_NR];
549 double io_u_lat_u[FIO_IO_U_LAT_U_NR];
550 double io_u_lat_m[FIO_IO_U_LAT_M_NR];
551 double usr_cpu, sys_cpu;
555 log_info("%s;%s;%d;%d", FIO_TERSE_VERSION, ts->name, ts->groupid,
557 /* Log Read Status */
558 show_ddir_status_terse(ts, rs, 0);
559 /* Log Write Status */
560 show_ddir_status_terse(ts, rs, 1);
563 if (ts->total_run_time) {
564 double runt = (double) ts->total_run_time;
566 usr_cpu = (double) ts->usr_time * 100 / runt;
567 sys_cpu = (double) ts->sys_time * 100 / runt;
573 log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf,
576 /* Calc % distribution of IO depths, usecond, msecond latency */
577 stat_calc_dist(ts->io_u_map, ts_total_io_u(ts), io_u_dist);
578 stat_calc_lat_u(ts, io_u_lat_u);
579 stat_calc_lat_m(ts, io_u_lat_m);
581 /* Only show fixed 7 I/O depth levels*/
582 log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%",
583 io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3],
584 io_u_dist[4], io_u_dist[5], io_u_dist[6]);
586 /* Microsecond latency */
587 for (i = 0; i < FIO_IO_U_LAT_U_NR; i++)
588 log_info(";%3.2f%%", io_u_lat_u[i]);
589 /* Millisecond latency */
590 for (i = 0; i < FIO_IO_U_LAT_M_NR; i++)
591 log_info(";%3.2f%%", io_u_lat_m[i]);
592 /* Additional output if continue_on_error set - default off*/
593 if (ts->continue_on_error)
594 log_info(";%lu;%d", ts->total_err_count, ts->first_error);
597 /* Additional output if description is set */
599 log_info(";%s", ts->description);
604 static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr)
608 dst->min_val = min(dst->min_val, src->min_val);
609 dst->max_val = max(dst->max_val, src->max_val);
612 * Compute new mean and S after the merge
613 * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance
614 * #Parallel_algorithm>
620 double delta = src->mean - dst->mean;
622 mean = ((src->mean * src->samples) +
623 (dst->mean * dst->samples)) /
624 (dst->samples + src->samples);
626 S = src->S + dst->S + pow(delta, 2.0) *
627 (dst->samples * src->samples) /
628 (dst->samples + src->samples);
631 dst->samples += src->samples;
636 void show_run_stats(void)
638 struct group_run_stats *runstats, *rs;
639 struct thread_data *td;
640 struct thread_stat *threadstats, *ts;
641 int i, j, k, l, nr_ts, last_ts, idx;
642 int kb_base_warned = 0;
644 runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1));
646 for (i = 0; i < groupid + 1; i++) {
649 memset(rs, 0, sizeof(*rs));
650 rs->min_bw[0] = rs->min_run[0] = ~0UL;
651 rs->min_bw[1] = rs->min_run[1] = ~0UL;
655 * find out how many threads stats we need. if group reporting isn't
656 * enabled, it's one-per-td.
661 if (!td->o.group_reporting) {
665 if (last_ts == td->groupid)
668 last_ts = td->groupid;
672 threadstats = malloc(nr_ts * sizeof(struct thread_stat));
674 for (i = 0; i < nr_ts; i++) {
675 ts = &threadstats[i];
677 memset(ts, 0, sizeof(*ts));
678 for (j = 0; j <= DDIR_WRITE; j++) {
679 ts->lat_stat[j].min_val = -1UL;
680 ts->clat_stat[j].min_val = -1UL;
681 ts->slat_stat[j].min_val = -1UL;
682 ts->bw_stat[j].min_val = -1UL;
691 if (idx && (!td->o.group_reporting ||
692 (td->o.group_reporting && last_ts != td->groupid))) {
697 last_ts = td->groupid;
699 ts = &threadstats[j];
701 ts->clat_percentiles = td->o.clat_percentiles;
702 if (td->o.overwrite_plist)
703 ts->percentile_list = td->o.percentile_list;
705 ts->percentile_list = NULL;
710 if (ts->groupid == -1) {
712 * These are per-group shared already
714 ts->name = td->o.name;
715 ts->description = td->o.description;
716 ts->groupid = td->groupid;
719 * first pid in group, not very useful...
723 ts->kb_base = td->o.kb_base;
724 } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) {
725 log_info("fio: kb_base differs for jobs in group, using"
726 " %u as the base\n", ts->kb_base);
730 ts->continue_on_error = td->o.continue_on_error;
731 ts->total_err_count += td->total_err_count;
732 ts->first_error = td->first_error;
734 if (!td->error && td->o.continue_on_error &&
736 ts->error = td->first_error;
737 ts->verror = td->verror;
738 } else if (td->error) {
739 ts->error = td->error;
740 ts->verror = td->verror;
744 for (l = 0; l <= DDIR_WRITE; l++) {
745 sum_stat(&ts->clat_stat[l], &td->ts.clat_stat[l], idx);
746 sum_stat(&ts->slat_stat[l], &td->ts.slat_stat[l], idx);
747 sum_stat(&ts->lat_stat[l], &td->ts.lat_stat[l], idx);
748 sum_stat(&ts->bw_stat[l], &td->ts.bw_stat[l], idx);
750 ts->stat_io_bytes[l] += td->ts.stat_io_bytes[l];
751 ts->io_bytes[l] += td->ts.io_bytes[l];
753 if (ts->runtime[l] < td->ts.runtime[l])
754 ts->runtime[l] = td->ts.runtime[l];
757 ts->usr_time += td->ts.usr_time;
758 ts->sys_time += td->ts.sys_time;
759 ts->ctx += td->ts.ctx;
760 ts->majf += td->ts.majf;
761 ts->minf += td->ts.minf;
763 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
764 ts->io_u_map[k] += td->ts.io_u_map[k];
765 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
766 ts->io_u_submit[k] += td->ts.io_u_submit[k];
767 for (k = 0; k < FIO_IO_U_MAP_NR; k++)
768 ts->io_u_complete[k] += td->ts.io_u_complete[k];
769 for (k = 0; k < FIO_IO_U_LAT_U_NR; k++)
770 ts->io_u_lat_u[k] += td->ts.io_u_lat_u[k];
771 for (k = 0; k < FIO_IO_U_LAT_M_NR; k++)
772 ts->io_u_lat_m[k] += td->ts.io_u_lat_m[k];
775 for (k = 0; k <= 2; k++) {
778 ts->total_io_u[k] += td->ts.total_io_u[k];
779 ts->short_io_u[k] += td->ts.short_io_u[k];
781 for (m = 0; m < FIO_IO_U_PLAT_NR; m++)
782 ts->io_u_plat[k][m] += td->ts.io_u_plat[k][m];
785 ts->total_run_time += td->ts.total_run_time;
786 ts->total_submit += td->ts.total_submit;
787 ts->total_complete += td->ts.total_complete;
790 for (i = 0; i < nr_ts; i++) {
791 unsigned long long bw;
793 ts = &threadstats[i];
794 rs = &runstats[ts->groupid];
795 rs->kb_base = ts->kb_base;
797 for (j = 0; j <= DDIR_WRITE; j++) {
800 if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j])
801 rs->min_run[j] = ts->runtime[j];
802 if (ts->runtime[j] > rs->max_run[j])
803 rs->max_run[j] = ts->runtime[j];
806 if (ts->runtime[j]) {
809 runt = ts->runtime[j];
810 bw = ts->io_bytes[j] / runt;
812 if (bw < rs->min_bw[j])
814 if (bw > rs->max_bw[j])
817 rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base;
821 for (i = 0; i < groupid + 1; i++) {
822 unsigned long max_run[2];
825 max_run[0] = rs->max_run[0];
826 max_run[1] = rs->max_run[1];
829 rs->agg[0] = (rs->io_kb[0] * 1000) / max_run[0];
831 rs->agg[1] = (rs->io_kb[1] * 1000) / max_run[1];
835 * don't overwrite last signal output
840 for (i = 0; i < nr_ts; i++) {
841 ts = &threadstats[i];
842 rs = &runstats[ts->groupid];
845 show_thread_status_terse(ts, rs);
847 show_thread_status(ts, rs);
851 for (i = 0; i < groupid + 1; i++)
852 show_group_stats(&runstats[i], i);
861 static inline void add_stat_sample(struct io_stat *is, unsigned long data)
866 if (data > is->max_val)
868 if (data < is->min_val)
871 delta = val - is->mean;
873 is->mean += delta / (is->samples + 1.0);
874 is->S += delta * (val - is->mean);
880 static void __add_log_sample(struct io_log *iolog, unsigned long val,
881 enum fio_ddir ddir, unsigned int bs,
884 const int nr_samples = iolog->nr_samples;
886 if (iolog->nr_samples == iolog->max_samples) {
887 int new_size = sizeof(struct io_sample) * iolog->max_samples*2;
889 iolog->log = realloc(iolog->log, new_size);
890 iolog->max_samples <<= 1;
893 iolog->log[nr_samples].val = val;
894 iolog->log[nr_samples].time = t;
895 iolog->log[nr_samples].ddir = ddir;
896 iolog->log[nr_samples].bs = bs;
900 static void add_log_sample(struct thread_data *td, struct io_log *iolog,
901 unsigned long val, enum fio_ddir ddir,
907 __add_log_sample(iolog, val, ddir, bs, mtime_since_now(&td->epoch));
910 void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs)
912 struct io_log *iolog;
917 iolog = agg_io_log[ddir];
918 __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis());
921 static void add_clat_percentile_sample(struct thread_stat *ts,
922 unsigned long usec, enum fio_ddir ddir)
924 unsigned int idx = plat_val_to_idx(usec);
925 assert(idx < FIO_IO_U_PLAT_NR);
927 ts->io_u_plat[ddir][idx]++;
930 void add_clat_sample(struct thread_data *td, enum fio_ddir ddir,
931 unsigned long usec, unsigned int bs)
933 struct thread_stat *ts = &td->ts;
938 add_stat_sample(&ts->clat_stat[ddir], usec);
941 add_log_sample(td, ts->clat_log, usec, ddir, bs);
943 if (ts->clat_percentiles)
944 add_clat_percentile_sample(ts, usec, ddir);
947 void add_slat_sample(struct thread_data *td, enum fio_ddir ddir,
948 unsigned long usec, unsigned int bs)
950 struct thread_stat *ts = &td->ts;
955 add_stat_sample(&ts->slat_stat[ddir], usec);
958 add_log_sample(td, ts->slat_log, usec, ddir, bs);
961 void add_lat_sample(struct thread_data *td, enum fio_ddir ddir,
962 unsigned long usec, unsigned int bs)
964 struct thread_stat *ts = &td->ts;
969 add_stat_sample(&ts->lat_stat[ddir], usec);
972 add_log_sample(td, ts->lat_log, usec, ddir, bs);
975 void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs,
978 struct thread_stat *ts = &td->ts;
979 unsigned long spent, rate;
984 spent = mtime_since(&ts->stat_sample_time[ddir], t);
985 if (spent < td->o.bw_avg_time)
988 rate = (td->this_io_bytes[ddir] - ts->stat_io_bytes[ddir]) *
990 add_stat_sample(&ts->bw_stat[ddir], rate);
993 add_log_sample(td, ts->bw_log, rate, ddir, bs);
995 fio_gettime(&ts->stat_sample_time[ddir], NULL);
996 ts->stat_io_bytes[ddir] = td->this_io_bytes[ddir];