koder aka kdanilov | 23e6bdf | 2016-12-24 02:18:54 +0200 | [diff] [blame] | 1 | from typing import List |
| 2 | |
| 3 | |
| 4 | expected_lat_bins = 1216 |
| 5 | |
| 6 | |
| 7 | #---------------------------- FIO HIST LOG PARSE CODE ----------------------------------------------------------------- |
| 8 | |
| 9 | # Copy-paste from fio/tools/hist/fiologparser_hist.py. |
| 10 | # Because that's impossible to understand or improve, |
| 11 | # you can only copy such a pearl. |
| 12 | |
| 13 | def _plat_idx_to_val(idx: int , edge: float = 0.5, FIO_IO_U_PLAT_BITS: int = 6, FIO_IO_U_PLAT_VAL: int = 64) -> float: |
| 14 | """ Taken from fio's stat.c for calculating the latency value of a bin |
| 15 | from that bin's index. |
| 16 | |
| 17 | idx : the value of the index into the histogram bins |
| 18 | edge : fractional value in the range [0,1]** indicating how far into |
| 19 | the bin we wish to compute the latency value of. |
| 20 | |
| 21 | ** edge = 0.0 and 1.0 computes the lower and upper latency bounds |
| 22 | respectively of the given bin index. """ |
| 23 | |
| 24 | # MSB <= (FIO_IO_U_PLAT_BITS-1), cannot be rounded off. Use |
| 25 | # all bits of the sample as index |
| 26 | if (idx < (FIO_IO_U_PLAT_VAL << 1)): |
| 27 | return idx |
| 28 | |
| 29 | # Find the group and compute the minimum value of that group |
| 30 | error_bits = (idx >> FIO_IO_U_PLAT_BITS) - 1 |
| 31 | base = 1 << (error_bits + FIO_IO_U_PLAT_BITS) |
| 32 | |
| 33 | # Find its bucket number of the group |
| 34 | k = idx % FIO_IO_U_PLAT_VAL |
| 35 | |
| 36 | # Return the mean (if edge=0.5) of the range of the bucket |
| 37 | return base + ((k + edge) * (1 << error_bits)) |
| 38 | |
| 39 | |
| 40 | def plat_idx_to_val_coarse(idx: int, coarseness: int, edge: float = 0.5) -> float: |
| 41 | """ Converts the given *coarse* index into a non-coarse index as used by fio |
| 42 | in stat.h:plat_idx_to_val(), subsequently computing the appropriate |
| 43 | latency value for that bin. |
| 44 | """ |
| 45 | |
| 46 | # Multiply the index by the power of 2 coarseness to get the bin |
| 47 | # bin index with a max of 1536 bins (FIO_IO_U_PLAT_GROUP_NR = 24 in stat.h) |
| 48 | stride = 1 << coarseness |
| 49 | idx = idx * stride |
| 50 | lower = _plat_idx_to_val(idx, edge=0.0) |
| 51 | upper = _plat_idx_to_val(idx + stride, edge=1.0) |
| 52 | return lower + (upper - lower) * edge |
| 53 | |
| 54 | |
| 55 | def get_lat_vals(columns: int = 1216, coarseness: int = 0) -> List[float]: |
| 56 | return [plat_idx_to_val_coarse(val, coarseness) for val in range(columns)] |
| 57 | |