Skip to content

Commit dc817c4

Browse files
committed
Annotate profiling sampling parameters
1 parent 0b05261 commit dc817c4

1 file changed

Lines changed: 51 additions & 17 deletions

File tree

stdlib/profiling/sampling.pyi

Lines changed: 51 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
# pyright: reportMissingParameterType=false, reportUnknownParameterType=false
2-
31
from _typeshed import StrOrBytesPath
42
from abc import ABC, abstractmethod
3+
from collections.abc import Sequence
4+
from typing import Protocol, TypeAlias
55

66
__all__ = (
77
"Collector",
@@ -13,52 +13,86 @@ __all__ = (
1313
"StringTable",
1414
)
1515

16+
_Location: TypeAlias = int | tuple[int, int, int, int] | None
17+
_Timestamps: TypeAlias = Sequence[int] | None
18+
19+
class _FrameInfo(Protocol):
20+
filename: str
21+
location: _Location
22+
funcname: str
23+
def __getitem__(self, index: int, /) -> object: ...
24+
25+
class _ThreadInfo(Protocol):
26+
status: int
27+
thread_id: int
28+
frame_info: Sequence[_FrameInfo]
29+
30+
class _InterpreterInfo(Protocol):
31+
threads: Sequence[_ThreadInfo]
32+
33+
class _CoroutineInfo(Protocol):
34+
call_stack: Sequence[_FrameInfo]
35+
36+
class _TaskInfo(Protocol):
37+
task_id: int
38+
task_name: str
39+
awaited_by: Sequence[_TaskInfo]
40+
coroutine_stack: Sequence[_CoroutineInfo]
41+
42+
class _AwaitedInfo(Protocol):
43+
thread_id: int
44+
awaited_by: Sequence[_TaskInfo]
45+
46+
_StackFrames: TypeAlias = Sequence[_InterpreterInfo] | Sequence[_AwaitedInfo]
47+
1648
class Collector(ABC):
1749
@abstractmethod
18-
def collect(self, stack_frames, timestamps_us=None) -> None: ...
50+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
1951
def collect_failed_sample(self) -> None: ...
2052
@abstractmethod
2153
def export(self, filename: StrOrBytesPath) -> None: ...
2254

2355
class PstatsCollector(Collector):
2456
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
25-
def collect(self, stack_frames, timestamps_us=None) -> None: ...
57+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
2658
def export(self, filename: StrOrBytesPath) -> None: ...
2759
def create_stats(self) -> None: ...
28-
def print_stats(self, sort=-1, limit: int | None = None, show_summary: bool = True, mode=None) -> None: ...
60+
def print_stats(
61+
self, sort: int = -1, limit: int | None = None, show_summary: bool = True, mode: int | None = None
62+
) -> None: ...
2963

3064
class CollapsedStackCollector(Collector):
31-
def __init__(self, *args, **kwargs) -> None: ...
32-
def collect(self, stack_frames, timestamps_us=None) -> None: ...
65+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
66+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
3367
def export(self, filename: StrOrBytesPath) -> None: ...
34-
def process_frames(self, frames, thread_id: int, weight: int = 1) -> None: ...
68+
def process_frames(self, frames: Sequence[_FrameInfo], thread_id: int, weight: int = 1) -> None: ...
3569

3670
class HeatmapCollector(Collector):
3771
FILE_INDEX_FORMAT: str
38-
def __init__(self, *args, **kwargs) -> None: ...
39-
def collect(self, stack_frames, timestamps_us=None) -> None: ...
72+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
73+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
4074
def export(self, output_path: StrOrBytesPath) -> None: ...
41-
def process_frames(self, frames, thread_id: int, weight: int = 1) -> None: ...
75+
def process_frames(self, frames: Sequence[_FrameInfo], thread_id: int, weight: int = 1) -> None: ...
4276
def set_stats(
4377
self,
4478
sample_interval_usec: int,
4579
duration_sec: float,
4680
sample_rate: float,
4781
error_rate: float | None = None,
48-
missed_samples: int | None = None,
49-
**kwargs,
82+
missed_samples: float | None = None,
83+
**kwargs: object,
5084
) -> None: ...
5185

5286
class GeckoCollector(Collector):
5387
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False, opcodes: bool = False) -> None: ...
54-
def collect(self, stack_frames, timestamps_us=None) -> None: ...
88+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
5589
def export(self, filename: StrOrBytesPath) -> None: ...
5690

5791
class JsonlCollector(Collector):
58-
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False, mode=None) -> None: ...
59-
def collect(self, stack_frames, timestamps_us=None) -> None: ...
92+
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False, mode: int | None = None) -> None: ...
93+
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
6094
def export(self, filename: StrOrBytesPath) -> None: ...
61-
def process_frames(self, frames, _thread_id: int, weight: int = 1) -> None: ...
95+
def process_frames(self, frames: Sequence[_FrameInfo], _thread_id: int, weight: int = 1) -> None: ...
6296

6397
class StringTable:
6498
def intern(self, string: object) -> int: ...

0 commit comments

Comments
 (0)