-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
stat.c
3721 lines (3093 loc) · 99.6 KB
/
stat.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/time.h>
#include <sys/stat.h>
#include <math.h>
#include "fio.h"
#include "diskutil.h"
#include "lib/ieee754.h"
#include "json.h"
#include "lib/getrusage.h"
#include "idletime.h"
#include "lib/pow2.h"
#include "lib/output_buffer.h"
#include "helper_thread.h"
#include "smalloc.h"
#include "zbd.h"
#include "oslib/asprintf.h"
#ifdef WIN32
#define LOG_MSEC_SLACK 2
#else
#define LOG_MSEC_SLACK 1
#endif
struct log_sample {
union io_sample_data data;
uint32_t ddir;
uint64_t bs;
uint64_t offset;
uint16_t priority;
uint64_t issue_time;
};
struct fio_sem *stat_sem;
void clear_rusage_stat(struct thread_data *td)
{
struct thread_stat *ts = &td->ts;
fio_getrusage(&td->ru_start);
ts->usr_time = ts->sys_time = 0;
ts->ctx = 0;
ts->minf = ts->majf = 0;
}
void update_rusage_stat(struct thread_data *td)
{
struct thread_stat *ts = &td->ts;
fio_getrusage(&td->ru_end);
ts->usr_time += mtime_since_tv(&td->ru_start.ru_utime,
&td->ru_end.ru_utime);
ts->sys_time += mtime_since_tv(&td->ru_start.ru_stime,
&td->ru_end.ru_stime);
ts->ctx += td->ru_end.ru_nvcsw + td->ru_end.ru_nivcsw
- (td->ru_start.ru_nvcsw + td->ru_start.ru_nivcsw);
ts->minf += td->ru_end.ru_minflt - td->ru_start.ru_minflt;
ts->majf += td->ru_end.ru_majflt - td->ru_start.ru_majflt;
memcpy(&td->ru_start, &td->ru_end, sizeof(td->ru_end));
}
/*
* Given a latency, return the index of the corresponding bucket in
* the structure tracking percentiles.
*
* (1) find the group (and error bits) that the value (latency)
* belongs to by looking at its MSB. (2) find the bucket number in the
* group by looking at the index bits.
*
*/
static unsigned int plat_val_to_idx(unsigned long long val)
{
unsigned int msb, error_bits, base, offset, idx;
/* Find MSB starting from bit 0 */
if (val == 0)
msb = 0;
else
msb = (sizeof(val)*8) - __builtin_clzll(val) - 1;
/*
* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
* all bits of the sample as index
*/
if (msb <= FIO_IO_U_PLAT_BITS)
return val;
/* Compute the number of error bits to discard*/
error_bits = msb - FIO_IO_U_PLAT_BITS;
/* Compute the number of buckets before the group */
base = (error_bits + 1) << FIO_IO_U_PLAT_BITS;
/*
* Discard the error bits and apply the mask to find the
* index for the buckets in the group
*/
offset = (FIO_IO_U_PLAT_VAL - 1) & (val >> error_bits);
/* Make sure the index does not exceed (array size - 1) */
idx = (base + offset) < (FIO_IO_U_PLAT_NR - 1) ?
(base + offset) : (FIO_IO_U_PLAT_NR - 1);
return idx;
}
/*
* Convert the given index of the bucket array to the value
* represented by the bucket
*/
static unsigned long long plat_idx_to_val(unsigned int idx)
{
unsigned int error_bits;
unsigned long long k, base;
assert(idx < FIO_IO_U_PLAT_NR);
/* MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use
* all bits of the sample as index */
if (idx < (FIO_IO_U_PLAT_VAL << 1))
return idx;
/* Find the group and compute the minimum value of that group */
error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1;
base = ((unsigned long long) 1) << (error_bits + FIO_IO_U_PLAT_BITS);
/* Find its bucket number of the group */
k = idx % FIO_IO_U_PLAT_VAL;
/* Return the mean of the range of the bucket */
return base + ((k + 0.5) * (1 << error_bits));
}
static int double_cmp(const void *a, const void *b)
{
const fio_fp64_t fa = *(const fio_fp64_t *) a;
const fio_fp64_t fb = *(const fio_fp64_t *) b;
int cmp = 0;
if (fa.u.f > fb.u.f)
cmp = 1;
else if (fa.u.f < fb.u.f)
cmp = -1;
return cmp;
}
unsigned int calc_clat_percentiles(uint64_t *io_u_plat, unsigned long long nr,
fio_fp64_t *plist, unsigned long long **output,
unsigned long long *maxv, unsigned long long *minv)
{
unsigned long long sum = 0;
unsigned int len, i, j = 0;
unsigned long long *ovals = NULL;
bool is_last;
*minv = -1ULL;
*maxv = 0;
len = 0;
while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
len++;
if (!len)
return 0;
/*
* Sort the percentile list. Note that it may already be sorted if
* we are using the default values, but since it's a short list this
* isn't a worry. Also note that this does not work for NaN values.
*/
if (len > 1)
qsort(plist, len, sizeof(plist[0]), double_cmp);
ovals = malloc(len * sizeof(*ovals));
if (!ovals)
return 0;
/*
* Calculate bucket values, note down max and min values
*/
is_last = false;
for (i = 0; i < FIO_IO_U_PLAT_NR && !is_last; i++) {
sum += io_u_plat[i];
while (sum >= ((long double) plist[j].u.f / 100.0 * nr)) {
assert(plist[j].u.f <= 100.0);
ovals[j] = plat_idx_to_val(i);
if (ovals[j] < *minv)
*minv = ovals[j];
if (ovals[j] > *maxv)
*maxv = ovals[j];
is_last = (j == len - 1) != 0;
if (is_last)
break;
j++;
}
}
if (!is_last)
log_err("fio: error calculating latency percentiles\n");
*output = ovals;
return len;
}
/*
* Find and display the p-th percentile of clat
*/
static void show_clat_percentiles(uint64_t *io_u_plat, unsigned long long nr,
fio_fp64_t *plist, unsigned int precision,
const char *pre, struct buf_output *out)
{
unsigned int divisor, len, i, j = 0;
unsigned long long minv, maxv;
unsigned long long *ovals;
int per_line, scale_down, time_width;
bool is_last;
char fmt[32];
len = calc_clat_percentiles(io_u_plat, nr, plist, &ovals, &maxv, &minv);
if (!len || !ovals)
return;
/*
* We default to nsecs, but if the value range is such that we
* should scale down to usecs or msecs, do that.
*/
if (minv > 2000000 && maxv > 99999999ULL) {
scale_down = 2;
divisor = 1000000;
log_buf(out, " %s percentiles (msec):\n |", pre);
} else if (minv > 2000 && maxv > 99999) {
scale_down = 1;
divisor = 1000;
log_buf(out, " %s percentiles (usec):\n |", pre);
} else {
scale_down = 0;
divisor = 1;
log_buf(out, " %s percentiles (nsec):\n |", pre);
}
time_width = max(5, (int) (log10(maxv / divisor) + 1));
snprintf(fmt, sizeof(fmt), " %%%u.%ufth=[%%%dllu]%%c", precision + 3,
precision, time_width);
/* fmt will be something like " %5.2fth=[%4llu]%c" */
per_line = (80 - 7) / (precision + 10 + time_width);
for (j = 0; j < len; j++) {
/* for formatting */
if (j != 0 && (j % per_line) == 0)
log_buf(out, " |");
/* end of the list */
is_last = (j == len - 1) != 0;
for (i = 0; i < scale_down; i++)
ovals[j] = (ovals[j] + 999) / 1000;
log_buf(out, fmt, plist[j].u.f, ovals[j], is_last ? '\n' : ',');
if (is_last)
break;
if ((j % per_line) == per_line - 1) /* for formatting */
log_buf(out, "\n");
}
free(ovals);
}
static int get_nr_prios_with_samples(struct thread_stat *ts, enum fio_ddir ddir)
{
int i, nr_prios_with_samples = 0;
for (i = 0; i < ts->nr_clat_prio[ddir]; i++) {
if (ts->clat_prio[ddir][i].clat_stat.samples)
nr_prios_with_samples++;
}
return nr_prios_with_samples;
}
bool calc_lat(struct io_stat *is, unsigned long long *min,
unsigned long long *max, double *mean, double *dev)
{
double n = (double) is->samples;
if (n == 0)
return false;
*min = is->min_val;
*max = is->max_val;
*mean = is->mean.u.f;
if (n > 1.0)
*dev = sqrt(is->S.u.f / (n - 1.0));
else
*dev = 0;
return true;
}
void show_mixed_group_stats(struct group_run_stats *rs, struct buf_output *out)
{
char *io, *agg, *min, *max;
char *ioalt, *aggalt, *minalt, *maxalt;
uint64_t io_mix = 0, agg_mix = 0, min_mix = -1, max_mix = 0;
uint64_t min_run = -1, max_run = 0;
const int i2p = is_power_of_2(rs->kb_base);
int i;
for (i = 0; i < DDIR_RWDIR_CNT; i++) {
if (!rs->max_run[i])
continue;
io_mix += rs->iobytes[i];
agg_mix += rs->agg[i];
min_mix = min_mix < rs->min_bw[i] ? min_mix : rs->min_bw[i];
max_mix = max_mix > rs->max_bw[i] ? max_mix : rs->max_bw[i];
min_run = min_run < rs->min_run[i] ? min_run : rs->min_run[i];
max_run = max_run > rs->max_run[i] ? max_run : rs->max_run[i];
}
io = num2str(io_mix, rs->sig_figs, 1, i2p, N2S_BYTE);
ioalt = num2str(io_mix, rs->sig_figs, 1, !i2p, N2S_BYTE);
agg = num2str(agg_mix, rs->sig_figs, 1, i2p, rs->unit_base);
aggalt = num2str(agg_mix, rs->sig_figs, 1, !i2p, rs->unit_base);
min = num2str(min_mix, rs->sig_figs, 1, i2p, rs->unit_base);
minalt = num2str(min_mix, rs->sig_figs, 1, !i2p, rs->unit_base);
max = num2str(max_mix, rs->sig_figs, 1, i2p, rs->unit_base);
maxalt = num2str(max_mix, rs->sig_figs, 1, !i2p, rs->unit_base);
log_buf(out, " MIXED: bw=%s (%s), %s-%s (%s-%s), io=%s (%s), run=%llu-%llumsec\n",
agg, aggalt, min, max, minalt, maxalt, io, ioalt,
(unsigned long long) min_run,
(unsigned long long) max_run);
free(io);
free(agg);
free(min);
free(max);
free(ioalt);
free(aggalt);
free(minalt);
free(maxalt);
}
void show_group_stats(struct group_run_stats *rs, struct buf_output *out)
{
char *io, *agg, *min, *max;
char *ioalt, *aggalt, *minalt, *maxalt;
const char *str[] = { " READ", " WRITE" , " TRIM"};
int i;
log_buf(out, "\nRun status group %d (all jobs):\n", rs->groupid);
for (i = 0; i < DDIR_RWDIR_CNT; i++) {
const int i2p = is_power_of_2(rs->kb_base);
if (!rs->max_run[i])
continue;
io = num2str(rs->iobytes[i], rs->sig_figs, 1, i2p, N2S_BYTE);
ioalt = num2str(rs->iobytes[i], rs->sig_figs, 1, !i2p, N2S_BYTE);
agg = num2str(rs->agg[i], rs->sig_figs, 1, i2p, rs->unit_base);
aggalt = num2str(rs->agg[i], rs->sig_figs, 1, !i2p, rs->unit_base);
min = num2str(rs->min_bw[i], rs->sig_figs, 1, i2p, rs->unit_base);
minalt = num2str(rs->min_bw[i], rs->sig_figs, 1, !i2p, rs->unit_base);
max = num2str(rs->max_bw[i], rs->sig_figs, 1, i2p, rs->unit_base);
maxalt = num2str(rs->max_bw[i], rs->sig_figs, 1, !i2p, rs->unit_base);
log_buf(out, "%s: bw=%s (%s), %s-%s (%s-%s), io=%s (%s), run=%llu-%llumsec\n",
(rs->unified_rw_rep == UNIFIED_MIXED) ? " MIXED" : str[i],
agg, aggalt, min, max, minalt, maxalt, io, ioalt,
(unsigned long long) rs->min_run[i],
(unsigned long long) rs->max_run[i]);
free(io);
free(agg);
free(min);
free(max);
free(ioalt);
free(aggalt);
free(minalt);
free(maxalt);
}
/* Need to aggregate statistics to show mixed values */
if (rs->unified_rw_rep == UNIFIED_BOTH)
show_mixed_group_stats(rs, out);
}
void stat_calc_dist(uint64_t *map, unsigned long total, double *io_u_dist)
{
int i;
/*
* Do depth distribution calculations
*/
for (i = 0; i < FIO_IO_U_MAP_NR; i++) {
if (total) {
io_u_dist[i] = (double) map[i] / (double) total;
io_u_dist[i] *= 100.0;
if (io_u_dist[i] < 0.1 && map[i])
io_u_dist[i] = 0.1;
} else
io_u_dist[i] = 0.0;
}
}
static void stat_calc_lat(struct thread_stat *ts, double *dst,
uint64_t *src, int nr)
{
unsigned long total = ddir_rw_sum(ts->total_io_u);
int i;
/*
* Do latency distribution calculations
*/
for (i = 0; i < nr; i++) {
if (total) {
dst[i] = (double) src[i] / (double) total;
dst[i] *= 100.0;
if (dst[i] < 0.01 && src[i])
dst[i] = 0.01;
} else
dst[i] = 0.0;
}
}
/*
* To keep the terse format unaltered, add all of the ns latency
* buckets to the first us latency bucket
*/
static void stat_calc_lat_nu(struct thread_stat *ts, double *io_u_lat_u)
{
unsigned long ntotal = 0, total = ddir_rw_sum(ts->total_io_u);
int i;
stat_calc_lat(ts, io_u_lat_u, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
for (i = 0; i < FIO_IO_U_LAT_N_NR; i++)
ntotal += ts->io_u_lat_n[i];
io_u_lat_u[0] += 100.0 * (double) ntotal / (double) total;
}
void stat_calc_lat_n(struct thread_stat *ts, double *io_u_lat)
{
stat_calc_lat(ts, io_u_lat, ts->io_u_lat_n, FIO_IO_U_LAT_N_NR);
}
void stat_calc_lat_u(struct thread_stat *ts, double *io_u_lat)
{
stat_calc_lat(ts, io_u_lat, ts->io_u_lat_u, FIO_IO_U_LAT_U_NR);
}
void stat_calc_lat_m(struct thread_stat *ts, double *io_u_lat)
{
stat_calc_lat(ts, io_u_lat, ts->io_u_lat_m, FIO_IO_U_LAT_M_NR);
}
static void display_lat(const char *name, unsigned long long min,
unsigned long long max, double mean, double dev,
struct buf_output *out)
{
const char *base = "(nsec)";
char *minp, *maxp;
if (nsec_to_msec(&min, &max, &mean, &dev))
base = "(msec)";
else if (nsec_to_usec(&min, &max, &mean, &dev))
base = "(usec)";
minp = num2str(min, 6, 1, 0, N2S_NONE);
maxp = num2str(max, 6, 1, 0, N2S_NONE);
log_buf(out, " %s %s: min=%s, max=%s, avg=%5.02f,"
" stdev=%5.02f\n", name, base, minp, maxp, mean, dev);
free(minp);
free(maxp);
}
static struct thread_stat *gen_mixed_ddir_stats_from_ts(struct thread_stat *ts)
{
struct thread_stat *ts_lcl;
/*
* Handle aggregation of Reads (ddir = 0), Writes (ddir = 1), and
* Trims (ddir = 2)
*/
ts_lcl = malloc(sizeof(struct thread_stat));
if (!ts_lcl) {
log_err("fio: failed to allocate local thread stat\n");
return NULL;
}
init_thread_stat(ts_lcl);
/* calculate mixed stats */
ts_lcl->unified_rw_rep = UNIFIED_MIXED;
ts_lcl->lat_percentiles = ts->lat_percentiles;
ts_lcl->clat_percentiles = ts->clat_percentiles;
ts_lcl->slat_percentiles = ts->slat_percentiles;
ts_lcl->percentile_precision = ts->percentile_precision;
memcpy(ts_lcl->percentile_list, ts->percentile_list, sizeof(ts->percentile_list));
sum_thread_stats(ts_lcl, ts);
return ts_lcl;
}
static double convert_agg_kbytes_percent(struct group_run_stats *rs,
enum fio_ddir ddir, int mean)
{
double p_of_agg = 100.0;
if (rs && rs->agg[ddir] > 1024) {
p_of_agg = mean * 100.0 / (double) (rs->agg[ddir] / 1024.0);
if (p_of_agg > 100.0)
p_of_agg = 100.0;
}
return p_of_agg;
}
static void show_ddir_status(struct group_run_stats *rs, struct thread_stat *ts,
enum fio_ddir ddir, struct buf_output *out)
{
unsigned long runt;
unsigned long long min, max, bw, iops;
double mean, dev;
char *io_p, *bw_p, *bw_p_alt, *iops_p, *post_st = NULL;
int i2p, i;
const char *clat_type = ts->lat_percentiles ? "lat" : "clat";
if (ddir_sync(ddir)) {
if (calc_lat(&ts->sync_stat, &min, &max, &mean, &dev)) {
log_buf(out, " %s:\n", "fsync/fdatasync/sync_file_range");
display_lat(io_ddir_name(ddir), min, max, mean, dev, out);
show_clat_percentiles(ts->io_u_sync_plat,
ts->sync_stat.samples,
ts->percentile_list,
ts->percentile_precision,
io_ddir_name(ddir), out);
}
return;
}
assert(ddir_rw(ddir));
if (!ts->runtime[ddir])
return;
i2p = is_power_of_2(rs->kb_base);
runt = ts->runtime[ddir];
bw = (1000 * ts->io_bytes[ddir]) / runt;
io_p = num2str(ts->io_bytes[ddir], ts->sig_figs, 1, i2p, N2S_BYTE);
bw_p = num2str(bw, ts->sig_figs, 1, i2p, ts->unit_base);
bw_p_alt = num2str(bw, ts->sig_figs, 1, !i2p, ts->unit_base);
iops = (1000 * (uint64_t)ts->total_io_u[ddir]) / runt;
iops_p = num2str(iops, ts->sig_figs, 1, 0, N2S_NONE);
if (ddir == DDIR_WRITE || ddir == DDIR_TRIM)
post_st = zbd_write_status(ts);
else if (ddir == DDIR_READ && ts->cachehit && ts->cachemiss) {
uint64_t total;
double hit;
total = ts->cachehit + ts->cachemiss;
hit = (double) ts->cachehit / (double) total;
hit *= 100.0;
if (asprintf(&post_st, "; Cachehit=%0.2f%%", hit) < 0)
post_st = NULL;
}
log_buf(out, " %s: IOPS=%s, BW=%s (%s)(%s/%llumsec)%s\n",
(ts->unified_rw_rep == UNIFIED_MIXED) ? "mixed" : io_ddir_name(ddir),
iops_p, bw_p, bw_p_alt, io_p,
(unsigned long long) ts->runtime[ddir],
post_st ? : "");
free(post_st);
free(io_p);
free(bw_p);
free(bw_p_alt);
free(iops_p);
if (calc_lat(&ts->slat_stat[ddir], &min, &max, &mean, &dev))
display_lat("slat", min, max, mean, dev, out);
if (calc_lat(&ts->clat_stat[ddir], &min, &max, &mean, &dev))
display_lat("clat", min, max, mean, dev, out);
if (calc_lat(&ts->lat_stat[ddir], &min, &max, &mean, &dev))
display_lat(" lat", min, max, mean, dev, out);
/* Only print per prio stats if there are >= 2 prios with samples */
if (get_nr_prios_with_samples(ts, ddir) >= 2) {
for (i = 0; i < ts->nr_clat_prio[ddir]; i++) {
char buf[64];
if (!calc_lat(&ts->clat_prio[ddir][i].clat_stat, &min,
&max, &mean, &dev))
continue;
snprintf(buf, sizeof(buf),
"%s prio %u/%u/%u",
clat_type,
ioprio_class(ts->clat_prio[ddir][i].ioprio),
ioprio(ts->clat_prio[ddir][i].ioprio),
ioprio_hint(ts->clat_prio[ddir][i].ioprio));
display_lat(buf, min, max, mean, dev, out);
}
}
if (ts->slat_percentiles && ts->slat_stat[ddir].samples > 0)
show_clat_percentiles(ts->io_u_plat[FIO_SLAT][ddir],
ts->slat_stat[ddir].samples,
ts->percentile_list,
ts->percentile_precision, "slat", out);
if (ts->clat_percentiles && ts->clat_stat[ddir].samples > 0)
show_clat_percentiles(ts->io_u_plat[FIO_CLAT][ddir],
ts->clat_stat[ddir].samples,
ts->percentile_list,
ts->percentile_precision, "clat", out);
if (ts->lat_percentiles && ts->lat_stat[ddir].samples > 0)
show_clat_percentiles(ts->io_u_plat[FIO_LAT][ddir],
ts->lat_stat[ddir].samples,
ts->percentile_list,
ts->percentile_precision, "lat", out);
if (ts->clat_percentiles || ts->lat_percentiles) {
char prio_name[64];
uint64_t samples;
if (ts->lat_percentiles)
samples = ts->lat_stat[ddir].samples;
else
samples = ts->clat_stat[ddir].samples;
/* Only print per prio stats if there are >= 2 prios with samples */
if (get_nr_prios_with_samples(ts, ddir) >= 2) {
for (i = 0; i < ts->nr_clat_prio[ddir]; i++) {
uint64_t prio_samples =
ts->clat_prio[ddir][i].clat_stat.samples;
if (!prio_samples)
continue;
snprintf(prio_name, sizeof(prio_name),
"%s prio %u/%u/%u (%.2f%% of IOs)",
clat_type,
ioprio_class(ts->clat_prio[ddir][i].ioprio),
ioprio(ts->clat_prio[ddir][i].ioprio),
ioprio_hint(ts->clat_prio[ddir][i].ioprio),
100. * (double) prio_samples / (double) samples);
show_clat_percentiles(ts->clat_prio[ddir][i].io_u_plat,
prio_samples, ts->percentile_list,
ts->percentile_precision,
prio_name, out);
}
}
}
if (calc_lat(&ts->bw_stat[ddir], &min, &max, &mean, &dev)) {
double p_of_agg = 100.0, fkb_base = (double)rs->kb_base;
const char *bw_str;
if ((rs->unit_base == 1) && i2p)
bw_str = "Kibit";
else if (rs->unit_base == 1)
bw_str = "kbit";
else if (i2p)
bw_str = "KiB";
else
bw_str = "kB";
p_of_agg = convert_agg_kbytes_percent(rs, ddir, mean);
if (rs->unit_base == 1) {
min *= 8.0;
max *= 8.0;
mean *= 8.0;
dev *= 8.0;
}
if (mean > fkb_base * fkb_base) {
min /= fkb_base;
max /= fkb_base;
mean /= fkb_base;
dev /= fkb_base;
bw_str = (rs->unit_base == 1 ? "Mibit" : "MiB");
}
log_buf(out, " bw (%5s/s): min=%5llu, max=%5llu, per=%3.2f%%, "
"avg=%5.02f, stdev=%5.02f, samples=%" PRIu64 "\n",
bw_str, min, max, p_of_agg, mean, dev,
(&ts->bw_stat[ddir])->samples);
}
if (calc_lat(&ts->iops_stat[ddir], &min, &max, &mean, &dev)) {
log_buf(out, " iops : min=%5llu, max=%5llu, "
"avg=%5.02f, stdev=%5.02f, samples=%" PRIu64 "\n",
min, max, mean, dev, (&ts->iops_stat[ddir])->samples);
}
}
static void show_mixed_ddir_status(struct group_run_stats *rs,
struct thread_stat *ts,
struct buf_output *out)
{
struct thread_stat *ts_lcl = gen_mixed_ddir_stats_from_ts(ts);
if (ts_lcl)
show_ddir_status(rs, ts_lcl, DDIR_READ, out);
free_clat_prio_stats(ts_lcl);
free(ts_lcl);
}
static bool show_lat(double *io_u_lat, int nr, const char **ranges,
const char *msg, struct buf_output *out)
{
bool new_line = true, shown = false;
int i, line = 0;
for (i = 0; i < nr; i++) {
if (io_u_lat[i] <= 0.0)
continue;
shown = true;
if (new_line) {
if (line)
log_buf(out, "\n");
log_buf(out, " lat (%s) : ", msg);
new_line = false;
line = 0;
}
if (line)
log_buf(out, ", ");
log_buf(out, "%s%3.2f%%", ranges[i], io_u_lat[i]);
line++;
if (line == 5)
new_line = true;
}
if (shown)
log_buf(out, "\n");
return true;
}
static void show_lat_n(double *io_u_lat_n, struct buf_output *out)
{
const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
"250=", "500=", "750=", "1000=", };
show_lat(io_u_lat_n, FIO_IO_U_LAT_N_NR, ranges, "nsec", out);
}
static void show_lat_u(double *io_u_lat_u, struct buf_output *out)
{
const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
"250=", "500=", "750=", "1000=", };
show_lat(io_u_lat_u, FIO_IO_U_LAT_U_NR, ranges, "usec", out);
}
static void show_lat_m(double *io_u_lat_m, struct buf_output *out)
{
const char *ranges[] = { "2=", "4=", "10=", "20=", "50=", "100=",
"250=", "500=", "750=", "1000=", "2000=",
">=2000=", };
show_lat(io_u_lat_m, FIO_IO_U_LAT_M_NR, ranges, "msec", out);
}
static void show_latencies(struct thread_stat *ts, struct buf_output *out)
{
double io_u_lat_n[FIO_IO_U_LAT_N_NR];
double io_u_lat_u[FIO_IO_U_LAT_U_NR];
double io_u_lat_m[FIO_IO_U_LAT_M_NR];
stat_calc_lat_n(ts, io_u_lat_n);
stat_calc_lat_u(ts, io_u_lat_u);
stat_calc_lat_m(ts, io_u_lat_m);
show_lat_n(io_u_lat_n, out);
show_lat_u(io_u_lat_u, out);
show_lat_m(io_u_lat_m, out);
}
static int block_state_category(int block_state)
{
switch (block_state) {
case BLOCK_STATE_UNINIT:
return 0;
case BLOCK_STATE_TRIMMED:
case BLOCK_STATE_WRITTEN:
return 1;
case BLOCK_STATE_WRITE_FAILURE:
case BLOCK_STATE_TRIM_FAILURE:
return 2;
default:
/* Silence compile warning on some BSDs and have a return */
assert(0);
return -1;
}
}
static int compare_block_infos(const void *bs1, const void *bs2)
{
uint64_t block1 = *(uint64_t *)bs1;
uint64_t block2 = *(uint64_t *)bs2;
int state1 = BLOCK_INFO_STATE(block1);
int state2 = BLOCK_INFO_STATE(block2);
int bscat1 = block_state_category(state1);
int bscat2 = block_state_category(state2);
int cycles1 = BLOCK_INFO_TRIMS(block1);
int cycles2 = BLOCK_INFO_TRIMS(block2);
if (bscat1 < bscat2)
return -1;
if (bscat1 > bscat2)
return 1;
if (cycles1 < cycles2)
return -1;
if (cycles1 > cycles2)
return 1;
if (state1 < state2)
return -1;
if (state1 > state2)
return 1;
assert(block1 == block2);
return 0;
}
static int calc_block_percentiles(int nr_block_infos, uint32_t *block_infos,
fio_fp64_t *plist, unsigned int **percentiles,
unsigned int *types)
{
int len = 0;
int i, nr_uninit;
qsort(block_infos, nr_block_infos, sizeof(uint32_t), compare_block_infos);
while (len < FIO_IO_U_LIST_MAX_LEN && plist[len].u.f != 0.0)
len++;
if (!len)
return 0;
/*
* Sort the percentile list. Note that it may already be sorted if
* we are using the default values, but since it's a short list this
* isn't a worry. Also note that this does not work for NaN values.
*/
if (len > 1)
qsort(plist, len, sizeof(plist[0]), double_cmp);
/* Start only after the uninit entries end */
for (nr_uninit = 0;
nr_uninit < nr_block_infos
&& BLOCK_INFO_STATE(block_infos[nr_uninit]) == BLOCK_STATE_UNINIT;
nr_uninit ++)
;
if (nr_uninit == nr_block_infos)
return 0;
*percentiles = calloc(len, sizeof(**percentiles));
for (i = 0; i < len; i++) {
int idx = (plist[i].u.f * (nr_block_infos - nr_uninit) / 100)
+ nr_uninit;
(*percentiles)[i] = BLOCK_INFO_TRIMS(block_infos[idx]);
}
memset(types, 0, sizeof(*types) * BLOCK_STATE_COUNT);
for (i = 0; i < nr_block_infos; i++)
types[BLOCK_INFO_STATE(block_infos[i])]++;
return len;
}
static const char *block_state_names[] = {
[BLOCK_STATE_UNINIT] = "unwritten",
[BLOCK_STATE_TRIMMED] = "trimmed",
[BLOCK_STATE_WRITTEN] = "written",
[BLOCK_STATE_TRIM_FAILURE] = "trim failure",
[BLOCK_STATE_WRITE_FAILURE] = "write failure",
};
static void show_block_infos(int nr_block_infos, uint32_t *block_infos,
fio_fp64_t *plist, struct buf_output *out)
{
int len, pos, i;
unsigned int *percentiles = NULL;
unsigned int block_state_counts[BLOCK_STATE_COUNT];
len = calc_block_percentiles(nr_block_infos, block_infos, plist,
&percentiles, block_state_counts);
log_buf(out, " block lifetime percentiles :\n |");
pos = 0;
for (i = 0; i < len; i++) {
uint32_t block_info = percentiles[i];
#define LINE_LENGTH 75
char str[LINE_LENGTH];
int strln = snprintf(str, LINE_LENGTH, " %3.2fth=%u%c",
plist[i].u.f, block_info,
i == len - 1 ? '\n' : ',');
assert(strln < LINE_LENGTH);
if (pos + strln > LINE_LENGTH) {
pos = 0;
log_buf(out, "\n |");
}
log_buf(out, "%s", str);
pos += strln;
#undef LINE_LENGTH
}
if (percentiles)
free(percentiles);
log_buf(out, " states :");
for (i = 0; i < BLOCK_STATE_COUNT; i++)
log_buf(out, " %s=%u%c",
block_state_names[i], block_state_counts[i],
i == BLOCK_STATE_COUNT - 1 ? '\n' : ',');
}
static void show_ss_normal(struct thread_stat *ts, struct buf_output *out)
{
char *p1, *p1alt, *p2;
unsigned long long bw_mean, iops_mean;
const int i2p = is_power_of_2(ts->kb_base);
if (!ts->ss_dur)
return;
bw_mean = steadystate_bw_mean(ts);
iops_mean = steadystate_iops_mean(ts);
p1 = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, i2p, ts->unit_base);
p1alt = num2str(bw_mean / ts->kb_base, ts->sig_figs, ts->kb_base, !i2p, ts->unit_base);
p2 = num2str(iops_mean, ts->sig_figs, 1, 0, N2S_NONE);
log_buf(out, " steadystate : attained=%s, bw=%s (%s), iops=%s, %s%s=%.3f%s\n",
ts->ss_state & FIO_SS_ATTAINED ? "yes" : "no",
p1, p1alt, p2,
ts->ss_state & FIO_SS_IOPS ? "iops" : "bw",
ts->ss_state & FIO_SS_SLOPE ? " slope": " mean dev",
ts->ss_criterion.u.f,
ts->ss_state & FIO_SS_PCT ? "%" : "");
free(p1);
free(p1alt);
free(p2);
}
static void show_agg_stats(struct disk_util_agg *agg, int terse,
struct buf_output *out)
{
if (!agg->slavecount)
return;
if (!terse) {
log_buf(out, ", aggrios=%llu/%llu, aggsectors=%llu/%llu, "
"aggrmerge=%llu/%llu, aggrticks=%llu/%llu, "
"aggrin_queue=%llu, aggrutil=%3.2f%%",
(unsigned long long) agg->ios[0] / agg->slavecount,
(unsigned long long) agg->ios[1] / agg->slavecount,
(unsigned long long) agg->sectors[0] / agg->slavecount,
(unsigned long long) agg->sectors[1] / agg->slavecount,
(unsigned long long) agg->merges[0] / agg->slavecount,
(unsigned long long) agg->merges[1] / agg->slavecount,
(unsigned long long) agg->ticks[0] / agg->slavecount,
(unsigned long long) agg->ticks[1] / agg->slavecount,
(unsigned long long) agg->time_in_queue / agg->slavecount,
agg->max_util.u.f);
} else {
log_buf(out, ";slaves;%llu;%llu;%llu;%llu;%llu;%llu;%llu;%3.2f%%",
(unsigned long long) agg->ios[0] / agg->slavecount,
(unsigned long long) agg->ios[1] / agg->slavecount,
(unsigned long long) agg->merges[0] / agg->slavecount,
(unsigned long long) agg->merges[1] / agg->slavecount,
(unsigned long long) agg->ticks[0] / agg->slavecount,
(unsigned long long) agg->ticks[1] / agg->slavecount,
(unsigned long long) agg->time_in_queue / agg->slavecount,
agg->max_util.u.f);
}
}
static void aggregate_slaves_stats(struct disk_util *masterdu)
{
struct disk_util_agg *agg = &masterdu->agg;
struct disk_util_stat *dus;