| 1 | import sys |
| 2 | from _typeshed import StrOrBytesPath |
| 3 | from collections.abc import Iterable |
| 4 | from cProfile import Profile as _cProfile |
| 5 | from dataclasses import dataclass |
| 6 | from profile import Profile |
| 7 | from typing import IO, Any, Literal, overload |
| 8 | from typing_extensions import Self, TypeAlias |
| 9 | |
| 10 | if sys.version_info >= (3, 11): |
| 11 | from enum import StrEnum |
| 12 | else: |
| 13 | from enum import Enum |
| 14 | |
| 15 | __all__ = ["Stats", "SortKey", "FunctionProfile", "StatsProfile"] |
| 16 | |
| 17 | _Selector: TypeAlias = str | float | int |
| 18 | |
| 19 | if sys.version_info >= (3, 11): |
| 20 | class SortKey(StrEnum): |
| 21 | CALLS = "calls" |
| 22 | CUMULATIVE = "cumulative" |
| 23 | FILENAME = "filename" |
| 24 | LINE = "line" |
| 25 | NAME = "name" |
| 26 | NFL = "nfl" |
| 27 | PCALLS = "pcalls" |
| 28 | STDNAME = "stdname" |
| 29 | TIME = "time" |
| 30 | |
| 31 | else: |
| 32 | class SortKey(str, Enum): |
| 33 | CALLS = "calls" |
| 34 | CUMULATIVE = "cumulative" |
| 35 | FILENAME = "filename" |
| 36 | LINE = "line" |
| 37 | NAME = "name" |
| 38 | NFL = "nfl" |
| 39 | PCALLS = "pcalls" |
| 40 | STDNAME = "stdname" |
| 41 | TIME = "time" |
| 42 | |
| 43 | @dataclass(unsafe_hash=True) |
| 44 | class FunctionProfile: |
| 45 | ncalls: str |
| 46 | tottime: float |
| 47 | percall_tottime: float |
| 48 | cumtime: float |
| 49 | percall_cumtime: float |
| 50 | file_name: str |
| 51 | line_number: int |
| 52 | |
| 53 | @dataclass(unsafe_hash=True) |
| 54 | class StatsProfile: |
| 55 | total_tt: float |
| 56 | func_profiles: dict[str, FunctionProfile] |
| 57 | |
| 58 | _SortArgDict: TypeAlias = dict[str, tuple[tuple[tuple[int, int], ...], str]] |
| 59 | |
| 60 | class Stats: |
| 61 | sort_arg_dict_default: _SortArgDict |
| 62 | def __init__( |
| 63 | self, |
| 64 | arg: None | str | Profile | _cProfile = None, |
| 65 | /, |
| 66 | *args: None | str | Profile | _cProfile | Self, |
| 67 | stream: IO[Any] | None = None, |
| 68 | ) -> None: ... |
| 69 | def init(self, arg: None | str | Profile | _cProfile) -> None: ... |
| 70 | def load_stats(self, arg: None | str | Profile | _cProfile) -> None: ... |
| 71 | def get_top_level_stats(self) -> None: ... |
| 72 | def add(self, *arg_list: None | str | Profile | _cProfile | Self) -> Self: ... |
| 73 | def dump_stats(self, filename: StrOrBytesPath) -> None: ... |
| 74 | def get_sort_arg_defs(self) -> _SortArgDict: ... |
| 75 | @overload |
| 76 | def sort_stats(self, field: Literal[-1, 0, 1, 2]) -> Self: ... |
| 77 | @overload |
| 78 | def sort_stats(self, *field: str) -> Self: ... |
| 79 | def reverse_order(self) -> Self: ... |
| 80 | def strip_dirs(self) -> Self: ... |
| 81 | def calc_callees(self) -> None: ... |
| 82 | def eval_print_amount(self, sel: _Selector, list: list[str], msg: str) -> tuple[list[str], str]: ... |
| 83 | def get_stats_profile(self) -> StatsProfile: ... |
| 84 | def get_print_list(self, sel_list: Iterable[_Selector]) -> tuple[int, list[str]]: ... |
| 85 | def print_stats(self, *amount: _Selector) -> Self: ... |
| 86 | def print_callees(self, *amount: _Selector) -> Self: ... |
| 87 | def print_callers(self, *amount: _Selector) -> Self: ... |
| 88 | def print_call_heading(self, name_size: int, column_title: str) -> None: ... |
| 89 | def print_call_line(self, name_size: int, source: str, call_dict: dict[str, Any], arrow: str = "->") -> None: ... |
| 90 | def print_title(self) -> None: ... |
| 91 | def print_line(self, func: str) -> None: ... |