ParsePseudoFloat parses the peculiar format produced by bcache's bch_hprint.
(str string)
| 90 | |
| 91 | // ParsePseudoFloat parses the peculiar format produced by bcache's bch_hprint. |
| 92 | func parsePseudoFloat(str string) (float64, error) { |
| 93 | ss := strings.Split(str, ".") |
| 94 | |
| 95 | intPart, err := strconv.ParseFloat(ss[0], 64) |
| 96 | if err != nil { |
| 97 | return 0, err |
| 98 | } |
| 99 | |
| 100 | if len(ss) == 1 { |
| 101 | // Pure integers are fine. |
| 102 | return intPart, nil |
| 103 | } |
| 104 | fracPart, err := strconv.ParseFloat(ss[1], 64) |
| 105 | if err != nil { |
| 106 | return 0, err |
| 107 | } |
| 108 | // fracPart is a number between 0 and 1023 divided by 100; it is off |
| 109 | // by a small amount. Unexpected bumps in time lines may occur because |
| 110 | // for bch_hprint .1 != .10 and .10 > .9 (at least up to Linux |
| 111 | // v4.12-rc3). |
| 112 | |
| 113 | // Restore the proper order: |
| 114 | fracPart /= 10.24 |
| 115 | return intPart + fracPart, nil |
| 116 | } |
| 117 | |
| 118 | // Dehumanize converts a human-readable byte slice into a uint64. |
| 119 | func dehumanize(hbytes []byte) (uint64, error) { |
no outgoing calls