Skip to content

add _lsprof module #11159

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions stdlib/VERSIONS
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ _heapq: 2.7-
_imp: 3.0-
_json: 2.7-
_locale: 2.7-
_lsprof: 2.7-
_markupbase: 2.7-
_msi: 2.7-
_operator: 3.4-
Expand Down
36 changes: 36 additions & 0 deletions stdlib/_lsprof.pyi
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import sys
from _typeshed import structseq
from collections.abc import Callable
from types import CodeType
from typing import Any
from typing_extensions import Final, final

class Profiler:
def __init__(
self, timer: Callable[[], float] | None = None, timeunit: float = 0.0, subcalls: bool = True, builtins: bool = True
) -> None: ...
def getstats(self) -> list[profiler_entry]: ...
def enable(self, subcalls: bool = True, builtins: bool = True) -> None: ...
def disable(self) -> None: ...
def clear(self) -> None: ...

@final
class profiler_entry(structseq[Any], tuple[CodeType | str, int, int, float, float, list[profiler_subentry]]):
if sys.version_info >= (3, 10):
__match_args__: Final = ("code", "callcount", "reccallcount", "totaltime", "inlinetime", "calls")
code: CodeType | str
callcount: int
reccallcount: int
totaltime: float
inlinetime: float
calls: list[profiler_subentry]

@final
class profiler_subentry(structseq[Any], tuple[CodeType | str, int, int, float, float]):
if sys.version_info >= (3, 10):
__match_args__: Final = ("code", "callcount", "reccallcount", "totaltime", "inlinetime")
code: CodeType | str
callcount: int
reccallcount: int
totaltime: float
inlinetime: float
9 changes: 3 additions & 6 deletions stdlib/cProfile.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ from types import CodeType
from typing import Any, TypeVar
from typing_extensions import ParamSpec, Self, TypeAlias

import _lsprof

__all__ = ["run", "runctx", "Profile"]

def run(statement: str, filename: str | None = None, sort: str | int = -1) -> None: ...
Expand All @@ -16,13 +18,8 @@ _T = TypeVar("_T")
_P = ParamSpec("_P")
_Label: TypeAlias = tuple[str, int, str]

class Profile:
class Profile(_lsprof.Profiler):
stats: dict[_Label, tuple[int, int, int, int, dict[_Label, tuple[int, int, int, int]]]] # undocumented
def __init__(
self, timer: Callable[[], float] = ..., timeunit: float = ..., subcalls: bool = ..., builtins: bool = ...
) -> None: ...
def enable(self) -> None: ...
def disable(self) -> None: ...
def print_stats(self, sort: str | int = -1) -> None: ...
def dump_stats(self, file: StrOrBytesPath) -> None: ...
def create_stats(self) -> None: ...
Expand Down