Skip to content

Commit 8a6a2e3

Browse files
committed
Refine remote debugging profiling stubs
1 parent 9f66b3f commit 8a6a2e3

7 files changed

Lines changed: 47 additions & 20 deletions

File tree

stdlib/_remote_debugging.pyi

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ from collections.abc import Callable, Sequence
33
from typing import Final, TypeAlias, final
44
from typing_extensions import Self
55

6-
_Location: TypeAlias = int | LocationInfo | None
6+
_Location: TypeAlias = LocationInfo | None
77
_Frame: TypeAlias = tuple[str, _Location, str, int | None] | FrameInfo
8-
_StackFrames: TypeAlias = Sequence[InterpreterInfo]
98
_Stats: TypeAlias = dict[str, int | float]
109

1110
PROCESS_VM_READV_SUPPORTED: Final[int]
@@ -149,11 +148,12 @@ class GCMonitor:
149148

150149
@final
151150
class BinaryWriter:
152-
total_samples: int
153151
def __init__(
154152
self, filename: StrOrBytesPath, sample_interval_us: int, start_time_us: int, *, compression: int = 0
155153
) -> None: ...
156-
def write_sample(self, stack_frames: _StackFrames, timestamp_us: int) -> None: ...
154+
@property
155+
def total_samples(self) -> int: ...
156+
def write_sample(self, stack_frames: Sequence[InterpreterInfo], timestamp_us: int) -> None: ...
157157
def finalize(self) -> None: ...
158158
def close(self) -> None: ...
159159
def __enter__(self) -> Self: ...
@@ -162,9 +162,11 @@ class BinaryWriter:
162162

163163
@final
164164
class BinaryReader:
165-
sample_count: int
166-
sample_interval_us: int
167165
def __init__(self, filename: StrOrBytesPath) -> None: ...
166+
@property
167+
def sample_count(self) -> int: ...
168+
@property
169+
def sample_interval_us(self) -> int: ...
168170
def replay(self, collector: object, progress_callback: Callable[[int, int], object] | None = None) -> int: ...
169171
def get_info(self) -> dict[str, object]: ...
170172
def get_stats(self) -> _Stats: ...

stdlib/profiling/sampling/collector.pyi

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ from typing import TypeAlias
55

66
from _remote_debugging import AwaitedInfo, FrameInfo, InterpreterInfo, LocationInfo
77

8-
_Location: TypeAlias = int | tuple[int, int, int, int] | LocationInfo | None
8+
_Location: TypeAlias = tuple[int, int, int, int] | LocationInfo | None
99
_Frame: TypeAlias = FrameInfo | tuple[str, _Location, str, int | None]
1010
_Timestamps: TypeAlias = Sequence[int] | None
11-
_StackFrames: TypeAlias = Sequence[InterpreterInfo] | Sequence[AwaitedInfo]
1211

1312
def normalize_location(location: _Location) -> tuple[int, int, int, int]: ...
1413
def extract_lineno(location: _Location) -> int: ...
@@ -17,7 +16,9 @@ def iter_async_frames(awaited_info_list: Sequence[AwaitedInfo]) -> object: ...
1716

1817
class Collector(ABC):
1918
@abstractmethod
20-
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
19+
def collect(
20+
self, stack_frames: Sequence[InterpreterInfo] | Sequence[AwaitedInfo], timestamps_us: _Timestamps = None
21+
) -> None: ...
2122
def collect_failed_sample(self) -> None: ...
2223
@abstractmethod
2324
def export(self, filename: StrOrBytesPath) -> None: ...
Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
from _typeshed import StrOrBytesPath
2+
from collections.abc import Sequence
23

3-
from .collector import Collector, _StackFrames, _Timestamps
4+
from _remote_debugging import AwaitedInfo, InterpreterInfo
5+
6+
from .collector import Collector, _Timestamps
47

58
class GeckoCollector(Collector):
69
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: ...
10+
def collect(
11+
self, stack_frames: Sequence[InterpreterInfo] | Sequence[AwaitedInfo], timestamps_us: _Timestamps = None
12+
) -> None: ...
813
def export(self, filename: StrOrBytesPath) -> None: ...

stdlib/profiling/sampling/heatmap_collector.pyi

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,16 @@
11
from _typeshed import StrOrBytesPath
22
from collections.abc import Sequence
33

4-
from .collector import Collector, _Frame, _StackFrames, _Timestamps
4+
from _remote_debugging import AwaitedInfo, InterpreterInfo
5+
6+
from .collector import Collector, _Frame, _Timestamps
57

68
class HeatmapCollector(Collector):
79
FILE_INDEX_FORMAT: str
810
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
9-
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
11+
def collect(
12+
self, stack_frames: Sequence[InterpreterInfo] | Sequence[AwaitedInfo], timestamps_us: _Timestamps = None
13+
) -> None: ...
1014
def export(self, output_path: StrOrBytesPath) -> None: ...
1115
def process_frames(self, frames: Sequence[_Frame], thread_id: int, weight: int = 1) -> None: ...
1216
def set_stats(
Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
from _typeshed import StrOrBytesPath
22
from collections.abc import Sequence
33

4-
from .collector import _Frame, _StackFrames, _Timestamps
4+
from _remote_debugging import AwaitedInfo, InterpreterInfo
5+
6+
from .collector import _Frame, _Timestamps
57
from .stack_collector import StackTraceCollector
68

79
class JsonlCollector(StackTraceCollector):
810
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: ...
11+
def collect(
12+
self, stack_frames: Sequence[InterpreterInfo] | Sequence[AwaitedInfo], timestamps_us: _Timestamps = None
13+
) -> None: ...
1014
def export(self, filename: StrOrBytesPath) -> None: ...
1115
def process_frames(self, frames: Sequence[_Frame], _thread_id: int, weight: int = 1) -> None: ...

stdlib/profiling/sampling/pstats_collector.pyi

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
from _typeshed import StrOrBytesPath
2+
from collections.abc import Sequence
23

3-
from .collector import Collector, _StackFrames, _Timestamps
4+
from _remote_debugging import AwaitedInfo, InterpreterInfo
5+
6+
from .collector import Collector, _Timestamps
47

58
class PstatsCollector(Collector):
69
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
7-
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
10+
def collect(
11+
self, stack_frames: Sequence[InterpreterInfo] | Sequence[AwaitedInfo], timestamps_us: _Timestamps = None
12+
) -> None: ...
813
def export(self, filename: StrOrBytesPath) -> None: ...
914
def create_stats(self) -> None: ...
1015
def print_stats(

stdlib/profiling/sampling/stack_collector.pyi

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@ from _typeshed import StrOrBytesPath
22
from abc import ABCMeta
33
from collections.abc import Sequence
44

5-
from .collector import Collector, _Frame, _StackFrames, _Timestamps
5+
from _remote_debugging import AwaitedInfo, InterpreterInfo
6+
7+
from .collector import Collector, _Frame, _Timestamps
68

79
class StackTraceCollector(Collector, metaclass=ABCMeta):
810
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
9-
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
11+
def collect(
12+
self, stack_frames: Sequence[InterpreterInfo] | Sequence[AwaitedInfo], timestamps_us: _Timestamps = None
13+
) -> None: ...
1014
def process_frames(self, frames: Sequence[_Frame], thread_id: int, weight: int = 1) -> None: ...
1115

1216
class CollapsedStackCollector(StackTraceCollector):
@@ -16,7 +20,9 @@ class CollapsedStackCollector(StackTraceCollector):
1620

1721
class FlamegraphCollector(StackTraceCollector):
1822
def __init__(self, sample_interval_usec: int, *, skip_idle: bool = False) -> None: ...
19-
def collect(self, stack_frames: _StackFrames, timestamps_us: _Timestamps = None) -> None: ...
23+
def collect(
24+
self, stack_frames: Sequence[InterpreterInfo] | Sequence[AwaitedInfo], timestamps_us: _Timestamps = None
25+
) -> None: ...
2026
def set_stats(
2127
self,
2228
sample_interval_usec: int,

0 commit comments

Comments
 (0)