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

Method top_functions

tools/fastgrind.py:927–967  ·  view source on GitHub ↗
(
        self,
        start_ms: int | None = None,
        end_ms: int | None = None,
        thread_ids: Sequence[int] | None = None,
        limit: int = 10,
        metric: str = "net",
        scope: str = "exclusive",
    )

Source from the content-addressed store, hash-verified

925 return SeriesResponse(ticks=ticks, series=series, metric=metric, scope=scope, split=split_mode)
926
927 def top_functions(
928 self,
929 start_ms: int | None = None,
930 end_ms: int | None = None,
931 thread_ids: Sequence[int] | None = None,
932 limit: int = 10,
933 metric: str = "net",
934 scope: str = "exclusive",
935 ) -> list[dict[str, Any]]:
936 metric = _normalize_metric_name(metric)
937 start_tick, end_tick = self._normalize_window(start_ms, end_ms)
938 selected_threads = self._normalize_thread_ids(thread_ids)
939 totals: dict[int, float] = defaultdict(float)
940
941 for _tick_ms, _thread_id, leaf_node_id, malloc_bytes, free_bytes in self._iter_records(
942 start_tick, end_tick, selected_threads
943 ):
944 value = float(self._metric_value(malloc_bytes, free_bytes, "net" if metric == "live" else metric))
945 if scope == "exclusive":
946 function_ids = (self.reader.stack_nodes[leaf_node_id].function_id,)
947 else:
948 function_ids = self.reader.node_paths[leaf_node_id]
949 for function_id in function_ids:
950 totals[function_id] += value
951
952 rows = []
953 for function_id, value in totals.items():
954 rows.append(
955 {
956 "function_id": function_id,
957 "display_name": self.reader.display_names[function_id],
958 "canonical_name": self.reader.function_names[function_id],
959 "value": value,
960 }
961 )
962
963 if metric == "net":
964 rows.sort(key=lambda row: (-abs(row["value"]), row["display_name"].casefold()))
965 else:
966 rows.sort(key=lambda row: (-row["value"], row["display_name"].casefold()))
967 return rows[:limit]
968
969 def stack_breakdown(
970 self,

Callers 5

list_functionsMethod · 0.95
export_html_snapshotMethod · 0.95
query_bundleMethod · 0.95
_dispatchMethod · 0.80
_on_plot_clickMethod · 0.80

Calls 5

_normalize_windowMethod · 0.95
_normalize_thread_idsMethod · 0.95
_iter_recordsMethod · 0.95
_metric_valueMethod · 0.95
_normalize_metric_nameFunction · 0.85

Tested by

no test coverage detected