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