Skip to content

Commit e31d00c

Browse files
committed
Make profiling sampling a stub package
1 parent dc817c4 commit e31d00c

9 files changed

Lines changed: 164 additions & 101 deletions

File tree

stdlib/profiling/sampling.pyi

Lines changed: 0 additions & 101 deletions
This file was deleted.
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
from .collector import Collector as Collector
2+
from .gecko_collector import GeckoCollector as GeckoCollector
3+
from .heatmap_collector import HeatmapCollector as HeatmapCollector
4+
from .jsonl_collector import JsonlCollector as JsonlCollector
5+
from .pstats_collector import PstatsCollector as PstatsCollector
6+
from .stack_collector import CollapsedStackCollector as CollapsedStackCollector
7+
from .string_table import StringTable as StringTable
8+
9+
__all__ = (
10+
"Collector",
11+
"PstatsCollector",
12+
"CollapsedStackCollector",
13+
"HeatmapCollector",
14+
"GeckoCollector",
15+
"JsonlCollector",
16+
"StringTable",
17+
)
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
from _typeshed import StrOrBytesPath
2+
from abc import ABC, abstractmethod
3+
from collections.abc import Sequence
4+
from typing import Protocol, TypeAlias
5+
6+
_Location: TypeAlias = int | tuple[int, int, int, int] | _LocationInfo | None
7+
_Frame: TypeAlias = _FrameInfo | tuple[str, _Location, str, int | None]
8+
_Timestamps: TypeAlias = Sequence[int] | None
9+
_StackFrames: TypeAlias = Sequence[_InterpreterInfo] | Sequence[_AwaitedInfo]
10+
11+
class _LocationInfo(Protocol):
12+
lineno: int
13+
end_lineno: int
14+
col_offset: int
15+
end_col_offset: int
16+
def __getitem__(self, index: int, /) -> int: ...
17+
18+
class _FrameInfo(Protocol):
19+
filename: str
20+
location: _Location
21+
funcname: str
22+
opcode: int | None
23+
def __getitem__(self, index: int, /) -> object: ...
24+
25+
class _ThreadInfo(Protocol):
26+
thread_id: int
27+
status: int
28+
frame_info: Sequence[_Frame]
29+
30+
class _InterpreterInfo(Protocol):
31+
interpreter_id: int
32+
threads: Sequence[_ThreadInfo]
33+
34+
class _CoroInfo(Protocol):
35+
call_stack: Sequence[_Frame]
36+
task_name: int | str
37+
38+
class _TaskInfo(Protocol):
39+
task_id: int
40+
task_name: str
41+
coroutine_stack: Sequence[_CoroInfo]
42+
awaited_by: Sequence[_CoroInfo]
43+
44+
class _AwaitedInfo(Protocol):
45+
thread_id: int
46+
awaited_by: Sequence[_TaskInfo]
47+
48+
def normalize_location(location: _Location) -> tuple[int, int, int, int]: ...
49+
def extract_lineno(location: _Location) -> int: ...
50+
def filter_internal_frames(frames: Sequence[_Frame]) -> list[_Frame]: ...
51+
def iter_async_frames(awaited_info_list: Sequence[_AwaitedInfo]) -> object: ...
52+
53+
class Collector(ABC):
54+
@abstractmethod
55+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
56+
def collect_failed_sample(self) -> None: ...
57+
@abstractmethod
58+
def export(self, filename: StrOrBytesPath) -> None: ...
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from _typeshed import StrOrBytesPath
2+
3+
from .collector import Collector, _StackFrames, _Timestamps
4+
5+
class GeckoCollector(Collector):
6+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False, opcodes: bool = False) -> None: ...
7+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
8+
def export(self, filename: StrOrBytesPath) -> None: ...
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from _typeshed import StrOrBytesPath
2+
from collections.abc import Sequence
3+
4+
from .collector import Collector, _Frame, _StackFrames, _Timestamps
5+
6+
class HeatmapCollector(Collector):
7+
FILE_INDEX_FORMAT: str
8+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
9+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
10+
def export(self, output_path: StrOrBytesPath) -> None: ...
11+
def process_frames(self, frames: Sequence[_Frame], thread_id: int, weight: int = 1) -> None: ...
12+
def set_stats(
13+
self,
14+
sample_interval_usec: int,
15+
duration_sec: float,
16+
sample_rate: float,
17+
error_rate: float | None = None,
18+
missed_samples: float | None = None,
19+
**kwargs: object,
20+
) -> None: ...
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
from _typeshed import StrOrBytesPath
2+
from collections.abc import Sequence
3+
4+
from .collector import _Frame, _StackFrames, _Timestamps
5+
from .stack_collector import StackTraceCollector
6+
7+
class JsonlCollector(StackTraceCollector):
8+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False, mode: int | None = None) -> None: ...
9+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
10+
def export(self, filename: StrOrBytesPath) -> None: ...
11+
def process_frames(self, frames: Sequence[_Frame], _thread_id: int, weight: int = 1) -> None: ...
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
from _typeshed import StrOrBytesPath
2+
3+
from .collector import Collector, _StackFrames, _Timestamps
4+
5+
class PstatsCollector(Collector):
6+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
7+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
8+
def export(self, filename: StrOrBytesPath) -> None: ...
9+
def create_stats(self) -> None: ...
10+
def print_stats(
11+
self, sort: int = -1, limit: int | None = None, show_summary: bool = True, mode: int | None = None
12+
) -> None: ...
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from _typeshed import StrOrBytesPath
2+
from abc import ABCMeta
3+
from collections.abc import Sequence
4+
5+
from .collector import Collector, _Frame, _StackFrames, _Timestamps
6+
7+
class StackTraceCollector(Collector, metaclass=ABCMeta):
8+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
9+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
10+
def process_frames(self, frames: Sequence[_Frame], thread_id: int, weight: int = 1) -> None: ...
11+
12+
class CollapsedStackCollector(StackTraceCollector):
13+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
14+
def process_frames(self, frames: Sequence[_Frame], thread_id: int, weight: int = 1) -> None: ...
15+
def export(self, filename: StrOrBytesPath) -> None: ...
16+
17+
class FlamegraphCollector(StackTraceCollector):
18+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
19+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
20+
def set_stats(
21+
self,
22+
sample_interval_usec: int,
23+
duration_sec: float,
24+
sample_rate: float,
25+
error_rate: float | None = None,
26+
missed_samples: float | None = None,
27+
mode: int | None = None,
28+
) -> None: ...
29+
def export(self, filename: StrOrBytesPath) -> None: ...
30+
def process_frames(self, frames: Sequence[_Frame], thread_id: int, weight: int = 1) -> None: ...
31+
32+
class DiffFlamegraphCollector(FlamegraphCollector):
33+
def __init__(self, sample_interval_usec: int, *, baseline_binary_path: StrOrBytesPath, skip_idle: bool = False) -> None: ...
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class StringTable:
2+
def intern(self, string: object) -> int: ...
3+
def get_string(self, index: int) -> str: ...
4+
def get_strings(self) -> list[str]: ...
5+
def __len__(self) -> int: ...

0 commit comments

Comments
 (0)