Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <string.h> |
| 3 | #include <sys/time.h> |
| 4 | #include <sys/types.h> |
Jens Axboe | 5c4e1db | 2006-06-07 14:17:08 +0200 | [diff] [blame] | 5 | #include <sys/stat.h> |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 6 | #include <dirent.h> |
| 7 | #include <libgen.h> |
| 8 | #include <math.h> |
| 9 | |
| 10 | #include "fio.h" |
Jens Axboe | 7c9b1bc | 2009-06-03 09:25:57 +0200 | [diff] [blame] | 11 | #include "diskutil.h" |
Jens Axboe | c7c6cb4 | 2011-10-13 14:12:40 +0200 | [diff] [blame] | 12 | #include "lib/ieee754.h" |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 13 | #include "json.h" |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 14 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 15 | void update_rusage_stat(struct thread_data *td) |
| 16 | { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 17 | struct thread_stat *ts = &td->ts; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 18 | |
Yufei Ren | 4005939 | 2012-10-22 21:29:37 -0400 | [diff] [blame] | 19 | #ifdef RUSAGE_THREAD |
Yufei Ren | f5fd0b1 | 2012-10-19 23:11:50 -0400 | [diff] [blame] | 20 | getrusage(RUSAGE_THREAD, &td->ru_end); |
| 21 | #else |
Jens Axboe | c8aaba1 | 2011-10-03 12:14:19 +0200 | [diff] [blame] | 22 | getrusage(RUSAGE_SELF, &td->ru_end); |
Yufei Ren | f5fd0b1 | 2012-10-19 23:11:50 -0400 | [diff] [blame] | 23 | #endif |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 24 | |
Jens Axboe | c8aaba1 | 2011-10-03 12:14:19 +0200 | [diff] [blame] | 25 | ts->usr_time += mtime_since(&td->ru_start.ru_utime, |
| 26 | &td->ru_end.ru_utime); |
| 27 | ts->sys_time += mtime_since(&td->ru_start.ru_stime, |
| 28 | &td->ru_end.ru_stime); |
| 29 | ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw |
| 30 | - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); |
| 31 | ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt; |
| 32 | ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt; |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 33 | |
Jens Axboe | c8aaba1 | 2011-10-03 12:14:19 +0200 | [diff] [blame] | 34 | memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 35 | } |
| 36 | |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 37 | /* |
| 38 | * Given a latency, return the index of the corresponding bucket in |
| 39 | * the structure tracking percentiles. |
| 40 | * |
| 41 | * (1) find the group (and error bits) that the value (latency) |
| 42 | * belongs to by looking at its MSB. (2) find the bucket number in the |
| 43 | * group by looking at the index bits. |
| 44 | * |
| 45 | */ |
| 46 | static unsigned int plat_val_to_idx(unsigned int val) |
| 47 | { |
| 48 | unsigned int msb, error_bits, base, offset, idx; |
| 49 | |
| 50 | /* Find MSB starting from bit 0 */ |
| 51 | if (val == 0) |
| 52 | msb = 0; |
| 53 | else |
| 54 | msb = (sizeof(val)*8) - __builtin_clz(val) - 1; |
| 55 | |
Jens Axboe | 716050f | 2011-08-16 08:43:45 +0200 | [diff] [blame] | 56 | /* |
| 57 | * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use |
| 58 | * all bits of the sample as index |
| 59 | */ |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 60 | if (msb <= FIO_IO_U_PLAT_BITS) |
| 61 | return val; |
| 62 | |
| 63 | /* Compute the number of error bits to discard*/ |
| 64 | error_bits = msb - FIO_IO_U_PLAT_BITS; |
| 65 | |
| 66 | /* Compute the number of buckets before the group */ |
| 67 | base = (error_bits + 1) << FIO_IO_U_PLAT_BITS; |
| 68 | |
Jens Axboe | 716050f | 2011-08-16 08:43:45 +0200 | [diff] [blame] | 69 | /* |
| 70 | * Discard the error bits and apply the mask to find the |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 71 | * index for the buckets in the group |
Jens Axboe | 716050f | 2011-08-16 08:43:45 +0200 | [diff] [blame] | 72 | */ |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 73 | offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits); |
| 74 | |
| 75 | /* Make sure the index does not exceed (array size - 1) */ |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 76 | idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1) ? |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 77 | (base + offset) : (FIO_IO_U_PLAT_NR - 1); |
| 78 | |
| 79 | return idx; |
| 80 | } |
| 81 | |
| 82 | /* |
| 83 | * Convert the given index of the bucket array to the value |
| 84 | * represented by the bucket |
| 85 | */ |
| 86 | static unsigned int plat_idx_to_val(unsigned int idx) |
| 87 | { |
| 88 | unsigned int error_bits, k, base; |
| 89 | |
| 90 | assert(idx < FIO_IO_U_PLAT_NR); |
| 91 | |
| 92 | /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use |
| 93 | * all bits of the sample as index */ |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 94 | if (idx < (FIO_IO_U_PLAT_VAL << 1)) |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 95 | return idx; |
| 96 | |
| 97 | /* Find the group and compute the minimum value of that group */ |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 98 | error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 99 | base = 1 << (error_bits + FIO_IO_U_PLAT_BITS); |
| 100 | |
| 101 | /* Find its bucket number of the group */ |
| 102 | k = idx % FIO_IO_U_PLAT_VAL; |
| 103 | |
| 104 | /* Return the mean of the range of the bucket */ |
| 105 | return base + ((k + 0.5) * (1 << error_bits)); |
| 106 | } |
| 107 | |
| 108 | static int double_cmp(const void *a, const void *b) |
| 109 | { |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 110 | const fio_fp64_t fa = *(const fio_fp64_t *) a; |
| 111 | const fio_fp64_t fb = *(const fio_fp64_t *) b; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 112 | int cmp = 0; |
| 113 | |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 114 | if (fa.u.f > fb.u.f) |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 115 | cmp = 1; |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 116 | else if (fa.u.f < fb.u.f) |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 117 | cmp = -1; |
| 118 | |
| 119 | return cmp; |
| 120 | } |
| 121 | |
Jens Axboe | a269790 | 2012-03-05 16:43:49 +0100 | [diff] [blame] | 122 | unsigned int calc_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, |
| 123 | fio_fp64_t *plist, unsigned int **output, |
| 124 | unsigned int *maxv, unsigned int *minv) |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 125 | { |
| 126 | unsigned long sum = 0; |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 127 | unsigned int len, i, j = 0; |
| 128 | unsigned int oval_len = 0; |
| 129 | unsigned int *ovals = NULL; |
| 130 | int is_last; |
| 131 | |
| 132 | *minv = -1U; |
| 133 | *maxv = 0; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 134 | |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 135 | len = 0; |
| 136 | while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) |
| 137 | len++; |
Jens Axboe | 716050f | 2011-08-16 08:43:45 +0200 | [diff] [blame] | 138 | |
Jens Axboe | 351de8d | 2011-10-12 21:03:45 +0200 | [diff] [blame] | 139 | if (!len) |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 140 | return 0; |
Jens Axboe | 351de8d | 2011-10-12 21:03:45 +0200 | [diff] [blame] | 141 | |
Jens Axboe | 716050f | 2011-08-16 08:43:45 +0200 | [diff] [blame] | 142 | /* |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 143 | * Sort the percentile list. Note that it may already be sorted if |
| 144 | * we are using the default values, but since it's a short list this |
| 145 | * isn't a worry. Also note that this does not work for NaN values. |
Jens Axboe | 716050f | 2011-08-16 08:43:45 +0200 | [diff] [blame] | 146 | */ |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 147 | if (len > 1) |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 148 | qsort((void *)plist, len, sizeof(plist[0]), double_cmp); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 149 | |
Jens Axboe | 4f6f829 | 2011-10-13 09:28:21 +0200 | [diff] [blame] | 150 | /* |
| 151 | * Calculate bucket values, note down max and min values |
| 152 | */ |
Jens Axboe | 07511a6 | 2011-10-13 12:00:24 +0200 | [diff] [blame] | 153 | is_last = 0; |
| 154 | for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) { |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 155 | sum += io_u_plat[i]; |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 156 | while (sum >= (plist[j].u.f / 100.0 * nr)) { |
| 157 | assert(plist[j].u.f <= 100.0); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 158 | |
Jens Axboe | 4f6f829 | 2011-10-13 09:28:21 +0200 | [diff] [blame] | 159 | if (j == oval_len) { |
| 160 | oval_len += 100; |
| 161 | ovals = realloc(ovals, oval_len * sizeof(unsigned int)); |
| 162 | } |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 163 | |
Jens Axboe | 4f6f829 | 2011-10-13 09:28:21 +0200 | [diff] [blame] | 164 | ovals[j] = plat_idx_to_val(i); |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 165 | if (ovals[j] < *minv) |
| 166 | *minv = ovals[j]; |
| 167 | if (ovals[j] > *maxv) |
| 168 | *maxv = ovals[j]; |
Jens Axboe | 07511a6 | 2011-10-13 12:00:24 +0200 | [diff] [blame] | 169 | |
| 170 | is_last = (j == len - 1); |
| 171 | if (is_last) |
| 172 | break; |
| 173 | |
Jens Axboe | 4f6f829 | 2011-10-13 09:28:21 +0200 | [diff] [blame] | 174 | j++; |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 175 | } |
| 176 | } |
Jens Axboe | 4f6f829 | 2011-10-13 09:28:21 +0200 | [diff] [blame] | 177 | |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 178 | *output = ovals; |
| 179 | return len; |
| 180 | } |
| 181 | |
| 182 | /* |
| 183 | * Find and display the p-th percentile of clat |
| 184 | */ |
| 185 | static void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, |
| 186 | fio_fp64_t *plist) |
| 187 | { |
| 188 | unsigned int len, j = 0, minv, maxv; |
| 189 | unsigned int *ovals; |
| 190 | int is_last, scale_down; |
| 191 | |
| 192 | len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv); |
| 193 | if (!len) |
| 194 | goto out; |
| 195 | |
Jens Axboe | 4f6f829 | 2011-10-13 09:28:21 +0200 | [diff] [blame] | 196 | /* |
| 197 | * We default to usecs, but if the value range is such that we |
| 198 | * should scale down to msecs, do that. |
| 199 | */ |
| 200 | if (minv > 2000 && maxv > 99999) { |
| 201 | scale_down = 1; |
| 202 | log_info(" clat percentiles (msec):\n |"); |
| 203 | } else { |
| 204 | scale_down = 0; |
| 205 | log_info(" clat percentiles (usec):\n |"); |
| 206 | } |
| 207 | |
| 208 | for (j = 0; j < len; j++) { |
| 209 | char fbuf[8]; |
| 210 | |
| 211 | /* for formatting */ |
| 212 | if (j != 0 && (j % 4) == 0) |
| 213 | log_info(" |"); |
| 214 | |
| 215 | /* end of the list */ |
| 216 | is_last = (j == len - 1); |
| 217 | |
| 218 | if (plist[j].u.f < 10.0) |
| 219 | sprintf(fbuf, " %2.2f", plist[j].u.f); |
| 220 | else |
| 221 | sprintf(fbuf, "%2.2f", plist[j].u.f); |
| 222 | |
| 223 | if (scale_down) |
| 224 | ovals[j] = (ovals[j] + 999) / 1000; |
| 225 | |
| 226 | log_info(" %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ','); |
| 227 | |
| 228 | if (is_last) |
| 229 | break; |
| 230 | |
| 231 | if (j % 4 == 3) /* for formatting */ |
| 232 | log_info("\n"); |
| 233 | } |
| 234 | |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 235 | out: |
Jens Axboe | 4f6f829 | 2011-10-13 09:28:21 +0200 | [diff] [blame] | 236 | if (ovals) |
| 237 | free(ovals); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 238 | } |
| 239 | |
Jens Axboe | b29ad56 | 2012-03-05 13:08:51 +0100 | [diff] [blame] | 240 | int calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, |
| 241 | double *mean, double *dev) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 242 | { |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 243 | double n = is->samples; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 244 | |
| 245 | if (is->samples == 0) |
| 246 | return 0; |
| 247 | |
| 248 | *min = is->min_val; |
| 249 | *max = is->max_val; |
| 250 | |
| 251 | n = (double) is->samples; |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 252 | *mean = is->mean.u.f; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 253 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 254 | if (n > 1.0) |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 255 | *dev = sqrt(is->S.u.f / (n - 1.0)); |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 256 | else |
Jens Axboe | 4b43f54 | 2007-07-19 21:38:35 +0200 | [diff] [blame] | 257 | *dev = 0; |
Jens Axboe | ef9c5c4 | 2007-01-03 14:21:13 +0100 | [diff] [blame] | 258 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 259 | return 1; |
| 260 | } |
| 261 | |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 262 | void show_group_stats(struct group_run_stats *rs) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 263 | { |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 264 | char *p1, *p2, *p3, *p4; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 265 | const char *ddir_str[] = { " READ", " WRITE" , " TRIM"}; |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 266 | int i; |
| 267 | |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 268 | log_info("\nRun status group %d (all jobs):\n", rs->groupid); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 269 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 270 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 271 | const int i2p = is_power_of_2(rs->kb_base); |
| 272 | |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 273 | if (!rs->max_run[i]) |
| 274 | continue; |
| 275 | |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 276 | p1 = num2str(rs->io_kb[i], 6, rs->kb_base, i2p); |
| 277 | p2 = num2str(rs->agg[i], 6, rs->kb_base, i2p); |
| 278 | p3 = num2str(rs->min_bw[i], 6, rs->kb_base, i2p); |
| 279 | p4 = num2str(rs->max_bw[i], 6, rs->kb_base, i2p); |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 280 | |
Jens Axboe | b22989b | 2009-07-17 22:29:23 +0200 | [diff] [blame] | 281 | log_info("%s: io=%sB, aggrb=%sB/s, minb=%sB/s, maxb=%sB/s," |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 282 | " mint=%llumsec, maxt=%llumsec\n", ddir_str[i], p1, p2, |
| 283 | p3, p4, rs->min_run[i], |
| 284 | rs->max_run[i]); |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 285 | |
| 286 | free(p1); |
| 287 | free(p2); |
| 288 | free(p3); |
| 289 | free(p4); |
| 290 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 291 | } |
| 292 | |
Jens Axboe | 2e33101 | 2012-03-05 22:07:54 +0100 | [diff] [blame] | 293 | void stat_calc_dist(unsigned int *map, unsigned long total, double *io_u_dist) |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 294 | { |
| 295 | int i; |
| 296 | |
| 297 | /* |
| 298 | * Do depth distribution calculations |
| 299 | */ |
| 300 | for (i = 0; i < FIO_IO_U_MAP_NR; i++) { |
Jens Axboe | 838bc70 | 2008-05-22 13:08:23 +0200 | [diff] [blame] | 301 | if (total) { |
| 302 | io_u_dist[i] = (double) map[i] / (double) total; |
| 303 | io_u_dist[i] *= 100.0; |
| 304 | if (io_u_dist[i] < 0.1 && map[i]) |
| 305 | io_u_dist[i] = 0.1; |
| 306 | } else |
| 307 | io_u_dist[i] = 0.0; |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 311 | static void stat_calc_lat(struct thread_stat *ts, double *dst, |
| 312 | unsigned int *src, int nr) |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 313 | { |
Jens Axboe | d79db12 | 2012-09-24 08:51:24 +0200 | [diff] [blame] | 314 | unsigned long total = ddir_rw_sum(ts->total_io_u); |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 315 | int i; |
| 316 | |
| 317 | /* |
| 318 | * Do latency distribution calculations |
| 319 | */ |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 320 | for (i = 0; i < nr; i++) { |
Jens Axboe | 838bc70 | 2008-05-22 13:08:23 +0200 | [diff] [blame] | 321 | if (total) { |
| 322 | dst[i] = (double) src[i] / (double) total; |
| 323 | dst[i] *= 100.0; |
| 324 | if (dst[i] < 0.01 && src[i]) |
| 325 | dst[i] = 0.01; |
| 326 | } else |
| 327 | dst[i] = 0.0; |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 328 | } |
| 329 | } |
| 330 | |
Jens Axboe | e5bd134 | 2012-03-05 21:38:12 +0100 | [diff] [blame] | 331 | void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat) |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 332 | { |
| 333 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR); |
| 334 | } |
| 335 | |
Jens Axboe | e5bd134 | 2012-03-05 21:38:12 +0100 | [diff] [blame] | 336 | void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat) |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 337 | { |
| 338 | stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR); |
| 339 | } |
| 340 | |
Jens Axboe | b29ad56 | 2012-03-05 13:08:51 +0100 | [diff] [blame] | 341 | static void display_lat(const char *name, unsigned long min, unsigned long max, |
| 342 | double mean, double dev) |
Jens Axboe | ea2accc | 2007-06-19 09:48:44 +0200 | [diff] [blame] | 343 | { |
Jens Axboe | b29ad56 | 2012-03-05 13:08:51 +0100 | [diff] [blame] | 344 | const char *base = "(usec)"; |
| 345 | char *minp, *maxp; |
Jens Axboe | ea2accc | 2007-06-19 09:48:44 +0200 | [diff] [blame] | 346 | |
Jens Axboe | b29ad56 | 2012-03-05 13:08:51 +0100 | [diff] [blame] | 347 | if (!usec_to_msec(&min, &max, &mean, &dev)) |
| 348 | base = "(msec)"; |
| 349 | |
| 350 | minp = num2str(min, 6, 1, 0); |
| 351 | maxp = num2str(max, 6, 1, 0); |
| 352 | |
| 353 | log_info(" %s %s: min=%s, max=%s, avg=%5.02f," |
| 354 | " stdev=%5.02f\n", name, base, minp, maxp, mean, dev); |
| 355 | |
| 356 | free(minp); |
| 357 | free(maxp); |
Jens Axboe | ea2accc | 2007-06-19 09:48:44 +0200 | [diff] [blame] | 358 | } |
| 359 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 360 | static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 361 | int ddir) |
| 362 | { |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 363 | const char *ddir_str[] = { "read ", "write", "trim" }; |
Jens Axboe | 8879fd1 | 2009-04-20 10:06:02 +0200 | [diff] [blame] | 364 | unsigned long min, max, runt; |
Jens Axboe | b360506 | 2007-03-12 14:19:47 +0100 | [diff] [blame] | 365 | unsigned long long bw, iops; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 366 | double mean, dev; |
Jens Axboe | b360506 | 2007-03-12 14:19:47 +0100 | [diff] [blame] | 367 | char *io_p, *bw_p, *iops_p; |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 368 | int i2p; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 369 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 370 | assert(ddir_rw(ddir)); |
| 371 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 372 | if (!ts->runtime[ddir]) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 373 | return; |
| 374 | |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 375 | i2p = is_power_of_2(rs->kb_base); |
Jens Axboe | 8879fd1 | 2009-04-20 10:06:02 +0200 | [diff] [blame] | 376 | runt = ts->runtime[ddir]; |
| 377 | |
| 378 | bw = (1000 * ts->io_bytes[ddir]) / runt; |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 379 | io_p = num2str(ts->io_bytes[ddir], 6, 1, i2p); |
| 380 | bw_p = num2str(bw, 6, 1, i2p); |
Jens Axboe | 8879fd1 | 2009-04-20 10:06:02 +0200 | [diff] [blame] | 381 | |
Bruce Cran | 0aacc50 | 2011-07-09 08:19:53 +0200 | [diff] [blame] | 382 | iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt; |
Jens Axboe | b360506 | 2007-03-12 14:19:47 +0100 | [diff] [blame] | 383 | iops_p = num2str(iops, 6, 1, 0); |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 384 | |
Signed-off-by Steven Pratt | cda99fa | 2010-12-14 08:31:36 +0100 | [diff] [blame] | 385 | log_info(" %s: io=%sB, bw=%sB/s, iops=%s, runt=%6llumsec\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 386 | ddir_str[ddir], io_p, bw_p, iops_p, |
| 387 | ts->runtime[ddir]); |
Jens Axboe | dbe1125 | 2007-02-11 00:19:51 +0100 | [diff] [blame] | 388 | |
| 389 | free(io_p); |
| 390 | free(bw_p); |
Jens Axboe | b360506 | 2007-03-12 14:19:47 +0100 | [diff] [blame] | 391 | free(iops_p); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 392 | |
Jens Axboe | b29ad56 | 2012-03-05 13:08:51 +0100 | [diff] [blame] | 393 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
| 394 | display_lat("slat", min, max, mean, dev); |
| 395 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
| 396 | display_lat("clat", min, max, mean, dev); |
| 397 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) |
| 398 | display_lat(" lat", min, max, mean, dev); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 399 | |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 400 | if (ts->clat_percentiles) { |
| 401 | show_clat_percentiles(ts->io_u_plat[ddir], |
| 402 | ts->clat_stat[ddir].samples, |
| 403 | ts->percentile_list); |
| 404 | } |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 405 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
Jens Axboe | 19d3e96 | 2012-02-07 12:27:28 +0100 | [diff] [blame] | 406 | double p_of_agg = 100.0; |
Jens Axboe | b7017e3 | 2011-10-14 09:30:01 +0200 | [diff] [blame] | 407 | const char *bw_str = "KB"; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 408 | |
Jens Axboe | 2f2c692 | 2012-02-07 16:42:43 +0100 | [diff] [blame] | 409 | if (rs->agg[ddir]) { |
Jens Axboe | 19d3e96 | 2012-02-07 12:27:28 +0100 | [diff] [blame] | 410 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
| 411 | if (p_of_agg > 100.0) |
| 412 | p_of_agg = 100.0; |
| 413 | } |
Jens Axboe | b7017e3 | 2011-10-14 09:30:01 +0200 | [diff] [blame] | 414 | |
| 415 | if (mean > 999999.9) { |
| 416 | min /= 1000.0; |
| 417 | max /= 1000.0; |
| 418 | mean /= 1000.0; |
| 419 | dev /= 1000.0; |
| 420 | bw_str = "MB"; |
| 421 | } |
| 422 | |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 423 | log_info(" bw (%s/s) : min=%5lu, max=%5lu, per=%3.2f%%," |
Jens Axboe | b7017e3 | 2011-10-14 09:30:01 +0200 | [diff] [blame] | 424 | " avg=%5.02f, stdev=%5.02f\n", bw_str, min, max, |
| 425 | p_of_agg, mean, dev); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 426 | } |
| 427 | } |
| 428 | |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 429 | static int show_lat(double *io_u_lat, int nr, const char **ranges, |
| 430 | const char *msg) |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 431 | { |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 432 | int new_line = 1, i, line = 0, shown = 0; |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 433 | |
| 434 | for (i = 0; i < nr; i++) { |
| 435 | if (io_u_lat[i] <= 0.0) |
| 436 | continue; |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 437 | shown = 1; |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 438 | if (new_line) { |
Jens Axboe | 4539ed7 | 2007-07-23 14:21:17 +0200 | [diff] [blame] | 439 | if (line) |
| 440 | log_info("\n"); |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 441 | log_info(" lat (%s) : ", msg); |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 442 | new_line = 0; |
| 443 | line = 0; |
| 444 | } |
| 445 | if (line) |
| 446 | log_info(", "); |
| 447 | log_info("%s%3.2f%%", ranges[i], io_u_lat[i]); |
| 448 | line++; |
| 449 | if (line == 5) |
| 450 | new_line = 1; |
| 451 | } |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 452 | |
| 453 | if (shown) |
| 454 | log_info("\n"); |
| 455 | |
| 456 | return shown; |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 457 | } |
| 458 | |
| 459 | static void show_lat_u(double *io_u_lat_u) |
| 460 | { |
| 461 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", |
| 462 | "250=", "500=", "750=", "1000=", }; |
| 463 | |
| 464 | show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec"); |
| 465 | } |
| 466 | |
| 467 | static void show_lat_m(double *io_u_lat_m) |
| 468 | { |
| 469 | const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", |
| 470 | "250=", "500=", "750=", "1000=", "2000=", |
| 471 | ">=2000=", }; |
| 472 | |
| 473 | show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec"); |
| 474 | } |
| 475 | |
Jens Axboe | c551f65 | 2012-03-05 20:49:10 +0100 | [diff] [blame] | 476 | static void show_latencies(struct thread_stat *ts) |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 477 | { |
Jens Axboe | c551f65 | 2012-03-05 20:49:10 +0100 | [diff] [blame] | 478 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
| 479 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; |
| 480 | |
Jens Axboe | 5a18988 | 2012-03-05 14:08:34 +0100 | [diff] [blame] | 481 | stat_calc_lat_u(ts, io_u_lat_u); |
| 482 | stat_calc_lat_m(ts, io_u_lat_m); |
| 483 | |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 484 | show_lat_u(io_u_lat_u); |
| 485 | show_lat_m(io_u_lat_m); |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 486 | } |
| 487 | |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 488 | void show_thread_status(struct thread_stat *ts, struct group_run_stats *rs) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 489 | { |
| 490 | double usr_cpu, sys_cpu; |
Jens Axboe | 6900899 | 2006-11-24 13:12:56 +0100 | [diff] [blame] | 491 | unsigned long runtime; |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 492 | double io_u_dist[FIO_IO_U_MAP_NR]; |
Jens Axboe | 57a6432 | 2012-06-14 15:11:15 +0200 | [diff] [blame] | 493 | time_t time_p; |
| 494 | char time_buf[64]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 495 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 496 | if (!(ts->io_bytes[DDIR_READ] + ts->io_bytes[DDIR_WRITE] + |
| 497 | ts->io_bytes[DDIR_TRIM]) && !(ts->total_io_u[DDIR_READ] + |
| 498 | ts->total_io_u[DDIR_WRITE] + ts->total_io_u[DDIR_TRIM])) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 499 | return; |
| 500 | |
Jens Axboe | 57a6432 | 2012-06-14 15:11:15 +0200 | [diff] [blame] | 501 | time(&time_p); |
Saurabh De | 45054cb | 2012-10-09 14:46:24 -0600 | [diff] [blame] | 502 | os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf)); |
Jens Axboe | 57a6432 | 2012-06-14 15:11:15 +0200 | [diff] [blame] | 503 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 504 | if (!ts->error) { |
Jens Axboe | 57a6432 | 2012-06-14 15:11:15 +0200 | [diff] [blame] | 505 | log_info("%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 506 | ts->name, ts->groupid, ts->members, |
Jens Axboe | 57a6432 | 2012-06-14 15:11:15 +0200 | [diff] [blame] | 507 | ts->error, (int) ts->pid, time_buf); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 508 | } else { |
Jens Axboe | 57a6432 | 2012-06-14 15:11:15 +0200 | [diff] [blame] | 509 | log_info("%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 510 | ts->name, ts->groupid, ts->members, |
Jens Axboe | 57a6432 | 2012-06-14 15:11:15 +0200 | [diff] [blame] | 511 | ts->error, ts->verror, (int) ts->pid, |
| 512 | time_buf); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 513 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 514 | |
Jens Axboe | 259e47d | 2011-10-13 21:05:59 +0200 | [diff] [blame] | 515 | if (strlen(ts->description)) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 516 | log_info(" Description : [%s]\n", ts->description); |
Jens Axboe | 7bdce1b | 2007-03-06 20:01:13 +0100 | [diff] [blame] | 517 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 518 | if (ts->io_bytes[DDIR_READ]) |
| 519 | show_ddir_status(rs, ts, DDIR_READ); |
| 520 | if (ts->io_bytes[DDIR_WRITE]) |
| 521 | show_ddir_status(rs, ts, DDIR_WRITE); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 522 | if (ts->io_bytes[DDIR_TRIM]) |
| 523 | show_ddir_status(rs, ts, DDIR_TRIM); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 524 | |
Jens Axboe | c551f65 | 2012-03-05 20:49:10 +0100 | [diff] [blame] | 525 | show_latencies(ts); |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 526 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 527 | runtime = ts->total_run_time; |
Jens Axboe | 6900899 | 2006-11-24 13:12:56 +0100 | [diff] [blame] | 528 | if (runtime) { |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 529 | double runt = (double) runtime; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 530 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 531 | usr_cpu = (double) ts->usr_time * 100 / runt; |
| 532 | sys_cpu = (double) ts->sys_time * 100 / runt; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 533 | } else { |
| 534 | usr_cpu = 0; |
| 535 | sys_cpu = 0; |
| 536 | } |
| 537 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 538 | log_info(" cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%lu, majf=%lu," |
| 539 | " minf=%lu\n", usr_cpu, sys_cpu, ts->ctx, ts->majf, ts->minf); |
Jens Axboe | 71619dc | 2007-01-13 23:56:33 +0100 | [diff] [blame] | 540 | |
Jens Axboe | d79db12 | 2012-09-24 08:51:24 +0200 | [diff] [blame] | 541 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 542 | log_info(" IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%," |
| 543 | " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
| 544 | io_u_dist[1], io_u_dist[2], |
| 545 | io_u_dist[3], io_u_dist[4], |
| 546 | io_u_dist[5], io_u_dist[6]); |
Jens Axboe | 838bc70 | 2008-05-22 13:08:23 +0200 | [diff] [blame] | 547 | |
| 548 | stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist); |
| 549 | log_info(" submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," |
| 550 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
| 551 | io_u_dist[1], io_u_dist[2], |
| 552 | io_u_dist[3], io_u_dist[4], |
| 553 | io_u_dist[5], io_u_dist[6]); |
| 554 | stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist); |
| 555 | log_info(" complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," |
| 556 | " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], |
| 557 | io_u_dist[1], io_u_dist[2], |
| 558 | io_u_dist[3], io_u_dist[4], |
| 559 | io_u_dist[5], io_u_dist[6]); |
Jens Axboe | 7e1773b | 2011-10-14 12:47:56 +0200 | [diff] [blame] | 560 | log_info(" issued : total=r=%lu/w=%lu/d=%lu," |
| 561 | " short=r=%lu/w=%lu/d=%lu\n", |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 562 | ts->total_io_u[0], ts->total_io_u[1], |
Jens Axboe | 0d29de8 | 2010-09-01 13:54:15 +0200 | [diff] [blame] | 563 | ts->total_io_u[2], |
| 564 | ts->short_io_u[0], ts->short_io_u[1], |
| 565 | ts->short_io_u[2]); |
Radha Ramachandran | f2bba18 | 2009-06-15 08:40:16 +0200 | [diff] [blame] | 566 | if (ts->continue_on_error) { |
Jens Axboe | 1ec99ee | 2009-06-15 12:37:30 +0200 | [diff] [blame] | 567 | log_info(" errors : total=%lu, first_error=%d/<%s>\n", |
| 568 | ts->total_err_count, |
| 569 | ts->first_error, |
| 570 | strerror(ts->first_error)); |
Radha Ramachandran | f2bba18 | 2009-06-15 08:40:16 +0200 | [diff] [blame] | 571 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 572 | } |
| 573 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 574 | static void show_ddir_status_terse(struct thread_stat *ts, |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 575 | struct group_run_stats *rs, int ddir) |
| 576 | { |
| 577 | unsigned long min, max; |
Jens Axboe | 312b4af | 2011-10-13 13:11:42 +0200 | [diff] [blame] | 578 | unsigned long long bw, iops; |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 579 | unsigned int *ovals = NULL; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 580 | double mean, dev; |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 581 | unsigned int len, minv, maxv; |
| 582 | int i; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 583 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 584 | assert(ddir_rw(ddir)); |
| 585 | |
Jens Axboe | 312b4af | 2011-10-13 13:11:42 +0200 | [diff] [blame] | 586 | iops = bw = 0; |
| 587 | if (ts->runtime[ddir]) { |
| 588 | uint64_t runt = ts->runtime[ddir]; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 589 | |
Jens Axboe | 033bbb5 | 2012-05-07 09:46:40 +0200 | [diff] [blame] | 590 | bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; |
Jens Axboe | 312b4af | 2011-10-13 13:11:42 +0200 | [diff] [blame] | 591 | iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt; |
| 592 | } |
| 593 | |
| 594 | log_info(";%llu;%llu;%llu;%llu", ts->io_bytes[ddir] >> 10, bw, iops, |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 595 | ts->runtime[ddir]); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 596 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 597 | if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 598 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 599 | else |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 600 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 601 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 602 | if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 603 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 604 | else |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 605 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 606 | |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 607 | if (ts->clat_percentiles) { |
| 608 | len = calc_clat_percentiles(ts->io_u_plat[ddir], |
| 609 | ts->clat_stat[ddir].samples, |
| 610 | ts->percentile_list, &ovals, &maxv, |
| 611 | &minv); |
| 612 | } else |
| 613 | len = 0; |
| 614 | |
| 615 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { |
| 616 | if (i >= len) { |
| 617 | log_info(";0%%=0"); |
| 618 | continue; |
| 619 | } |
| 620 | log_info(";%2.2f%%=%u", ts->percentile_list[i].u.f, ovals[i]); |
| 621 | } |
Keplar kramer | 2341a37 | 2011-10-19 21:31:27 +0200 | [diff] [blame] | 622 | |
| 623 | if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) |
| 624 | log_info(";%lu;%lu;%f;%f", min, max, mean, dev); |
| 625 | else |
| 626 | log_info(";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); |
| 627 | |
Jens Axboe | 1db92cb | 2011-10-13 13:43:36 +0200 | [diff] [blame] | 628 | if (ovals) |
| 629 | free(ovals); |
| 630 | |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 631 | if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
Jens Axboe | 19d3e96 | 2012-02-07 12:27:28 +0100 | [diff] [blame] | 632 | double p_of_agg = 100.0; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 633 | |
Jens Axboe | 19d3e96 | 2012-02-07 12:27:28 +0100 | [diff] [blame] | 634 | if (rs->agg[ddir]) { |
| 635 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
| 636 | if (p_of_agg > 100.0) |
| 637 | p_of_agg = 100.0; |
| 638 | } |
| 639 | |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 640 | log_info(";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 641 | } else |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 642 | log_info(";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 643 | } |
| 644 | |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 645 | static void add_ddir_status_json(struct thread_stat *ts, |
| 646 | struct group_run_stats *rs, int ddir, struct json_object *parent) |
| 647 | { |
| 648 | unsigned long min, max; |
| 649 | unsigned long long bw, iops; |
| 650 | unsigned int *ovals = NULL; |
| 651 | double mean, dev; |
| 652 | unsigned int len, minv, maxv; |
| 653 | int i; |
| 654 | const char *ddirname[] = {"read", "write", "trim"}; |
| 655 | struct json_object *dir_object, *tmp_object, *percentile_object; |
| 656 | char buf[120]; |
| 657 | double p_of_agg = 100.0; |
| 658 | |
| 659 | assert(ddir_rw(ddir)); |
| 660 | |
| 661 | dir_object = json_create_object(); |
| 662 | json_object_add_value_object(parent, ddirname[ddir], dir_object); |
| 663 | |
| 664 | iops = bw = 0; |
| 665 | if (ts->runtime[ddir]) { |
| 666 | uint64_t runt = ts->runtime[ddir]; |
| 667 | |
| 668 | bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; |
| 669 | iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt; |
| 670 | } |
| 671 | |
| 672 | json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10); |
| 673 | json_object_add_value_int(dir_object, "bw", bw); |
| 674 | json_object_add_value_int(dir_object, "iops", iops); |
| 675 | json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]); |
| 676 | |
| 677 | if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) { |
| 678 | min = max = 0; |
| 679 | mean = dev = 0.0; |
| 680 | } |
| 681 | tmp_object = json_create_object(); |
| 682 | json_object_add_value_object(dir_object, "slat", tmp_object); |
| 683 | json_object_add_value_int(tmp_object, "min", min); |
| 684 | json_object_add_value_int(tmp_object, "max", max); |
| 685 | json_object_add_value_float(tmp_object, "mean", mean); |
| 686 | json_object_add_value_float(tmp_object, "stddev", dev); |
| 687 | |
| 688 | if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) { |
| 689 | min = max = 0; |
| 690 | mean = dev = 0.0; |
| 691 | } |
| 692 | tmp_object = json_create_object(); |
| 693 | json_object_add_value_object(dir_object, "clat", tmp_object); |
| 694 | json_object_add_value_int(tmp_object, "min", min); |
| 695 | json_object_add_value_int(tmp_object, "max", max); |
| 696 | json_object_add_value_float(tmp_object, "mean", mean); |
| 697 | json_object_add_value_float(tmp_object, "stddev", dev); |
| 698 | |
| 699 | if (ts->clat_percentiles) { |
| 700 | len = calc_clat_percentiles(ts->io_u_plat[ddir], |
| 701 | ts->clat_stat[ddir].samples, |
| 702 | ts->percentile_list, &ovals, &maxv, |
| 703 | &minv); |
| 704 | } else |
| 705 | len = 0; |
| 706 | |
| 707 | percentile_object = json_create_object(); |
| 708 | json_object_add_value_object(tmp_object, "percentile", percentile_object); |
| 709 | for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { |
| 710 | if (i >= len) { |
| 711 | json_object_add_value_int(percentile_object, "0.00", 0); |
| 712 | continue; |
| 713 | } |
| 714 | snprintf(buf, sizeof(buf) - 1, "%2.2f", ts->percentile_list[i].u.f); |
| 715 | json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]); |
| 716 | } |
| 717 | |
| 718 | if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) { |
| 719 | min = max = 0; |
| 720 | mean = dev = 0.0; |
| 721 | } |
| 722 | tmp_object = json_create_object(); |
| 723 | json_object_add_value_object(dir_object, "lat", tmp_object); |
| 724 | json_object_add_value_int(tmp_object, "min", min); |
| 725 | json_object_add_value_int(tmp_object, "max", max); |
| 726 | json_object_add_value_float(tmp_object, "mean", mean); |
| 727 | json_object_add_value_float(tmp_object, "stddev", dev); |
| 728 | if (ovals) |
| 729 | free(ovals); |
| 730 | |
| 731 | if (!calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { |
| 732 | if (rs->agg[ddir]) { |
| 733 | p_of_agg = mean * 100 / (double) rs->agg[ddir]; |
| 734 | if (p_of_agg > 100.0) |
| 735 | p_of_agg = 100.0; |
| 736 | } |
| 737 | } else { |
| 738 | min = max = 0; |
| 739 | p_of_agg = mean = dev = 0.0; |
| 740 | } |
| 741 | json_object_add_value_int(dir_object, "bw_min", min); |
| 742 | json_object_add_value_int(dir_object, "bw_max", max); |
| 743 | json_object_add_value_float(dir_object, "bw_agg", mean); |
| 744 | json_object_add_value_float(dir_object, "bw_mean", mean); |
| 745 | json_object_add_value_float(dir_object, "bw_dev", dev); |
| 746 | } |
| 747 | |
Jens Axboe | 4d65865 | 2011-10-17 15:05:47 +0200 | [diff] [blame] | 748 | static void show_thread_status_terse_v2(struct thread_stat *ts, |
Jens Axboe | 3c3ed07 | 2012-03-27 09:12:39 +0200 | [diff] [blame] | 749 | struct group_run_stats *rs) |
Jens Axboe | 4d65865 | 2011-10-17 15:05:47 +0200 | [diff] [blame] | 750 | { |
| 751 | double io_u_dist[FIO_IO_U_MAP_NR]; |
| 752 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
| 753 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; |
| 754 | double usr_cpu, sys_cpu; |
| 755 | int i; |
| 756 | |
| 757 | /* General Info */ |
| 758 | log_info("2;%s;%d;%d", ts->name, ts->groupid, ts->error); |
| 759 | /* Log Read Status */ |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 760 | show_ddir_status_terse(ts, rs, DDIR_READ); |
Jens Axboe | 4d65865 | 2011-10-17 15:05:47 +0200 | [diff] [blame] | 761 | /* Log Write Status */ |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 762 | show_ddir_status_terse(ts, rs, DDIR_WRITE); |
| 763 | /* Log Trim Status */ |
| 764 | show_ddir_status_terse(ts, rs, DDIR_TRIM); |
Jens Axboe | 4d65865 | 2011-10-17 15:05:47 +0200 | [diff] [blame] | 765 | |
| 766 | /* CPU Usage */ |
| 767 | if (ts->total_run_time) { |
| 768 | double runt = (double) ts->total_run_time; |
| 769 | |
| 770 | usr_cpu = (double) ts->usr_time * 100 / runt; |
| 771 | sys_cpu = (double) ts->sys_time * 100 / runt; |
| 772 | } else { |
| 773 | usr_cpu = 0; |
| 774 | sys_cpu = 0; |
| 775 | } |
| 776 | |
| 777 | log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf, |
| 778 | ts->minf); |
| 779 | |
| 780 | /* Calc % distribution of IO depths, usecond, msecond latency */ |
Jens Axboe | d79db12 | 2012-09-24 08:51:24 +0200 | [diff] [blame] | 781 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
Jens Axboe | 4d65865 | 2011-10-17 15:05:47 +0200 | [diff] [blame] | 782 | stat_calc_lat_u(ts, io_u_lat_u); |
| 783 | stat_calc_lat_m(ts, io_u_lat_m); |
| 784 | |
| 785 | /* Only show fixed 7 I/O depth levels*/ |
| 786 | log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", |
| 787 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], |
| 788 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); |
| 789 | |
| 790 | /* Microsecond latency */ |
| 791 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) |
| 792 | log_info(";%3.2f%%", io_u_lat_u[i]); |
| 793 | /* Millisecond latency */ |
| 794 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) |
| 795 | log_info(";%3.2f%%", io_u_lat_m[i]); |
| 796 | /* Additional output if continue_on_error set - default off*/ |
| 797 | if (ts->continue_on_error) |
| 798 | log_info(";%lu;%d", ts->total_err_count, ts->first_error); |
| 799 | log_info("\n"); |
| 800 | |
| 801 | /* Additional output if description is set */ |
| 802 | if (ts->description) |
| 803 | log_info(";%s", ts->description); |
| 804 | |
| 805 | log_info("\n"); |
| 806 | } |
| 807 | |
Jens Axboe | 3449ab8 | 2012-09-14 23:35:08 +0200 | [diff] [blame] | 808 | static void show_thread_status_terse_v3_v4(struct thread_stat *ts, |
| 809 | struct group_run_stats *rs, int ver) |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 810 | { |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 811 | double io_u_dist[FIO_IO_U_MAP_NR]; |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 812 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
| 813 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 814 | double usr_cpu, sys_cpu; |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 815 | int i; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 816 | |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 817 | /* General Info */ |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 818 | log_info("%d;%s;%s;%d;%d", ver, fio_version_string, |
Jens Axboe | 5e726d0 | 2011-10-14 08:08:10 +0200 | [diff] [blame] | 819 | ts->name, ts->groupid, ts->error); |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 820 | /* Log Read Status */ |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 821 | show_ddir_status_terse(ts, rs, DDIR_READ); |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 822 | /* Log Write Status */ |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 823 | show_ddir_status_terse(ts, rs, DDIR_WRITE); |
| 824 | /* Log Trim Status */ |
Jens Axboe | 3449ab8 | 2012-09-14 23:35:08 +0200 | [diff] [blame] | 825 | if (ver == 4) |
| 826 | show_ddir_status_terse(ts, rs, DDIR_TRIM); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 827 | |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 828 | /* CPU Usage */ |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 829 | if (ts->total_run_time) { |
| 830 | double runt = (double) ts->total_run_time; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 831 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 832 | usr_cpu = (double) ts->usr_time * 100 / runt; |
| 833 | sys_cpu = (double) ts->sys_time * 100 / runt; |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 834 | } else { |
| 835 | usr_cpu = 0; |
| 836 | sys_cpu = 0; |
| 837 | } |
| 838 | |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 839 | log_info(";%f%%;%f%%;%lu;%lu;%lu", usr_cpu, sys_cpu, ts->ctx, ts->majf, |
| 840 | ts->minf); |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 841 | |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 842 | /* Calc % distribution of IO depths, usecond, msecond latency */ |
Jens Axboe | d79db12 | 2012-09-24 08:51:24 +0200 | [diff] [blame] | 843 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 844 | stat_calc_lat_u(ts, io_u_lat_u); |
| 845 | stat_calc_lat_m(ts, io_u_lat_m); |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 846 | |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 847 | /* Only show fixed 7 I/O depth levels*/ |
Jens Axboe | 5ec10ea | 2008-03-06 15:42:00 +0100 | [diff] [blame] | 848 | log_info(";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", |
| 849 | io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], |
| 850 | io_u_dist[4], io_u_dist[5], io_u_dist[6]); |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 851 | |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 852 | /* Microsecond latency */ |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 853 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) |
| 854 | log_info(";%3.2f%%", io_u_lat_u[i]); |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 855 | /* Millisecond latency */ |
Jens Axboe | 04a0fea | 2007-06-19 12:48:41 +0200 | [diff] [blame] | 856 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) |
| 857 | log_info(";%3.2f%%", io_u_lat_m[i]); |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 858 | |
| 859 | /* disk util stats, if any */ |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 860 | show_disk_util(1, NULL); |
Jens Axboe | f2f788d | 2011-10-13 14:03:52 +0200 | [diff] [blame] | 861 | |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 862 | /* Additional output if continue_on_error set - default off*/ |
Radha Ramachandran | f2bba18 | 2009-06-15 08:40:16 +0200 | [diff] [blame] | 863 | if (ts->continue_on_error) |
| 864 | log_info(";%lu;%d", ts->total_err_count, ts->first_error); |
Jens Axboe | 2270890 | 2007-03-06 17:05:32 +0100 | [diff] [blame] | 865 | |
David Nellans | 562c2d2 | 2010-09-23 08:38:17 +0200 | [diff] [blame] | 866 | /* Additional output if description is set */ |
Jens Axboe | 4b0f225 | 2011-10-13 15:03:25 +0200 | [diff] [blame] | 867 | if (strlen(ts->description)) |
Jens Axboe | 6d86144 | 2007-03-15 09:22:23 +0100 | [diff] [blame] | 868 | log_info(";%s", ts->description); |
Jens Axboe | 946e427 | 2012-03-23 19:22:21 +0100 | [diff] [blame] | 869 | |
| 870 | log_info("\n"); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 871 | } |
| 872 | |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 873 | static struct json_object *show_thread_status_json(struct thread_stat *ts, |
| 874 | struct group_run_stats *rs) |
| 875 | { |
| 876 | struct json_object *root, *tmp; |
| 877 | double io_u_dist[FIO_IO_U_MAP_NR]; |
| 878 | double io_u_lat_u[FIO_IO_U_LAT_U_NR]; |
| 879 | double io_u_lat_m[FIO_IO_U_LAT_M_NR]; |
| 880 | double usr_cpu, sys_cpu; |
| 881 | int i; |
| 882 | |
| 883 | root = json_create_object(); |
| 884 | json_object_add_value_string(root, "jobname", ts->name); |
| 885 | json_object_add_value_int(root, "groupid", ts->groupid); |
| 886 | json_object_add_value_int(root, "error", ts->error); |
| 887 | |
| 888 | add_ddir_status_json(ts, rs, DDIR_READ, root); |
| 889 | add_ddir_status_json(ts, rs, DDIR_WRITE, root); |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 890 | add_ddir_status_json(ts, rs, DDIR_TRIM, root); |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 891 | |
| 892 | /* CPU Usage */ |
| 893 | if (ts->total_run_time) { |
| 894 | double runt = (double) ts->total_run_time; |
| 895 | |
| 896 | usr_cpu = (double) ts->usr_time * 100 / runt; |
| 897 | sys_cpu = (double) ts->sys_time * 100 / runt; |
| 898 | } else { |
| 899 | usr_cpu = 0; |
| 900 | sys_cpu = 0; |
| 901 | } |
| 902 | json_object_add_value_float(root, "usr_cpu", usr_cpu); |
| 903 | json_object_add_value_float(root, "sys_cpu", sys_cpu); |
| 904 | json_object_add_value_int(root, "ctx", ts->ctx); |
| 905 | json_object_add_value_int(root, "majf", ts->majf); |
| 906 | json_object_add_value_int(root, "minf", ts->minf); |
| 907 | |
| 908 | |
| 909 | /* Calc % distribution of IO depths, usecond, msecond latency */ |
Jens Axboe | d79db12 | 2012-09-24 08:51:24 +0200 | [diff] [blame] | 910 | stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 911 | stat_calc_lat_u(ts, io_u_lat_u); |
| 912 | stat_calc_lat_m(ts, io_u_lat_m); |
| 913 | |
| 914 | tmp = json_create_object(); |
| 915 | json_object_add_value_object(root, "iodepth_level", tmp); |
| 916 | /* Only show fixed 7 I/O depth levels*/ |
| 917 | for (i = 0; i < 7; i++) { |
| 918 | char name[20]; |
| 919 | if (i < 6) |
| 920 | snprintf(name, 19, "%d", 1 << i); |
| 921 | else |
| 922 | snprintf(name, 19, ">=%d", 1 << i); |
| 923 | json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]); |
| 924 | } |
| 925 | |
| 926 | tmp = json_create_object(); |
| 927 | json_object_add_value_object(root, "latency_us", tmp); |
| 928 | /* Microsecond latency */ |
| 929 | for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) { |
| 930 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", |
| 931 | "250", "500", "750", "1000", }; |
| 932 | json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]); |
| 933 | } |
| 934 | /* Millisecond latency */ |
| 935 | tmp = json_create_object(); |
| 936 | json_object_add_value_object(root, "latency_ms", tmp); |
| 937 | for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) { |
| 938 | const char *ranges[] = { "2", "4", "10", "20", "50", "100", |
| 939 | "250", "500", "750", "1000", "2000", |
| 940 | ">=2000", }; |
| 941 | json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]); |
| 942 | } |
| 943 | |
| 944 | /* Additional output if continue_on_error set - default off*/ |
| 945 | if (ts->continue_on_error) { |
| 946 | json_object_add_value_int(root, "total_err", ts->total_err_count); |
| 947 | json_object_add_value_int(root, "total_err", ts->first_error); |
| 948 | } |
| 949 | |
| 950 | /* Additional output if description is set */ |
| 951 | if (strlen(ts->description)) |
| 952 | json_object_add_value_string(root, "desc", ts->description); |
| 953 | |
| 954 | return root; |
| 955 | } |
| 956 | |
Jens Axboe | 4d65865 | 2011-10-17 15:05:47 +0200 | [diff] [blame] | 957 | static void show_thread_status_terse(struct thread_stat *ts, |
| 958 | struct group_run_stats *rs) |
| 959 | { |
| 960 | if (terse_version == 2) |
| 961 | show_thread_status_terse_v2(ts, rs); |
Jens Axboe | 3449ab8 | 2012-09-14 23:35:08 +0200 | [diff] [blame] | 962 | else if (terse_version == 3 || terse_version == 4) |
| 963 | show_thread_status_terse_v3_v4(ts, rs, terse_version); |
Jens Axboe | 4d65865 | 2011-10-17 15:05:47 +0200 | [diff] [blame] | 964 | else |
| 965 | log_err("fio: bad terse version!? %d\n", terse_version); |
| 966 | } |
| 967 | |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 968 | static void sum_stat(struct io_stat *dst, struct io_stat *src, int nr) |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 969 | { |
| 970 | double mean, S; |
| 971 | |
Zheng Liu | e09231c | 2011-09-16 08:20:12 +0200 | [diff] [blame] | 972 | if (src->samples == 0) |
| 973 | return; |
| 974 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 975 | dst->min_val = min(dst->min_val, src->min_val); |
| 976 | dst->max_val = max(dst->max_val, src->max_val); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 977 | |
| 978 | /* |
Yu-ju Hong | cdcac5c | 2011-07-30 09:18:13 +0200 | [diff] [blame] | 979 | * Compute new mean and S after the merge |
| 980 | * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance |
| 981 | * #Parallel_algorithm> |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 982 | */ |
| 983 | if (nr == 1) { |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 984 | mean = src->mean.u.f; |
| 985 | S = src->S.u.f; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 986 | } else { |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 987 | double delta = src->mean.u.f - dst->mean.u.f; |
Yu-ju Hong | cdcac5c | 2011-07-30 09:18:13 +0200 | [diff] [blame] | 988 | |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 989 | mean = ((src->mean.u.f * src->samples) + |
| 990 | (dst->mean.u.f * dst->samples)) / |
Yu-ju Hong | cdcac5c | 2011-07-30 09:18:13 +0200 | [diff] [blame] | 991 | (dst->samples + src->samples); |
| 992 | |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 993 | S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) * |
Yu-ju Hong | cdcac5c | 2011-07-30 09:18:13 +0200 | [diff] [blame] | 994 | (dst->samples * src->samples) / |
| 995 | (dst->samples + src->samples); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 996 | } |
| 997 | |
Yu-ju Hong | cdcac5c | 2011-07-30 09:18:13 +0200 | [diff] [blame] | 998 | dst->samples += src->samples; |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 999 | dst->mean.u.f = mean; |
| 1000 | dst->S.u.f = S; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1001 | } |
| 1002 | |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1003 | void sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src) |
| 1004 | { |
| 1005 | int i; |
| 1006 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1007 | for (i = 0; i < DDIR_RWDIR_CNT; i++) { |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1008 | if (dst->max_run[i] < src->max_run[i]) |
| 1009 | dst->max_run[i] = src->max_run[i]; |
| 1010 | if (dst->min_run[i] && dst->min_run[i] > src->min_run[i]) |
| 1011 | dst->min_run[i] = src->min_run[i]; |
| 1012 | if (dst->max_bw[i] < src->max_bw[i]) |
| 1013 | dst->max_bw[i] = src->max_bw[i]; |
| 1014 | if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i]) |
| 1015 | dst->min_bw[i] = src->min_bw[i]; |
| 1016 | |
| 1017 | dst->io_kb[i] += src->io_kb[i]; |
| 1018 | dst->agg[i] += src->agg[i]; |
| 1019 | } |
| 1020 | |
| 1021 | } |
| 1022 | |
Jens Axboe | 5b9babb | 2011-10-10 12:14:30 +0200 | [diff] [blame] | 1023 | void sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, int nr) |
| 1024 | { |
| 1025 | int l, k; |
| 1026 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1027 | for (l = 0; l < DDIR_RWDIR_CNT; l++) { |
Jens Axboe | 5b9babb | 2011-10-10 12:14:30 +0200 | [diff] [blame] | 1028 | sum_stat(&dst->clat_stat[l], &src->clat_stat[l], nr); |
| 1029 | sum_stat(&dst->slat_stat[l], &src->slat_stat[l], nr); |
| 1030 | sum_stat(&dst->lat_stat[l], &src->lat_stat[l], nr); |
| 1031 | sum_stat(&dst->bw_stat[l], &src->bw_stat[l], nr); |
| 1032 | |
| 1033 | dst->io_bytes[l] += src->io_bytes[l]; |
| 1034 | |
| 1035 | if (dst->runtime[l] < src->runtime[l]) |
| 1036 | dst->runtime[l] = src->runtime[l]; |
| 1037 | } |
| 1038 | |
| 1039 | dst->usr_time += src->usr_time; |
| 1040 | dst->sys_time += src->sys_time; |
| 1041 | dst->ctx += src->ctx; |
| 1042 | dst->majf += src->majf; |
| 1043 | dst->minf += src->minf; |
| 1044 | |
| 1045 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) |
| 1046 | dst->io_u_map[k] += src->io_u_map[k]; |
| 1047 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) |
| 1048 | dst->io_u_submit[k] += src->io_u_submit[k]; |
| 1049 | for (k = 0; k < FIO_IO_U_MAP_NR; k++) |
| 1050 | dst->io_u_complete[k] += src->io_u_complete[k]; |
| 1051 | for (k = 0; k < FIO_IO_U_LAT_U_NR; k++) |
| 1052 | dst->io_u_lat_u[k] += src->io_u_lat_u[k]; |
| 1053 | for (k = 0; k < FIO_IO_U_LAT_M_NR; k++) |
| 1054 | dst->io_u_lat_m[k] += src->io_u_lat_m[k]; |
| 1055 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1056 | for (k = 0; k < DDIR_RWDIR_CNT; k++) { |
Jens Axboe | 5b9babb | 2011-10-10 12:14:30 +0200 | [diff] [blame] | 1057 | dst->total_io_u[k] += src->total_io_u[k]; |
| 1058 | dst->short_io_u[k] += src->short_io_u[k]; |
| 1059 | } |
| 1060 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1061 | for (k = 0; k < DDIR_RWDIR_CNT; k++) { |
Jens Axboe | 5b9babb | 2011-10-10 12:14:30 +0200 | [diff] [blame] | 1062 | int m; |
| 1063 | for (m = 0; m < FIO_IO_U_PLAT_NR; m++) |
| 1064 | dst->io_u_plat[k][m] += src->io_u_plat[k][m]; |
| 1065 | } |
| 1066 | |
| 1067 | dst->total_run_time += src->total_run_time; |
| 1068 | dst->total_submit += src->total_submit; |
| 1069 | dst->total_complete += src->total_complete; |
| 1070 | } |
| 1071 | |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1072 | void init_group_run_stat(struct group_run_stats *gs) |
| 1073 | { |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1074 | int i; |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1075 | memset(gs, 0, sizeof(*gs)); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1076 | |
| 1077 | for (i = 0; i < DDIR_RWDIR_CNT; i++) |
| 1078 | gs->min_bw[i] = gs->min_run[i] = ~0UL; |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1079 | } |
| 1080 | |
| 1081 | void init_thread_stat(struct thread_stat *ts) |
| 1082 | { |
| 1083 | int j; |
| 1084 | |
| 1085 | memset(ts, 0, sizeof(*ts)); |
| 1086 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1087 | for (j = 0; j < DDIR_RWDIR_CNT; j++) { |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1088 | ts->lat_stat[j].min_val = -1UL; |
| 1089 | ts->clat_stat[j].min_val = -1UL; |
| 1090 | ts->slat_stat[j].min_val = -1UL; |
| 1091 | ts->bw_stat[j].min_val = -1UL; |
| 1092 | } |
| 1093 | ts->groupid = -1; |
| 1094 | } |
| 1095 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1096 | void show_run_stats(void) |
| 1097 | { |
| 1098 | struct group_run_stats *runstats, *rs; |
| 1099 | struct thread_data *td; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1100 | struct thread_stat *threadstats, *ts; |
Jens Axboe | 5b9babb | 2011-10-10 12:14:30 +0200 | [diff] [blame] | 1101 | int i, j, nr_ts, last_ts, idx; |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 1102 | int kb_base_warned = 0; |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 1103 | struct json_object *root = NULL; |
| 1104 | struct json_array *array = NULL; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1105 | |
| 1106 | runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); |
| 1107 | |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1108 | for (i = 0; i < groupid + 1; i++) |
| 1109 | init_group_run_stat(&runstats[i]); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1110 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1111 | /* |
| 1112 | * find out how many threads stats we need. if group reporting isn't |
| 1113 | * enabled, it's one-per-td. |
| 1114 | */ |
| 1115 | nr_ts = 0; |
| 1116 | last_ts = -1; |
Jens Axboe | 34572e2 | 2006-10-20 09:33:18 +0200 | [diff] [blame] | 1117 | for_each_td(td, i) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 1118 | if (!td->o.group_reporting) { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1119 | nr_ts++; |
| 1120 | continue; |
| 1121 | } |
| 1122 | if (last_ts == td->groupid) |
| 1123 | continue; |
| 1124 | |
| 1125 | last_ts = td->groupid; |
| 1126 | nr_ts++; |
| 1127 | } |
| 1128 | |
| 1129 | threadstats = malloc(nr_ts * sizeof(struct thread_stat)); |
| 1130 | |
Jens Axboe | 37f0c1a | 2011-10-11 14:08:33 +0200 | [diff] [blame] | 1131 | for (i = 0; i < nr_ts; i++) |
| 1132 | init_thread_stat(&threadstats[i]); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1133 | |
| 1134 | j = 0; |
| 1135 | last_ts = -1; |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 1136 | idx = 0; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1137 | for_each_td(td, i) { |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 1138 | if (idx && (!td->o.group_reporting || |
| 1139 | (td->o.group_reporting && last_ts != td->groupid))) { |
Jens Axboe | 7abd0e3 | 2007-03-12 15:24:43 +0100 | [diff] [blame] | 1140 | idx = 0; |
| 1141 | j++; |
| 1142 | } |
| 1143 | |
| 1144 | last_ts = td->groupid; |
| 1145 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1146 | ts = &threadstats[j]; |
| 1147 | |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 1148 | ts->clat_percentiles = td->o.clat_percentiles; |
| 1149 | if (td->o.overwrite_plist) |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 1150 | memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list)); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 1151 | else |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 1152 | memcpy(ts->percentile_list, def_percentile_list, sizeof(def_percentile_list)); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 1153 | |
Jens Axboe | 197574e | 2007-03-08 15:35:11 +0100 | [diff] [blame] | 1154 | idx++; |
Jens Axboe | 6586ee8 | 2007-03-06 19:46:09 +0100 | [diff] [blame] | 1155 | ts->members++; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1156 | |
Jens Axboe | 7abd0e3 | 2007-03-12 15:24:43 +0100 | [diff] [blame] | 1157 | if (ts->groupid == -1) { |
Jens Axboe | 2dc84ba | 2007-03-06 15:46:33 +0100 | [diff] [blame] | 1158 | /* |
| 1159 | * These are per-group shared already |
| 1160 | */ |
Jens Axboe | f6bb5b8 | 2011-10-03 12:21:25 +0200 | [diff] [blame] | 1161 | strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE); |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 1162 | if (td->o.description) |
| 1163 | strncpy(ts->description, td->o.description, |
| 1164 | FIO_JOBNAME_SIZE); |
| 1165 | else |
| 1166 | memset(ts->description, 0, FIO_JOBNAME_SIZE); |
| 1167 | |
Jens Axboe | 2f122b1 | 2012-03-15 13:10:19 +0100 | [diff] [blame] | 1168 | /* |
| 1169 | * If multiple entries in this group, this is |
| 1170 | * the first member. |
| 1171 | */ |
| 1172 | ts->thread_number = td->thread_number; |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1173 | ts->groupid = td->groupid; |
Jens Axboe | 2dc84ba | 2007-03-06 15:46:33 +0100 | [diff] [blame] | 1174 | |
| 1175 | /* |
| 1176 | * first pid in group, not very useful... |
| 1177 | */ |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1178 | ts->pid = td->pid; |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 1179 | |
| 1180 | ts->kb_base = td->o.kb_base; |
| 1181 | } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) { |
| 1182 | log_info("fio: kb_base differs for jobs in group, using" |
| 1183 | " %u as the base\n", ts->kb_base); |
| 1184 | kb_base_warned = 1; |
Jens Axboe | 2dc84ba | 2007-03-06 15:46:33 +0100 | [diff] [blame] | 1185 | } |
| 1186 | |
Radha Ramachandran | f2bba18 | 2009-06-15 08:40:16 +0200 | [diff] [blame] | 1187 | ts->continue_on_error = td->o.continue_on_error; |
| 1188 | ts->total_err_count += td->total_err_count; |
| 1189 | ts->first_error = td->first_error; |
| 1190 | if (!ts->error) { |
| 1191 | if (!td->error && td->o.continue_on_error && |
| 1192 | td->first_error) { |
| 1193 | ts->error = td->first_error; |
Jens Axboe | f6bb5b8 | 2011-10-03 12:21:25 +0200 | [diff] [blame] | 1194 | strcpy(ts->verror, td->verror); |
Radha Ramachandran | f2bba18 | 2009-06-15 08:40:16 +0200 | [diff] [blame] | 1195 | } else if (td->error) { |
| 1196 | ts->error = td->error; |
Jens Axboe | f6bb5b8 | 2011-10-03 12:21:25 +0200 | [diff] [blame] | 1197 | strcpy(ts->verror, td->verror); |
Radha Ramachandran | f2bba18 | 2009-06-15 08:40:16 +0200 | [diff] [blame] | 1198 | } |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1199 | } |
| 1200 | |
Jens Axboe | 5b9babb | 2011-10-10 12:14:30 +0200 | [diff] [blame] | 1201 | sum_thread_stats(ts, &td->ts, idx); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | for (i = 0; i < nr_ts; i++) { |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 1205 | unsigned long long bw; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1206 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1207 | ts = &threadstats[i]; |
| 1208 | rs = &runstats[ts->groupid]; |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 1209 | rs->kb_base = ts->kb_base; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1210 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1211 | for (j = 0; j < DDIR_RWDIR_CNT; j++) { |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 1212 | if (!ts->runtime[j]) |
| 1213 | continue; |
| 1214 | if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j]) |
| 1215 | rs->min_run[j] = ts->runtime[j]; |
| 1216 | if (ts->runtime[j] > rs->max_run[j]) |
| 1217 | rs->max_run[j] = ts->runtime[j]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1218 | |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 1219 | bw = 0; |
Jens Axboe | 8879fd1 | 2009-04-20 10:06:02 +0200 | [diff] [blame] | 1220 | if (ts->runtime[j]) { |
Jens Axboe | c857cfe | 2012-04-05 08:42:11 -0600 | [diff] [blame] | 1221 | unsigned long runt = ts->runtime[j]; |
| 1222 | unsigned long long kb; |
Jens Axboe | 8879fd1 | 2009-04-20 10:06:02 +0200 | [diff] [blame] | 1223 | |
Jens Axboe | c857cfe | 2012-04-05 08:42:11 -0600 | [diff] [blame] | 1224 | kb = ts->io_bytes[j] / rs->kb_base; |
| 1225 | bw = kb * 1000 / runt; |
Jens Axboe | 8879fd1 | 2009-04-20 10:06:02 +0200 | [diff] [blame] | 1226 | } |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 1227 | if (bw < rs->min_bw[j]) |
| 1228 | rs->min_bw[j] = bw; |
| 1229 | if (bw > rs->max_bw[j]) |
| 1230 | rs->max_bw[j] = bw; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1231 | |
Jens Axboe | 90fef2d | 2009-07-17 22:33:32 +0200 | [diff] [blame] | 1232 | rs->io_kb[j] += ts->io_bytes[j] / rs->kb_base; |
Jens Axboe | 94370ac | 2007-03-08 15:28:10 +0100 | [diff] [blame] | 1233 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | for (i = 0; i < groupid + 1; i++) { |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1237 | int ddir; |
| 1238 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1239 | rs = &runstats[i]; |
| 1240 | |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1241 | for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { |
| 1242 | if (rs->max_run[ddir]) |
| 1243 | rs->agg[ddir] = (rs->io_kb[ddir] * 1000) / |
| 1244 | rs->max_run[ddir]; |
| 1245 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1246 | } |
| 1247 | |
| 1248 | /* |
| 1249 | * don't overwrite last signal output |
| 1250 | */ |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1251 | if (output_format == FIO_OUTPUT_NORMAL) |
Jens Axboe | 4ceb30d | 2010-02-24 09:19:14 +0100 | [diff] [blame] | 1252 | log_info("\n"); |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1253 | else if (output_format == FIO_OUTPUT_JSON) { |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 1254 | root = json_create_object(); |
| 1255 | json_object_add_value_string(root, "fio version", fio_version_string); |
| 1256 | array = json_create_array(); |
| 1257 | json_object_add_value_array(root, "jobs", array); |
| 1258 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1259 | |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1260 | for (i = 0; i < nr_ts; i++) { |
| 1261 | ts = &threadstats[i]; |
| 1262 | rs = &runstats[ts->groupid]; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1263 | |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 1264 | if (is_backend) |
| 1265 | fio_server_send_ts(ts, rs); |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1266 | else if (output_format == FIO_OUTPUT_TERSE) |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1267 | show_thread_status_terse(ts, rs); |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1268 | else if (output_format == FIO_OUTPUT_JSON) { |
| 1269 | struct json_object *tmp = show_thread_status_json(ts, rs); |
| 1270 | json_array_add_value_object(array, tmp); |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 1271 | } else |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1272 | show_thread_status(ts, rs); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1273 | } |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1274 | if (output_format == FIO_OUTPUT_JSON) { |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 1275 | /* disk util stats, if any */ |
| 1276 | show_disk_util(1, root); |
| 1277 | |
| 1278 | json_print_object(root); |
| 1279 | log_info("\n"); |
| 1280 | json_free_object(root); |
| 1281 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1282 | |
Jens Axboe | 72c27ff | 2011-10-16 11:50:31 +0200 | [diff] [blame] | 1283 | for (i = 0; i < groupid + 1; i++) { |
| 1284 | rs = &runstats[i]; |
Jens Axboe | a64e88d | 2011-10-03 14:20:01 +0200 | [diff] [blame] | 1285 | |
Jens Axboe | 72c27ff | 2011-10-16 11:50:31 +0200 | [diff] [blame] | 1286 | rs->groupid = i; |
Jens Axboe | d09a64a | 2011-10-13 11:38:56 +0200 | [diff] [blame] | 1287 | if (is_backend) |
Jens Axboe | 72c27ff | 2011-10-16 11:50:31 +0200 | [diff] [blame] | 1288 | fio_server_send_gs(rs); |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1289 | else if (output_format == FIO_OUTPUT_NORMAL) |
Jens Axboe | 72c27ff | 2011-10-16 11:50:31 +0200 | [diff] [blame] | 1290 | show_group_stats(rs); |
Jens Axboe | c6ae0a5 | 2006-06-12 11:04:44 +0200 | [diff] [blame] | 1291 | } |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 1292 | |
Jens Axboe | 72c27ff | 2011-10-16 11:50:31 +0200 | [diff] [blame] | 1293 | if (is_backend) |
| 1294 | fio_server_send_du(); |
Jens Axboe | f3afa57 | 2012-09-17 13:34:16 +0200 | [diff] [blame] | 1295 | else if (output_format == FIO_OUTPUT_NORMAL) |
Shaohua Li | cc372b1 | 2012-09-17 09:12:18 +0200 | [diff] [blame] | 1296 | show_disk_util(0, NULL); |
Jens Axboe | 72c27ff | 2011-10-16 11:50:31 +0200 | [diff] [blame] | 1297 | |
Jens Axboe | eecf272 | 2006-10-20 14:00:36 +0200 | [diff] [blame] | 1298 | free(runstats); |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1299 | free(threadstats); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1300 | } |
| 1301 | |
Jens Axboe | b852e7c | 2012-03-30 10:30:35 +0200 | [diff] [blame] | 1302 | static void *__show_running_run_stats(void *arg) |
| 1303 | { |
| 1304 | struct thread_data *td; |
| 1305 | unsigned long long *rt; |
| 1306 | struct timeval tv; |
| 1307 | int i; |
| 1308 | |
| 1309 | rt = malloc(thread_number * sizeof(unsigned long long)); |
| 1310 | fio_gettime(&tv, NULL); |
| 1311 | |
| 1312 | for_each_td(td, i) { |
| 1313 | rt[i] = mtime_since(&td->start, &tv); |
| 1314 | if (td_read(td) && td->io_bytes[DDIR_READ]) |
| 1315 | td->ts.runtime[DDIR_READ] += rt[i]; |
| 1316 | if (td_write(td) && td->io_bytes[DDIR_WRITE]) |
| 1317 | td->ts.runtime[DDIR_WRITE] += rt[i]; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1318 | if (td_trim(td) && td->io_bytes[DDIR_TRIM]) |
| 1319 | td->ts.runtime[DDIR_TRIM] += rt[i]; |
Jens Axboe | b852e7c | 2012-03-30 10:30:35 +0200 | [diff] [blame] | 1320 | |
| 1321 | update_rusage_stat(td); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1322 | td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ]; |
| 1323 | td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE]; |
| 1324 | td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM]; |
Jens Axboe | b852e7c | 2012-03-30 10:30:35 +0200 | [diff] [blame] | 1325 | td->ts.total_run_time = mtime_since(&td->epoch, &tv); |
| 1326 | } |
| 1327 | |
| 1328 | show_run_stats(); |
| 1329 | |
| 1330 | for_each_td(td, i) { |
| 1331 | if (td_read(td) && td->io_bytes[DDIR_READ]) |
| 1332 | td->ts.runtime[DDIR_READ] -= rt[i]; |
| 1333 | if (td_write(td) && td->io_bytes[DDIR_WRITE]) |
| 1334 | td->ts.runtime[DDIR_WRITE] -= rt[i]; |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1335 | if (td_trim(td) && td->io_bytes[DDIR_TRIM]) |
| 1336 | td->ts.runtime[DDIR_TRIM] -= rt[i]; |
Jens Axboe | b852e7c | 2012-03-30 10:30:35 +0200 | [diff] [blame] | 1337 | } |
| 1338 | |
| 1339 | free(rt); |
| 1340 | return NULL; |
| 1341 | } |
| 1342 | |
| 1343 | /* |
| 1344 | * Called from signal handler. It _should_ be safe to just run this inline |
| 1345 | * in the sig handler, but we should be disturbing the system less by just |
| 1346 | * creating a thread to do it. |
| 1347 | */ |
| 1348 | void show_running_run_stats(void) |
| 1349 | { |
| 1350 | pthread_t thread; |
| 1351 | |
| 1352 | pthread_create(&thread, NULL, __show_running_run_stats, NULL); |
| 1353 | pthread_detach(thread); |
| 1354 | } |
| 1355 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 1356 | static inline void add_stat_sample(struct io_stat *is, unsigned long data) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1357 | { |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 1358 | double val = data; |
Jens Axboe | 6660cc6 | 2007-03-06 15:48:38 +0100 | [diff] [blame] | 1359 | double delta; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1360 | |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 1361 | if (data > is->max_val) |
| 1362 | is->max_val = data; |
| 1363 | if (data < is->min_val) |
| 1364 | is->min_val = data; |
| 1365 | |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 1366 | delta = val - is->mean.u.f; |
Jens Axboe | ef11d73 | 2007-03-29 15:36:29 +0200 | [diff] [blame] | 1367 | if (delta) { |
Jens Axboe | 802ad4a | 2011-10-05 09:51:58 +0200 | [diff] [blame] | 1368 | is->mean.u.f += delta / (is->samples + 1.0); |
| 1369 | is->S.u.f += delta * (val - is->mean.u.f); |
Jens Axboe | ef11d73 | 2007-03-29 15:36:29 +0200 | [diff] [blame] | 1370 | } |
Jens Axboe | 6870408 | 2007-01-10 19:56:37 +0100 | [diff] [blame] | 1371 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1372 | is->samples++; |
| 1373 | } |
| 1374 | |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 1375 | static void __add_log_sample(struct io_log *iolog, unsigned long val, |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1376 | enum fio_ddir ddir, unsigned int bs, |
Jens Axboe | 2b13e71 | 2011-01-19 14:04:16 -0700 | [diff] [blame] | 1377 | unsigned long t) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1378 | { |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1379 | const int nr_samples = iolog->nr_samples; |
| 1380 | |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 1381 | if (!iolog->nr_samples) |
| 1382 | iolog->avg_last = t; |
| 1383 | |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1384 | if (iolog->nr_samples == iolog->max_samples) { |
| 1385 | int new_size = sizeof(struct io_sample) * iolog->max_samples*2; |
| 1386 | |
| 1387 | iolog->log = realloc(iolog->log, new_size); |
| 1388 | iolog->max_samples <<= 1; |
| 1389 | } |
| 1390 | |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1391 | iolog->log[nr_samples].val = val; |
Jens Axboe | 2b13e71 | 2011-01-19 14:04:16 -0700 | [diff] [blame] | 1392 | iolog->log[nr_samples].time = t; |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1393 | iolog->log[nr_samples].ddir = ddir; |
| 1394 | iolog->log[nr_samples].bs = bs; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1395 | iolog->nr_samples++; |
| 1396 | } |
| 1397 | |
Jens Axboe | 7fb28d3 | 2011-12-01 15:17:24 +0100 | [diff] [blame] | 1398 | static inline void reset_io_stat(struct io_stat *ios) |
| 1399 | { |
| 1400 | ios->max_val = ios->min_val = ios->samples = 0; |
| 1401 | ios->mean.u.f = ios->S.u.f = 0; |
| 1402 | } |
| 1403 | |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 1404 | static void add_log_sample(struct thread_data *td, struct io_log *iolog, |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1405 | unsigned long val, enum fio_ddir ddir, |
| 1406 | unsigned int bs) |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 1407 | { |
Jens Axboe | 7fb28d3 | 2011-12-01 15:17:24 +0100 | [diff] [blame] | 1408 | unsigned long elapsed, this_window; |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 1409 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 1410 | if (!ddir_rw(ddir)) |
| 1411 | return; |
| 1412 | |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 1413 | elapsed = mtime_since_now(&td->epoch); |
| 1414 | |
| 1415 | /* |
| 1416 | * If no time averaging, just add the log sample. |
| 1417 | */ |
| 1418 | if (!iolog->avg_msec) { |
| 1419 | __add_log_sample(iolog, val, ddir, bs, elapsed); |
| 1420 | return; |
| 1421 | } |
| 1422 | |
| 1423 | /* |
| 1424 | * Add the sample. If the time period has passed, then |
| 1425 | * add that entry to the log and clear. |
| 1426 | */ |
| 1427 | add_stat_sample(&iolog->avg_window[ddir], val); |
| 1428 | |
Jens Axboe | 7fb28d3 | 2011-12-01 15:17:24 +0100 | [diff] [blame] | 1429 | /* |
| 1430 | * If period hasn't passed, adding the above sample is all we |
| 1431 | * need to do. |
| 1432 | */ |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 1433 | this_window = elapsed - iolog->avg_last; |
| 1434 | if (this_window < iolog->avg_msec) |
| 1435 | return; |
| 1436 | |
Jens Axboe | 7fb28d3 | 2011-12-01 15:17:24 +0100 | [diff] [blame] | 1437 | /* |
| 1438 | * Note an entry in the log. Use the mean from the logged samples, |
| 1439 | * making sure to properly round up. Only write a log entry if we |
| 1440 | * had actual samples done. |
| 1441 | */ |
| 1442 | if (iolog->avg_window[DDIR_READ].samples) { |
| 1443 | unsigned long mr; |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 1444 | |
Jens Axboe | 7fb28d3 | 2011-12-01 15:17:24 +0100 | [diff] [blame] | 1445 | mr = iolog->avg_window[DDIR_READ].mean.u.f + 0.50; |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 1446 | __add_log_sample(iolog, mr, DDIR_READ, 0, elapsed); |
Jens Axboe | 7fb28d3 | 2011-12-01 15:17:24 +0100 | [diff] [blame] | 1447 | } |
| 1448 | if (iolog->avg_window[DDIR_WRITE].samples) { |
| 1449 | unsigned long mw; |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 1450 | |
Jens Axboe | 7fb28d3 | 2011-12-01 15:17:24 +0100 | [diff] [blame] | 1451 | mw = iolog->avg_window[DDIR_WRITE].mean.u.f + 0.50; |
| 1452 | __add_log_sample(iolog, mw, DDIR_WRITE, 0, elapsed); |
| 1453 | } |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1454 | if (iolog->avg_window[DDIR_TRIM].samples) { |
| 1455 | unsigned long mw; |
| 1456 | |
| 1457 | mw = iolog->avg_window[DDIR_TRIM].mean.u.f + 0.50; |
| 1458 | __add_log_sample(iolog, mw, DDIR_TRIM, 0, elapsed); |
| 1459 | } |
| 1460 | |
Jens Axboe | 7fb28d3 | 2011-12-01 15:17:24 +0100 | [diff] [blame] | 1461 | |
| 1462 | reset_io_stat(&iolog->avg_window[DDIR_READ]); |
| 1463 | reset_io_stat(&iolog->avg_window[DDIR_WRITE]); |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1464 | reset_io_stat(&iolog->avg_window[DDIR_TRIM]); |
Jens Axboe | b8bc8cb | 2011-12-01 09:04:31 +0100 | [diff] [blame] | 1465 | iolog->avg_last = elapsed; |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 1466 | } |
| 1467 | |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1468 | void add_agg_sample(unsigned long val, enum fio_ddir ddir, unsigned int bs) |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 1469 | { |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 1470 | struct io_log *iolog; |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 1471 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 1472 | if (!ddir_rw(ddir)) |
| 1473 | return; |
| 1474 | |
| 1475 | iolog = agg_io_log[ddir]; |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1476 | __add_log_sample(iolog, val, ddir, bs, mtime_since_genesis()); |
Jens Axboe | bb3884d | 2007-01-17 17:23:11 +1100 | [diff] [blame] | 1477 | } |
| 1478 | |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 1479 | static void add_clat_percentile_sample(struct thread_stat *ts, |
| 1480 | unsigned long usec, enum fio_ddir ddir) |
| 1481 | { |
| 1482 | unsigned int idx = plat_val_to_idx(usec); |
| 1483 | assert(idx < FIO_IO_U_PLAT_NR); |
| 1484 | |
| 1485 | ts->io_u_plat[ddir][idx]++; |
| 1486 | } |
| 1487 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 1488 | void add_clat_sample(struct thread_data *td, enum fio_ddir ddir, |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1489 | unsigned long usec, unsigned int bs) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1490 | { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1491 | struct thread_stat *ts = &td->ts; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1492 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 1493 | if (!ddir_rw(ddir)) |
| 1494 | return; |
| 1495 | |
Jens Axboe | d85f511 | 2007-06-18 09:41:23 +0200 | [diff] [blame] | 1496 | add_stat_sample(&ts->clat_stat[ddir], usec); |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 1497 | |
Jens Axboe | 7b9f733 | 2011-10-03 10:06:44 +0200 | [diff] [blame] | 1498 | if (td->clat_log) |
| 1499 | add_log_sample(td, td->clat_log, usec, ddir, bs); |
Yu-ju Hong | 8334919 | 2011-08-13 00:53:44 +0200 | [diff] [blame] | 1500 | |
| 1501 | if (ts->clat_percentiles) |
| 1502 | add_clat_percentile_sample(ts, usec, ddir); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1503 | } |
| 1504 | |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 1505 | void add_slat_sample(struct thread_data *td, enum fio_ddir ddir, |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1506 | unsigned long usec, unsigned int bs) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1507 | { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1508 | struct thread_stat *ts = &td->ts; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1509 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 1510 | if (!ddir_rw(ddir)) |
| 1511 | return; |
| 1512 | |
Jens Axboe | d85f511 | 2007-06-18 09:41:23 +0200 | [diff] [blame] | 1513 | add_stat_sample(&ts->slat_stat[ddir], usec); |
Jens Axboe | 079ad09 | 2007-02-20 13:58:20 +0100 | [diff] [blame] | 1514 | |
Jens Axboe | 7b9f733 | 2011-10-03 10:06:44 +0200 | [diff] [blame] | 1515 | if (td->slat_log) |
| 1516 | add_log_sample(td, td->slat_log, usec, ddir, bs); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1517 | } |
| 1518 | |
Jens Axboe | 02af098 | 2010-06-24 09:59:34 +0200 | [diff] [blame] | 1519 | void add_lat_sample(struct thread_data *td, enum fio_ddir ddir, |
| 1520 | unsigned long usec, unsigned int bs) |
| 1521 | { |
| 1522 | struct thread_stat *ts = &td->ts; |
| 1523 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 1524 | if (!ddir_rw(ddir)) |
| 1525 | return; |
| 1526 | |
Jens Axboe | 02af098 | 2010-06-24 09:59:34 +0200 | [diff] [blame] | 1527 | add_stat_sample(&ts->lat_stat[ddir], usec); |
| 1528 | |
Jens Axboe | 7b9f733 | 2011-10-03 10:06:44 +0200 | [diff] [blame] | 1529 | if (td->lat_log) |
| 1530 | add_log_sample(td, td->lat_log, usec, ddir, bs); |
Jens Axboe | 02af098 | 2010-06-24 09:59:34 +0200 | [diff] [blame] | 1531 | } |
| 1532 | |
Jens Axboe | 306ddc9 | 2009-05-18 13:08:12 +0200 | [diff] [blame] | 1533 | void add_bw_sample(struct thread_data *td, enum fio_ddir ddir, unsigned int bs, |
Jens Axboe | 1e97cce | 2006-12-05 11:44:16 +0100 | [diff] [blame] | 1534 | struct timeval *t) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1535 | { |
Jens Axboe | 756867b | 2007-03-06 15:19:24 +0100 | [diff] [blame] | 1536 | struct thread_stat *ts = &td->ts; |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 1537 | unsigned long spent, rate; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1538 | |
Jens Axboe | ff58fce | 2010-08-25 12:02:08 +0200 | [diff] [blame] | 1539 | if (!ddir_rw(ddir)) |
| 1540 | return; |
| 1541 | |
Jens Axboe | c8eeb9d | 2011-10-05 14:02:22 +0200 | [diff] [blame] | 1542 | spent = mtime_since(&td->bw_sample_time, t); |
Jens Axboe | 2dc1bbe | 2007-03-15 15:01:33 +0100 | [diff] [blame] | 1543 | if (spent < td->o.bw_avg_time) |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1544 | return; |
Jens Axboe | 9602d8d | 2012-02-20 20:19:28 +0100 | [diff] [blame] | 1545 | |
| 1546 | /* |
Josh Carter | 5daa4eb | 2012-02-20 10:12:22 +0100 | [diff] [blame] | 1547 | * Compute both read and write rates for the interval. |
| 1548 | */ |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1549 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
Josh Carter | 5daa4eb | 2012-02-20 10:12:22 +0100 | [diff] [blame] | 1550 | uint64_t delta; |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1551 | |
Josh Carter | 5daa4eb | 2012-02-20 10:12:22 +0100 | [diff] [blame] | 1552 | delta = td->this_io_bytes[ddir] - td->stat_io_bytes[ddir]; |
| 1553 | if (!delta) |
| 1554 | continue; /* No entries for interval */ |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1555 | |
Josh Carter | 5daa4eb | 2012-02-20 10:12:22 +0100 | [diff] [blame] | 1556 | rate = delta * 1000 / spent / 1024; |
| 1557 | add_stat_sample(&ts->bw_stat[ddir], rate); |
| 1558 | |
| 1559 | if (td->bw_log) |
| 1560 | add_log_sample(td, td->bw_log, rate, ddir, bs); |
| 1561 | |
| 1562 | td->stat_io_bytes[ddir] = td->this_io_bytes[ddir]; |
| 1563 | } |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1564 | |
Jens Axboe | c8eeb9d | 2011-10-05 14:02:22 +0200 | [diff] [blame] | 1565 | fio_gettime(&td->bw_sample_time, NULL); |
Jens Axboe | 3c39a37 | 2006-06-06 20:56:12 +0200 | [diff] [blame] | 1566 | } |
Jens Axboe | c8eeb9d | 2011-10-05 14:02:22 +0200 | [diff] [blame] | 1567 | |
| 1568 | void add_iops_sample(struct thread_data *td, enum fio_ddir ddir, |
| 1569 | struct timeval *t) |
| 1570 | { |
| 1571 | struct thread_stat *ts = &td->ts; |
| 1572 | unsigned long spent, iops; |
| 1573 | |
| 1574 | if (!ddir_rw(ddir)) |
| 1575 | return; |
| 1576 | |
| 1577 | spent = mtime_since(&td->iops_sample_time, t); |
| 1578 | if (spent < td->o.iops_avg_time) |
| 1579 | return; |
| 1580 | |
Jens Axboe | 9602d8d | 2012-02-20 20:19:28 +0100 | [diff] [blame] | 1581 | /* |
| 1582 | * Compute both read and write rates for the interval. |
| 1583 | */ |
Shaohua Li | 6eaf09d | 2012-09-14 08:49:43 +0200 | [diff] [blame] | 1584 | for (ddir = DDIR_READ; ddir < DDIR_RWDIR_CNT; ddir++) { |
Jens Axboe | 9602d8d | 2012-02-20 20:19:28 +0100 | [diff] [blame] | 1585 | uint64_t delta; |
Jens Axboe | c8eeb9d | 2011-10-05 14:02:22 +0200 | [diff] [blame] | 1586 | |
Jens Axboe | 9602d8d | 2012-02-20 20:19:28 +0100 | [diff] [blame] | 1587 | delta = td->this_io_blocks[ddir] - td->stat_io_blocks[ddir]; |
| 1588 | if (!delta) |
| 1589 | continue; /* No entries for interval */ |
Jens Axboe | c8eeb9d | 2011-10-05 14:02:22 +0200 | [diff] [blame] | 1590 | |
Jens Axboe | 9602d8d | 2012-02-20 20:19:28 +0100 | [diff] [blame] | 1591 | iops = (delta * 1000) / spent; |
| 1592 | add_stat_sample(&ts->iops_stat[ddir], iops); |
| 1593 | |
| 1594 | if (td->iops_log) |
| 1595 | add_log_sample(td, td->iops_log, iops, ddir, 0); |
| 1596 | |
Jens Axboe | 421f4a8 | 2012-02-28 08:20:26 +0100 | [diff] [blame] | 1597 | td->stat_io_blocks[ddir] = td->this_io_blocks[ddir]; |
Jens Axboe | 9602d8d | 2012-02-20 20:19:28 +0100 | [diff] [blame] | 1598 | } |
Jens Axboe | c8eeb9d | 2011-10-05 14:02:22 +0200 | [diff] [blame] | 1599 | |
| 1600 | fio_gettime(&td->iops_sample_time, NULL); |
Jens Axboe | c8eeb9d | 2011-10-05 14:02:22 +0200 | [diff] [blame] | 1601 | } |