MCPcopy Create free account
hub / github.com/adny-code/fastgrind / _finalize_stack_tree

Method _finalize_stack_tree

tools/fastgrind.py:1386–1403  ·  view source on GitHub ↗
(self, node: dict[str, Any], metric: str)

Source from the content-addressed store, hash-verified

1384 }
1385
1386 def _finalize_stack_tree(self, node: dict[str, Any], metric: str) -> dict[str, Any]:
1387 sort_metric = "net" if metric == "live" else metric
1388 children = [self._finalize_stack_tree(child, metric) for child in node.get("children", {}).values()]
1389 if sort_metric == "net":
1390 children.sort(key=lambda child: (-abs(float(child["value"])), _stack_node_name(child).casefold()))
1391 else:
1392 children.sort(key=lambda child: (-float(child["value"]), _stack_node_name(child).casefold()))
1393 return {
1394 "thread_id": node.get("thread_id"),
1395 "function_id": node.get("function_id"),
1396 "display_name": node.get("display_name"),
1397 "canonical_name": node.get("canonical_name"),
1398 "malloc": float(node.get("malloc", 0.0)),
1399 "free": float(node.get("free", 0.0)),
1400 "value": self._metric_value(node.get("malloc", 0.0), node.get("free", 0.0), sort_metric),
1401 "children": children,
1402 "child_count": len(children),
1403 }
1404
1405 def _apply_stack_tree_shares(self, tree: dict[str, Any]) -> dict[str, Any]:
1406 total_value = float(tree.get("value", 0.0))

Callers 1

stack_treeMethod · 0.95

Calls 2

_metric_valueMethod · 0.95
_stack_node_nameFunction · 0.85

Tested by

no test coverage detected