13c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe#include <stdio.h> 23c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe#include <string.h> 33c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe#include <sys/time.h> 43c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe#include <sys/types.h> 55c4e1dbc4ec6ee963220c5f4e64a04cd6130dc81Jens Axboe#include <sys/stat.h> 63c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe#include <dirent.h> 73c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe#include <libgen.h> 83c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe#include <math.h> 93c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 103c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe#include "fio.h" 117c9b1bce094d58c374b086bbb780c08265623ea4Jens Axboe#include "diskutil.h" 12c7c6cb4cb3114ec4ce3107e15c184e161b50122eJens Axboe#include "lib/ieee754.h" 13cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li#include "json.h" 1444404c5a7f90aa42c3228b56b6f686f15a50fb29Jens Axboe#include "lib/getrusage.h" 15f2a2ce0eedb44eaa8689e4cbfa77c79b1751b216Huadong Liu#include "idletime.h" 16eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes#include "lib/pow2.h" 17eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes#include "lib/output_buffer.h" 18eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes#include "helper_thread.h" 19eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes#include "smalloc.h" 20eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 21eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes#define LOG_MSEC_SLACK 10 223c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 23c38e38f16f77567a423f75c26e1929cbe4902e24Vasily Tarasovstruct fio_mutex *stat_mutex; 24cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe 25eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesvoid clear_rusage_stat(struct thread_data *td) 26eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 27eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct thread_stat *ts = &td->ts; 28eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 29eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes fio_getrusage(&td->ru_start); 30eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->usr_time = ts->sys_time = 0; 31eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ctx = 0; 32eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->minf = ts->majf = 0; 33eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 34eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 353c39a379542fd819dbc5cf6daf59380911c39141Jens Axboevoid update_rusage_stat(struct thread_data *td) 363c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 37756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe struct thread_stat *ts = &td->ts; 383c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 3944404c5a7f90aa42c3228b56b6f686f15a50fb29Jens Axboe fio_getrusage(&td->ru_end); 40c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe ts->usr_time += mtime_since(&td->ru_start.ru_utime, 41c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe &td->ru_end.ru_utime); 42c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe ts->sys_time += mtime_since(&td->ru_start.ru_stime, 43c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe &td->ru_end.ru_stime); 44c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw 45c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe - (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw); 46c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt; 47c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt; 485ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe 49c8aaba193fd910f89486ba4caab0c023306fffaeJens Axboe memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end)); 503c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 513c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 52833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong/* 53833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * Given a latency, return the index of the corresponding bucket in 54833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * the structure tracking percentiles. 55833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * 56833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * (1) find the group (and error bits) that the value (latency) 57833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * belongs to by looking at its MSB. (2) find the bucket number in the 58833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * group by looking at the index bits. 59833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * 60833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong */ 61833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hongstatic unsigned int plat_val_to_idx(unsigned int val) 62833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong{ 63833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong unsigned int msb, error_bits, base, offset, idx; 64833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 65833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong /* Find MSB starting from bit 0 */ 66833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong if (val == 0) 67833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong msb = 0; 68833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong else 69833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong msb = (sizeof(val)*8) - __builtin_clz(val) - 1; 70833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 71716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe /* 72716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe * MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use 73716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe * all bits of the sample as index 74716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe */ 75833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong if (msb <= FIO_IO_U_PLAT_BITS) 76833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong return val; 77833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 78833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong /* Compute the number of error bits to discard*/ 79833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong error_bits = msb - FIO_IO_U_PLAT_BITS; 80833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 81833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong /* Compute the number of buckets before the group */ 82833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong base = (error_bits + 1) << FIO_IO_U_PLAT_BITS; 83833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 84716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe /* 85716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe * Discard the error bits and apply the mask to find the 863c3ed070502bbfec387ded2c43d5e4559ca24a63Jens Axboe * index for the buckets in the group 87716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe */ 88833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits); 89833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 90833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong /* Make sure the index does not exceed (array size - 1) */ 913c3ed070502bbfec387ded2c43d5e4559ca24a63Jens Axboe idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1) ? 92833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong (base + offset) : (FIO_IO_U_PLAT_NR - 1); 93833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 94833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong return idx; 95833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong} 96833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 97833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong/* 98833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * Convert the given index of the bucket array to the value 99833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * represented by the bucket 100833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong */ 101eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic unsigned long long plat_idx_to_val(unsigned int idx) 102833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong{ 103833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong unsigned int error_bits, k, base; 104833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 105833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong assert(idx < FIO_IO_U_PLAT_NR); 106833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 107833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong /* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use 108833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong * all bits of the sample as index */ 1093c3ed070502bbfec387ded2c43d5e4559ca24a63Jens Axboe if (idx < (FIO_IO_U_PLAT_VAL << 1)) 110833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong return idx; 111833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 112833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong /* Find the group and compute the minimum value of that group */ 1133c3ed070502bbfec387ded2c43d5e4559ca24a63Jens Axboe error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1; 114833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong base = 1 << (error_bits + FIO_IO_U_PLAT_BITS); 115833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 116833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong /* Find its bucket number of the group */ 117833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong k = idx % FIO_IO_U_PLAT_VAL; 118833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 119833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong /* Return the mean of the range of the bucket */ 120833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong return base + ((k + 0.5) * (1 << error_bits)); 121833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong} 122833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 123833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hongstatic int double_cmp(const void *a, const void *b) 124833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong{ 125802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe const fio_fp64_t fa = *(const fio_fp64_t *) a; 126802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe const fio_fp64_t fb = *(const fio_fp64_t *) b; 127833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong int cmp = 0; 128833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 129802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe if (fa.u.f > fb.u.f) 130833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong cmp = 1; 131802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe else if (fa.u.f < fb.u.f) 132833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong cmp = -1; 133833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 134833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong return cmp; 135833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong} 136833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 137a269790cd25788dd4226641a3ceab1b3c8fda14bJens Axboeunsigned int calc_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, 138a269790cd25788dd4226641a3ceab1b3c8fda14bJens Axboe fio_fp64_t *plist, unsigned int **output, 139a269790cd25788dd4226641a3ceab1b3c8fda14bJens Axboe unsigned int *maxv, unsigned int *minv) 140833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong{ 141833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong unsigned long sum = 0; 1421db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe unsigned int len, i, j = 0; 1431db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe unsigned int oval_len = 0; 1441db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe unsigned int *ovals = NULL; 1451db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe int is_last; 1461db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe 1471db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe *minv = -1U; 1481db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe *maxv = 0; 149833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 150802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe len = 0; 151802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) 152802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe len++; 153716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe 154351de8de68623375d2693192047cef7411f16442Jens Axboe if (!len) 1551db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe return 0; 156351de8de68623375d2693192047cef7411f16442Jens Axboe 157716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe /* 158802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe * Sort the percentile list. Note that it may already be sorted if 159802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe * we are using the default values, but since it's a short list this 160802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe * isn't a worry. Also note that this does not work for NaN values. 161716050f2a0b858835d7836ad74e8b680973e08e8Jens Axboe */ 162802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe if (len > 1) 1633c3ed070502bbfec387ded2c43d5e4559ca24a63Jens Axboe qsort((void *)plist, len, sizeof(plist[0]), double_cmp); 164833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 1654f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe /* 1664f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe * Calculate bucket values, note down max and min values 1674f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe */ 16807511a632ef219eb578d8c7f12825a275c640bcfJens Axboe is_last = 0; 16907511a632ef219eb578d8c7f12825a275c640bcfJens Axboe for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) { 170833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong sum += io_u_plat[i]; 171802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe while (sum >= (plist[j].u.f / 100.0 * nr)) { 172802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe assert(plist[j].u.f <= 100.0); 173833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 1744f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe if (j == oval_len) { 1754f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe oval_len += 100; 1764f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe ovals = realloc(ovals, oval_len * sizeof(unsigned int)); 1774f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe } 1784f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe 1794f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe ovals[j] = plat_idx_to_val(i); 1801db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe if (ovals[j] < *minv) 1811db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe *minv = ovals[j]; 1821db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe if (ovals[j] > *maxv) 1831db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe *maxv = ovals[j]; 18407511a632ef219eb578d8c7f12825a275c640bcfJens Axboe 18507511a632ef219eb578d8c7f12825a275c640bcfJens Axboe is_last = (j == len - 1); 18607511a632ef219eb578d8c7f12825a275c640bcfJens Axboe if (is_last) 18707511a632ef219eb578d8c7f12825a275c640bcfJens Axboe break; 18807511a632ef219eb578d8c7f12825a275c640bcfJens Axboe 1894f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe j++; 1904f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe } 1914f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe } 192833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 1931db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe *output = ovals; 1941db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe return len; 1951db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe} 1961db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe 1971db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe/* 1981db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe * Find and display the p-th percentile of clat 1991db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe */ 2001db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboestatic void show_clat_percentiles(unsigned int *io_u_plat, unsigned long nr, 201eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes fio_fp64_t *plist, unsigned int precision, 202eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct buf_output *out) 2031db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe{ 2041db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe unsigned int len, j = 0, minv, maxv; 2051db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe unsigned int *ovals; 206eef02441621aa969f01a1a331e0215dd587d25afJens Axboe int is_last, per_line, scale_down; 207eef02441621aa969f01a1a331e0215dd587d25afJens Axboe char fmt[32]; 2081db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe 2091db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv); 2101db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe if (!len) 2111db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe goto out; 2121db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe 2134f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe /* 2144f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe * We default to usecs, but if the value range is such that we 2154f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe * should scale down to msecs, do that. 2164f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe */ 2174f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe if (minv > 2000 && maxv > 99999) { 2184f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe scale_down = 1; 219eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " clat percentiles (msec):\n |"); 2204f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe } else { 2214f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe scale_down = 0; 222eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " clat percentiles (usec):\n |"); 2234f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe } 224833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 2253dc1e5b28bc4d9b673fe81fc4884b1a621ffe9deJens Axboe snprintf(fmt, sizeof(fmt), "%%1.%uf", precision); 226eef02441621aa969f01a1a331e0215dd587d25afJens Axboe per_line = (80 - 7) / (precision + 14); 227619adf9c5aa472904eec3a62f13030e6b261ea25Jens Axboe 2284f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe for (j = 0; j < len; j++) { 229619adf9c5aa472904eec3a62f13030e6b261ea25Jens Axboe char fbuf[16], *ptr = fbuf; 23081ab0b3ab4db39033e020a1e611197fe04df6c3eJens Axboe 2314f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe /* for formatting */ 232eef02441621aa969f01a1a331e0215dd587d25afJens Axboe if (j != 0 && (j % per_line) == 0) 233eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " |"); 234833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 2354f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe /* end of the list */ 2364f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe is_last = (j == len - 1); 237833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 2384f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe if (plist[j].u.f < 10.0) 239619adf9c5aa472904eec3a62f13030e6b261ea25Jens Axboe ptr += sprintf(fbuf, " "); 240619adf9c5aa472904eec3a62f13030e6b261ea25Jens Axboe 241eef02441621aa969f01a1a331e0215dd587d25afJens Axboe snprintf(ptr, sizeof(fbuf), fmt, plist[j].u.f); 2424f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe 2434f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe if (scale_down) 2444f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe ovals[j] = (ovals[j] + 999) / 1000; 2454f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe 246eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " %sth=[%5u]%c", fbuf, ovals[j], is_last ? '\n' : ','); 2474f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe 2484f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe if (is_last) 2494f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe break; 2504f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe 251eef02441621aa969f01a1a331e0215dd587d25afJens Axboe if ((j % per_line) == per_line - 1) /* for formatting */ 252eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "\n"); 253833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong } 2544f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe 2551db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboeout: 2564f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe if (ovals) 2574f6f8298a2d3f19cec0ba65525930a62eee3967fJens Axboe free(ovals); 258833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong} 259833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 260eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesbool calc_lat(struct io_stat *is, unsigned long *min, unsigned long *max, 261eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes double *mean, double *dev) 2623c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 263ee0ccb794be1d3c677e2c02b416a8702d59811d7Erwan Velu double n = (double) is->samples; 2643c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 265ee0ccb794be1d3c677e2c02b416a8702d59811d7Erwan Velu if (n == 0) 266eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return false; 2673c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 2683c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe *min = is->min_val; 2693c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe *max = is->max_val; 270802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe *mean = is->mean.u.f; 271e6d276f2c07cc35f3d57210713e8288bb44daf97Jens Axboe 272687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboe if (n > 1.0) 273802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe *dev = sqrt(is->S.u.f / (n - 1.0)); 274ef9c5c40a9f4b0ce3be9f13cedaaf7e2a90d47a6Jens Axboe else 2754b43f54ed7dece502350658bee10eba551aeb4a4Jens Axboe *dev = 0; 276ef9c5c40a9f4b0ce3be9f13cedaaf7e2a90d47a6Jens Axboe 277eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return true; 2783c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 2793c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 280eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesvoid show_group_stats(struct group_run_stats *rs, struct buf_output *out) 2813c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 282eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char *io, *agg, *min, *max; 283eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char *ioalt, *aggalt, *minalt, *maxalt; 2844d6922b77db7109369f0499506cf2cf7a62aba45Jens Axboe const char *str[] = { " READ", " WRITE" , " TRIM"}; 285dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe int i; 286dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe 287eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "\nRun status group %d (all jobs):\n", rs->groupid); 2883c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 2896eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (i = 0; i < DDIR_RWDIR_CNT; i++) { 29090fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe const int i2p = is_power_of_2(rs->kb_base); 29190fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe 292dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe if (!rs->max_run[i]) 293dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe continue; 294dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe 295eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes io = num2str(rs->iobytes[i], 4, 1, i2p, N2S_BYTE); 296eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ioalt = num2str(rs->iobytes[i], 4, 1, !i2p, N2S_BYTE); 297eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes agg = num2str(rs->agg[i], 4, 1, i2p, rs->unit_base); 298eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes aggalt = num2str(rs->agg[i], 4, 1, !i2p, rs->unit_base); 299eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes min = num2str(rs->min_bw[i], 4, 1, i2p, rs->unit_base); 300eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes minalt = num2str(rs->min_bw[i], 4, 1, !i2p, rs->unit_base); 301eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes max = num2str(rs->max_bw[i], 4, 1, i2p, rs->unit_base); 302eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes maxalt = num2str(rs->max_bw[i], 4, 1, !i2p, rs->unit_base); 303eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "%s: bw=%s (%s), %s-%s (%s-%s), io=%s (%s), run=%llu-%llumsec\n", 3044d6922b77db7109369f0499506cf2cf7a62aba45Jens Axboe rs->unified_rw_rep ? " MIXED" : str[i], 305eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes agg, aggalt, min, max, minalt, maxalt, io, ioalt, 3064e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) rs->min_run[i], 3074e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) rs->max_run[i]); 308dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe 309eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(io); 310eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(agg); 311eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(min); 312eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(max); 313eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(ioalt); 314eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(aggalt); 315eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(minalt); 316eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(maxalt); 317dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe } 3183c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 3193c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 3202e33101f218a1603eeecca969f5b7a0e98696a01Jens Axboevoid stat_calc_dist(unsigned int *map, unsigned long total, double *io_u_dist) 3212270890cef8d98ab97f87d348d16dce6454e631fJens Axboe{ 3222270890cef8d98ab97f87d348d16dce6454e631fJens Axboe int i; 3232270890cef8d98ab97f87d348d16dce6454e631fJens Axboe 3242270890cef8d98ab97f87d348d16dce6454e631fJens Axboe /* 3252270890cef8d98ab97f87d348d16dce6454e631fJens Axboe * Do depth distribution calculations 3262270890cef8d98ab97f87d348d16dce6454e631fJens Axboe */ 3272270890cef8d98ab97f87d348d16dce6454e631fJens Axboe for (i = 0; i < FIO_IO_U_MAP_NR; i++) { 328838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe if (total) { 329838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[i] = (double) map[i] / (double) total; 330838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[i] *= 100.0; 331838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe if (io_u_dist[i] < 0.1 && map[i]) 332838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[i] = 0.1; 333838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe } else 334838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[i] = 0.0; 3352270890cef8d98ab97f87d348d16dce6454e631fJens Axboe } 3362270890cef8d98ab97f87d348d16dce6454e631fJens Axboe} 3372270890cef8d98ab97f87d348d16dce6454e631fJens Axboe 33804a0feae73ca50d05914cc3c425b2a6949523204Jens Axboestatic void stat_calc_lat(struct thread_stat *ts, double *dst, 33904a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe unsigned int *src, int nr) 3402270890cef8d98ab97f87d348d16dce6454e631fJens Axboe{ 341d79db1222039e906dd49ae290daa59701f4e2385Jens Axboe unsigned long total = ddir_rw_sum(ts->total_io_u); 3422270890cef8d98ab97f87d348d16dce6454e631fJens Axboe int i; 3432270890cef8d98ab97f87d348d16dce6454e631fJens Axboe 3442270890cef8d98ab97f87d348d16dce6454e631fJens Axboe /* 3452270890cef8d98ab97f87d348d16dce6454e631fJens Axboe * Do latency distribution calculations 3462270890cef8d98ab97f87d348d16dce6454e631fJens Axboe */ 34704a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe for (i = 0; i < nr; i++) { 348838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe if (total) { 349838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe dst[i] = (double) src[i] / (double) total; 350838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe dst[i] *= 100.0; 351838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe if (dst[i] < 0.01 && src[i]) 352838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe dst[i] = 0.01; 353838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe } else 354838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe dst[i] = 0.0; 3552270890cef8d98ab97f87d348d16dce6454e631fJens Axboe } 3562270890cef8d98ab97f87d348d16dce6454e631fJens Axboe} 3572270890cef8d98ab97f87d348d16dce6454e631fJens Axboe 358e5bd13470beaeed9c4a6835b7b92265fb94173a9Jens Axboevoid stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat) 35904a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe{ 36004a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR); 36104a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe} 36204a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 363e5bd13470beaeed9c4a6835b7b92265fb94173a9Jens Axboevoid stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat) 36404a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe{ 36504a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR); 36604a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe} 36704a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 368b29ad56266faa33326de00e315d2b34b735fb028Jens Axboestatic void display_lat(const char *name, unsigned long min, unsigned long max, 369eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes double mean, double dev, struct buf_output *out) 370ea2accc50fe911f7c24f08e62db55de4d2386b71Jens Axboe{ 371b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe const char *base = "(usec)"; 372b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe char *minp, *maxp; 373ea2accc50fe911f7c24f08e62db55de4d2386b71Jens Axboe 374eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (usec_to_msec(&min, &max, &mean, &dev)) 375b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe base = "(msec)"; 376b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe 377eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes minp = num2str(min, 6, 1, 0, N2S_NONE); 378eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes maxp = num2str(max, 6, 1, 0, N2S_NONE); 379b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe 380eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " %s %s: min=%s, max=%s, avg=%5.02f," 381b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe " stdev=%5.02f\n", name, base, minp, maxp, mean, dev); 382b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe 383b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe free(minp); 384b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe free(maxp); 385ea2accc50fe911f7c24f08e62db55de4d2386b71Jens Axboe} 386ea2accc50fe911f7c24f08e62db55de4d2386b71Jens Axboe 387756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboestatic void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts, 388eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int ddir, struct buf_output *out) 3893c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 390eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes const char *str[] = { " read", "write", " trim" }; 3918879fd15550a5edac3f4fdab6f98badb18dea18cJens Axboe unsigned long min, max, runt; 392b3605062146bce0136918763bb8eb584478ae042Jens Axboe unsigned long long bw, iops; 3933c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe double mean, dev; 394eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char *io_p, *bw_p, *bw_p_alt, *iops_p; 39590fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe int i2p; 3963c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 397ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe assert(ddir_rw(ddir)); 398ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe 399756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe if (!ts->runtime[ddir]) 4003c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe return; 4013c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 40290fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe i2p = is_power_of_2(rs->kb_base); 4038879fd15550a5edac3f4fdab6f98badb18dea18cJens Axboe runt = ts->runtime[ddir]; 4048879fd15550a5edac3f4fdab6f98badb18dea18cJens Axboe 4058879fd15550a5edac3f4fdab6f98badb18dea18cJens Axboe bw = (1000 * ts->io_bytes[ddir]) / runt; 406eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes io_p = num2str(ts->io_bytes[ddir], 4, 1, i2p, N2S_BYTE); 407eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_p = num2str(bw, 4, 1, i2p, ts->unit_base); 408eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_p_alt = num2str(bw, 4, 1, !i2p, ts->unit_base); 4098879fd15550a5edac3f4fdab6f98badb18dea18cJens Axboe 4100aacc50c2fa41e44512ce8eacfd3d679cb016d86Bruce Cran iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt; 411eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iops_p = num2str(iops, 4, 1, 0, N2S_NONE); 412dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe 413eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " %s: IOPS=%s, BW=%s (%s)(%s/%llumsec)\n", 414eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes rs->unified_rw_rep ? "mixed" : str[ddir], 415eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iops_p, bw_p, bw_p_alt, io_p, 416eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes (unsigned long long) ts->runtime[ddir]); 417dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe 418dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe free(io_p); 419dbe1125e9c53b2a0b1fc2fd9c6cfd0b3fbddda8bJens Axboe free(bw_p); 420eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(bw_p_alt); 421b3605062146bce0136918763bb8eb584478ae042Jens Axboe free(iops_p); 4223c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 423b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) 424eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes display_lat("slat", min, max, mean, dev, out); 425b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) 426eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes display_lat("clat", min, max, mean, dev, out); 427b29ad56266faa33326de00e315d2b34b735fb028Jens Axboe if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) 428eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes display_lat(" lat", min, max, mean, dev, out); 42902af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe 430833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong if (ts->clat_percentiles) { 431833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong show_clat_percentiles(ts->io_u_plat[ddir], 432833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong ts->clat_stat[ddir].samples, 433435d195a9da120c5a618129cdb73418f4748c20aVincent Kang Fu ts->percentile_list, 434eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->percentile_precision, out); 435833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong } 436079ad09b1ef22fa0d47c2cd2673908c5619aa41aJens Axboe if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { 437142c7f2d081337362afd85c1613627d8ee9ddeafSteven Noonan double p_of_agg = 100.0, fkb_base = (double)rs->kb_base; 438eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes const char *bw_str; 439eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 440eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if ((rs->unit_base == 1) && i2p) 441eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_str = "Kibit"; 442eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else if (rs->unit_base == 1) 443eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_str = "kbit"; 444eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else if (i2p) 445eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_str = "KiB"; 446eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else 447eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_str = "kB"; 448d686990a3c4bf23823d78c9b69196b24028491eeSteven Noonan 449d686990a3c4bf23823d78c9b69196b24028491eeSteven Noonan if (rs->unit_base == 1) { 450d686990a3c4bf23823d78c9b69196b24028491eeSteven Noonan min *= 8.0; 451d686990a3c4bf23823d78c9b69196b24028491eeSteven Noonan max *= 8.0; 452d686990a3c4bf23823d78c9b69196b24028491eeSteven Noonan mean *= 8.0; 453d686990a3c4bf23823d78c9b69196b24028491eeSteven Noonan dev *= 8.0; 454d686990a3c4bf23823d78c9b69196b24028491eeSteven Noonan } 4553c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 4562f2c69242ba72508fb5429d12e1fd72c3cc1e76cJens Axboe if (rs->agg[ddir]) { 45719d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe p_of_agg = mean * 100 / (double) rs->agg[ddir]; 45819d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe if (p_of_agg > 100.0) 45919d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe p_of_agg = 100.0; 46019d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe } 461b7017e324de0484b5b4db881bdb280611523cf7eJens Axboe 462142c7f2d081337362afd85c1613627d8ee9ddeafSteven Noonan if (mean > fkb_base * fkb_base) { 463142c7f2d081337362afd85c1613627d8ee9ddeafSteven Noonan min /= fkb_base; 464142c7f2d081337362afd85c1613627d8ee9ddeafSteven Noonan max /= fkb_base; 465142c7f2d081337362afd85c1613627d8ee9ddeafSteven Noonan mean /= fkb_base; 466142c7f2d081337362afd85c1613627d8ee9ddeafSteven Noonan dev /= fkb_base; 467eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_str = (rs->unit_base == 1 ? "Mibit" : "MiB"); 468b7017e324de0484b5b4db881bdb280611523cf7eJens Axboe } 469b7017e324de0484b5b4db881bdb280611523cf7eJens Axboe 470eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " bw (%5s/s): min=%5lu, max=%5lu, per=%3.2f%%, avg=%5.02f, stdev=%5.02f\n", 471eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_str, min, max, p_of_agg, mean, dev); 4723c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe } 4733c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 4743c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 4757e1773ba2033a2f70bcbb36c07dc8743c6ce05d1Jens Axboestatic int show_lat(double *io_u_lat, int nr, const char **ranges, 476eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes const char *msg, struct buf_output *out) 47704a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe{ 4787e1773ba2033a2f70bcbb36c07dc8743c6ce05d1Jens Axboe int new_line = 1, i, line = 0, shown = 0; 47904a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 48004a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe for (i = 0; i < nr; i++) { 48104a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe if (io_u_lat[i] <= 0.0) 48204a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe continue; 4837e1773ba2033a2f70bcbb36c07dc8743c6ce05d1Jens Axboe shown = 1; 48404a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe if (new_line) { 4854539ed73159735c20cf6c2808eea84d0cc25a608Jens Axboe if (line) 486eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "\n"); 487eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " lat (%s) : ", msg); 48804a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe new_line = 0; 48904a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe line = 0; 49004a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe } 49104a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe if (line) 492eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ", "); 493eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "%s%3.2f%%", ranges[i], io_u_lat[i]); 49404a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe line++; 49504a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe if (line == 5) 49604a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe new_line = 1; 49704a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe } 4987e1773ba2033a2f70bcbb36c07dc8743c6ce05d1Jens Axboe 4997e1773ba2033a2f70bcbb36c07dc8743c6ce05d1Jens Axboe if (shown) 500eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "\n"); 5017e1773ba2033a2f70bcbb36c07dc8743c6ce05d1Jens Axboe 5027e1773ba2033a2f70bcbb36c07dc8743c6ce05d1Jens Axboe return shown; 50304a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe} 50404a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 505eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void show_lat_u(double *io_u_lat_u, struct buf_output *out) 50604a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe{ 50704a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", 50804a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe "250=", "500=", "750=", "1000=", }; 50904a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 510eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec", out); 51104a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe} 51204a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 513eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void show_lat_m(double *io_u_lat_m, struct buf_output *out) 51404a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe{ 51504a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=", 51604a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe "250=", "500=", "750=", "1000=", "2000=", 51704a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe ">=2000=", }; 51804a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 519eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec", out); 52004a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe} 52104a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 522eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void show_latencies(struct thread_stat *ts, struct buf_output *out) 52304a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe{ 524c551f65a0a2a972c19f9c274f3cf24f4b6d98680Jens Axboe double io_u_lat_u[FIO_IO_U_LAT_U_NR]; 525c551f65a0a2a972c19f9c274f3cf24f4b6d98680Jens Axboe double io_u_lat_m[FIO_IO_U_LAT_M_NR]; 526c551f65a0a2a972c19f9c274f3cf24f4b6d98680Jens Axboe 5275a18988ebd18598bf93cfc76ce1e954f2eede438Jens Axboe stat_calc_lat_u(ts, io_u_lat_u); 5285a18988ebd18598bf93cfc76ce1e954f2eede438Jens Axboe stat_calc_lat_m(ts, io_u_lat_m); 5295a18988ebd18598bf93cfc76ce1e954f2eede438Jens Axboe 530eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_lat_u(io_u_lat_u, out); 531eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_lat_m(io_u_lat_m, out); 532eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 533eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 534eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic int block_state_category(int block_state) 535eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 536eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes switch (block_state) { 537eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes case BLOCK_STATE_UNINIT: 538eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 0; 539eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes case BLOCK_STATE_TRIMMED: 540eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes case BLOCK_STATE_WRITTEN: 541eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 1; 542eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes case BLOCK_STATE_WRITE_FAILURE: 543eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes case BLOCK_STATE_TRIM_FAILURE: 544eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 2; 545eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes default: 546eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* Silence compile warning on some BSDs and have a return */ 547eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes assert(0); 548eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return -1; 549eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 550eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 551eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 552eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic int compare_block_infos(const void *bs1, const void *bs2) 553eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 554eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes uint32_t block1 = *(uint32_t *)bs1; 555eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes uint32_t block2 = *(uint32_t *)bs2; 556eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int state1 = BLOCK_INFO_STATE(block1); 557eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int state2 = BLOCK_INFO_STATE(block2); 558eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int bscat1 = block_state_category(state1); 559eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int bscat2 = block_state_category(state2); 560eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int cycles1 = BLOCK_INFO_TRIMS(block1); 561eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int cycles2 = BLOCK_INFO_TRIMS(block2); 562eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 563eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (bscat1 < bscat2) 564eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return -1; 565eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (bscat1 > bscat2) 566eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 1; 567eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 568eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (cycles1 < cycles2) 569eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return -1; 570eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (cycles1 > cycles2) 571eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 1; 572eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 573eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (state1 < state2) 574eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return -1; 575eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (state1 > state2) 576eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 1; 577eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 578eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes assert(block1 == block2); 579eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 0; 580eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 581eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 582eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic int calc_block_percentiles(int nr_block_infos, uint32_t *block_infos, 583eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes fio_fp64_t *plist, unsigned int **percentiles, 584eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int *types) 585eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 586eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int len = 0; 587eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int i, nr_uninit; 588eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 589eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes qsort(block_infos, nr_block_infos, sizeof(uint32_t), compare_block_infos); 590eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 591eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0) 592eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes len++; 593eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 594eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!len) 595eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 0; 596eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 597eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 598eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Sort the percentile list. Note that it may already be sorted if 599eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * we are using the default values, but since it's a short list this 600eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * isn't a worry. Also note that this does not work for NaN values. 601eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 602eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (len > 1) 603eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes qsort((void *)plist, len, sizeof(plist[0]), double_cmp); 604eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 605eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes nr_uninit = 0; 606eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* Start only after the uninit entries end */ 607eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (nr_uninit = 0; 608eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes nr_uninit < nr_block_infos 609eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes && BLOCK_INFO_STATE(block_infos[nr_uninit]) == BLOCK_STATE_UNINIT; 610eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes nr_uninit ++) 611eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ; 612eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 613eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (nr_uninit == nr_block_infos) 614eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 0; 615eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 616eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes *percentiles = calloc(len, sizeof(**percentiles)); 617eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 618eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < len; i++) { 619eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int idx = (plist[i].u.f * (nr_block_infos - nr_uninit) / 100) 620eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes + nr_uninit; 621eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes (*percentiles)[i] = BLOCK_INFO_TRIMS(block_infos[idx]); 622eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 623eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 624eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes memset(types, 0, sizeof(*types) * BLOCK_STATE_COUNT); 625eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < nr_block_infos; i++) 626eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes types[BLOCK_INFO_STATE(block_infos[i])]++; 627eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 628eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return len; 629eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 630eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 631eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic const char *block_state_names[] = { 632eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes [BLOCK_STATE_UNINIT] = "unwritten", 633eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes [BLOCK_STATE_TRIMMED] = "trimmed", 634eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes [BLOCK_STATE_WRITTEN] = "written", 635eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes [BLOCK_STATE_TRIM_FAILURE] = "trim failure", 636eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes [BLOCK_STATE_WRITE_FAILURE] = "write failure", 637eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes}; 638eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 639eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void show_block_infos(int nr_block_infos, uint32_t *block_infos, 640eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes fio_fp64_t *plist, struct buf_output *out) 641eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 642eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int len, pos, i; 643eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int *percentiles = NULL; 644eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int block_state_counts[BLOCK_STATE_COUNT]; 645eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 646eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes len = calc_block_percentiles(nr_block_infos, block_infos, plist, 647eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes &percentiles, block_state_counts); 648eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 649eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " block lifetime percentiles :\n |"); 650eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes pos = 0; 651eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < len; i++) { 652eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes uint32_t block_info = percentiles[i]; 653eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes#define LINE_LENGTH 75 654eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char str[LINE_LENGTH]; 655eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int strln = snprintf(str, LINE_LENGTH, " %3.2fth=%u%c", 656eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes plist[i].u.f, block_info, 657eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes i == len - 1 ? '\n' : ','); 658eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes assert(strln < LINE_LENGTH); 659eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (pos + strln > LINE_LENGTH) { 660eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes pos = 0; 661eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "\n |"); 662eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 663eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "%s", str); 664eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes pos += strln; 665eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes#undef LINE_LENGTH 666eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 667eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (percentiles) 668eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(percentiles); 669eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 670eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " states :"); 671eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < BLOCK_STATE_COUNT; i++) 672eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " %s=%u%c", 673eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes block_state_names[i], block_state_counts[i], 674eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes i == BLOCK_STATE_COUNT - 1 ? '\n' : ','); 675eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 676eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 677eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void show_ss_normal(struct thread_stat *ts, struct buf_output *out) 678eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 679eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char *p1, *p1alt, *p2; 680eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned long long bw_mean, iops_mean; 681eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes const int i2p = is_power_of_2(ts->kb_base); 682eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 683eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!ts->ss_dur) 684eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return; 685eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 686eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw_mean = steadystate_bw_mean(ts); 687eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iops_mean = steadystate_iops_mean(ts); 688eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 689eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes p1 = num2str(bw_mean / ts->kb_base, 4, ts->kb_base, i2p, ts->unit_base); 690eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes p1alt = num2str(bw_mean / ts->kb_base, 4, ts->kb_base, !i2p, ts->unit_base); 691eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes p2 = num2str(iops_mean, 4, 1, 0, N2S_NONE); 692eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 693eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " steadystate : attained=%s, bw=%s (%s), iops=%s, %s%s=%.3f%s\n", 694eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state & __FIO_SS_ATTAINED ? "yes" : "no", 695eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes p1, p1alt, p2, 696eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state & __FIO_SS_IOPS ? "iops" : "bw", 697eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state & __FIO_SS_SLOPE ? " slope": " mean dev", 698eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_criterion.u.f, 699eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state & __FIO_SS_PCT ? "%" : ""); 700eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 701eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(p1); 702eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(p1alt); 703eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(p2); 70404a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe} 70504a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe 70610aa136bddbaa7c845ab4eacb4a9a4a88d6657a3Jens Axboestatic void show_thread_status_normal(struct thread_stat *ts, 707eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct group_run_stats *rs, 708eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct buf_output *out) 7093c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 7103c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe double usr_cpu, sys_cpu; 711690089990d051d86b4ef2b6fd5c1972c0dd4897bJens Axboe unsigned long runtime; 71271619dc28506f7b7b40905b942e992b02f0d5b96Jens Axboe double io_u_dist[FIO_IO_U_MAP_NR]; 71357a64324184090fdc9f5052a6a34ab2b42359a22Jens Axboe time_t time_p; 714ffb17c0048ff2e4ba97478152729d1f011057d0fJens Axboe char time_buf[32]; 7153c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 716e93fd530b57b2cd4bf8205d557c509dbdb2a69ccJens Axboe if (!ddir_rw_sum(ts->io_bytes) && !ddir_rw_sum(ts->total_io_u)) 7173c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe return; 718eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 719eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes memset(time_buf, 0, sizeof(time_buf)); 7203c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 72157a64324184090fdc9f5052a6a34ab2b42359a22Jens Axboe time(&time_p); 72245054cbec0e624de3b79a795d7dfe1c64cdea934Saurabh De os_ctime_r((const time_t *) &time_p, time_buf, sizeof(time_buf)); 72357a64324184090fdc9f5052a6a34ab2b42359a22Jens Axboe 7245ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe if (!ts->error) { 725eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "%s: (groupid=%d, jobs=%d): err=%2d: pid=%d: %s", 7265ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe ts->name, ts->groupid, ts->members, 72757a64324184090fdc9f5052a6a34ab2b42359a22Jens Axboe ts->error, (int) ts->pid, time_buf); 7285ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe } else { 729eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "%s: (groupid=%d, jobs=%d): err=%2d (%s): pid=%d: %s", 7305ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe ts->name, ts->groupid, ts->members, 73157a64324184090fdc9f5052a6a34ab2b42359a22Jens Axboe ts->error, ts->verror, (int) ts->pid, 73257a64324184090fdc9f5052a6a34ab2b42359a22Jens Axboe time_buf); 7335ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe } 7343c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 735259e47dea8db94a372a73b07b5245d43d4f9ab92Jens Axboe if (strlen(ts->description)) 736eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " Description : [%s]\n", ts->description); 7377bdce1bde82e37c8876270853840c1d09d760b67Jens Axboe 738756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe if (ts->io_bytes[DDIR_READ]) 739eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status(rs, ts, DDIR_READ, out); 740756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe if (ts->io_bytes[DDIR_WRITE]) 741eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status(rs, ts, DDIR_WRITE, out); 7426eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li if (ts->io_bytes[DDIR_TRIM]) 743eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status(rs, ts, DDIR_TRIM, out); 7443c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 745eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_latencies(ts, out); 7467e1773ba2033a2f70bcbb36c07dc8743c6ce05d1Jens Axboe 747756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe runtime = ts->total_run_time; 748690089990d051d86b4ef2b6fd5c1972c0dd4897bJens Axboe if (runtime) { 7491e97cce9f5a87a67293a05ec4533ed6968698b2eJens Axboe double runt = (double) runtime; 7503c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 751756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe usr_cpu = (double) ts->usr_time * 100 / runt; 752756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe sys_cpu = (double) ts->sys_time * 100 / runt; 7533c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe } else { 7543c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe usr_cpu = 0; 7553c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe sys_cpu = 0; 7563c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe } 7573c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 758eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " cpu : usr=%3.2f%%, sys=%3.2f%%, ctx=%llu," 7594e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe " majf=%llu, minf=%llu\n", usr_cpu, sys_cpu, 7604e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->ctx, 7614e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->majf, 7624e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->minf); 76371619dc28506f7b7b40905b942e992b02f0d5b96Jens Axboe 764d79db1222039e906dd49ae290daa59701f4e2385Jens Axboe stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); 765eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " IO depths : 1=%3.1f%%, 2=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%," 7665ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe " 16=%3.1f%%, 32=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], 7675ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe io_u_dist[1], io_u_dist[2], 7685ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe io_u_dist[3], io_u_dist[4], 7695ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe io_u_dist[5], io_u_dist[6]); 770838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe 771838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe stat_calc_dist(ts->io_u_submit, ts->total_submit, io_u_dist); 772eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " submit : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," 773838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], 774838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[1], io_u_dist[2], 775838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[3], io_u_dist[4], 776838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[5], io_u_dist[6]); 777838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe stat_calc_dist(ts->io_u_complete, ts->total_complete, io_u_dist); 778eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " complete : 0=%3.1f%%, 4=%3.1f%%, 8=%3.1f%%, 16=%3.1f%%," 779838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe " 32=%3.1f%%, 64=%3.1f%%, >=64=%3.1f%%\n", io_u_dist[0], 780838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[1], io_u_dist[2], 781838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[3], io_u_dist[4], 782838bc709279964bdcc64070d4eb2777a0f79bcbbJens Axboe io_u_dist[5], io_u_dist[6]); 783eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " issued rwt: total=%llu,%llu,%llu," 784eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes " short=%llu,%llu,%llu," 785eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes " dropped=%llu,%llu,%llu\n", 7864e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->total_io_u[0], 7874e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->total_io_u[1], 7884e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->total_io_u[2], 7894e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->short_io_u[0], 7904e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->short_io_u[1], 79167e149c4c2b580089287813246344908770c3be9Jens Axboe (unsigned long long) ts->short_io_u[2], 79267e149c4c2b580089287813246344908770c3be9Jens Axboe (unsigned long long) ts->drop_io_u[0], 79367e149c4c2b580089287813246344908770c3be9Jens Axboe (unsigned long long) ts->drop_io_u[1], 79467e149c4c2b580089287813246344908770c3be9Jens Axboe (unsigned long long) ts->drop_io_u[2]); 795f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran if (ts->continue_on_error) { 796eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " errors : total=%llu, first_error=%d/<%s>\n", 7974e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long)ts->total_err_count, 7981ec99eea970609e63f49982f0d052a23ac18848dJens Axboe ts->first_error, 7991ec99eea970609e63f49982f0d052a23ac18848dJens Axboe strerror(ts->first_error)); 800f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran } 8013e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe if (ts->latency_depth) { 802eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, " latency : target=%llu, window=%llu, percentile=%.2f%%, depth=%u\n", 8033e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe (unsigned long long)ts->latency_target, 8043e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe (unsigned long long)ts->latency_window, 8053e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe ts->latency_percentile.u.f, 8063e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe ts->latency_depth); 8073e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe } 808eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 809eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (ts->nr_block_infos) 810eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_block_infos(ts->nr_block_infos, ts->block_infos, 811eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->percentile_list, out); 812eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 813eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (ts->ss_dur) 814eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ss_normal(ts, out); 8153c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 8163c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 817756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboestatic void show_ddir_status_terse(struct thread_stat *ts, 818eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct group_run_stats *rs, int ddir, 819eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct buf_output *out) 820c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe{ 821c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe unsigned long min, max; 822312b4af22018a73a445ae6ecf640d71f12120ab9Jens Axboe unsigned long long bw, iops; 8231db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe unsigned int *ovals = NULL; 824c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe double mean, dev; 8251db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe unsigned int len, minv, maxv; 8261db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe int i; 827c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 828ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe assert(ddir_rw(ddir)); 829ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe 830312b4af22018a73a445ae6ecf640d71f12120ab9Jens Axboe iops = bw = 0; 831312b4af22018a73a445ae6ecf640d71f12120ab9Jens Axboe if (ts->runtime[ddir]) { 832312b4af22018a73a445ae6ecf640d71f12120ab9Jens Axboe uint64_t runt = ts->runtime[ddir]; 833312b4af22018a73a445ae6ecf640d71f12120ab9Jens Axboe 834eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; /* KiB/s */ 835312b4af22018a73a445ae6ecf640d71f12120ab9Jens Axboe iops = (1000 * (uint64_t) ts->total_io_u[ddir]) / runt; 836312b4af22018a73a445ae6ecf640d71f12120ab9Jens Axboe } 837c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 838eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%llu;%llu;%llu;%llu", 8394e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->io_bytes[ddir] >> 10, bw, iops, 8404e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->runtime[ddir]); 841c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 842079ad09b1ef22fa0d47c2cd2673908c5619aa41aJens Axboe if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) 843eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%lu;%lu;%f;%f", min, max, mean, dev); 844c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe else 845eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); 846c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 847079ad09b1ef22fa0d47c2cd2673908c5619aa41aJens Axboe if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) 848eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%lu;%lu;%f;%f", min, max, mean, dev); 849c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe else 850eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); 851c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 8521db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe if (ts->clat_percentiles) { 8531db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe len = calc_clat_percentiles(ts->io_u_plat[ddir], 8541db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe ts->clat_stat[ddir].samples, 8551db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe ts->percentile_list, &ovals, &maxv, 8561db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe &minv); 8571db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe } else 8581db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe len = 0; 8591db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe 8601db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { 8611db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe if (i >= len) { 862eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";0%%=0"); 8631db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe continue; 8641db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe } 865eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%f%%=%u", ts->percentile_list[i].u.f, ovals[i]); 8661db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe } 8672341a37a2df4bca221d5ea25aa7d8a8307407d1aKeplar kramer 8682341a37a2df4bca221d5ea25aa7d8a8307407d1aKeplar kramer if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) 869eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%lu;%lu;%f;%f", min, max, mean, dev); 8702341a37a2df4bca221d5ea25aa7d8a8307407d1aKeplar kramer else 871eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%lu;%lu;%f;%f", 0UL, 0UL, 0.0, 0.0); 8722341a37a2df4bca221d5ea25aa7d8a8307407d1aKeplar kramer 8731db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe if (ovals) 8741db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe free(ovals); 8751db92cb6b3db5965a52359cb2dab7ebd3f476f53Jens Axboe 876079ad09b1ef22fa0d47c2cd2673908c5619aa41aJens Axboe if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { 87719d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe double p_of_agg = 100.0; 87819d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe 87919d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe if (rs->agg[ddir]) { 88019d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe p_of_agg = mean * 100 / (double) rs->agg[ddir]; 88119d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe if (p_of_agg > 100.0) 88219d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe p_of_agg = 100.0; 88319d3e967ff31c055c1497dd67f4d7305ec1607f4Jens Axboe } 884c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 885eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%lu;%lu;%f%%;%f;%f", min, max, p_of_agg, mean, dev); 886c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe } else 887eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%lu;%lu;%f%%;%f;%f", 0UL, 0UL, 0.0, 0.0, 0.0); 888c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe} 889c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 890cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Listatic void add_ddir_status_json(struct thread_stat *ts, 891cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li struct group_run_stats *rs, int ddir, struct json_object *parent) 892cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li{ 893cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li unsigned long min, max; 894ff0dbe14c236da5b0e4ab68bc65e1ac6fbeb1ce8Ben England unsigned long long bw; 895cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li unsigned int *ovals = NULL; 896ff0dbe14c236da5b0e4ab68bc65e1ac6fbeb1ce8Ben England double mean, dev, iops; 897cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li unsigned int len, minv, maxv; 898cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li int i; 899cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li const char *ddirname[] = {"read", "write", "trim"}; 900eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct json_object *dir_object, *tmp_object, *percentile_object, *clat_bins_object; 901cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li char buf[120]; 902cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li double p_of_agg = 100.0; 903cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 904cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li assert(ddir_rw(ddir)); 905cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 906771e58befea806d2d881953050c4e65329eee382Jens Axboe if (ts->unified_rw_rep && ddir != DDIR_READ) 907771e58befea806d2d881953050c4e65329eee382Jens Axboe return; 908771e58befea806d2d881953050c4e65329eee382Jens Axboe 909cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li dir_object = json_create_object(); 910771e58befea806d2d881953050c4e65329eee382Jens Axboe json_object_add_value_object(parent, 911771e58befea806d2d881953050c4e65329eee382Jens Axboe ts->unified_rw_rep ? "mixed" : ddirname[ddir], dir_object); 912cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 913ff0dbe14c236da5b0e4ab68bc65e1ac6fbeb1ce8Ben England bw = 0; 914ff0dbe14c236da5b0e4ab68bc65e1ac6fbeb1ce8Ben England iops = 0.0; 915cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (ts->runtime[ddir]) { 916cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li uint64_t runt = ts->runtime[ddir]; 917cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 918eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw = ((1000 * ts->io_bytes[ddir]) / runt) / 1024; /* KiB/s */ 919ff0dbe14c236da5b0e4ab68bc65e1ac6fbeb1ce8Ben England iops = (1000.0 * (uint64_t) ts->total_io_u[ddir]) / runt; 920cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 921cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 922cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(dir_object, "io_bytes", ts->io_bytes[ddir] >> 10); 923cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(dir_object, "bw", bw); 924ff0dbe14c236da5b0e4ab68bc65e1ac6fbeb1ce8Ben England json_object_add_value_float(dir_object, "iops", iops); 925cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(dir_object, "runtime", ts->runtime[ddir]); 926e93fd530b57b2cd4bf8205d557c509dbdb2a69ccJens Axboe json_object_add_value_int(dir_object, "total_ios", ts->total_io_u[ddir]); 927e93fd530b57b2cd4bf8205d557c509dbdb2a69ccJens Axboe json_object_add_value_int(dir_object, "short_ios", ts->short_io_u[ddir]); 928e93fd530b57b2cd4bf8205d557c509dbdb2a69ccJens Axboe json_object_add_value_int(dir_object, "drop_ios", ts->drop_io_u[ddir]); 929cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 930cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (!calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev)) { 931cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li min = max = 0; 932cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li mean = dev = 0.0; 933cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 934cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li tmp_object = json_create_object(); 935cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_object(dir_object, "slat", tmp_object); 936cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(tmp_object, "min", min); 937cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(tmp_object, "max", max); 938cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp_object, "mean", mean); 939cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp_object, "stddev", dev); 940cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 941cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (!calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev)) { 942cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li min = max = 0; 943cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li mean = dev = 0.0; 944cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 945cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li tmp_object = json_create_object(); 946cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_object(dir_object, "clat", tmp_object); 947cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(tmp_object, "min", min); 948cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(tmp_object, "max", max); 949cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp_object, "mean", mean); 950cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp_object, "stddev", dev); 951cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 952cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (ts->clat_percentiles) { 953cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li len = calc_clat_percentiles(ts->io_u_plat[ddir], 954cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li ts->clat_stat[ddir].samples, 955cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li ts->percentile_list, &ovals, &maxv, 956cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li &minv); 957cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } else 958cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li len = 0; 959cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 960cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li percentile_object = json_create_object(); 961cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_object(tmp_object, "percentile", percentile_object); 962cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li for (i = 0; i < FIO_IO_U_LIST_MAX_LEN; i++) { 963cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (i >= len) { 964cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(percentile_object, "0.00", 0); 965cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li continue; 966cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 967435d195a9da120c5a618129cdb73418f4748c20aVincent Kang Fu snprintf(buf, sizeof(buf), "%f", ts->percentile_list[i].u.f); 968cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(percentile_object, (const char *)buf, ovals[i]); 969cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 970cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 971eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_JSON_PLUS) { 972eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes clat_bins_object = json_create_object(); 973eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_object(tmp_object, "bins", clat_bins_object); 974eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for(i = 0; i < FIO_IO_U_PLAT_NR; i++) { 975eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (ts->io_u_plat[ddir][i]) { 976eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes snprintf(buf, sizeof(buf), "%llu", plat_idx_to_val(i)); 977eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(clat_bins_object, (const char *)buf, ts->io_u_plat[ddir][i]); 978eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 979eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 980eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 981eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 982cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (!calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev)) { 983cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li min = max = 0; 984cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li mean = dev = 0.0; 985cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 986cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li tmp_object = json_create_object(); 987cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_object(dir_object, "lat", tmp_object); 988cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(tmp_object, "min", min); 989cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(tmp_object, "max", max); 990cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp_object, "mean", mean); 991cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp_object, "stddev", dev); 992cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (ovals) 993cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li free(ovals); 994cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 995b9e1b49128450bcfd792165354b98026e3ac2734Shaohua Li if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) { 996cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (rs->agg[ddir]) { 997cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li p_of_agg = mean * 100 / (double) rs->agg[ddir]; 998cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (p_of_agg > 100.0) 999cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li p_of_agg = 100.0; 1000cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 1001cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } else { 1002cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li min = max = 0; 1003cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li p_of_agg = mean = dev = 0.0; 1004cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 1005cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(dir_object, "bw_min", min); 1006cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(dir_object, "bw_max", max); 1007a806bf2e054ca389a56130849a4394ac9d4334b6Erwan Velu json_object_add_value_float(dir_object, "bw_agg", p_of_agg); 1008cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(dir_object, "bw_mean", mean); 1009cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(dir_object, "bw_dev", dev); 1010cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li} 1011cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 10124d658652bac63fd72af8302e27deba5beb381906Jens Axboestatic void show_thread_status_terse_v2(struct thread_stat *ts, 1013eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct group_run_stats *rs, 1014eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct buf_output *out) 10154d658652bac63fd72af8302e27deba5beb381906Jens Axboe{ 10164d658652bac63fd72af8302e27deba5beb381906Jens Axboe double io_u_dist[FIO_IO_U_MAP_NR]; 10174d658652bac63fd72af8302e27deba5beb381906Jens Axboe double io_u_lat_u[FIO_IO_U_LAT_U_NR]; 10184d658652bac63fd72af8302e27deba5beb381906Jens Axboe double io_u_lat_m[FIO_IO_U_LAT_M_NR]; 10194d658652bac63fd72af8302e27deba5beb381906Jens Axboe double usr_cpu, sys_cpu; 10204d658652bac63fd72af8302e27deba5beb381906Jens Axboe int i; 10214d658652bac63fd72af8302e27deba5beb381906Jens Axboe 10224d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* General Info */ 1023eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "2;%s;%d;%d", ts->name, ts->groupid, ts->error); 10244d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* Log Read Status */ 1025eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status_terse(ts, rs, DDIR_READ, out); 10264d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* Log Write Status */ 1027eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status_terse(ts, rs, DDIR_WRITE, out); 10286eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li /* Log Trim Status */ 1029eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status_terse(ts, rs, DDIR_TRIM, out); 10304d658652bac63fd72af8302e27deba5beb381906Jens Axboe 10314d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* CPU Usage */ 10324d658652bac63fd72af8302e27deba5beb381906Jens Axboe if (ts->total_run_time) { 10334d658652bac63fd72af8302e27deba5beb381906Jens Axboe double runt = (double) ts->total_run_time; 10344d658652bac63fd72af8302e27deba5beb381906Jens Axboe 10354d658652bac63fd72af8302e27deba5beb381906Jens Axboe usr_cpu = (double) ts->usr_time * 100 / runt; 10364d658652bac63fd72af8302e27deba5beb381906Jens Axboe sys_cpu = (double) ts->sys_time * 100 / runt; 10374d658652bac63fd72af8302e27deba5beb381906Jens Axboe } else { 10384d658652bac63fd72af8302e27deba5beb381906Jens Axboe usr_cpu = 0; 10394d658652bac63fd72af8302e27deba5beb381906Jens Axboe sys_cpu = 0; 10404d658652bac63fd72af8302e27deba5beb381906Jens Axboe } 10414d658652bac63fd72af8302e27deba5beb381906Jens Axboe 1042eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%f%%;%f%%;%llu;%llu;%llu", usr_cpu, sys_cpu, 10434e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->ctx, 10444e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->majf, 10454e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->minf); 10464d658652bac63fd72af8302e27deba5beb381906Jens Axboe 10474d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* Calc % distribution of IO depths, usecond, msecond latency */ 1048d79db1222039e906dd49ae290daa59701f4e2385Jens Axboe stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); 10494d658652bac63fd72af8302e27deba5beb381906Jens Axboe stat_calc_lat_u(ts, io_u_lat_u); 10504d658652bac63fd72af8302e27deba5beb381906Jens Axboe stat_calc_lat_m(ts, io_u_lat_m); 10514d658652bac63fd72af8302e27deba5beb381906Jens Axboe 10524d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* Only show fixed 7 I/O depth levels*/ 1053eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", 10544d658652bac63fd72af8302e27deba5beb381906Jens Axboe io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], 10554d658652bac63fd72af8302e27deba5beb381906Jens Axboe io_u_dist[4], io_u_dist[5], io_u_dist[6]); 10564d658652bac63fd72af8302e27deba5beb381906Jens Axboe 10574d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* Microsecond latency */ 10584d658652bac63fd72af8302e27deba5beb381906Jens Axboe for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) 1059eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%3.2f%%", io_u_lat_u[i]); 10604d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* Millisecond latency */ 10614d658652bac63fd72af8302e27deba5beb381906Jens Axboe for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) 1062eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%3.2f%%", io_u_lat_m[i]); 10634d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* Additional output if continue_on_error set - default off*/ 10644d658652bac63fd72af8302e27deba5beb381906Jens Axboe if (ts->continue_on_error) 1065eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%llu;%d", (unsigned long long) ts->total_err_count, ts->first_error); 1066eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "\n"); 10674d658652bac63fd72af8302e27deba5beb381906Jens Axboe 10684d658652bac63fd72af8302e27deba5beb381906Jens Axboe /* Additional output if description is set */ 10690a3c52f0875c85b6750239a8b65bfe230d28df35Jens Axboe if (strlen(ts->description)) 1070eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%s", ts->description); 10714d658652bac63fd72af8302e27deba5beb381906Jens Axboe 1072eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "\n"); 10734d658652bac63fd72af8302e27deba5beb381906Jens Axboe} 10744d658652bac63fd72af8302e27deba5beb381906Jens Axboe 10753449ab8c4d2addb716105ded698438a1d3811572Jens Axboestatic void show_thread_status_terse_v3_v4(struct thread_stat *ts, 1076eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct group_run_stats *rs, int ver, 1077eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct buf_output *out) 1078c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe{ 10792270890cef8d98ab97f87d348d16dce6454e631fJens Axboe double io_u_dist[FIO_IO_U_MAP_NR]; 108004a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe double io_u_lat_u[FIO_IO_U_LAT_U_NR]; 108104a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe double io_u_lat_m[FIO_IO_U_LAT_M_NR]; 1082c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe double usr_cpu, sys_cpu; 108304a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe int i; 1084c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 1085562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* General Info */ 1086eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "%d;%s;%s;%d;%d", ver, fio_version_string, 10875e726d0a29b815f526f835e44afe3225522c6c20Jens Axboe ts->name, ts->groupid, ts->error); 1088562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* Log Read Status */ 1089eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status_terse(ts, rs, DDIR_READ, out); 1090562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* Log Write Status */ 1091eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status_terse(ts, rs, DDIR_WRITE, out); 10926eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li /* Log Trim Status */ 10933449ab8c4d2addb716105ded698438a1d3811572Jens Axboe if (ver == 4) 1094eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_ddir_status_terse(ts, rs, DDIR_TRIM, out); 1095c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 1096562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* CPU Usage */ 1097756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe if (ts->total_run_time) { 1098756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe double runt = (double) ts->total_run_time; 1099c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 1100756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe usr_cpu = (double) ts->usr_time * 100 / runt; 1101756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe sys_cpu = (double) ts->sys_time * 100 / runt; 1102c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe } else { 1103c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe usr_cpu = 0; 1104c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe sys_cpu = 0; 1105c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe } 1106c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe 1107eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%f%%;%f%%;%llu;%llu;%llu", usr_cpu, sys_cpu, 11084e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->ctx, 11094e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->majf, 11104e0a8fa2593006505b7f4e18931a201d221b49e9Jens Axboe (unsigned long long) ts->minf); 11112270890cef8d98ab97f87d348d16dce6454e631fJens Axboe 1112562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* Calc % distribution of IO depths, usecond, msecond latency */ 1113d79db1222039e906dd49ae290daa59701f4e2385Jens Axboe stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); 111404a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe stat_calc_lat_u(ts, io_u_lat_u); 111504a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe stat_calc_lat_m(ts, io_u_lat_m); 11162270890cef8d98ab97f87d348d16dce6454e631fJens Axboe 1117562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* Only show fixed 7 I/O depth levels*/ 1118eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%;%3.1f%%", 11195ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe io_u_dist[0], io_u_dist[1], io_u_dist[2], io_u_dist[3], 11205ec10eaad3b09875b91e19a20bbdfa06f2117562Jens Axboe io_u_dist[4], io_u_dist[5], io_u_dist[6]); 11212270890cef8d98ab97f87d348d16dce6454e631fJens Axboe 1122562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* Microsecond latency */ 112304a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) 1124eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%3.2f%%", io_u_lat_u[i]); 1125562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* Millisecond latency */ 112604a0feae73ca50d05914cc3c425b2a6949523204Jens Axboe for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) 1127eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%3.2f%%", io_u_lat_m[i]); 1128f2f788dd732d97c2c3a5f5dd93223a7bfafcc410Jens Axboe 1129f2f788dd732d97c2c3a5f5dd93223a7bfafcc410Jens Axboe /* disk util stats, if any */ 1130eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_disk_util(1, NULL, out); 1131f2f788dd732d97c2c3a5f5dd93223a7bfafcc410Jens Axboe 1132562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* Additional output if continue_on_error set - default off*/ 1133f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran if (ts->continue_on_error) 1134eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%llu;%d", (unsigned long long) ts->total_err_count, ts->first_error); 11352270890cef8d98ab97f87d348d16dce6454e631fJens Axboe 1136562c2d2f25ae829c812a58c10bc1a03ab6f6f52bDavid Nellans /* Additional output if description is set */ 11374b0f22588568035952ea4c4673fdb1d7f5444eedJens Axboe if (strlen(ts->description)) 1138eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, ";%s", ts->description); 1139eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1140eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(out, "\n"); 1141eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 1142eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1143eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void json_add_job_opts(struct json_object *root, const char *name, 1144eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct flist_head *opt_list, bool num_jobs) 1145eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 1146eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct json_object *dir_object; 1147eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct flist_head *entry; 1148eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct print_option *p; 1149eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1150eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (flist_empty(opt_list)) 1151eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return; 1152eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1153eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes dir_object = json_create_object(); 1154eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_object(root, name, dir_object); 1155946e42764c6cc536d42e55acbf2fa8bc424124bdJens Axboe 1156eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes flist_for_each(entry, opt_list) { 1157eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes const char *pos = ""; 1158eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1159eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes p = flist_entry(entry, struct print_option, list); 1160eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!num_jobs && !strcmp(p->name, "numjobs")) 1161eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes continue; 1162eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (p->value) 1163eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes pos = p->value; 1164eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_string(dir_object, p->name, pos); 1165eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1166756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe} 1167756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1168cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Listatic struct json_object *show_thread_status_json(struct thread_stat *ts, 1169eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct group_run_stats *rs, 1170eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct flist_head *opt_list) 1171cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li{ 1172cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li struct json_object *root, *tmp; 1173eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct jobs_eta *je; 1174cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li double io_u_dist[FIO_IO_U_MAP_NR]; 1175cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li double io_u_lat_u[FIO_IO_U_LAT_U_NR]; 1176cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li double io_u_lat_m[FIO_IO_U_LAT_M_NR]; 1177cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li double usr_cpu, sys_cpu; 1178cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li int i; 1179eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes size_t size; 1180cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1181cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li root = json_create_object(); 1182cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_string(root, "jobname", ts->name); 1183cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(root, "groupid", ts->groupid); 1184cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(root, "error", ts->error); 1185cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1186eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* ETA Info */ 1187eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes je = get_jobs_eta(true, &size); 1188eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (je) { 1189eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(root, "eta", je->eta_sec); 1190eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(root, "elapsed", je->elapsed_sec); 1191eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1192eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1193eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (opt_list) 1194eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_add_job_opts(root, "job options", opt_list, true); 1195eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1196cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li add_ddir_status_json(ts, rs, DDIR_READ, root); 1197cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li add_ddir_status_json(ts, rs, DDIR_WRITE, root); 1198f3afa57e36550288340f1b6c694f354ae72654b9Jens Axboe add_ddir_status_json(ts, rs, DDIR_TRIM, root); 1199cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1200cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li /* CPU Usage */ 1201cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (ts->total_run_time) { 1202cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li double runt = (double) ts->total_run_time; 1203cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1204cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li usr_cpu = (double) ts->usr_time * 100 / runt; 1205cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li sys_cpu = (double) ts->sys_time * 100 / runt; 1206cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } else { 1207cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li usr_cpu = 0; 1208cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li sys_cpu = 0; 1209cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 1210cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(root, "usr_cpu", usr_cpu); 1211cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(root, "sys_cpu", sys_cpu); 1212cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(root, "ctx", ts->ctx); 1213cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(root, "majf", ts->majf); 1214cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(root, "minf", ts->minf); 1215cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1216cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1217cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li /* Calc % distribution of IO depths, usecond, msecond latency */ 1218d79db1222039e906dd49ae290daa59701f4e2385Jens Axboe stat_calc_dist(ts->io_u_map, ddir_rw_sum(ts->total_io_u), io_u_dist); 1219cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li stat_calc_lat_u(ts, io_u_lat_u); 1220cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li stat_calc_lat_m(ts, io_u_lat_m); 1221cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1222cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li tmp = json_create_object(); 1223cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_object(root, "iodepth_level", tmp); 1224cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li /* Only show fixed 7 I/O depth levels*/ 1225cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li for (i = 0; i < 7; i++) { 1226cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li char name[20]; 1227cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (i < 6) 122898ffb8f3ecebed9984d1744f142eb8be10c14dbdKen Raeburn snprintf(name, 20, "%d", 1 << i); 1229cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li else 123098ffb8f3ecebed9984d1744f142eb8be10c14dbdKen Raeburn snprintf(name, 20, ">=%d", 1 << i); 1231cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp, (const char *)name, io_u_dist[i]); 1232cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 1233cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1234cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li tmp = json_create_object(); 1235cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_object(root, "latency_us", tmp); 1236cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li /* Microsecond latency */ 1237cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) { 1238cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li const char *ranges[] = { "2", "4", "10", "20", "50", "100", 1239cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li "250", "500", "750", "1000", }; 1240cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp, ranges[i], io_u_lat_u[i]); 1241cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 1242cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li /* Millisecond latency */ 1243cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li tmp = json_create_object(); 1244cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_object(root, "latency_ms", tmp); 1245cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) { 1246cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li const char *ranges[] = { "2", "4", "10", "20", "50", "100", 1247cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li "250", "500", "750", "1000", "2000", 1248cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li ">=2000", }; 1249cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_float(tmp, ranges[i], io_u_lat_m[i]); 1250cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 1251cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1252cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li /* Additional output if continue_on_error set - default off*/ 1253cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (ts->continue_on_error) { 1254cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_int(root, "total_err", ts->total_err_count); 1255952b05e00103bf45576e1860cde0626bd42ed52aCastor Fu json_object_add_value_int(root, "first_error", ts->first_error); 1256cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 1257cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 12583e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe if (ts->latency_depth) { 12593e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe json_object_add_value_int(root, "latency_depth", ts->latency_depth); 12603e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe json_object_add_value_int(root, "latency_target", ts->latency_target); 12613e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe json_object_add_value_float(root, "latency_percentile", ts->latency_percentile.u.f); 12623e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe json_object_add_value_int(root, "latency_window", ts->latency_window); 12633e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe } 12643e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe 1265cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li /* Additional output if description is set */ 1266cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li if (strlen(ts->description)) 1267cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_string(root, "desc", ts->description); 1268cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1269eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (ts->nr_block_infos) { 1270eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* Block error histogram and types */ 1271eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int len; 1272eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int *percentiles = NULL; 1273eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int block_state_counts[BLOCK_STATE_COUNT]; 1274eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1275eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes len = calc_block_percentiles(ts->nr_block_infos, ts->block_infos, 1276eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->percentile_list, 1277eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes &percentiles, block_state_counts); 1278eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1279eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (len) { 1280eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct json_object *block, *percentile_object, *states; 1281eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int state; 1282eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes block = json_create_object(); 1283eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_object(root, "block", block); 1284eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1285eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes percentile_object = json_create_object(); 1286eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_object(block, "percentiles", 1287eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes percentile_object); 1288eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < len; i++) { 1289eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char buf[20]; 1290eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes snprintf(buf, sizeof(buf), "%f", 1291eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->percentile_list[i].u.f); 1292eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(percentile_object, 1293eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes (const char *)buf, 1294eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes percentiles[i]); 1295eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1296eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1297eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes states = json_create_object(); 1298eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_object(block, "states", states); 1299eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (state = 0; state < BLOCK_STATE_COUNT; state++) { 1300eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(states, 1301eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes block_state_names[state], 1302eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes block_state_counts[state]); 1303eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1304eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(percentiles); 1305eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1306eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1307eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1308eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (ts->ss_dur) { 1309eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct json_object *data; 1310eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct json_array *iops, *bw; 1311eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int i, j, k; 1312eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes char ss_buf[64]; 1313eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1314eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes snprintf(ss_buf, sizeof(ss_buf), "%s%s:%f%s", 1315eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state & __FIO_SS_IOPS ? "iops" : "bw", 1316eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state & __FIO_SS_SLOPE ? "_slope" : "", 1317eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes (float) ts->ss_limit.u.f, 1318eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state & __FIO_SS_PCT ? "%" : ""); 1319eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1320eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes tmp = json_create_object(); 1321eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_object(root, "steadystate", tmp); 1322eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_string(tmp, "ss", ss_buf); 1323eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(tmp, "duration", (int)ts->ss_dur); 1324eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(tmp, "attained", (ts->ss_state & __FIO_SS_ATTAINED) > 0); 1325eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1326eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes snprintf(ss_buf, sizeof(ss_buf), "%f%s", (float) ts->ss_criterion.u.f, 1327eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state & __FIO_SS_PCT ? "%" : ""); 1328eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_string(tmp, "criterion", ss_buf); 1329eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_float(tmp, "max_deviation", ts->ss_deviation.u.f); 1330eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_float(tmp, "slope", ts->ss_slope.u.f); 1331eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1332eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes data = json_create_object(); 1333eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_object(tmp, "data", data); 1334eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw = json_create_array(); 1335eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iops = json_create_array(); 1336eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1337eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 1338eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ** if ss was attained or the buffer is not full, 1339eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ** ss->head points to the first element in the list. 1340eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ** otherwise it actually points to the second element 1341eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ** in the list 1342eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 1343eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if ((ts->ss_state & __FIO_SS_ATTAINED) || !(ts->ss_state & __FIO_SS_BUFFER_FULL)) 1344eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes j = ts->ss_head; 1345eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else 1346eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes j = ts->ss_head == 0 ? ts->ss_dur - 1 : ts->ss_head - 1; 1347eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < ts->ss_dur; i++) { 1348eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes k = (j + i) % ts->ss_dur; 1349eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_array_add_value_int(bw, ts->ss_bw_data[k]); 1350eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_array_add_value_int(iops, ts->ss_iops_data[k]); 1351eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1352eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(data, "bw_mean", steadystate_bw_mean(ts)); 1353eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(data, "iops_mean", steadystate_iops_mean(ts)); 1354eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_array(data, "iops", iops); 1355eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_array(data, "bw", bw); 1356eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1357eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1358cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li return root; 1359cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li} 1360cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 13614d658652bac63fd72af8302e27deba5beb381906Jens Axboestatic void show_thread_status_terse(struct thread_stat *ts, 1362eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct group_run_stats *rs, 1363eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct buf_output *out) 13644d658652bac63fd72af8302e27deba5beb381906Jens Axboe{ 13654d658652bac63fd72af8302e27deba5beb381906Jens Axboe if (terse_version == 2) 1366eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_thread_status_terse_v2(ts, rs, out); 13673449ab8c4d2addb716105ded698438a1d3811572Jens Axboe else if (terse_version == 3 || terse_version == 4) 1368eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_thread_status_terse_v3_v4(ts, rs, terse_version, out); 13694d658652bac63fd72af8302e27deba5beb381906Jens Axboe else 13704d658652bac63fd72af8302e27deba5beb381906Jens Axboe log_err("fio: bad terse version!? %d\n", terse_version); 13714d658652bac63fd72af8302e27deba5beb381906Jens Axboe} 13724d658652bac63fd72af8302e27deba5beb381906Jens Axboe 1373952b05e00103bf45576e1860cde0626bd42ed52aCastor Fustruct json_object *show_thread_status(struct thread_stat *ts, 1374eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct group_run_stats *rs, 1375eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct flist_head *opt_list, 1376eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct buf_output *out) 1377952b05e00103bf45576e1860cde0626bd42ed52aCastor Fu{ 1378eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct json_object *ret = NULL; 1379eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1380eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_TERSE) 1381eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_thread_status_terse(ts, rs, out); 1382eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_JSON) 1383eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ret = show_thread_status_json(ts, rs, opt_list); 1384eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_NORMAL) 1385eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_thread_status_normal(ts, rs, out); 1386eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1387eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return ret; 1388952b05e00103bf45576e1860cde0626bd42ed52aCastor Fu} 1389952b05e00103bf45576e1860cde0626bd42ed52aCastor Fu 1390eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void sum_stat(struct io_stat *dst, struct io_stat *src, bool first) 1391756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe{ 1392756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe double mean, S; 1393756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1394e09231c214906b4ff8cbc3dc202c39755fbf6afdZheng Liu if (src->samples == 0) 1395e09231c214906b4ff8cbc3dc202c39755fbf6afdZheng Liu return; 1396e09231c214906b4ff8cbc3dc202c39755fbf6afdZheng Liu 1397756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe dst->min_val = min(dst->min_val, src->min_val); 1398756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe dst->max_val = max(dst->max_val, src->max_val); 1399756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1400756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe /* 1401cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong * Compute new mean and S after the merge 1402cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong * <http://en.wikipedia.org/wiki/Algorithms_for_calculating_variance 1403cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong * #Parallel_algorithm> 1404756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe */ 1405eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (first) { 1406802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe mean = src->mean.u.f; 1407802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe S = src->S.u.f; 1408756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe } else { 1409802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe double delta = src->mean.u.f - dst->mean.u.f; 1410cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong 1411802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe mean = ((src->mean.u.f * src->samples) + 1412802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe (dst->mean.u.f * dst->samples)) / 1413cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong (dst->samples + src->samples); 1414cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong 1415802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe S = src->S.u.f + dst->S.u.f + pow(delta, 2.0) * 1416cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong (dst->samples * src->samples) / 1417cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong (dst->samples + src->samples); 1418756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe } 1419756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1420cdcac5cf0e9262105e676874d11c4639a80574ebYu-ju Hong dst->samples += src->samples; 1421802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe dst->mean.u.f = mean; 1422802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe dst->S.u.f = S; 1423756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe} 1424756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 142537f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboevoid sum_group_stats(struct group_run_stats *dst, struct group_run_stats *src) 142637f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe{ 142737f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe int i; 142837f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe 14296eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (i = 0; i < DDIR_RWDIR_CNT; i++) { 143037f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe if (dst->max_run[i] < src->max_run[i]) 143137f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe dst->max_run[i] = src->max_run[i]; 143237f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe if (dst->min_run[i] && dst->min_run[i] > src->min_run[i]) 143337f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe dst->min_run[i] = src->min_run[i]; 143437f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe if (dst->max_bw[i] < src->max_bw[i]) 143537f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe dst->max_bw[i] = src->max_bw[i]; 143637f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe if (dst->min_bw[i] && dst->min_bw[i] > src->min_bw[i]) 143737f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe dst->min_bw[i] = src->min_bw[i]; 143837f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe 1439eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes dst->iobytes[i] += src->iobytes[i]; 144037f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe dst->agg[i] += src->agg[i]; 144137f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe } 144237f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe 1443c2d6668d35e9bdc0a56311fcc769f8eb00f62727Jens Axboe if (!dst->kb_base) 1444c2d6668d35e9bdc0a56311fcc769f8eb00f62727Jens Axboe dst->kb_base = src->kb_base; 1445c2d6668d35e9bdc0a56311fcc769f8eb00f62727Jens Axboe if (!dst->unit_base) 1446c2d6668d35e9bdc0a56311fcc769f8eb00f62727Jens Axboe dst->unit_base = src->unit_base; 144737f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe} 144837f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe 1449eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesvoid sum_thread_stats(struct thread_stat *dst, struct thread_stat *src, 1450eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bool first) 14515b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe{ 14525b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe int l, k; 14535b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe 14546eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (l = 0; l < DDIR_RWDIR_CNT; l++) { 1455771e58befea806d2d881953050c4e65329eee382Jens Axboe if (!dst->unified_rw_rep) { 1456eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_stat(&dst->clat_stat[l], &src->clat_stat[l], first); 1457eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_stat(&dst->slat_stat[l], &src->slat_stat[l], first); 1458eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_stat(&dst->lat_stat[l], &src->lat_stat[l], first); 1459eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_stat(&dst->bw_stat[l], &src->bw_stat[l], first); 1460771e58befea806d2d881953050c4e65329eee382Jens Axboe 1461771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->io_bytes[l] += src->io_bytes[l]; 1462771e58befea806d2d881953050c4e65329eee382Jens Axboe 1463771e58befea806d2d881953050c4e65329eee382Jens Axboe if (dst->runtime[l] < src->runtime[l]) 1464771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->runtime[l] = src->runtime[l]; 1465771e58befea806d2d881953050c4e65329eee382Jens Axboe } else { 1466eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_stat(&dst->clat_stat[0], &src->clat_stat[l], first); 1467eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_stat(&dst->slat_stat[0], &src->slat_stat[l], first); 1468eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_stat(&dst->lat_stat[0], &src->lat_stat[l], first); 1469eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_stat(&dst->bw_stat[0], &src->bw_stat[l], first); 1470771e58befea806d2d881953050c4e65329eee382Jens Axboe 1471771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->io_bytes[0] += src->io_bytes[l]; 1472771e58befea806d2d881953050c4e65329eee382Jens Axboe 1473771e58befea806d2d881953050c4e65329eee382Jens Axboe if (dst->runtime[0] < src->runtime[l]) 1474771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->runtime[0] = src->runtime[l]; 1475eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1476eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 1477eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * We're summing to the same destination, so override 1478eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * 'first' after the first iteration of the loop 1479eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 1480eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes first = false; 1481771e58befea806d2d881953050c4e65329eee382Jens Axboe } 14825b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe } 14835b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe 14845b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->usr_time += src->usr_time; 14855b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->sys_time += src->sys_time; 14865b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->ctx += src->ctx; 14875b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->majf += src->majf; 14885b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->minf += src->minf; 14895b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe 14905b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe for (k = 0; k < FIO_IO_U_MAP_NR; k++) 14915b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->io_u_map[k] += src->io_u_map[k]; 14925b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe for (k = 0; k < FIO_IO_U_MAP_NR; k++) 14935b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->io_u_submit[k] += src->io_u_submit[k]; 14945b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe for (k = 0; k < FIO_IO_U_MAP_NR; k++) 14955b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->io_u_complete[k] += src->io_u_complete[k]; 14965b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe for (k = 0; k < FIO_IO_U_LAT_U_NR; k++) 14975b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->io_u_lat_u[k] += src->io_u_lat_u[k]; 14985b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe for (k = 0; k < FIO_IO_U_LAT_M_NR; k++) 14995b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->io_u_lat_m[k] += src->io_u_lat_m[k]; 15005b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe 15016eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (k = 0; k < DDIR_RWDIR_CNT; k++) { 1502771e58befea806d2d881953050c4e65329eee382Jens Axboe if (!dst->unified_rw_rep) { 1503771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->total_io_u[k] += src->total_io_u[k]; 1504771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->short_io_u[k] += src->short_io_u[k]; 150567e149c4c2b580089287813246344908770c3be9Jens Axboe dst->drop_io_u[k] += src->drop_io_u[k]; 1506771e58befea806d2d881953050c4e65329eee382Jens Axboe } else { 1507771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->total_io_u[0] += src->total_io_u[k]; 1508771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->short_io_u[0] += src->short_io_u[k]; 150967e149c4c2b580089287813246344908770c3be9Jens Axboe dst->drop_io_u[0] += src->drop_io_u[k]; 1510771e58befea806d2d881953050c4e65329eee382Jens Axboe } 15115b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe } 15125b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe 15136eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (k = 0; k < DDIR_RWDIR_CNT; k++) { 15145b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe int m; 1515771e58befea806d2d881953050c4e65329eee382Jens Axboe 1516771e58befea806d2d881953050c4e65329eee382Jens Axboe for (m = 0; m < FIO_IO_U_PLAT_NR; m++) { 1517771e58befea806d2d881953050c4e65329eee382Jens Axboe if (!dst->unified_rw_rep) 1518771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->io_u_plat[k][m] += src->io_u_plat[k][m]; 1519771e58befea806d2d881953050c4e65329eee382Jens Axboe else 1520771e58befea806d2d881953050c4e65329eee382Jens Axboe dst->io_u_plat[0][m] += src->io_u_plat[k][m]; 1521771e58befea806d2d881953050c4e65329eee382Jens Axboe } 15225b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe } 15235b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe 15245b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->total_run_time += src->total_run_time; 15255b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->total_submit += src->total_submit; 15265b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe dst->total_complete += src->total_complete; 15275b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe} 15285b9babb7fb9ac46c0e960ccd88c2d85ba3065c01Jens Axboe 152937f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboevoid init_group_run_stat(struct group_run_stats *gs) 153037f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe{ 15316eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li int i; 153237f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe memset(gs, 0, sizeof(*gs)); 15336eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li 15346eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (i = 0; i < DDIR_RWDIR_CNT; i++) 15356eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li gs->min_bw[i] = gs->min_run[i] = ~0UL; 153637f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe} 153737f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe 153837f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboevoid init_thread_stat(struct thread_stat *ts) 153937f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe{ 154037f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe int j; 154137f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe 154237f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe memset(ts, 0, sizeof(*ts)); 154337f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe 15446eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (j = 0; j < DDIR_RWDIR_CNT; j++) { 154537f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe ts->lat_stat[j].min_val = -1UL; 154637f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe ts->clat_stat[j].min_val = -1UL; 154737f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe ts->slat_stat[j].min_val = -1UL; 154837f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe ts->bw_stat[j].min_val = -1UL; 154937f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe } 155037f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe ts->groupid = -1; 155137f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe} 155237f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe 15532e627243f7877cefb3606ef99ec24debe32ac98cJens Axboevoid __show_run_stats(void) 15543c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 15553c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe struct group_run_stats *runstats, *rs; 15563c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe struct thread_data *td; 1557756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe struct thread_stat *threadstats, *ts; 1558eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int i, j, k, nr_ts, last_ts, idx; 155990fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe int kb_base_warned = 0; 1560ad705bcb7e79a7cdb9891db17b4c40b13b6c30c3Steven Noonan int unit_base_warned = 0; 1561cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li struct json_object *root = NULL; 1562cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li struct json_array *array = NULL; 1563eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct buf_output output[FIO_OUTPUT_NR]; 1564eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct flist_head **opt_lists; 1565eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 15663c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe runstats = malloc(sizeof(struct group_run_stats) * (groupid + 1)); 15673c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 156837f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe for (i = 0; i < groupid + 1; i++) 156937f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe init_group_run_stat(&runstats[i]); 15703c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 1571756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe /* 1572756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe * find out how many threads stats we need. if group reporting isn't 1573756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe * enabled, it's one-per-td. 1574756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe */ 1575756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe nr_ts = 0; 1576756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe last_ts = -1; 1577756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe for_each_td(td, i) { 15782dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe if (!td->o.group_reporting) { 1579756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe nr_ts++; 1580756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe continue; 1581756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe } 1582756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe if (last_ts == td->groupid) 1583756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe continue; 1584eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!td->o.stats) 1585eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes continue; 1586756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1587756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe last_ts = td->groupid; 1588756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe nr_ts++; 1589756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe } 1590756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1591756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe threadstats = malloc(nr_ts * sizeof(struct thread_stat)); 1592eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes opt_lists = malloc(nr_ts * sizeof(struct flist_head *)); 1593756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1594eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < nr_ts; i++) { 159537f0c1ae23ad1716403d3d113c3dfdf41c47e329Jens Axboe init_thread_stat(&threadstats[i]); 1596eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes opt_lists[i] = NULL; 1597eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1598756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1599756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe j = 0; 1600756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe last_ts = -1; 1601197574e43bea5ac00f7b64d4731173c177041de0Jens Axboe idx = 0; 160234572e28f8cf45ba4e2601797f2aa4a114601fb2Jens Axboe for_each_td(td, i) { 1603eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!td->o.stats) 1604eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes continue; 16052dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe if (idx && (!td->o.group_reporting || 16062dc1bbeb58edc85f2829eed6729862c438ea2353Jens Axboe (td->o.group_reporting && last_ts != td->groupid))) { 16077abd0e3a872b000aefb740028f777aae1fa6f77dJens Axboe idx = 0; 16087abd0e3a872b000aefb740028f777aae1fa6f77dJens Axboe j++; 16097abd0e3a872b000aefb740028f777aae1fa6f77dJens Axboe } 16107abd0e3a872b000aefb740028f777aae1fa6f77dJens Axboe 16117abd0e3a872b000aefb740028f777aae1fa6f77dJens Axboe last_ts = td->groupid; 16127abd0e3a872b000aefb740028f777aae1fa6f77dJens Axboe 1613756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe ts = &threadstats[j]; 1614756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1615833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong ts->clat_percentiles = td->o.clat_percentiles; 1616435d195a9da120c5a618129cdb73418f4748c20aVincent Kang Fu ts->percentile_precision = td->o.percentile_precision; 1617fd112d34a2cfdc2d9efcd394e38b6d87b357c23dVincent Kang Fu memcpy(ts->percentile_list, td->o.percentile_list, sizeof(td->o.percentile_list)); 1618eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes opt_lists[j] = &td->opt_list; 1619833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 1620197574e43bea5ac00f7b64d4731173c177041de0Jens Axboe idx++; 16216586ee8992b30e81334d83d10480bdc4f6c8cc1aJens Axboe ts->members++; 1622756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 16237abd0e3a872b000aefb740028f777aae1fa6f77dJens Axboe if (ts->groupid == -1) { 16242dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe /* 16252dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe * These are per-group shared already 16262dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe */ 16274e59d0f3a3ff569bddb31fe6927a9faf204ae9bfJens Axboe strncpy(ts->name, td->o.name, FIO_JOBNAME_SIZE - 1); 1628a64e88dad0c0e4a510ae8ab54cde1a20b99c59d1Jens Axboe if (td->o.description) 1629a64e88dad0c0e4a510ae8ab54cde1a20b99c59d1Jens Axboe strncpy(ts->description, td->o.description, 16304e59d0f3a3ff569bddb31fe6927a9faf204ae9bfJens Axboe FIO_JOBDESC_SIZE - 1); 1631a64e88dad0c0e4a510ae8ab54cde1a20b99c59d1Jens Axboe else 16324e59d0f3a3ff569bddb31fe6927a9faf204ae9bfJens Axboe memset(ts->description, 0, FIO_JOBDESC_SIZE); 1633a64e88dad0c0e4a510ae8ab54cde1a20b99c59d1Jens Axboe 16342f122b135b7319ff8dd04dadf31ff28b301051a3Jens Axboe /* 16352f122b135b7319ff8dd04dadf31ff28b301051a3Jens Axboe * If multiple entries in this group, this is 16362f122b135b7319ff8dd04dadf31ff28b301051a3Jens Axboe * the first member. 16372f122b135b7319ff8dd04dadf31ff28b301051a3Jens Axboe */ 16382f122b135b7319ff8dd04dadf31ff28b301051a3Jens Axboe ts->thread_number = td->thread_number; 1639756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe ts->groupid = td->groupid; 16402dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe 16412dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe /* 16422dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe * first pid in group, not very useful... 16432dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe */ 1644756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe ts->pid = td->pid; 164590fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe 164690fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe ts->kb_base = td->o.kb_base; 1647ad705bcb7e79a7cdb9891db17b4c40b13b6c30c3Steven Noonan ts->unit_base = td->o.unit_base; 1648771e58befea806d2d881953050c4e65329eee382Jens Axboe ts->unified_rw_rep = td->o.unified_rw_rep; 164990fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe } else if (ts->kb_base != td->o.kb_base && !kb_base_warned) { 165090fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe log_info("fio: kb_base differs for jobs in group, using" 165190fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe " %u as the base\n", ts->kb_base); 165290fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe kb_base_warned = 1; 1653ad705bcb7e79a7cdb9891db17b4c40b13b6c30c3Steven Noonan } else if (ts->unit_base != td->o.unit_base && !unit_base_warned) { 1654ad705bcb7e79a7cdb9891db17b4c40b13b6c30c3Steven Noonan log_info("fio: unit_base differs for jobs in group, using" 1655ad705bcb7e79a7cdb9891db17b4c40b13b6c30c3Steven Noonan " %u as the base\n", ts->unit_base); 1656ad705bcb7e79a7cdb9891db17b4c40b13b6c30c3Steven Noonan unit_base_warned = 1; 16572dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe } 16582dc84ba74186eb9ef4dde0f08dc20571c62e001eJens Axboe 1659f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran ts->continue_on_error = td->o.continue_on_error; 1660f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran ts->total_err_count += td->total_err_count; 1661f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran ts->first_error = td->first_error; 1662f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran if (!ts->error) { 1663f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran if (!td->error && td->o.continue_on_error && 1664f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran td->first_error) { 1665f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran ts->error = td->first_error; 16663660ceae229f08b4086279be7c82e86926f0304bJens Axboe ts->verror[sizeof(ts->verror) - 1] = '\0'; 16673660ceae229f08b4086279be7c82e86926f0304bJens Axboe strncpy(ts->verror, td->verror, sizeof(ts->verror) - 1); 1668f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran } else if (td->error) { 1669f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran ts->error = td->error; 16703660ceae229f08b4086279be7c82e86926f0304bJens Axboe ts->verror[sizeof(ts->verror) - 1] = '\0'; 16713660ceae229f08b4086279be7c82e86926f0304bJens Axboe strncpy(ts->verror, td->verror, sizeof(ts->verror) - 1); 1672f2bba1820a567ac00b09916239ac8feb125cead2Radha Ramachandran } 1673756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe } 1674756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 16753e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe ts->latency_depth = td->latency_qd; 16763e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe ts->latency_target = td->o.latency_target; 16773e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe ts->latency_percentile = td->o.latency_percentile; 16783e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe ts->latency_window = td->o.latency_window; 16793e260a46ea9a8de224c3d0a29a608da3440f284aJens Axboe 1680eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->nr_block_infos = td->ts.nr_block_infos; 1681eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (k = 0; k < ts->nr_block_infos; k++) 1682eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->block_infos[k] = td->ts.block_infos[k]; 1683eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1684eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sum_thread_stats(ts, &td->ts, idx == 1); 1685eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1686eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->o.ss_dur) { 1687eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_state = td->ss.state; 1688eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_dur = td->ss.dur; 1689eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_head = td->ss.head; 1690eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_bw_data = td->ss.bw_data; 1691eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_iops_data = td->ss.iops_data; 1692eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_limit.u.f = td->ss.limit; 1693eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_slope.u.f = td->ss.slope; 1694eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_deviation.u.f = td->ss.deviation; 1695eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_criterion.u.f = td->ss.criterion; 1696eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1697eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else 1698eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->ss_dur = ts->ss_state = 0; 1699756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe } 1700756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe 1701756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe for (i = 0; i < nr_ts; i++) { 170294370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe unsigned long long bw; 17033c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 1704756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe ts = &threadstats[i]; 1705eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (ts->groupid == -1) 1706eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes continue; 1707756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe rs = &runstats[ts->groupid]; 170890fef2d162fba55ad684c2c80b3b9739b8d16e72Jens Axboe rs->kb_base = ts->kb_base; 1709ad705bcb7e79a7cdb9891db17b4c40b13b6c30c3Steven Noonan rs->unit_base = ts->unit_base; 1710771e58befea806d2d881953050c4e65329eee382Jens Axboe rs->unified_rw_rep += ts->unified_rw_rep; 17113c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 17126eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (j = 0; j < DDIR_RWDIR_CNT; j++) { 171394370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe if (!ts->runtime[j]) 171494370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe continue; 171594370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe if (ts->runtime[j] < rs->min_run[j] || !rs->min_run[j]) 171694370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe rs->min_run[j] = ts->runtime[j]; 171794370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe if (ts->runtime[j] > rs->max_run[j]) 171894370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe rs->max_run[j] = ts->runtime[j]; 171994370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe 172094370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe bw = 0; 1721eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (ts->runtime[j]) 1722eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bw = ts->io_bytes[j] * 1000 / ts->runtime[j]; 172394370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe if (bw < rs->min_bw[j]) 172494370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe rs->min_bw[j] = bw; 172594370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe if (bw > rs->max_bw[j]) 172694370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe rs->max_bw[j] = bw; 172794370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe 1728eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes rs->iobytes[j] += ts->io_bytes[j]; 172994370ac42ddee6572c434073d3c1840a513bc8f4Jens Axboe } 17303c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe } 17313c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 17323c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe for (i = 0; i < groupid + 1; i++) { 17336eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li int ddir; 17346eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li 17353c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe rs = &runstats[i]; 17363c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 17376eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { 17386eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li if (rs->max_run[ddir]) 1739eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes rs->agg[ddir] = (rs->iobytes[ddir] * 1000) / 17406eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li rs->max_run[ddir]; 17416eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li } 17423c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe } 17433c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 1744eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < FIO_OUTPUT_NR; i++) 1745eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes buf_output_init(&output[i]); 1746eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 17473c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe /* 17483c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe * don't overwrite last signal output 17493c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe */ 1750eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_NORMAL) 1751eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(&output[__FIO_OUTPUT_NORMAL], "\n"); 1752eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_JSON) { 1753eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct thread_data *global; 1754ffb17c0048ff2e4ba97478152729d1f011057d0fJens Axboe char time_buf[32]; 1755eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct timeval now; 1756eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned long long ms_since_epoch; 1757eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1758eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes gettimeofday(&now, NULL); 1759eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ms_since_epoch = (unsigned long long)(now.tv_sec) * 1000 + 1760eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes (unsigned long long)(now.tv_usec) / 1000; 17610a24a7391078256a4481cab56afb27d58da28768Steve ODriscoll 1762eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes os_ctime_r((const time_t *) &now.tv_sec, time_buf, 17630a24a7391078256a4481cab56afb27d58da28768Steve ODriscoll sizeof(time_buf)); 1764eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (time_buf[strlen(time_buf) - 1] == '\n') 1765eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes time_buf[strlen(time_buf) - 1] = '\0'; 17660a24a7391078256a4481cab56afb27d58da28768Steve ODriscoll 1767cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li root = json_create_object(); 1768cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_string(root, "fio version", fio_version_string); 1769eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(root, "timestamp", now.tv_sec); 1770eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_object_add_value_int(root, "timestamp_ms", ms_since_epoch); 17710a24a7391078256a4481cab56afb27d58da28768Steve ODriscoll json_object_add_value_string(root, "time", time_buf); 1772eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes global = get_global_options(); 1773eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_add_job_opts(root, "global options", &global->opt_list, false); 1774cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li array = json_create_array(); 1775cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_object_add_value_array(root, "jobs", array); 1776cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 17773c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 1778eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (is_backend) 1779eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes fio_server_send_job_options(&get_global_options()->opt_list, -1U); 1780eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1781756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe for (i = 0; i < nr_ts; i++) { 1782756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe ts = &threadstats[i]; 1783756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe rs = &runstats[ts->groupid]; 17843c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 1785eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (is_backend) { 1786eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes fio_server_send_job_options(opt_lists[i], i); 1787a64e88dad0c0e4a510ae8ab54cde1a20b99c59d1Jens Axboe fio_server_send_ts(ts, rs); 1788eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } else { 1789eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_TERSE) 1790eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_thread_status_terse(ts, rs, &output[__FIO_OUTPUT_TERSE]); 1791eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_JSON) { 1792eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct json_object *tmp = show_thread_status_json(ts, rs, opt_lists[i]); 1793eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_array_add_value_object(array, tmp); 1794eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1795eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (output_format & FIO_OUTPUT_NORMAL) 1796eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_thread_status_normal(ts, rs, &output[__FIO_OUTPUT_NORMAL]); 1797eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 17983c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe } 1799eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!is_backend && (output_format & FIO_OUTPUT_JSON)) { 1800cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li /* disk util stats, if any */ 1801eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_disk_util(1, root, &output[__FIO_OUTPUT_JSON]); 1802cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li 1803eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_idle_prof_stats(FIO_OUTPUT_JSON, root, &output[__FIO_OUTPUT_JSON]); 1804f2a2ce0eedb44eaa8689e4cbfa77c79b1751b216Huadong Liu 1805eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes json_print_object(root, &output[__FIO_OUTPUT_JSON]); 1806eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_buf(&output[__FIO_OUTPUT_JSON], "\n"); 1807cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li json_free_object(root); 1808cc372b17f2827e89da79241f1bbaca1e7c650611Shaohua Li } 18093c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 181072c27ff8f2eaf945ae34776dab4da3fee753707dJens Axboe for (i = 0; i < groupid + 1; i++) { 181172c27ff8f2eaf945ae34776dab4da3fee753707dJens Axboe rs = &runstats[i]; 18123c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 181372c27ff8f2eaf945ae34776dab4da3fee753707dJens Axboe rs->groupid = i; 1814d09a64a01a6c807596e9286c93f6c6f30fd2ea26Jens Axboe if (is_backend) 181572c27ff8f2eaf945ae34776dab4da3fee753707dJens Axboe fio_server_send_gs(rs); 1816eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else if (output_format & FIO_OUTPUT_NORMAL) 1817eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_group_stats(rs, &output[__FIO_OUTPUT_NORMAL]); 1818c6ae0a5b8123ea9af2ce70319081fbd5d65c8093Jens Axboe } 1819eecf272f1b2d55c1e49aadd7f65b9a433ba04c15Jens Axboe 182072c27ff8f2eaf945ae34776dab4da3fee753707dJens Axboe if (is_backend) 182172c27ff8f2eaf945ae34776dab4da3fee753707dJens Axboe fio_server_send_du(); 1822eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else if (output_format & FIO_OUTPUT_NORMAL) { 1823eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_disk_util(0, NULL, &output[__FIO_OUTPUT_NORMAL]); 1824eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes show_idle_prof_stats(FIO_OUTPUT_NORMAL, NULL, &output[__FIO_OUTPUT_NORMAL]); 1825609040037aabb49b7ac65562587c17d990f6b303Huadong Liu } 1826f2a2ce0eedb44eaa8689e4cbfa77c79b1751b216Huadong Liu 1827eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < FIO_OUTPUT_NR; i++) { 1828eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes buf_output_flush(&output[i]); 1829eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes buf_output_free(&output[i]); 18302b8c71b0f046434d22dffd15308a326bca0c8d16Christian Ehrhardt } 18312b8c71b0f046434d22dffd15308a326bca0c8d16Christian Ehrhardt 1832fdd5f15f8231e8c91c4deff22e630a34addd0fefVincent Kang Fu log_info_flush(); 1833eecf272f1b2d55c1e49aadd7f65b9a433ba04c15Jens Axboe free(runstats); 1834756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe free(threadstats); 1835eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes free(opt_lists); 18363c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 18373c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 1838cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboevoid show_run_stats(void) 1839cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe{ 1840cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe fio_mutex_down(stat_mutex); 1841cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe __show_run_stats(); 1842cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe fio_mutex_up(stat_mutex); 1843cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe} 1844cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe 18457fe36313273ef051670d16aa27953699fd5cdf06Jens Axboevoid __show_running_run_stats(void) 1846b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe{ 1847b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe struct thread_data *td; 1848b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe unsigned long long *rt; 1849b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe struct timeval tv; 1850b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe int i; 1851b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe 1852560f4617435902ae34a8ca4de1a19a9208becaafJens Axboe fio_mutex_down(stat_mutex); 1853560f4617435902ae34a8ca4de1a19a9208becaafJens Axboe 1854b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe rt = malloc(thread_number * sizeof(unsigned long long)); 1855b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe fio_gettime(&tv, NULL); 1856b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe 1857b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe for_each_td(td, i) { 1858c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe td->update_rusage = 1; 18596eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li td->ts.io_bytes[DDIR_READ] = td->io_bytes[DDIR_READ]; 18606eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li td->ts.io_bytes[DDIR_WRITE] = td->io_bytes[DDIR_WRITE]; 18616eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li td->ts.io_bytes[DDIR_TRIM] = td->io_bytes[DDIR_TRIM]; 1862b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe td->ts.total_run_time = mtime_since(&td->epoch, &tv); 1863eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1864eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes rt[i] = mtime_since(&td->start, &tv); 1865eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td_read(td) && td->ts.io_bytes[DDIR_READ]) 1866eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->ts.runtime[DDIR_READ] += rt[i]; 1867eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td_write(td) && td->ts.io_bytes[DDIR_WRITE]) 1868eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->ts.runtime[DDIR_WRITE] += rt[i]; 1869eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td_trim(td) && td->ts.io_bytes[DDIR_TRIM]) 1870eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->ts.runtime[DDIR_TRIM] += rt[i]; 1871b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe } 1872b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe 1873c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe for_each_td(td, i) { 187404247864f004c0a20ceb9fb0c0ce3c3a3c512326Jens Axboe if (td->runstate >= TD_EXITED) 187504247864f004c0a20ceb9fb0c0ce3c3a3c512326Jens Axboe continue; 1876c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe if (td->rusage_sem) { 1877c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe td->update_rusage = 1; 1878c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe fio_mutex_down(td->rusage_sem); 1879c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe } 1880c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe td->update_rusage = 0; 1881c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe } 1882c97f1ad6d2a2fb4fe9f3b15e40158aac21e5699eJens Axboe 1883cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe __show_run_stats(); 1884b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe 1885b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe for_each_td(td, i) { 1886eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td_read(td) && td->ts.io_bytes[DDIR_READ]) 1887b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe td->ts.runtime[DDIR_READ] -= rt[i]; 1888eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td_write(td) && td->ts.io_bytes[DDIR_WRITE]) 1889b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe td->ts.runtime[DDIR_WRITE] -= rt[i]; 1890eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td_trim(td) && td->ts.io_bytes[DDIR_TRIM]) 18916eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li td->ts.runtime[DDIR_TRIM] -= rt[i]; 1892b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe } 1893b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe 1894b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe free(rt); 1895cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe fio_mutex_up(stat_mutex); 1896b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe} 1897b852e7cf097cec1c7fb92305f9c3c6b394bb39adJens Axboe 189806464907159baf7a1eeac654a023743e33f28d86Jens Axboestatic int status_interval_init; 189906464907159baf7a1eeac654a023743e33f28d86Jens Axboestatic struct timeval status_time; 190077d9967586f9cc8d445056510e25be4eeded2689Jens Axboestatic int status_file_disabled; 190106464907159baf7a1eeac654a023743e33f28d86Jens Axboe 1902dac45f23c3c7d146f7df82047ae7f25abf231ed3Jens Axboe#define FIO_STATUS_FILE "fio-dump-status" 190306464907159baf7a1eeac654a023743e33f28d86Jens Axboe 190406464907159baf7a1eeac654a023743e33f28d86Jens Axboestatic int check_status_file(void) 190506464907159baf7a1eeac654a023743e33f28d86Jens Axboe{ 190606464907159baf7a1eeac654a023743e33f28d86Jens Axboe struct stat sb; 1907a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran const char *temp_dir; 1908a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran char fio_status_file_path[PATH_MAX]; 190906464907159baf7a1eeac654a023743e33f28d86Jens Axboe 191077d9967586f9cc8d445056510e25be4eeded2689Jens Axboe if (status_file_disabled) 191177d9967586f9cc8d445056510e25be4eeded2689Jens Axboe return 0; 191277d9967586f9cc8d445056510e25be4eeded2689Jens Axboe 1913a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran temp_dir = getenv("TMPDIR"); 191448b16e2725249985c9f1841928eb08574c24d3ccJens Axboe if (temp_dir == NULL) { 1915a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran temp_dir = getenv("TEMP"); 191648b16e2725249985c9f1841928eb08574c24d3ccJens Axboe if (temp_dir && strlen(temp_dir) >= PATH_MAX) 191748b16e2725249985c9f1841928eb08574c24d3ccJens Axboe temp_dir = NULL; 191848b16e2725249985c9f1841928eb08574c24d3ccJens Axboe } 1919a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran if (temp_dir == NULL) 1920a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran temp_dir = "/tmp"; 1921a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran 1922a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran snprintf(fio_status_file_path, sizeof(fio_status_file_path), "%s/%s", temp_dir, FIO_STATUS_FILE); 1923a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran 1924a0bafb7d88c33b9046073e0bc4af7d64d0caa30bBruce Cran if (stat(fio_status_file_path, &sb)) 192506464907159baf7a1eeac654a023743e33f28d86Jens Axboe return 0; 192606464907159baf7a1eeac654a023743e33f28d86Jens Axboe 192777d9967586f9cc8d445056510e25be4eeded2689Jens Axboe if (unlink(fio_status_file_path) < 0) { 192877d9967586f9cc8d445056510e25be4eeded2689Jens Axboe log_err("fio: failed to unlink %s: %s\n", fio_status_file_path, 192977d9967586f9cc8d445056510e25be4eeded2689Jens Axboe strerror(errno)); 193077d9967586f9cc8d445056510e25be4eeded2689Jens Axboe log_err("fio: disabling status file updates\n"); 193177d9967586f9cc8d445056510e25be4eeded2689Jens Axboe status_file_disabled = 1; 193277d9967586f9cc8d445056510e25be4eeded2689Jens Axboe } 193377d9967586f9cc8d445056510e25be4eeded2689Jens Axboe 193406464907159baf7a1eeac654a023743e33f28d86Jens Axboe return 1; 193506464907159baf7a1eeac654a023743e33f28d86Jens Axboe} 193606464907159baf7a1eeac654a023743e33f28d86Jens Axboe 193706464907159baf7a1eeac654a023743e33f28d86Jens Axboevoid check_for_running_stats(void) 193806464907159baf7a1eeac654a023743e33f28d86Jens Axboe{ 193906464907159baf7a1eeac654a023743e33f28d86Jens Axboe if (status_interval) { 194006464907159baf7a1eeac654a023743e33f28d86Jens Axboe if (!status_interval_init) { 194106464907159baf7a1eeac654a023743e33f28d86Jens Axboe fio_gettime(&status_time, NULL); 194206464907159baf7a1eeac654a023743e33f28d86Jens Axboe status_interval_init = 1; 194306464907159baf7a1eeac654a023743e33f28d86Jens Axboe } else if (mtime_since_now(&status_time) >= status_interval) { 194406464907159baf7a1eeac654a023743e33f28d86Jens Axboe show_running_run_stats(); 194506464907159baf7a1eeac654a023743e33f28d86Jens Axboe fio_gettime(&status_time, NULL); 194606464907159baf7a1eeac654a023743e33f28d86Jens Axboe return; 194706464907159baf7a1eeac654a023743e33f28d86Jens Axboe } 194806464907159baf7a1eeac654a023743e33f28d86Jens Axboe } 194906464907159baf7a1eeac654a023743e33f28d86Jens Axboe if (check_status_file()) { 195006464907159baf7a1eeac654a023743e33f28d86Jens Axboe show_running_run_stats(); 195106464907159baf7a1eeac654a023743e33f28d86Jens Axboe return; 195206464907159baf7a1eeac654a023743e33f28d86Jens Axboe } 195306464907159baf7a1eeac654a023743e33f28d86Jens Axboe} 195406464907159baf7a1eeac654a023743e33f28d86Jens Axboe 1955687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboestatic inline void add_stat_sample(struct io_stat *is, unsigned long data) 19563c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 1957687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboe double val = data; 19586660cc67cb72b70d1ea0ab8c465976d715fcb976Jens Axboe double delta; 1959687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboe 1960687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboe if (data > is->max_val) 1961687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboe is->max_val = data; 1962687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboe if (data < is->min_val) 1963687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboe is->min_val = data; 1964687040842bf56502d33b6c0cb5d2af6da27d080cJens Axboe 1965802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe delta = val - is->mean.u.f; 1966ef11d7376273302d22c7d013bb9c296ee27f4082Jens Axboe if (delta) { 1967802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe is->mean.u.f += delta / (is->samples + 1.0); 1968802ad4a83e92a30b5fdccf117d59fbb69068c054Jens Axboe is->S.u.f += delta * (val - is->mean.u.f); 1969ef11d7376273302d22c7d013bb9c296ee27f4082Jens Axboe } 19703c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 19713c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe is->samples++; 19723c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 19733c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 1974eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes/* 1975eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Return a struct io_logs, which is added to the tail of the log 1976eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * list for 'iolog'. 1977eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 1978eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic struct io_logs *get_new_log(struct io_log *iolog) 1979eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 1980eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes size_t new_size, new_samples; 1981eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_logs *cur_log; 1982eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1983eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 1984eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Cap the size at MAX_LOG_ENTRIES, so we don't keep doubling 1985eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * forever 1986eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 1987eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!iolog->cur_log_max) 1988eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes new_samples = DEF_LOG_ENTRIES; 1989eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else { 1990eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes new_samples = iolog->cur_log_max * 2; 1991eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (new_samples > MAX_LOG_ENTRIES) 1992eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes new_samples = MAX_LOG_ENTRIES; 1993eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 1994eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1995eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes new_size = new_samples * log_entry_sz(iolog); 1996eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 1997eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log = smalloc(sizeof(*cur_log)); 1998eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (cur_log) { 1999eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes INIT_FLIST_HEAD(&cur_log->list); 2000eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log->log = malloc(new_size); 2001eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (cur_log->log) { 2002eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log->nr_samples = 0; 2003eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log->max_samples = new_samples; 2004eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes flist_add_tail(&cur_log->list, &iolog->io_logs); 2005eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iolog->cur_log_max = new_samples; 2006eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return cur_log; 2007eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2008eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes sfree(cur_log); 2009eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2010eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2011eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return NULL; 2012eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 2013eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2014eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes/* 2015eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Add and return a new log chunk, or return current log if big enough 2016eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 2017eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic struct io_logs *regrow_log(struct io_log *iolog) 2018eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2019eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_logs *cur_log; 2020eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int i; 2021eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2022eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!iolog || iolog->disabled) 2023eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes goto disable; 2024eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2025eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log = iolog_cur_log(iolog); 2026eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!cur_log) { 2027eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log = get_new_log(iolog); 2028eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!cur_log) 2029eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return NULL; 2030eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2031eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2032eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (cur_log->nr_samples < cur_log->max_samples) 2033eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return cur_log; 2034eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2035eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 2036eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * No room for a new sample. If we're compressing on the fly, flush 2037eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * out the current chunk 2038eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 2039eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (iolog->log_gz) { 2040eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (iolog_cur_flush(iolog, cur_log)) { 2041eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_err("fio: failed flushing iolog! Will stop logging.\n"); 2042eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return NULL; 2043eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2044eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2045eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2046eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 2047eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Get a new log array, and add to our list 2048eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 2049eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log = get_new_log(iolog); 2050eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!cur_log) { 2051eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes log_err("fio: failed extending iolog! Will stop logging.\n"); 2052eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return NULL; 2053eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2054eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2055eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!iolog->pending || !iolog->pending->nr_samples) 2056eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return cur_log; 2057eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2058eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 2059eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Flush pending items to new log 2060eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 2061eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < iolog->pending->nr_samples; i++) { 2062eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_sample *src, *dst; 2063eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2064eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes src = get_sample(iolog, iolog->pending, i); 2065eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes dst = get_sample(iolog, cur_log, i); 2066eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes memcpy(dst, src, log_entry_sz(iolog)); 2067eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2068eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log->nr_samples = iolog->pending->nr_samples; 2069eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2070eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iolog->pending->nr_samples = 0; 2071eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return cur_log; 2072eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesdisable: 2073eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (iolog) 2074eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iolog->disabled = true; 2075eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return NULL; 2076eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 2077eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2078eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesvoid regrow_logs(struct thread_data *td) 2079eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2080eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes regrow_log(td->slat_log); 2081eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes regrow_log(td->clat_log); 2082eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes regrow_log(td->clat_hist_log); 2083eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes regrow_log(td->lat_log); 2084eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes regrow_log(td->bw_log); 2085eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes regrow_log(td->iops_log); 2086eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->flags &= ~TD_F_REGROW_LOGS; 2087eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 2088eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2089eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic struct io_logs *get_cur_log(struct io_log *iolog) 2090eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2091eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_logs *cur_log; 2092eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2093eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log = iolog_cur_log(iolog); 2094eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!cur_log) { 2095eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log = get_new_log(iolog); 2096eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!cur_log) 2097eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return NULL; 2098eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2099eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2100eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (cur_log->nr_samples < cur_log->max_samples) 2101eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return cur_log; 2102eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2103eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 2104eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Out of space. If we're in IO offload mode, or we're not doing 2105eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * per unit logging (hence logging happens outside of the IO thread 2106eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * as well), add a new log chunk inline. If we're doing inline 2107eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * submissions, flag 'td' as needing a log regrow and we'll take 2108eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * care of it on the submission side. 2109eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 2110eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (iolog->td->o.io_submit_mode == IO_MODE_OFFLOAD || 2111eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes !per_unit_log(iolog)) 2112eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return regrow_log(iolog); 2113eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2114eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iolog->td->flags |= TD_F_REGROW_LOGS; 2115eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes assert(iolog->pending->nr_samples < iolog->pending->max_samples); 2116eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return iolog->pending; 2117eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 2118eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2119eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void __add_log_sample(struct io_log *iolog, union io_sample_data data, 2120306ddc9752eef70c3fbb111af63d197a3a6d447fJens Axboe enum fio_ddir ddir, unsigned int bs, 2121ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe unsigned long t, uint64_t offset) 21223c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 2123eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_logs *cur_log; 2124306ddc9752eef70c3fbb111af63d197a3a6d447fJens Axboe 21253c568239a319087a965b06bc2ed94d058810100fJens Axboe if (iolog->disabled) 21263c568239a319087a965b06bc2ed94d058810100fJens Axboe return; 2127eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (flist_empty(&iolog->io_logs)) 2128b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe iolog->avg_last = t; 2129b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe 2130eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log = get_cur_log(iolog); 2131eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (cur_log) { 2132eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_sample *s; 21333c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 2134eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes s = get_sample(iolog, cur_log, cur_log->nr_samples); 213538a812d7fa79a673855efb6324c8fc68b92b89c1Jens Axboe 2136eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes s->data = data; 2137eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes s->time = t + (iolog->td ? iolog->td->unix_epoch : 0); 2138eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes io_sample_set_ddir(iolog, s, ddir); 2139eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes s->bs = bs; 2140ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe 2141eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (iolog->log_offset) { 2142eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_sample_offset *so = (void *) s; 2143ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe 2144eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes so->offset = offset; 2145eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2146ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe 2147eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes cur_log->nr_samples++; 2148eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return; 2149ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe } 2150ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe 2151eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iolog->disabled = true; 21523c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 21533c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 21547fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboestatic inline void reset_io_stat(struct io_stat *ios) 21557fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe{ 21567fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe ios->max_val = ios->min_val = ios->samples = 0; 21577fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe ios->mean.u.f = ios->S.u.f = 0; 21587fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe} 21597fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe 21606bb58215842760895071d9f331da4dc2dfc16f30Jens Axboevoid reset_io_stats(struct thread_data *td) 21616bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe{ 21626bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe struct thread_stat *ts = &td->ts; 21636bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe int i, j; 21646bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe 21656bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe for (i = 0; i < DDIR_RWDIR_CNT; i++) { 21666bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe reset_io_stat(&ts->clat_stat[i]); 21676bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe reset_io_stat(&ts->slat_stat[i]); 21686bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe reset_io_stat(&ts->lat_stat[i]); 21696bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe reset_io_stat(&ts->bw_stat[i]); 21706bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe reset_io_stat(&ts->iops_stat[i]); 21716bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe 21726bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe ts->io_bytes[i] = 0; 21736bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe ts->runtime[i] = 0; 2174eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->total_io_u[i] = 0; 2175eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->short_io_u[i] = 0; 2176eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->drop_io_u[i] = 0; 21776bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe 21786bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe for (j = 0; j < FIO_IO_U_PLAT_NR; j++) 21796bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe ts->io_u_plat[i][j] = 0; 21806bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe } 21816bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe 21826bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe for (i = 0; i < FIO_IO_U_MAP_NR; i++) { 21836bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe ts->io_u_map[i] = 0; 21846bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe ts->io_u_submit[i] = 0; 21856bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe ts->io_u_complete[i] = 0; 2186eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2187eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2188eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < FIO_IO_U_LAT_U_NR; i++) 21896bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe ts->io_u_lat_u[i] = 0; 2190eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (i = 0; i < FIO_IO_U_LAT_M_NR; i++) 21916bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe ts->io_u_lat_m[i] = 0; 21926bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe 2193eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->total_submit = 0; 2194eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes ts->total_complete = 0; 21956bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe} 21966bb58215842760895071d9f331da4dc2dfc16f30Jens Axboe 2197eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void __add_stat_to_log(struct io_log *iolog, enum fio_ddir ddir, 2198eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned long elapsed, bool log_max) 21999900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter{ 22009900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter /* 22019900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter * Note an entry in the log. Use the mean from the logged samples, 22029900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter * making sure to properly round up. Only write a log entry if we 22039900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter * had actual samples done. 22049900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter */ 2205eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (iolog->avg_window[ddir].samples) { 2206eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes union io_sample_data data; 22079900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter 2208eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (log_max) 2209eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes data.val = iolog->avg_window[ddir].max_val; 2210eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else 2211eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes data.val = iolog->avg_window[ddir].mean.u.f + 0.50; 22129900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter 2213eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes __add_log_sample(iolog, data, ddir, 0, elapsed, 0); 22149900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter } 22159900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter 2216eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes reset_io_stat(&iolog->avg_window[ddir]); 2217eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 2218eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2219eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic void _add_stat_to_log(struct io_log *iolog, unsigned long elapsed, 2220eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bool log_max) 2221eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2222eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int ddir; 22239900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter 2224eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) 2225eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes __add_stat_to_log(iolog, ddir, elapsed, log_max); 22269900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter} 22279900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter 2228eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic long add_log_sample(struct thread_data *td, struct io_log *iolog, 2229eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes union io_sample_data data, enum fio_ddir ddir, 2230ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe unsigned int bs, uint64_t offset) 2231bb3884d855100fa8fa6a1d2aac79e867dfd47bf9Jens Axboe{ 22327fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe unsigned long elapsed, this_window; 2233b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe 2234ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe if (!ddir_rw(ddir)) 2235eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 0; 2236ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe 2237b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe elapsed = mtime_since_now(&td->epoch); 2238b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe 2239b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe /* 2240b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe * If no time averaging, just add the log sample. 2241b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe */ 2242b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe if (!iolog->avg_msec) { 2243eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes __add_log_sample(iolog, data, ddir, bs, elapsed, offset); 2244eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return 0; 2245b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe } 2246b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe 2247b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe /* 2248b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe * Add the sample. If the time period has passed, then 2249b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe * add that entry to the log and clear. 2250b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe */ 2251eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_stat_sample(&iolog->avg_window[ddir], data.val); 2252b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe 22537fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe /* 22547fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe * If period hasn't passed, adding the above sample is all we 22557fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe * need to do. 22567fb28d3661a5833d8be24a014a04ee4548ec1c16Jens Axboe */ 2257b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe this_window = elapsed - iolog->avg_last; 2258eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (elapsed < iolog->avg_last) 2259eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return iolog->avg_last - elapsed; 2260eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else if (this_window < iolog->avg_msec) { 2261eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int diff = iolog->avg_msec - this_window; 2262eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2263eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (inline_log(iolog) || diff > LOG_MSEC_SLACK) 2264eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return diff; 2265eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2266b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe 2267eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes _add_stat_to_log(iolog, elapsed, td->o.log_max != 0); 2268b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe 2269eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes iolog->avg_last = elapsed - (this_window - iolog->avg_msec); 2270eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return iolog->avg_msec; 22719900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter} 22726eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li 2273eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesvoid finalize_logs(struct thread_data *td, bool unit_logs) 22749900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter{ 22759900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter unsigned long elapsed; 22766eaf09d6e9ca1f8accb057cdb18620b7e53ae33fShaohua Li 22779900706854ce4919afb064ef6be42447f698d581Peter Oberparleiter elapsed = mtime_since_now(&td->epoch); 2278b8bc8cba9512c6dce4891fda86de675053605ca2Jens Axboe 2279eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->clat_log && unit_logs) 2280eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes _add_stat_to_log(td->clat_log, elapsed, td->o.log_max != 0); 2281eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->slat_log && unit_logs) 2282eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes _add_stat_to_log(td->slat_log, elapsed, td->o.log_max != 0); 2283eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->lat_log && unit_logs) 2284eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes _add_stat_to_log(td->lat_log, elapsed, td->o.log_max != 0); 2285eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->bw_log && (unit_logs == per_unit_log(td->bw_log))) 2286eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes _add_stat_to_log(td->bw_log, elapsed, td->o.log_max != 0); 2287eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->iops_log && (unit_logs == per_unit_log(td->iops_log))) 2288eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes _add_stat_to_log(td->iops_log, elapsed, td->o.log_max != 0); 2289bb3884d855100fa8fa6a1d2aac79e867dfd47bf9Jens Axboe} 2290bb3884d855100fa8fa6a1d2aac79e867dfd47bf9Jens Axboe 2291eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesvoid add_agg_sample(union io_sample_data data, enum fio_ddir ddir, unsigned int bs) 2292bb3884d855100fa8fa6a1d2aac79e867dfd47bf9Jens Axboe{ 2293ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe struct io_log *iolog; 2294bb3884d855100fa8fa6a1d2aac79e867dfd47bf9Jens Axboe 2295ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe if (!ddir_rw(ddir)) 2296ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe return; 2297ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe 2298ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe iolog = agg_io_log[ddir]; 2299eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes __add_log_sample(iolog, data, ddir, bs, mtime_since_genesis(), 0); 2300bb3884d855100fa8fa6a1d2aac79e867dfd47bf9Jens Axboe} 2301bb3884d855100fa8fa6a1d2aac79e867dfd47bf9Jens Axboe 2302833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hongstatic void add_clat_percentile_sample(struct thread_stat *ts, 2303833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong unsigned long usec, enum fio_ddir ddir) 2304833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong{ 2305833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong unsigned int idx = plat_val_to_idx(usec); 2306833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong assert(idx < FIO_IO_U_PLAT_NR); 2307833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 2308833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong ts->io_u_plat[ddir][idx]++; 2309833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong} 2310833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 23111e97cce9f5a87a67293a05ec4533ed6968698b2eJens Axboevoid add_clat_sample(struct thread_data *td, enum fio_ddir ddir, 2312ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe unsigned long usec, unsigned int bs, uint64_t offset) 23133c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 2314eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned long elapsed, this_window; 2315756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe struct thread_stat *ts = &td->ts; 2316eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_log *iolog = td->clat_hist_log; 2317079ad09b1ef22fa0d47c2cd2673908c5619aa41aJens Axboe 2318eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_lock(td); 2319ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe 2320d85f5118c41a112c3b8a58cc6908d00294bfb78dJens Axboe add_stat_sample(&ts->clat_stat[ddir], usec); 23213c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 23227b9f733afb91a5c92f44bb6e68860f17ba14f585Jens Axboe if (td->clat_log) 2323eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_log_sample(td, td->clat_log, sample_val(usec), ddir, bs, 2324eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes offset); 2325833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong 2326833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong if (ts->clat_percentiles) 2327833491908a1afd67d27ce79257de3a4d80143d9fYu-ju Hong add_clat_percentile_sample(ts, usec, ddir); 2328eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2329eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (iolog && iolog->hist_msec) { 2330eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_hist *hw = &iolog->hist_window[ddir]; 2331eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2332eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes hw->samples++; 2333eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes elapsed = mtime_since_now(&td->epoch); 2334eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!hw->hist_last) 2335eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes hw->hist_last = elapsed; 2336eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes this_window = elapsed - hw->hist_last; 2337eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2338eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (this_window >= iolog->hist_msec) { 2339eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int *io_u_plat; 2340eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_u_plat_entry *dst; 2341eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2342eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 2343eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Make a byte-for-byte copy of the latency histogram 2344eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * stored in td->ts.io_u_plat[ddir], recording it in a 2345eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * log sample. Note that the matching call to free() is 2346eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * located in iolog.c after printing this sample to the 2347eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * log file. 2348eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 2349eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes io_u_plat = (unsigned int *) td->ts.io_u_plat[ddir]; 2350eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes dst = malloc(sizeof(struct io_u_plat_entry)); 2351eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes memcpy(&(dst->io_u_plat), io_u_plat, 2352eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes FIO_IO_U_PLAT_NR * sizeof(unsigned int)); 2353eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes flist_add(&dst->list, &hw->list); 2354eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes __add_log_sample(iolog, sample_plat(dst), ddir, bs, 2355eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes elapsed, offset); 2356eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2357eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* 2358eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Update the last time we recorded as being now, minus 2359eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * any drift in time we encountered before actually 2360eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * making the record. 2361eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 2362eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes hw->hist_last = elapsed - (this_window - iolog->hist_msec); 2363eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes hw->samples = 0; 2364eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2365eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2366eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2367eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_unlock(td); 23683c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 23693c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 23701e97cce9f5a87a67293a05ec4533ed6968698b2eJens Axboevoid add_slat_sample(struct thread_data *td, enum fio_ddir ddir, 2371ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe unsigned long usec, unsigned int bs, uint64_t offset) 23723c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 2373756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe struct thread_stat *ts = &td->ts; 2374079ad09b1ef22fa0d47c2cd2673908c5619aa41aJens Axboe 2375ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe if (!ddir_rw(ddir)) 2376ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe return; 2377ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe 2378eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_lock(td); 2379eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2380d85f5118c41a112c3b8a58cc6908d00294bfb78dJens Axboe add_stat_sample(&ts->slat_stat[ddir], usec); 23813c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 23827b9f733afb91a5c92f44bb6e68860f17ba14f585Jens Axboe if (td->slat_log) 2383eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_log_sample(td, td->slat_log, sample_val(usec), ddir, bs, offset); 2384eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2385eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_unlock(td); 23863c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 23873c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 238802af09886db695e5ea2b7fd2a632733955f3c03fJens Axboevoid add_lat_sample(struct thread_data *td, enum fio_ddir ddir, 2389ccefd5fea1de87a83db9c372985b69f4fbbe922cJens Axboe unsigned long usec, unsigned int bs, uint64_t offset) 239002af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe{ 239102af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe struct thread_stat *ts = &td->ts; 239202af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe 2393ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe if (!ddir_rw(ddir)) 2394ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe return; 2395ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe 2396eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_lock(td); 2397eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 239802af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe add_stat_sample(&ts->lat_stat[ddir], usec); 239902af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe 24007b9f733afb91a5c92f44bb6e68860f17ba14f585Jens Axboe if (td->lat_log) 2401eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_log_sample(td, td->lat_log, sample_val(usec), ddir, bs, 2402eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes offset); 2403eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2404eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_unlock(td); 240502af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe} 240602af09886db695e5ea2b7fd2a632733955f3c03fJens Axboe 2407eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesvoid add_bw_sample(struct thread_data *td, struct io_u *io_u, 2408eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int bytes, unsigned long spent) 24093c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe{ 2410756867bd127cfa1fb27ae2d4ba973af8cb341f13Jens Axboe struct thread_stat *ts = &td->ts; 2411eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned long rate; 2412eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2413eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (spent) 2414eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes rate = bytes * 1000 / spent; 2415eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else 2416eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes rate = 0; 2417eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2418eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_lock(td); 2419eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2420eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_stat_sample(&ts->bw_stat[io_u->ddir], rate); 2421eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2422eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->bw_log) 2423eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_log_sample(td, td->bw_log, sample_val(rate), io_u->ddir, 2424eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bytes, io_u->offset); 2425eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2426eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->stat_io_bytes[io_u->ddir] = td->this_io_bytes[io_u->ddir]; 2427eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_unlock(td); 2428eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 2429eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2430eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic int __add_samples(struct thread_data *td, struct timeval *parent_tv, 2431eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct timeval *t, unsigned int avg_time, 2432eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes uint64_t *this_io_bytes, uint64_t *stat_io_bytes, 2433eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct io_stat *stat, struct io_log *log, 2434eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bool is_kb) 2435eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2436ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe unsigned long spent, rate; 2437eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes enum fio_ddir ddir; 2438eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int next, next_log; 2439ff58fcede39d16a2c642897cbe5a7f28b2da1950Jens Axboe 2440eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes next_log = avg_time; 24413c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 2442eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes spent = mtime_since(parent_tv, t); 2443eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (spent < avg_time && avg_time - spent >= LOG_MSEC_SLACK) 2444eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return avg_time - spent; 2445eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2446eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_lock(td); 24479602d8df781db46f78a25a02abc75de03a69b6a8Jens Axboe 24489602d8df781db46f78a25a02abc75de03a69b6a8Jens Axboe /* 24495daa4ebed724cb0223dac4a1386e068f59722dabJosh Carter * Compute both read and write rates for the interval. 24505daa4ebed724cb0223dac4a1386e068f59722dabJosh Carter */ 2451eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for (ddir = 0; ddir < DDIR_RWDIR_CNT; ddir++) { 24525daa4ebed724cb0223dac4a1386e068f59722dabJosh Carter uint64_t delta; 24535daa4ebed724cb0223dac4a1386e068f59722dabJosh Carter 2454eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes delta = this_io_bytes[ddir] - stat_io_bytes[ddir]; 24555daa4ebed724cb0223dac4a1386e068f59722dabJosh Carter if (!delta) 24565daa4ebed724cb0223dac4a1386e068f59722dabJosh Carter continue; /* No entries for interval */ 24573c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 2458eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (spent) { 2459eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (is_kb) 2460eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes rate = delta * 1000 / spent / 1024; /* KiB/s */ 2461eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else 2462eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes rate = (delta * 1000) / spent; 2463eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } else 24640956264f3dca6a0467092fe9ef335f3cae1c6177Jens Axboe rate = 0; 24650956264f3dca6a0467092fe9ef335f3cae1c6177Jens Axboe 2466eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_stat_sample(&stat[ddir], rate); 2467eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2468eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (log) { 2469eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int bs = 0; 2470eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2471eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->o.min_bs[ddir] == td->o.max_bs[ddir]) 2472eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bs = td->o.min_bs[ddir]; 24733c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 2474eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes next = add_log_sample(td, log, sample_val(rate), ddir, bs, 0); 2475eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes next_log = min(next_log, next); 2476eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 24775daa4ebed724cb0223dac4a1386e068f59722dabJosh Carter 2478eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes stat_io_bytes[ddir] = this_io_bytes[ddir]; 24795daa4ebed724cb0223dac4a1386e068f59722dabJosh Carter } 24803c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe 2481eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes timeval_add_msec(parent_tv, avg_time); 2482eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2483eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_unlock(td); 2484eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2485eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (spent <= avg_time) 2486eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes next = avg_time; 2487eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes else 2488eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes next = avg_time - (1 + spent - avg_time); 2489eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2490eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return min(next, next_log); 24913c39a379542fd819dbc5cf6daf59380911c39141Jens Axboe} 2492c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe 2493eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic int add_bw_samples(struct thread_data *td, struct timeval *t) 2494eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2495eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return __add_samples(td, &td->bw_sample_time, t, td->o.bw_avg_time, 2496eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->this_io_bytes, td->stat_io_bytes, 2497eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->ts.bw_stat, td->bw_log, true); 2498eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 2499eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2500eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesvoid add_iops_sample(struct thread_data *td, struct io_u *io_u, 2501eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int bytes) 2502c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe{ 2503c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe struct thread_stat *ts = &td->ts; 2504c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe 2505eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_lock(td); 2506c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe 2507eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_stat_sample(&ts->iops_stat[io_u->ddir], 1); 2508c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe 2509eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (td->iops_log) 2510eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes add_log_sample(td, td->iops_log, sample_val(1), io_u->ddir, 2511eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes bytes, io_u->offset); 2512c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe 2513eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->stat_io_blocks[io_u->ddir] = td->this_io_blocks[io_u->ddir]; 2514eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td_io_u_unlock(td); 2515eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 25169602d8df781db46f78a25a02abc75de03a69b6a8Jens Axboe 2517eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesstatic int add_iops_samples(struct thread_data *td, struct timeval *t) 2518eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2519eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return __add_samples(td, &td->iops_sample_time, t, td->o.iops_avg_time, 2520eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->this_io_blocks, td->stat_io_blocks, 2521eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes td->ts.iops_stat, td->iops_log, false); 2522eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 25230956264f3dca6a0467092fe9ef335f3cae1c6177Jens Axboe 2524eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes/* 2525eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * Returns msecs to next event 2526eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes */ 2527eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesint calc_log_samples(void) 2528eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2529eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct thread_data *td; 2530eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes unsigned int next = ~0U, tmp; 2531eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes struct timeval now; 2532eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int i; 2533c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe 2534eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes fio_gettime(&now, NULL); 25359602d8df781db46f78a25a02abc75de03a69b6a8Jens Axboe 2536eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes for_each_td(td, i) { 2537eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!td->o.stats) 2538eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes continue; 2539eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (in_ramp_time(td) || 2540eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes !(td->runstate == TD_RUNNING || td->runstate == TD_VERIFYING)) { 2541eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes next = min(td->o.iops_avg_time, td->o.bw_avg_time); 2542eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes continue; 2543eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2544eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!td->bw_log || 2545eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes (td->bw_log && !per_unit_log(td->bw_log))) { 2546eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes tmp = add_bw_samples(td, &now); 2547eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (tmp < next) 2548eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes next = tmp; 2549eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 2550eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (!td->iops_log || 2551eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes (td->iops_log && !per_unit_log(td->iops_log))) { 2552eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes tmp = add_iops_samples(td, &now); 2553eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes if (tmp < next) 2554eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes next = tmp; 2555eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes } 25569602d8df781db46f78a25a02abc75de03a69b6a8Jens Axboe } 2557c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe 2558eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return next == ~0U ? 0 : next; 2559c8eeb9df1f52f28567a5937e141decc6a26ec30bJens Axboe} 2560cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe 2561cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboevoid stat_init(void) 2562cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe{ 2563cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe stat_mutex = fio_mutex_init(FIO_MUTEX_UNLOCKED); 2564cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe} 2565cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe 2566cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboevoid stat_exit(void) 2567cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe{ 2568cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe /* 2569cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe * When we have the mutex, we know out-of-band access to it 2570cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe * have ended. 2571cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe */ 2572cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe fio_mutex_down(stat_mutex); 2573cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe fio_mutex_remove(stat_mutex); 2574cef9175e52e8a240117b9f45b228fdaa0f1c0572Jens Axboe} 2575fdb0da8028e156c0da43aca18e1423d1b300bdadJens Axboe 2576fdb0da8028e156c0da43aca18e1423d1b300bdadJens Axboe/* 2577fdb0da8028e156c0da43aca18e1423d1b300bdadJens Axboe * Called from signal handler. Wake up status thread. 2578fdb0da8028e156c0da43aca18e1423d1b300bdadJens Axboe */ 2579fdb0da8028e156c0da43aca18e1423d1b300bdadJens Axboevoid show_running_run_stats(void) 2580fdb0da8028e156c0da43aca18e1423d1b300bdadJens Axboe{ 2581eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes helper_do_stat(); 2582eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes} 2583eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes 2584eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughesuint32_t *io_u_block_info(struct thread_data *td, struct io_u *io_u) 2585eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes{ 2586eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes /* Ignore io_u's which span multiple blocks--they will just get 2587eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes * inaccurate counts. */ 2588eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes int idx = (io_u->offset - io_u->file->file_offset) 2589eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes / td->o.bs[DDIR_TRIM]; 2590eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes uint32_t *info = &td->ts.block_infos[idx]; 2591eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes assert(idx < td->ts.nr_block_infos); 2592eda3a60699e1d96bb68875ef2169ca819eb8f4f9Elliott Hughes return info; 2593fdb0da8028e156c0da43aca18e1423d1b300bdadJens Axboe} 2594