| 1354 | return str(key) |
| 1355 | |
| 1356 | def _downsample( |
| 1357 | self, ticks: list[int], series: dict[str, list[float]], resolution: int, metric: str |
| 1358 | ) -> tuple[list[int], dict[str, list[float]]]: |
| 1359 | bucket_size = max(1, (len(ticks) + resolution - 1) // resolution) |
| 1360 | sampled_ticks = [] |
| 1361 | sampled_series = {label: [] for label in series} |
| 1362 | for index in range(0, len(ticks), bucket_size): |
| 1363 | slice_end = min(index + bucket_size, len(ticks)) |
| 1364 | sampled_ticks.append(ticks[slice_end - 1]) |
| 1365 | for label, values in series.items(): |
| 1366 | chunk = values[index:slice_end] |
| 1367 | if metric == "live": |
| 1368 | sampled_series[label].append(chunk[-1] if chunk else 0.0) |
| 1369 | else: |
| 1370 | sampled_series[label].append(sum(chunk)) |
| 1371 | return sampled_ticks, sampled_series |
| 1372 | |
| 1373 | def _new_stack_tree_node(self, function_id: int) -> dict[str, Any]: |
| 1374 | display_name = self.reader.display_names[function_id] or self.reader.function_names[function_id] or str(function_id) |