(self)
| 180 | return |
| 181 | |
| 182 | def read_record(self) -> None: |
| 183 | while True: |
| 184 | line = self._read_non_empty_line_lower_stripped() |
| 185 | split_line = [x.strip() for x in line.split(",")] |
| 186 | |
| 187 | # End-of-record |
| 188 | if len(split_line) == 1 and split_line[0] == g_params.end_tag: |
| 189 | return |
| 190 | |
| 191 | # Header / meta lines |
| 192 | if len(split_line) == 4 and split_line[0] == 'timestamp' and split_line[1] == 'microsec': |
| 193 | self.data['timestamp'] = int(split_line[2]) |
| 194 | self.date = split_line[3] |
| 195 | continue |
| 196 | |
| 197 | if len(split_line) == 2 and split_line[0] == g_params.label_tag: |
| 198 | self.label = split_line[1] |
| 199 | continue |
| 200 | |
| 201 | if len(split_line) == 2 and split_line[0] == g_params.label_data_source: |
| 202 | self.data_source = split_line[1] |
| 203 | continue |
| 204 | |
| 205 | if len(split_line) == 2 and split_line[0] == g_params.latencyunit_tag: |
| 206 | unit = split_line[1] |
| 207 | if unit not in ('millisec', 'microsec', 'nanosec'): |
| 208 | raise ValueError(f"Cannot understand latency unit in line: {line!r}") |
| 209 | g_params.latency_unit = unit |
| 210 | continue |
| 211 | |
| 212 | # Data lines: <power_of_two_value>,<count> |
| 213 | if len(split_line) != 2: |
| 214 | raise ValueError(f"Cannot process record line: {line!r}") |
| 215 | |
| 216 | try: |
| 217 | power_of_two_val = int(split_line[0]) |
| 218 | count = int(split_line[1]) |
| 219 | bucket = math.log(power_of_two_val, 2.0) |
| 220 | except Exception as exc: |
| 221 | raise ValueError(f"Cannot parse data line: {line!r} ({exc})") from exc |
| 222 | |
| 223 | if abs(int(bucket) - bucket) > 1e-6: |
| 224 | raise ValueError(f"Bucket value must be a power of 2: {line!r}") |
| 225 | bucket = int(bucket) |
| 226 | |
| 227 | # Keep cumulative count for this exponent bucket |
| 228 | self.data[bucket] = self.data.get(bucket, 0) + count |
| 229 | |
| 230 | # ----------------------- Computations & autotune ----------------------- # |
| 231 |
no test coverage detected